anyconfig.backend.sh.variables
¶
A simple backend module to load and dump files contain shell variables.
Format to support: Simple shell variables’ definitions w/o any shell variable expansions nor complex shell statements such as conditionals, etc.
Requirements: None (built-in)
Development Status :: 4 - Beta
Limitations: Currently, it only supports a varialbe defined in a line.
Special options: None
Changelog:
Added in version 0.7.0:
Added an experimental parser for simple shelll vars’ definitions w/o shell variable expansions nor complex shell statements like conditionals.
- anyconfig.backend.sh.variables._parseline(line)¶
Parse a line contains shell variable definition.
- Parameters:
line (
str
) – A string to parse, must not start with ‘#’ (comment)- Return type:
tuple
[Optional
[str
],Optional
[str
]]- Returns:
A tuple of (key, value), both key and value may be None
- anyconfig.backend.sh.variables.load(stream, container=<class 'dict'>, **_kwargs)¶
Load shell variable definitions data from
stream
.- Parameters:
stream (
IO
) – A file or file like objectcontainer (
Callable
[...
,dict
[str
,Any
]]) – Factory function to create a dict-like object to store properties
- Return type:
dict
[str
,Any
]- Returns:
Dict-like object holding shell variables’ definitions
- class anyconfig.backend.sh.variables.Parser¶
Bases:
StreamParser
Parser for Shell variable definition files.
-
_cid:
ClassVar
[str
] = 'sh.variables'¶
-
_type:
ClassVar
[str
] = 'shellvars'¶
-
_extensions:
tuple
[str
,...
] = ('sh',)¶
-
_ordered:
ClassVar
[bool
] = True¶
-
_dict_opts:
tuple
[str
,...
] = ('ac_dict',)¶
- load_from_stream(stream, container, **kwargs)¶
Load config from given file like object
stream
.- Parameters:
stream (
IO
) – A file or file like object of shell scripts define shell variablescontainer (
Callable
[...
,dict
[str
,Any
]]) – callble to make a container objectkwargs – optional keyword parameters (ignored)
- Return type:
dict
[str
,Any
]- Returns:
Dict-like object holding config parameters
- dump_to_stream(cnf, stream, **_kwargs)¶
Dump config dat
cnf
to a file or file-like objectstream
.- Parameters:
cnf (
Union
[None
,int
,float
,bool
,str
,dict
[str
,Any
]]) – Shell variables data to dumpstream (
IO
) – Shell script file or file like objectkwargs – backend-specific optional keyword parameters :: dict
- Return type:
None
- __annotations__ = {'_allow_primitives': 'typing.ClassVar[bool]', '_cid': 'typing.ClassVar[str]', '_dict_opts': 'tuple[str, ...]', '_dump_opts': 'tuple[str, ...]', '_extensions': 'tuple[str, ...]', '_load_opts': 'tuple[str, ...]', '_open_read_mode': 'typing.ClassVar[str]', '_open_write_mode': 'typing.ClassVar[str]', '_ordered': 'typing.ClassVar[bool]', '_priority': 'typing.ClassVar[int]', '_type': 'typing.ClassVar[str]'}¶
- __module__ = 'anyconfig.backend.sh.variables'¶
-
_cid: