mrv.conf

Epydoc: mrv.conf

Contains implementation of the configuration system allowing to flexibly control the programs behaviour.

  • read and write sections with key=value pairs from and to INI style file-like objects !
  • Wrappers for these file-like objects allow virtually any source for the operation
  • configuration inheritance
  • allow precise control over the inheritance behaviour and inheritance defaults
  • final results of the inheritance operation will be cached into the ConfigManager
  • Environment Variables can serve as final instance to override values using the DictConfigINIFile
  • Creation and Maintenance of individual configuration files as controlled by submodules of the application
  • These configuration go to a default location, or to the given file-like object
  • embed more complex data to be read by specialised classes using URLs
  • its safe and easy to write back possibly altered values even if complex inheritance schemes are applied

Functions

mrv.conf._checkString(string, re)
Check the given string with given re for correctness :param re: must match the whole string for success :return: the passed in and stripped string :raise ValueError:
mrv.conf._excmsgprefix(msg)
Put msg in front of current exception and reraise :warning: use only within except blocks

Classes

Epydoc: mrv.conf.BasicSet

class mrv.conf.BasicSet

Bases: set

Set with ability to return the key which matches the requested one

This functionality is the built-in in default STL sets, and I do not understand why it is not provided here ! Of course I want to define custom objects with overridden hash functions, put them into a set, and finally retrieve the same object again !

Note:indexing a set is not the fastest because the matching key has to be searched. Good news is that the actual ‘is k in set’ question can be answered quickly
add

Add an element to a set.

This has no effect if the element is already present.

clear
Remove all elements from this set.
copy
Return a shallow copy of a set.
difference

Return the difference of two or more sets as a new set.

(i.e. all elements that are in this set but not the others.)

difference_update
Remove all elements of another set from this set.
discard

Remove an element from a set if it is a member.

If the element is not a member, do nothing.

intersection

Return the intersection of two or more sets as a new set.

(i.e. elements that are common to all of the sets.)

intersection_update
Update a set with the intersection of itself and another.
isdisjoint
Return True if two sets have a null intersection.
issubset
Report whether another set contains this set.
issuperset
Report whether this set contains another set.
pop
Remove and return an arbitrary set element. Raises KeyError if the set is empty.
remove

Remove an element from a set; it must be a member.

If the element is not a member, raise a KeyError.

symmetric_difference

Return the symmetric difference of two sets as a new set.

(i.e. all elements that are in exactly one of the sets.)

symmetric_difference_update
Update a set with the symmetric difference of itself and another.
union

Return the union of sets as a new set.

(i.e. all elements that are in either set.)

update
Update a set with the union of itself and others.

Epydoc: mrv.conf.ConfigAccessor

class mrv.conf.ConfigAccessor

Bases: object

Provides full access to the Configuration

Differences to ConfigParser:

As the functionality and featureset is very different from the original ConfigParser implementation, this class does not support the interface directly. It contains functions to create original ConfigParser able to fully write and alter the contained data in an unchecked manner.

Additional Exceptions have been defined to cover extended functionality.

Sources and Nodes:
Each input providing configuration data is stored in a node. This node knows about its writable state. Nodes that are not writable can be altered in memory, but the changes cannot be written back to the source. This does not impose a problem though as changes will be applied as long as there is one writable node in the chain - due to the inheritance scheme applied by the configmanager, the final configuration result will match the changes applied at runtime.
Additional Information:
The term configuration is rather complex though configuration is based on an extended INI file format its not fully compatible, but slightly more narrow regarding allowed input to support extended functionality configuration is read from file-like objects a list of file-like objects creates a configuration chain keys have properties attached to them defining how they behave when being overridden once all the INI configurations have been read and processed, one can access the configuration as if it was just in one file. Direct access is obtained though Key and Section objects Keys and Sections have property attributes of type Section Their keys and values are used to further define key merging behaviour for example
Note:The configaccessor should only be used in conjunction with the ConfigManager
flatten(fp)

Copy all our members into a new ConfigAccessor which only has one node, instead of N nodes

By default, a configuration can be made up of several different sources that create a chain. Each source can redefine and alter values previously defined by other sources.

A flattened chain though does only conist of one of such node containing concrete values that can quickly be accessed.

Flattened configurations are provided by the ConfigManager.

Parameter:fp – file-like object that will be used as storage once the configuration is written
Returns:Flattened copy of self
get(key_id, default=None)

