Tree-View Dumper¶
dictdumper.tree contains Tree
only, which dumpers a tree-view text (TXT) format file. Usage
sample is described as below.
>>> dumper = Tree(filename)
>>> dumper(content_dict_1, name=contentname_1)
>>> dumper(content_dict_2, name=contentname_2)
............
Dumper class¶
-
class
dictdumper.tree.Tree(fname, **kwargs)[source]¶ Bases:
dictdumper.dumper.DumperDump 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)
_hsrt (str) – start string (
_HEADER_START)_hend (str) – end string (
_HEADER_END)_bctx (List[str]) – blank branch (indentation) context record
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
-
__type__= ((<class 'str'>, 'string'), (<class 'bool'>, 'bool'), (<class 'dict'>, 'branch'), (<class 'NoneType'>, 'none'), (<class 'datetime.date'>, 'date'), (<class 'datetime.datetime'>, 'date'), (<class 'datetime.time'>, 'date'), (<class 'int'>, 'number'), (<class 'float'>, 'number'), (<class 'complex'>, 'number'), (<class 'bytes'>, 'bytes'), (<class 'list'>, 'array'))¶ Type codes.
-
_hsrt= ''¶ Tree-view head string.
-
_hend= ''¶ Tree-view tail string.
-
property
kind¶ File format of current dumper.
- Return type
Literal[‘txt’]
-
_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,frozensetto 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
Internal utilities¶
-
dictdumper.tree.indent(ctx, branch=True)[source]¶ Indentation context.
- Parameters
ctx (
List[str]) – indentation contextbranch (bool) – if
Truepush the branch template (_TEMP_BRANCH) to the context, else push the spaces template (_TEMP_SPACES)
- Yields
None– temporarily push a template to the context
-
dictdumper.tree._HEADER_START= ''¶ Tree-view head string.
-
dictdumper.tree._HEADER_END= ''¶ Tree-view tail string.
-
dictdumper.tree._TEMP_BRANCH= ' | '¶ Branch template
-
dictdumper.tree._TEMP_SPACES= ' '¶ Spaces template