Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes | Private Member Functions | Static Private Attributes
configobj.TemplateInterpolation Class Reference
Inheritance diagram for configobj.TemplateInterpolation:
Inheritance graph
[legend]
Collaboration diagram for configobj.TemplateInterpolation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def interpolate

Public Attributes

 section

Private Member Functions

def _parse_match

Static Private Attributes

string _delimiter = '$'
tuple _KEYCRE = re.compile(r""" \$(?: (?P<escaped>\$) | # Two $ signs (?P<named>[_a-z][_a-z0-9]*) | # $name format {(?P<braced>[^}]*)} # ${name} format ) """, re.IGNORECASE | re.VERBOSE)

Detailed Description

Behaves like string.Template.

Definition at line 421 of file configobj.py.


Member Function Documentation

def configobj.TemplateInterpolation._parse_match (   self,
  match 
) [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 432 of file configobj.py.

00432 
00433     def _parse_match(self, match):
00434         # Valid name (in or out of braces): fetch value from section
00435         key = match.group('named') or match.group('braced')
00436         if key is not None:
00437             value, section = self._fetch(key)
00438             return key, value, section
00439         # Escaped delimiter (e.g., $$): return single delimiter
00440         if match.group('escaped') is not None:
00441             # Return None for key and section to indicate it's time to stop
00442             return None, self._delimiter, None
00443         # Anything else: ignore completely, just return it unchanged
00444         return None, match.group(), None

Here is the call graph for this function:

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

Definition at line 311 of file configobj.py.

00311 
00312     def interpolate(self, key, value):
00313         def recursive_interpolate(key, value, section, backtrail):
00314             """The function that does the actual work.
00315 
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
00320 
00321             This is similar to a depth-first-search algorithm.
00322             """
00323             # Have we been here already?
00324             if backtrail.has_key((key, section.name)):
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, section.name)] = 1
00329 
00330             # Now start the actual work
00331             match = self._KEYCRE.search(value)
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 = self._KEYCRE.search(value, new_search_start)
00349 
00350             # Now safe to come back here again; remove marker from backtrail
00351             del backtrail[(key, section.name)]
00352 
00353             return value
00354 
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

string configobj.TemplateInterpolation._delimiter = '$' [static, private]

Definition at line 423 of file configobj.py.

tuple configobj.TemplateInterpolation._KEYCRE = re.compile(r""" \$(?: (?P<escaped>\$) | # Two $ signs (?P<named>[_a-z][_a-z0-9]*) | # $name format {(?P<braced>[^}]*)} # ${name} format ) """, re.IGNORECASE | re.VERBOSE) [static, private]

Reimplemented from configobj.InterpolationEngine.

Definition at line 424 of file configobj.py.

Definition at line 309 of file configobj.py.


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