Convenience function allowing to easily specify the key you wish to retrieve with the option to provide a default value

Parameters:
  • key_id – string specifying a key, either as sectionname.keyname or keyname. In case you specify a section, the key must reside in the given section, if only a keyname is given, it may reside in any section
  • default – Default value to be given to a newly created key in case there is no existing value. If None, the method may raise in case the given key_id does not exist.
Returns:

Key instance whose value may be queried through its value or values attributes

hasSection(name)
Returns:True if the given section exists
isEmpty()
Returns:True if the accessor does not stor information
iterateKeysByName(name)
As keysByName, but returns an iterator instead
keyDefault(sectionname, keyname, value)

Convenience Function: get key with keyname in first section with sectionname with the key’s value being initialized to value if it did not exist.

Parameters:
  • sectionname – the name of the sectionname the key is supposed to be in - it will be created if needed
  • keyname – the name of the key you wish to find
  • value – the value you wish to receive as as default if the key has to be created. It can be a list of values as well, basically anything that Key allows as value
Returns:

Key

keyIterator()
Returns:iterator returning tuples of (Key,`Section`) pairs
keysByName(name)
Parameter:name – the name of the key you wish to find
Returns:List of (Key,`Section`) tuples of key(s) matching name found in section, or empty list
mergeSection(section)

Merge and/or add the given section into our chain of nodes. The first writable node will be used

Raises IOError:if no writable node was found
Returns:name of the file source that has received the section
readfp(filefporlist, close_fp=True)

Read the configuration from the file like object(s) representing INI files.

Note:

This will overwrite and discard all existing configuration.

Parameters:
  • filefporlist – single file like object or list of such
  • close_fp – if True, the file-like object will be closed before the method returns, but only for file-like objects that have actually been processed
Raises ConfigParsingError:
 
removeSection(name)

Completely remove the given section name from all nodes in our configuration

Returns:the number of nodes that did not allow the section to be removed as they are read-only, thus 0 will be returned if everything was alright
section(section)
Returns:first section with name
Note:as there might be several nodes defining the section for inheritance, you might not get the desired results unless this config accessor acts on a flatten ed list.
Raises NoSectionError:
 if the requested section name does not exist
sectionDefault(section)
Returns:section with given name.
Raises IOError:If section does not exist and it cannot be created as the configuration is readonly
Note:the section will be created if it does not yet exist
sectionIterator()
Returns:iterator returning all sections
write(close_fp=True)
Write current state back to files.
During initialization in readfp, ExtendedFileInterface objects have been passed in - these will now be used to write back the current state of the configuration - the files will be opened for writing if possible.
Parameter:close_fp – close the file-object after writing to it
Returns:list of names of files that have actually been written - as files can be read-only this list might be smaller than the amount of nodes in the accessor.

Epydoc: mrv.conf.ConfigChain

class mrv.conf.ConfigChain

Bases: list

A chain of config nodes

This utility class keeps several ConfigNode objects, but can be operated like any other list.

Note:this solution is mainly fast to implement, but a linked-list like behaviour is intended
append(node)
Append a ConfigNode
count
L.count(value) -> integer – return number of occurrences of value
extend(*args, **kwargs)
Raises NotImplementedError:
 
index
L.index(value, [start, [stop]]) -> integer – return first index of value. Raises ValueError if the value is not present.
insert(node, index)
Insert L?{ConfigNode} before index
iterateKeysByName(name)
Parameter:name – the name of the key you wish to find
Returns:Iterator yielding (Key,`Section`) of key matching name found in section
keyIterator()
Returns:iterator returning tuples of (key,section) pairs
pop
L.pop([index]) -> item – remove and return item at index (default last). Raises IndexError if list is empty or index is out of range.
remove
L.remove(value) – remove first occurrence of value. Raises ValueError if the value is not present.
reverse
L.reverse() – reverse IN PLACE
sectionIterator()
Returns:section iterator for whole configuration chain
sort(*args, **kwargs)
Raises NotImplementedError:
 

Epydoc: mrv.conf.ConfigDiffer

class mrv.conf.ConfigDiffer(A, B)

Bases: mrv.conf.DiffData

Compares two configuration objects and allows retrieval of differences

Use this class to find added/removed sections or keys or differences in values and properties.

