コード例 #1
0
 def call_view(self, *args, **kwargs):
     view_fn = self.func
     config = flask.current_app.config
     parser = config.get('APISPEC_WEBARGS_PARSER', flaskparser.parser)
     # Delegate webargs.use_args annotations
     annotation = utils.resolve_annotations(self.func, 'args', self.instance)
     if annotation.apply is not False:
         for option in annotation.options:
             schema = utils.resolve_schema(option['argmap'], request=flask.request)
             view_fn = parser.use_args(schema, **option['kwargs'])(view_fn)
     # Delegate webargs.use_kwargs annotations
     annotation = utils.resolve_annotations(self.func, 'kwargs', self.instance)
     if annotation.apply is not False:
         for option in annotation.options:
             schema = utils.resolve_schema(option['argmap'], request=flask.request)
             if getattr(schema, 'many', False):
                 raise Exception("@use_kwargs cannot be used with a with a "
                                 "'many=True' schema, as it must deserialize "
                                 "to a dict")
             elif isinstance(schema, ma.Schema):
                 # Spy the post_load to provide a more informative error
                 # if it doesn't return a Mapping
                 post_load_fns = post_load_fn_names(schema)
                 for post_load_fn_name in post_load_fns:
                     spy_post_load(schema, post_load_fn_name)
             view_fn = parser.use_kwargs(schema, **option['kwargs'])(view_fn)
     return view_fn(*args, **kwargs)
コード例 #2
0
 def call_view(self, *args, **kwargs):
     config = flask.current_app.config
     parser = config.get('APISPEC_WEBARGS_PARSER', fixed_parser)
     annotation = utils.resolve_annotations(self.func, 'args',
                                            self.instance)
     if annotation.apply is not False:
         for option in annotation.options:
             schema = utils.resolve_schema(option['args'],
                                           request=flask.request)
             parsed = parser.parse(schema,
                                   locations=option['kwargs']['locations'])
             # if not isinstance(parsed, dict):
             #     parsed = dict(obj=parsed)
             # print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ args", repr(args))
             # print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ kwargs", repr(kwargs))
             # print("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ parsed", repr(parsed))
             if isinstance(parsed, list):
                 # parsed = {"obj": parsed }
                 # if getattr(schema, 'many', False):
                 args += tuple(parsed)
             elif isinstance(parsed, dict):
                 kwargs.update(parsed)
             else:
                 args += (parsed, )
     return self.func(*args, **kwargs)
コード例 #3
0
 def marshal_result(self, unpacked, status_code):
     config = flask.current_app.config
     format_response = config.get('APISPEC_FORMAT_RESPONSE', flask.jsonify) or identity
     annotation = utils.resolve_annotations(self.func, 'schemas', self.instance)
     schemas = utils.merge_recursive(annotation.options)
     schema = schemas.get(status_code, schemas.get('default'))
     if schema and annotation.apply is not False:
         schema = utils.resolve_schema(schema['schema'], request=flask.request)
         dumped = schema.dump(unpacked[0])
         output = dumped.data if MARSHMALLOW_VERSION_INFO[0] < 3 else dumped
     else:
         output = unpacked[0]
     return format_output((format_response(output), ) + unpacked[1:])
コード例 #4
0
ファイル: wrapper.py プロジェクト: levensailor/pip4lambda
 def call_view(self, *args, **kwargs):
     config = flask.current_app.config
     parser = config.get('APISPEC_WEBARGS_PARSER', flaskparser.parser)
     annotation = utils.resolve_annotations(self.func, 'args',
                                            self.instance)
     if annotation.apply is not False:
         for option in annotation.options:
             schema = utils.resolve_schema(option['args'],
                                           request=flask.request)
             parsed = parser.parse(schema,
                                   locations=option['kwargs']['locations'])
             if getattr(schema, 'many', False):
                 args += tuple(parsed)
             else:
                 kwargs.update(parsed)
     return self.func(*args, **kwargs)