cfgparse.config
index

Implements basic mechanisms for managing configuration information
 
* A NAMESPACE is a collection of values and other namepsaces
* A VALUE is a basic value, like 3.1415, or 'Hello World!'
* A NAME identifies a value or namespace within a namespace
 
The namespace class is an abstract class that defines the basic
interface implemented by all namespace objects.  Two concrete
implementations are include: basic_namespace and ini_namespace.
 
Each is described in detail elsewhere.  However, here's an
example of the capabilities available:
 
Create namespace and populate it:
 
    >>> n = basic_namespace()
    >>> n.playlist.expand_playlist = True
    >>> n.ui.display_clock = True
    >>> n.ui.display_qlength = True
    >>> n.ui.width = 150
 
Examine data:
 
    >>> print n.playlist.expand_playlist
    True
    >>> print n['ui']['width']
    150
 
    >>> print n
    playlist.expand_playlist = True
    ui.display_clock = True
    ui.display_qlength = True
    ui.width = 150
 
Delete items:
 
    >>> del n.playlist
    >>> print n
    ui.display_clock = True
    ui.display_qlength = True
    ui.width = 150
 
Convert it to ini format:
 
    >>> from cfgparse import iniparser
    >>> i = iniparser.ini_namespace()
    >>> i.import_namespace(n)
 
    >>> print i
    [ui]
    display_clock = True
    display_qlength = True
    width = 150

 
Classes
       
__builtin__.object
namespace
basic_namespace
unknown

 
class basic_namespace(namespace)
    Represents a collection of named values
 
Values are added using dotted notation:
 
>>> n = basic_namespace()
>>> n.x = 7
>>> n.name.first = 'paramjit'
>>> n.name.last = 'oberoi'
 
...and accessed the same way, or with [...]:
 
>>> n.x
7
>>> n.name.first
'paramjit'
>>> n.name.last
'oberoi'
>>> n['x']
7
 
The namespace object is a 'container object'.  The default
iterator returns the names of values (i.e. keys).
 
>>> l = list(n)
>>> l.sort()
>>> l
['name', 'x']
 
Values can be deleted using 'del' and printed using 'print'.
 
>>> n.aaa = 42
>>> del n.x
>>> print n
aaa = 42
name.first = paramjit
name.last = oberoi
 
Nested namepsaces are also namespaces:
 
>>> isinstance(n.name, namespace)
True
>>> print n.name
first = paramjit
last = oberoi
 
Finally, values can be read from a file as follows:
 
>>> from StringIO import StringIO
>>> sio = StringIO('''
... # comment
... ui.height = 100
... ui.width = 150
... complexity = medium
... have_python
... data.secret.password = goodness=gracious me
... ''')
>>> n = basic_namespace()
>>> n.readfp(sio)
>>> print n
complexity = medium
data.secret.password = goodness=gracious me
have_python
ui.height = 100
ui.width = 150
 
 
Method resolution order:
basic_namespace
namespace
__builtin__.object

Methods defined here:
__delitem__(self, key)
__getitem__(self, key)
__init__(self)
__iter__(self)
__setitem__(self, key, value)
__str__(self, prefix='')
new_namespace(self, name)
readfp(self, fp)

Methods inherited from namespace:
__delattr__(self, name)
__getattr__(self, name)
__setattr__(self, name, value)
import_namespace(self, ns)

Data and other attributes inherited from namespace:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'namespace' objects>
list of weak references to the object (if defined)

 
class namespace(__builtin__.object)
     Methods defined here:
__delattr__(self, name)
__delitem__(self, key)
__getattr__(self, name)
__getitem__(self, key)
__iter__(self)
__setattr__(self, name, value)
__setitem__(self, key, value)
import_namespace(self, ns)
new_namespace(self, name)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'namespace' objects>
list of weak references to the object (if defined)

 
class unknown(__builtin__.object)
     Methods defined here:
__init__(self, name, namespace)
__setattr__(self, name, value)

Data and other attributes defined here:
__dict__ = <dictproxy object>
dictionary for instance variables (if defined)
__weakref__ = <attribute '__weakref__' of 'unknown' objects>
list of weak references to the object (if defined)