V0 style config¶
Description¶
V0-style config files support all the features of python’s configparser parseable configs plus allows features such as:
Features¶
ORed
sections:
These kind of sections can declare multiple elements in the same section for duplication of key-value pairs using the V0-style delimiter (|
), for e.g.
# Motivation for ORed section
# section1 and section2 have the same keys and values
# ; VERSION = v0
[section1]
k1=v1
k2=v2
[section2]
k1=v1
k2=v2
Similar sections can be combined using |
, for e.g.
# ORed section demonstration
# section1 and section2 can be combined in the same section using v0 style delimiter (|), like so
# ; VERSION = v0
[section1|section2]
k1=v1
k2=v2
with open(full_path('ORed-section-motivation-cfg.ini')) as mf:
motive_dict = EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).run()
with open(full_path('ORed-section-demonstration-cfg.ini')) as df:
demo_dict = EtcTest(df, EncConfigParser.for_version(ConfigVersion.v0)).run()
assert motive_dict == demo_dict
*
or the default section:
These sections match any unmatched key, for e.g.
# Default or * section demonstration
# ; VERSION = v0
[section1|section2]
k1=v1
k2=v2
# * or the DEFAULT section
[*]
k1=v2
with open(full_path('default-section-demonstration-cfg.ini')) as mf:
etc_test = EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0))
etc_test.run() # initialise the parser
_ = etc_test.config_parser.get_section('section1') # section1 is present and hence no error is thrown
_ = etc_test.config_parser.get_section('section2') # section2 is present and hence no error is thrown
st_section = etc_test.config_parser.get_section('*') # * or the default section is present and hence no error is thrown
assert st_section == etc_test.config_parser.get_section('untitled') # There is no untitled section so this section is defaulted to the * section
Restrictions¶
Section names cannot start with delimiter (
|
)
# Section starting with delimiter
# ; VERSION = v0
[|section]
k=v
with open(full_path('ORed-section-starting-with-delimiter.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)
Section names cannot end with delimiter (
|
)
# Section ending with delimiter
# ; VERSION = v0
[section|]
k=v
with open(full_path('ORed-section-ending-with-delimiter.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)
Duplication across/outside sections is not allowed
# Duplication outside section demonstration
# ERROR: section1 is redefined in [section1|section2] section.
# ; VERSION = v0
[section1]
k1=v1
[section1|section2]
k1=v1
k2=v2
with open(full_path('duplication-outside-section-cfg.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)
Duplication within sections is not allowed
# Duplication within section demonstration
# ERROR: section1 is defined twice in [section1|section2|section1] section.
# ; VERSION = v0
[section1|section2|section1]
k1=v1
k2=v2
with open(full_path('duplication-within-section-cfg.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)
Sections starting with space/spaces are not allowed
# FAULTY section config
# sections cannot start with space/spaces
# ; VERSION = v0
[ section starting with space]
k1=v1
with open(full_path('section-starting-with-space-cfg.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)
Sections ending with space/spaces are not allowed
# FAULTY section config
# sections cannot end with space/spaces
# ; VERSION = v0
[section ending with space ]
k1=v1
with open(full_path('section-ending-with-space-cfg.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)
Sections starting and ending with space/spaces are not allowed
# FAULTY section config
# sections cannot start and end with space/spaces
# ; VERSION = v0
[ section starting and ending with space ]
k1=v1
with open(full_path('section-starting-ending-with-space-cfg.ini')) as mf:
EtcTest(mf, EncConfigParser.for_version(ConfigVersion.v0)).raises(EncConfigError)