#NEWLINE# def json_to_params( fn = None , return_json = True ) : #NEWLINE# #INDENT# '\n    Convert JSON in the body of the request to the parameters for the wrapped\n    function.\n\n    If the JSON is list, add it to ``*args``.\n\n    If dict, add it to ``**kwargs`` in non-rewrite mode (no key in ``**kwargs``\n    will be overwritten).\n\n    If single value, add it to ``*args``.\n\n    Args:\n        return_json (bool, default True): Should the decorator automatically\n                    convert returned value to JSON?\n    ' #NEWLINE# def json_to_params_decorator( fn ) : #NEWLINE# #INDENT# @ handle_type_error #NEWLINE# @ wraps ( fn ) #NEWLINE# def json_to_params_wrapper( * args , **kwargs ) : #NEWLINE# #INDENT# data = decode_json_body ( ) #NEWLINE# if ( type ( data ) in [ tuple , list ] ) : #NEWLINE# #INDENT# args = ( list ( args ) + data ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( data ) == dict ) : #NEWLINE# #INDENT# allowed_keys = ( set ( data . keys ( ) ) - set ( kwargs . keys ( ) ) ) #NEWLINE# for key in allowed_keys : #NEWLINE# #INDENT# kwargs [ key ] = data [ key ] #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# if ( type ( data ) in [ bool , int , float , long , str , unicode ] ) : #NEWLINE# #INDENT# args = list ( args ) #NEWLINE# args . append ( data ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not return_json ) : #NEWLINE# #INDENT# return fn ( * args , ** kwargs ) #NEWLINE# #UNINDENT# return encode_json_body ( fn ( * args , ** kwargs ) ) #NEWLINE# #UNINDENT# return json_to_params_wrapper #NEWLINE# #UNINDENT# if fn : #NEWLINE# #INDENT# return json_to_params_decorator ( return_json ) #NEWLINE# #UNINDENT# return json_to_params_decorator