• Facebook
  • Twitter
  • Reddit
  • StumbleUpon
  • Digg
  • email

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)
        


src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_decode.py   PyAMF(Download)
def test_decimal():
    rval = S.loads('1.1', parse_float=decimal.Decimal)
    assert isinstance(rval, decimal.Decimal)
    assert rval == decimal.Decimal('1.1')
 
def test_float():
    rval = S.loads('1', parse_int=float)

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_unicode.py   PyAMF(Download)
def test_big_unicode_decode():
    u = u'z\U0001d120x'
    assert S.loads('"' + u + '"') == u
    assert S.loads('"z\\ud834\\udd20x"') == u
 
def test_unicode_decode():
    for i in range(0, 0xd7ff):
        u = unichr(i)
        json = '"\\u%04x"' % (i,)
        res = S.loads(json)

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_separators.py   PyAMF(Download)
    d1 = simplejson.dumps(h)
    d2 = simplejson.dumps(h, indent=2, sort_keys=True, separators=(' ,', ' : '))
 
    h1 = simplejson.loads(d1)
    h2 = simplejson.loads(d2)
 
    assert h1 == h

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_pass1.py   PyAMF(Download)
def test_parse():
    # test in/out equivalence and parsing
    import simplejson
    res = simplejson.loads(JSON)
    out = simplejson.dumps(res)
    assert res == simplejson.loads(out)
    try:

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_indent.py   PyAMF(Download)
    d1 = simplejson.dumps(h)
    d2 = simplejson.dumps(h, indent=2, sort_keys=True, separators=(',', ': '))
 
    h1 = simplejson.loads(d1)
    h2 = simplejson.loads(d2)
 
    assert h1 == h

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_pass3.py   PyAMF(Download)
def test_parse():
    # test in/out equivalence and parsing
    import simplejson
    res = simplejson.loads(JSON)
    out = simplejson.dumps(res)
    assert res == simplejson.loads(out)
 

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/tests/test_pass2.py   PyAMF(Download)
def test_parse():
    # test in/out equivalence and parsing
    import simplejson
    res = simplejson.loads(JSON)
    out = simplejson.dumps(res)
    assert res == simplejson.loads(out)
 

src/r/e/REST-Web-Services-interaction-HEAD/python/extended_example.py   REST-Web-Services-interaction(Download)
def find_allele(connection, allele):
  params = "allele_symbol_superscript=" + allele['allele_symbol_superscript']
  params += "&ikmc_project_id=" + allele['ikmc_project_id']
 
  response = connection.request( 'GET', 'alleles.json?' + params )
  alleles = json.loads(response)
 
def create_allele(connection, allele_data):
  data = { 'allele': allele_data }
  response = connection.request( 'POST', 'alleles.json', json.dumps(data) )
  return json.loads( response )
 
# Helper function to interact with the web services and find 
# a product.
def find_product(connection, product):
  params = 'escell_clone=' + product['escell_clone']
  response = connection.request( 'GET', 'products.json?' + params )
 
  # Check that we have a unique product - the repository does
  # handle this for us, but you can't be too cautious!
  products = json.loads(response)
  })
 
  response = connection.request( 'POST', 'products.json', data )
  return json.loads( response )
 
 
#
# (We're storing the pipeline details in a hash, keyed 
# by the pipeline name for use in the allele building).
response = connection.request( 'GET', 'pipelines.json' )
pipelines = dict([ (p['name'], p['id']) for p in json.loads(response) ])
 
 
# Now we define the alleles and products that we want 

