kopia lustrzana https://github.com/micropython/micropython-lib
unix-ffi/json: Accept both str and bytes as arg for json.loads().
Same as micropython's internal json lib does. Fixes #985. Signed-off-by: Dominik Heidler <dheidler@suse.de>pull/986/head
rodzic
f72f3f1a39
commit
d1a74360a2
|
@ -354,8 +354,8 @@ def loads(
|
||||||
object_pairs_hook=None,
|
object_pairs_hook=None,
|
||||||
**kw
|
**kw
|
||||||
):
|
):
|
||||||
"""Deserialize ``s`` (a ``str`` instance containing a JSON
|
"""Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance
|
||||||
document) to a Python object.
|
containing a JSON document) to a Python object.
|
||||||
|
|
||||||
``object_hook`` is an optional function that will be called with the
|
``object_hook`` is an optional function that will be called with the
|
||||||
result of any object literal decode (a ``dict``). The return value of
|
result of any object literal decode (a ``dict``). The return value of
|
||||||
|
@ -413,4 +413,6 @@ def loads(
|
||||||
kw["parse_int"] = parse_int
|
kw["parse_int"] = parse_int
|
||||||
if parse_constant is not None:
|
if parse_constant is not None:
|
||||||
kw["parse_constant"] = parse_constant
|
kw["parse_constant"] = parse_constant
|
||||||
|
if isinstance(s, (bytes, bytearray)):
|
||||||
|
s = s.decode('utf-8')
|
||||||
return cls(**kw).decode(s)
|
return cls(**kw).decode(s)
|
||||||
|
|
Ładowanie…
Reference in New Issue