Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes
configobj.ConfigParserInterpolation Class Reference
Inheritance diagram for configobj.ConfigParserInterpolation:
Inheritance graph
Collaboration diagram for configobj.ConfigParserInterpolation:
Collaboration graph

List of all members.

Public Member Functions

def interpolate

Public Attributes


Private Member Functions

def _parse_match

Static Private Attributes

tuple _KEYCRE = re.compile(r"%\(([^)]*)\)s")

Detailed Description

Behaves like ConfigParser.

Definition at line 411 of file

Member Function Documentation

def configobj.ConfigParserInterpolation._parse_match (   self,
) [private]
Implementation-dependent helper function.

Will be passed a match object corresponding to the interpolation
key we just found (e.g., "%(foo)s" or "$foo"). Should look up that
key in the appropriate config file section (using the ``_fetch()``
helper function) and return a 3-tuple: (key, value, section)

``key`` is the name of the key we're looking for
``value`` is the value found for that key
``section`` is a reference to the section where it was found

``key`` and ``section`` should be None if no further
interpolation should be performed on the resulting value
(e.g., if we interpolated "$$" and returned "$").

Reimplemented from configobj.InterpolationEngine.

Definition at line 415 of file

00416     def _parse_match(self, match):
00417         key =
00418         value, section = self._fetch(key)
00419         return key, value, section

Here is the call graph for this function:

def configobj.InterpolationEngine.interpolate (   self,
) [inherited]

Definition at line 311 of file

00312     def interpolate(self, key, value):
00313         def recursive_interpolate(key, value, section, backtrail):
00314             """The function that does the actual work.
00316             ``value``: the string we're trying to interpolate.
00317             ``section``: the section in which that string was found
00318             ``backtrail``: a dict to keep track of where we've been,
00319             to detect and prevent infinite recursion loops
00321             This is similar to a depth-first-search algorithm.
00322             """
00323             # Have we been here already?
00324             if backtrail.has_key((key,
00325                 # Yes - infinite loop detected
00326                 raise InterpolationLoopError(key)
00327             # Place a marker on our backtrail so we won't come back here again
00328             backtrail[(key,] = 1
00330             # Now start the actual work
00331             match =
00332             while match:
00333                 # The actual parsing of the match is implementation-dependent,
00334                 # so delegate to our helper function
00335                 k, v, s = self._parse_match(match)
00336                 if k is None:
00337                     # That's the signal that no further interpolation is needed
00338                     replacement = v
00339                 else:
00340                     # Further interpolation may be needed to obtain final value
00341                     replacement = recursive_interpolate(k, v, s, backtrail)
00342                 # Replace the matched string with its final value
00343                 start, end = match.span()
00344                 value = ''.join((value[:start], replacement, value[end:]))
00345                 new_search_start = start + len(replacement)
00346                 # Pick up the next interpolation key, if any, for next time
00347                 # through the while loop
00348                 match =, new_search_start)
00350             # Now safe to come back here again; remove marker from backtrail
00351             del backtrail[(key,]
00353             return value
00355         # Back in interpolate(), all we have to do is kick off the recursive
00356         # function with appropriate starting values
00357         value = recursive_interpolate(key, value, self.section, {})
00358         return value

Here is the call graph for this function:

Member Data Documentation

tuple configobj.ConfigParserInterpolation._KEYCRE = re.compile(r"%\(([^)]*)\)s") [static, private]

Reimplemented from configobj.InterpolationEngine.

Definition at line 413 of file

Definition at line 309 of file

The documentation for this class was generated from the following file: