All Samples(2357) | Call(2199) | Derive(0) | Import(158)
Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is false then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
If ``ensure_ascii`` is false, then the return value will be a
``unicode`` instance subject to normal Python ``str`` to ``unicode``
coercion rules instead of being escaped to an ASCII ``str``.
If ``check_circular`` is false, then the circular reference check
for container types will be skipped and a circular reference will
result in an ``OverflowError`` (or worse).
If ``allow_nan`` is false, then it will be a ``ValueError`` to
serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
If ``indent`` is a string, then JSON array elements and object members
will be pretty-printed with a newline followed by that string repeated
for each level of nesting. ``None`` (the default) selects the most compact
representation without any newlines. For backwards compatibility with
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
then it will be used instead of the default ``(', ', ': ')`` separators.
``(',', ':')`` is the most compact JSON representation.
``encoding`` is the character encoding for str instances, default is UTF-8.
``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.
If *use_decimal* is true (default: ``False``) then decimal.Decimal
will be natively serialized to JSON with full precision.
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg.
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,
allow_nan=True, cls=None, indent=None, separators=None,
encoding='utf-8', default=None, use_decimal=False, **kw):
"""Serialize ``obj`` to a JSON formatted ``str``.
If ``skipkeys`` is false then ``dict`` keys that are not basic types
(``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
will be skipped instead of raising a ``TypeError``.
If ``ensure_ascii`` is false, then the return value will be a
``unicode`` instance subject to normal Python ``str`` to ``unicode``
coercion rules instead of being escaped to an ASCII ``str``.
If ``check_circular`` is false, then the circular reference check
for container types will be skipped and a circular reference will
result in an ``OverflowError`` (or worse).
If ``allow_nan`` is false, then it will be a ``ValueError`` to
serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
strict compliance of the JSON specification, instead of using the
JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
If ``indent`` is a string, then JSON array elements and object members
will be pretty-printed with a newline followed by that string repeated
for each level of nesting. ``None`` (the default) selects the most compact
representation without any newlines. For backwards compatibility with
versions of simplejson earlier than 2.1.0, an integer is also accepted
and is converted to a string with that many spaces.
If ``separators`` is an ``(item_separator, dict_separator)`` tuple
then it will be used instead of the default ``(', ', ': ')`` separators.
``(',', ':')`` is the most compact JSON representation.
``encoding`` is the character encoding for str instances, default is UTF-8.
``default(obj)`` is a function that should return a serializable version
of obj or raise TypeError. The default simply raises TypeError.
If *use_decimal* is true (default: ``False``) then decimal.Decimal
will be natively serialized to JSON with full precision.
To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg.
"""
# cached encoder
if (not skipkeys and ensure_ascii and
check_circular and allow_nan and
cls is None and indent is None and separators is None and
encoding == 'utf-8' and default is None and not use_decimal
and not kw):
return _default_encoder.encode(obj)
if cls is None:
cls = JSONEncoder
return cls(
skipkeys=skipkeys, ensure_ascii=ensure_ascii,
check_circular=check_circular, allow_nan=allow_nan, indent=indent,
separators=separators, encoding=encoding, default=default,
use_decimal=use_decimal, **kw).encode(obj)
from json import loads, dumps
except ImportError:
try:
from simplejson import loads, dumps
except ImportError:
loads, dumps = (None, None)
if loads and dumps:
class JSONSerializer(object):
@classmethod
def serialize(cls, items, _):
return dumps(items, sort_keys=True, indent=2)
def serialize(cls, items, map_name):
return "%(map_name)s(%(dump)s);" % {
'map_name': map_name,
'dump': dumps(items, sort_keys=True, indent=2)}
@classmethod
def deserialize(cls, string):
def serialize(cls, items, map_name):
return (
"var %s = " % map_name
+ dumps(items, sort_keys=True, indent=2)
+ ";")
@classmethod
src/a/g/agtl-0.7.1.0-freerunner0/advancedcaching/core.py agtl(Download)
try:
from json import loads, dumps
except (ImportError, AttributeError):
from simplejson import loads, dumps
from sys import argv, exit
from sys import path as sys_path
def __write_config(self):
filename = path.join(self.SETTINGS_DIR, 'config')
logger.debug("Writing settings to %s" % filename)
f = file(filename, 'w')
config = dumps(self.settings, sort_keys=True, indent=4)
f.write(config)
src/b/i/BigBlueButton-PythonExample-HEAD/main.py BigBlueButton-PythonExample(Download)
#! coding: utf-8
# pylint: disable-msg=W0311
from bottle import route, redirect, request, run, jinja2_template, \
debug, static_file, response
from simplejson import dumps
import api
import settings
src/i/n/inforlearn-python-client-HEAD/inforlearn.py inforlearn-python-client(Download)
- post/comment/get_messages/get_info """ from simplejson import loads, dumps import urllib2 import oauth #from settings import *
"method": "get_messages"}
output = []
result = self._request(parameters)
print dumps(result, indent=2)
if result['status'] == 'success':
entries = result['response']['entries']
for entry in entries:
def raw_format(self):
return dumps(self.info, indent=2)
def post(self, message, location, nick):
nick = nick + '@' + NS_DOMAIN
params = {'message': message,
'location': location,
def raw_format(self):
return dumps(self.info, indent=2)
def post(self, message, location):
nick = self.nick + '@' + NS_DOMAIN
params = {'message': message,
'location': location,
def raw_format(self):
return dumps(self.entry, indent=2)
if __name__ == "__main__":
api = API("b3c5e9952f9f4fa2994278964d7694b0",
"bf56567651504f22a2d86e952e3759b0",
src/i/n/inforlearn-python-client-HEAD/api.py inforlearn-python-client(Download)
""" from simplejson import loads, dumps import urllib2 import urlparse import oauth
"method": "get_stream"}
output = []
result = self._request(parameters)
print dumps(result, indent=2)
if result['status'] == 'success':
entries = result['response']['entries']
for entry in entries:
def raw_format(self):
return dumps(self.info, indent=2)
class User(API):
def __init__(self, info_dict):
self.info = info_dict['response']['actor']
def raw_format(self):
return dumps(self.info, indent=2)
class Comment:
def __init__(self, entry_dict):
self.entry = entry_dict
def raw_format(self):
return dumps(self.entry, indent=2)
if __name__ == "__main__":
CONSUMER_KEY = 'b3c5e9952f9f4fa2994278964d7694b0'
CONSUMER_SECRET = 'bf56567651504f22a2d86e952e3759b0'
src/j/s/jsonstore-0.3/jsonstore/rest.py jsonstore(Download)
from sha import sha from webob import Request, Response from simplejson import loads, dumps, JSONEncoder from jsonstore.store import EntryManager from jsonstore import rison
items = self.em.search(obj, count=True)
result = self.em.search(obj, size, offset)
body = dumps(result, cls=DatetimeEncoder)
etag = '"%s"' % sha(body).hexdigest()
if etag in req.if_none_match:
return Response(status='304 Not Modified')
def POST(self, req):
entry = load_entry(req.body)
result = self.em.create(entry)
body = dumps(result, cls=DatetimeEncoder)
etag = '"%s"' % sha(body).hexdigest()
location = urljoin(req.application_url, result['__id__'])
return Response(status='412 Precondition Failed')
result = self.em.update(entry)
body = dumps(result, cls=DatetimeEncoder)
etag = '"%s"' % sha(body).hexdigest()
return Response(
src/k/h/Khan-0.1.6dev/khan/json.py Khan(Download)
from paste.request import construct_url from paste.registry import StackedObjectProxy, RegistryManager from paste.util.import_string import eval_import from simplejson import dumps, loads from webob import Request, Response from webob.exc import HTTPException, status_map from khan.httpstatus import HTTPStatus
:rtype: `webob.Response`
"""
body = dumps(json_data)
resp = Response(body, content_type = JSON_MIME_TYPE, **keyword)
resp.content_encoding = encoding
return resp
# request is a Notification
if id is not None:
json['id'] = id
return dumps(json)
@staticmethod
def response(result = None, error = None, id = None, version = "1.0"):
id = int(id)
json['result'] = result
json['id'] = id
return dumps(json)
class JSONRPCErrorMeta(type):
return self._bad_gateway_app(environ, start_response)
if resp.status_int == 200:
try:
body = callback + "(" + simplejson.dumps(resp.body, encoding = self.encoding) + ")"
except:
url = construct_url(environ)
self.logger.error("'%s' responses can't convert to json data." % url, exc_info = True)
return start_response(status, headers, exc_info)
body = self.app(environ, repl_start_response)
try:
body = callback + "(" + simplejson.dumps(body) + ")"
except:
body = callback + "()"
resp = Response(body, content_type = "text/javascript; charset=utf-8")
src/p/y/pyfinger-HEAD/pyfinger/foaf.py pyfinger(Download)
import pyfinger.fingerurl
import getpass, pwd, os
try:
from json import dumps
except ImportError:
from simplejson import dumps
from ordf.command import Command
thimbl["following"].append(friend)
return dumps(thimbl, indent=4)
class Thimbl(Command):
parser = Command.StandardParser()
src/c/o/compare-locales-0.9/lib/Mozilla/CompareLocales.py compare-locales(Download)
try: from json import dumps except: from simplejson import dumps import Parser
"Build": {"pluralLabel": "Builds"}
}}
data['items'] = items
return dumps(data, indent=2)
def serialize(self, type="text/plain"):
if type=="application/json":
return self.toExhibit()
src/p/l/planes-HEAD/json.py planes(Download)
"""provides JSON and JSONP services."""
from types import FunctionType
from urllib import unquote
from simplejson import dumps, dump, load, loads
from planes.lazy import Response
content_type = 'text/javascript'
def JsonResponse(value):
return Response(
dumps(value),
def wrapped(kit, *args, **kws):
return Response(
dumps(service(kit, *args, **kws)),
content_type = content_type,
)
return wrapped
1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 Next