Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: configparser.py
"""Configuration file parser.
[0] Fix | Delete
[1] Fix | Delete
A configuration file consists of sections, lead by a "[section]" header,
[2] Fix | Delete
and followed by "name: value" entries, with continuations and such in
[3] Fix | Delete
the style of RFC 822.
[4] Fix | Delete
[5] Fix | Delete
Intrinsic defaults can be specified by passing them into the
[6] Fix | Delete
ConfigParser constructor as a dictionary.
[7] Fix | Delete
[8] Fix | Delete
class:
[9] Fix | Delete
[10] Fix | Delete
ConfigParser -- responsible for parsing a list of
[11] Fix | Delete
configuration files, and managing the parsed database.
[12] Fix | Delete
[13] Fix | Delete
methods:
[14] Fix | Delete
[15] Fix | Delete
__init__(defaults=None, dict_type=_default_dict, allow_no_value=False,
[16] Fix | Delete
delimiters=('=', ':'), comment_prefixes=('#', ';'),
[17] Fix | Delete
inline_comment_prefixes=None, strict=True,
[18] Fix | Delete
empty_lines_in_values=True, default_section='DEFAULT',
[19] Fix | Delete
interpolation=<unset>, converters=<unset>):
[20] Fix | Delete
Create the parser. When `defaults' is given, it is initialized into the
[21] Fix | Delete
dictionary or intrinsic defaults. The keys must be strings, the values
[22] Fix | Delete
must be appropriate for %()s string interpolation.
[23] Fix | Delete
[24] Fix | Delete
When `dict_type' is given, it will be used to create the dictionary
[25] Fix | Delete
objects for the list of sections, for the options within a section, and
[26] Fix | Delete
for the default values.
[27] Fix | Delete
[28] Fix | Delete
When `delimiters' is given, it will be used as the set of substrings
[29] Fix | Delete
that divide keys from values.
[30] Fix | Delete
[31] Fix | Delete
When `comment_prefixes' is given, it will be used as the set of
[32] Fix | Delete
substrings that prefix comments in empty lines. Comments can be
[33] Fix | Delete
indented.
[34] Fix | Delete
[35] Fix | Delete
When `inline_comment_prefixes' is given, it will be used as the set of
[36] Fix | Delete
substrings that prefix comments in non-empty lines.
[37] Fix | Delete
[38] Fix | Delete
When `strict` is True, the parser won't allow for any section or option
[39] Fix | Delete
duplicates while reading from a single source (file, string or
[40] Fix | Delete
dictionary). Default is True.
[41] Fix | Delete
[42] Fix | Delete
When `empty_lines_in_values' is False (default: True), each empty line
[43] Fix | Delete
marks the end of an option. Otherwise, internal empty lines of
[44] Fix | Delete
a multiline option are kept as part of the value.
[45] Fix | Delete
[46] Fix | Delete
When `allow_no_value' is True (default: False), options without
[47] Fix | Delete
values are accepted; the value presented for these is None.
[48] Fix | Delete
[49] Fix | Delete
When `default_section' is given, the name of the special section is
[50] Fix | Delete
named accordingly. By default it is called ``"DEFAULT"`` but this can
[51] Fix | Delete
be customized to point to any other valid section name. Its current
[52] Fix | Delete
value can be retrieved using the ``parser_instance.default_section``
[53] Fix | Delete
attribute and may be modified at runtime.
[54] Fix | Delete
[55] Fix | Delete
When `interpolation` is given, it should be an Interpolation subclass
[56] Fix | Delete
instance. It will be used as the handler for option value
[57] Fix | Delete
pre-processing when using getters. RawConfigParser objects don't do
[58] Fix | Delete
any sort of interpolation, whereas ConfigParser uses an instance of
[59] Fix | Delete
BasicInterpolation. The library also provides a ``zc.buildbot``
[60] Fix | Delete
inspired ExtendedInterpolation implementation.
[61] Fix | Delete
[62] Fix | Delete
When `converters` is given, it should be a dictionary where each key
[63] Fix | Delete
represents the name of a type converter and each value is a callable
[64] Fix | Delete
implementing the conversion from string to the desired datatype. Every
[65] Fix | Delete
converter gets its corresponding get*() method on the parser object and
[66] Fix | Delete
section proxies.
[67] Fix | Delete
[68] Fix | Delete
sections()
[69] Fix | Delete
Return all the configuration section names, sans DEFAULT.
[70] Fix | Delete
[71] Fix | Delete
has_section(section)
[72] Fix | Delete
Return whether the given section exists.
[73] Fix | Delete
[74] Fix | Delete
has_option(section, option)
[75] Fix | Delete
Return whether the given option exists in the given section.
[76] Fix | Delete
[77] Fix | Delete
options(section)
[78] Fix | Delete
Return list of configuration options for the named section.
[79] Fix | Delete
[80] Fix | Delete
read(filenames, encoding=None)
[81] Fix | Delete
Read and parse the iterable of named configuration files, given by
[82] Fix | Delete
name. A single filename is also allowed. Non-existing files
[83] Fix | Delete
are ignored. Return list of successfully read files.
[84] Fix | Delete
[85] Fix | Delete
read_file(f, filename=None)
[86] Fix | Delete
Read and parse one configuration file, given as a file object.
[87] Fix | Delete
The filename defaults to f.name; it is only used in error
[88] Fix | Delete
messages (if f has no `name' attribute, the string `<???>' is used).
[89] Fix | Delete
[90] Fix | Delete
read_string(string)
[91] Fix | Delete
Read configuration from a given string.
[92] Fix | Delete
[93] Fix | Delete
read_dict(dictionary)
[94] Fix | Delete
Read configuration from a dictionary. Keys are section names,
[95] Fix | Delete
values are dictionaries with keys and values that should be present
[96] Fix | Delete
in the section. If the used dictionary type preserves order, sections
[97] Fix | Delete
and their keys will be added in order. Values are automatically
[98] Fix | Delete
converted to strings.
[99] Fix | Delete
[100] Fix | Delete
get(section, option, raw=False, vars=None, fallback=_UNSET)
[101] Fix | Delete
Return a string value for the named option. All % interpolations are
[102] Fix | Delete
expanded in the return values, based on the defaults passed into the
[103] Fix | Delete
constructor and the DEFAULT section. Additional substitutions may be
[104] Fix | Delete
provided using the `vars' argument, which must be a dictionary whose
[105] Fix | Delete
contents override any pre-existing defaults. If `option' is a key in
[106] Fix | Delete
`vars', the value from `vars' is used.
[107] Fix | Delete
[108] Fix | Delete
getint(section, options, raw=False, vars=None, fallback=_UNSET)
[109] Fix | Delete
Like get(), but convert value to an integer.
[110] Fix | Delete
[111] Fix | Delete
getfloat(section, options, raw=False, vars=None, fallback=_UNSET)
[112] Fix | Delete
Like get(), but convert value to a float.
[113] Fix | Delete
[114] Fix | Delete
getboolean(section, options, raw=False, vars=None, fallback=_UNSET)
[115] Fix | Delete
Like get(), but convert value to a boolean (currently case
[116] Fix | Delete
insensitively defined as 0, false, no, off for False, and 1, true,
[117] Fix | Delete
yes, on for True). Returns False or True.
[118] Fix | Delete
[119] Fix | Delete
items(section=_UNSET, raw=False, vars=None)
[120] Fix | Delete
If section is given, return a list of tuples with (name, value) for
[121] Fix | Delete
each option in the section. Otherwise, return a list of tuples with
[122] Fix | Delete
(section_name, section_proxy) for each section, including DEFAULTSECT.
[123] Fix | Delete
[124] Fix | Delete
remove_section(section)
[125] Fix | Delete
Remove the given file section and all its options.
[126] Fix | Delete
[127] Fix | Delete
remove_option(section, option)
[128] Fix | Delete
Remove the given option from the given section.
[129] Fix | Delete
[130] Fix | Delete
set(section, option, value)
[131] Fix | Delete
Set the given option.
[132] Fix | Delete
[133] Fix | Delete
write(fp, space_around_delimiters=True)
[134] Fix | Delete
Write the configuration state in .ini format. If
[135] Fix | Delete
`space_around_delimiters' is True (the default), delimiters
[136] Fix | Delete
between keys and values are surrounded by spaces.
[137] Fix | Delete
"""
[138] Fix | Delete
[139] Fix | Delete
from collections.abc import MutableMapping
[140] Fix | Delete
from collections import ChainMap as _ChainMap
[141] Fix | Delete
import functools
[142] Fix | Delete
import io
[143] Fix | Delete
import itertools
[144] Fix | Delete
import os
[145] Fix | Delete
import re
[146] Fix | Delete
import sys
[147] Fix | Delete
import warnings
[148] Fix | Delete
[149] Fix | Delete
__all__ = ["NoSectionError", "DuplicateOptionError", "DuplicateSectionError",
[150] Fix | Delete
"NoOptionError", "InterpolationError", "InterpolationDepthError",
[151] Fix | Delete
"InterpolationMissingOptionError", "InterpolationSyntaxError",
[152] Fix | Delete
"ParsingError", "MissingSectionHeaderError",
[153] Fix | Delete
"ConfigParser", "SafeConfigParser", "RawConfigParser",
[154] Fix | Delete
"Interpolation", "BasicInterpolation", "ExtendedInterpolation",
[155] Fix | Delete
"LegacyInterpolation", "SectionProxy", "ConverterMapping",
[156] Fix | Delete
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
[157] Fix | Delete
[158] Fix | Delete
_default_dict = dict
[159] Fix | Delete
DEFAULTSECT = "DEFAULT"
[160] Fix | Delete
[161] Fix | Delete
MAX_INTERPOLATION_DEPTH = 10
[162] Fix | Delete
[163] Fix | Delete
[164] Fix | Delete
[165] Fix | Delete
# exception classes
[166] Fix | Delete
class Error(Exception):
[167] Fix | Delete
"""Base class for ConfigParser exceptions."""
[168] Fix | Delete
[169] Fix | Delete
def __init__(self, msg=''):
[170] Fix | Delete
self.message = msg
[171] Fix | Delete
Exception.__init__(self, msg)
[172] Fix | Delete
[173] Fix | Delete
def __repr__(self):
[174] Fix | Delete
return self.message
[175] Fix | Delete
[176] Fix | Delete
__str__ = __repr__
[177] Fix | Delete
[178] Fix | Delete
[179] Fix | Delete
class NoSectionError(Error):
[180] Fix | Delete
"""Raised when no section matches a requested option."""
[181] Fix | Delete
[182] Fix | Delete
def __init__(self, section):
[183] Fix | Delete
Error.__init__(self, 'No section: %r' % (section,))
[184] Fix | Delete
self.section = section
[185] Fix | Delete
self.args = (section, )
[186] Fix | Delete
[187] Fix | Delete
[188] Fix | Delete
class DuplicateSectionError(Error):
[189] Fix | Delete
"""Raised when a section is repeated in an input source.
[190] Fix | Delete
[191] Fix | Delete
Possible repetitions that raise this exception are: multiple creation
[192] Fix | Delete
using the API or in strict parsers when a section is found more than once
[193] Fix | Delete
in a single input file, string or dictionary.
[194] Fix | Delete
"""
[195] Fix | Delete
[196] Fix | Delete
def __init__(self, section, source=None, lineno=None):
[197] Fix | Delete
msg = [repr(section), " already exists"]
[198] Fix | Delete
if source is not None:
[199] Fix | Delete
message = ["While reading from ", repr(source)]
[200] Fix | Delete
if lineno is not None:
[201] Fix | Delete
message.append(" [line {0:2d}]".format(lineno))
[202] Fix | Delete
message.append(": section ")
[203] Fix | Delete
message.extend(msg)
[204] Fix | Delete
msg = message
[205] Fix | Delete
else:
[206] Fix | Delete
msg.insert(0, "Section ")
[207] Fix | Delete
Error.__init__(self, "".join(msg))
[208] Fix | Delete
self.section = section
[209] Fix | Delete
self.source = source
[210] Fix | Delete
self.lineno = lineno
[211] Fix | Delete
self.args = (section, source, lineno)
[212] Fix | Delete
[213] Fix | Delete
[214] Fix | Delete
class DuplicateOptionError(Error):
[215] Fix | Delete
"""Raised by strict parsers when an option is repeated in an input source.
[216] Fix | Delete
[217] Fix | Delete
Current implementation raises this exception only when an option is found
[218] Fix | Delete
more than once in a single file, string or dictionary.
[219] Fix | Delete
"""
[220] Fix | Delete
[221] Fix | Delete
def __init__(self, section, option, source=None, lineno=None):
[222] Fix | Delete
msg = [repr(option), " in section ", repr(section),
[223] Fix | Delete
" already exists"]
[224] Fix | Delete
if source is not None:
[225] Fix | Delete
message = ["While reading from ", repr(source)]
[226] Fix | Delete
if lineno is not None:
[227] Fix | Delete
message.append(" [line {0:2d}]".format(lineno))
[228] Fix | Delete
message.append(": option ")
[229] Fix | Delete
message.extend(msg)
[230] Fix | Delete
msg = message
[231] Fix | Delete
else:
[232] Fix | Delete
msg.insert(0, "Option ")
[233] Fix | Delete
Error.__init__(self, "".join(msg))
[234] Fix | Delete
self.section = section
[235] Fix | Delete
self.option = option
[236] Fix | Delete
self.source = source
[237] Fix | Delete
self.lineno = lineno
[238] Fix | Delete
self.args = (section, option, source, lineno)
[239] Fix | Delete
[240] Fix | Delete
[241] Fix | Delete
class NoOptionError(Error):
[242] Fix | Delete
"""A requested option was not found."""
[243] Fix | Delete
[244] Fix | Delete
def __init__(self, option, section):
[245] Fix | Delete
Error.__init__(self, "No option %r in section: %r" %
[246] Fix | Delete
(option, section))
[247] Fix | Delete
self.option = option
[248] Fix | Delete
self.section = section
[249] Fix | Delete
self.args = (option, section)
[250] Fix | Delete
[251] Fix | Delete
[252] Fix | Delete
class InterpolationError(Error):
[253] Fix | Delete
"""Base class for interpolation-related exceptions."""
[254] Fix | Delete
[255] Fix | Delete
def __init__(self, option, section, msg):
[256] Fix | Delete
Error.__init__(self, msg)
[257] Fix | Delete
self.option = option
[258] Fix | Delete
self.section = section
[259] Fix | Delete
self.args = (option, section, msg)
[260] Fix | Delete
[261] Fix | Delete
[262] Fix | Delete
class InterpolationMissingOptionError(InterpolationError):
[263] Fix | Delete
"""A string substitution required a setting which was not available."""
[264] Fix | Delete
[265] Fix | Delete
def __init__(self, option, section, rawval, reference):
[266] Fix | Delete
msg = ("Bad value substitution: option {!r} in section {!r} contains "
[267] Fix | Delete
"an interpolation key {!r} which is not a valid option name. "
[268] Fix | Delete
"Raw value: {!r}".format(option, section, reference, rawval))
[269] Fix | Delete
InterpolationError.__init__(self, option, section, msg)
[270] Fix | Delete
self.reference = reference
[271] Fix | Delete
self.args = (option, section, rawval, reference)
[272] Fix | Delete
[273] Fix | Delete
[274] Fix | Delete
class InterpolationSyntaxError(InterpolationError):
[275] Fix | Delete
"""Raised when the source text contains invalid syntax.
[276] Fix | Delete
[277] Fix | Delete
Current implementation raises this exception when the source text into
[278] Fix | Delete
which substitutions are made does not conform to the required syntax.
[279] Fix | Delete
"""
[280] Fix | Delete
[281] Fix | Delete
[282] Fix | Delete
class InterpolationDepthError(InterpolationError):
[283] Fix | Delete
"""Raised when substitutions are nested too deeply."""
[284] Fix | Delete
[285] Fix | Delete
def __init__(self, option, section, rawval):
[286] Fix | Delete
msg = ("Recursion limit exceeded in value substitution: option {!r} "
[287] Fix | Delete
"in section {!r} contains an interpolation key which "
[288] Fix | Delete
"cannot be substituted in {} steps. Raw value: {!r}"
[289] Fix | Delete
"".format(option, section, MAX_INTERPOLATION_DEPTH,
[290] Fix | Delete
rawval))
[291] Fix | Delete
InterpolationError.__init__(self, option, section, msg)
[292] Fix | Delete
self.args = (option, section, rawval)
[293] Fix | Delete
[294] Fix | Delete
[295] Fix | Delete
class ParsingError(Error):
[296] Fix | Delete
"""Raised when a configuration file does not follow legal syntax."""
[297] Fix | Delete
[298] Fix | Delete
def __init__(self, source=None, filename=None):
[299] Fix | Delete
# Exactly one of `source'/`filename' arguments has to be given.
[300] Fix | Delete
# `filename' kept for compatibility.
[301] Fix | Delete
if filename and source:
[302] Fix | Delete
raise ValueError("Cannot specify both `filename' and `source'. "
[303] Fix | Delete
"Use `source'.")
[304] Fix | Delete
elif not filename and not source:
[305] Fix | Delete
raise ValueError("Required argument `source' not given.")
[306] Fix | Delete
elif filename:
[307] Fix | Delete
source = filename
[308] Fix | Delete
Error.__init__(self, 'Source contains parsing errors: %r' % source)
[309] Fix | Delete
self.source = source
[310] Fix | Delete
self.errors = []
[311] Fix | Delete
self.args = (source, )
[312] Fix | Delete
[313] Fix | Delete
@property
[314] Fix | Delete
def filename(self):
[315] Fix | Delete
"""Deprecated, use `source'."""
[316] Fix | Delete
warnings.warn(
[317] Fix | Delete
"The 'filename' attribute will be removed in future versions. "
[318] Fix | Delete
"Use 'source' instead.",
[319] Fix | Delete
DeprecationWarning, stacklevel=2
[320] Fix | Delete
)
[321] Fix | Delete
return self.source
[322] Fix | Delete
[323] Fix | Delete
@filename.setter
[324] Fix | Delete
def filename(self, value):
[325] Fix | Delete
"""Deprecated, user `source'."""
[326] Fix | Delete
warnings.warn(
[327] Fix | Delete
"The 'filename' attribute will be removed in future versions. "
[328] Fix | Delete
"Use 'source' instead.",
[329] Fix | Delete
DeprecationWarning, stacklevel=2
[330] Fix | Delete
)
[331] Fix | Delete
self.source = value
[332] Fix | Delete
[333] Fix | Delete
def append(self, lineno, line):
[334] Fix | Delete
self.errors.append((lineno, line))
[335] Fix | Delete
self.message += '\n\t[line %2d]: %s' % (lineno, line)
[336] Fix | Delete
[337] Fix | Delete
[338] Fix | Delete
class MissingSectionHeaderError(ParsingError):
[339] Fix | Delete
"""Raised when a key-value pair is found before any section header."""
[340] Fix | Delete
[341] Fix | Delete
def __init__(self, filename, lineno, line):
[342] Fix | Delete
Error.__init__(
[343] Fix | Delete
self,
[344] Fix | Delete
'File contains no section headers.\nfile: %r, line: %d\n%r' %
[345] Fix | Delete
(filename, lineno, line))
[346] Fix | Delete
self.source = filename
[347] Fix | Delete
self.lineno = lineno
[348] Fix | Delete
self.line = line
[349] Fix | Delete
self.args = (filename, lineno, line)
[350] Fix | Delete
[351] Fix | Delete
[352] Fix | Delete
# Used in parser getters to indicate the default behaviour when a specific
[353] Fix | Delete
# option is not found it to raise an exception. Created to enable `None' as
[354] Fix | Delete
# a valid fallback value.
[355] Fix | Delete
_UNSET = object()
[356] Fix | Delete
[357] Fix | Delete
[358] Fix | Delete
class Interpolation:
[359] Fix | Delete
"""Dummy interpolation that passes the value through with no changes."""
[360] Fix | Delete
[361] Fix | Delete
def before_get(self, parser, section, option, value, defaults):
[362] Fix | Delete
return value
[363] Fix | Delete
[364] Fix | Delete
def before_set(self, parser, section, option, value):
[365] Fix | Delete
return value
[366] Fix | Delete
[367] Fix | Delete
def before_read(self, parser, section, option, value):
[368] Fix | Delete
return value
[369] Fix | Delete
[370] Fix | Delete
def before_write(self, parser, section, option, value):
[371] Fix | Delete
return value
[372] Fix | Delete
[373] Fix | Delete
[374] Fix | Delete
class BasicInterpolation(Interpolation):
[375] Fix | Delete
"""Interpolation as implemented in the classic ConfigParser.
[376] Fix | Delete
[377] Fix | Delete
The option values can contain format strings which refer to other values in
[378] Fix | Delete
the same section, or values in the special default section.
[379] Fix | Delete
[380] Fix | Delete
For example:
[381] Fix | Delete
[382] Fix | Delete
something: %(dir)s/whatever
[383] Fix | Delete
[384] Fix | Delete
would resolve the "%(dir)s" to the value of dir. All reference
[385] Fix | Delete
expansions are done late, on demand. If a user needs to use a bare % in
[386] Fix | Delete
a configuration file, she can escape it by writing %%. Other % usage
[387] Fix | Delete
is considered a user error and raises `InterpolationSyntaxError'."""
[388] Fix | Delete
[389] Fix | Delete
_KEYCRE = re.compile(r"%\(([^)]+)\)s")
[390] Fix | Delete
[391] Fix | Delete
def before_get(self, parser, section, option, value, defaults):
[392] Fix | Delete
L = []
[393] Fix | Delete
self._interpolate_some(parser, option, L, value, section, defaults, 1)
[394] Fix | Delete
return ''.join(L)
[395] Fix | Delete
[396] Fix | Delete
def before_set(self, parser, section, option, value):
[397] Fix | Delete
tmp_value = value.replace('%%', '') # escaped percent signs
[398] Fix | Delete
tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
[399] Fix | Delete
if '%' in tmp_value:
[400] Fix | Delete
raise ValueError("invalid interpolation syntax in %r at "
[401] Fix | Delete
"position %d" % (value, tmp_value.find('%')))
[402] Fix | Delete
return value
[403] Fix | Delete
[404] Fix | Delete
def _interpolate_some(self, parser, option, accum, rest, section, map,
[405] Fix | Delete
depth):
[406] Fix | Delete
rawval = parser.get(section, option, raw=True, fallback=rest)
[407] Fix | Delete
if depth > MAX_INTERPOLATION_DEPTH:
[408] Fix | Delete
raise InterpolationDepthError(option, section, rawval)
[409] Fix | Delete
while rest:
[410] Fix | Delete
p = rest.find("%")
[411] Fix | Delete
if p < 0:
[412] Fix | Delete
accum.append(rest)
[413] Fix | Delete
return
[414] Fix | Delete
if p > 0:
[415] Fix | Delete
accum.append(rest[:p])
[416] Fix | Delete
rest = rest[p:]
[417] Fix | Delete
# p is no longer used
[418] Fix | Delete
c = rest[1:2]
[419] Fix | Delete
if c == "%":
[420] Fix | Delete
accum.append("%")
[421] Fix | Delete
rest = rest[2:]
[422] Fix | Delete
elif c == "(":
[423] Fix | Delete
m = self._KEYCRE.match(rest)
[424] Fix | Delete
if m is None:
[425] Fix | Delete
raise InterpolationSyntaxError(option, section,
[426] Fix | Delete
"bad interpolation variable reference %r" % rest)
[427] Fix | Delete
var = parser.optionxform(m.group(1))
[428] Fix | Delete
rest = rest[m.end():]
[429] Fix | Delete
try:
[430] Fix | Delete
v = map[var]
[431] Fix | Delete
except KeyError:
[432] Fix | Delete
raise InterpolationMissingOptionError(
[433] Fix | Delete
option, section, rawval, var) from None
[434] Fix | Delete
if "%" in v:
[435] Fix | Delete
self._interpolate_some(parser, option, accum, v,
[436] Fix | Delete
section, map, depth + 1)
[437] Fix | Delete
else:
[438] Fix | Delete
accum.append(v)
[439] Fix | Delete
else:
[440] Fix | Delete
raise InterpolationSyntaxError(
[441] Fix | Delete
option, section,
[442] Fix | Delete
"'%%' must be followed by '%%' or '(', "
[443] Fix | Delete
"found: %r" % (rest,))
[444] Fix | Delete
[445] Fix | Delete
[446] Fix | Delete
class ExtendedInterpolation(Interpolation):
[447] Fix | Delete
"""Advanced variant of interpolation, supports the syntax used by
[448] Fix | Delete
`zc.buildout'. Enables interpolation between sections."""
[449] Fix | Delete
[450] Fix | Delete
_KEYCRE = re.compile(r"\$\{([^}]+)\}")
[451] Fix | Delete
[452] Fix | Delete
def before_get(self, parser, section, option, value, defaults):
[453] Fix | Delete
L = []
[454] Fix | Delete
self._interpolate_some(parser, option, L, value, section, defaults, 1)
[455] Fix | Delete
return ''.join(L)
[456] Fix | Delete
[457] Fix | Delete
def before_set(self, parser, section, option, value):
[458] Fix | Delete
tmp_value = value.replace('$$', '') # escaped dollar signs
[459] Fix | Delete
tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
[460] Fix | Delete
if '$' in tmp_value:
[461] Fix | Delete
raise ValueError("invalid interpolation syntax in %r at "
[462] Fix | Delete
"position %d" % (value, tmp_value.find('$')))
[463] Fix | Delete
return value
[464] Fix | Delete
[465] Fix | Delete
def _interpolate_some(self, parser, option, accum, rest, section, map,
[466] Fix | Delete
depth):
[467] Fix | Delete
rawval = parser.get(section, option, raw=True, fallback=rest)
[468] Fix | Delete
if depth > MAX_INTERPOLATION_DEPTH:
[469] Fix | Delete
raise InterpolationDepthError(option, section, rawval)
[470] Fix | Delete
while rest:
[471] Fix | Delete
p = rest.find("$")
[472] Fix | Delete
if p < 0:
[473] Fix | Delete
accum.append(rest)
[474] Fix | Delete
return
[475] Fix | Delete
if p > 0:
[476] Fix | Delete
accum.append(rest[:p])
[477] Fix | Delete
rest = rest[p:]
[478] Fix | Delete
# p is no longer used
[479] Fix | Delete
c = rest[1:2]
[480] Fix | Delete
if c == "$":
[481] Fix | Delete
accum.append("$")
[482] Fix | Delete
rest = rest[2:]
[483] Fix | Delete
elif c == "{":
[484] Fix | Delete
m = self._KEYCRE.match(rest)
[485] Fix | Delete
if m is None:
[486] Fix | Delete
raise InterpolationSyntaxError(option, section,
[487] Fix | Delete
"bad interpolation variable reference %r" % rest)
[488] Fix | Delete
path = m.group(1).split(':')
[489] Fix | Delete
rest = rest[m.end():]
[490] Fix | Delete
sect = section
[491] Fix | Delete
opt = option
[492] Fix | Delete
try:
[493] Fix | Delete
if len(path) == 1:
[494] Fix | Delete
opt = parser.optionxform(path[0])
[495] Fix | Delete
v = map[opt]
[496] Fix | Delete
elif len(path) == 2:
[497] Fix | Delete
sect = path[0]
[498] Fix | Delete
opt = parser.optionxform(path[1])
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function