Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/ShExBy/shex_roo.../proc/self/root/lib64/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 object s 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 OrderedDict as _default_dict, 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
DEFAULTSECT = "DEFAULT"
[159] Fix | Delete
[160] Fix | Delete
MAX_INTERPOLATION_DEPTH = 10
[161] Fix | Delete
[162] Fix | Delete
[163] Fix | Delete
[164] Fix | Delete
# exception classes
[165] Fix | Delete
class Error(Exception):
[166] Fix | Delete
"""Base class for ConfigParser exceptions."""
[167] Fix | Delete
[168] Fix | Delete
def __init__(self, msg=''):
[169] Fix | Delete
self.message = msg
[170] Fix | Delete
Exception.__init__(self, msg)
[171] Fix | Delete
[172] Fix | Delete
def __repr__(self):
[173] Fix | Delete
return self.message
[174] Fix | Delete
[175] Fix | Delete
__str__ = __repr__
[176] Fix | Delete
[177] Fix | Delete
[178] Fix | Delete
class NoSectionError(Error):
[179] Fix | Delete
"""Raised when no section matches a requested option."""
[180] Fix | Delete
[181] Fix | Delete
def __init__(self, section):
[182] Fix | Delete
Error.__init__(self, 'No section: %r' % (section,))
[183] Fix | Delete
self.section = section
[184] Fix | Delete
self.args = (section, )
[185] Fix | Delete
[186] Fix | Delete
[187] Fix | Delete
class DuplicateSectionError(Error):
[188] Fix | Delete
"""Raised when a section is repeated in an input source.
[189] Fix | Delete
[190] Fix | Delete
Possible repetitions that raise this exception are: multiple creation
[191] Fix | Delete
using the API or in strict parsers when a section is found more than once
[192] Fix | Delete
in a single input file, string or dictionary.
[193] Fix | Delete
"""
[194] Fix | Delete
[195] Fix | Delete
def __init__(self, section, source=None, lineno=None):
[196] Fix | Delete
msg = [repr(section), " already exists"]
[197] Fix | Delete
if source is not None:
[198] Fix | Delete
message = ["While reading from ", repr(source)]
[199] Fix | Delete
if lineno is not None:
[200] Fix | Delete
message.append(" [line {0:2d}]".format(lineno))
[201] Fix | Delete
message.append(": section ")
[202] Fix | Delete
message.extend(msg)
[203] Fix | Delete
msg = message
[204] Fix | Delete
else:
[205] Fix | Delete
msg.insert(0, "Section ")
[206] Fix | Delete
Error.__init__(self, "".join(msg))
[207] Fix | Delete
self.section = section
[208] Fix | Delete
self.source = source
[209] Fix | Delete
self.lineno = lineno
[210] Fix | Delete
self.args = (section, source, lineno)
[211] Fix | Delete
[212] Fix | Delete
[213] Fix | Delete
class DuplicateOptionError(Error):
[214] Fix | Delete
"""Raised by strict parsers when an option is repeated in an input source.
[215] Fix | Delete
[216] Fix | Delete
Current implementation raises this exception only when an option is found
[217] Fix | Delete
more than once in a single file, string or dictionary.
[218] Fix | Delete
"""
[219] Fix | Delete
[220] Fix | Delete
def __init__(self, section, option, source=None, lineno=None):
[221] Fix | Delete
msg = [repr(option), " in section ", repr(section),
[222] Fix | Delete
" already exists"]
[223] Fix | Delete
if source is not None:
[224] Fix | Delete
message = ["While reading from ", repr(source)]
[225] Fix | Delete
if lineno is not None:
[226] Fix | Delete
message.append(" [line {0:2d}]".format(lineno))
[227] Fix | Delete
message.append(": option ")
[228] Fix | Delete
message.extend(msg)
[229] Fix | Delete
msg = message
[230] Fix | Delete
else:
[231] Fix | Delete
msg.insert(0, "Option ")
[232] Fix | Delete
Error.__init__(self, "".join(msg))
[233] Fix | Delete
self.section = section
[234] Fix | Delete
self.option = option
[235] Fix | Delete
self.source = source
[236] Fix | Delete
self.lineno = lineno
[237] Fix | Delete
self.args = (section, option, source, lineno)
[238] Fix | Delete
[239] Fix | Delete
[240] Fix | Delete
class NoOptionError(Error):
[241] Fix | Delete
"""A requested option was not found."""
[242] Fix | Delete
[243] Fix | Delete
def __init__(self, option, section):
[244] Fix | Delete
Error.__init__(self, "No option %r in section: %r" %
[245] Fix | Delete
(option, section))
[246] Fix | Delete
self.option = option
[247] Fix | Delete
self.section = section
[248] Fix | Delete
self.args = (option, section)
[249] Fix | Delete
[250] Fix | Delete
[251] Fix | Delete
class InterpolationError(Error):
[252] Fix | Delete
"""Base class for interpolation-related exceptions."""
[253] Fix | Delete
[254] Fix | Delete
def __init__(self, option, section, msg):
[255] Fix | Delete
Error.__init__(self, msg)
[256] Fix | Delete
self.option = option
[257] Fix | Delete
self.section = section
[258] Fix | Delete
self.args = (option, section, msg)
[259] Fix | Delete
[260] Fix | Delete
[261] Fix | Delete
class InterpolationMissingOptionError(InterpolationError):
[262] Fix | Delete
"""A string substitution required a setting which was not available."""
[263] Fix | Delete
[264] Fix | Delete
def __init__(self, option, section, rawval, reference):
[265] Fix | Delete
msg = ("Bad value substitution: option {!r} in section {!r} contains "
[266] Fix | Delete
"an interpolation key {!r} which is not a valid option name. "
[267] Fix | Delete
"Raw value: {!r}".format(option, section, reference, rawval))
[268] Fix | Delete
InterpolationError.__init__(self, option, section, msg)
[269] Fix | Delete
self.reference = reference
[270] Fix | Delete
self.args = (option, section, rawval, reference)
[271] Fix | Delete
[272] Fix | Delete
[273] Fix | Delete
class InterpolationSyntaxError(InterpolationError):
[274] Fix | Delete
"""Raised when the source text contains invalid syntax.
[275] Fix | Delete
[276] Fix | Delete
Current implementation raises this exception when the source text into
[277] Fix | Delete
which substitutions are made does not conform to the required syntax.
[278] Fix | Delete
"""
[279] Fix | Delete
[280] Fix | Delete
[281] Fix | Delete
class InterpolationDepthError(InterpolationError):
[282] Fix | Delete
"""Raised when substitutions are nested too deeply."""
[283] Fix | Delete
[284] Fix | Delete
def __init__(self, option, section, rawval):
[285] Fix | Delete
msg = ("Recursion limit exceeded in value substitution: option {!r} "
[286] Fix | Delete
"in section {!r} contains an interpolation key which "
[287] Fix | Delete
"cannot be substituted in {} steps. Raw value: {!r}"
[288] Fix | Delete
"".format(option, section, MAX_INTERPOLATION_DEPTH,
[289] Fix | Delete
rawval))
[290] Fix | Delete
InterpolationError.__init__(self, option, section, msg)
[291] Fix | Delete
self.args = (option, section, rawval)
[292] Fix | Delete
[293] Fix | Delete
[294] Fix | Delete
class ParsingError(Error):
[295] Fix | Delete
"""Raised when a configuration file does not follow legal syntax."""
[296] Fix | Delete
[297] Fix | Delete
def __init__(self, source=None, filename=None):
[298] Fix | Delete
# Exactly one of `source'/`filename' arguments has to be given.
[299] Fix | Delete
# `filename' kept for compatibility.
[300] Fix | Delete
if filename and source:
[301] Fix | Delete
raise ValueError("Cannot specify both `filename' and `source'. "
[302] Fix | Delete
"Use `source'.")
[303] Fix | Delete
elif not filename and not source:
[304] Fix | Delete
raise ValueError("Required argument `source' not given.")
[305] Fix | Delete
elif filename:
[306] Fix | Delete
source = filename
[307] Fix | Delete
Error.__init__(self, 'Source contains parsing errors: %r' % source)
[308] Fix | Delete
self.source = source
[309] Fix | Delete
self.errors = []
[310] Fix | Delete
self.args = (source, )
[311] Fix | Delete
[312] Fix | Delete
@property
[313] Fix | Delete
def filename(self):
[314] Fix | Delete
"""Deprecated, use `source'."""
[315] Fix | Delete
warnings.warn(
[316] Fix | Delete
"The 'filename' attribute will be removed in future versions. "
[317] Fix | Delete
"Use 'source' instead.",
[318] Fix | Delete
DeprecationWarning, stacklevel=2
[319] Fix | Delete
)
[320] Fix | Delete
return self.source
[321] Fix | Delete
[322] Fix | Delete
@filename.setter
[323] Fix | Delete
def filename(self, value):
[324] Fix | Delete
"""Deprecated, user `source'."""
[325] Fix | Delete
warnings.warn(
[326] Fix | Delete
"The 'filename' attribute will be removed in future versions. "
[327] Fix | Delete
"Use 'source' instead.",
[328] Fix | Delete
DeprecationWarning, stacklevel=2
[329] Fix | Delete
)
[330] Fix | Delete
self.source = value
[331] Fix | Delete
[332] Fix | Delete
def append(self, lineno, line):
[333] Fix | Delete
self.errors.append((lineno, line))
[334] Fix | Delete
self.message += '\n\t[line %2d]: %s' % (lineno, line)
[335] Fix | Delete
[336] Fix | Delete
[337] Fix | Delete
class MissingSectionHeaderError(ParsingError):
[338] Fix | Delete
"""Raised when a key-value pair is found before any section header."""
[339] Fix | Delete
[340] Fix | Delete
def __init__(self, filename, lineno, line):
[341] Fix | Delete
Error.__init__(
[342] Fix | Delete
self,
[343] Fix | Delete
'File contains no section headers.\nfile: %r, line: %d\n%r' %
[344] Fix | Delete
(filename, lineno, line))
[345] Fix | Delete
self.source = filename
[346] Fix | Delete
self.lineno = lineno
[347] Fix | Delete
self.line = line
[348] Fix | Delete
self.args = (filename, lineno, line)
[349] Fix | Delete
[350] Fix | Delete
[351] Fix | Delete
# Used in parser getters to indicate the default behaviour when a specific
[352] Fix | Delete
# option is not found it to raise an exception. Created to enable `None' as
[353] Fix | Delete
# a valid fallback value.
[354] Fix | Delete
_UNSET = object()
[355] Fix | Delete
[356] Fix | Delete
[357] Fix | Delete
class Interpolation:
[358] Fix | Delete
"""Dummy interpolation that passes the value through with no changes."""
[359] Fix | Delete
[360] Fix | Delete
def before_get(self, parser, section, option, value, defaults):
[361] Fix | Delete
return value
[362] Fix | Delete
[363] Fix | Delete
def before_set(self, parser, section, option, value):
[364] Fix | Delete
return value
[365] Fix | Delete
[366] Fix | Delete
def before_read(self, parser, section, option, value):
[367] Fix | Delete
return value
[368] Fix | Delete
[369] Fix | Delete
def before_write(self, parser, section, option, value):
[370] Fix | Delete
return value
[371] Fix | Delete
[372] Fix | Delete
[373] Fix | Delete
class BasicInterpolation(Interpolation):
[374] Fix | Delete
"""Interpolation as implemented in the classic ConfigParser.
[375] Fix | Delete
[376] Fix | Delete
The option values can contain format strings which refer to other values in
[377] Fix | Delete
the same section, or values in the special default section.
[378] Fix | Delete
[379] Fix | Delete
For example:
[380] Fix | Delete
[381] Fix | Delete
something: %(dir)s/whatever
[382] Fix | Delete
[383] Fix | Delete
would resolve the "%(dir)s" to the value of dir. All reference
[384] Fix | Delete
expansions are done late, on demand. If a user needs to use a bare % in
[385] Fix | Delete
a configuration file, she can escape it by writing %%. Other % usage
[386] Fix | Delete
is considered a user error and raises `InterpolationSyntaxError'."""
[387] Fix | Delete
[388] Fix | Delete
_KEYCRE = re.compile(r"%\(([^)]+)\)s")
[389] Fix | Delete
[390] Fix | Delete
def before_get(self, parser, section, option, value, defaults):
[391] Fix | Delete
L = []
[392] Fix | Delete
self._interpolate_some(parser, option, L, value, section, defaults, 1)
[393] Fix | Delete
return ''.join(L)
[394] Fix | Delete
[395] Fix | Delete
def before_set(self, parser, section, option, value):
[396] Fix | Delete
tmp_value = value.replace('%%', '') # escaped percent signs
[397] Fix | Delete
tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
[398] Fix | Delete
if '%' in tmp_value:
[399] Fix | Delete
raise ValueError("invalid interpolation syntax in %r at "
[400] Fix | Delete
"position %d" % (value, tmp_value.find('%')))
[401] Fix | Delete
return value
[402] Fix | Delete
[403] Fix | Delete
def _interpolate_some(self, parser, option, accum, rest, section, map,
[404] Fix | Delete
depth):
[405] Fix | Delete
rawval = parser.get(section, option, raw=True, fallback=rest)
[406] Fix | Delete
if depth > MAX_INTERPOLATION_DEPTH:
[407] Fix | Delete
raise InterpolationDepthError(option, section, rawval)
[408] Fix | Delete
while rest:
[409] Fix | Delete
p = rest.find("%")
[410] Fix | Delete
if p < 0:
[411] Fix | Delete
accum.append(rest)
[412] Fix | Delete
return
[413] Fix | Delete
if p > 0:
[414] Fix | Delete
accum.append(rest[:p])
[415] Fix | Delete
rest = rest[p:]
[416] Fix | Delete
# p is no longer used
[417] Fix | Delete
c = rest[1:2]
[418] Fix | Delete
if c == "%":
[419] Fix | Delete
accum.append("%")
[420] Fix | Delete
rest = rest[2:]
[421] Fix | Delete
elif c == "(":
[422] Fix | Delete
m = self._KEYCRE.match(rest)
[423] Fix | Delete
if m is None:
[424] Fix | Delete
raise InterpolationSyntaxError(option, section,
[425] Fix | Delete
"bad interpolation variable reference %r" % rest)
[426] Fix | Delete
var = parser.optionxform(m.group(1))
[427] Fix | Delete
rest = rest[m.end():]
[428] Fix | Delete
try:
[429] Fix | Delete
v = map[var]
[430] Fix | Delete
except KeyError:
[431] Fix | Delete
raise InterpolationMissingOptionError(
[432] Fix | Delete
option, section, rawval, var) from None
[433] Fix | Delete
if "%" in v:
[434] Fix | Delete
self._interpolate_some(parser, option, accum, v,
[435] Fix | Delete
section, map, depth + 1)
[436] Fix | Delete
else:
[437] Fix | Delete
accum.append(v)
[438] Fix | Delete
else:
[439] Fix | Delete
raise InterpolationSyntaxError(
[440] Fix | Delete
option, section,
[441] Fix | Delete
"'%%' must be followed by '%%' or '(', "
[442] Fix | Delete
"found: %r" % (rest,))
[443] Fix | Delete
[444] Fix | Delete
[445] Fix | Delete
class ExtendedInterpolation(Interpolation):
[446] Fix | Delete
"""Advanced variant of interpolation, supports the syntax used by
[447] Fix | Delete
`zc.buildout'. Enables interpolation between sections."""
[448] Fix | Delete
[449] Fix | Delete
_KEYCRE = re.compile(r"\$\{([^}]+)\}")
[450] Fix | Delete
[451] Fix | Delete
def before_get(self, parser, section, option, value, defaults):
[452] Fix | Delete
L = []
[453] Fix | Delete
self._interpolate_some(parser, option, L, value, section, defaults, 1)
[454] Fix | Delete
return ''.join(L)
[455] Fix | Delete
[456] Fix | Delete
def before_set(self, parser, section, option, value):
[457] Fix | Delete
tmp_value = value.replace('$$', '') # escaped dollar signs
[458] Fix | Delete
tmp_value = self._KEYCRE.sub('', tmp_value) # valid syntax
[459] Fix | Delete
if '$' in tmp_value:
[460] Fix | Delete
raise ValueError("invalid interpolation syntax in %r at "
[461] Fix | Delete
"position %d" % (value, tmp_value.find('$')))
[462] Fix | Delete
return value
[463] Fix | Delete
[464] Fix | Delete
def _interpolate_some(self, parser, option, accum, rest, section, map,
[465] Fix | Delete
depth):
[466] Fix | Delete
rawval = parser.get(section, option, raw=True, fallback=rest)
[467] Fix | Delete
if depth > MAX_INTERPOLATION_DEPTH:
[468] Fix | Delete
raise InterpolationDepthError(option, section, rawval)
[469] Fix | Delete
while rest:
[470] Fix | Delete
p = rest.find("$")
[471] Fix | Delete
if p < 0:
[472] Fix | Delete
accum.append(rest)
[473] Fix | Delete
return
[474] Fix | Delete
if p > 0:
[475] Fix | Delete
accum.append(rest[:p])
[476] Fix | Delete
rest = rest[p:]
[477] Fix | Delete
# p is no longer used
[478] Fix | Delete
c = rest[1:2]
[479] Fix | Delete
if c == "$":
[480] Fix | Delete
accum.append("$")
[481] Fix | Delete
rest = rest[2:]
[482] Fix | Delete
elif c == "{":
[483] Fix | Delete
m = self._KEYCRE.match(rest)
[484] Fix | Delete
if m is None:
[485] Fix | Delete
raise InterpolationSyntaxError(option, section,
[486] Fix | Delete
"bad interpolation variable reference %r" % rest)
[487] Fix | Delete
path = m.group(1).split(':')
[488] Fix | Delete
rest = rest[m.end():]
[489] Fix | Delete
sect = section
[490] Fix | Delete
opt = option
[491] Fix | Delete
try:
[492] Fix | Delete
if len(path) == 1:
[493] Fix | Delete
opt = parser.optionxform(path[0])
[494] Fix | Delete
v = map[opt]
[495] Fix | Delete
elif len(path) == 2:
[496] Fix | Delete
sect = path[0]
[497] Fix | Delete
opt = parser.optionxform(path[1])
[498] Fix | Delete
v = parser.get(sect, opt, raw=True)
[499] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function