Back to index

python3.2  3.2.2
Public Member Functions | Private Member Functions | Static Private Attributes
configparser.BasicInterpolation Class Reference
Inheritance diagram for configparser.BasicInterpolation:
Inheritance graph
[legend]
Collaboration diagram for configparser.BasicInterpolation:
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"%\(([^)]+)\)s")

Detailed Description

Interpolation as implemented in the classic ConfigParser.

The option values can contain format strings which refer to other values in
the same section, or values in the special default section.

For example:

    something: %(dir)s/whatever

would resolve the "%(dir)s" to the value of dir.  All reference
expansions are done late, on demand. If a user needs to use a bare % in
a configuration file, she can escape it by writing %%. Other other % usage
is considered a user error and raises `InterpolationSyntaxError'.

Definition at line 372 of file configparser.py.


Member Function Documentation

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

Definition at line 403 of file configparser.py.

00403 
00404                           depth):
00405         if depth > MAX_INTERPOLATION_DEPTH:
00406             raise InterpolationDepthError(option, section, rest)
00407         while rest:
00408             p = rest.find("%")
00409             if p < 0:
00410                 accum.append(rest)
00411                 return
00412             if p > 0:
00413                 accum.append(rest[:p])
00414                 rest = rest[p:]
00415             # p is no longer used
00416             c = rest[1:2]
00417             if c == "%":
00418                 accum.append("%")
00419                 rest = rest[2:]
00420             elif c == "(":
00421                 m = self._KEYCRE.match(rest)
00422                 if m is None:
00423                     raise InterpolationSyntaxError(option, section,
00424                         "bad interpolation variable reference %r" % rest)
00425                 var = parser.optionxform(m.group(1))
00426                 rest = rest[m.end():]
00427                 try:
00428                     v = map[var]
00429                 except KeyError:
00430                     raise InterpolationMissingOptionError(
00431                         option, section, rest, var)
00432                 if "%" in v:
00433                     self._interpolate_some(parser, option, accum, v,
00434                                            section, map, depth + 1)
00435                 else:
00436                     accum.append(v)
00437             else:
00438                 raise InterpolationSyntaxError(
00439                     option, section,
00440                     "'%%' must be followed by '%%' or '(', "
00441                     "found: %r" % (rest,))
00442 

Here is the call graph for this function:

Here is the caller graph for this function:

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

Reimplemented from configparser.Interpolation.

Definition at line 389 of file configparser.py.

00389 
00390     def before_get(self, parser, section, option, value, defaults):
00391         L = []
00392         self._interpolate_some(parser, option, L, value, section, defaults, 1)
00393         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.BasicInterpolation.before_set (   self,
  parser,
  section,
  option,
  value 
)

Reimplemented from configparser.Interpolation.

Definition at line 394 of file configparser.py.

00394 
00395     def before_set(self, parser, section, option, value):
00396         tmp_value = value.replace('%%', '') # escaped percent signs
00397         tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
00398         if '%' in tmp_value:
00399             raise ValueError("invalid interpolation syntax in %r at "
00400                              "position %d" % (value, tmp_value.find('%')))
00401         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.BasicInterpolation._KEYCRE = re.compile(r"%\(([^)]+)\)s") [static, private]

Definition at line 387 of file configparser.py.


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