Example Applicance:
Test use it to verify that reading and writing a (possibly) changed configuration has the expected results Programs interacting with the User by a GUI can easily determine whether the user has actually changed something, applying actions only if required alternatively, programs can simply be more efficient by acting only on items that actually changed
Data Structure:
  • every object in the diffing structure has a ‘name’ attribute
  • ConfigDiffer.added|removed|unchanged: Section objects that have been added, removed or kept unchanged respectively
  • ConfigDiffer.changed: DiffSection objects that indicate the changes in respective section
  • DiffSection.added|removed|unchanged: Key objects that have been added, removed or kept unchanged respectively
  • DiffSection.changed: DiffKey objects that indicate the changes in the repsective key
  • DiffKey.added|removed: the key’s values that have been added and/or removed respectively
  • DiffKey.properties: see DiffSection.properties
  • DiffSection.properties:None if this is a section diff, otherwise it contains a DiffSection with the respective differences
added
applyTo(ca)

Apply the stored differences in this ConfigDiffer instance to the given ConfigAccessor

If our diff contains the changes of A to B, then applying ourselves to A would make A equal B.

Note:

individual nodes reqpresenting an input source (like a file) can be marked read-only. This means they cannot be altered - thus it can be that section or key removal fails for them. Addition of elements normally works as long as there is one writable node.

Parameter:

ca – The configacceesor to apply our differences to

Returns:

tuple of lists containing the sections that could not be added, removed or get their changes applied

  • [0] = list of Section s failed to be added
  • [1] = list of Section s failed to be removed
  • [2] = list of DiffSection s failed to apply their changes
changed
hasDifferences()
Returns:true if we have stored differences (A is not equal to B)
name
properties
removed
toStr(typename)
Convert own data representation to a string
unchanged

Epydoc: mrv.conf.ConfigFile

class mrv.conf.ConfigFile(*args, **kwargs)

Bases: mrv.conf.ExtendedFileInterface

file object implementation of the ExtendedFileInterface

isClosed()
isWritable()
Returns:True if the file is truly writable
name()
openForWriting()

Epydoc: mrv.conf.ConfigManager

class mrv.conf.ConfigManager(filePointers=[], write_back_on_desctruction=True, close_fp=True)

Bases: object

Cache Configurations for fast access and provide a convenient interface

The the ConfigAccessor has limited speed due to the hierarchical nature of configuration chains. The config manager flattens the chain providing fast access. Once it is being deleted or if asked, it will find the differences between the fast cached configuration and the original one, and apply the changes back to the original chain, which will then write the changes back (if possible).

This class should be preferred over the direct congiguration accessor. This class mimics the ConfigAccessor inteface as far as possible to improve ease of use. Use self.config to directly access the configuration through the ConfigAccessor interface

To use this class, read a list of ini files and use configManager.config to access the configuration.

For convenience, it will wire through all calls it cannot handle to its ConfigAccessor stored at .config

config
readfp(filefporlist, close_fp=True)

Read the configuration from the file pointers.

Raises ConfigParsingError:
 
Parameter:filefporlist – single file like object or list of such
Returns:the configuration that is meant to be used for accessing the configuration
classmethod taggedFileDescriptors(directories, taglist, pattern=None)

Finds tagged configuration files in given directories and return them.

The files retrieved can be files like “file.ext” or can contain tags. Tags are ‘.’ separated files tags that are to be matched with the tags in taglist in order.

All tags must match to retrieve a filepointer to the respective file.

Example Usage: you could give two paths, one is a global one in a read-only location, another is a local one in the user’s home (where you might have precreated a file already).

The list of filepointers returned would be all matching files from the global path and all matching files from the local one, sorted such that the file with the smallest amount of tags come first, files with more tags (more specialized ones) will come after that.

If fed into the readfp or the __init__ method, the individual file contents can override each other. Once changes have been applied to the configuration, they can be written back to the writable file pointers respectively.

Parameters:
  • directories – [string(path) ...] of directories to look in for files
  • taglist – [string(tag) ...] of tags, like a tag for the operating system, or the user name
  • pattern – simple fnmatch pattern as used for globs or a list of them (allowing to match several different patterns at once)
write()

Write the possibly changed configuration back to its sources.

Raises IOError:if at least one node could not be properly written.
Raises ValueError:
 if instance is not properly initialized.
