DictDumper package

Table of Contents

Module Contents

Stream formatted output dumper.

dictdumper is an open source Python program works as a stream formatted output dumper. Currently, it supports following formats:

  • Dumper

    Abstract base class of all dumpers.

  • JSON

    Dump JavaScript object notation (JSON) format file.

  • PLIST

    Dump Apple property list (PLIST) format file.

  • Tree

    Dump tree-view text (TXT) format file.

  • XML

    Dump extensible markup language (XML) file; this is an abstract base class

  • VueJS

    Dump JavaScript file using Vue.js framework; this class is deprecated due to grammar error.

    Deprecated since version 0.8.0.

class dictdumper.JSON(fname, **kwargs)[source]

Bases: Dumper

Dump JavaScript object notation (JSON) format file.

>>> dumper = JSON(file_name)
>>> dumper(content_dict_1, name=content_name_1)
>>> dumper(content_dict_2, name=content_name_2)
............
Variables:
  • _file (str) – output file name

  • _sptr (int) – indicates start of appending point (file pointer)

  • _tctr (int) – tab level counter

  • _hsrt (str) – _HEADER_START

  • _hend (str) – _HEADER_END

  • _vctr (DefaultDict[int, int]) – value counter dict

Note

Terminology:

object    ::=  "{}" | ("{" members "}")
members   ::=  pair | (pair "," members)
pair      ::=  string ":" value
array     ::=  "[]" | ("[" elements "]")
elements  ::=  value | (value "," elements)
value     ::=  string | number | object
                | array | true | false | null
property kind

File format of current dumper.

Return type:

Literal[‘json’]

__init__(fname, **kwargs)[source]

Initialise dumper.

Parameters:
  • fname (str) – output file name

  • **kwargs – addition keyword arguments for initialisation

_encode_value(o)[source]

Check content type for function call.

Parameters:

o (Any) – object to convert

Returns:

the converted object

Return type:

Any

See also

The function is a direct wrapper for object_hook().

Notes

The function will by default converts bytearray, memoryview, tuple, set, frozenset to JSON serialisable data.

_append_value(value, file, name)[source]

Call this function to write contents.

Parameters:
  • value (Dict[str, Any]) – content to be dumped

  • file (io.TextIOWrapper) – output file

  • name (str) – name of current content block

_append_object(value, file)[source]

Call this function to write object contents.

Parameters:
_append_array(value, file)[source]

Call this function to write array contents.

Parameters:
  • value (List[Any]) – content to be dumped

  • file (io.TextIOWrapper) – output file

_append_string(value, file)[source]

Call this function to write string contents.

Parameters:
_append_date(value, file)[source]

Call this function to write date contents.

Parameters:
_append_number(value, file)[source]

Call this function to write number contents.

Parameters:
_append_bool(value, file)[source]

Call this function to write bool contents.

Parameters:
_append_null(value, file)[source]

Call this function to write null contents.

Parameters:
class dictdumper.PLIST(fname, **kwargs)[source]

Bases: XML

Dump Apple property list (PLIST) format file.

>>> dumper = PLIST(file_name)
>>> dumper(content_dict_1, name=content_name_1)
>>> dumper(content_dict_2, name=content_name_2)
............
Variables:
  • _file (str) – output file name

  • _sptr (int) – indicates start of appending point (file pointer)

  • _tctr (int) – tab level counter

  • _hsrt (str) – start string (_HEADER_START)

  • _hend (str) – end string (_HEADER_END)

Note

Terminology:

value    ::=  array | dict | string | data
                | date | integer | real | bool
array    ::=  "<array>" value* "</array>"
dict     ::=  "<dict>" ("<key>" str "</key>" value)* "</dict>"
string   ::=  "<string>" str "</string>"
data     ::=  "<data>" bytes "</data>"
date     ::=  "<date>" datetime "</date>"
integer  ::=  "<integer>" int "</integer>"
real     ::=  "<real>" float "</real>"
bool     ::=  "<true/>" | "<false/>"
property kind

File format of current dumper.

Return type:

