<commit_before>import datetime
import json
import six

'''
Adds the ability to send date and datetime objects to the API
The date and datetime formats from the API are automatically supported and parsed
'''


def _datetime_encoder(obj):
    if isinstance(obj, (datetime.datetime, datetime.date)):
        return obj.isoformat()


def _datetime_decoder(dict_):
    for key, value in dict_.items():
        # The built-in `json` library will `unicode` strings, except for empty
        # strings which are of type `str`. `jsondate` patches this for
        # consistency so that `unicode` is always returned.
        if value == '':
            dict_[key] = u''
            continue

        if value is not None and isinstance(value, six.string_types):
            try:
                # The api always returns times like this
                # 2014-07-25T09:12:24.735
                datetime_obj = datetime.datetime.strptime(
                    value, "%Y-%m-%dT%H:%M:%S.%f")
                dict_[key] = datetime_obj
            except (ValueError, TypeError):
                try:
                    # The api always returns times like this
                    # 2014-07-25T09:12:24.735
                    datetime_obj = datetime.datetime.strptime(
                        value, "%Y-%m-%d")
                    dict_[key] = datetime_obj.date()
                except (ValueError, TypeError):
                    continue
    return dict_


def dumps(*args, **kwargs):
    kwargs['default'] = _datetime_encoder
    return json.dumps(*args, **kwargs)


def dump(*args, **kwargs):
    kwargs['default'] = _datetime_encoder
    return json.dump(*args, **kwargs)


def loads(*args, **kwargs):
    kwargs['object_hook'] = _datetime_decoder
    return json.loads(*args, **kwargs)


def load(*args, **kwargs):
    kwargs['object_hook'] = _datetime_decoder
    return json.load(*args, **kwargs)
<commit_msg>Coverage: Remove unused dump and load methods<commit_after>import datetime
import json
import six

'''
Adds the ability to send date and datetime objects to the API
The date and datetime formats from the API are automatically supported and parsed
'''


def _datetime_encoder(obj):
    if isinstance(obj, (datetime.datetime, datetime.date)):
        return obj.isoformat()


def _datetime_decoder(dict_):
    for key, value in dict_.items():
        # The built-in `json` library will `unicode` strings, except for empty
        # strings which are of type `str`. `jsondate` patches this for
        # consistency so that `unicode` is always returned.
        if value == '':
            dict_[key] = u''
            continue

        if value is not None and isinstance(value, six.string_types):
            try:
                # The api always returns times like this
                # 2014-07-25T09:12:24.735
                datetime_obj = datetime.datetime.strptime(
                    value, "%Y-%m-%dT%H:%M:%S.%f")
                dict_[key] = datetime_obj
            except (ValueError, TypeError):
                try:
                    # The api always returns times like this
                    # 2014-07-25T09:12:24.735
                    datetime_obj = datetime.datetime.strptime(
                        value, "%Y-%m-%d")
                    dict_[key] = datetime_obj.date()
                except (ValueError, TypeError):
                    continue
    return dict_


def dumps(*args, **kwargs):
    kwargs['default'] = _datetime_encoder
    return json.dumps(*args, **kwargs)


def loads(*args, **kwargs):
    kwargs['object_hook'] = _datetime_decoder
    return json.loads(*args, **kwargs)

{'fraction_non_alphanumeric': 0.10359116022099447, 'fraction_numerical': 0.01878453038674033, 'mean_word_length': 2.108154506437768, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2057358', 'n_tokens_mistral': 1041, 'n_tokens_neox': 948, 'n_words': 304}