Note:It could be the case that all nodes are marked read-only and thus cannot be written - this will also raise as the request to write the changes could not be accomodated.
Returns:the names of the files that have been written as string list

Epydoc: mrv.conf.ConfigNode

class mrv.conf.ConfigNode(fp)

Bases: object

Represents node in the configuration chain

It keeps information about the origin of the configuration and all its data. Additionally, it is aware of it being element of a chain, and can provide next and previous elements respectively

hasSection(name)
Returns:True if the given section exists
listSections()
Returns:list() with string names of available sections
Todo:return an iterator instead
parse()

parse default INI information into the extended structure

Parse the given INI file using a _FixedConfigParser, convert all information in it into an internal format

Raises ConfigParsingError:
 
section(name)
Returns:Section with name
Raises NoSectionError:
 
sectionDefault(name)
Returns:Section with name, create it if required
writable
write(rcp, close_fp=True)

Write our contents to our file-like object

Parameter:rcp – RawConfigParser to use for writing
Returns:the name of the written file
Raises IOError:if we are read-only

Epydoc: mrv.conf.ConfigStringIO

class mrv.conf.ConfigStringIO(buf='')

Bases: StringIO.StringIO, mrv.conf.ExtendedFileInterface

cStringIO object implementation of ExtendedFileInterface

close()
Free the memory buffer.
flush()
Flush the internal buffer
getvalue()

Retrieve the entire contents of the “file” at any time before the StringIO object’s close() method is called.

The StringIO object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, 8-bit strings that cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause a UnicodeError to be raised when getvalue() is called.

isClosed()
isWritable()
Once we are closed, we are not writable anymore
isatty()
Returns False because StringIO objects are not connected to a tty-like device.
name()
We do not have a real name
next()
A file object is its own iterator, for example iter(f) returns f (unless f is closed). When a file is used as an iterator, typically in a for loop (for example, for line in f: print line), the next() method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit.
openForWriting()
We if we are closed already, there is no way to reopen us
read(n=-1)

Read at most size bytes from the file (less if the read hits EOF before obtaining size bytes).

If the size argument is negative or omitted, read all data until EOF is reached. The bytes are returned as a string object. An empty string is returned when EOF is encountered immediately.

readline(length=None)

Read one entire line from the file.

A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). If the size argument is present and non-negative, it is a maximum byte count (including the trailing newline) and an incomplete line may be returned.

An empty string is returned only when EOF is encountered immediately.

Note: Unlike stdio’s fgets(), the returned string contains null characters (‘0’) if they occurred in the input.

readlines(sizehint=0)

Read until EOF using readline() and return a list containing the lines thus read.

If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (or more to accommodate a final whole line).

seek(pos, mode=0)

Set the file’s current position.

The mode argument is optional and defaults to 0 (absolute file positioning); other values are 1 (seek relative to the current position) and 2 (seek relative to the file’s end).

There is no return value.

tell()
Return the file’s current position.
truncate(size=None)

Truncate the file’s size.

If the optional size argument is present, the file is truncated to (at most) that size. The size defaults to the current position. The current file position is not changed unless the position is beyond the new file size.

If the specified size exceeds the file’s current size, the file remains unchanged.

write(s)

Write a string to the file.

There is no return value.

writelines(iterable)

Write a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings. There is no return value.

(The name is intended to match readlines(); writelines() does not add line separators.)

Epydoc: mrv.conf.DictConfigINIFile

class mrv.conf.DictConfigINIFile(option_dict, section='DEFAULT', description='')

Bases: mrv.conf.DictToINIFile, mrv.conf.ExtendedFileInterface

dict file object implementation of ExtendedFileInterface

close()
Free the memory buffer.
flush()
Flush the internal buffer
getvalue()

Retrieve the entire contents of the “file” at any time before the StringIO object’s close() method is called.

The StringIO object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, 8-bit strings that cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause a UnicodeError to be raised when getvalue() is called.

isClosed()
isWritable()
Returns:True if the file can be written to
isatty()
Returns False because StringIO objects are not connected to a tty-like device.
name()
We do not have a real name
next()
A file object is its own iterator, for example iter(f) returns f (unless f is closed). When a file is used as an iterator, typically in a for loop (for example, for line in f: print line), the next() method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit.
openForWriting()
We cannot be opened for writing, and are always read-only
read(n=-1)

Read at most size bytes from the file (less if the read hits EOF before obtaining size bytes).

