diff --git a/simplejson/__init__.py b/simplejson/__init__.py index 3dd63130ded9450b0d3de71e4cc68103e47cd61b_c2ltcGxlanNvbi9fX2luaXRfXy5weQ==..0b63b759242cc6a4bb9fb165ad22ba48a37395ad_c2ltcGxlanNvbi9fX2luaXRfXy5weQ== 100644 --- a/simplejson/__init__.py +++ b/simplejson/__init__.py @@ -212,7 +212,10 @@ separators=separators, encoding=encoding, **kw).encode(obj) -def load(fp, encoding=None, cls=None, object_hook=None, **kw): +_default_decoder = JSONDecoder(encoding=None, object_hook=None) + +def load(fp, encoding=None, cls=None, object_hook=None, + _decode=_default_decoder.decode, **kw): """ Deserialize ``fp`` (a ``.read()``-supporting file-like object containing a JSON document) to a Python object. @@ -232,9 +235,11 @@ To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` kwarg. """ + if cls is None and encoding is None and object_hook is None and not kw: + return _decode(fp.read()) if cls is None: cls = JSONDecoder if object_hook is not None: kw['object_hook'] = object_hook return cls(encoding=encoding, **kw).decode(fp.read()) @@ -235,10 +240,11 @@ if cls is None: cls = JSONDecoder if object_hook is not None: kw['object_hook'] = object_hook return cls(encoding=encoding, **kw).decode(fp.read()) -def loads(s, encoding=None, cls=None, object_hook=None, **kw): +def loads(s, encoding=None, cls=None, object_hook=None, + _decode=_default_decoder.decode, **kw): """ Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON document) to a Python object. @@ -256,6 +262,8 @@ To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` kwarg. """ + if cls is None and encoding is None and object_hook is None and not kw: + return _decode(s) if cls is None: cls = JSONDecoder if object_hook is not None: