anyconfig.backend.base.loaders
¶
Abstract and basic loaders.
- class anyconfig.backend.base.loaders.LoaderMixin¶
Bases:
object
Mixin class to load data.
Inherited classes must implement the following methods.
load_from_string()
: Load config from stringload_from_stream()
: Load config from a file or file-like objectload_from_path()
: Load config from file of given path
Member variables:
_load_opts: Backend specific options on load
_ordered: True if the parser keep the order of items by default
_allow_primitives: True if the parser.load* may return objects of primitive data types other than mapping types such like JSON parser
_dict_opts: Backend options to customize dict class to make results
_open_read_mode: Backend option to specify read mode passed to open()
- classmethod ordered()¶
Test if the parser keeps the order of the data.
- Return type:
bool
- classmethod allow_primitives()¶
Test if the paresr allows to hold primitive data.
- Return type:
bool
- Returns:
True if the parser.load* may return objects of primitive data types other than mapping types such like JSON parser
- classmethod dict_options()¶
Get the list of dict factory options.
- Return type:
tuple
[str
,...
]
- ropen(filepath, **options)¶
Open files with read only mode.
- Return type:
IO
- load_from_string(content, container, **options)¶
Load config from given string ‘content’.
- Parameters:
content (
str
) – Config content stringcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters
- load_from_path(filepath, container, **options)¶
Load config from given file path ‘filepath`.
- Parameters:
filepath (
Union
[str
,Path
]) – Config file pathcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters
- load_from_stream(stream, container, **options)¶
Load config from given file like object ‘stream`.
- Parameters:
stream (
IO
) – Config file or file like objectcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters
- loads(content, **options)¶
Load config from given string ‘content’ after some checks.
- Parameters:
content (
str
) – Config file contentoptions – options will be passed to backend specific loading functions. please note that options have to be sanitized w/
anyconfig.utils.filter_options()
later to filter out options not in _load_opts.
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
dict or dict-like object holding configurations
- load(ioi, *, ac_ignore_missing=False, **options)¶
Load config from
ioi
.- Parameters:
ioi (
IOInfo
) – ‘anyconfig.ioinfo.IOInfo’ namedtuple object provides various info of input object to load data fromac_ignore_missing (
bool
) – Ignore and just return empty result if given ioi object does not exist in actual.options – options will be passed to backend specific loading functions. please note that options have to be sanitized w/
anyconfig.utils.filter_options()
later to filter out options not in _load_opts.
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
dict or dict-like object holding configurations
- class anyconfig.backend.base.loaders.BinaryLoaderMixin¶
Bases:
LoaderMixin
Mixin class to load binary (byte string) configuration files.
- class anyconfig.backend.base.loaders.FromStringLoaderMixin¶
Bases:
LoaderMixin
Abstract parser provides a method below.
amethod to load configuration from string content to help implement parser of which backend lacks of such function.
Parser classes inherit this class have to override the method
load_from_string()
at least.- load_from_stream(stream, container, **options)¶
Load config from given stream ‘stream’.
- Parameters:
stream (
IO
) – Config file or file-like objectcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters
- load_from_path(filepath, container, **options)¶
Load config from given file path ‘filepath’.
- Parameters:
filepath (
Union
[str
,Path
]) – Config file pathcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters
- class anyconfig.backend.base.loaders.FromStreamLoaderMixin¶
Bases:
LoaderMixin
Abstract parser provides a method below.
A method to load configuration from string content to help implement parser of which backend lacks of such function.
Parser classes inherit this class have to override the method
load_from_stream()
at least.- load_from_string(content, container, **options)¶
Load config from given string ‘cnf_content’.
- Parameters:
content (
str
) – Config content stringcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters
- load_from_path(filepath, container, **options)¶
Load config from given file path ‘filepath’.
- Parameters:
filepath (
Union
[str
,Path
]) – Config file pathcontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container object lateroptions – optional keyword parameters to be sanitized :: dict
- Return type:
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]- Returns:
Dict-like object holding config parameters