If the size argument is negative or omitted, read all data until EOF is reached. The bytes are returned as a string object. An empty string is returned when EOF is encountered immediately.

readline(length=None)

Read one entire line from the file.

A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). If the size argument is present and non-negative, it is a maximum byte count (including the trailing newline) and an incomplete line may be returned.

An empty string is returned only when EOF is encountered immediately.

Note: Unlike stdio’s fgets(), the returned string contains null characters (‘0’) if they occurred in the input.

readlines(sizehint=0)

Read until EOF using readline() and return a list containing the lines thus read.

If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (or more to accommodate a final whole line).

seek(pos, mode=0)

Set the file’s current position.

The mode argument is optional and defaults to 0 (absolute file positioning); other values are 1 (seek relative to the current position) and 2 (seek relative to the file’s end).

There is no return value.

tell()
Return the file’s current position.
truncate(size=None)

Truncate the file’s size.

If the optional size argument is present, the file is truncated to (at most) that size. The size defaults to the current position. The current file position is not changed unless the position is beyond the new file size.

If the specified size exceeds the file’s current size, the file remains unchanged.

write(s)

Write a string to the file.

There is no return value.

writelines(iterable)

Write a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings. There is no return value.

(The name is intended to match readlines(); writelines() does not add line separators.)

Epydoc: mrv.conf.DictToINIFile

class mrv.conf.DictToINIFile(option_dict, section='DEFAULT', description='')

Bases: StringIO.StringIO

Wraps a dictionary into an objects returning an INI file when read

This class can be used to make configuration information as supplied by os.environ natively available to the configuration system

Note:writing back values to the object will not alter the original dict
Note:the current implementation caches the dict’s INI representation, data is not generated on demand
Note:implementation speed has been preferred over runtime speed
close()
Free the memory buffer.
flush()
Flush the internal buffer
getvalue()

Retrieve the entire contents of the “file” at any time before the StringIO object’s close() method is called.

The StringIO object can accept either Unicode or 8-bit strings, but mixing the two may take some care. If both are used, 8-bit strings that cannot be interpreted as 7-bit ASCII (that use the 8th bit) will cause a UnicodeError to be raised when getvalue() is called.

isatty()
Returns False because StringIO objects are not connected to a tty-like device.
next()
A file object is its own iterator, for example iter(f) returns f (unless f is closed). When a file is used as an iterator, typically in a for loop (for example, for line in f: print line), the next() method is called repeatedly. This method returns the next input line, or raises StopIteration when EOF is hit.
read(n=-1)

Read at most size bytes from the file (less if the read hits EOF before obtaining size bytes).

If the size argument is negative or omitted, read all data until EOF is reached. The bytes are returned as a string object. An empty string is returned when EOF is encountered immediately.

readline(length=None)

Read one entire line from the file.

A trailing newline character is kept in the string (but may be absent when a file ends with an incomplete line). If the size argument is present and non-negative, it is a maximum byte count (including the trailing newline) and an incomplete line may be returned.

An empty string is returned only when EOF is encountered immediately.

Note: Unlike stdio’s fgets(), the returned string contains null characters (‘0’) if they occurred in the input.

readlines(sizehint=0)

Read until EOF using readline() and return a list containing the lines thus read.

If the optional sizehint argument is present, instead of reading up to EOF, whole lines totalling approximately sizehint bytes (or more to accommodate a final whole line).

seek(pos, mode=0)

Set the file’s current position.

The mode argument is optional and defaults to 0 (absolute file positioning); other values are 1 (seek relative to the current position) and 2 (seek relative to the file’s end).

There is no return value.

tell()
Return the file’s current position.
truncate(size=None)

Truncate the file’s size.

If the optional size argument is present, the file is truncated to (at most) that size. The size defaults to the current position. The current file position is not changed unless the position is beyond the new file size.

If the specified size exceeds the file’s current size, the file remains unchanged.

write(s)

Write a string to the file.

There is no return value.

writelines(iterable)

Write a sequence of strings to the file. The sequence can be any iterable object producing strings, typically a list of strings. There is no return value.

(The name is intended to match readlines(); writelines() does not add line separators.)

Epydoc: mrv.conf.DiffData

class mrv.conf.DiffData(A, B)

Bases: object

Struct keeping data about added, removed and/or changed data Subclasses should override some private methods to automatically utilize some basic functionality

