Schema option reference¶
This document contains details about the option attributes and option types included in configglue.
See also
If the built-in options don’t do the trick, you can easily write your own custom schema options.
Option attributes¶
The following arguments are available to all option types. All are optional.
name¶
- Option.name¶
The name of the option. This will be automatically set to the name assigned to the option in the schema definition.
raw¶
- Option.raw¶
If True, variable interpolation will not be carried out for this option.
Default is False.
default¶
- Option.default¶
The default value for this option, if none is provided in the config file.
Default is configglue.schema.NO_DEFAULT.
fatal¶
- Option.fatal¶
If True, SchemaConfigParser.parse_all will raise an exception if no value is provided in the configuration file for this option. Otherwise, self.default will be used.
Default is False.
Option types¶
ListOption¶
- class ListOption(item[, remove_duplicates=False, parse_json=True, **attributes])¶
A list of items.
- ListOption.item¶
Required.
List elements will be parsed as being of this type. Should be an instance of a subclass of Option.
- ListOption.remove_duplicates¶
Optional.
If True, duplicate elements will be removed from the parsed value.
- DictOption.parse_json¶
New in version 1.0.
Optional.
The value for this option can be specified as a json string representing the list.
Parsing will be attempted as if the value is a json string; if it fails, or the json string doesn’t represent a list, the original semantics will be applied (ie, the value is interpreted as a newline-separated string).
If False, no attempt is made at trying to parse the value as a json string.
StringOption¶
- class StringOption([null=False, **attributes])¶
A string.
- StringOption.null¶
Optional.
If True, a value of ‘None’ will be parsed into None instead of just leaving it as the string ‘None’.
TupleOption¶
- class TupleOption([length=0, **attributes])¶
A tuple of elements.
- TupleOption.length¶
Optional.
If not 0, the tuple has to have exactly this number of elements.
DictOption¶
- class DictOption([spec=None, strict=False, item=None, parse_json=True, **attributes])¶
A dictionary.
- DictOption.spec¶
Optional.
If not None, should be a dict instance, such that its values are instances of a subclass of Option.
- DictOption.strict¶
Optional.
If True, no keys will be allowed other than those specified in the spec.
- DictOption.item¶
Optional.
Any not explicitly defined attributes will be parsed as being of this type. This should be an instance of a subclass of Option.
- DictOption.parse_json
New in version 1.0.
Optional.
The value for this option can be specified as a json string representing the dictionary.
Parsing will be attempted as if the value is a json string; if it fails, or the json string doesn’t represent a dictionary, the original semantics will be applied (ie, the value represents the name of a section defining the dictionary).
If False, no attempt is made at trying to parse the value as a json string.