<commit_before># -*- coding: utf-8 -*-


from datetime import datetime
from collections import namedtuple

from bson.errors import InvalidId
from bson.objectid import ObjectId

from marshmallow import (
        Schema, fields, validates, ValidationError
)
from flask_restful import Resource
from flask import current_app, request, session

from model import (
        get_article, vote_article,
        get_begin_day, get_before_day, get_after_day,
        get_entries_by_day,
        get_entries_next, get_entries_pre, get_entries_by_spider,
        get_spiders,
)
from .utils import format_messages


Spider = namedtuple('Spider', ['id', 'source'])


class ObjectIdField(fields.Field):

    def _serialize(self, value, attr, obj, **kwargs):
        return str(value)

    def _deserialize(self, value, attr, data, **kwargs):
        try:
            return ObjectId(value)
        except InvalidId:
            raise ValidationError(f'invalid ObjectId {value}')


class Day(Resource):

    def get(self):

        class DayRequestSchema(Schema):
            day = fields.Date(required=True)

            def __init__(self, strict=True, **kwargs):
                super().__init__(strict=strict, **kwargs)

            @validates('day')
            def validate_day(self, day):
                day_begin = get_begin_day()
                if not day_begin <= day <= datetime.utcnow().date():
                    raise ValidationError('invalid day value')

        schema = DayRequestSchema()
        try:
            day_request = schema.load(request.args).data
        except ValidationError as err:
            return {'message': format_messages(err.messages)}, 400
        except Exception:
            return {'message': 'invalid request'}, 400<commit_msg>fix bug: marshmallow update<commit_after># -*- coding: utf-8 -*-


from datetime import datetime
from collections import namedtuple

from bson.errors import InvalidId
from bson.objectid import ObjectId

from marshmallow import (
        Schema, fields, validates, ValidationError
)
from flask_restful import Resource
from flask import current_app, request, session

from model import (
        get_article, vote_article,
        get_begin_day, get_before_day, get_after_day,
        get_entries_by_day,
        get_entries_next, get_entries_pre, get_entries_by_spider,
        get_spiders,
)
from .utils import format_messages


Spider = namedtuple('Spider', ['id', 'source'])


class ObjectIdField(fields.Field):

    def _serialize(self, value, attr, obj, **kwargs):
        return str(value)

    def _deserialize(self, value, attr, data, **kwargs):
        try:
            return ObjectId(value)
        except InvalidId:
            raise ValidationError(f'invalid ObjectId {value}')


class Day(Resource):

    def get(self):

        class DayRequestSchema(Schema):
            day = fields.Date(required=True)

            @validates('day')
            def validate_day(self, day):
                day_begin = get_begin_day()
                if not day_begin <= day <= datetime.utcnow().date():
                    raise ValidationError('invalid day value')

        schema = DayRequestSchema()
        try:
            day_request = schema.load(request.args)
        except ValidationError as err:
            return {'message': format_messages(err.messages)}, 400
        except Exception as e:
            return {'message': 'invalid request'}, 400
{'fraction_non_alphanumeric': 0.0932748538011696, 'fraction_numerical': 0.004093567251461989, 'mean_word_length': 2.6983783783783784, 'pattern_counts': {'":': 0, '<': 7, '<?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': '6493712', 'n_tokens_mistral': 964, 'n_tokens_neox': 910, 'n_words': 260}