Class instances define the following values:
  • ivar added: Copies of all the sections that are only in B (as they have been added to B)
  • ivar removed: Copies of all the sections that are only in A (as they have been removed from B)
  • ivar changed: Copies of all the sections that are in A and B, but with changed keys and/or properties
added
changed
hasDifferences()
Returns:true if we have stored differences (A is not equal to B)
name
properties
removed
toStr(typename)
Convert own data representation to a string
unchanged

Epydoc: mrv.conf.DiffKey

class mrv.conf.DiffKey(A, B)

Bases: mrv.conf.DiffData

Implements DiffData on Key level

added
applyTo(key)
Apply our changes to the given Key
changed
hasDifferences()
Returns:true if we have stored differences (A is not equal to B)
name
properties
removed
toStr(typename)
Convert own data representation to a string
unchanged

Epydoc: mrv.conf.DiffSection

class mrv.conf.DiffSection(A, B)

Bases: mrv.conf.DiffData

Implements DiffData on section level

added
applyTo(targetSection)
Apply our changes to targetSection
changed
hasDifferences()
Returns:true if we have stored differences (A is not equal to B)
name
properties
removed
toStr(typename)
Convert own data representation to a string
unchanged

Epydoc: mrv.conf.ExtendedFileInterface

class mrv.conf.ExtendedFileInterface

Bases: object

Define additional methods required by the Configuration System :warning: Additionally, readline and write must be supported - its not mentioned here for reasons of speed :note: override the methods with implementation

isClosed()
Returns:True if the file has been closed, and needs to be reopened for writing
isWritable()
Returns:True if the file can be written to
name()
Returns:a name for the file object
openForWriting()
Open the file to write to it :raise IOError: on failure

Epydoc: mrv.conf.Key

class mrv.conf.Key(name, value, order)

Bases: mrv.conf._PropertyHolderBase

Key with an associated values and an optional set of propterties

Note:a key’s value will be always be stripped if its a string
Note:a key’s name will be stored stripped only, must not contain certain chars
Todo:add support for escpaing comas within quotes - currently it split at comas, no matter what
appendValue(value)

Append the given value or list of values to the list of current values

Parameter:value – list, tuple or scalar value
Todo:this implementation could be faster (costing more code)
mergeWith(otherkey)

Merge self with otherkey according to our properties

Note:self will be altered
name
Access the name of the key
order
properties
removeValue(value)

remove the given value or list of values from the list of current values

Parameter:value – list, tuple or scalar value
Todo:this implementation could be faster (costing more code)
value
read: first value if the key’s values write: same effect as write of ‘values’
valueString()
Convert our value to a string suitable for the INI format
values
read: values of the key as list write: write single values or llist of values

Epydoc: mrv.conf.PropertySection

class mrv.conf.PropertySection(name, order)

Bases: mrv.conf.Section

Define a section containing keys that make up properties of somethingI

key(name)
Returns:Key with name
Raises NoOptionError:
 
keyDefault(name, value)
Parameter:value – anything supported by setKey
Returns:tuple: 0 = Key with name, create it if required with given value, 1 = true if newly created, false otherwise
keys
mergeWith(othersection)

Merge our section with othersection

:note:self will be altered

name
order
properties
setKey(name, value)

Set the value to key with name, or create a new key with name and value

Parameter:value – int, long, float, string or list of any of such
Raises ValueError:
 if key has incorrect value

Epydoc: mrv.conf

class mrv.conf.RawConfigParser(defaults=None, dict_type=<type 'dict'>)
add_section(section)

Create a new section in the configuration.

Raise DuplicateSectionError if a section by the specified name already exists. Raise ValueError if name is DEFAULT or any of it’s case-insensitive variants.

defaults()
get(section, option)
getboolean(section, option)
getfloat(section, option)
getint(section, option)
has_option(section, option)
Check for the existence of a given option in a given section.
has_section(section)

Indicate whether the named section is present in the configuration.

The DEFAULT section is not acknowledged.

items(section)
options(section)
Return a list of option names for the given section name.
optionxform(optionstr)
read(filenames)

Read and parse a filename or a list of filenames.

Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given.

Return list of successfully read files.

readfp(fp, filename=None)

Like read() but the argument must be a file-like object.

