prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Pyramid parser use_kwargs throws exception when used
  The following code using the pyramid parser throws an exception:
  
  ``` python
  @parser.use_kwargs({'myvalue': Arg(int)})
  def baz(request, myvalue):
      return {'myvalue': myvalue}
  ```
  
  The exception:
  
  ```
          kwargs['as_kwargs'] = True
  >       return self.use_args(*args, **kwargs)
  E       TypeError: use_args() got an unexpected keyword argument 'as_kwargs'
  ```
  
  Pyramid parser use_kwargs throws exception when used
  The following code using the pyramid parser throws an exception:
  
  ``` python
  @parser.use_kwargs({'myvalue': Arg(int)})
  def baz(request, myvalue):
      return {'myvalue': myvalue}
  ```
  
  The exception:
  
  ```
          kwargs['as_kwargs'] = True
  >       return self.use_args(*args, **kwargs)
  E       TypeError: use_args() got an unexpected keyword argument 'as_kwargs'
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `webargs/pyramidparser.py`
  Content:
  ```
  1 # -*- coding: utf-8 -*-
  2 """Pyramid request argument parsing.
  3 
  4 Example usage: ::
  5 
  6     from wsgiref.simple_server import make_server
  7     from pyramid.config import Configurator
  8     from pyramid.response import Response
  9     from webargs import Arg
  10     from webargs.pyramidparser import use_args
  11 
  12     hello_args = {
  13         'name': Arg(str, default='World')
  14     }
  15 
  16     @use_args(hello_args)
  17     def hello_world(request, args):
  18         return Response('Hello ' + args['name'])
  19 
  20     if __name__ == '__main__':
  21         config = Configurator()
  22         config.add_route('hello', '/')
  23         config.add_view(hello_world, route_name='hello')
  24         app = config.make_wsgi_app()
  25         server = make_server('0.0.0.0', 6543, app)
  26         server.serve_forever()
  27 """
  28 import functools
  29 import logging
  30 
  31 from webob.multidict import MultiDict
  32 from pyramid.httpexceptions import exception_response
  33 
  34 from webargs import core
  35 from webargs.core import text_type
  36 
  37 logger = logging.getLogger(__name__)
  38 
  39 class PyramidParser(core.Parser):
  40     """Pyramid request argument parser."""
  41 
  42     def parse_querystring(self, req, name, arg):
  43         """Pull a querystring value from the request."""
  44         return core.get_value(req.GET, name, arg.multiple)
  45 
  46     def parse_form(self, req, name, arg):
  47         """Pull a form value from the request."""
  48         return core.get_value(req.POST, name, arg.multiple)
  49 
  50     def parse_json(self, req, name, arg):
  51         """Pull a json value from the request."""
  52         try:
  53             json_data = req.json_body
  54         except ValueError:
  55             return core.Missing
  56 
  57         return core.get_value(json_data, name, arg.multiple)
  58 
  59     def parse_cookies(self, req, name, arg):
  60         """Pull the value from the cookiejar."""
  61         return core.get_value(req.cookies, name, arg.multiple)
  62 
  63     def parse_headers(self, req, name, arg):
  64         """Pull a value from the header data."""
  65         return core.get_value(req.headers, name, arg.multiple)
  66 
  67     def parse_files(self, req, name, arg):
  68         """Pull a file from the request."""
  69         files = ((k, v) for k, v in req.POST.items() if hasattr(v, 'file'))
  70         return core.get_value(MultiDict(files), name, arg.multiple)
  71 
  72     def handle_error(self, error):
  73         """Handles errors during parsing. Aborts the current HTTP request and
  74         responds with a 400 error.
  75         """
  76         logger.error(error)
  77         status_code = getattr(error, 'status_code', 400)
  78         data = getattr(error, 'data', {})
  79         raise exception_response(status_code, detail=text_type(error), **data)
  80 
  81     def use_args(self, argmap, req=None, locations=core.Parser.DEFAULT_LOCATIONS,
  82                  validate=None):
  83         """Decorator that injects parsed arguments into a view callable.
  84         Supports the *Class-based View* pattern where `request` is saved as an instance
  85         attribute on a view class.
  86 
  87         :param dict argmap: Dictionary of argument_name:Arg object pairs.
  88         :param req: The request object to parse
  89         :param tuple locations: Where on the request to search for values.
  90         :param callable validate:
  91             Validation function that receives the dictionary of parsed arguments.
  92             If the function returns ``False``, the parser will raise a
  93             :exc:`ValidationError`.
  94         """
  95         def decorator(func):
  96             @functools.wraps(func)
  97             def wrapper(obj, *args, **kwargs):
  98                 # The first argument is either `self` or `request`
  99                 try:  # get self.request
  100                     request = obj.request
  101                 except AttributeError:  # first arg is request
  102                     request = obj
  103                 parsed_args = self.parse(argmap, req=request, locations=locations,
  104                                          validate=None)
  105                 return func(obj, parsed_args, *args, **kwargs)
  106             return wrapper
  107         return decorator
  108 
  109 parser = PyramidParser()
  110 use_args = parser.use_args
  111 use_kwargs = parser.use_kwargs
  112
  ```
  --- 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()
  
  ```
  
