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

Type ConfigReader

object --+
         |
        ConfigReader


This internal class implements a parser for configurations.
Method Summary
  __init__(self, config)
  __repr__(self)
  __str__(self)
str getChar(self)
Get the next char from the stream.
A token tuple. getToken(self)
Get a token from the stream.
  load(self, stream, parent, suffix)
Load the configuration from the specified stream.
str location(self)
Return the current location (filename, line, column) in the stream as a string.
a token tuple - see getToken. match(self, t)
Ensure that the current token type matches the specified value, and advance to the next token.
any scalar parseFactor(self)
Parse a factor in an multiplicative expression (a * b, a / b, a % b)
  parseKeyValuePair(self, parent)
Parse a key-value pair, and add it to the provided Mapping.
Mapping parseMapping(self, parent, suffix)
Parse a mapping.
  parseMappingBody(self, parent)
Parse the internals of a mapping, and add entries to the provided Mapping.
Reference parseReference(self, type)
Parse a reference.
any scalar parseScalar(self)
Parse a scalar - a terminal value such as a string or number, or an Expression or Reference.
Sequence parseSequence(self, parent, suffix)
Parse a sequence.
  parseSuffix(self, ref)
Parse a reference suffix.
any scalar parseTerm(self)
Parse a term in an additive expression (a + b, a - b)
any parseValue(self, parent, suffix)
Parse a value.
  setStream(self, stream)
Set the stream to the specified value, and prepare to read from it.
    Inherited from object
  __delattr__(...)
x.__delattr__('name') <==> del x.name
  __getattribute__(...)
x.__getattribute__('name') <==> 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
  __setattr__(...)
x.__setattr__('name', value) <==> x.name = value

Method Details

__init__(self, config)
(Constructor)

Overrides:
__builtin__.object.__init__

__repr__(self)
(Representation operator)

Overrides:
__builtin__.object.__repr__

__str__(self)
(Informal representation operator)

Overrides:
__builtin__.object.__repr__

getChar(self)

Get the next char from the stream. Update line and column numbers appropriately.
Returns:
The next character from the stream.
           (type=str)

getToken(self)

Get a token from the stream. String values are returned in a form where you need to eval() the returned value to get the actual string. The return value is (token_type, token_value).

Multiline string tokenizing is thanks to David Janes (BlogMatrix)
Returns:
The next token.
           (type=A token tuple.)

load(self, stream, parent=None, suffix=None)

Load the configuration from the specified stream.
Parameters:
stream - A stream from which to load the configuration.
           (type=A stream (file-like object).)
parent - The parent of the configuration (to which this reader belongs) in the hierarchy. Specified when the configuration is included in another one.
           (type=A Container instance.)
suffix - The suffix of this configuration in the parent configuration. Should be specified whenever the parent is not None.
Raises:
ConfigError - If parent is specified but suffix is not.
ConfigFormatError - If there are syntax errors in the stream.

location(self)

Return the current location (filename, line, column) in the stream as a string.

Used when printing error messages,
Returns:
A string representing a location in the stream being read.
           (type=str)

match(self, t)

Ensure that the current token type matches the specified value, and advance to the next token.
Parameters:
t - The token type to match.
           (type=A valid token type.)
Returns:
The token which was last read from the stream before this function is called.
           (type=a token tuple - see getToken.)
Raises:
ConfigFormatError - If the token does not match what's expected.

parseFactor(self)

Parse a factor in an multiplicative expression (a * b, a / b, a % b)
Returns:
the parsed factor
           (type=any scalar)
Raises:
ConfigFormatError - if a syntax error is found.

parseKeyValuePair(self, parent)

Parse a key-value pair, and add it to the provided Mapping.
Parameters:
parent - The mapping to add entries to.
           (type=A Mapping instance.)
Raises:
ConfigFormatError - if a syntax error is found.

parseMapping(self, parent, suffix)

Parse a mapping.
Parameters:
parent - The container to which the mapping will be added.
           (type=A Container instance.)
suffix - The suffix for the value.
           (type=str)
Returns:
a Mapping instance representing the mapping.
           (type=Mapping)
Raises:
ConfigFormatError - if a syntax error is found.

parseMappingBody(self, parent)

Parse the internals of a mapping, and add entries to the provided Mapping.
Parameters:
parent - The mapping to add entries to.
           (type=A Mapping instance.)

parseReference(self, type)

Parse a reference.
Returns:
the parsed reference
           (type=Reference)
Raises:
ConfigFormatError - if a syntax error is found.

parseScalar(self)

Parse a scalar - a terminal value such as a string or number, or an Expression or Reference.
Returns:
the parsed scalar
           (type=any scalar)
Raises:
ConfigFormatError - if a syntax error is found.

parseSequence(self, parent, suffix)

Parse a sequence.
Parameters:
parent - The container to which the sequence will be added.
           (type=A Container instance.)
suffix - The suffix for the value.
           (type=str)
Returns:
a Sequence instance representing the sequence.
           (type=Sequence)
Raises:
ConfigFormatError - if a syntax error is found.

parseSuffix(self, ref)

Parse a reference suffix.
Parameters:
ref - The reference of which this suffix is a part.
           (type=Reference.)
Raises:
ConfigFormatError - if a syntax error is found.

parseTerm(self)

Parse a term in an additive expression (a + b, a - b)
Returns:
the parsed term
           (type=any scalar)
Raises:
ConfigFormatError - if a syntax error is found.

parseValue(self, parent, suffix)

Parse a value.
Parameters:
parent - The container to which the value will be added.
           (type=A Container instance.)
suffix - The suffix for the value.
           (type=str)
Returns:
The value
           (type=any)
Raises:
ConfigFormatError - if a syntax error is found.

setStream(self, stream)

Set the stream to the specified value, and prepare to read from it.
Parameters:
stream - A stream from which to load the configuration.
           (type=A stream (file-like object).)