cfgparse.iniparser
index

Access and/or modify INI files
 
* Compatiable with ConfigParser
* Preserves order of sections & options
* Preserves comments/blank lines/etc
* More conveninet access to data
 
Example:
 
    >>> from StringIO import StringIO
    >>> sio = StringIO('''# configure foo-application
    ... [foo]
    ... bar1 = qualia
    ... bar2 = 1977
    ... [foo-ext]
    ... special = 1
    ... ''')
 
    >>> cfg = ini_namespace(sio)
    >>> print cfg.special
    1
    >>> print cfg.foo.bar1
    qualia
    >>> cfg.foo.newopt = 'hi!'
 
    >>> print cfg
    # configure foo-application
    [foo]
    bar1 = qualia
    bar2 = 1977
    newopt = hi!
    [foo-ext]
    special = 1

 
Modules
       
cfgparse.config
re

 
Classes
       
cfgparse.config.namespace(__builtin__.object)
ini_namespace
section
__builtin__.object
line_container
line_type
comment_line
continuation_line
empty_line
option_line
section_line

 
class comment_line(line_type)
    
Method resolution order:
comment_line
line_type
__builtin__.object

Methods defined here:
__init__(self, comment='', separator='#', line=None)
to_string(self)

Class methods defined here:
parse(cls, line) from __builtin__.type

Data and other attributes defined here:
regex = <_sre.SRE_Pattern object>

Methods inherited from line_type:
__setattr__(self, name, value)
# If an attribute is modified after initialization
# set line to None since it is no longer accurate.
__str__(self)
# Return the original line for unmodified objects
# Otherwise construct using the current attribute values

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

 
class continuation_line(line_type)
    
Method resolution order:
continuation_line
line_type
__builtin__.object

Methods defined here:
__init__(self, value, value_offset=8, line=None)
to_string(self)

Class methods defined here:
parse(cls, line) from __builtin__.type

Data and other attributes defined here:
regex = <_sre.SRE_Pattern object>

Methods inherited from line_type:
__setattr__(self, name, value)
# If an attribute is modified after initialization
# set line to None since it is no longer accurate.
__str__(self)
# Return the original line for unmodified objects
# Otherwise construct using the current attribute values

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

 
class empty_line(line_type)
    
Method resolution order:
empty_line
line_type
__builtin__.object

Methods defined here:
to_string(self)
# could make this a singleton

Class methods defined here:
parse(cls, line) from __builtin__.type

Methods inherited from line_type:
__init__(self, line=None)
__setattr__(self, name, value)
# If an attribute is modified after initialization
# set line to None since it is no longer accurate.
__str__(self)
# Return the original line for unmodified objects
# Otherwise construct using the current attribute values

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

 
class ini_namespace(cfgparse.config.namespace)
    
Method resolution order:
ini_namespace
cfgparse.config.namespace
__builtin__.object

Methods defined here:
__delitem__(self, key)
__getitem__(self, key)
__init__(self, fp=None, defaults=None, parse_exc=True, optionxform=<method 'lower' of 'str' objects>, sectionxform=None)
__iter__(self)
__setitem__(self, key, value)
__str__(self)
new_namespace(self, name)
readfp(self, fp)

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

Data and other attributes inherited from cfgparse.config.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 line_container(__builtin__.object)
     Methods defined here:
__init__(self, d=None)
__str__(self)
add(self, x)
extend(self, x)
find(self, key)
finditer(self, key)
get_name(self)
get_value(self)
set_name(self, data)
set_value(self, data)

Properties defined here:
name
get = get_name(self)
set = set_name(self, data)
value
get = get_value(self)
set = set_value(self, data)

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

 
class line_type(__builtin__.object)
     Methods defined here:
__init__(self, line=None)
__setattr__(self, name, value)
# If an attribute is modified after initialization
# set line to None since it is no longer accurate.
__str__(self)
# Return the original line for unmodified objects
# Otherwise construct using the current attribute values
to_string(self)

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

 
class option_line(line_type)
    
Method resolution order:
option_line
line_type
__builtin__.object

Methods defined here:
__init__(self, name, value, separator='=', comment=None, comment_separator=None, comment_offset=-1, line=None)
to_string(self)

Class methods defined here:
parse(cls, line) from __builtin__.type

Data and other attributes defined here:
regex = <_sre.SRE_Pattern object>

Methods inherited from line_type:
__setattr__(self, name, value)
# If an attribute is modified after initialization
# set line to None since it is no longer accurate.
__str__(self)
# Return the original line for unmodified objects
# Otherwise construct using the current attribute values

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

 
class section(cfgparse.config.namespace)
    
Method resolution order:
section
cfgparse.config.namespace
__builtin__.object

Methods defined here:
__delitem__(self, key)
__getitem__(self, key)
__init__(self, lineobj, defaults=None, optionxform=None)
__iter__(self)
__setitem__(self, key, value)
new_namespace(self, name)

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

Data and other attributes inherited from cfgparse.config.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 section_line(line_type)
    
Method resolution order:
section_line
line_type
__builtin__.object

Methods defined here:
__init__(self, name, comment=None, comment_separator=None, comment_offset=-1, line=None)
to_string(self)

Class methods defined here:
parse(cls, line) from __builtin__.type

Data and other attributes defined here:
regex = <_sre.SRE_Pattern object>

Methods inherited from line_type:
__setattr__(self, name, value)
# If an attribute is modified after initialization
# set line to None since it is no longer accurate.
__str__(self)
# Return the original line for unmodified objects
# Otherwise construct using the current attribute values

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

 
Functions
       
make_comment(line)

 
Data
        DEFAULTSECT = 'DEFAULT'