Ejemplo n.º 1
0
 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 4
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:
         yield from req.post()
         self._cache['post'] = req.POST
     return core.get_value(self._cache['post'], name, field)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 8
0
 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 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
Ejemplo n.º 13
0
 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
Ejemplo n.º 14
0
 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)
Ejemplo n.º 15
0
 def parse_querystring(self, req, name, field):
     """Pull the querystring value from the request."""
     return core.get_value(req.GET, name, field)
Ejemplo n.º 16
0
 def parse_querystring(self, req, name, field):
     """Pull a querystring value from the request."""
     return core.get_value(req.params, name, field)
Ejemplo n.º 17
0
def parse_data(request, name, field):
    return core.get_value(request.data, name, field)
Ejemplo n.º 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)
Ejemplo n.º 19
0
 def parse_cookies(self, req, name, field):
     """Pull a value from the cookiejar."""
     return core.get_value(req.cookies, name, field)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 25
0
def test_get_value_multidict(input_dict):
    field = fields.List(fields.Str())
    assert get_value(input_dict, 'foos', field) == ['a', 'b']
Ejemplo n.º 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
Ejemplo n.º 27
0
 def parse_headers(self, req, name, field):
     """Pull a value from the header data."""
     return core.get_value(req.headers, name, field)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 31
0
 def parse_headers(self, req, name, field):
     """Pull a value from the header data."""
     return core.get_value(req.headers, name, field)
Ejemplo n.º 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)
Ejemplo n.º 33
0
 def parse_files(self, req, name, field):
     """Pull a file from the request."""
     return core.get_value(req.files, name, field)
Ejemplo n.º 34
0
 def parse_querystring(self, req, name, field):
     return core.get_value(self._parse_streamepochs_from_argdict(req.query),
                           name, field)
Ejemplo n.º 35
0
 def parse_form(self, req, name, field):
     """Pull a form value from the request."""
     return core.get_value(req.params, name, field)
Ejemplo n.º 36
0
 async def parse_form(self, req, name, field):
     return core.get_value(self._parse_postfile(await req.text()), name,
                           field)
Ejemplo n.º 37
0
 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 40
0
def test_get_value_multidict(input_dict):
    field = fields.List(fields.Str())
    assert get_value(input_dict, "foos", field) == ["a", "b"]
Ejemplo n.º 41
0
 def parse_form(self, req, name, field):
     """Pull the form value from the request."""
     return core.get_value(req.POST, name, field)
Ejemplo n.º 42
0
 def parse_files(self, req, name, arg):
     """Pull a file from the request."""
     return core.get_value(req.files, name, arg.multiple)
Ejemplo n.º 43
0
 def parse_files(self, req, name, field):
     """Pull a file from the request."""
     return core.get_value(req.FILES, name, field)
Ejemplo n.º 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)
Ejemplo n.º 45
0
 def parse_matchdict(self, req, name, arg):
     return core.get_value(req.matchdict, name, arg.multiple)
Ejemplo n.º 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)
Ejemplo n.º 47
0
 def parse_cookies(self, req, name, field):
     """Pull a value from the cookiejar."""
     return core.get_value(req.cookies, name, field)
Ejemplo n.º 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
Ejemplo n.º 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)
Ejemplo n.º 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
Ejemplo n.º 51
0
 def parse_querystring(self, req, name, field):
     return get_value(req.query, name, field)
Ejemplo n.º 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)
Ejemplo n.º 53
0
 def parse_files(self, req, name, arg):
     """Pull a file from the request."""
     return core.get_value(req.files, name, arg.multiple)
Ejemplo n.º 54
0
 def parse_json(self, req, name, field):
     return get_value(req.json, name, field)
Ejemplo n.º 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)
Ejemplo n.º 56
0
 def parse_cookies(self, req, name, field):
     return get_value(req.cookies, name, field)
Ejemplo n.º 57
0
 def parse_cookies(self, req, name, arg):
     """Pull the value from the cookiejar."""
     return core.get_value(req.cookies, name, arg.multiple)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 60
0
 def parse_cookies(self, web_request, name, arg):
     return get_value(web_request.cookies, name, arg)