Gaudi Framework, version v21r9

Home   Generated: 3 May 2010

simplejson Namespace Reference


Namespaces

namespace  decoder
namespace  encoder
namespace  scanner
namespace  tool

Functions

def dump
def dumps
def load
def loads

Variables

string __version__ = '2.0.9'
list __all__
string __author__ = 'Bob Ippolito <bob@redivi.com>'
tuple _default_encoder
tuple _default_decoder = JSONDecoder(encoding=None, object_hook=None)


Function Documentation

def simplejson::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,
  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 non-negative integer, then JSON array elements and object
members will be pretty-printed with that indent level. An indent level
of 0 will only insert newlines. ``None`` is the most compact representation.

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.

To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg.

Definition at line 122 of file __init__.py.

00124                                              :
00125     """Serialize ``obj`` as a JSON formatted stream to ``fp`` (a
00126     ``.write()``-supporting file-like object).
00127 
00128     If ``skipkeys`` is true then ``dict`` keys that are not basic types
00129     (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
00130     will be skipped instead of raising a ``TypeError``.
00131 
00132     If ``ensure_ascii`` is false, then the some chunks written to ``fp``
00133     may be ``unicode`` instances, subject to normal Python ``str`` to
00134     ``unicode`` coercion rules. Unless ``fp.write()`` explicitly
00135     understands ``unicode`` (as in ``codecs.getwriter()``) this is likely
00136     to cause an error.
00137 
00138     If ``check_circular`` is false, then the circular reference check
00139     for container types will be skipped and a circular reference will
00140     result in an ``OverflowError`` (or worse).
00141 
00142     If ``allow_nan`` is false, then it will be a ``ValueError`` to
00143     serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``)
00144     in strict compliance of the JSON specification, instead of using the
00145     JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
00146 
00147     If ``indent`` is a non-negative integer, then JSON array elements and object
00148     members will be pretty-printed with that indent level. An indent level
00149     of 0 will only insert newlines. ``None`` is the most compact representation.
00150 
00151     If ``separators`` is an ``(item_separator, dict_separator)`` tuple
00152     then it will be used instead of the default ``(', ', ': ')`` separators.
00153     ``(',', ':')`` is the most compact JSON representation.
00154 
00155     ``encoding`` is the character encoding for str instances, default is UTF-8.
00156 
00157     ``default(obj)`` is a function that should return a serializable version
00158     of obj or raise TypeError. The default simply raises TypeError.
00159 
00160     To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
00161     ``.default()`` method to serialize additional types), specify it with
00162     the ``cls`` kwarg.
00163 
00164     """
00165     # cached encoder
00166     if (not skipkeys and ensure_ascii and
00167         check_circular and allow_nan and
00168         cls is None and indent is None and separators is None and
00169         encoding == 'utf-8' and default is None and not kw):
00170         iterable = _default_encoder.iterencode(obj)
00171     else:
00172         if cls is None:
00173             cls = JSONEncoder
00174         iterable = cls(skipkeys=skipkeys, ensure_ascii=ensure_ascii,
00175             check_circular=check_circular, allow_nan=allow_nan, indent=indent,
00176             separators=separators, encoding=encoding,
00177             default=default, **kw).iterencode(obj)
00178     # could accelerate with writelines in some versions of Python, at
00179     # a debuggability cost
00180     for chunk in iterable:
00181         fp.write(chunk)
00182 
00183 
def dumps(obj, skipkeys=False, ensure_ascii=True, check_circular=True,

def simplejson::dumps (   obj,
  skipkeys = False,
  ensure_ascii = True,
  check_circular = True,
  allow_nan = True,
  cls = None,
  indent = None,
  separators = None,
  encoding = 'utf-8',
  default = None,
  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 non-negative integer, then JSON array elements and
object members will be pretty-printed with that indent level. An indent
level of 0 will only insert newlines. ``None`` is the most compact
representation.

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.

To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
``.default()`` method to serialize additional types), specify it with
the ``cls`` kwarg.

Definition at line 184 of file __init__.py.

00186                                              :
00187     """Serialize ``obj`` to a JSON formatted ``str``.
00188 
00189     If ``skipkeys`` is false then ``dict`` keys that are not basic types
00190     (``str``, ``unicode``, ``int``, ``long``, ``float``, ``bool``, ``None``)
00191     will be skipped instead of raising a ``TypeError``.
00192 
00193     If ``ensure_ascii`` is false, then the return value will be a
00194     ``unicode`` instance subject to normal Python ``str`` to ``unicode``
00195     coercion rules instead of being escaped to an ASCII ``str``.
00196 
00197     If ``check_circular`` is false, then the circular reference check
00198     for container types will be skipped and a circular reference will
00199     result in an ``OverflowError`` (or worse).
00200 
00201     If ``allow_nan`` is false, then it will be a ``ValueError`` to
00202     serialize out of range ``float`` values (``nan``, ``inf``, ``-inf``) in
00203     strict compliance of the JSON specification, instead of using the
00204     JavaScript equivalents (``NaN``, ``Infinity``, ``-Infinity``).
00205 
00206     If ``indent`` is a non-negative integer, then JSON array elements and
00207     object members will be pretty-printed with that indent level. An indent
00208     level of 0 will only insert newlines. ``None`` is the most compact
00209     representation.
00210 
00211     If ``separators`` is an ``(item_separator, dict_separator)`` tuple
00212     then it will be used instead of the default ``(', ', ': ')`` separators.
00213     ``(',', ':')`` is the most compact JSON representation.
00214 
00215     ``encoding`` is the character encoding for str instances, default is UTF-8.
00216 
00217     ``default(obj)`` is a function that should return a serializable version
00218     of obj or raise TypeError. The default simply raises TypeError.
00219 
00220     To use a custom ``JSONEncoder`` subclass (e.g. one that overrides the
00221     ``.default()`` method to serialize additional types), specify it with
00222     the ``cls`` kwarg.
00223 
00224     """
00225     # cached encoder
00226     if (not skipkeys and ensure_ascii and
00227         check_circular and allow_nan and
00228         cls is None and indent is None and separators is None and
00229         encoding == 'utf-8' and default is None and not kw):
00230         return _default_encoder.encode(obj)
00231     if cls is None:
00232         cls = JSONEncoder
00233     return cls(
00234         skipkeys=skipkeys, ensure_ascii=ensure_ascii,
00235         check_circular=check_circular, allow_nan=allow_nan, indent=indent,
00236         separators=separators, encoding=encoding, default=default,
00237         **kw).encode(obj)
00238 
00239 
_default_decoder = JSONDecoder(encoding=None, object_hook=None)

def simplejson::load (   fp,
  encoding = None,
  cls = None,
  object_hook = None,
  parse_float = None,
  parse_int = None,
  parse_constant = None,
  kw 
)

Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
a JSON document) to a Python object.

