Package tipy :: Module drvr :: Class Configuration
[hide private]
[frames] | no frames]

Class Configuration

source code

ConfigParser.RawConfigParser --+    
                               |    
       ConfigParser.ConfigParser --+
                                   |
                                  Configuration

Copy a configuration file (ini format) in memory.

This class subclass the Configparser class. Configparser is used to read() a configuration file (ini format) in memory in the form of a dictionary associating sections and options. This class implement a new method which allow to retrieve and cast a configuration option and asserts the option do exists and can be casted. The config file could be edited by the user and you know... never trust user input.

Class Hierarchy for Configuration
Class Hierarchy for Configuration

Instance Methods [hide private]
 
__init__(self)
Configuration creator.
source code
str or int or bool or float or list (depends on "typeCast" param)
getas(self, section, option, typeCast=None)
A more secure way to retrieve configuration options.
source code

Inherited from ConfigParser.ConfigParser: get, items

Inherited from ConfigParser.ConfigParser (private): _interpolate, _interpolation_replace

Inherited from ConfigParser.RawConfigParser: add_section, defaults, getboolean, getfloat, getint, has_option, has_section, options, optionxform, read, readfp, remove_option, remove_section, sections, set, write

Inherited from ConfigParser.RawConfigParser (private): _get, _read

Class Variables [hide private]

Inherited from ConfigParser.ConfigParser (private): _KEYCRE

Inherited from ConfigParser.RawConfigParser: OPTCRE, OPTCRE_NV, SECTCRE

Inherited from ConfigParser.RawConfigParser (private): _boolean_states

Method Details [hide private]

__init__(self)
(Constructor)

source code 

Configuration creator.

Overrides: ConfigParser.RawConfigParser.__init__

getas(self, section, option, typeCast=None)

source code 

A more secure way to retrieve configuration options.

This method check if the section and the option is in the configuration dictionary, else it raise an error. Also this method allow an optional parameter for casting the result before returning it. Allowed type casting are:

  • bool: cast to bool
  • int: cas to int
  • float: cast to float
  • list: cast to list
  • intlist: cast to list and cast each element to int
  • floatlist: cast to list and cast each element to float

The method makes sure the casting is possible.

Parameters:
  • section (str) - The section from which to retrieve the option.
  • option (str) - The option to retrieve inside the section.
  • typeCast - Indicate how to cast the result. If no value are passed the result is returned as a string.
Returns: str or int or bool or float or list (depends on "typeCast" param)
The casted value of the given option found inside the given section.
Raises: