| Trees | Index | Help |
|
|---|
|
|
Functions for doing data persistence with ConfigObj.
It requires access to the validate module and ConfigObj.
|
|||
|
add_configspec(config)
A function that adds a configspec to a ConfigObj. |
|||
|
write_configspec(config)
Return the configspec (of a ConfigObj) as a list of lines. |
|||
|
add_typeinfo(config)
Turns the configspec attribute of each section into a member of the section. |
|||
|
typeinfo_to_configspec(config)
Turns the '__types__' member of each section into a configspec. |
|||
|
store(config)
" Passed a ConfigObj instance add type info and save. |
|||
|
restore(stored)
Restore a ConfigObj saved using the store function. |
|||
|
save_configspec(config)
Creates a configspec and returns it as a list of lines. |
|||
|
_test()
A dummy function for the sake of doctest. |
|||
|
|||
| __version__ | |||
| vtor | |||
Imports: configobj.ConfigObj, validate.Validator, doctest
|
|||
A function that adds a configspec to a ConfigObj. Will only work for ConfigObj instances using basic datatypes :
|
|
Turns the configspec attribute of each section into a member of the section. (Called __types__). You must have already called add_configspec on the ConfigObj. |
|
" Passed a ConfigObj instance add type info and save. Returns the result of calling config.write(). |
Restore a ConfigObj saved using the store function. Takes a filename or list of lines, returns the ConfigObj instance. Uses the built-in Validator instance of this module (vtor). Raises an ImportError if the validate module isn't available |
|
A dummy function for the sake of doctest. First test add_configspec >>> from configobj import ConfigObj >>> from validate import Validator >>> vtor = Validator() >>> config = ConfigObj() >>> config['member 1'] = 3 >>> config['member 2'] = 3.0 >>> config['member 3'] = True >>> config['member 4'] = [3, 3.0, True] >>> add_configspec(config) >>> assert config.configspec == { 'member 2': 'float', ... 'member 3': 'boolean', 'member 1': 'integer', ... 'member 4': "mixed_list('integer', 'float', 'boolean')"} >>> assert config.validate(vtor) == True Next test write_configspec - including a nested section >>> config['section 1'] = config.copy() >>> add_configspec(config) >>> a = config.write() >>> configspec = write_configspec(config) >>> b = ConfigObj(a, configspec=configspec) >>> assert b.validate(vtor) == True >>> assert b == config Next test add_typeinfo and typeinfo_to_configspec >>> orig = ConfigObj(config) >>> add_typeinfo(config) >>> a = ConfigObj(config.write()) >>> typeinfo_to_configspec(a) >>> assert a.validate(vtor) == True >>> assert a == orig >>> typeinfo_to_configspec(config) >>> assert config.validate(vtor) == True >>> assert config == orig Test store and restore >>> a = store(config) >>> b = restore(a) >>> assert b == orig Test save_configspec >>> a = save_configspec(orig) >>> b = ConfigObj(b, configspec=a) >>> b.validate(vtor) 1 |
|
|||
__version__
|
vtor
|
| Trees | Index | Help |
|
|---|
| Generated by Epydoc 3.0alpha2 on Sat Apr 29 11:03:34 2006 | http://epydoc.sf.net |