Beispiel #1
0
 def load_form(self, req, schema):
     """Return form values from the request as a MultiDictProxy."""
     # For consistency with other parsers' behavior, don't attempt to
     #  parse if content-type is mismatched.
     #  TODO: Make this check more specific
     if core.is_json(req.content_type):
         return core.missing
     return self._makeproxy(req.forms, schema)
 def parse_form(self, req, name, field):
     """Pull a form value from the request."""
     # For consistency with other parsers' behavior, don't attempt to
     #  parse if content-type is mismatched.
     #  TODO: Make this check more specific
     if core.is_json(req.content_type):
         return core.missing
     return core.get_value(req.forms, name, field)
def parse_json_body(req):
    """Return the decoded JSON body from the request."""
    content_type = req.headers.get('Content-Type')
    if content_type and core.is_json(content_type):
        try:
            return core.parse_json(req.body)
        except (TypeError, ValueError):
            pass
    return {}
Beispiel #4
0
def parse_json_body(req):
    """Return the decoded JSON body from the request."""
    content_type = req.headers.get('Content-Type')
    if content_type and core.is_json(content_type):
        try:
            return core.parse_json(req.body)
        except (TypeError, ValueError):
            pass
    return {}
Beispiel #5
0
def parse_json_body(req):
    """Return the decoded JSON body from the request."""
    content_type = req.headers.get("Content-Type")
    if content_type and core.is_json(content_type):
        try:
            return core.parse_json(req.body)
        except TypeError:
            pass
        except json.JSONDecodeError as e:
            if e.doc == "":
                return core.missing
            else:
                raise
    return {}
Beispiel #6
0
    def parse_json(self, req, name, field):
        """Pull a json value from the request."""
        json_data = self._cache.get("json")
        if json_data is None:
            if not core.is_json(req.content_type):
                return core.missing

            try:
                self._cache["json"] = json_data = core.parse_json(req.body)
            except json.JSONDecodeError as e:
                if e.doc == "":
                    return core.missing
                else:
                    raise
        return core.get_value(json_data, name, field, allow_many_nested=True)
Beispiel #7
0
def is_json_request(req):
    content_type = req.get_header('Content-Type')
    return content_type and core.is_json(content_type)
Beispiel #8
0
def is_json_request(req):
    """check the validity of json via core functionality"""
    content_type = req.content_type
    return core.is_json(content_type)
Beispiel #9
0
def is_json_request(req):
    return core.is_json(req.mimetype)
Beispiel #10
0
def is_json_request(req):
    content_type = req.get_header("Content-Type")
    return content_type and core.is_json(content_type)
Beispiel #11
0
def is_json_request(req):
    content_type = req.content_type
    return core.is_json(content_type)
Beispiel #12
0
def is_json_request(req):
    content_type = req.headers.get("Content-Type")
    return content_type is not None and core.is_json(content_type)
Beispiel #13
0
def is_json_request(req):
    return core.is_json(req.headers.get("content-type"))
Beispiel #14
0
def is_json_request(req: Request) -> bool:
    content_type = req.content_type
    return core.is_json(content_type)
Beispiel #15
0
def is_json_request(req: quart.Request):
    return core.is_json(req.mimetype)
Beispiel #16
0
def test_is_json():
    assert is_json(None) is False
    assert is_json("application/json") is True
    assert is_json("application/xml") is False
    assert is_json("application/vnd.api+json") is True
Beispiel #17
0
def is_json_request(req):
    return core.is_json(req.content_type)
Beispiel #18
0
def is_json_request(req):
    return core.is_json(req.mimetype)
Beispiel #19
0
def is_json_request(req: Request) -> bool:
    content_type = req.headers.get("content-type")
    return core.is_json(content_type)
 def _raw_load_json(self, req):
     """Return a json payload from the request for the core parser's load_json."""
     if not core.is_json(req.content_type):
         return core.missing
     return core.parse_json(req.body)
Beispiel #21
0
def is_json_request(req):
    content_type = req.content_type
    return core.is_json(content_type)