Base Dumper¶
dumper
contains Dumper
only,
which is an abstract base class for all dumpers, eg. VueJS
,
JSON
, PLIST
,
Tree
, and XML
.
Dumper class¶
-
class
dictdumper.dumper.
Dumper
(fname, **kwargs)¶ Bases:
object
Abstract base class of all dumpers.
>>> dumper = Dumper(file_name) >>> dumper(content_dict_1, name=content_name_1) >>> dumper(content_dict_2, name=content_name_2) ............
- Variables
-
__type__
= ()¶ Type codes.
- Type
Tuple[Tuple[type, str]]
-
_tctr
= 1¶ Tab level counter.
- Type
int
-
_hsrt
= ''¶ Dumper head string.
-
_hend
= ''¶ Dumper tail string.
-
abstract property
kind
¶ str
: File format of current dumper.
-
property
filename
¶ str
: Output file name.
-
static
make_object
(o, value, **kwargs)¶ Create an object with convertion information.
- Parameters
o (Any) – object to convert
value (Any) – converted value of
o
**kwargs – additional information for the convertion
- Returns
Information context of the convertion.
- Return type
Dict[str, Any]
-
object_hook
(o)¶ Convert content for function call.
- Parameters
o (
Any
) – object to convert- Returns
the converted object
- Return type
Any
-
default
(o)¶ Check content type for function call.
- Parameters
o (
Any
) – object to check- Raises
DumperError –
o
is an unsupported content type
-
__init__
(fname, **kwargs)¶ Initialise dumper.
- Parameters
fname (str) – output file name
**kwargs – addition keyword arguments for initialisation
-
__call__
(value, name=None)¶ Dumper a new block.
- Parameters
value (
Dict[str, Any]
) – content to be dumpedname (
Optional[str]
) – name of current content block
- Returns
the dumper class itself (to support chain calling)
- Return type
-
_dump_header
()¶ Initially dump file heads and tails.
-
_encode_func
(o)¶ Check content type for function call.
- Parameters
o (
Any
) – object to check
-
_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()
.
-
abstract
_append_value
(value, file, name)¶ Call this function to write contents.
- Parameters
value (
Dict[str, Any]
) – content to be dumpedfile (
file
object) – output filename (str) – name of current content block