def __call__(self, request, response, api_version=None, **kwargs):
        context = self.api.context_factory(response=response, request=request, api=self.api, api_version=api_version,
                                           interface=self)
        """Call the wrapped function over HTTP pulling information as needed"""
        if isinstance(api_version, str) and api_version.isdigit():
            api_version = int(api_version)
        else:
            api_version = None
        if not self.catch_exceptions:
            exception_types = ()
        else:
            exception_types = self.api.http.exception_handlers(api_version)
            exception_types = tuple(exception_types.keys()) if exception_types else ()
        input_parameters = {}
        try:
            self.set_response_defaults(response, request)
            lacks_requirement = self.check_requirements(request, response, context)
            if lacks_requirement:
                response.data = self.outputs(lacks_requirement,
                                             **self._arguments(self._params_for_outputs, request, response))
                self.api.delete_context(context, lacks_requirement=lacks_requirement)
                return

            input_parameters = self.gather_parameters(request, response, context, api_version, **kwargs)
            errors = self.validate(input_parameters, context)
            if errors:
                self.api.delete_context(context, errors=errors)
                return self.render_errors(errors, request, response)

            self.render_content(self.call_function(input_parameters), context, request, response, **kwargs)
        except falcon.HTTPNotFound as exception:
            self.cleanup_parameters(input_parameters, exception=exception)
            self.api.delete_context(context, exception=exception)
            return self.api.http.not_found(request, response, **kwargs)
        except exception_types as exception:
            self.cleanup_parameters(input_parameters, exception=exception)
            self.api.delete_context(context, exception=exception)
            handler = None
            exception_type = type(exception)
            if exception_type in exception_types:
                handler = self.api.http.exception_handlers(api_version)[exception_type][0]
            else:
                for match_exception_type, exception_handlers in \
                  tuple(self.api.http.exception_handlers(api_version).items())[::-1]:
                    if isinstance(exception, match_exception_type):
                        for potential_handler in exception_handlers:
                             if not isinstance(exception, potential_handler.exclude):
                                handler = potential_handler

            if not handler:
                raise exception

            handler(request=request, response=response, exception=exception, **kwargs)
        except Exception as exception:
            self.cleanup_parameters(input_parameters, exception=exception)
            self.api.delete_context(context, exception=exception)
            raise exception
        self.cleanup_parameters(input_parameters)
        self.api.delete_context(context)
def __call__ ( self , request , response , api_version = None , ** kwargs ) : context = self . api . context_factory ( response = response , request = request , api = self . api , api_version = api_version , interface = self ) if isinstance ( api_version , str ) and api_version . isdigit ( ) : api_version = int ( api_version ) else : api_version = None if not self . catch_exceptions : exception_types = ( ) else : exception_types = self . api . http . exception_handlers ( api_version ) exception_types = tuple ( exception_types . keys ( ) ) if exception_types else ( ) input_parameters = { } try : self . set_response_defaults ( response , request ) lacks_requirement = self . check_requirements ( request , response , context ) if lacks_requirement : response . data = self . outputs ( lacks_requirement , ** self . _arguments ( self . _params_for_outputs , request , response ) ) self . api . delete_context ( context , lacks_requirement = lacks_requirement ) return input_parameters = self . gather_parameters ( request , response , context , api_version , ** kwargs ) errors = self . validate ( input_parameters , context ) if errors : self . api . delete_context ( context , errors = errors ) return self . render_errors ( errors , request , response ) self . render_content ( self . call_function ( input_parameters ) , context , request , response , ** kwargs ) except falcon . HTTPNotFound as exception : self . cleanup_parameters ( input_parameters , exception = exception ) self . api . delete_context ( context , exception = exception ) return self . api . http . not_found ( request , response , ** kwargs ) except exception_types as exception : self . cleanup_parameters ( input_parameters , exception = exception ) self . api . delete_context ( context , exception = exception ) handler = None exception_type = type ( exception ) if exception_type in exception_types : handler = self . api . http . exception_handlers ( api_version ) [ exception_type ] [ 0 ] else : for match_exception_type , exception_handlers in tuple ( self . api . http . exception_handlers ( api_version ) . items ( ) ) [ : : - 1 ] : if isinstance ( exception , match_exception_type ) : for potential_handler in exception_handlers : if not isinstance ( exception , potential_handler . exclude ) : handler = potential_handler if not handler : raise exception handler ( request = request , response = response , exception = exception , ** kwargs ) except Exception as exception : self . cleanup_parameters ( input_parameters , exception = exception ) self . api . delete_context ( context , exception = exception ) raise exception self . cleanup_parameters ( input_parameters ) self . api . delete_context ( context )
Call the wrapped function over HTTP pulling information as needed