#NEWLINE# def validate( cls , instance_or_dict , trusted_data = None , partial = False , strict = False , convert = True , context = None , **kwargs ) : #NEWLINE# #INDENT# '\n    Validate some untrusted data using a model. Trusted data can be passed in\n    the `trusted_data` parameter.\n\n    :param cls:\n        The model class to use as source for validation. If given an instance,\n        will also run instance-level validators on the data.\n    :param instance_or_dict:\n        A ``dict`` or ``dict``-like structure for incoming data.\n    :param partial:\n        Allow partial data to validate; useful for PATCH requests.\n        Essentially drops the ``required=True`` arguments from field\n        definitions. Default: False\n    :param strict:\n        Complain about unrecognized keys. Default: False\n    :param trusted_data:\n        A ``dict``-like structure that may contain already validated data.\n    :param convert:\n        Controls whether to perform import conversion before validating.\n        Can be turned off to skip an unnecessary conversion step if all values\n        are known to have the right datatypes (e.g., when validating immediately\n        after the initial import). Default: True\n\n    :returns: data\n        ``dict`` containing the valid raw_data plus ``trusted_data``.\n        If errors are found, they are raised as a ValidationError with a list\n        of errors attached.\n    ' #NEWLINE# context = ( context or get_validation_context ( partial = partial , strict = strict , convert = convert ) ) #NEWLINE# errors = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# try : #NEWLINE# #INDENT# data = import_loop ( cls , instance_or_dict , trusted_data = trusted_data , context = context , ** kwargs ) #NEWLINE# #UNINDENT# except DataError as exc : #NEWLINE# #INDENT# errors = exc . messages #NEWLINE# data = exc . partial_data #NEWLINE# #UNINDENT# partial_data = dict ( ( ( key , value ) for ( key , value ) in data . items ( ) if ( value is not Undefined ) ) ) #NEWLINE# errors . update ( _validate_model ( cls , data , partial_data , context ) ) #NEWLINE# if errors : #NEWLINE# #INDENT# raise DataError ( errors , partial_data ) #NEWLINE# #UNINDENT# return data