ClericPy/torequests · _py3_patch.py
python logo
def json(self, encoding=None, loads=json.loads):
        return loads(self.content.decode(encoding or self.encoding))
Similar code snippets
1.
kevin1024/vcrpy · __init__.py
Match rating: 78.93% · See similar code snippets
python logo
async def json(self, *, encoding='utf-8', loads=json.loads, **kwargs):  # NOQA: E999
        return loads(self._body.decode(encoding))
2.
mozillazg/bustard · http.py
Match rating: 71.94% · See similar code snippets
python logo
def get_json(self, encoding='utf-8'):
        content = self.data.decode(encoding)
        try:
            return json.loads(content)
        except ValueError:
            return
3.
xiyouMc/ncmbot · core.py
Match rating: 71.84% · See similar code snippets
python logo
def json(self):
        """Returns the json-encoded content of a response, if any."""

        if not self.headers and len(self.content) > 3:
            encoding = get_encoding_from_headers(self.headers)
            if encoding is not None:
                return json.loads(self.content.decode(encoding))
        return json.loads(self.content)
4.
restran/mountains · __init__.py
Match rating: 70.86% · See similar code snippets
python logo
def loads(content, encoding='utf-8', **kwargs):
    if PY3:
        return json.loads(s=force_bytes(content), encoding=encoding, **kwargs)
    else:
        return json.loads(s=content, encoding=encoding, **kwargs)
5.
siznax/wptools · utils.py
Match rating: 68.68% · See similar code snippets
python logo
def json_loads(data):
    """
    python-version-safe json.loads
    """
    try:
        return json.loads(data, encoding='utf-8')
    except TypeError:
        return json.loads(data.decode('utf-8'))
6.
mottosso/be · models.py
Match rating: 68.49% · See similar code snippets
python logo
def json(self, **kwargs):
        """Returns the json-encoded content of a response, if any.

        :param \*\*kwargs: Optional arguments that ``json.loads`` takes.
        """

        if not self.encoding and len(self.content) > 3:
            # No encoding set. JSON RFC 4627 section 3 states we should expect
            # UTF-8, -16 or -32. Detect which one to use; If the detection or
            # decoding fails, fall back to `self.text` (using chardet to make
            # a best guess).
            encoding = guess_json_utf(self.content)
            if encoding is not None:
                try:
                    return json.loads(self.content.decode(encoding), **kwargs)
                except UnicodeDecodeError:
                    # Wrong UTF codec detected; usually because it's not UTF-8
                    # but some other 8-bit codec.  This is an RFC violation,
                    # and the server didn't bother to tell us what codec *was*
                    # used.
                    pass
        return json.loads(self.text, **kwargs)
7.
howie6879/ruia · response.py
Match rating: 67.93% · See similar code snippets
python logo
async def json(self,
                   *,
                   encoding: str = None,
                   loads: JSONDecoder = DEFAULT_JSON_DECODER,
                   content_type: Optional[str] = 'application/json') -> Any:
        """Read and decodes JSON response."""
        return await self._aws_json(
            encoding=encoding, loads=loads, content_type=content_type)
8.
jazzband/sorl-thumbnail · helpers.py
Match rating: 67.67% · See similar code snippets
python logo
def deserialize(s):
    if isinstance(s, bytes):
        return json.loads(s.decode('utf-8'))
    return json.loads(s)
9.
aio-libs/aioredis · pubsub.py
Match rating: 67.14% · See similar code snippets
python logo
async def get_json(self, encoding='utf-8'):
        """Shortcut to get JSON messages."""
        return (await self.get(encoding=encoding, decoder=json.loads))
10.
aio-libs/aiohttp · http_websocket.py
Match rating: 66.94% · See similar code snippets
python logo
def json(self, *,  # type: ignore
             loads: Callable[[Any], Any]=json.loads) -> None:
        """Return parsed JSON data.

        .. versionadded:: 0.22
        """
        return loads(self.data)