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)[source]

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
  • _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)

__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

File format of current dumper.

Return type

str

property filename

Output file name.

Return type

str

static make_object(o, value, **kwargs)[source]

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)[source]

Convert content for function call.

Parameters

o (Any) – object to convert

Returns

the converted object

Return type

Any

default(o)[source]

Check content type for function call.

Parameters

o (Any) – object to check

Raises

DumperErroro is an unsupported content type

__init__(fname, **kwargs)[source]

Initialise dumper.

Parameters
  • fname (str) – output file name

  • **kwargs – addition keyword arguments for initialisation

__call__(value, name=None)[source]

Dumper a new block.

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

  • name (v) – name of current content block

Returns

the dumper class itself (to support chain calling)

Return type

Dumper

_dump_header(**kwargs)[source]

Initially dump file heads and tails.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

_encode_func(o)[source]

Check content type for function call.

Parameters

o (Any) – object to check

See also

If the type of o is not defined in __type__, the function refers to default() for custom hooks.

_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().

abstract _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

Internal utilities

dictdumper.dumper.deprecated(cls)[source]

Deprecation warning.

Parameters

cls (object) – the class to mark as deprecated

Returns

The original cls itself.

Return type

object

exception dictdumper.dumper.DumperError[source]

Bases: TypeError

Unsupported content type.