golden_diff: diff --git a/webargs/pyramidparser.py b/webargs/pyramidparser.py
  --- a/webargs/pyramidparser.py
  +++ b/webargs/pyramidparser.py
  @@ -79,7 +79,7 @@
           raise exception_response(status_code, detail=text_type(error), **data)
   
       def use_args(self, argmap, req=None, locations=core.Parser.DEFAULT_LOCATIONS,
  -                 validate=None):
  +                 as_kwargs=False, validate=None):
           """Decorator that injects parsed arguments into a view callable.
           Supports the *Class-based View* pattern where `request` is saved as an instance
           attribute on a view class.
  @@ -102,7 +102,11 @@
                       request = obj
                   parsed_args = self.parse(argmap, req=request, locations=locations,
                                            validate=None)
  -                return func(obj, parsed_args, *args, **kwargs)
  +                if as_kwargs:
  +                    kwargs.update(parsed_args)
  +                    return func(obj, *args, **kwargs)
  +                else:
  +                    return func(obj, parsed_args, *args, **kwargs)
               return wrapper
           return decorator
  
verification_info: {"golden_diff": "diff --git a/webargs/pyramidparser.py b/webargs/pyramidparser.py\n--- a/webargs/pyramidparser.py\n+++ b/webargs/pyramidparser.py\n@@ -79,7 +79,7 @@\n         raise exception_response(status_code, detail=text_type(error), **data)\n \n     def use_args(self, argmap, req=None, locations=core.Parser.DEFAULT_LOCATIONS,\n-                 validate=None):\n+                 as_kwargs=False, validate=None):\n         \"\"\"Decorator that injects parsed arguments into a view callable.\n         Supports the *Class-based View* pattern where `request` is saved as an instance\n         attribute on a view class.\n@@ -102,7 +102,11 @@\n                     request = obj\n                 parsed_args = self.parse(argmap, req=request, locations=locations,\n                                          validate=None)\n-                return func(obj, parsed_args, *args, **kwargs)\n+                if as_kwargs:\n+                    kwargs.update(parsed_args)\n+                    return func(obj, *args, **kwargs)\n+                else:\n+                    return func(obj, parsed_args, *args, **kwargs)\n             return wrapper\n         return decorator\n", "issue": "Pyramid parser use_kwargs throws exception when used\nThe following code using the pyramid parser throws an exception:\n\n``` python\n@parser.use_kwargs({'myvalue': Arg(int)})\ndef baz(request, myvalue):\n    return {'myvalue': myvalue}\n```\n\nThe exception:\n\n```\n        kwargs['as_kwargs'] = True\n>       return self.use_args(*args, **kwargs)\nE       TypeError: use_args() got an unexpected keyword argument 'as_kwargs'\n```\n\nPyramid parser use_kwargs throws exception when used\nThe following code using the pyramid parser throws an exception:\n\n``` python\n@parser.use_kwargs({'myvalue': Arg(int)})\ndef baz(request, myvalue):\n    return {'myvalue': myvalue}\n```\n\nThe exception:\n\n```\n        kwargs['as_kwargs'] = True\n>       return self.use_args(*args, **kwargs)\nE       TypeError: use_args() got an unexpected keyword argument 'as_kwargs'\n```\n\n", "before_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Pyramid request argument parsing.\n\nExample usage: ::\n\n    from wsgiref.simple_server import make_server\n    from pyramid.config import Configurator\n    from pyramid.response import Response\n    from webargs import Arg\n    from webargs.pyramidparser import use_args\n\n    hello_args = {\n        'name': Arg(str, default='World')\n    }\n\n    @use_args(hello_args)\n    def hello_world(request, args):\n        return Response('Hello ' + args['name'])\n\n    if __name__ == '__main__':\n        config = Configurator()\n        config.add_route('hello', '/')\n        config.add_view(hello_world, route_name='hello')\n        app = config.make_wsgi_app()\n        server = make_server('0.0.0.0', 6543, app)\n        server.serve_forever()\n\"\"\"\nimport functools\nimport logging\n\nfrom webob.multidict import MultiDict\nfrom pyramid.httpexceptions import exception_response\n\nfrom webargs import core\nfrom webargs.core import text_type\n\nlogger = logging.getLogger(__name__)\n\nclass PyramidParser(core.Parser):\n    \"\"\"Pyramid request argument parser.\"\"\"\n\n    def parse_querystring(self, req, name, arg):\n        \"\"\"Pull a querystring value from the request.\"\"\"\n        return core.get_value(req.GET, name, arg.multiple)\n\n    def parse_form(self, req, name, arg):\n        \"\"\"Pull a form value from the request.\"\"\"\n        return core.get_value(req.POST, name, arg.multiple)\n\n    def parse_json(self, req, name, arg):\n        \"\"\"Pull a json value from the request.\"\"\"\n        try:\n            json_data = req.json_body\n        except ValueError:\n            return core.Missing\n\n        return core.get_value(json_data, name, arg.multiple)\n\n    def parse_cookies(self, req, name, arg):\n        \"\"\"Pull the value from the cookiejar.\"\"\"\n        return core.get_value(req.cookies, name, arg.multiple)\n\n    def parse_headers(self, req, name, arg):\n        \"\"\"Pull a value from the header data.\"\"\"\n        return core.get_value(req.headers, name, arg.multiple)\n\n    def parse_files(self, req, name, arg):\n        \"\"\"Pull a file from the request.\"\"\"\n        files = ((k, v) for k, v in req.POST.items() if hasattr(v, 'file'))\n        return core.get_value(MultiDict(files), name, arg.multiple)\n\n    def handle_error(self, error):\n        \"\"\"Handles errors during parsing. Aborts the current HTTP request and\n        responds with a 400 error.\n        \"\"\"\n        logger.error(error)\n        status_code = getattr(error, 'status_code', 400)\n        data = getattr(error, 'data', {})\n        raise exception_response(status_code, detail=text_type(error), **data)\n\n    def use_args(self, argmap, req=None, locations=core.Parser.DEFAULT_LOCATIONS,\n                 validate=None):\n        \"\"\"Decorator that injects parsed arguments into a view callable.\n        Supports the *Class-based View* pattern where `request` is saved as an instance\n        attribute on a view class.\n\n        :param dict argmap: Dictionary of argument_name:Arg object pairs.\n        :param req: The request object to parse\n        :param tuple locations: Where on the request to search for values.\n        :param callable validate:\n            Validation function that receives the dictionary of parsed arguments.\n            If the function returns ``False``, the parser will raise a\n            :exc:`ValidationError`.\n        \"\"\"\n        def decorator(func):\n            @functools.wraps(func)\n            def wrapper(obj, *args, **kwargs):\n                # The first argument is either `self` or `request`\n                try:  # get self.request\n                    request = obj.request\n                except AttributeError:  # first arg is request\n                    request = obj\n                parsed_args = self.parse(argmap, req=request, locations=locations,\n                                         validate=None)\n                return func(obj, parsed_args, *args, **kwargs)\n            return wrapper\n        return decorator\n\nparser = PyramidParser()\nuse_args = parser.use_args\nuse_kwargs = parser.use_kwargs\n", "path": "webargs/pyramidparser.py"}], "after_files": [{"content": "# -*- coding: utf-8 -*-\n\"\"\"Pyramid request argument parsing.\n\nExample usage: ::\n\n    from wsgiref.simple_server import make_server\n    from pyramid.config import Configurator\n    from pyramid.response import Response\n    from webargs import Arg\n    from webargs.pyramidparser import use_args\n\n    hello_args = {\n        'name': Arg(str, default='World')\n    }\n\n    @use_args(hello_args)\n    def hello_world(request, args):\n        return Response('Hello ' + args['name'])\n\n    if __name__ == '__main__':\n        config = Configurator()\n        config.add_route('hello', '/')\n        config.add_view(hello_world, route_name='hello')\n        app = config.make_wsgi_app()\n        server = make_server('0.0.0.0', 6543, app)\n        server.serve_forever()\n\"\"\"\nimport functools\nimport logging\n\nfrom webob.multidict import MultiDict\nfrom pyramid.httpexceptions import exception_response\n\nfrom webargs import core\nfrom webargs.core import text_type\n\nlogger = logging.getLogger(__name__)\n\nclass PyramidParser(core.Parser):\n    \"\"\"Pyramid request argument parser.\"\"\"\n\n    def parse_querystring(self, req, name, arg):\n        \"\"\"Pull a querystring value from the request.\"\"\"\n        return core.get_value(req.GET, name, arg.multiple)\n\n    def parse_form(self, req, name, arg):\n        \"\"\"Pull a form value from the request.\"\"\"\n        return core.get_value(req.POST, name, arg.multiple)\n\n    def parse_json(self, req, name, arg):\n        \"\"\"Pull a json value from the request.\"\"\"\n        try:\n            json_data = req.json_body\n        except ValueError:\n            return core.Missing\n\n        return core.get_value(json_data, name, arg.multiple)\n\n    def parse_cookies(self, req, name, arg):\n        \"\"\"Pull the value from the cookiejar.\"\"\"\n        return core.get_value(req.cookies, name, arg.multiple)\n\n    def parse_headers(self, req, name, arg):\n        \"\"\"Pull a value from the header data.\"\"\"\n        return core.get_value(req.headers, name, arg.multiple)\n\n    def parse_files(self, req, name, arg):\n        \"\"\"Pull a file from the request.\"\"\"\n        files = ((k, v) for k, v in req.POST.items() if hasattr(v, 'file'))\n        return core.get_value(MultiDict(files), name, arg.multiple)\n\n    def handle_error(self, error):\n        \"\"\"Handles errors during parsing. Aborts the current HTTP request and\n        responds with a 400 error.\n        \"\"\"\n        logger.error(error)\n        status_code = getattr(error, 'status_code', 400)\n        data = getattr(error, 'data', {})\n        raise exception_response(status_code, detail=text_type(error), **data)\n\n    def use_args(self, argmap, req=None, locations=core.Parser.DEFAULT_LOCATIONS,\n                 as_kwargs=False, validate=None):\n        \"\"\"Decorator that injects parsed arguments into a view callable.\n        Supports the *Class-based View* pattern where `request` is saved as an instance\n        attribute on a view class.\n\n        :param dict argmap: Dictionary of argument_name:Arg object pairs.\n        :param req: The request object to parse\n        :param tuple locations: Where on the request to search for values.\n        :param callable validate:\n            Validation function that receives the dictionary of parsed arguments.\n            If the function returns ``False``, the parser will raise a\n            :exc:`ValidationError`.\n        \"\"\"\n        def decorator(func):\n            @functools.wraps(func)\n            def wrapper(obj, *args, **kwargs):\n                # The first argument is either `self` or `request`\n                try:  # get self.request\n                    request = obj.request\n                except AttributeError:  # first arg is request\n                    request = obj\n                parsed_args = self.parse(argmap, req=request, locations=locations,\n                                         validate=None)\n                if as_kwargs:\n                    kwargs.update(parsed_args)\n                    return func(obj, *args, **kwargs)\n                else:\n                    return func(obj, parsed_args, *args, **kwargs)\n            return wrapper\n        return decorator\n\nparser = PyramidParser()\nuse_args = parser.use_args\nuse_kwargs = parser.use_kwargs\n", "path": "webargs/pyramidparser.py"}]}