A section container used to store a mapping between name and other containers.
Parameters: | **kwargs – parameters used to override meta |
---|
Typically, this class has to be derived to specify accepted key for the section:
class MySection(Section):
a_key = Value(Integer())
A section can also be defined imperatively:
>>> section = MySection()
>>> section.add('another_key', Value(Integer()))
A section can hold some metadata, for example to define arguments schema or how many time the section can appear. This metadata can be defined in several different ways:
In the _meta dict of a section definition (metadata are inherited from parent classes):
class MySection(Section):
_meta = {'unique': True}
In the meta dict of a section object:
>>> section = MySection()
>>> section.meta['unique'] = True
In keyword parameters on instance initialization:
>>> section = MySection(unique=True)
The args metadata (default None) store the container used to validate the section argument (value between the section name and the opening brace). You can use any type of container but a Section.
If the metadata is set to None (the default), argument for the section is forbidden.
Example:
class MySection(Section):
_meta = {'args': Value(String())}
Note
This meta can’t be defined for the __top__ section.
The unique metadata (default False) can be used to prevent multiple section to have the same arguments.
For example if you have a section with this kind of schema:
class MySubSection(Section):
_meta = {'args': Value(String()), 'unique': True}
class MySection(Section):
sub = MySubSection()
And a configuration file with this content:
sub "foo" {...}
sub "bar" {...}
sub "foo" {...}
The last “foo” section will throw a validation error because an another “sub” section already exists with this argument.
Note
This meta can’t be defined for the __top__ section.
The repeat metadata (default to (1, 1)) allow to define how many time the section can appear. The first value is the minimum number of times, and the second the maximum number of time.
Values must be non-negative integers, and the first must be smaller or equal to the second. The second value can be set to None to express the infinite value.
Examples:
Some shortcut are available in the dotconf.schema.containers module:
Note
This meta can’t be defined for the __top__ section.
The allow_unknow metadata (default to False) allow the user to set value which are not defined in the section schema. Unknown data are then available in the validated section.
A value container used to store a scalar value of specified type.
Parameters: |
|
---|
A list container used to store a list of scalar value of specified type.
Parameters: |
|
---|
Parameters: |
|
---|
Parameters: |
|
---|