<commit_before>from tastypie.fields import DateTimeField as BaseDateTimeField, FileField as BaseFileField


class DateTimeField(BaseDateTimeField):
    """Normalizes a datetime field by removing the microseconds."""
    def __init__(self, *args, **kwargs):
        self.normalize = kwargs.pop('normalize', True)
        super(DateTimeField, self).__init__(*args, **kwargs)

    def dehydrate(self, bundle):
        value = super(DateTimeField, self).dehydrate(bundle)
        if value:
            value = value.replace(microsecond=0)
        return value

    def hydrate(self, bundle):
        value = super(DateTimeField, self).hydrate(bundle)
        if value:
            value = value.replace(microsecond=0)
        return value



class FileField(BaseFileField):
    """
    Provides a way of dehydrating the file URL as an absolute URL,
    as well as hydrating using the 'files' bundle attribute to use
    multipart/form-data to upload a file. To use this, you can
    also use the FileUploadMixin to handle multipart/form-data
    in a post_list handler.
    """
    def __init__(self, *args, **kwargs):
        self.absolute = kwargs.pop('absolute', False)
        super(FileField, self).__init__(*args, **kwargs)

    def dehydrate(self, bundle):
        value = super(FileField, self).dehydrate(bundle)
        if value and self.absolute and hasattr(bundle, 'request'):
            value = bundle.request.build_absolute_uri(unicode(value))
        return value

    def hydrate(self, bundle):
        "The only difference with the base class is we check the 'files' bundle attribute."
        if self.readonly:
            return None
        if not hasattr(bundle, 'files'):
            return None

        if self.instance_name not in bundle.files:
            return super(FileField, self).hydrate(bundle)

        return bundle.files[self.instance_name]
<commit_msg>Update dehydrate for tastypie 0.9.15<commit_after>from tastypie.fields import DateTimeField as BaseDateTimeField, FileField as BaseFileField


class DateTimeField(BaseDateTimeField):
    """Normalizes a datetime field by removing the microseconds."""
    def __init__(self, *args, **kwargs):
        self.normalize = kwargs.pop('normalize', True)
        super(DateTimeField, self).__init__(*args, **kwargs)

    def dehydrate(self, bundle, for_list=True):
        value = super(DateTimeField, self).dehydrate(bundle)
        if value:
            value = value.replace(microsecond=0)
        return value

    def hydrate(self, bundle):
        value = super(DateTimeField, self).hydrate(bundle)
        if value:
            value = value.replace(microsecond=0)
        return value



class FileField(BaseFileField):
    """
    Provides a way of dehydrating the file URL as an absolute URL,
    as well as hydrating using the 'files' bundle attribute to use
    multipart/form-data to upload a file. To use this, you can
    also use the FileUploadMixin to handle multipart/form-data
    in a post_list handler.
    """
    def __init__(self, *args, **kwargs):
        self.absolute = kwargs.pop('absolute', False)
        super(FileField, self).__init__(*args, **kwargs)

    def dehydrate(self, bundle, for_list=True):
        value = super(FileField, self).dehydrate(bundle)
        if value and self.absolute and hasattr(bundle, 'request'):
            value = bundle.request.build_absolute_uri(unicode(value))
        return value

    def hydrate(self, bundle):
        "The only difference with the base class is we check the 'files' bundle attribute."
        if self.readonly:
            return None
        if not hasattr(bundle, 'files'):
            return None

        if self.instance_name not in bundle.files:
            return super(FileField, self).hydrate(bundle)

        return bundle.files[self.instance_name]

{'fraction_non_alphanumeric': 0.09312058592728224, 'fraction_numerical': 0.00209259743656814, 'mean_word_length': 2.906026557711951, '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': '5073755', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1038, 'n_words': 332}