Module config :: Class Config
[show private | hide private]
[frames | no frames]

Type Config

object --+        
         |        
 Container --+    
             |    
       Mapping --+
                 |
                Config


This class represents a configuration, and is the only one which clients need to interface to, under normal circumstances.
Method Summary
  __init__(self, streamOrFile, parent)
Initializes an instance.
  addNamespace(self, ns, name)
Add a namespace to this configuration which can be used to evaluate (resolve) dotted-identifier expressions.
any getByPath(self, path)
Obtain a value in the configuration via its path.
  load(self, stream)
Load the configuration from the specified stream.
  removeNamespace(self, ns, name)
Remove a namespace added with addNamespace.
  save(self, stream, indent)
Save this configuration to the specified stream.
    Inherited from Mapping
  __contains__(self, item)
  __delitem__(self, key)
Remove an item
  __getattr__(self, key)
  __getattribute__(self, name)
  __getitem__(self, key)
  __iter__(self)
  __len__(self)
  __repr__(self)
  __setattr__(self, name, value)
  __setitem__(self, name, value)
  __str__(self)
  addMapping(self, key, value, comment, setting)
Add a key-value mapping with a comment.
  get(self, key, default)
Allows a dictionary-style get operation.
  iteritems(self)
  iterkeys(self)
  keys(self)
Return the keys in a similar way to a dictionary.
  writeToStream(self, stream, indent, container)
Write this instance to a stream at the specified indentation level.
    Inherited from Container
  evaluate(self, item)
Evaluate items which are instances of Reference or Expression.
  setPath(self, path)
Set the path for this instance.
  writeValue(self, value, stream, indent)
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __hash__(x)
Return hash(x)...
  __new__(T, S, ...)
Return a new object with type S, a subtype of T...
  __reduce__(...)
helper for pickle
  __reduce_ex__(...)
helper for pickle

Instance Variable Summary
    Inherited from Container
  path: A string which describes how to get to this instance from the root of the hierarchy.

Class Variable Summary
type Namespace = config.Namespace

Method Details

__init__(self, streamOrFile=None, parent=None)
(Constructor)

Initializes an instance.
Parameters:
streamOrFile - If specified, causes this instance to be loaded from the stream (by calling load). If a string is provided, it is passed to streamOpener to open a stream. Otherwise, the passed value is assumed to be a stream and used as is.
           (type=A readable stream (file-like object) or a name.)
parent - If specified, this becomes the parent of this instance in the configuration hierarchy.
           (type=a Container instance.)
Overrides:
config.Mapping.__init__

addNamespace(self, ns, name=None)

Add a namespace to this configuration which can be used to evaluate (resolve) dotted-identifier expressions.
Parameters:
ns - The namespace to be added.
           (type=A module or other namespace suitable for passing as an argument to vars().)
name - A name for the namespace, which, if specified, provides an additional level of indirection.
           (type=str)

getByPath(self, path)

Obtain a value in the configuration via its path.
Parameters:
path - The path of the required value
           (type=str @return the value at the specified path.)
Returns:
any
Raises:
ConfigError - If the path is invalid

load(self, stream)

Load the configuration from the specified stream. Multiple streams can be used to populate the same instance, as long as there are no clashing keys. The stream is closed.
Parameters:
stream - A stream from which the configuration is read.
           (type=A read-only stream (file-like object).)
Raises:
ConfigError - if keys in the loaded configuration clash with existing keys.
ConfigFormatError - if there is a syntax error in the stream.

removeNamespace(self, ns, name=None)

Remove a namespace added with addNamespace.
Parameters:
ns - The namespace to be removed.
name - The name which was specified when addNamespace was called.
           (type=str)

save(self, stream, indent=0)

Save this configuration to the specified stream. The stream is closed if this is the top-level configuration in the hierarchy. Mapping.save is called to do all the work.
Parameters:
stream - A stream to which the configuration is written.
           (type=A write-only stream (file-like object).)
indent - The indentation level for the output.
           (type=int)
Overrides:
config.Mapping.save