<commit_before>from tastypie import fields
from tastypie.fields import ApiField, ToOneField, ToManyField, ApiFieldError
from tastypie.bundle import Bundle
from tastypie.utils import dict_strip_unicode_keys


class ListField(ApiField):
    dehydrated_type     =   'list'

    def dehydrate(self, obj):
        return self.convert(super(ListField, self).dehydrate(obj))

    def convert(self, value):
        if value is None:
            return None
        return value 

class EmbeddedListField(ToManyField):
    is_related = False
    is_m2m = False

    def dehydrate(self, bundle):
        if not bundle.obj or not bundle.obj.pk:
            if not self.null:
                raise ApiFieldError("The model '%r' does not have a primary key and can not be d in a ToMany context." % bundle.obj)
            return []
        if not getattr(bundle.obj, self.attribute):
            if not self.null:
                raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't all a null value." % (bundle.obj, self.attribute))
            return []
        self.m2m_resources = []
        m2m_dehydrated = []
        # TODO: Also model-specific and leaky. Relies on there being a
        #       ``Manager`` there.
        # NOTE: only had to remove .all()
        for index, m2m in enumerate(getattr(bundle.obj, self.attribute)):
            m2m_resource = self.get_related_resource(m2m)
            m2m_resource.id = index
            m2m_bundle = Bundle(obj=m2m)
            self.m2m_resources.append(m2m_resource)
            m2m_dehydrated.append(self.dehydrate_related(m2m_bundle, m2m_resource))
        return m2m_dehydrated

    def hydrate(self, bundle):
        return [b.obj for b in self.hydrate_m2m(bundle)]

class DictField(ApiField):
    dehydrated_type     =   'dict'
    
    def dehydrate(self, obj):
        return self.convert(super(DictField, self).dehydrate(obj))

    def convert(self, value):
        if value is None:
            return None

        return value

class EmbeddedModelField(ToOneField):<commit_msg>Revert unused changes.<commit_after>from tastypie import fields
from tastypie.fields import ApiField, ToOneField, ToManyField, ApiFieldError
from tastypie.bundle import Bundle
from tastypie.utils import dict_strip_unicode_keys


class ListField(ApiField):
    dehydrated_type     =   'list'

    def dehydrate(self, obj):
        return self.convert(super(ListField, self).dehydrate(obj))

    def convert(self, value):
        if value is None:
            return None
        return value 

class EmbeddedListField(ToManyField):
    is_related = False
    is_m2m = False

    def dehydrate(self, bundle):
        if not bundle.obj or not bundle.obj.pk:
            if not self.null:
                raise ApiFieldError("The model '%r' does not have a primary key and can not be d in a ToMany context." % bundle.obj)
            return []
        if not getattr(bundle.obj, self.attribute):
            if not self.null:
                raise ApiFieldError("The model '%r' has an empty attribute '%s' and doesn't all a null value." % (bundle.obj, self.attribute))
            return []
        self.m2m_resources = []
        m2m_dehydrated = []
        # TODO: Also model-specific and leaky. Relies on there being a
        #       ``Manager`` there.
        # NOTE: only had to remove .all()
        for m2m in getattr(bundle.obj, self.attribute):
            m2m_resource = self.get_related_resource(m2m)
            m2m_bundle = Bundle(obj=m2m)
            self.m2m_resources.append(m2m_resource)
            m2m_dehydrated.append(self.dehydrate_related(m2m_bundle, m2m_resource))
        return m2m_dehydrated

    def hydrate(self, bundle):
        return [b.obj for b in self.hydrate_m2m(bundle)]

class DictField(ApiField):
    dehydrated_type     =   'dict'
    
    def dehydrate(self, obj):
        return self.convert(super(DictField, self).dehydrate(obj))

    def convert(self, value):
        if value is None:
            return None

        return value

class EmbeddedModelField(ToOneField):
{'fraction_non_alphanumeric': 0.08605851979345955, 'fraction_numerical': 0.007622326038849275, 'mean_word_length': 2.4798973481608213, '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': '4480383', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1231, 'n_words': 344}