satella.configuration.schema package¶
Submodules¶
satella.configuration.schema.base module¶
- class satella.configuration.schema.base.CheckerCondition(condition, description='', is_pre_checker=True)¶
Bases:
object
- Parameters:
condition (Callable[[Optional[Union[int, float, str, dict, list, bool]]], bool]) –
description (str) –
is_pre_checker (bool) –
- POST_CHECKER = 1¶
- PRE_CHECKER = 0¶
- condition¶
- description¶
- is_pre_checker¶
- class satella.configuration.schema.base.Descriptor¶
Bases:
object
Base class for a descriptor
- static BASIC_MAKER(v)¶
- CHECKERS = []¶
- MY_EXCEPTIONS = [<class 'TypeError'>, <class 'ValueError'>]¶
- add_checker(checker)¶
- Parameters:
checker (CheckerCondition) –
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- satella.configuration.schema.base.must_be_one_of(*items)¶
- satella.configuration.schema.base.must_be_type(*cls_or_tuple)¶
satella.configuration.schema.basic module¶
- class satella.configuration.schema.basic.Boolean¶
Bases:
Descriptor
This value must be a boolean, or be converted to one
- static BASIC_MAKER(v)¶
- Parameters:
v (Any) –
- Return type:
bool
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.basic.Directory¶
Bases:
Descriptor
This value must be a valid path to a file. The value in your schema will be an instance of
FileObject
- static BASIC_MAKER(v)¶
- Parameters:
v (str) –
- Return type:
bool
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.basic.DirectoryObject(path)¶
Bases:
object
What you get for values in schema of
Directory
.This object is comparable and hashable, and is equal to the string of it’s path
- Parameters:
path (str) –
- get_files()¶
Return a list of files inside this directory :return:
- Return type:
Iterable[str]
- path¶
- class satella.configuration.schema.basic.File¶
Bases:
Descriptor
This value must be a valid path to a file. The value in your schema will be an instance of
FileObject
- static BASIC_MAKER(v)¶
- Parameters:
v (str) –
- Return type:
bool
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.basic.FileContents(encoding=None, strip_afterwards=False)¶
Bases:
Descriptor
This value must be a valid path to a file. The value in your schema will be the contents of this file, applied with encoding (if given). By default, bytes will be read in
- Parameters:
encoding (Optional[str]) –
strip_afterwards (bool) –
- BASIC_MAKER(c)¶
- Parameters:
c (str) –
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.basic.FileObject(path)¶
Bases:
object
What you get for values in schema of
File
.This object is comparable and hashable, and is equal to the string of it’s path
- Parameters:
path (str) –
- get_value(encoding=None)¶
Read in the entire file into memory
- Parameters:
encoding (Optional[str]) – optional encoding to apply. If None given, bytes will be returned
- Returns:
file contents
- Return type:
Union[str, bytes]
- open(mode)¶
Open the file in specified mode
- Parameters:
mode (str) – mode to open the file in
- Returns:
file handle
- path¶
- class satella.configuration.schema.basic.Float¶
Bases:
Descriptor
This value must be a float, or be converted to one
- BASIC_MAKER¶
alias of
float
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.basic.IPv4¶
Bases:
Regexp
This must be a valid IPv4 address (no hostnames allowed)
- REGEXP = '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'¶
- regexp¶
- class satella.configuration.schema.basic.Integer¶
Bases:
Descriptor
This value must be an integer, or be converted to one
- BASIC_MAKER¶
alias of
int
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.basic.Regexp¶
Bases:
String
Base class for declaring regexp-based descriptors. Overload it’s attribute REGEXP. Use as following:
>>> class IPv6(Regexp): >>> REGEXP = '(([0-9a-f]{1,4}:)' ...
- REGEXP = '.*'¶
- regexp¶
- class satella.configuration.schema.basic.String¶
Bases:
Descriptor
This value must be a string, or be converted to one
- BASIC_MAKER¶
alias of
str
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
satella.configuration.schema.from_json module¶
- satella.configuration.schema.from_json.descriptor_from_dict(dct)¶
Giving a Python dictionary-defined schema of the configuration, return a Descriptor-based one
- Parameters:
dct (dict) – something like
- Return type:
- {
“a”: “int”, “b”: “str”, “c”: {
“type”: “int” “optional”: True, “default”: 5
}, “d”: {
“a”: “int”, “b”: “str”
}
}
although you can pass “int”, “float” and “str” without enclosing quotes, that will work too
- Returns:
a Descriptor-based schema
- Parameters:
dct (dict) –
- Return type:
satella.configuration.schema.registry module¶
- satella.configuration.schema.registry.register_custom_descriptor(name, is_plain=True)¶
A decorator used for registering custom descriptors in order to be loadable via descriptor_from_dict
Use like:
>>> @register_custom_descriptor('ipv6') >>> class IPv6(Regexp): >>> REGEXP = '(([0-9a-f]{1,4}:)' ...
- Parameters:
name (str) – under which it is supposed to be invokable
is_plain (bool) – is this a nested structure?
satella.configuration.schema.structs module¶
- class satella.configuration.schema.structs.Caster(to_cast)¶
Bases:
Descriptor
A value must be ran through a function.
Use like:
>>> class Environment(enum.IntEnum): >>> PRODUCTION = 0 >>> assert Caster(Environment)(0) == Environment.PRODUCTION
- Parameters:
to_cast (Callable[[Any], Any]) –
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.structs.Dict(keys, unknown_key_mapper=<function Dict.<lambda>>)¶
Bases:
Descriptor
This entry must be a dict, having at least specified keys.
Use like:
>>> Dict([ >>> create_key(String(), 'key_s'), >>> create_key(Integer(), 'key_i'), >>> create_key(Float(), 'key_f'), >>> create_key(String(), 'key_not_present', optional=True, >>> default='hello world'), >>> create_key(IPv4(), 'ip_addr') >>>])
- Parameters:
keys (List[DictDescriptorKey]) –
unknown_key_mapper (Callable[[str, Optional[Union[int, float, str, dict, list, bool]]], Any]) –
- BASIC_MAKER¶
alias of
dict
- CHECKERS = [<satella.configuration.schema.base.CheckerCondition object>]¶
- UnknownKeyHandlerType¶
alias of
Callable
[[str
,Optional
[Union
[int
,float
,str
,dict
,list
,bool
]]],Any
]
- keys: Dict[str, DictDescriptorKey]¶
- unknown_key_mapper¶
- class satella.configuration.schema.structs.List(type_descriptor=None)¶
Bases:
Descriptor
This must be a list, made of entries of a descriptor (this is optional)
- Parameters:
type_descriptor (Optional[Descriptor]) –
- BASIC_MAKER¶
alias of
list
- CHECKERS = [<satella.configuration.schema.base.CheckerCondition object>]¶
- type_descriptor: Descriptor¶
- class satella.configuration.schema.structs.Union(*descriptors)¶
Bases:
Descriptor
The type of one of the child descriptors. If posed as such:
Union(List(), Dict())
then value can be either a list or a dict
- Parameters:
descriptors (List[Descriptor]) –
- descriptors¶
- satella.configuration.schema.structs.create_key(descriptor, name, optional=False, default=None)¶
- Parameters:
descriptor (Descriptor) –
name (str) –
optional (bool) –
default (Optional[Any]) –
- Return type:
DictDescriptorKey
Module contents¶
- class satella.configuration.schema.Boolean¶
Bases:
Descriptor
This value must be a boolean, or be converted to one
- static BASIC_MAKER(v)¶
- Parameters:
v (Any) –
- Return type:
bool
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.Caster(to_cast)¶
Bases:
Descriptor
A value must be ran through a function.
Use like:
>>> class Environment(enum.IntEnum): >>> PRODUCTION = 0 >>> assert Caster(Environment)(0) == Environment.PRODUCTION
- Parameters:
to_cast (Callable[[Any], Any]) –
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.CheckerCondition(condition, description='', is_pre_checker=True)¶
Bases:
object
- Parameters:
condition (Callable[[Optional[Union[int, float, str, dict, list, bool]]], bool]) –
description (str) –
is_pre_checker (bool) –
- POST_CHECKER = 1¶
- PRE_CHECKER = 0¶
- condition¶
- description¶
- is_pre_checker¶
- class satella.configuration.schema.Descriptor¶
Bases:
object
Base class for a descriptor
- static BASIC_MAKER(v)¶
- CHECKERS = []¶
- MY_EXCEPTIONS = [<class 'TypeError'>, <class 'ValueError'>]¶
- add_checker(checker)¶
- Parameters:
checker (CheckerCondition) –
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.Dict(keys, unknown_key_mapper=<function Dict.<lambda>>)¶
Bases:
Descriptor
This entry must be a dict, having at least specified keys.
Use like:
>>> Dict([ >>> create_key(String(), 'key_s'), >>> create_key(Integer(), 'key_i'), >>> create_key(Float(), 'key_f'), >>> create_key(String(), 'key_not_present', optional=True, >>> default='hello world'), >>> create_key(IPv4(), 'ip_addr') >>>])
- Parameters:
keys (Dict[str, DictDescriptorKey]) –
unknown_key_mapper (Callable[[str, Optional[Union[int, float, str, dict, list, bool]]], Any]) –
- BASIC_MAKER¶
alias of
dict
- CHECKERS = [<satella.configuration.schema.base.CheckerCondition object>]¶
- UnknownKeyHandlerType¶
alias of
Callable
[[str
,Optional
[Union
[int
,float
,str
,dict
,list
,bool
]]],Any
]
- keys: Dict[str, DictDescriptorKey]¶
- unknown_key_mapper¶
- class satella.configuration.schema.Directory¶
Bases:
Descriptor
This value must be a valid path to a file. The value in your schema will be an instance of
FileObject
- static BASIC_MAKER(v)¶
- Parameters:
v (str) –
- Return type:
bool
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.DirectoryObject(path)¶
Bases:
object
What you get for values in schema of
Directory
.This object is comparable and hashable, and is equal to the string of it’s path
- Parameters:
path (str) –
- get_files()¶
Return a list of files inside this directory :return:
- Return type:
Iterable[str]
- path¶
- class satella.configuration.schema.File¶
Bases:
Descriptor
This value must be a valid path to a file. The value in your schema will be an instance of
FileObject
- static BASIC_MAKER(v)¶
- Parameters:
v (str) –
- Return type:
bool
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.FileContents(encoding=None, strip_afterwards=False)¶
Bases:
Descriptor
This value must be a valid path to a file. The value in your schema will be the contents of this file, applied with encoding (if given). By default, bytes will be read in
- Parameters:
encoding (Optional[str]) –
strip_afterwards (bool) –
- BASIC_MAKER(c)¶
- Parameters:
c (str) –
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.FileObject(path)¶
Bases:
object
What you get for values in schema of
File
.This object is comparable and hashable, and is equal to the string of it’s path
- Parameters:
path (str) –
- get_value(encoding=None)¶
Read in the entire file into memory
- Parameters:
encoding (Optional[str]) – optional encoding to apply. If None given, bytes will be returned
- Returns:
file contents
- Return type:
Union[str, bytes]
- open(mode)¶
Open the file in specified mode
- Parameters:
mode (str) – mode to open the file in
- Returns:
file handle
- path¶
- class satella.configuration.schema.Float¶
Bases:
Descriptor
This value must be a float, or be converted to one
- BASIC_MAKER¶
alias of
float
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.IPv4¶
Bases:
Regexp
This must be a valid IPv4 address (no hostnames allowed)
- REGEXP = '\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}'¶
- regexp¶
- class satella.configuration.schema.Integer¶
Bases:
Descriptor
This value must be an integer, or be converted to one
- BASIC_MAKER¶
alias of
int
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.List(type_descriptor=None)¶
Bases:
Descriptor
This must be a list, made of entries of a descriptor (this is optional)
- Parameters:
type_descriptor (Descriptor) –
- BASIC_MAKER¶
alias of
list
- CHECKERS = [<satella.configuration.schema.base.CheckerCondition object>]¶
- type_descriptor: Descriptor¶
- class satella.configuration.schema.Regexp¶
Bases:
String
Base class for declaring regexp-based descriptors. Overload it’s attribute REGEXP. Use as following:
>>> class IPv6(Regexp): >>> REGEXP = '(([0-9a-f]{1,4}:)' ...
- REGEXP = '.*'¶
- regexp¶
- class satella.configuration.schema.String¶
Bases:
Descriptor
This value must be a string, or be converted to one
- BASIC_MAKER¶
alias of
str
- default: Optional[Any]¶
- my_exceptions: Tuple[Type[Exception], ...]¶
- name: Optional[str]¶
- optional: Optional[bool]¶
- post_checkers: Callable[[bool], None]¶
- pre_checkers: Callable[[bool], None]¶
- class satella.configuration.schema.Union(*descriptors)¶
Bases:
Descriptor
The type of one of the child descriptors. If posed as such:
Union(List(), Dict())
then value can be either a list or a dict
- Parameters:
descriptors (List[Descriptor]) –
- descriptors¶
- satella.configuration.schema.create_key(descriptor, name, optional=False, default=None)¶
- Parameters:
descriptor (Descriptor) –
name (str) –
optional (bool) –
default (Optional[Any]) –
- Return type:
DictDescriptorKey
- satella.configuration.schema.descriptor_from_dict(dct)¶
Giving a Python dictionary-defined schema of the configuration, return a Descriptor-based one
- Parameters:
dct (dict) – something like
- Return type:
- {
“a”: “int”, “b”: “str”, “c”: {
“type”: “int” “optional”: True, “default”: 5
}, “d”: {
“a”: “int”, “b”: “str”
}
}
although you can pass “int”, “float” and “str” without enclosing quotes, that will work too
- Returns:
a Descriptor-based schema
- Parameters:
dct (dict) –
- Return type:
- satella.configuration.schema.register_custom_descriptor(name, is_plain=True)¶
A decorator used for registering custom descriptors in order to be loadable via descriptor_from_dict
Use like:
>>> @register_custom_descriptor('ipv6') >>> class IPv6(Regexp): >>> REGEXP = '(([0-9a-f]{1,4}:)' ...
- Parameters:
name (str) – under which it is supposed to be invokable
is_plain (bool) – is this a nested structure?