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)¶ 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, file pointer) – indicates start of appending point_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
-
__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.
- Type
Tuple[Tuple[type, str]]
-
_tctr= 1¶ Tab level counter.
- Type
int
-
_hsrt= ''¶ Tree-view head string.
-
_hend= ''¶ Tree-view tail string.
-
_nctr= 0¶ Branch number counter.
- Type
int
-
_bctx= []¶ Blank branch (indentation) context record.
- Type
List[str]
-
property
kind¶ str: File format of current dumper.
-
static
check_newline(value)¶ 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
valueis adictvalueis string (str) and its length is greater than 32 distinct charactersvalueis bytestring (bytes) and the length of its hex representation is greater than 40 distinct characters
-
_encode_value(o)¶ 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)¶ Call this function to write contents.
- Parameters
value (
Dict[str, Any]) – content to be dumpedfile (
fileobject) – output filename (str) – name of current content block
-
_append_branch(value, file)¶ Call this function to write branch contents.
- Parameters
value (
Dict[str, Any]) – content to be dumpedfile (
fileobject) – output file
-
_append_array(value, file)¶ Call this function to write array contents.
- Parameters
value (
List[Any]) – content to be dumpedfile (
fileobject) – output file
-
_append_string(value, file)¶ Call this function to write string contents.
- Parameters
value (str) – content to be dumped
file (
fileobject) – output file
-
_append_bytes(value, file)¶ Call this function to write bytes contents.
- Parameters
value (bytes) – content to be dumped
file (
fileobject) – output file
-
_append_date(value, file)¶ Call this function to write date contents.
- Parameters
value (
Union[datetime.date, datetime.datetime, datetime.time]) – content to be dumpedfile (
fileobject) – output file
-
_append_number(value, file)¶ Call this function to write number contents.
- Parameters
value (
Union[int, float, complex]) – content to be dumpedfile (
fileobject) – output file
-
_append_bool(value, file)¶ Call this function to write bool contents.
- Parameters
value (bool) – content to be dumped
file (
fileobject) – output file
-
_append_none(value, file)¶ Call this function to write none contents.
- Parameters
value (
None) – content to be dumpedfile (
fileobject) – output file
Internal utilities¶
-
dictdumper.tree.indent(ctx, branch=True)¶ 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