Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Static Private Attributes
configparser.ExtendedInterpolation Class Reference
Inheritance diagram for configparser.ExtendedInterpolation:
Inheritance graph
[legend]
Collaboration diagram for configparser.ExtendedInterpolation:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def before_get
def before_set
def before_read
def before_write

Private Member Functions

def _interpolate_some

Static Private Attributes

tuple _KEYCRE = re.compile(r"\$\{([^}]+)\}")

Detailed Description

Advanced variant of interpolation, supports the syntax used by
`zc.buildout'. Enables interpolation between sections.

Definition at line 443 of file configparser.py.


Member Function Documentation

def configparser.ExtendedInterpolation._interpolate_some (   self,
  parser,
  option,
  accum,
  rest,
  section,
  map,
  depth 
) [private]

Definition at line 463 of file configparser.py.

00463 
00464                           depth):
00465         if depth > MAX_INTERPOLATION_DEPTH:
00466             raise InterpolationDepthError(option, section, rest)
00467         while rest:
00468             p = rest.find("$")
00469             if p < 0:
00470                 accum.append(rest)
00471                 return
00472             if p > 0:
00473                 accum.append(rest[:p])
00474                 rest = rest[p:]
00475             # p is no longer used
00476             c = rest[1:2]
00477             if c == "$":
00478                 accum.append("$")
00479                 rest = rest[2:]
00480             elif c == "{":
00481                 m = self._KEYCRE.match(rest)
00482                 if m is None:
00483                     raise InterpolationSyntaxError(option, section,
00484                         "bad interpolation variable reference %r" % rest)
00485                 path = m.group(1).split(':')
00486                 rest = rest[m.end():]
00487                 sect = section
00488                 opt = option
00489                 try:
00490                     if len(path) == 1:
00491                         opt = parser.optionxform(path[0])
00492                         v = map[opt]
00493                     elif len(path) == 2:
00494                         sect = path[0]
00495                         opt = parser.optionxform(path[1])
00496                         v = parser.get(sect, opt, raw=True)
00497                     else:
00498                         raise InterpolationSyntaxError(
00499                             option, section,
00500                             "More than one ':' found: %r" % (rest,))
00501                 except (KeyError, NoSectionError, NoOptionError):
00502                     raise InterpolationMissingOptionError(
00503                         option, section, rest, ":".join(path))
00504                 if "$" in v:
00505                     self._interpolate_some(parser, opt, accum, v, sect,
00506                                            dict(parser.items(sect, raw=True)),
00507                                            depth + 1)
00508                 else:
00509                     accum.append(v)
00510             else:
00511                 raise InterpolationSyntaxError(
00512                     option, section,
00513                     "'$' must be followed by '$' or '{', "
00514                     "found: %r" % (rest,))
00515 

Here is the call graph for this function:

Here is the caller graph for this function:

def configparser.ExtendedInterpolation.before_get (   self,
  parser,
  section,
  option,
  value,
  defaults 
)

Reimplemented from configparser.Interpolation.

Definition at line 449 of file configparser.py.

00449 
00450     def before_get(self, parser, section, option, value, defaults):
00451         L = []
00452         self._interpolate_some(parser, option, L, value, section, defaults, 1)
00453         return ''.join(L)

Here is the call graph for this function:

def configparser.Interpolation.before_read (   self,
  parser,
  section,
  option,
  value 
) [inherited]

Definition at line 365 of file configparser.py.

00365 
00366     def before_read(self, parser, section, option, value):
00367         return value

def configparser.ExtendedInterpolation.before_set (   self,
  parser,
  section,
  option,
  value 
)

Reimplemented from configparser.Interpolation.

Definition at line 454 of file configparser.py.

00454 
00455     def before_set(self, parser, section, option, value):
00456         tmp_value = value.replace('$$', '') # escaped dollar signs
00457         tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
00458         if '$' in tmp_value:
00459             raise ValueError("invalid interpolation syntax in %r at "
00460                              "position %d" % (value, tmp_value.find('%')))
00461         return value

Here is the call graph for this function:

def configparser.Interpolation.before_write (   self,
  parser,
  section,
  option,
  value 
) [inherited]

Definition at line 368 of file configparser.py.

00368 
00369     def before_write(self, parser, section, option, value):
00370         return value
00371 


Member Data Documentation

tuple configparser.ExtendedInterpolation._KEYCRE = re.compile(r"\$\{([^}]+)\}") [static, private]

Definition at line 447 of file configparser.py.


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