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

Class Config

source code

object --+
         |
        Config

Represents an INI file as a tree of Config instances

Say you have C{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.



Instance Methods [hide private]
 
from_ini(self, filepath, encoding='ISO-8859-1')
Loads the configuration file into the current instance of Config.
source code
object
get(self, section, option, default=None, raise_error=False)
Retrieve the value for a particular node in the configuration tree.
source code
 
_convert_type(self, value)
Do dummy conversion of the string 'True', 'False' and 'None' into their object equivalent
source code
 
get_section(self, section) source code
dict
get_all_values(self, section, capitalize=False)
Returns a dictionnary of all nodes which parent is the section.
source code

Inherited from object: __delattr__, __getattribute__, __hash__, __init__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __str__

Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

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

source code 
Loads the configuration file into the current instance of Config.
>>> from amplee.loader import Config
>>> conf = Config()
>>> conf.from_ini('./my.conf')
Parameters:
  • filepath (string) - path to the configuration file.
  • encoding (string) - indicates how to decode each value.

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

source code 
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 'general.verbose'"
Parameters:
  • section (string) - name of the parent node of which option is a child.
  • option (string) - name of the node to lookup.
  • default (object) - value when the node was not found. This applies when raise_error is False, which is the default.
  • raise_error (bool) - set to True an AttributeError exception will be raised if the node is not found.
Returns: object
the retrieved value or default.

get_all_values(self, section, capitalize=False)

source code 
Returns a dictionnary of all nodes which parent is the section.
Parameters:
  • section (string) - name of the parent node to look for.
  • capitalize (bool) - indicates if the keys of the dictionnary should start with a capital letter.
Returns: dict
dictionnary of all the nodes which parent is the specified section.