DictDumper package¶
Table of Contents¶
- Base Dumper
- Tree-View Dumper
- Dumper class
Tree
Tree.__type__
Tree._tctr
Tree._hsrt
Tree._hend
Tree._nctr
Tree._bctx
Tree.kind
Tree.check_newline()
Tree._encode_value()
Tree._append_value()
Tree._append_branch()
Tree._append_array()
Tree._append_string()
Tree._append_bytes()
Tree._append_date()
Tree._append_number()
Tree._append_bool()
Tree._append_none()
- Internal utilities
- Dumper class
- Base XML Dumper
- PLIST Dumper
- JSON Dumper
- Vue.js Dumper (DEPRECATED)
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:
-
Abstract base class of all dumpers.
-
Dump JavaScript object notation (
JSON
) format file. -
Dump Apple property list (
PLIST
) format file. -
Dump tree-view text (
TXT
) format file. -
Dump extensible markup language (
XML
) file; this is an abstract base class -
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
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:
value (Dict[str, Any]) – content to be dumped
file (io.TextIOWrapper) – output file
- _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:
value (str) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_date(value, file)[source]
Call this function to write date contents.
- Parameters:
value (Union[datetime.date, datetime.datetime, datetime.time]) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_number(value, file)[source]
Call this function to write number contents.
- Parameters:
file (io.TextIOWrapper) – output file
- _append_bool(value, file)[source]
Call this function to write bool contents.
- Parameters:
value (bool) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_null(value, file)[source]
Call this function to write null contents.
- Parameters:
value (None) – content to be dumped
file (io.TextIOWrapper) – output file
- 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:
value (Dict[str, Any]) – content to be dumped
file (io.TextIOWrapper) – output file
- _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:
value (str) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_data(value, file)[source]
Call this function to write data contents.
- Parameters:
value (bytes) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_date(value, file)[source]
Call this function to write date contents.
- Parameters:
value (Union[datetime.date, datetime.datetime]) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_integer(value, file)[source]
Call this function to write integer contents.
- Parameters:
value (int) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_real(value, file)[source]
Call this function to write real contents.
- Parameters:
value (float) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_bool(value, file)[source]
Call this function to write bool contents.
- Parameters:
value (bool) – content to be dumped
file (io.TextIOWrapper) – output file
- 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.
- _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:
value (Dict[str, Any]) – content to be dumped
file (io.TextIOWrapper) – output file
- _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:
value (str) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_bytes(value, file)[source]
Call this function to write bytes contents.
- Parameters:
value (bytes) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_date(value, file)[source]
Call this function to write date contents.
- Parameters:
value (Union[datetime.date, datetime.datetime, datetime.time]) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_number(value, file)[source]
Call this function to write number contents.
- Parameters:
file (io.TextIOWrapper) – output file
- _append_bool(value, file)[source]
Call this function to write bool contents.
- Parameters:
value (bool) – content to be dumped
file (io.TextIOWrapper) – output file
- _append_none(value, file)[source]
Call this function to write none contents.
- Parameters:
value (None) – content to be dumped
file (io.TextIOWrapper) – output file