#NEWLINE# def validate_schema( schema , **kwargs ) : #NEWLINE# #INDENT# '\n    Validate input according to some JSON-schema file,\n    and return an error object if there is a problem.\n    ' #NEWLINE# def decorator( callback ) : #NEWLINE# #INDENT# def convert_to_dict( bottle_form ) : #NEWLINE# #INDENT# '\n            Function for converting a bottle multiple non-unique keys\n            dictionary to a normal python dictionary with lists automatically\n            created where appropriate, according to the JSON schema.\n            ' #NEWLINE# d = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , value ) in bottle_form . iterallitems ( ) : #NEWLINE# #INDENT# if ( key not in d ) : #NEWLINE# #INDENT# d [ key ] = value #NEWLINE# if ( ( key in schema . get ( 'properties' ) ) and ( not isinstance ( value , list ) ) ) : #NEWLINE# #INDENT# if ( ( 'array' == schema [ 'properties' ] [ key ] . get ( 'type' ) ) or ( 'array' in schema [ 'properties' ] [ key ] . get ( 'type' ) ) ) : #NEWLINE# #INDENT# d [ key ] = [ value ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( d [ key ] , list ) : #NEWLINE# #INDENT# d [ key ] += [ value ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# d [ key ] = ( [ d . get ( key ) ] + [ value ] ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# return d #NEWLINE# #UNINDENT# @ wraps ( callback ) #NEWLINE# def wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# if ( request . headers . get ( 'Content-Type' ) in ( 'application/json' , 'application/javascript' , 'text/javascript' ) ) : #NEWLINE# #INDENT# data = request . json #NEWLINE# instance = data #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# data = request . forms #NEWLINE# data . update ( request . query ) #NEWLINE# instance = convert_to_dict ( data ) #NEWLINE# #UNINDENT# request . cleaned_data = instance #NEWLINE# errors = jsonvalidation . get_error_dictionary ( schema = schema , instance = instance ) #NEWLINE# if errors : #NEWLINE# #INDENT# raise ValidationError ( message = _ ( 'There were errors validating your request.' ) , fields = errors ) #NEWLINE# #UNINDENT# return callback ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return wrapper #NEWLINE# #UNINDENT# return decorator