The `fp’ argument must have a `readline’ method. Optional second argument is the `filename’, which if not given, is taken from fp.name. If fp has no `name’ attribute, `<???>’ is used.

remove_option(section, option)
Remove an option.
remove_section(section)
Remove a file section.
sections()
Return a list of section names, excluding [DEFAULT]
set(section, option, value)
Set an option.
write(fp)
Write an .ini-format representation of the configuration state.

Epydoc: mrv.conf.Section

class mrv.conf.Section(name, order)

Bases: mrv.conf._PropertyHolderBase

Class defininig an indivual section of a configuration file including all its keys and section properties

Note:name will be stored stripped and must not contain certain chars
key(name)
Returns:Key with name
Raises NoOptionError:
 
keyDefault(name, value)
Parameter:value – anything supported by setKey
Returns:tuple: 0 = Key with name, create it if required with given value, 1 = true if newly created, false otherwise
keys
mergeWith(othersection)

Merge our section with othersection

:note:self will be altered

name
order
properties
setKey(name, value)

Set the value to key with name, or create a new key with name and value

Parameter:value – int, long, float, string or list of any of such
Raises ValueError:
 if key has incorrect value

Epydoc: mrv.conf._FixedConfigParser

class mrv.conf._FixedConfigParser(defaults=None, dict_type=<type 'dict'>)

Bases: ConfigParser.RawConfigParser

The RawConfigParser stores options lowercase - but we do not want that and keep the case - for this we just need to override a method

add_section(section)

Create a new section in the configuration.

Raise DuplicateSectionError if a section by the specified name already exists. Raise ValueError if name is DEFAULT or any of it’s case-insensitive variants.

defaults()
get(section, option)
getboolean(section, option)
getfloat(section, option)
getint(section, option)
has_option(section, option)
Check for the existence of a given option in a given section.
has_section(section)

Indicate whether the named section is present in the configuration.

The DEFAULT section is not acknowledged.

items(section)
options(section)
Return a list of option names for the given section name.
optionxform(option)
read(filenames)

Read and parse a filename or a list of filenames.

Files that cannot be opened are silently ignored; this is designed so that you can specify a list of potential configuration file locations (e.g. current directory, user’s home directory, systemwide directory), and all existing configuration files in the list will be read. A single filename may also be given.

Return list of successfully read files.

readfp(fp, filename=None)

Like read() but the argument must be a file-like object.

The `fp’ argument must have a `readline’ method. Optional second argument is the `filename’, which if not given, is taken from fp.name. If fp has no `name’ attribute, `<???>’ is used.

remove_option(section, option)
Remove an option.
remove_section(section)
Remove a file section.
sections()
Return a list of section names, excluding [DEFAULT]
set(section, option, value)
Set an option.
write(fp)
Write an .ini-format representation of the configuration state.

Epydoc: mrv.conf._PropertyHolderBase

class mrv.conf._PropertyHolderBase(name, order)

Bases: object

Simple Base defining how to deal with properties :note: to use this interface, the subclass must have a ‘name’ field

name
order
properties

Exceptions

Epydoc: mrv.conf.ConfigParsingError

class mrv.conf.ConfigParsingError(*args, **kwargs)

Bases: mrv.exc.MRVError

Indicates that the parsing failed

args
message

Epydoc: mrv.conf.ConfigParsingPropertyError

class mrv.conf.ConfigParsingPropertyError(*args, **kwargs)

Bases: mrv.conf.ConfigParsingError

Indicates that the property-parsing encountered a problem

args
message

Epydoc: mrv.conf

class mrv.conf.MRVError(*args, **kwargs)

Bases: exceptions.Exception

Base Class for all exceptions that the mrv framework throws

args
message

Epydoc: mrv.conf

class mrv.conf.NoOptionError(option, section)

Bases: ConfigParser.Error

A requested option was not found.

args
message
Getter for ‘message’; needed only to override deprecation in BaseException.

Epydoc: mrv.conf

class mrv.conf.NoSectionError(section)

Bases: ConfigParser.Error

Raised when no section matches a requested option.

args
message
Getter for ‘message’; needed only to override deprecation in BaseException.

Epydoc: mrv.conf

class mrv.conf.ParsingError(filename)

Bases: ConfigParser.Error

Raised when a configuration file does not follow legal syntax.

append(lineno, line)
args
message
Getter for ‘message’; needed only to override deprecation in BaseException.

Table Of Contents

Previous topic

mrv.path

Next topic

mrv.enum

This Page