All Samples(2566) | Call(2426) | Derive(0) | Import(140)
Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON document) to a Python object. *encoding* determines the encoding used to interpret any :class:`str` objects decoded by this instance (``'utf-8'`` by default). It has no effect when decoding :class:`unicode` objects. Note that currently only encodings that are a superset of ASCII work, strings of other encodings should be passed in as :class:`unicode`. *object_hook*, if specified, will be called with the result of every JSON object decoded and its return value will be used in place of the given :class:`dict`. This can be used to provide custom deserializations (e.g. to support JSON-RPC class hinting). *object_pairs_hook* is an optional function that will be called with the result of any object literal decode with an ordered list of pairs. The return value of *object_pairs_hook* will be used instead of the :class:`dict`. This feature can be used to implement custom decoders that rely on the order that the key and value pairs are decoded (for example, :func:`collections.OrderedDict` will remember the order of insertion). If *object_hook* is also defined, the *object_pairs_hook* takes priority. *parse_float*, if specified, will be called with the string of every JSON float to be decoded. By default, this is equivalent to ``float(num_str)``. This can be used to use another datatype or parser for JSON floats (e.g. :class:`decimal.Decimal`). *parse_int*, if specified, will be called with the string of every JSON int to be decoded. By default, this is equivalent to ``int(num_str)``. This can be used to use another datatype or parser for JSON integers (e.g. :class:`float`). *parse_constant*, if specified, will be called with one of the following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be used to raise an exception if invalid JSON numbers are encountered. If *use_decimal* is true (default: ``False``) then it implies parse_float=decimal.Decimal for parity with ``dump``. To use a custom ``JSONDecoder`` subclass, specify it with the ``cls`` kwarg.
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,
parse_int=None, parse_constant=None, object_pairs_hook=None,
use_decimal=False, **kw):
"""Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
document) to a Python object.
*encoding* determines the encoding used to interpret any
:class:`str` objects decoded by this instance (``'utf-8'`` by
default). It has no effect when decoding :class:`unicode` objects.
Note that currently only encodings that are a superset of ASCII work,
strings of other encodings should be passed in as :class:`unicode`.
*object_hook*, if specified, will be called with the result of every
JSON object decoded and its return value will be used in place of the
given :class:`dict`. This can be used to provide custom
deserializations (e.g. to support JSON-RPC class hinting).
*object_pairs_hook* is an optional function that will be called with
the result of any object literal decode with an ordered list of pairs.
The return value of *object_pairs_hook* will be used instead of the
:class:`dict`. This feature can be used to implement custom decoders
that rely on the order that the key and value pairs are decoded (for
example, :func:`collections.OrderedDict` will remember the order of
insertion). If *object_hook* is also defined, the *object_pairs_hook*
takes priority.
*parse_float*, if specified, will be called with the string of every
JSON float to be decoded. By default, this is equivalent to
``float(num_str)``. This can be used to use another datatype or parser
for JSON floats (e.g. :class:`decimal.Decimal`).
*parse_int*, if specified, will be called with the string of every
JSON int to be decoded. By default, this is equivalent to
``int(num_str)``. This can be used to use another datatype or parser
for JSON integers (e.g. :class:`float`).
*parse_constant*, if specified, will be called with one of the
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This
can be used to raise an exception if invalid JSON numbers are
encountered.
If *use_decimal* is true (default: ``False``) then it implies
parse_float=decimal.Decimal for parity with ``dump``.
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
parse_int is None and parse_float is None and
parse_constant is None and object_pairs_hook is None
and not use_decimal and not kw):
return _default_decoder.decode(s)
if cls is None:
cls = JSONDecoder
if object_hook is not None:
kw['object_hook'] = object_hook
if object_pairs_hook is not None:
kw['object_pairs_hook'] = object_pairs_hook
if parse_float is not None:
kw['parse_float'] = parse_float
if parse_int is not None:
kw['parse_int'] = parse_int
if parse_constant is not None:
kw['parse_constant'] = parse_constant
if use_decimal:
if parse_float is not None:
raise TypeError("use_decimal=True implies parse_float=Decimal")
kw['parse_float'] = Decimal
return cls(encoding=encoding, **kw).decode(s)
from simplejson import loads
from datetime import datetime, timedelta
import sys
import urllib2
from fiveruns import dash
TERM = 'twitter'
class TwitterGetter(object):
def load(self):
url = 'http://twitter.com/statuses/public_timeline.json'
req = urllib2.Request(url)
response = urllib2.urlopen(req)
return loads(response.read())
src/n/o/noc-0.5/contrib/src/WebTest/docs/chipy-presentation/rest-api-example.py noc(Download)
setattr(httplib.HTTPConnection, attr,
getattr(wsgi_intercept.WSGI_HTTPConnection, attr).im_func)
from wsgifilter.proxyapp import DebugHeaders
from simplejson import loads as json_loads
data_filename = os.path.join(os.path.dirname(__file__), 'test-data')
wsgi_app = make_app({}, data_dir=data_filename)
'[{"path": "/testpost"}]',
status=204)
res = app.get('/.deliverance/remote_uris')
data = json_loads(res.body)
for item in data:
assert not item['path'].startswith('/testpost')
status=204)
res = app.get('/.deliverance/redirects')
res.mustcontain('otherexample.com')
data = json_loads(res.body)
for item in data:
if not item.get('path'):
continue
src/w/e/webtest-HEAD/docs/chipy-presentation/rest-api-example.py webtest(Download)
setattr(httplib.HTTPConnection, attr,
getattr(wsgi_intercept.WSGI_HTTPConnection, attr).im_func)
from wsgifilter.proxyapp import DebugHeaders
from simplejson import loads as json_loads
data_filename = os.path.join(os.path.dirname(__file__), 'test-data')
wsgi_app = make_app({}, data_dir=data_filename)
'[{"path": "/testpost"}]',
status=204)
res = app.get('/.deliverance/remote_uris')
data = json_loads(res.body)
for item in data:
assert not item['path'].startswith('/testpost')
status=204)
res = app.get('/.deliverance/redirects')
res.mustcontain('otherexample.com')
data = json_loads(res.body)
for item in data:
if not item.get('path'):
continue
src/a/u/auf-refer-1.1.1/aufrefer.py auf-refer(Download)
from urllib2 import Request, urlopen, HTTPError, URLError
from cStringIO import StringIO
from gzip import GzipFile
from simplejson import loads
def path(referentiel):
return join(DIR_BASE, referentiel)
u.close()
if referentiel.endswith('.json'):
try:
loads(data, encoding='utf-8')
except ValueError:
raise RuntimeError, "Les données ne sont pas au format JSON.\n" \
"URL concernée : %s" % url
f.close()
if referentiel.endswith('.json'):
try:
data = loads(data, encoding='utf-8')
except ValueError:
raise RuntimeError, \
"Les données du référentiel '%s' ne sont pas au format JSON.\n" \
src/h/t/HTTPEncode-0.1/trunk/httpencode/json.py HTTPEncode(Download)
from simplejson import load, dump, loads, dumps
from httpencode.format import Format
def dump_json_iter(data, content_type):
return [dumps(data)]
def load_json(fp, content_type):
data = fp.read()
# @@: For some reason simplejson is not liking \', even though
# that seems entirely reasonable to me. So we'll fix
# it up:
data = data.replace("\\'", "'")
return loads(data)
src/h/t/HTTPEncode-0.1/httpencode/json.py HTTPEncode(Download)
from simplejson import load, dump, loads, dumps
from httpencode.format import Format
def dump_json_iter(data, content_type):
return [dumps(data)]
def load_json(fp, content_type):
data = fp.read()
# @@: For some reason simplejson is not liking \', even though
# that seems entirely reasonable to me. So we'll fix
# it up:
data = data.replace("\\'", "'")
return loads(data)
src/j/s/jsonbot-0.4/gozerlib/persist.py jsonbot(Download)
## simplejson imports from simplejson import load, dump, loads, dumps ## basic imports
logging.debug('persist - jsontxt is %s' % jsontxt)
gotcache = False
else: gotcache = True
self.data = loads(jsontxt)
if type(self.data) == types.DictType:
d = LazyDict()
d.update(self.data)
return
try:
self.data = loads(data)
if type(self.data) == types.DictType:
d = LazyDict()
d.update(self.data)
src/f/e/feedprovider-0.2.1/gozerlib/utils/lazydict.py feedprovider(Download)
## simplejson imports from simplejson import loads, dumps ## basic imports from xml.sax.saxutils import unescape
def load(self, input):
""" load from json string. """
instr = unescape(input)
try:
temp = loads(instr)
except ValueError:
logging.error("lazydict - can't decode %s" % input)
src/j/s/jsonbot-0.4/gozerlib/utils/lazydict.py jsonbot(Download)
## simplejson imports from simplejson import loads, dumps ## basic imports
def load(self, input):
""" load from json string. """
try: temp = loads(input)
except ValueError:
handle_exception()
logging.error("lazydict - can't decode %s" % input)
return self
src/s/y/synoptic-0.92.2/synoptic/__init__.py synoptic(Download)
def http_rename_tag(self, request):
from simplejson import loads, dumps
data = loads(request.POST["json"])
old_name = data["old_name"]
new_name = data["new_name"]
def http_store_item(self, request):
from simplejson import loads, dumps
data = loads(request.POST["json"])
# if view ordering is present for current query,
# make sure this entry shows up last
if data["contents"] is not None:
def http_reorder_item(self, request):
from simplejson import loads
data = loads(request.POST["json"])
from synoptic.query import parse_query
from synoptic.datamodel import ViewOrderingHandler
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next