Package tdi :: Package tools :: Module javascript :: Class SimpleJSON
[frames] | no frames]

Class SimpleJSON

source code

object --+
         |
        SimpleJSON

JSON generator for use with replace or fill

This class uses simplejson for generating JSON output.

The encoder looks for either the json module or, if that fails, for the simplejson module. If both fail, an ImportError is raised from the as_json method.

Instance Methods
 
__init__(self, content, inlined=False, str_encoding='latin-1')
Initialization
source code
 
__repr__(self)
Debug representation
source code
unicode
as_json(self, inlined=None)
Content as JSON
source code
unicode
__unicode__(self, inlined=None)
Content as JSON
source code
str
__str__(self)
JSON as str (UTF-8 encoded)
source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __sizeof__, __subclasshook__

Properties

Inherited from object: __class__

Method Details

__init__(self, content, inlined=False, str_encoding='latin-1')
(Constructor)

source code 
Initialization
Parameters:
  • content (any) - Content to wrap for json conversion
  • inlined (bool) - Is it going to be inlined? Certain sequences are escaped then.
  • str_encoding (str) - Encoding to be applied on str content parts. Latin-1 is a failsafe default here, because it always translates. It may be wrong though.
Overrides: object.__init__

__repr__(self)
(Representation operator)

source code 
Debug representation
Overrides: object.__repr__

as_json(self, inlined=None)

source code 
Content as JSON
Parameters:
  • inlined (bool or None) - escape for inlining? If omitted or None, the default value from construction is used.
Returns: unicode
The JSON encoded content

__unicode__(self, inlined=None)

source code 
Content as JSON
Parameters:
  • inlined (bool or None) - escape for inlining? If omitted or None, the default value from construction is used.
Returns: unicode
The JSON encoded content

__str__(self)
(Informal representation operator)

source code 
JSON as str (UTF-8 encoded)
Returns: str
JSON string
Overrides: object.__str__