If the contents of ``fp`` is encoded with an ASCII based encoding other
than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
be specified. Encodings that are not ASCII based (such as UCS-2) are
not allowed, and should be wrapped with
``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
object and passed to ``loads()``

``object_hook`` is an optional function that will be called with the
result of any object literal decode (a ``dict``). The return value of
``object_hook`` will be used instead of the ``dict``. This feature
can be used to implement custom decoders (e.g. JSON-RPC class hinting).

To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
kwarg.

Definition at line 243 of file __init__.py.

00244                                                   :
00245     """Deserialize ``fp`` (a ``.read()``-supporting file-like object containing
00246     a JSON document) to a Python object.
00247 
00248     If the contents of ``fp`` is encoded with an ASCII based encoding other
00249     than utf-8 (e.g. latin-1), then an appropriate ``encoding`` name must
00250     be specified. Encodings that are not ASCII based (such as UCS-2) are
00251     not allowed, and should be wrapped with
00252     ``codecs.getreader(fp)(encoding)``, or simply decoded to a ``unicode``
00253     object and passed to ``loads()``
00254 
00255     ``object_hook`` is an optional function that will be called with the
00256     result of any object literal decode (a ``dict``). The return value of
00257     ``object_hook`` will be used instead of the ``dict``. This feature
00258     can be used to implement custom decoders (e.g. JSON-RPC class hinting).
00259 
00260     To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
00261     kwarg.
00262 
00263     """
00264     return loads(fp.read(),
00265         encoding=encoding, cls=cls, object_hook=object_hook,
00266         parse_float=parse_float, parse_int=parse_int,
00267         parse_constant=parse_constant, **kw)
00268 
00269 
def loads(s, encoding=None, cls=None, object_hook=None, parse_float=None,

def simplejson::loads (   s,
  encoding = None,
  cls = None,
  object_hook = None,
  parse_float = None,
  parse_int = None,
  parse_constant = None,
  kw 
)

Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
document) to a Python object.

