# Path: scalymongo/errors.py
# class ValidationError(Exception):
#     """Raised when a model has failed validation."""
#     pass


from inspect import isclass
from scalymongo.errors import ValidationError

        self.field_validator(path, value, sub_structure)


def _check_for_unknown_fields(body, structure, path):
    """Check `body` for any keys not present in `structure`.

    This only checks the first level of keys.  Any keys from :class:`dict`s in
    the `body`\ 's values will not be checked.

    """
    type_keys = tuple([key for key in structure if isclass(key)])
    existing_fields = set([key for key in body if not isclass(key)])
    unknown_fields = existing_fields.difference(structure.keys())
    # If there are valid types for a key filter out unknown fields that match a
    # type.
    if type_keys:
        unknown_fields = [key for key in unknown_fields
                          if not isinstance(key, type_keys)]

    if unknown_fields:
        unknown_fields = ', '.join([repr(field) for field in unknown_fields])
        if path:
            err = ('Encountered field(s), in subdocument at {0},'
                   ' not present in structure: {1}'.format(
                       path, unknown_fields))
        else:
            err = 'Encountered field(s) not present in structure: {0}'.format(
                unknown_fields)


# Path: scalymongo/errors.py
# class ValidationError(Exception):
#     """Raised when a model has failed validation."""
#     pass


# Path: scalymongo/structure_walker.py
from inspect import isclass
from scalymongo.errors import ValidationError


        self.field_validator(path, value, sub_structure)


def _check_for_unknown_fields(body, structure, path):
    """Check `body` for any keys not present in `structure`.

    This only checks the first level of keys.  Any keys from :class:`dict`s in
    the `body`\ 's values will not be checked.

    """
    type_keys = tuple([key for key in structure if isclass(key)])
    existing_fields = set([key for key in body if not isclass(key)])
    unknown_fields = existing_fields.difference(structure.keys())
    # If there are valid types for a key filter out unknown fields that match a
    # type.
    if type_keys:
        unknown_fields = [key for key in unknown_fields
                          if not isinstance(key, type_keys)]

    if unknown_fields:
        unknown_fields = ', '.join([repr(field) for field in unknown_fields])
        if path:
            err = ('Encountered field(s), in subdocument at {0},'
                   ' not present in structure: {1}'.format(
                       path, unknown_fields))
        else:
            err = 'Encountered field(s) not present in structure: {0}'.format(
                unknown_fields)


        raise ValidationError(err)