Literal[‘plist’]

_encode_value(o)[source]

Check content type for function call.

Parameters:

o (Any) – object to convert

Returns:

the converted object

Return type:

Any

See also

The function is a direct wrapper for object_hook().

Notes

The function will by default converts bytearray, None, memoryview, tuple, set, frozenset to PLIST serialisable data.

_append_value(value, file, name)[source]

Call this function to write contents.

Parameters:
  • value (Dict[str, Any]) – content to be dumped

  • file (io.TextIOWrapper) – output file

  • name (str) – name of current content block

_append_dict(value, file)[source]

Call this function to write dict contents.

Parameters:
_append_array(value, file)[source]

Call this function to write array contents.

Parameters:
  • value (List[Any]) – content to be dumped

  • file (io.TextIOWrapper) – output file

_append_string(value, file)[source]

Call this function to write string contents.

Parameters:
_append_data(value, file)[source]

Call this function to write data contents.

Parameters:
_append_date(value, file)[source]

Call this function to write date contents.

Parameters:
_append_integer(value, file)[source]

Call this function to write integer contents.

Parameters:
_append_real(value, file)[source]

Call this function to write real contents.

Parameters:
_append_bool(value, file)[source]

Call this function to write bool contents.

Parameters:
class dictdumper.Tree(fname, **kwargs)[source]

Bases: Dumper

Dump a tree-view text (TXT) format file.

>>> dumper = Tree(filename)
>>> dumper(content_dict_1, name=contentname_1)
>>> dumper(content_dict_2, name=contentname_2)
............
Variables:
  • _file (str) – output file name

  • _sptr (int) – indicates start of appending point (file pointer)

  • _tctr (int) – tab level counter

  • _hsrt (str) – start string (_HEADER_START)

  • _hend (str) – end string (_HEADER_END)

  • _bctx (List[str]) – blank branch (indentation) context record

  • _nctr (int) – branch number counter

Note

Terminology:

value   ::=  branch | array | string | number | bool | N/A
string
|-- string
|     |-- string -> value
|     |-- string
|     |     |-- string -> value
|     |     |-- string -> value
|     |-- string -> value
|     |-- string -> value
|           |-- string -> value
|           |-- string -> value
|-- string -> value, value, value
|-- string -> True
|-- string -> False
|-- string -> N/A
|-- string -> value
|-- string -> value
property kind

File format of current dumper.

Return type:

Literal[‘txt’]

static check_newline(value)[source]

Check if newline is needed.

Parameters:

value (Union[Dict[str, Any], AnyStr]) – value to check if new line is needed

Returns:

if newline is needed

Return type:

bool

Notes

Newline is needed if

  1. value is a dict

  2. value is string (str) and its length is greater than 32 distinct characters

  3. value is bytestring (bytes) and the length of its hex representation is greater than 40 distinct characters

_encode_value(o)[source]

Convert content for function call.

Parameters:

o (Any) – object to convert

Returns:

the converted object

Return type:

Any

See also

The function is a direct wrapper for object_hook().

Notes

The function will by default converts bytearray, memoryview, tuple, set, frozenset to tree-view represetable data.

_append_value(value, file, name)[source]

Call this function to write contents.

Parameters:
  • value (Dict[str, Any]) – content to be dumped

  • file (io.TextIOWrapper) – output file

  • name (str) – name of current content block

_append_branch(value, file)[source]

Call this function to write branch contents.

Parameters:
_append_array(value, file)[source]

Call this function to write array contents.

Parameters:
  • value (List[Any]) – content to be dumped

  • file (io.TextIOWrapper) – output file

_append_string(value, file)[source]

Call this function to write string contents.

Parameters:
_append_bytes(value, file)[source]

Call this function to write bytes contents.

Parameters:
_append_date(value, file)[source]

Call this function to write date contents.

Parameters:
_append_number(value, file)[source]

Call this function to write number contents.

Parameters:
_append_bool(value, file)[source]

Call this function to write bool contents.

Parameters:
_append_none(value, file)[source]

Call this function to write none contents.

Parameters: