anyconfig.backend.base.dumpers¶
Abstract and basic dumpes.
- class anyconfig.backend.base.dumpers.DumperMixin¶
Bases:
objectMixin class to dump data.
Inherited classes must implement the following methods.
dump_to_string(): Dump config as a stringdump_to_stream(): Dump config to a file or file-like objectdump_to_path(): Dump config to a file of given path
Member variables:
_dump_opts: Backend specific options on dump
_open_write_mode: Backend option to specify write mode passed to open()
- wopen(filepath, **options)¶
Open file
filepathwith the write mode_open_write_mode.- Return type:
IO
- dump_to_string(cnf, **options)¶
Dump config ‘cnf’ to a string.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
str- Returns:
string represents the configuration
- dump_to_path(cnf, filepath, **options)¶
Dump config ‘cnf’ to a file ‘filepath’.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpfilepath (
Union[str,Path]) – Config file pathoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
None
- dump_to_stream(cnf, stream, **options)¶
Dump config ‘cnf’ to a file-like object ‘stream’.
TODO: How to process socket objects same as file objects ?
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpstream (
IO) – Config file or file like objectoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
None
- dumps(cnf, **options)¶
Dump config ‘cnf’ to a string.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
str- Returns:
string represents the configuration
- dump(cnf, ioi, **options)¶
Dump config ‘cnf’ to output object of which ‘ioi’ referring.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpioi (
IOInfo) – an ‘anyconfig.cmmon.IOInfo’ namedtuple object provides various info of input object to load data fromoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Raises:
IOError, OSError, AttributeError – When dump failed.
- Return type:
None
- class anyconfig.backend.base.dumpers.BinaryDumperMixin¶
Bases:
DumperMixinMixin class to dump binary (byte string) configuration data.
- class anyconfig.backend.base.dumpers.ToStringDumperMixin¶
Bases:
DumperMixinAbstract config parser provides the followings.
a method to dump configuration to a file or file-like object (stream) and a file of given path to help implement parser of which backend lacks of such functions.
Parser classes inherit this class have to override the method
dump_to_string()at least.- dump_to_path(cnf, filepath, **options)¶
Dump config ‘cnf’ to a file ‘filepath’.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpfilepath (
Union[str,Path]) – Config file pathoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
None
- dump_to_stream(cnf, stream, **options)¶
Dump config ‘cnf’ to a file-like object ‘stream’.
TODO: How to process socket objects same as file objects ?
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpstream (
IO) – Config file or file like objectoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
None
- class anyconfig.backend.base.dumpers.ToStreamDumperMixin¶
Bases:
DumperMixinAbstract config parser provides the following methods.
to dump configuration to a string content or a file of given path to help implement parser of which backend lacks of such functions.
Parser classes inherit this class have to override the method
dump_to_stream()at least.- dump_to_string(cnf, **options)¶
Dump config ‘cnf’ to a string.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
str- Returns:
Dict-like object holding config parameters
- dump_to_path(cnf, filepath, **options)¶
Dump config ‘cnf’ to a file ‘filepath`.
- Parameters:
cnf (
Union[None,int,float,bool,str,dict[str,Any]]) – Configuration data to dumpfilepath (
Union[str,Path]) – Config file pathoptions (
Any) – optional keyword parameters to be sanitized :: dict
- Return type:
None