src/p/y/PyMT-0.5.1/examples/apps/mtwitter/twitter.py   PyMT(Download)
      parameters['since_id'] = since_id
    url = 'http://twitter.com/statuses/public_timeline.json'
    json = self._FetchUrl(url,  parameters=parameters)
    data = simplejson.loads(json)
    return [Status.NewFromJsonDict(x) for x in data]
 
  def GetFriendsTimeline(self, user=None, since=None):
    if since:
      parameters['since'] = since
    json = self._FetchUrl(url, parameters=parameters)
    data = simplejson.loads(json)
    return [Status.NewFromJsonDict(x) for x in data]
 
  def GetUserTimeline(self, user=None, count=None, since=None):
    else:
      url = 'http://twitter.com/statuses/user_timeline.json'
    json = self._FetchUrl(url, parameters=parameters)
    data = simplejson.loads(json)
    return [Status.NewFromJsonDict(x) for x in data]
 
  def GetStatus(self, id):
      raise TwitterError("id must be an integer")
    url = 'http://twitter.com/statuses/show/%s.json' % id
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
 
  def DestroyStatus(self, id):
      raise TwitterError("id must be an integer")
    url = 'http://twitter.com/statuses/destroy/%s.json' % id
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
 
  def PostUpdate(self, text):
    url = 'http://twitter.com/statuses/update.json'
    data = {'status': text}
    json = self._FetchUrl(url, post_data=data)
    data = simplejson.loads(json)
    return Status.NewFromJsonDict(data)
 
  def GetReplies(self):
    if not self._username:
      raise TwitterError("The twitter.Api instance must be authenticated.")
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return [Status.NewFromJsonDict(x) for x in data]
 
  def GetFriends(self, user=None):
    else:
      url = 'http://twitter.com/statuses/friends.json'
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return [User.NewFromJsonDict(x) for x in data]
 
  def GetFollowers(self):
      raise TwitterError("twitter.Api instance must be authenticated")
    url = 'http://twitter.com/statuses/followers.json'
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return [User.NewFromJsonDict(x) for x in data]
 
  def GetFeatured(self):
    '''
    url = 'http://twitter.com/statuses/featured.json'
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return [User.NewFromJsonDict(x) for x in data]
 
  def GetUser(self, user):
    '''
    url = 'http://twitter.com/users/show/%s.json' % user
    json = self._FetchUrl(url)
    data = simplejson.loads(json)
    return User.NewFromJsonDict(data)
 
  def GetDirectMessages(self, since=None):
    if since:
      parameters['since'] = since
    json = self._FetchUrl(url, parameters=parameters)
    data = simplejson.loads(json)
    return [DirectMessage.NewFromJsonDict(x) for x in data]
 
  def PostDirectMessage(self, user, text):
    url = 'http://twitter.com/direct_messages/new.json'
    data = {'text': text, 'user': user}
    json = self._FetchUrl(url, post_data=data)
    data = simplejson.loads(json)
    return DirectMessage.NewFromJsonDict(data)
 
  def DestroyDirectMessage(self, id):
    '''
    url = 'http://twitter.com/direct_messages/destroy/%s.json' % id
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return DirectMessage.NewFromJsonDict(data)
 
  def CreateFriendship(self, user):
    '''
    url = 'http://twitter.com/friendships/create/%s.json' % user
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return User.NewFromJsonDict(data)
 
  def DestroyFriendship(self, user):
    '''
    url = 'http://twitter.com/friendships/destroy/%s.json' % user
    json = self._FetchUrl(url, post_data={})
    data = simplejson.loads(json)
    return User.NewFromJsonDict(data)
 
  def SetCredentials(self, username, password):

src/p/y/PyAMF-HEAD/doc/tutorials/examples/actionscript/google_appengine/simplejson/jsonfilter.py   PyAMF(Download)
            if environ.get('CONTENT_TYPE', '') == self.mime_type:
                args = [_ for _ in [environ.get('CONTENT_LENGTH')] if _]
                data = environ['wsgi.input'].read(*map(int, args))
                environ['jsonfilter.json'] = simplejson.loads(data)
        res = simplejson.dumps(self.app(environ, json_start_response))
        jsonp = cgi.parse_qs(environ.get('QUERY_STRING', '')).get('jsonp')
        if jsonp:

  1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9  Next