a [f$@s\dZddlmZddlZddlmZddlmZddZdd Z d d Z d d Z ddZ dS)zHook decorators.)wrapsN)COMBINED_METHODS) get_argnamescsfdd}|S)aDecorator to execute the given action function *before* the responder. Args: action (callable): A function of the form ``func(req, resp, resource, params)``, where `resource` is a reference to the resource class instance associated with the request, and `params` is a dict of URI Template field names, if any, that will be passed into the resource responder as kwargs. Note: Hooks may inject extra params as needed. For example:: def do_something(req, resp, resource, params): try: params['id'] = int(params['id']) except ValueError: raise falcon.HTTPBadRequest('Invalid ID', 'ID was not valid.') params['answer'] = 42 *args: Any additional arguments will be passed to *action* in the order given, immediately following the *req*, *resp*, *resource*, and *params* arguments. **kwargs: Any additional keyword arguments will be passed through to *action*. c st|tjrr|tD]X}d|zt}WntyDYq0t|r|ffdd }|qS|}t|}|SdS)Non_cst|}t|dSN)_wrap_with_beforesetattr) responder do_before_allactionargskwargsresourceresponder_namep/sparta/input/_build_configuration/image_build+validate/lib/bmcenv/lib64/python3.9/site-packages/falcon/hooks.pyletLsz$before.._before..let) isinstancesix class_typesrlowergetattrAttributeErrorcallabler)responder_or_resourcemethodr r do_before_oner r rrrr_before8s   zbefore.._beforer)r r rr rrrbefores#r!csfdd}|S)aFDecorator to execute the given action function *after* the responder. Args: action (callable): A function of the form ``func(req, resp, resource)``, where `resource` is a reference to the resource class instance associated with the request *args: Any additional arguments will be passed to *action* in the order given, immediately following the *req*, *resp*, *resource*, and *params* arguments. **kwargs: Any additional keyword arguments will be passed through to *action*. c st|tjrr|tD]X}d|zt}WntyDYq0t|r|ffdd }|qS|}t|}|SdS)Nrcst|}t|dSr)_wrap_with_afterr)r do_after_allr rrrsz"after.._after..let) rrrrrrrrr")rrr r do_after_onerrr_afteros   zafter.._afterr)r r rr%rrrafter^sr&csRdtvrn fddt}|ddtfdd}|S)aExecute the given action function after a responder method. Args: responder: The responder method to wrap. action: A function with a signature similar to a resource responder method, taking the form ``func(req, resp, resource)``. action_args: Additiona positional agruments to pass to *action*. action_kwargs: Additional keyword arguments to pass to *action*. rcs||g|Ri|dSrr)reqresprr rr rrshimsz_wrap_with_after..shimNcsB|rt|||||fi||||gRidSr_merge_responder_argsselfr'r(r r action_args action_kwargsextra_argnamesr r*rrdo_afters z"_wrap_with_after..do_afterrr)r r r1r2responder_argnamesr4rr r1r2r3r r*rr"s   r"csRdtvrn fddt}|ddtfdd}|S)aExecute the given action function before a responder method. Args: responder: The responder method to wrap. action: A function with a similar signature to a resource responder method, taking the form ``func(req, resp, resource, params)``. action_args: Additiona positional agruments to pass to *action*. action_kwargs: Additional keyword arguments to pass to *action*. rcs|||g|Ri|dSrr)r'r(rparamsr rr)rrr*sz_wrap_with_before..shimr+NcsD|rt||||||gRi|||fi|dSrr,r.r0rr do_befores z$_wrap_with_before..do_beforer5)r r r1r2r6r9rr7rrs   rcCs*t|D]\}}||vr||||<qdS)aBMerge responder args into kwargs. The framework always passes extra args as keyword arguments. However, when the app calls the responder directly, it might use positional arguments instead, so we need to handle that case. This might happen, for example, when overriding a resource and calling a responder via super(). Args: args (tuple): Extra args passed into the responder kwargs (dict): Keyword args passed into the responder argnames (list): Extra argnames from the responder's signature, ordered as defined N) enumerate)r rargnamesiargnamerrrr-sr-) __doc__ functoolsrrfalconrfalcon.util.miscrr!r&r"rr-rrrrs   E8%'