If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
must be specified. Encodings that are not ASCII based (such as UCS-2)
are not allowed and should be decoded to ``unicode`` first.

``object_hook`` is an optional function that will be called with the
result of any object literal decode (a ``dict``). The return value of
``object_hook`` will be used instead of the ``dict``. This feature
can be used to implement custom decoders (e.g. JSON-RPC class hinting).

``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. 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. float).

``parse_constant``, if specified, will be called with one of the
following strings: -Infinity, Infinity, NaN, null, true, false.
This can be used to raise an exception if invalid JSON numbers
are encountered.

To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
kwarg.

Definition at line 270 of file __init__.py.

00271                                                   :
00272     """Deserialize ``s`` (a ``str`` or ``unicode`` instance containing a JSON
00273     document) to a Python object.
00274 
00275     If ``s`` is a ``str`` instance and is encoded with an ASCII based encoding
00276     other than utf-8 (e.g. latin-1) then an appropriate ``encoding`` name
00277     must be specified. Encodings that are not ASCII based (such as UCS-2)
00278     are not allowed and should be decoded to ``unicode`` first.
00279 
00280     ``object_hook`` is an optional function that will be called with the
00281     result of any object literal decode (a ``dict``). The return value of
00282     ``object_hook`` will be used instead of the ``dict``. This feature
00283     can be used to implement custom decoders (e.g. JSON-RPC class hinting).
00284 
00285     ``parse_float``, if specified, will be called with the string
00286     of every JSON float to be decoded. By default this is equivalent to
00287     float(num_str). This can be used to use another datatype or parser
00288     for JSON floats (e.g. decimal.Decimal).
00289 
00290     ``parse_int``, if specified, will be called with the string
00291     of every JSON int to be decoded. By default this is equivalent to
00292     int(num_str). This can be used to use another datatype or parser
00293     for JSON integers (e.g. float).
00294 
00295     ``parse_constant``, if specified, will be called with one of the
00296     following strings: -Infinity, Infinity, NaN, null, true, false.
00297     This can be used to raise an exception if invalid JSON numbers
00298     are encountered.
00299 
00300     To use a custom ``JSONDecoder`` subclass, specify it with the ``cls``
00301     kwarg.
00302 
00303     """
00304     if (cls is None and encoding is None and object_hook is None and
00305             parse_int is None and parse_float is None and
00306             parse_constant is None and not kw):
00307         return _default_decoder.decode(s)
00308     if cls is None:
00309         cls = JSONDecoder
00310     if object_hook is not None:
00311         kw['object_hook'] = object_hook
00312     if parse_float is not None:
00313         kw['parse_float'] = parse_float
00314     if parse_int is not None:
00315         kw['parse_int'] = parse_int
00316     if parse_constant is not None:
00317         kw['parse_constant'] = parse_constant
00318     return cls(encoding=encoding, **kw).decode(s)
    return cls(encoding=encoding, **kw).decode(s)


Variable Documentation

Initial value:

[
    'dump', 'dumps', 'load', 'loads',
    'JSONDecoder', 'JSONEncoder',
]

Definition at line 101 of file __init__.py.

string simplejson::__author__ = 'Bob Ippolito <bob@redivi.com>'

Definition at line 106 of file __init__.py.

string simplejson::__version__ = '2.0.9'

Definition at line 100 of file __init__.py.

tuple simplejson::_default_decoder = JSONDecoder(encoding=None, object_hook=None)

Definition at line 240 of file __init__.py.

Initial value:

JSONEncoder(
    skipkeys=False,
    ensure_ascii=True,
    check_circular=True,
    allow_nan=True,
    indent=None,
    separators=None,
    encoding='utf-8',
    default=None,
)

Definition at line 111 of file __init__.py.


Generated at Mon May 3 12:29:53 2010 for Gaudi Framework, version v21r9 by Doxygen version 1.5.6 written by Dimitri van Heesch, © 1997-2004