All Samples(190) | Call(172) | Derive(0) | Import(18)
Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
``.write()``-supporting file-like object).
If ``skipkeys`` is true 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 some chunks written to ``fp``
may be ``unicode`` instances, subject to normal Python ``str`` to
``unicode`` coercion rules. Unless ``fp.write()`` explicitly
understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
to cause an error.
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 dump(obj, fp, 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`` as a JSON formatted stream to ``fp`` (a
``.write()``-supporting file-like object).
If ``skipkeys`` is true 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 some chunks written to ``fp``
may be ``unicode`` instances, subject to normal Python ``str`` to
``unicode`` coercion rules. Unless ``fp.write()`` explicitly
understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
to cause an error.
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 kw):
iterable = _default_encoder.iterencode(obj)
else:
if cls is None:
cls = JSONEncoder
iterable = 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).iterencode(obj)
# could accelerate with writelines in some versions of Python, at
# a debuggability cost
for chunk in iterable:
fp.write(chunk)
## simplejson imports from simplejson import load, dump, loads, dumps ## basic imports
except IOError, ex:
logging.error("persist - can't save %s: %s" % (self.fn, str(ex)))
return
dump(self.data, datafile)
datafile.close()
try: os.rename(tmp, self.fn)
except OSError:
src/f/e/feedprovider-0.2.1/gozerlib/persist.py feedprovider(Download)
## simplejson imports from simplejson import load, dump, loads, dumps ## basic imports
# dump JSON to file
#cp = copy.copy(self.data)
dump(self.data, datafile)
datafile.close()
try:
src/g/o/gozerbot-0.9.2b1/gozerbot/persist/persist.py gozerbot(Download)
from gozerbot.utils.lazydict import LazyDict from gozerbot.datadir import datadir from gozerbot.config import config from simplejson import load, dump, loads, dumps # basic imports import pickle, thread, os, copy, sys, types
# dump JSON to file
#cp = copy.copy(self.data)
dump(self.data, datafile)
datafile.close()
try:
src/g/o/gozerbot-0.9.2b1/gozerbot/utils/reboot.py gozerbot(Download)
# gozerbot/utils/reboot.py # # from gozerbot.fleet import fleet from gozerbot.config import config from simplejson import dump
session['bots'].update(i._resumedata())
session['partyline'] = partyline._resumedata()
sessionfile = tempfile.mkstemp('-session', 'gozerbot-')[1]
dump(session, open(sessionfile, 'w'))
fleet.save()
fleet.exit(jabber=True)
os.execl(sys.argv[0], sys.argv[0], '-r', sessionfile)
src/j/s/jsonbot-0.4/gozerlib/reboot.py jsonbot(Download)
## basic imports from simplejson import dump import os import sys import pickle
if i.bottype == "sxmpp": i.exit()
session['partyline'] = partyline._resumedata()
sessionfile = tempfile.mkstemp('-session', 'gozerbot-')[1]
dump(session, open(sessionfile, 'w'))
fleet.save()
os.execl(sys.argv[0], sys.argv[0], '-r', sessionfile)
src/g/o/gozerbot-0.9.2b1/gozerbot/reboot.py gozerbot(Download)
from gozerbot.fleet import fleet from gozerbot.config import config from simplejson import dump import os, sys, pickle, tempfile
session['partyline'] = partyline._resumedata()
sessionfile = tempfile.mkstemp('-session', 'gozerbot-')[1]
dump(session, open(sessionfile, 'w'))
fleet.save()
fleet.exit(jabber=True)
os.execl(sys.argv[0], sys.argv[0], '-r', sessionfile)
src/g/l/Glashammer-0.2.1/glashammer/bundles/i18n/compilejs.py Glashammer(Download)
from __future__ import with_statement from os import listdir, path from babel.messages.pofile import read_po from simplejson import dump domains = ['messages']
jscatalog[msgid] = message.string
with file(path.join(folder, domain + '.js'), 'w') as f:
f.write('babel.Translations.load(');
dump(dict(
messages=jscatalog,
plural_expr=catalog.plural_expr,
locale=str(catalog.locale),
src/p/l/Plurk_Solace-0.1/solace/scripts.py Plurk_Solace(Download)
from babel.messages.pofile import read_po from babel.messages.frontend import compile_catalog from simplejson import dump as dump_json class RunserverCommand(Command):
outfile = open(js_file, 'wb')
try:
outfile.write('Solace.TRANSLATIONS.load(');
dump_json(dict(
messages=jscatalog,
plural_expr=catalog.plural_expr,
locale=str(catalog.locale),
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
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):
1 | 2 Next