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
Exemple #2
0
 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
Exemple #3
0
 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)
Exemple #5
0
 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
Exemple #6
0
 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
Exemple #7
0
 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
Exemple #9
0
    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)
Exemple #10
0
 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
Exemple #11
0
 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
Exemple #12
0
 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)
Exemple #17
0
def parse_data(request, name, field):
    return core.get_value(request.data, name, field)
Exemple #18
0
 def parse_headers(self, req, name, arg):
     """Pull a value from the header data."""
     return core.get_value(req.headers, name, arg.multiple)
Exemple #19
0
 def parse_cookies(self, req, name, field):
     """Pull a value from the cookiejar."""
     return core.get_value(req.cookies, name, field)
Exemple #20
0
 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)
Exemple #21
0
 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)
Exemple #22
0
 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)
Exemple #23
0
 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)
Exemple #24
0
 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)
Exemple #25
0
def test_get_value_multidict(input_dict):
    field = fields.List(fields.Str())
    assert get_value(input_dict, 'foos', field) == ['a', 'b']
Exemple #26
0
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
Exemple #27
0
 def parse_headers(self, req, name, field):
     """Pull a value from the header data."""
     return core.get_value(req.headers, name, field)
Exemple #28
0
 def parse_matchdict(self, req, name, field):
     """Pull a value from the request's `matchdict`."""
     return core.get_value(req.matchdict, name, field)
Exemple #29
0
 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)
Exemple #30
0
 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)
Exemple #31
0
 def parse_headers(self, req, name, field):
     """Pull a value from the header data."""
     return core.get_value(req.headers, name, field)
Exemple #32
0
 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)
Exemple #33
0
 def parse_files(self, req, name, field):
     """Pull a file from the request."""
     return core.get_value(req.files, name, field)
Exemple #34
0
 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)
Exemple #36
0
 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)
Exemple #38
0
 def parse_form(self, req, name, arg):
     """Pull a form value from the request."""
     return core.get_value(req.forms, name, arg.multiple)
Exemple #39
0
 def parse_matchdict(self, req, name, field):
     """Pull a value from the request's `matchdict`."""
     return core.get_value(req.matchdict, name, field)
Exemple #40
0
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)
Exemple #42
0
 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)
Exemple #44
0
 def parse_querystring(self, req, name, arg):
     """Pull a querystring value from the request."""
     return core.get_value(req.GET, name, arg.multiple)
Exemple #45
0
 def parse_matchdict(self, req, name, arg):
     return core.get_value(req.matchdict, name, arg.multiple)
Exemple #46
0
 def parse_querystring(self, req, name, arg):
     """Pull a querystring value from the request."""
     return core.get_value(req.query, name, arg.multiple)
Exemple #47
0
 def parse_cookies(self, req, name, field):
     """Pull a value from the cookiejar."""
     return core.get_value(req.cookies, name, field)
Exemple #48
0
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
Exemple #49
0
 def parse_headers(self, req, name, arg):
     """Pull a value from the header data."""
     return core.get_value(req.headers, name, arg.multiple)
Exemple #50
0
 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
Exemple #51
0
 def parse_querystring(self, req, name, field):
     return get_value(req.query, name, field)
Exemple #52
0
 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)
Exemple #53
0
 def parse_files(self, req, name, arg):
     """Pull a file from the request."""
     return core.get_value(req.files, name, arg.multiple)
Exemple #54
0
 def parse_json(self, req, name, field):
     return get_value(req.json, name, field)
Exemple #55
0
 def parse_form(self, req, name, arg):
     """Pull a form value from the request."""
     return core.get_value(req.POST, name, arg.multiple)
Exemple #56
0
 def parse_cookies(self, req, name, field):
     return get_value(req.cookies, name, field)
Exemple #57
0
 def parse_cookies(self, req, name, arg):
     """Pull the value from the cookiejar."""
     return core.get_value(req.cookies, name, arg.multiple)
Exemple #58
0
 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)
Exemple #59
0
 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)
Exemple #60
0
 def parse_cookies(self, web_request, name, arg):
     return get_value(web_request.cookies, name, arg)