<commit_before>from six import add_metaclass
from collections import OrderedDict, namedtuple
from core_serializers.fields import (
    SkipField, ValidationError, Field
)
from core_serializers.utils import (
    BasicObject, parse_html_dict, parse_html_list, empty, is_html_input, set_value
)
import copy


FieldResult = namedtuple('FieldResult', ['field', 'value', 'error'])


class BaseSerializer(Field):
    def __init__(self, instance=None, data=None, **kwargs):
        super(BaseSerializer, self).__init__(**kwargs)
        self.instance = instance
        self._initial_data = data

    def to_native(self, data):
        raise NotImplementedError()

    def to_primative(self, instance):
        raise NotImplementedError()

    def save(self):
        raise NotImplementedError()

    def is_valid(self):
        try:
            self._validated_data = self.to_native(self._initial_data)
        except ValidationError as exc:
            self._validated_data = {}
            self._errors = exc.message
            return False
        self._errors = {}
        return True

    @property
    def data(self):
        if not hasattr(self, '_data'):
            if self.instance is not None:
                self._data = self.to_primative(self.instance)
            elif self._initial_data is not None:
                self._data = {
                    field_name: field.get_value(self._initial_data)
                    for field_name, field in self.fields.items()
                }
            else:
                self._data = self.get_initial()
        return self._data

    @property
    def errors(self):
        if not hasattr(self, '_errors'):
            msg = 'You must call `.is_valid()` before accessing `.errors`.'
            raise AssertionError(msg)
        return self._errors

    @property
    def validated_data(self):<commit_msg>Python3 doesn't have exception.message any longer.<commit_after>from six import add_metaclass
from collections import OrderedDict, namedtuple
from core_serializers.fields import (
    SkipField, ValidationError, Field
)
from core_serializers.utils import (
    BasicObject, parse_html_dict, parse_html_list, empty, is_html_input, set_value
)
import copy


FieldResult = namedtuple('FieldResult', ['field', 'value', 'error'])


class BaseSerializer(Field):
    def __init__(self, instance=None, data=None, **kwargs):
        super(BaseSerializer, self).__init__(**kwargs)
        self.instance = instance
        self._initial_data = data

    def to_native(self, data):
        raise NotImplementedError()

    def to_primative(self, instance):
        raise NotImplementedError()

    def save(self):
        raise NotImplementedError()

    def is_valid(self):
        try:
            self._validated_data = self.to_native(self._initial_data)
        except ValidationError as exc:
            self._validated_data = {}
            self._errors = exc.args[0]
            return False
        self._errors = {}
        return True

    @property
    def data(self):
        if not hasattr(self, '_data'):
            if self.instance is not None:
                self._data = self.to_primative(self.instance)
            elif self._initial_data is not None:
                self._data = {
                    field_name: field.get_value(self._initial_data)
                    for field_name, field in self.fields.items()
                }
            else:
                self._data = self.get_initial()
        return self._data

    @property
    def errors(self):
        if not hasattr(self, '_errors'):
            msg = 'You must call `.is_valid()` before accessing `.errors`.'
            raise AssertionError(msg)
        return self._errors

    @property
    def validated_data(self):
{'fraction_non_alphanumeric': 0.09018355945730247, 'fraction_numerical': 0.0005320563979781857, 'mean_word_length': 2.315696649029982, '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': '3721813', 'n_tokens_mistral': 1049, 'n_tokens_neox': 1006, 'n_words': 262}