Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: configparser.py
else:
[500] Fix | Delete
raise InterpolationSyntaxError(
[501] Fix | Delete
option, section,
[502] Fix | Delete
"More than one ':' found: %r" % (rest,))
[503] Fix | Delete
except (KeyError, NoSectionError, NoOptionError):
[504] Fix | Delete
raise InterpolationMissingOptionError(
[505] Fix | Delete
option, section, rawval, ":".join(path)) from None
[506] Fix | Delete
if "$" in v:
[507] Fix | Delete
self._interpolate_some(parser, opt, accum, v, sect,
[508] Fix | Delete
dict(parser.items(sect, raw=True)),
[509] Fix | Delete
depth + 1)
[510] Fix | Delete
else:
[511] Fix | Delete
accum.append(v)
[512] Fix | Delete
else:
[513] Fix | Delete
raise InterpolationSyntaxError(
[514] Fix | Delete
option, section,
[515] Fix | Delete
"'$' must be followed by '$' or '{', "
[516] Fix | Delete
"found: %r" % (rest,))
[517] Fix | Delete
[518] Fix | Delete
[519] Fix | Delete
class LegacyInterpolation(Interpolation):
[520] Fix | Delete
"""Deprecated interpolation used in old versions of ConfigParser.
[521] Fix | Delete
Use BasicInterpolation or ExtendedInterpolation instead."""
[522] Fix | Delete
[523] Fix | Delete
_KEYCRE = re.compile(r"%\(([^)]*)\)s|.")
[524] Fix | Delete
[525] Fix | Delete
def before_get(self, parser, section, option, value, vars):
[526] Fix | Delete
rawval = value
[527] Fix | Delete
depth = MAX_INTERPOLATION_DEPTH
[528] Fix | Delete
while depth: # Loop through this until it's done
[529] Fix | Delete
depth -= 1
[530] Fix | Delete
if value and "%(" in value:
[531] Fix | Delete
replace = functools.partial(self._interpolation_replace,
[532] Fix | Delete
parser=parser)
[533] Fix | Delete
value = self._KEYCRE.sub(replace, value)
[534] Fix | Delete
try:
[535] Fix | Delete
value = value % vars
[536] Fix | Delete
except KeyError as e:
[537] Fix | Delete
raise InterpolationMissingOptionError(
[538] Fix | Delete
option, section, rawval, e.args[0]) from None
[539] Fix | Delete
else:
[540] Fix | Delete
break
[541] Fix | Delete
if value and "%(" in value:
[542] Fix | Delete
raise InterpolationDepthError(option, section, rawval)
[543] Fix | Delete
return value
[544] Fix | Delete
[545] Fix | Delete
def before_set(self, parser, section, option, value):
[546] Fix | Delete
return value
[547] Fix | Delete
[548] Fix | Delete
@staticmethod
[549] Fix | Delete
def _interpolation_replace(match, parser):
[550] Fix | Delete
s = match.group(1)
[551] Fix | Delete
if s is None:
[552] Fix | Delete
return match.group()
[553] Fix | Delete
else:
[554] Fix | Delete
return "%%(%s)s" % parser.optionxform(s)
[555] Fix | Delete
[556] Fix | Delete
[557] Fix | Delete
class RawConfigParser(MutableMapping):
[558] Fix | Delete
"""ConfigParser that does not do interpolation."""
[559] Fix | Delete
[560] Fix | Delete
# Regular expressions for parsing section headers and options
[561] Fix | Delete
_SECT_TMPL = r"""
[562] Fix | Delete
\[ # [
[563] Fix | Delete
(?P<header>[^]]+) # very permissive!
[564] Fix | Delete
\] # ]
[565] Fix | Delete
"""
[566] Fix | Delete
_OPT_TMPL = r"""
[567] Fix | Delete
(?P<option>.*?) # very permissive!
[568] Fix | Delete
\s*(?P<vi>{delim})\s* # any number of space/tab,
[569] Fix | Delete
# followed by any of the
[570] Fix | Delete
# allowed delimiters,
[571] Fix | Delete
# followed by any space/tab
[572] Fix | Delete
(?P<value>.*)$ # everything up to eol
[573] Fix | Delete
"""
[574] Fix | Delete
_OPT_NV_TMPL = r"""
[575] Fix | Delete
(?P<option>.*?) # very permissive!
[576] Fix | Delete
\s*(?: # any number of space/tab,
[577] Fix | Delete
(?P<vi>{delim})\s* # optionally followed by
[578] Fix | Delete
# any of the allowed
[579] Fix | Delete
# delimiters, followed by any
[580] Fix | Delete
# space/tab
[581] Fix | Delete
(?P<value>.*))?$ # everything up to eol
[582] Fix | Delete
"""
[583] Fix | Delete
# Interpolation algorithm to be used if the user does not specify another
[584] Fix | Delete
_DEFAULT_INTERPOLATION = Interpolation()
[585] Fix | Delete
# Compiled regular expression for matching sections
[586] Fix | Delete
SECTCRE = re.compile(_SECT_TMPL, re.VERBOSE)
[587] Fix | Delete
# Compiled regular expression for matching options with typical separators
[588] Fix | Delete
OPTCRE = re.compile(_OPT_TMPL.format(delim="=|:"), re.VERBOSE)
[589] Fix | Delete
# Compiled regular expression for matching options with optional values
[590] Fix | Delete
# delimited using typical separators
[591] Fix | Delete
OPTCRE_NV = re.compile(_OPT_NV_TMPL.format(delim="=|:"), re.VERBOSE)
[592] Fix | Delete
# Compiled regular expression for matching leading whitespace in a line
[593] Fix | Delete
NONSPACECRE = re.compile(r"\S")
[594] Fix | Delete
# Possible boolean values in the configuration.
[595] Fix | Delete
BOOLEAN_STATES = {'1': True, 'yes': True, 'true': True, 'on': True,
[596] Fix | Delete
'0': False, 'no': False, 'false': False, 'off': False}
[597] Fix | Delete
[598] Fix | Delete
def __init__(self, defaults=None, dict_type=_default_dict,
[599] Fix | Delete
allow_no_value=False, *, delimiters=('=', ':'),
[600] Fix | Delete
comment_prefixes=('#', ';'), inline_comment_prefixes=None,
[601] Fix | Delete
strict=True, empty_lines_in_values=True,
[602] Fix | Delete
default_section=DEFAULTSECT,
[603] Fix | Delete
interpolation=_UNSET, converters=_UNSET):
[604] Fix | Delete
[605] Fix | Delete
self._dict = dict_type
[606] Fix | Delete
self._sections = self._dict()
[607] Fix | Delete
self._defaults = self._dict()
[608] Fix | Delete
self._converters = ConverterMapping(self)
[609] Fix | Delete
self._proxies = self._dict()
[610] Fix | Delete
self._proxies[default_section] = SectionProxy(self, default_section)
[611] Fix | Delete
if defaults:
[612] Fix | Delete
for key, value in defaults.items():
[613] Fix | Delete
self._defaults[self.optionxform(key)] = value
[614] Fix | Delete
self._delimiters = tuple(delimiters)
[615] Fix | Delete
if delimiters == ('=', ':'):
[616] Fix | Delete
self._optcre = self.OPTCRE_NV if allow_no_value else self.OPTCRE
[617] Fix | Delete
else:
[618] Fix | Delete
d = "|".join(re.escape(d) for d in delimiters)
[619] Fix | Delete
if allow_no_value:
[620] Fix | Delete
self._optcre = re.compile(self._OPT_NV_TMPL.format(delim=d),
[621] Fix | Delete
re.VERBOSE)
[622] Fix | Delete
else:
[623] Fix | Delete
self._optcre = re.compile(self._OPT_TMPL.format(delim=d),
[624] Fix | Delete
re.VERBOSE)
[625] Fix | Delete
self._comment_prefixes = tuple(comment_prefixes or ())
[626] Fix | Delete
self._inline_comment_prefixes = tuple(inline_comment_prefixes or ())
[627] Fix | Delete
self._strict = strict
[628] Fix | Delete
self._allow_no_value = allow_no_value
[629] Fix | Delete
self._empty_lines_in_values = empty_lines_in_values
[630] Fix | Delete
self.default_section=default_section
[631] Fix | Delete
self._interpolation = interpolation
[632] Fix | Delete
if self._interpolation is _UNSET:
[633] Fix | Delete
self._interpolation = self._DEFAULT_INTERPOLATION
[634] Fix | Delete
if self._interpolation is None:
[635] Fix | Delete
self._interpolation = Interpolation()
[636] Fix | Delete
if converters is not _UNSET:
[637] Fix | Delete
self._converters.update(converters)
[638] Fix | Delete
[639] Fix | Delete
def defaults(self):
[640] Fix | Delete
return self._defaults
[641] Fix | Delete
[642] Fix | Delete
def sections(self):
[643] Fix | Delete
"""Return a list of section names, excluding [DEFAULT]"""
[644] Fix | Delete
# self._sections will never have [DEFAULT] in it
[645] Fix | Delete
return list(self._sections.keys())
[646] Fix | Delete
[647] Fix | Delete
def add_section(self, section):
[648] Fix | Delete
"""Create a new section in the configuration.
[649] Fix | Delete
[650] Fix | Delete
Raise DuplicateSectionError if a section by the specified name
[651] Fix | Delete
already exists. Raise ValueError if name is DEFAULT.
[652] Fix | Delete
"""
[653] Fix | Delete
if section == self.default_section:
[654] Fix | Delete
raise ValueError('Invalid section name: %r' % section)
[655] Fix | Delete
[656] Fix | Delete
if section in self._sections:
[657] Fix | Delete
raise DuplicateSectionError(section)
[658] Fix | Delete
self._sections[section] = self._dict()
[659] Fix | Delete
self._proxies[section] = SectionProxy(self, section)
[660] Fix | Delete
[661] Fix | Delete
def has_section(self, section):
[662] Fix | Delete
"""Indicate whether the named section is present in the configuration.
[663] Fix | Delete
[664] Fix | Delete
The DEFAULT section is not acknowledged.
[665] Fix | Delete
"""
[666] Fix | Delete
return section in self._sections
[667] Fix | Delete
[668] Fix | Delete
def options(self, section):
[669] Fix | Delete
"""Return a list of option names for the given section name."""
[670] Fix | Delete
try:
[671] Fix | Delete
opts = self._sections[section].copy()
[672] Fix | Delete
except KeyError:
[673] Fix | Delete
raise NoSectionError(section) from None
[674] Fix | Delete
opts.update(self._defaults)
[675] Fix | Delete
return list(opts.keys())
[676] Fix | Delete
[677] Fix | Delete
def read(self, filenames, encoding=None):
[678] Fix | Delete
"""Read and parse a filename or an iterable of filenames.
[679] Fix | Delete
[680] Fix | Delete
Files that cannot be opened are silently ignored; this is
[681] Fix | Delete
designed so that you can specify an iterable of potential
[682] Fix | Delete
configuration file locations (e.g. current directory, user's
[683] Fix | Delete
home directory, systemwide directory), and all existing
[684] Fix | Delete
configuration files in the iterable will be read. A single
[685] Fix | Delete
filename may also be given.
[686] Fix | Delete
[687] Fix | Delete
Return list of successfully read files.
[688] Fix | Delete
"""
[689] Fix | Delete
if isinstance(filenames, (str, os.PathLike)):
[690] Fix | Delete
filenames = [filenames]
[691] Fix | Delete
read_ok = []
[692] Fix | Delete
for filename in filenames:
[693] Fix | Delete
try:
[694] Fix | Delete
with open(filename, encoding=encoding) as fp:
[695] Fix | Delete
self._read(fp, filename)
[696] Fix | Delete
except OSError:
[697] Fix | Delete
continue
[698] Fix | Delete
if isinstance(filename, os.PathLike):
[699] Fix | Delete
filename = os.fspath(filename)
[700] Fix | Delete
read_ok.append(filename)
[701] Fix | Delete
return read_ok
[702] Fix | Delete
[703] Fix | Delete
def read_file(self, f, source=None):
[704] Fix | Delete
"""Like read() but the argument must be a file-like object.
[705] Fix | Delete
[706] Fix | Delete
The `f' argument must be iterable, returning one line at a time.
[707] Fix | Delete
Optional second argument is the `source' specifying the name of the
[708] Fix | Delete
file being read. If not given, it is taken from f.name. If `f' has no
[709] Fix | Delete
`name' attribute, `<???>' is used.
[710] Fix | Delete
"""
[711] Fix | Delete
if source is None:
[712] Fix | Delete
try:
[713] Fix | Delete
source = f.name
[714] Fix | Delete
except AttributeError:
[715] Fix | Delete
source = '<???>'
[716] Fix | Delete
self._read(f, source)
[717] Fix | Delete
[718] Fix | Delete
def read_string(self, string, source='<string>'):
[719] Fix | Delete
"""Read configuration from a given string."""
[720] Fix | Delete
sfile = io.StringIO(string)
[721] Fix | Delete
self.read_file(sfile, source)
[722] Fix | Delete
[723] Fix | Delete
def read_dict(self, dictionary, source='<dict>'):
[724] Fix | Delete
"""Read configuration from a dictionary.
[725] Fix | Delete
[726] Fix | Delete
Keys are section names, values are dictionaries with keys and values
[727] Fix | Delete
that should be present in the section. If the used dictionary type
[728] Fix | Delete
preserves order, sections and their keys will be added in order.
[729] Fix | Delete
[730] Fix | Delete
All types held in the dictionary are converted to strings during
[731] Fix | Delete
reading, including section names, option names and keys.
[732] Fix | Delete
[733] Fix | Delete
Optional second argument is the `source' specifying the name of the
[734] Fix | Delete
dictionary being read.
[735] Fix | Delete
"""
[736] Fix | Delete
elements_added = set()
[737] Fix | Delete
for section, keys in dictionary.items():
[738] Fix | Delete
section = str(section)
[739] Fix | Delete
try:
[740] Fix | Delete
self.add_section(section)
[741] Fix | Delete
except (DuplicateSectionError, ValueError):
[742] Fix | Delete
if self._strict and section in elements_added:
[743] Fix | Delete
raise
[744] Fix | Delete
elements_added.add(section)
[745] Fix | Delete
for key, value in keys.items():
[746] Fix | Delete
key = self.optionxform(str(key))
[747] Fix | Delete
if value is not None:
[748] Fix | Delete
value = str(value)
[749] Fix | Delete
if self._strict and (section, key) in elements_added:
[750] Fix | Delete
raise DuplicateOptionError(section, key, source)
[751] Fix | Delete
elements_added.add((section, key))
[752] Fix | Delete
self.set(section, key, value)
[753] Fix | Delete
[754] Fix | Delete
def readfp(self, fp, filename=None):
[755] Fix | Delete
"""Deprecated, use read_file instead."""
[756] Fix | Delete
warnings.warn(
[757] Fix | Delete
"This method will be removed in future versions. "
[758] Fix | Delete
"Use 'parser.read_file()' instead.",
[759] Fix | Delete
DeprecationWarning, stacklevel=2
[760] Fix | Delete
)
[761] Fix | Delete
self.read_file(fp, source=filename)
[762] Fix | Delete
[763] Fix | Delete
def get(self, section, option, *, raw=False, vars=None, fallback=_UNSET):
[764] Fix | Delete
"""Get an option value for a given section.
[765] Fix | Delete
[766] Fix | Delete
If `vars' is provided, it must be a dictionary. The option is looked up
[767] Fix | Delete
in `vars' (if provided), `section', and in `DEFAULTSECT' in that order.
[768] Fix | Delete
If the key is not found and `fallback' is provided, it is used as
[769] Fix | Delete
a fallback value. `None' can be provided as a `fallback' value.
[770] Fix | Delete
[771] Fix | Delete
If interpolation is enabled and the optional argument `raw' is False,
[772] Fix | Delete
all interpolations are expanded in the return values.
[773] Fix | Delete
[774] Fix | Delete
Arguments `raw', `vars', and `fallback' are keyword only.
[775] Fix | Delete
[776] Fix | Delete
The section DEFAULT is special.
[777] Fix | Delete
"""
[778] Fix | Delete
try:
[779] Fix | Delete
d = self._unify_values(section, vars)
[780] Fix | Delete
except NoSectionError:
[781] Fix | Delete
if fallback is _UNSET:
[782] Fix | Delete
raise
[783] Fix | Delete
else:
[784] Fix | Delete
return fallback
[785] Fix | Delete
option = self.optionxform(option)
[786] Fix | Delete
try:
[787] Fix | Delete
value = d[option]
[788] Fix | Delete
except KeyError:
[789] Fix | Delete
if fallback is _UNSET:
[790] Fix | Delete
raise NoOptionError(option, section)
[791] Fix | Delete
else:
[792] Fix | Delete
return fallback
[793] Fix | Delete
[794] Fix | Delete
if raw or value is None:
[795] Fix | Delete
return value
[796] Fix | Delete
else:
[797] Fix | Delete
return self._interpolation.before_get(self, section, option, value,
[798] Fix | Delete
d)
[799] Fix | Delete
[800] Fix | Delete
def _get(self, section, conv, option, **kwargs):
[801] Fix | Delete
return conv(self.get(section, option, **kwargs))
[802] Fix | Delete
[803] Fix | Delete
def _get_conv(self, section, option, conv, *, raw=False, vars=None,
[804] Fix | Delete
fallback=_UNSET, **kwargs):
[805] Fix | Delete
try:
[806] Fix | Delete
return self._get(section, conv, option, raw=raw, vars=vars,
[807] Fix | Delete
**kwargs)
[808] Fix | Delete
except (NoSectionError, NoOptionError):
[809] Fix | Delete
if fallback is _UNSET:
[810] Fix | Delete
raise
[811] Fix | Delete
return fallback
[812] Fix | Delete
[813] Fix | Delete
# getint, getfloat and getboolean provided directly for backwards compat
[814] Fix | Delete
def getint(self, section, option, *, raw=False, vars=None,
[815] Fix | Delete
fallback=_UNSET, **kwargs):
[816] Fix | Delete
return self._get_conv(section, option, int, raw=raw, vars=vars,
[817] Fix | Delete
fallback=fallback, **kwargs)
[818] Fix | Delete
[819] Fix | Delete
def getfloat(self, section, option, *, raw=False, vars=None,
[820] Fix | Delete
fallback=_UNSET, **kwargs):
[821] Fix | Delete
return self._get_conv(section, option, float, raw=raw, vars=vars,
[822] Fix | Delete
fallback=fallback, **kwargs)
[823] Fix | Delete
[824] Fix | Delete
def getboolean(self, section, option, *, raw=False, vars=None,
[825] Fix | Delete
fallback=_UNSET, **kwargs):
[826] Fix | Delete
return self._get_conv(section, option, self._convert_to_boolean,
[827] Fix | Delete
raw=raw, vars=vars, fallback=fallback, **kwargs)
[828] Fix | Delete
[829] Fix | Delete
def items(self, section=_UNSET, raw=False, vars=None):
[830] Fix | Delete
"""Return a list of (name, value) tuples for each option in a section.
[831] Fix | Delete
[832] Fix | Delete
All % interpolations are expanded in the return values, based on the
[833] Fix | Delete
defaults passed into the constructor, unless the optional argument
[834] Fix | Delete
`raw' is true. Additional substitutions may be provided using the
[835] Fix | Delete
`vars' argument, which must be a dictionary whose contents overrides
[836] Fix | Delete
any pre-existing defaults.
[837] Fix | Delete
[838] Fix | Delete
The section DEFAULT is special.
[839] Fix | Delete
"""
[840] Fix | Delete
if section is _UNSET:
[841] Fix | Delete
return super().items()
[842] Fix | Delete
d = self._defaults.copy()
[843] Fix | Delete
try:
[844] Fix | Delete
d.update(self._sections[section])
[845] Fix | Delete
except KeyError:
[846] Fix | Delete
if section != self.default_section:
[847] Fix | Delete
raise NoSectionError(section)
[848] Fix | Delete
# Update with the entry specific variables
[849] Fix | Delete
if vars:
[850] Fix | Delete
for key, value in vars.items():
[851] Fix | Delete
d[self.optionxform(key)] = value
[852] Fix | Delete
value_getter = lambda option: self._interpolation.before_get(self,
[853] Fix | Delete
section, option, d[option], d)
[854] Fix | Delete
if raw:
[855] Fix | Delete
value_getter = lambda option: d[option]
[856] Fix | Delete
return [(option, value_getter(option)) for option in d.keys()]
[857] Fix | Delete
[858] Fix | Delete
def popitem(self):
[859] Fix | Delete
"""Remove a section from the parser and return it as
[860] Fix | Delete
a (section_name, section_proxy) tuple. If no section is present, raise
[861] Fix | Delete
KeyError.
[862] Fix | Delete
[863] Fix | Delete
The section DEFAULT is never returned because it cannot be removed.
[864] Fix | Delete
"""
[865] Fix | Delete
for key in self.sections():
[866] Fix | Delete
value = self[key]
[867] Fix | Delete
del self[key]
[868] Fix | Delete
return key, value
[869] Fix | Delete
raise KeyError
[870] Fix | Delete
[871] Fix | Delete
def optionxform(self, optionstr):
[872] Fix | Delete
return optionstr.lower()
[873] Fix | Delete
[874] Fix | Delete
def has_option(self, section, option):
[875] Fix | Delete
"""Check for the existence of a given option in a given section.
[876] Fix | Delete
If the specified `section' is None or an empty string, DEFAULT is
[877] Fix | Delete
assumed. If the specified `section' does not exist, returns False."""
[878] Fix | Delete
if not section or section == self.default_section:
[879] Fix | Delete
option = self.optionxform(option)
[880] Fix | Delete
return option in self._defaults
[881] Fix | Delete
elif section not in self._sections:
[882] Fix | Delete
return False
[883] Fix | Delete
else:
[884] Fix | Delete
option = self.optionxform(option)
[885] Fix | Delete
return (option in self._sections[section]
[886] Fix | Delete
or option in self._defaults)
[887] Fix | Delete
[888] Fix | Delete
def set(self, section, option, value=None):
[889] Fix | Delete
"""Set an option."""
[890] Fix | Delete
if value:
[891] Fix | Delete
value = self._interpolation.before_set(self, section, option,
[892] Fix | Delete
value)
[893] Fix | Delete
if not section or section == self.default_section:
[894] Fix | Delete
sectdict = self._defaults
[895] Fix | Delete
else:
[896] Fix | Delete
try:
[897] Fix | Delete
sectdict = self._sections[section]
[898] Fix | Delete
except KeyError:
[899] Fix | Delete
raise NoSectionError(section) from None
[900] Fix | Delete
sectdict[self.optionxform(option)] = value
[901] Fix | Delete
[902] Fix | Delete
def write(self, fp, space_around_delimiters=True):
[903] Fix | Delete
"""Write an .ini-format representation of the configuration state.
[904] Fix | Delete
[905] Fix | Delete
If `space_around_delimiters' is True (the default), delimiters
[906] Fix | Delete
between keys and values are surrounded by spaces.
[907] Fix | Delete
"""
[908] Fix | Delete
if space_around_delimiters:
[909] Fix | Delete
d = " {} ".format(self._delimiters[0])
[910] Fix | Delete
else:
[911] Fix | Delete
d = self._delimiters[0]
[912] Fix | Delete
if self._defaults:
[913] Fix | Delete
self._write_section(fp, self.default_section,
[914] Fix | Delete
self._defaults.items(), d)
[915] Fix | Delete
for section in self._sections:
[916] Fix | Delete
self._write_section(fp, section,
[917] Fix | Delete
self._sections[section].items(), d)
[918] Fix | Delete
[919] Fix | Delete
def _write_section(self, fp, section_name, section_items, delimiter):
[920] Fix | Delete
"""Write a single section to the specified `fp'."""
[921] Fix | Delete
fp.write("[{}]\n".format(section_name))
[922] Fix | Delete
for key, value in section_items:
[923] Fix | Delete
value = self._interpolation.before_write(self, section_name, key,
[924] Fix | Delete
value)
[925] Fix | Delete
if value is not None or not self._allow_no_value:
[926] Fix | Delete
value = delimiter + str(value).replace('\n', '\n\t')
[927] Fix | Delete
else:
[928] Fix | Delete
value = ""
[929] Fix | Delete
fp.write("{}{}\n".format(key, value))
[930] Fix | Delete
fp.write("\n")
[931] Fix | Delete
[932] Fix | Delete
def remove_option(self, section, option):
[933] Fix | Delete
"""Remove an option."""
[934] Fix | Delete
if not section or section == self.default_section:
[935] Fix | Delete
sectdict = self._defaults
[936] Fix | Delete
else:
[937] Fix | Delete
try:
[938] Fix | Delete
sectdict = self._sections[section]
[939] Fix | Delete
except KeyError:
[940] Fix | Delete
raise NoSectionError(section) from None
[941] Fix | Delete
option = self.optionxform(option)
[942] Fix | Delete
existed = option in sectdict
[943] Fix | Delete
if existed:
[944] Fix | Delete
del sectdict[option]
[945] Fix | Delete
return existed
[946] Fix | Delete
[947] Fix | Delete
def remove_section(self, section):
[948] Fix | Delete
"""Remove a file section."""
[949] Fix | Delete
existed = section in self._sections
[950] Fix | Delete
if existed:
[951] Fix | Delete
del self._sections[section]
[952] Fix | Delete
del self._proxies[section]
[953] Fix | Delete
return existed
[954] Fix | Delete
[955] Fix | Delete
def __getitem__(self, key):
[956] Fix | Delete
if key != self.default_section and not self.has_section(key):
[957] Fix | Delete
raise KeyError(key)
[958] Fix | Delete
return self._proxies[key]
[959] Fix | Delete
[960] Fix | Delete
def __setitem__(self, key, value):
[961] Fix | Delete
# To conform with the mapping protocol, overwrites existing values in
[962] Fix | Delete
# the section.
[963] Fix | Delete
[964] Fix | Delete
# XXX this is not atomic if read_dict fails at any point. Then again,
[965] Fix | Delete
# no update method in configparser is atomic in this implementation.
[966] Fix | Delete
if key == self.default_section:
[967] Fix | Delete
self._defaults.clear()
[968] Fix | Delete
elif key in self._sections:
[969] Fix | Delete
self._sections[key].clear()
[970] Fix | Delete
self.read_dict({key: value})
[971] Fix | Delete
[972] Fix | Delete
def __delitem__(self, key):
[973] Fix | Delete
if key == self.default_section:
[974] Fix | Delete
raise ValueError("Cannot remove the default section.")
[975] Fix | Delete
if not self.has_section(key):
[976] Fix | Delete
raise KeyError(key)
[977] Fix | Delete
self.remove_section(key)
[978] Fix | Delete
[979] Fix | Delete
def __contains__(self, key):
[980] Fix | Delete
return key == self.default_section or self.has_section(key)
[981] Fix | Delete
[982] Fix | Delete
def __len__(self):
[983] Fix | Delete
return len(self._sections) + 1 # the default section
[984] Fix | Delete
[985] Fix | Delete
def __iter__(self):
[986] Fix | Delete
# XXX does it break when underlying container state changed?
[987] Fix | Delete
return itertools.chain((self.default_section,), self._sections.keys())
[988] Fix | Delete
[989] Fix | Delete
def _read(self, fp, fpname):
[990] Fix | Delete
"""Parse a sectioned configuration file.
[991] Fix | Delete
[992] Fix | Delete
Each section in a configuration file contains a header, indicated by
[993] Fix | Delete
a name in square brackets (`[]'), plus key/value options, indicated by
[994] Fix | Delete
`name' and `value' delimited with a specific substring (`=' or `:' by
[995] Fix | Delete
default).
[996] Fix | Delete
[997] Fix | Delete
Values can span multiple lines, as long as they are indented deeper
[998] Fix | Delete
than the first line of the value. Depending on the parser's mode, blank
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function