<commit_before># coding=utf-8

from marshmallow import Schema, fields, post_dump
from marshmallow import validate, validates_schema, ValidationError
from sii import __SII_VERSION__
from datetime import datetime

PERIODO_VALUES = [
    '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '0A'
]

TIPO_NO_EXENTA_VALUES = ['S1', 'S2']

TIPO_RECTIFICATIVA_VALUES = ['S', 'I']


class DateString(fields.String):
    def _validate(self, value):
        if value is None:
            return None
        try:
            datetime.strptime(value, '%Y-%m-%d')
        except (ValueError, AttributeError):
            raise ValidationError('Invalid date string', value)

    @post_dump
    def _serialize(self, value, attr, obj):
        return datetime.strptime(value, '%Y-%m-%d').strftime('%d-%m-%Y')


class MySchema(Schema):
    @validates_schema(pass_original=True)
    def check_unknown_fields(self, data, original_data):
        unknown = list(set(original_data) - set(self.fields))
        if unknown:
            raise ValidationError('Unknown field', unknown)


class NIF(MySchema):
    NIF = fields.String(
        required=True, validate=validate.Length(max=9)
    )  # TODO validate if it belongs to a NIF ??


class Titular(NIF):
    NombreRazon = fields.String(required=True, validate=validate.Length(max=40))


class Cabecera(MySchema):
    IDVersionSii = fields.String(required=True, default=__SII_VERSION__)
    Titular = fields.Nested(Titular, required=True)
    TipoComunicacion = fields.String(
        required=True, validate=validate.Length(max=2)
    )


class PeriodoImpositivo(MySchema):
    Ejercicio = fields.String(required=True, validate=validate.Length(max=4))  # TODO validate Año en formato 'YYYY'
    Periodo = fields.String(
        required=True, validate=validate.OneOf(PERIODO_VALUES)
    )

<commit_msg>Change NombreRazon lenght from 40 to 120<commit_after># coding=utf-8

from marshmallow import Schema, fields, post_dump
from marshmallow import validate, validates_schema, ValidationError
from sii import __SII_VERSION__
from datetime import datetime

PERIODO_VALUES = [
    '01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12', '0A'
]

TIPO_NO_EXENTA_VALUES = ['S1', 'S2']

TIPO_RECTIFICATIVA_VALUES = ['S', 'I']


class DateString(fields.String):
    def _validate(self, value):
        if value is None:
            return None
        try:
            datetime.strptime(value, '%Y-%m-%d')
        except (ValueError, AttributeError):
            raise ValidationError('Invalid date string', value)

    @post_dump
    def _serialize(self, value, attr, obj):
        return datetime.strptime(value, '%Y-%m-%d').strftime('%d-%m-%Y')


class MySchema(Schema):
    @validates_schema(pass_original=True)
    def check_unknown_fields(self, data, original_data):
        unknown = list(set(original_data) - set(self.fields))
        if unknown:
            raise ValidationError('Unknown field', unknown)


class NIF(MySchema):
    NIF = fields.String(
        required=True, validate=validate.Length(max=9)
    )  # TODO validate if it belongs to a NIF ??


class Titular(NIF):
    NombreRazon = fields.String(required=True, validate=validate.Length(max=120))


class Cabecera(MySchema):
    IDVersionSii = fields.String(required=True, default=__SII_VERSION__)
    Titular = fields.Nested(Titular, required=True)
    TipoComunicacion = fields.String(
        required=True, validate=validate.Length(max=2)
    )


class PeriodoImpositivo(MySchema):
    Ejercicio = fields.String(required=True, validate=validate.Length(max=4))  # TODO validate Año en formato 'YYYY'
    Periodo = fields.String(
        required=True, validate=validate.OneOf(PERIODO_VALUES)
    )


{'fraction_non_alphanumeric': 0.1270096463022508, 'fraction_numerical': 0.01929260450160772, 'mean_word_length': 3.816774193548387, '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': '1401145', 'n_tokens_mistral': 1281, 'n_tokens_neox': 1226, 'n_words': 276}