#NEWLINE# def route( self , resource , methods = None , endpoint = None , **options ) : #NEWLINE# #INDENT# resource = self . get_resource ( resource ) #NEWLINE# uri = resource [ 'uri' ] #NEWLINE# config = ( dict ( self . config , ** options ) if options else self . config ) #NEWLINE# methods = self . get_resource_methods ( resource , methods ) #NEWLINE# if ( endpoint is None ) : #NEWLINE# #INDENT# endpoint = self . get_endpoint ( resource , methods , self . endpoint_template ) #NEWLINE# #UNINDENT# auth = config [ 'auth' ] #NEWLINE# decorate = config . get ( 'decorate' , None ) #NEWLINE# decode_request = self . encoders [ config [ 'decode_request' ] ] #NEWLINE# encode_response = self . encoders [ config [ 'encode_response' ] ] #NEWLINE# convert_uri_params = config [ 'convert_uri_params' ] #NEWLINE# convert_query_params = methods [ 'convert_query_params' ] #NEWLINE# def decorator( view ) : #NEWLINE# #INDENT# self . log . debug ( 'map %s %s %s' , self . id , '/' . join ( sorted ( methods ) ) , uri ) #NEWLINE# @ wraps ( view ) #NEWLINE# def decorated_view( **uri_params ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# url = request . path #NEWLINE# self . log . info ( '%s %s << %s [%s|%s|%s]' , request . method , url , ( uri_params if ( self . app . debug or ( not uri_params ) ) else '{...}' ) , ( len ( uri_params ) or '-' ) , ( len ( request . args ) or '-' ) , ( len ( request . data ) or '-' ) ) #NEWLINE# if auth : #NEWLINE# #INDENT# auth . authorize ( uri_params , request ) #NEWLINE# #UNINDENT# method = self . get_method_spec ( resource , request . method ) #NEWLINE# if convert_uri_params : #NEWLINE# #INDENT# uri_params = self . converter . convert_params ( resource [ 'allUriParameters' ] , uri_params ) #NEWLINE# #UNINDENT# if convert_query_params : #NEWLINE# #INDENT# if ( 'queryParameters' in method ) : #NEWLINE# #INDENT# uri_params . update ( self . converter . convert_params ( method [ 'queryParameters' ] , request . args ) ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if request . args : #NEWLINE# #INDENT# self . abort ( 400 , 'resource does not accept query parameters' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if uri_params : #NEWLINE# #INDENT# self . log . debug ( '%s %s << args: %s [%s]' , request . method , url , uri_params , ( len ( uri_params ) or '-' ) ) #NEWLINE# #UNINDENT# if decode_request : #NEWLINE# #INDENT# self . log . debug ( '%s %s << data: %s [%s]' , request . method , url , decode_request . name , len ( request . data ) ) #NEWLINE# uri_params . update ( decode_request . get_request_data ( ) ) #NEWLINE# #UNINDENT# response = view ( ** uri_params ) #NEWLINE# if ( encode_response and ( not isinstance ( response , ( Response , basestring ) ) ) ) : #NEWLINE# #INDENT# response = encode_response . make_response ( response ) #NEWLINE# self . log . debug ( '%s %s >> %s [%s:%s] (%s)' , request . method , url , encode_response . name , type ( response . response ) , len ( response . response ) , response . status ) #NEWLINE# #UNINDENT# return response #NEWLINE# #UNINDENT# except HTTPException as error : #NEWLINE# #INDENT# if error . response : #NEWLINE# #INDENT# raise #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# self . abort ( error . code , error . description ) #NEWLINE# #UNINDENT# #UNINDENT# except ApiError as error : #NEWLINE# #INDENT# self . abort ( error . status , error . message ) #NEWLINE# #UNINDENT# except Exception as error : #NEWLINE# #INDENT# msg = ( str ( error ) if self . app . debug else self . default_error_message ) #NEWLINE# self . abort ( self . default_error_status , msg ) #NEWLINE# #UNINDENT# #UNINDENT# if decorate : #NEWLINE# #INDENT# decorated_view = decorate ( decorated_view ) #NEWLINE# #UNINDENT# self . app . add_url_rule ( uri , endpoint , decorated_view , methods = methods ) #NEWLINE# for method in methods : #NEWLINE# #INDENT# self . views . setdefault ( uri , { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } ) [ method ] = decorated_view #NEWLINE# #UNINDENT# return decorated_view #NEWLINE# #UNINDENT# return decorator