We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Hook after params attribute is missing 
Hi

```python
def do_before(req, resp, resource, params):
	# here params is available

def do_after(req, resp, resource, params):
	# here params is not available

```

How can I access the params?


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `falcon/hooks.py`
Content:
```
1 # Copyright 2013 by Rackspace Hosting, Inc.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 #    http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 """Hook decorators."""
16 
17 from functools import wraps
18 from inspect import getmembers
19 from inspect import iscoroutinefunction
20 import re
21 
22 from falcon.constants import COMBINED_METHODS
23 from falcon.util.misc import get_argnames
24 from falcon.util.sync import _wrap_non_coroutine_unsafe
25 
26 
27 _DECORABLE_METHOD_NAME = re.compile(
28     r'^on_({})(_\w+)?$'.format('|'.join(method.lower() for method in COMBINED_METHODS))
29 )
30 
31 
32 def before(action, *args, is_async=False, **kwargs):
33     """Execute the given action function *before* the responder.
34 
35     The `params` argument that is passed to the hook
36     contains only the fields from the URI template path; it does not
37     include query string values.
38 
39     Hooks may inject extra params as needed. For example::
40 
41         def do_something(req, resp, resource, params):
42             try:
43                 params['id'] = int(params['id'])
44             except ValueError:
45                 raise falcon.HTTPBadRequest(title='Invalid ID',
46                                             description='ID was not valid.')
47 
48             params['answer'] = 42
49 
50     Args:
51         action (callable): A function of the form
52             ``func(req, resp, resource, params)``, where `resource` is a
53             reference to the resource class instance associated with the
54             request and `params` is a dict of URI template field names,
55             if any, that will be passed into the resource responder as
56             kwargs.
57 
58         *args: Any additional arguments will be passed to *action* in the
59             order given, immediately following the *req*, *resp*, *resource*,
60             and *params* arguments.
61 
62     Keyword Args:
63         is_async (bool): Set to ``True`` for ASGI apps to provide a hint that
64             the decorated responder is a coroutine function (i.e., that it
65             is defined with ``async def``) or that it returns an awaitable
66             coroutine object.
67 
68             Normally, when the function source is declared using ``async def``,
69             the resulting function object is flagged to indicate it returns a
70             coroutine when invoked, and this can be automatically detected.
71             However, it is possible to use a regular function to return an
72             awaitable coroutine object, in which case a hint is required to let
73             the framework know what to expect. Also, a hint is always required
74             when using a cythonized coroutine function, since Cython does not
75             flag them in a way that can be detected in advance, even when the
76             function is declared using ``async def``.
77 
78         **kwargs: Any additional keyword arguments will be passed through to
79             *action*.
80     """
81 
82     def _before(responder_or_resource):
83         if isinstance(responder_or_resource, type):
84             resource = responder_or_resource
85 
86             for responder_name, responder in getmembers(resource, callable):
87                 if _DECORABLE_METHOD_NAME.match(responder_name):
88                     # This pattern is necessary to capture the current value of
89                     # responder in the do_before_all closure; otherwise, they
90                     # will capture the same responder variable that is shared
91                     # between iterations of the for loop, above.
92                     def let(responder=responder):
93                         do_before_all = _wrap_with_before(
94                             responder, action, args, kwargs, is_async
95                         )
96 
97                         setattr(resource, responder_name, do_before_all)
98 
99                     let()
100 
101             return resource
102 
103         else:
104             responder = responder_or_resource
105             do_before_one = _wrap_with_before(responder, action, args, kwargs, is_async)
106 
107             return do_before_one
108 
109     return _before
110 
111 
112 def after(action, *args, is_async=False, **kwargs):
113     """Execute the given action function *after* the responder.
114 
115     Args:
116         action (callable): A function of the form
117             ``func(req, resp, resource)``, where `resource` is a
118             reference to the resource class instance associated with the
119             request
120 
121         *args: Any additional arguments will be passed to *action* in the
122             order given, immediately following the *req*, *resp*, *resource*,
123             and *params* arguments.
124 
125     Keyword Args:
126         is_async (bool): Set to ``True`` for ASGI apps to provide a hint that
127             the decorated responder is a coroutine function (i.e., that it
128             is defined with ``async def``) or that it returns an awaitable
129             coroutine object.
130 
131             Normally, when the function source is declared using ``async def``,
132             the resulting function object is flagged to indicate it returns a
133             coroutine when invoked, and this can be automatically detected.
134             However, it is possible to use a regular function to return an
135             awaitable coroutine object, in which case a hint is required to let
136             the framework know what to expect. Also, a hint is always required
137             when using a cythonized coroutine function, since Cython does not
138             flag them in a way that can be detected in advance, even when the
139             function is declared using ``async def``.
140 
141         **kwargs: Any additional keyword arguments will be passed through to
142             *action*.
143     """
144 
145     def _after(responder_or_resource):
146         if isinstance(responder_or_resource, type):
147             resource = responder_or_resource
148 
149             for responder_name, responder in getmembers(resource, callable):
150                 if _DECORABLE_METHOD_NAME.match(responder_name):
151 
152                     def let(responder=responder):
153                         do_after_all = _wrap_with_after(
154                             responder, action, args, kwargs, is_async
155                         )
156 
157                         setattr(resource, responder_name, do_after_all)
158 
159                     let()
160 
161             return resource
162 
163         else:
164             responder = responder_or_resource
165             do_after_one = _wrap_with_after(responder, action, args, kwargs, is_async)
166 
167             return do_after_one
168 
169     return _after
170 
171 
172 # -----------------------------------------------------------------------------
173 # Helpers
174 # -----------------------------------------------------------------------------
175 
176 
177 def _wrap_with_after(responder, action, action_args, action_kwargs, is_async):
178     """Execute the given action function after a responder method.
179 
180     Args:
181         responder: The responder method to wrap.
182         action: A function with a signature similar to a resource responder
183             method, taking the form ``func(req, resp, resource)``.
184         action_args: Additional positional agruments to pass to *action*.
185         action_kwargs: Additional keyword arguments to pass to *action*.
186         is_async: Set to ``True`` for cythonized responders that are
187             actually coroutine functions, since such responders can not
188             be auto-detected. A hint is also required for regular functions
189             that happen to return an awaitable coroutine object.
190     """
191 
192     responder_argnames = get_argnames(responder)
193     extra_argnames = responder_argnames[2:]  # Skip req, resp
194 
195     if is_async or iscoroutinefunction(responder):
196         # NOTE(kgriffs): I manually verified that the implicit "else" branch
197         #   is actually covered, but coverage isn't tracking it for
198         #   some reason.
199         if not is_async:  # pragma: nocover
200             action = _wrap_non_coroutine_unsafe(action)
201 
202         @wraps(responder)
203         async def do_after(self, req, resp, *args, **kwargs):
204             if args:
205                 _merge_responder_args(args, kwargs, extra_argnames)
206 
207             await responder(self, req, resp, **kwargs)
208             await action(req, resp, self, *action_args, **action_kwargs)
209 
210     else:
211 
212         @wraps(responder)
213         def do_after(self, req, resp, *args, **kwargs):
214             if args:
215                 _merge_responder_args(args, kwargs, extra_argnames)
216 
217             responder(self, req, resp, **kwargs)
218             action(req, resp, self, *action_args, **action_kwargs)
219 
220     return do_after
221 
222 
223 def _wrap_with_before(responder, action, action_args, action_kwargs, is_async):
224     """Execute the given action function before a responder method.
225 
226     Args:
227         responder: The responder method to wrap.
228         action: A function with a similar signature to a resource responder
229             method, taking the form ``func(req, resp, resource, params)``.
230         action_args: Additional positional agruments to pass to *action*.
231         action_kwargs: Additional keyword arguments to pass to *action*.
232         is_async: Set to ``True`` for cythonized responders that are
233             actually coroutine functions, since such responders can not
234             be auto-detected. A hint is also required for regular functions
235             that happen to return an awaitable coroutine object.
236     """
237 
238     responder_argnames = get_argnames(responder)
239     extra_argnames = responder_argnames[2:]  # Skip req, resp
240 
241     if is_async or iscoroutinefunction(responder):
242         # NOTE(kgriffs): I manually verified that the implicit "else" branch
243         #   is actually covered, but coverage isn't tracking it for
244         #   some reason.
245         if not is_async:  # pragma: nocover
246             action = _wrap_non_coroutine_unsafe(action)
247 
248         @wraps(responder)
249         async def do_before(self, req, resp, *args, **kwargs):
250             if args:
251                 _merge_responder_args(args, kwargs, extra_argnames)
252 
253             await action(req, resp, self, kwargs, *action_args, **action_kwargs)
254             await responder(self, req, resp, **kwargs)
255 
256     else:
257 
258         @wraps(responder)
259         def do_before(self, req, resp, *args, **kwargs):
260             if args:
261                 _merge_responder_args(args, kwargs, extra_argnames)
262 
263             action(req, resp, self, kwargs, *action_args, **action_kwargs)
264             responder(self, req, resp, **kwargs)
265 
266     return do_before
267 
268 
269 def _merge_responder_args(args, kwargs, argnames):
270     """Merge responder args into kwargs.
271 
272     The framework always passes extra args as keyword arguments.
273     However, when the app calls the responder directly, it might use
274     positional arguments instead, so we need to handle that case. This
275     might happen, for example, when overriding a resource and calling
276     a responder via super().
277 
278     Args:
279         args (tuple): Extra args passed into the responder
280         kwargs (dict): Keyword args passed into the responder
281         argnames (list): Extra argnames from the responder's
282             signature, ordered as defined
283     """
284 
285     # NOTE(kgriffs): Merge positional args into kwargs by matching
286     # them up to the responder's signature. To do that, we must
287     # find out the names of the positional arguments by matching
288     # them in the order of the arguments named in the responder's
289     # signature.
290     for i, argname in enumerate(argnames):
291         # NOTE(kgriffs): extra_argnames may contain keyword arguments,
292         # which wont be in the args list, and are already in the kwargs
293         # dict anyway, so detect and skip them.
294         if argname not in kwargs:
295             kwargs[argname] = args[i]
296
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/falcon/hooks.py b/falcon/hooks.py
--- a/falcon/hooks.py
+++ b/falcon/hooks.py
@@ -119,8 +119,8 @@
             request
 
         *args: Any additional arguments will be passed to *action* in the
-            order given, immediately following the *req*, *resp*, *resource*,
-            and *params* arguments.
+            order given, immediately following the *req*, *resp* and *resource*
+            arguments.
 
     Keyword Args:
         is_async (bool): Set to ``True`` for ASGI apps to provide a hint that

{"golden_diff": "diff --git a/falcon/hooks.py b/falcon/hooks.py\n--- a/falcon/hooks.py\n+++ b/falcon/hooks.py\n@@ -119,8 +119,8 @@\n             request\n \n         *args: Any additional arguments will be passed to *action* in the\n-            order given, immediately following the *req*, *resp*, *resource*,\n-            and *params* arguments.\n+            order given, immediately following the *req*, *resp* and *resource*\n+            arguments.\n \n     Keyword Args:\n         is_async (bool): Set to ``True`` for ASGI apps to provide a hint that\n", "issue": "Hook after params attribute is missing \nHi\r\n\r\n```python\r\ndef do_before(req, resp, resource, params):\r\n\t# here params is available\r\n\r\ndef do_after(req, resp, resource, params):\r\n\t# here params is not available\r\n\r\n```\r\n\r\nHow can I access the params?\r\n\n", "before_files": [{"content": "# Copyright 2013 by Rackspace Hosting, Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Hook decorators.\"\"\"\n\nfrom functools import wraps\nfrom inspect import getmembers\nfrom inspect import iscoroutinefunction\nimport re\n\nfrom falcon.constants import COMBINED_METHODS\nfrom falcon.util.misc import get_argnames\nfrom falcon.util.sync import _wrap_non_coroutine_unsafe\n\n\n_DECORABLE_METHOD_NAME = re.compile(\n    r'^on_({})(_\\w+)?$'.format('|'.join(method.lower() for method in COMBINED_METHODS))\n)\n\n\ndef before(action, *args, is_async=False, **kwargs):\n    \"\"\"Execute the given action function *before* the responder.\n\n    The `params` argument that is passed to the hook\n    contains only the fields from the URI template path; it does not\n    include query string values.\n\n    Hooks may inject extra params as needed. For example::\n\n        def do_something(req, resp, resource, params):\n            try:\n                params['id'] = int(params['id'])\n            except ValueError:\n                raise falcon.HTTPBadRequest(title='Invalid ID',\n                                            description='ID was not valid.')\n\n            params['answer'] = 42\n\n    Args:\n        action (callable): A function of the form\n            ``func(req, resp, resource, params)``, where `resource` is a\n            reference to the resource class instance associated with the\n            request and `params` is a dict of URI template field names,\n            if any, that will be passed into the resource responder as\n            kwargs.\n\n        *args: Any additional arguments will be passed to *action* in the\n            order given, immediately following the *req*, *resp*, *resource*,\n            and *params* arguments.\n\n    Keyword Args:\n        is_async (bool): Set to ``True`` for ASGI apps to provide a hint that\n            the decorated responder is a coroutine function (i.e., that it\n            is defined with ``async def``) or that it returns an awaitable\n            coroutine object.\n\n            Normally, when the function source is declared using ``async def``,\n            the resulting function object is flagged to indicate it returns a\n            coroutine when invoked, and this can be automatically detected.\n            However, it is possible to use a regular function to return an\n            awaitable coroutine object, in which case a hint is required to let\n            the framework know what to expect. Also, a hint is always required\n            when using a cythonized coroutine function, since Cython does not\n            flag them in a way that can be detected in advance, even when the\n            function is declared using ``async def``.\n\n        **kwargs: Any additional keyword arguments will be passed through to\n            *action*.\n    \"\"\"\n\n    def _before(responder_or_resource):\n        if isinstance(responder_or_resource, type):\n            resource = responder_or_resource\n\n            for responder_name, responder in getmembers(resource, callable):\n                if _DECORABLE_METHOD_NAME.match(responder_name):\n                    # This pattern is necessary to capture the current value of\n                    # responder in the do_before_all closure; otherwise, they\n                    # will capture the same responder variable that is shared\n                    # between iterations of the for loop, above.\n                    def let(responder=responder):\n                        do_before_all = _wrap_with_before(\n                            responder, action, args, kwargs, is_async\n                        )\n\n                        setattr(resource, responder_name, do_before_all)\n\n                    let()\n\n            return resource\n\n        else:\n            responder = responder_or_resource\n            do_before_one = _wrap_with_before(responder, action, args, kwargs, is_async)\n\n            return do_before_one\n\n    return _before\n\n\ndef after(action, *args, is_async=False, **kwargs):\n    \"\"\"Execute the given action function *after* the responder.\n\n    Args:\n        action (callable): A function of the form\n            ``func(req, resp, resource)``, where `resource` is a\n            reference to the resource class instance associated with the\n            request\n\n        *args: Any additional arguments will be passed to *action* in the\n            order given, immediately following the *req*, *resp*, *resource*,\n            and *params* arguments.\n\n    Keyword Args:\n        is_async (bool): Set to ``True`` for ASGI apps to provide a hint that\n            the decorated responder is a coroutine function (i.e., that it\n            is defined with ``async def``) or that it returns an awaitable\n            coroutine object.\n\n            Normally, when the function source is declared using ``async def``,\n            the resulting function object is flagged to indicate it returns a\n            coroutine when invoked, and this can be automatically detected.\n            However, it is possible to use a regular function to return an\n            awaitable coroutine object, in which case a hint is required to let\n            the framework know what to expect. Also, a hint is always required\n            when using a cythonized coroutine function, since Cython does not\n            flag them in a way that can be detected in advance, even when the\n            function is declared using ``async def``.\n\n        **kwargs: Any additional keyword arguments will be passed through to\n            *action*.\n    \"\"\"\n\n    def _after(responder_or_resource):\n        if isinstance(responder_or_resource, type):\n            resource = responder_or_resource\n\n            for responder_name, responder in getmembers(resource, callable):\n                if _DECORABLE_METHOD_NAME.match(responder_name):\n\n                    def let(responder=responder):\n                        do_after_all = _wrap_with_after(\n                            responder, action, args, kwargs, is_async\n                        )\n\n                        setattr(resource, responder_name, do_after_all)\n\n                    let()\n\n            return resource\n\n        else:\n            responder = responder_or_resource\n            do_after_one = _wrap_with_after(responder, action, args, kwargs, is_async)\n\n            return do_after_one\n\n    return _after\n\n\n# -----------------------------------------------------------------------------\n# Helpers\n# -----------------------------------------------------------------------------\n\n\ndef _wrap_with_after(responder, action, action_args, action_kwargs, is_async):\n    \"\"\"Execute the given action function after a responder method.\n\n    Args:\n        responder: The responder method to wrap.\n        action: A function with a signature similar to a resource responder\n            method, taking the form ``func(req, resp, resource)``.\n        action_args: Additional positional agruments to pass to *action*.\n        action_kwargs: Additional keyword arguments to pass to *action*.\n        is_async: Set to ``True`` for cythonized responders that are\n            actually coroutine functions, since such responders can not\n            be auto-detected. A hint is also required for regular functions\n            that happen to return an awaitable coroutine object.\n    \"\"\"\n\n    responder_argnames = get_argnames(responder)\n    extra_argnames = responder_argnames[2:]  # Skip req, resp\n\n    if is_async or iscoroutinefunction(responder):\n        # NOTE(kgriffs): I manually verified that the implicit \"else\" branch\n        #   is actually covered, but coverage isn't tracking it for\n        #   some reason.\n        if not is_async:  # pragma: nocover\n            action = _wrap_non_coroutine_unsafe(action)\n\n        @wraps(responder)\n        async def do_after(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            await responder(self, req, resp, **kwargs)\n            await action(req, resp, self, *action_args, **action_kwargs)\n\n    else:\n\n        @wraps(responder)\n        def do_after(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            responder(self, req, resp, **kwargs)\n            action(req, resp, self, *action_args, **action_kwargs)\n\n    return do_after\n\n\ndef _wrap_with_before(responder, action, action_args, action_kwargs, is_async):\n    \"\"\"Execute the given action function before a responder method.\n\n    Args:\n        responder: The responder method to wrap.\n        action: A function with a similar signature to a resource responder\n            method, taking the form ``func(req, resp, resource, params)``.\n        action_args: Additional positional agruments to pass to *action*.\n        action_kwargs: Additional keyword arguments to pass to *action*.\n        is_async: Set to ``True`` for cythonized responders that are\n            actually coroutine functions, since such responders can not\n            be auto-detected. A hint is also required for regular functions\n            that happen to return an awaitable coroutine object.\n    \"\"\"\n\n    responder_argnames = get_argnames(responder)\n    extra_argnames = responder_argnames[2:]  # Skip req, resp\n\n    if is_async or iscoroutinefunction(responder):\n        # NOTE(kgriffs): I manually verified that the implicit \"else\" branch\n        #   is actually covered, but coverage isn't tracking it for\n        #   some reason.\n        if not is_async:  # pragma: nocover\n            action = _wrap_non_coroutine_unsafe(action)\n\n        @wraps(responder)\n        async def do_before(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            await action(req, resp, self, kwargs, *action_args, **action_kwargs)\n            await responder(self, req, resp, **kwargs)\n\n    else:\n\n        @wraps(responder)\n        def do_before(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            action(req, resp, self, kwargs, *action_args, **action_kwargs)\n            responder(self, req, resp, **kwargs)\n\n    return do_before\n\n\ndef _merge_responder_args(args, kwargs, argnames):\n    \"\"\"Merge responder args into kwargs.\n\n    The framework always passes extra args as keyword arguments.\n    However, when the app calls the responder directly, it might use\n    positional arguments instead, so we need to handle that case. This\n    might happen, for example, when overriding a resource and calling\n    a responder via super().\n\n    Args:\n        args (tuple): Extra args passed into the responder\n        kwargs (dict): Keyword args passed into the responder\n        argnames (list): Extra argnames from the responder's\n            signature, ordered as defined\n    \"\"\"\n\n    # NOTE(kgriffs): Merge positional args into kwargs by matching\n    # them up to the responder's signature. To do that, we must\n    # find out the names of the positional arguments by matching\n    # them in the order of the arguments named in the responder's\n    # signature.\n    for i, argname in enumerate(argnames):\n        # NOTE(kgriffs): extra_argnames may contain keyword arguments,\n        # which wont be in the args list, and are already in the kwargs\n        # dict anyway, so detect and skip them.\n        if argname not in kwargs:\n            kwargs[argname] = args[i]\n", "path": "falcon/hooks.py"}], "after_files": [{"content": "# Copyright 2013 by Rackspace Hosting, Inc.\n#\n# Licensed under the Apache License, Version 2.0 (the \"License\");\n# you may not use this file except in compliance with the License.\n# You may obtain a copy of the License at\n#\n#    http://www.apache.org/licenses/LICENSE-2.0\n#\n# Unless required by applicable law or agreed to in writing, software\n# distributed under the License is distributed on an \"AS IS\" BASIS,\n# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n# See the License for the specific language governing permissions and\n# limitations under the License.\n\n\"\"\"Hook decorators.\"\"\"\n\nfrom functools import wraps\nfrom inspect import getmembers\nfrom inspect import iscoroutinefunction\nimport re\n\nfrom falcon.constants import COMBINED_METHODS\nfrom falcon.util.misc import get_argnames\nfrom falcon.util.sync import _wrap_non_coroutine_unsafe\n\n\n_DECORABLE_METHOD_NAME = re.compile(\n    r'^on_({})(_\\w+)?$'.format('|'.join(method.lower() for method in COMBINED_METHODS))\n)\n\n\ndef before(action, *args, is_async=False, **kwargs):\n    \"\"\"Execute the given action function *before* the responder.\n\n    The `params` argument that is passed to the hook\n    contains only the fields from the URI template path; it does not\n    include query string values.\n\n    Hooks may inject extra params as needed. For example::\n\n        def do_something(req, resp, resource, params):\n            try:\n                params['id'] = int(params['id'])\n            except ValueError:\n                raise falcon.HTTPBadRequest(title='Invalid ID',\n                                            description='ID was not valid.')\n\n            params['answer'] = 42\n\n    Args:\n        action (callable): A function of the form\n            ``func(req, resp, resource, params)``, where `resource` is a\n            reference to the resource class instance associated with the\n            request and `params` is a dict of URI template field names,\n            if any, that will be passed into the resource responder as\n            kwargs.\n\n        *args: Any additional arguments will be passed to *action* in the\n            order given, immediately following the *req*, *resp*, *resource*,\n            and *params* arguments.\n\n    Keyword Args:\n        is_async (bool): Set to ``True`` for ASGI apps to provide a hint that\n            the decorated responder is a coroutine function (i.e., that it\n            is defined with ``async def``) or that it returns an awaitable\n            coroutine object.\n\n            Normally, when the function source is declared using ``async def``,\n            the resulting function object is flagged to indicate it returns a\n            coroutine when invoked, and this can be automatically detected.\n            However, it is possible to use a regular function to return an\n            awaitable coroutine object, in which case a hint is required to let\n            the framework know what to expect. Also, a hint is always required\n            when using a cythonized coroutine function, since Cython does not\n            flag them in a way that can be detected in advance, even when the\n            function is declared using ``async def``.\n\n        **kwargs: Any additional keyword arguments will be passed through to\n            *action*.\n    \"\"\"\n\n    def _before(responder_or_resource):\n        if isinstance(responder_or_resource, type):\n            resource = responder_or_resource\n\n            for responder_name, responder in getmembers(resource, callable):\n                if _DECORABLE_METHOD_NAME.match(responder_name):\n                    # This pattern is necessary to capture the current value of\n                    # responder in the do_before_all closure; otherwise, they\n                    # will capture the same responder variable that is shared\n                    # between iterations of the for loop, above.\n                    def let(responder=responder):\n                        do_before_all = _wrap_with_before(\n                            responder, action, args, kwargs, is_async\n                        )\n\n                        setattr(resource, responder_name, do_before_all)\n\n                    let()\n\n            return resource\n\n        else:\n            responder = responder_or_resource\n            do_before_one = _wrap_with_before(responder, action, args, kwargs, is_async)\n\n            return do_before_one\n\n    return _before\n\n\ndef after(action, *args, is_async=False, **kwargs):\n    \"\"\"Execute the given action function *after* the responder.\n\n    Args:\n        action (callable): A function of the form\n            ``func(req, resp, resource)``, where `resource` is a\n            reference to the resource class instance associated with the\n            request\n\n        *args: Any additional arguments will be passed to *action* in the\n            order given, immediately following the *req*, *resp* and *resource*\n            arguments.\n\n    Keyword Args:\n        is_async (bool): Set to ``True`` for ASGI apps to provide a hint that\n            the decorated responder is a coroutine function (i.e., that it\n            is defined with ``async def``) or that it returns an awaitable\n            coroutine object.\n\n            Normally, when the function source is declared using ``async def``,\n            the resulting function object is flagged to indicate it returns a\n            coroutine when invoked, and this can be automatically detected.\n            However, it is possible to use a regular function to return an\n            awaitable coroutine object, in which case a hint is required to let\n            the framework know what to expect. Also, a hint is always required\n            when using a cythonized coroutine function, since Cython does not\n            flag them in a way that can be detected in advance, even when the\n            function is declared using ``async def``.\n\n        **kwargs: Any additional keyword arguments will be passed through to\n            *action*.\n    \"\"\"\n\n    def _after(responder_or_resource):\n        if isinstance(responder_or_resource, type):\n            resource = responder_or_resource\n\n            for responder_name, responder in getmembers(resource, callable):\n                if _DECORABLE_METHOD_NAME.match(responder_name):\n\n                    def let(responder=responder):\n                        do_after_all = _wrap_with_after(\n                            responder, action, args, kwargs, is_async\n                        )\n\n                        setattr(resource, responder_name, do_after_all)\n\n                    let()\n\n            return resource\n\n        else:\n            responder = responder_or_resource\n            do_after_one = _wrap_with_after(responder, action, args, kwargs, is_async)\n\n            return do_after_one\n\n    return _after\n\n\n# -----------------------------------------------------------------------------\n# Helpers\n# -----------------------------------------------------------------------------\n\n\ndef _wrap_with_after(responder, action, action_args, action_kwargs, is_async):\n    \"\"\"Execute the given action function after a responder method.\n\n    Args:\n        responder: The responder method to wrap.\n        action: A function with a signature similar to a resource responder\n            method, taking the form ``func(req, resp, resource)``.\n        action_args: Additional positional agruments to pass to *action*.\n        action_kwargs: Additional keyword arguments to pass to *action*.\n        is_async: Set to ``True`` for cythonized responders that are\n            actually coroutine functions, since such responders can not\n            be auto-detected. A hint is also required for regular functions\n            that happen to return an awaitable coroutine object.\n    \"\"\"\n\n    responder_argnames = get_argnames(responder)\n    extra_argnames = responder_argnames[2:]  # Skip req, resp\n\n    if is_async or iscoroutinefunction(responder):\n        # NOTE(kgriffs): I manually verified that the implicit \"else\" branch\n        #   is actually covered, but coverage isn't tracking it for\n        #   some reason.\n        if not is_async:  # pragma: nocover\n            action = _wrap_non_coroutine_unsafe(action)\n\n        @wraps(responder)\n        async def do_after(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            await responder(self, req, resp, **kwargs)\n            await action(req, resp, self, *action_args, **action_kwargs)\n\n    else:\n\n        @wraps(responder)\n        def do_after(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            responder(self, req, resp, **kwargs)\n            action(req, resp, self, *action_args, **action_kwargs)\n\n    return do_after\n\n\ndef _wrap_with_before(responder, action, action_args, action_kwargs, is_async):\n    \"\"\"Execute the given action function before a responder method.\n\n    Args:\n        responder: The responder method to wrap.\n        action: A function with a similar signature to a resource responder\n            method, taking the form ``func(req, resp, resource, params)``.\n        action_args: Additional positional agruments to pass to *action*.\n        action_kwargs: Additional keyword arguments to pass to *action*.\n        is_async: Set to ``True`` for cythonized responders that are\n            actually coroutine functions, since such responders can not\n            be auto-detected. A hint is also required for regular functions\n            that happen to return an awaitable coroutine object.\n    \"\"\"\n\n    responder_argnames = get_argnames(responder)\n    extra_argnames = responder_argnames[2:]  # Skip req, resp\n\n    if is_async or iscoroutinefunction(responder):\n        # NOTE(kgriffs): I manually verified that the implicit \"else\" branch\n        #   is actually covered, but coverage isn't tracking it for\n        #   some reason.\n        if not is_async:  # pragma: nocover\n            action = _wrap_non_coroutine_unsafe(action)\n\n        @wraps(responder)\n        async def do_before(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            await action(req, resp, self, kwargs, *action_args, **action_kwargs)\n            await responder(self, req, resp, **kwargs)\n\n    else:\n\n        @wraps(responder)\n        def do_before(self, req, resp, *args, **kwargs):\n            if args:\n                _merge_responder_args(args, kwargs, extra_argnames)\n\n            action(req, resp, self, kwargs, *action_args, **action_kwargs)\n            responder(self, req, resp, **kwargs)\n\n    return do_before\n\n\ndef _merge_responder_args(args, kwargs, argnames):\n    \"\"\"Merge responder args into kwargs.\n\n    The framework always passes extra args as keyword arguments.\n    However, when the app calls the responder directly, it might use\n    positional arguments instead, so we need to handle that case. This\n    might happen, for example, when overriding a resource and calling\n    a responder via super().\n\n    Args:\n        args (tuple): Extra args passed into the responder\n        kwargs (dict): Keyword args passed into the responder\n        argnames (list): Extra argnames from the responder's\n            signature, ordered as defined\n    \"\"\"\n\n    # NOTE(kgriffs): Merge positional args into kwargs by matching\n    # them up to the responder's signature. To do that, we must\n    # find out the names of the positional arguments by matching\n    # them in the order of the arguments named in the responder's\n    # signature.\n    for i, argname in enumerate(argnames):\n        # NOTE(kgriffs): extra_argnames may contain keyword arguments,\n        # which wont be in the args list, and are already in the kwargs\n        # dict anyway, so detect and skip them.\n        if argname not in kwargs:\n            kwargs[argname] = args[i]\n", "path": "falcon/hooks.py"}]}