<commit_before>import os
import pytz
import six


# Django
from django.core.exceptions import ValidationError


from django.db import models
from django.db.models.fields.related_descriptors import ReverseOneToOneDescriptor
from django.core.exceptions import ObjectDoesNotExist
from django.db.models import OneToOneField
from django.db.transaction import atomic
from django.utils.deconstruct import deconstructible

from rest_framework_json_api import serializers

from cloudinary.models import CloudinaryField


class ReverseOneToOneDescriptorReturnsNone(ReverseOneToOneDescriptor):
    def __get__(self, instance, cls=None):
        try:
            return super().__get__(instance=instance)
        except ObjectDoesNotExist:
            return None


class OneToOneOrNoneField(models.OneToOneField):
    related_accessor_class = ReverseOneToOneDescriptorReturnsNone


@deconstructible
class PathAndRename(object):

    def __init__(self, sub_path=''):
        self.path = sub_path

    def __call__(self, instance, filename):
        f, ext = os.path.splitext(filename)
        filename = '{0}{1}'.format(instance.id, ext.lower())
        return os.path.join(self.path, filename)


class CloudinaryRenameField(CloudinaryField):

    def upload_options(self, model_instance):
        return {'public_id': str(model_instance.id)}


class TimezoneField(serializers.Field):
    def to_representation(self, obj):
        return six.text_type(obj)

    def to_internal_value(self, data):
        try:
            return pytz.timezone(str(data))
        except pytz.exceptions.UnknownTimeZoneError:
            raise ValidationError('Unknown timezone')
<commit_msg>Decruft AWS Renamer<commit_after>import pytz
import six


# Django
from django.core.exceptions import ValidationError


from django.db import models
from django.db.models.fields.related_descriptors import ReverseOneToOneDescriptor
from django.core.exceptions import ObjectDoesNotExist

from rest_framework_json_api import serializers

from cloudinary.models import CloudinaryField


class ReverseOneToOneDescriptorReturnsNone(ReverseOneToOneDescriptor):
    def __get__(self, instance, cls=None):
        try:
            return super().__get__(instance=instance)
        except ObjectDoesNotExist:
            return None


class OneToOneOrNoneField(models.OneToOneField):
    related_accessor_class = ReverseOneToOneDescriptorReturnsNone


class CloudinaryRenameField(CloudinaryField):

    def upload_options(self, model_instance):
        return {'public_id': str(model_instance.id)}


class TimezoneField(serializers.Field):
    def to_representation(self, obj):
        return six.text_type(obj)

    def to_internal_value(self, data):
        try:
            return pytz.timezone(str(data))
        except pytz.exceptions.UnknownTimeZoneError:
            raise ValidationError('Unknown timezone')

{'fraction_non_alphanumeric': 0.07289850017439832, 'fraction_numerical': 0.0006975933031042902, 'mean_word_length': 4.233576642335766, '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': '2447139', 'n_tokens_mistral': 823, 'n_tokens_neox': 791, 'n_words': 181}