def parse_form(self, req, name, field): """Pull a form value from the request.""" try: return core.get_value(req.form, name, field) except AttributeError: pass return core.missing
def parse_form(self, req, name, arg): """Pull a form value from the request.""" try: return core.get_value(req.form, name, arg.multiple) except AttributeError: pass return core.Missing
def parse_json(self, req, name, arg): """Pull a json value from the request.""" try: json_data = webapp2_extras.json.decode(req.body) return core.get_value(json_data, name, arg.multiple) except ValueError: return core.Missing
def parse_form(self, req, name, field): """Pull a form value from the request.""" post_data = self._cache.get('post') if post_data is None: yield from req.post() self._cache['post'] = req.POST return core.get_value(self._cache['post'], name, field)
def parse_json(self, req, name, arg): """Pull a json value from the request body.""" try: reqdata = json.loads(req.body.decode('utf-8')) return core.get_value(reqdata, name, arg.multiple) except (AttributeError, ValueError): return None
def parse_json(self, req, name, arg): """Pull a json value from the request.""" try: return core.get_value(req.json, name, arg.multiple) except (AttributeError, ValueError): pass return core.Missing
def parse_json(self, req, name, arg): """Pull a json value from the request.""" # Fail silently so that the webargs parser can handle the error json_data = req.get_json(silent=True) if json_data: return core.get_value(json_data, name, arg.multiple) else: return core.Missing
def parse_json(self, req, name, field): """Pull a json value from the request body.""" try: reqdata = json.loads(req.body.decode('utf-8')) return core.get_value(reqdata, name, field) except (AttributeError, ValueError): pass return core.missing
def parse_json(self, req, name, arg): """Pull a json value from the request.""" try: json_data = req.json_body except ValueError: return core.Missing return core.get_value(json_data, name, arg.multiple)
def parse_json(self, req, name, arg): """Pull a json value from the request.""" if req.content_type == 'application/json' and hasattr(req, 'json'): try: return core.get_value(req.json, name, arg.multiple) except AttributeError: return None else: return None
def parse_json(self, req, name, field): """Pull a json value from the request.""" if req.has_body: json_data = self._cache.get('json') if json_data is None: self._cache['json'] = yield from req.json() return core.get_value(self._cache['json'], name, field) else: return core.missing
def parse_json(self, req, name, field): """Pull a json value from the request.""" # Pass force in order to handle vendor media types, # e.g. applications/vnd.json+api # this should be unnecessary in Flask 1.0 force = is_json_request(req) # Fail silently so that the webargs parser can handle the error json_data = req.get_json(force=force, silent=True) if json_data: return core.get_value(json_data, name, field) else: return core.missing
def parse_json(self, req, name, field): """Pull a json value from the request.""" json_body = self._cache.get('json') if json_body is None: try: self._cache['json'] = json_body = req.json except (AttributeError, ValueError): return core.missing if json_body is not None: return core.get_value(req.json, name, field) else: return core.missing
def parse_cookies(self, req, name, field): """Pull a cookie value from the request.""" cookies = self._cache.get('cookies') if cookies is None: self._cache['cookies'] = cookies = req.cookies return core.get_value(cookies, name, field)
def parse_querystring(self, req, name, field): """Pull the querystring value from the request.""" return core.get_value(req.GET, name, field)
def parse_querystring(self, req, name, field): """Pull a querystring value from the request.""" return core.get_value(req.params, name, field)
def parse_data(request, name, field): return core.get_value(request.data, name, field)
def parse_headers(self, req, name, arg): """Pull a value from the header data.""" return core.get_value(req.headers, name, arg.multiple)
def parse_cookies(self, req, name, field): """Pull a value from the cookiejar.""" return core.get_value(req.cookies, name, field)
def parse_match_info(self, req: Request, name: str, field: Field) -> typing.Any: """Pull a value from the request's ``match_info``.""" return core.get_value(req.match_info, name, field)
def parse_querystring(self, req: Request, name: str, field: Field) -> typing.Any: """Pull a querystring value from the request.""" return core.get_value(req.query, name, field)
def parse_headers(self, req: Request, name: str, field: Field) -> typing.Any: """Pull a value from the header data.""" return core.get_value(req.headers, name, field)
def parse_cookies(self, req: Request, name: str, field: Field) -> typing.Any: """Pull a value from the cookiejar.""" return core.get_value(req.cookies, name, field)
def parse_files(self, req, name, field): """Pull a file from the request.""" files = ((k, v) for k, v in req.POST.items() if hasattr(v, 'file')) return core.get_value(webob.multidict.MultiDict(files), name, field)
def test_get_value_multidict(input_dict): field = fields.List(fields.Str()) assert get_value(input_dict, 'foos', field) == ['a', 'b']
def test_get_value_basic(): assert get_value({'foo': 42}, 'foo', False) == 42 assert get_value({'foo': 42}, 'bar', False) is missing assert get_value({'foos': ['a', 'b']}, 'foos', True) == ['a', 'b'] # https://github.com/sloria/webargs/pull/30 assert get_value({'foos': ['a', 'b']}, 'bar', True) is missing
def parse_headers(self, req, name, field): """Pull a value from the header data.""" return core.get_value(req.headers, name, field)
def parse_matchdict(self, req, name, field): """Pull a value from the request's `matchdict`.""" return core.get_value(req.matchdict, name, field)
def parse_match_info(self, req, name, field): """Pull a value from the request's ``match_info``.""" return core.get_value(req.match_info, name, field)
async def parse_form(self, req, name, field): """Pull a form value from the request.""" post_data = self._cache.get("post") if post_data is None: self._cache["post"] = await req.post() return core.get_value(self._cache["post"], name, field)
def parse_files(self, req, name, field): """Pull a file from the request.""" return core.get_value(req.files, name, field)
def parse_querystring(self, req, name, field): return core.get_value(self._parse_streamepochs_from_argdict(req.query), name, field)
def parse_form(self, req, name, field): """Pull a form value from the request.""" return core.get_value(req.params, name, field)
async def parse_form(self, req, name, field): return core.get_value(self._parse_postfile(await req.text()), name, field)
def parse_json(self, req, name, field): """Pull a JSON body value from the request.""" json_body = self._cache.get('json') if json_body is None: self._cache['json'] = json_body = parse_json_body(req) return core.get_value(json_body, name, field)
def parse_form(self, req, name, arg): """Pull a form value from the request.""" return core.get_value(req.forms, name, arg.multiple)
def test_get_value_multidict(input_dict): field = fields.List(fields.Str()) assert get_value(input_dict, "foos", field) == ["a", "b"]
def parse_form(self, req, name, field): """Pull the form value from the request.""" return core.get_value(req.POST, name, field)
def parse_files(self, req, name, arg): """Pull a file from the request.""" return core.get_value(req.files, name, arg.multiple)
def parse_files(self, req, name, field): """Pull a file from the request.""" return core.get_value(req.FILES, name, field)
def parse_querystring(self, req, name, arg): """Pull a querystring value from the request.""" return core.get_value(req.GET, name, arg.multiple)
def parse_matchdict(self, req, name, arg): return core.get_value(req.matchdict, name, arg.multiple)
def parse_querystring(self, req, name, arg): """Pull a querystring value from the request.""" return core.get_value(req.query, name, arg.multiple)
def test_get_value_basic(): assert get_value({"foo": 42}, "foo", False) == 42 assert get_value({"foo": 42}, "bar", False) is missing assert get_value({"foos": ["a", "b"]}, "foos", True) == ["a", "b"] # https://github.com/sloria/webargs/pull/30 assert get_value({"foos": ["a", "b"]}, "bar", True) is missing
def parse_json(self, req, name, arg): """Pull a json value from the request.""" try: return core.get_value(req.json, name, arg.multiple) except (AttributeError, ValueError): return None
def parse_querystring(self, req, name, field): return get_value(req.query, name, field)
def parse_form(self, req, name, field): """Pull a form value from the request.""" post_data = self._cache.get('post') if post_data is None: self._cache['post'] = yield from req.post() return core.get_value(self._cache['post'], name, field)
def parse_json(self, req, name, field): return get_value(req.json, name, field)
def parse_form(self, req, name, arg): """Pull a form value from the request.""" return core.get_value(req.POST, name, arg.multiple)
def parse_cookies(self, req, name, field): return get_value(req.cookies, name, field)
def parse_cookies(self, req, name, arg): """Pull the value from the cookiejar.""" return core.get_value(req.cookies, name, arg.multiple)
def parse_view_args(self, req, name, field): """Pull a value from the request's ``view_args``.""" return core.get_value(req.view_args, name, field)
def parse_files(self, req, name, arg): """Pull a file from the request.""" files = ((k, v) for k, v in req.POST.items() if hasattr(v, 'file')) return core.get_value(MultiDict(files), name, arg.multiple)
def parse_cookies(self, web_request, name, arg): return get_value(web_request.cookies, name, arg)