<commit_before>"""Schema used in Document"""
import marshmallow as ma

from .abstract import BaseSchema
from .i18n import gettext as _


__all__ = (
    'Schema',
    'schema_from_umongo_get_attribute',
    'SchemaFromUmongo',
)


def schema_from_umongo_get_attribute(self, obj, attr, default):
    """
    Overwrite default `Schema.get_attribute` method by this one to access
        umongo missing fields instead of returning `None`.

    example::

        class MySchema(marshsmallow.Schema):
            get_attribute = schema_from_umongo_get_attribute

            # Define the rest of your schema
            ...

    """
    ret = ma.Schema.get_attribute(self, obj, attr, default)
    if ret is None and ret is not default and attr in obj.schema.fields:
        raw_ret = obj._data.get(attr)
        return default if raw_ret is ma.missing else raw_ret
    return ret<commit_msg>Use ExposeMissing in schema_from_umongo_get_attribute<commit_after>"""Schema used in Document"""
import marshmallow as ma

from .abstract import BaseSchema
from .i18n import gettext as _
from .expose_missing import ExposeMissing

__all__ = (
    'Schema',
    'schema_from_umongo_get_attribute',
    'SchemaFromUmongo',
)


def schema_from_umongo_get_attribute(self, obj, attr, default):
    """
    Overwrite default `Schema.get_attribute` method by this one to access
        umongo missing fields instead of returning `None`.

    example::

        class MySchema(marshsmallow.Schema):
            get_attribute = schema_from_umongo_get_attribute

            # Define the rest of your schema
            ...

    """
    with ExposeMissing():
        return ma.Schema.get_attribute(self, obj, attr, default)
{'fraction_non_alphanumeric': 0.07769276044732196, 'fraction_numerical': 0.002354326074161271, 'mean_word_length': 3.1262135922330097, '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': '4777086', 'n_tokens_mistral': 501, 'n_tokens_neox': 485, 'n_words': 149}