Package amplee :: Module loader :: Class Config
[show private | hide private]
[frames | no frames]

Type Config

object --+
         |
        Config


Represents an INI file as a tree of Config instances

Say you have ``test.conf``:

[general] verbose = True
>>> from amplee.loader import Config
>>> config = Config()
>>> config.from_ini('test.conf')
>>> print config.general.verbose
>>> True

Each loaded value is an unicode object except the following strings: 'True' --> True 'False' --> False 'None' --> None

An empty string will not be transformed into a None though.
Method Summary
  from_ini(self, filepath, encoding)
Loads the configuration file into the current instance of `Config`.
  get(self, section, option, default, raise_error)
Retrieve the value for a particular node in the configuration tree.
  get_all_values(self, section, capitalize)
Returns a dictionnary of all nodes which parent is the section.
  get_section(self, section)
    Inherited from object
  __init__(...)
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> x.name
  __hash__(x)
x.__hash__() <==> hash(x)
  __new__(T, S, ...)
T.__new__(S, ...) -> a new object with type S, a subtype of T
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle
  __repr__(x)
x.__repr__() <==> repr(x)
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value
  __str__(x)
x.__str__() <==> str(x)

Method Details

from_ini(self, filepath, encoding='ISO-8859-1')

Loads the configuration file into the current instance of `Config`.

The ``filepath`` is the path to the configuration file.

The ``encoding`` indicates how to decode each value.

get(self, section, option, default=None, raise_error=False)

Retrieve the value for a particular node in the configuration tree.
>>> print config.get('general', 'verbose', default=1)
but also:
>>> try:
>>>    config.get('general', 'verbose', raise_error=True)
>>> except AttributeError:
>>>    print 'Could not find it'

The ``section`` is the name of the parent node of which ``option`` is a child.

The ``option`` is the name of the node to lookup.

You can provide a ``default`` value when the node was not found. This applies when ``raise_error`` is ``False``, which is the default.

If you set ``raise_error`` to ``True`` an ``AttributeError`` exception will be raised if the node is not found.

get_all_values(self, section, capitalize=False)

Returns a dictionnary of all nodes which parent is the section.

The ``section`` is the name of the parent node to look for. The ``capitalize`` parameter indicates if the keys of the returned dictionnary should start with a cpital letter.

Generated by Epydoc 2.1 on Thu Jul 19 15:32:17 2007 http://epydoc.sf.net