Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../lib64/python2....
File: ConfigParser.py
"""Configuration file parser.
[0] Fix | Delete
[1] Fix | Delete
A setup 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
The option values can contain format strings which refer to other values in
[6] Fix | Delete
the same section, or values in a special [DEFAULT] section.
[7] Fix | Delete
[8] Fix | Delete
For example:
[9] Fix | Delete
[10] Fix | Delete
something: %(dir)s/whatever
[11] Fix | Delete
[12] Fix | Delete
would resolve the "%(dir)s" to the value of dir. All reference
[13] Fix | Delete
expansions are done late, on demand.
[14] Fix | Delete
[15] Fix | Delete
Intrinsic defaults can be specified by passing them into the
[16] Fix | Delete
ConfigParser constructor as a dictionary.
[17] Fix | Delete
[18] Fix | Delete
class:
[19] Fix | Delete
[20] Fix | Delete
ConfigParser -- responsible for parsing a list of
[21] Fix | Delete
configuration files, and managing the parsed database.
[22] Fix | Delete
[23] Fix | Delete
methods:
[24] Fix | Delete
[25] Fix | Delete
__init__(defaults=None)
[26] Fix | Delete
create the parser and specify a dictionary of intrinsic defaults. The
[27] Fix | Delete
keys must be strings, the values must be appropriate for %()s string
[28] Fix | Delete
interpolation. Note that `__name__' is always an intrinsic default;
[29] Fix | Delete
its value is the section's name.
[30] Fix | Delete
[31] Fix | Delete
sections()
[32] Fix | Delete
return all the configuration section names, sans DEFAULT
[33] Fix | Delete
[34] Fix | Delete
has_section(section)
[35] Fix | Delete
return whether the given section exists
[36] Fix | Delete
[37] Fix | Delete
has_option(section, option)
[38] Fix | Delete
return whether the given option exists in the given section
[39] Fix | Delete
[40] Fix | Delete
options(section)
[41] Fix | Delete
return list of configuration options for the named section
[42] Fix | Delete
[43] Fix | Delete
read(filenames)
[44] Fix | Delete
read and parse the list of named configuration files, given by
[45] Fix | Delete
name. A single filename is also allowed. Non-existing files
[46] Fix | Delete
are ignored. Return list of successfully read files.
[47] Fix | Delete
[48] Fix | Delete
readfp(fp, filename=None)
[49] Fix | Delete
read and parse one configuration file, given as a file object.
[50] Fix | Delete
The filename defaults to fp.name; it is only used in error
[51] Fix | Delete
messages (if fp has no `name' attribute, the string `<???>' is used).
[52] Fix | Delete
[53] Fix | Delete
get(section, option, raw=False, vars=None)
[54] Fix | Delete
return a string value for the named option. All % interpolations are
[55] Fix | Delete
expanded in the return values, based on the defaults passed into the
[56] Fix | Delete
constructor and the DEFAULT section. Additional substitutions may be
[57] Fix | Delete
provided using the `vars' argument, which must be a dictionary whose
[58] Fix | Delete
contents override any pre-existing defaults.
[59] Fix | Delete
[60] Fix | Delete
getint(section, options)
[61] Fix | Delete
like get(), but convert value to an integer
[62] Fix | Delete
[63] Fix | Delete
getfloat(section, options)
[64] Fix | Delete
like get(), but convert value to a float
[65] Fix | Delete
[66] Fix | Delete
getboolean(section, options)
[67] Fix | Delete
like get(), but convert value to a boolean (currently case
[68] Fix | Delete
insensitively defined as 0, false, no, off for False, and 1, true,
[69] Fix | Delete
yes, on for True). Returns False or True.
[70] Fix | Delete
[71] Fix | Delete
items(section, raw=False, vars=None)
[72] Fix | Delete
return a list of tuples with (name, value) for each option
[73] Fix | Delete
in the section.
[74] Fix | Delete
[75] Fix | Delete
remove_section(section)
[76] Fix | Delete
remove the given file section and all its options
[77] Fix | Delete
[78] Fix | Delete
remove_option(section, option)
[79] Fix | Delete
remove the given option from the given section
[80] Fix | Delete
[81] Fix | Delete
set(section, option, value)
[82] Fix | Delete
set the given option
[83] Fix | Delete
[84] Fix | Delete
write(fp)
[85] Fix | Delete
write the configuration state in .ini format
[86] Fix | Delete
"""
[87] Fix | Delete
[88] Fix | Delete
try:
[89] Fix | Delete
from collections import OrderedDict as _default_dict
[90] Fix | Delete
except ImportError:
[91] Fix | Delete
# fallback for setup.py which hasn't yet built _collections
[92] Fix | Delete
_default_dict = dict
[93] Fix | Delete
[94] Fix | Delete
import re
[95] Fix | Delete
[96] Fix | Delete
__all__ = ["NoSectionError", "DuplicateSectionError", "NoOptionError",
[97] Fix | Delete
"InterpolationError", "InterpolationDepthError",
[98] Fix | Delete
"InterpolationSyntaxError", "ParsingError",
[99] Fix | Delete
"MissingSectionHeaderError",
[100] Fix | Delete
"ConfigParser", "SafeConfigParser", "RawConfigParser",
[101] Fix | Delete
"DEFAULTSECT", "MAX_INTERPOLATION_DEPTH"]
[102] Fix | Delete
[103] Fix | Delete
DEFAULTSECT = "DEFAULT"
[104] Fix | Delete
[105] Fix | Delete
MAX_INTERPOLATION_DEPTH = 10
[106] Fix | Delete
[107] Fix | Delete
[108] Fix | Delete
[109] Fix | Delete
# exception classes
[110] Fix | Delete
class Error(Exception):
[111] Fix | Delete
"""Base class for ConfigParser exceptions."""
[112] Fix | Delete
[113] Fix | Delete
def _get_message(self):
[114] Fix | Delete
"""Getter for 'message'; needed only to override deprecation in
[115] Fix | Delete
BaseException."""
[116] Fix | Delete
return self.__message
[117] Fix | Delete
[118] Fix | Delete
def _set_message(self, value):
[119] Fix | Delete
"""Setter for 'message'; needed only to override deprecation in
[120] Fix | Delete
BaseException."""
[121] Fix | Delete
self.__message = value
[122] Fix | Delete
[123] Fix | Delete
# BaseException.message has been deprecated since Python 2.6. To prevent
[124] Fix | Delete
# DeprecationWarning from popping up over this pre-existing attribute, use
[125] Fix | Delete
# a new property that takes lookup precedence.
[126] Fix | Delete
message = property(_get_message, _set_message)
[127] Fix | Delete
[128] Fix | Delete
def __init__(self, msg=''):
[129] Fix | Delete
self.message = msg
[130] Fix | Delete
Exception.__init__(self, msg)
[131] Fix | Delete
[132] Fix | Delete
def __repr__(self):
[133] Fix | Delete
return self.message
[134] Fix | Delete
[135] Fix | Delete
__str__ = __repr__
[136] Fix | Delete
[137] Fix | Delete
class NoSectionError(Error):
[138] Fix | Delete
"""Raised when no section matches a requested option."""
[139] Fix | Delete
[140] Fix | Delete
def __init__(self, section):
[141] Fix | Delete
Error.__init__(self, 'No section: %r' % (section,))
[142] Fix | Delete
self.section = section
[143] Fix | Delete
self.args = (section, )
[144] Fix | Delete
[145] Fix | Delete
class DuplicateSectionError(Error):
[146] Fix | Delete
"""Raised when a section is multiply-created."""
[147] Fix | Delete
[148] Fix | Delete
def __init__(self, section):
[149] Fix | Delete
Error.__init__(self, "Section %r already exists" % section)
[150] Fix | Delete
self.section = section
[151] Fix | Delete
self.args = (section, )
[152] Fix | Delete
[153] Fix | Delete
class NoOptionError(Error):
[154] Fix | Delete
"""A requested option was not found."""
[155] Fix | Delete
[156] Fix | Delete
def __init__(self, option, section):
[157] Fix | Delete
Error.__init__(self, "No option %r in section: %r" %
[158] Fix | Delete
(option, section))
[159] Fix | Delete
self.option = option
[160] Fix | Delete
self.section = section
[161] Fix | Delete
self.args = (option, section)
[162] Fix | Delete
[163] Fix | Delete
class InterpolationError(Error):
[164] Fix | Delete
"""Base class for interpolation-related exceptions."""
[165] Fix | Delete
[166] Fix | Delete
def __init__(self, option, section, msg):
[167] Fix | Delete
Error.__init__(self, msg)
[168] Fix | Delete
self.option = option
[169] Fix | Delete
self.section = section
[170] Fix | Delete
self.args = (option, section, msg)
[171] Fix | Delete
[172] Fix | Delete
class InterpolationMissingOptionError(InterpolationError):
[173] Fix | Delete
"""A string substitution required a setting which was not available."""
[174] Fix | Delete
[175] Fix | Delete
def __init__(self, option, section, rawval, reference):
[176] Fix | Delete
msg = ("Bad value substitution:\n"
[177] Fix | Delete
"\tsection: [%s]\n"
[178] Fix | Delete
"\toption : %s\n"
[179] Fix | Delete
"\tkey : %s\n"
[180] Fix | Delete
"\trawval : %s\n"
[181] Fix | Delete
% (section, option, reference, rawval))
[182] Fix | Delete
InterpolationError.__init__(self, option, section, msg)
[183] Fix | Delete
self.reference = reference
[184] Fix | Delete
self.args = (option, section, rawval, reference)
[185] Fix | Delete
[186] Fix | Delete
class InterpolationSyntaxError(InterpolationError):
[187] Fix | Delete
"""Raised when the source text into which substitutions are made
[188] Fix | Delete
does not conform to the required syntax."""
[189] Fix | Delete
[190] Fix | Delete
class InterpolationDepthError(InterpolationError):
[191] Fix | Delete
"""Raised when substitutions are nested too deeply."""
[192] Fix | Delete
[193] Fix | Delete
def __init__(self, option, section, rawval):
[194] Fix | Delete
msg = ("Value interpolation too deeply recursive:\n"
[195] Fix | Delete
"\tsection: [%s]\n"
[196] Fix | Delete
"\toption : %s\n"
[197] Fix | Delete
"\trawval : %s\n"
[198] Fix | Delete
% (section, option, rawval))
[199] Fix | Delete
InterpolationError.__init__(self, option, section, msg)
[200] Fix | Delete
self.args = (option, section, rawval)
[201] Fix | Delete
[202] Fix | Delete
class ParsingError(Error):
[203] Fix | Delete
"""Raised when a configuration file does not follow legal syntax."""
[204] Fix | Delete
[205] Fix | Delete
def __init__(self, filename):
[206] Fix | Delete
Error.__init__(self, 'File contains parsing errors: %s' % filename)
[207] Fix | Delete
self.filename = filename
[208] Fix | Delete
self.errors = []
[209] Fix | Delete
self.args = (filename, )
[210] Fix | Delete
[211] Fix | Delete
def append(self, lineno, line):
[212] Fix | Delete
self.errors.append((lineno, line))
[213] Fix | Delete
self.message += '\n\t[line %2d]: %s' % (lineno, line)
[214] Fix | Delete
[215] Fix | Delete
class MissingSectionHeaderError(ParsingError):
[216] Fix | Delete
"""Raised when a key-value pair is found before any section header."""
[217] Fix | Delete
[218] Fix | Delete
def __init__(self, filename, lineno, line):
[219] Fix | Delete
Error.__init__(
[220] Fix | Delete
self,
[221] Fix | Delete
'File contains no section headers.\nfile: %s, line: %d\n%r' %
[222] Fix | Delete
(filename, lineno, line))
[223] Fix | Delete
self.filename = filename
[224] Fix | Delete
self.lineno = lineno
[225] Fix | Delete
self.line = line
[226] Fix | Delete
self.args = (filename, lineno, line)
[227] Fix | Delete
[228] Fix | Delete
[229] Fix | Delete
class RawConfigParser:
[230] Fix | Delete
def __init__(self, defaults=None, dict_type=_default_dict,
[231] Fix | Delete
allow_no_value=False):
[232] Fix | Delete
self._dict = dict_type
[233] Fix | Delete
self._sections = self._dict()
[234] Fix | Delete
self._defaults = self._dict()
[235] Fix | Delete
if allow_no_value:
[236] Fix | Delete
self._optcre = self.OPTCRE_NV
[237] Fix | Delete
else:
[238] Fix | Delete
self._optcre = self.OPTCRE
[239] Fix | Delete
if defaults:
[240] Fix | Delete
for key, value in defaults.items():
[241] Fix | Delete
self._defaults[self.optionxform(key)] = value
[242] Fix | Delete
[243] Fix | Delete
def defaults(self):
[244] Fix | Delete
return self._defaults
[245] Fix | Delete
[246] Fix | Delete
def sections(self):
[247] Fix | Delete
"""Return a list of section names, excluding [DEFAULT]"""
[248] Fix | Delete
# self._sections will never have [DEFAULT] in it
[249] Fix | Delete
return self._sections.keys()
[250] Fix | Delete
[251] Fix | Delete
def add_section(self, section):
[252] Fix | Delete
"""Create a new section in the configuration.
[253] Fix | Delete
[254] Fix | Delete
Raise DuplicateSectionError if a section by the specified name
[255] Fix | Delete
already exists. Raise ValueError if name is DEFAULT or any of it's
[256] Fix | Delete
case-insensitive variants.
[257] Fix | Delete
"""
[258] Fix | Delete
if section.lower() == "default":
[259] Fix | Delete
raise ValueError, 'Invalid section name: %s' % section
[260] Fix | Delete
[261] Fix | Delete
if section in self._sections:
[262] Fix | Delete
raise DuplicateSectionError(section)
[263] Fix | Delete
self._sections[section] = self._dict()
[264] Fix | Delete
[265] Fix | Delete
def has_section(self, section):
[266] Fix | Delete
"""Indicate whether the named section is present in the configuration.
[267] Fix | Delete
[268] Fix | Delete
The DEFAULT section is not acknowledged.
[269] Fix | Delete
"""
[270] Fix | Delete
return section in self._sections
[271] Fix | Delete
[272] Fix | Delete
def options(self, section):
[273] Fix | Delete
"""Return a list of option names for the given section name."""
[274] Fix | Delete
try:
[275] Fix | Delete
opts = self._sections[section].copy()
[276] Fix | Delete
except KeyError:
[277] Fix | Delete
raise NoSectionError(section)
[278] Fix | Delete
opts.update(self._defaults)
[279] Fix | Delete
if '__name__' in opts:
[280] Fix | Delete
del opts['__name__']
[281] Fix | Delete
return opts.keys()
[282] Fix | Delete
[283] Fix | Delete
def read(self, filenames):
[284] Fix | Delete
"""Read and parse a filename or a list of filenames.
[285] Fix | Delete
[286] Fix | Delete
Files that cannot be opened are silently ignored; this is
[287] Fix | Delete
designed so that you can specify a list of potential
[288] Fix | Delete
configuration file locations (e.g. current directory, user's
[289] Fix | Delete
home directory, systemwide directory), and all existing
[290] Fix | Delete
configuration files in the list will be read. A single
[291] Fix | Delete
filename may also be given.
[292] Fix | Delete
[293] Fix | Delete
Return list of successfully read files.
[294] Fix | Delete
"""
[295] Fix | Delete
if isinstance(filenames, basestring):
[296] Fix | Delete
filenames = [filenames]
[297] Fix | Delete
read_ok = []
[298] Fix | Delete
for filename in filenames:
[299] Fix | Delete
try:
[300] Fix | Delete
fp = open(filename)
[301] Fix | Delete
except IOError:
[302] Fix | Delete
continue
[303] Fix | Delete
self._read(fp, filename)
[304] Fix | Delete
fp.close()
[305] Fix | Delete
read_ok.append(filename)
[306] Fix | Delete
return read_ok
[307] Fix | Delete
[308] Fix | Delete
def readfp(self, fp, filename=None):
[309] Fix | Delete
"""Like read() but the argument must be a file-like object.
[310] Fix | Delete
[311] Fix | Delete
The `fp' argument must have a `readline' method. Optional
[312] Fix | Delete
second argument is the `filename', which if not given, is
[313] Fix | Delete
taken from fp.name. If fp has no `name' attribute, `<???>' is
[314] Fix | Delete
used.
[315] Fix | Delete
[316] Fix | Delete
"""
[317] Fix | Delete
if filename is None:
[318] Fix | Delete
try:
[319] Fix | Delete
filename = fp.name
[320] Fix | Delete
except AttributeError:
[321] Fix | Delete
filename = '<???>'
[322] Fix | Delete
self._read(fp, filename)
[323] Fix | Delete
[324] Fix | Delete
def get(self, section, option):
[325] Fix | Delete
opt = self.optionxform(option)
[326] Fix | Delete
if section not in self._sections:
[327] Fix | Delete
if section != DEFAULTSECT:
[328] Fix | Delete
raise NoSectionError(section)
[329] Fix | Delete
if opt in self._defaults:
[330] Fix | Delete
return self._defaults[opt]
[331] Fix | Delete
else:
[332] Fix | Delete
raise NoOptionError(option, section)
[333] Fix | Delete
elif opt in self._sections[section]:
[334] Fix | Delete
return self._sections[section][opt]
[335] Fix | Delete
elif opt in self._defaults:
[336] Fix | Delete
return self._defaults[opt]
[337] Fix | Delete
else:
[338] Fix | Delete
raise NoOptionError(option, section)
[339] Fix | Delete
[340] Fix | Delete
def items(self, section):
[341] Fix | Delete
try:
[342] Fix | Delete
d2 = self._sections[section]
[343] Fix | Delete
except KeyError:
[344] Fix | Delete
if section != DEFAULTSECT:
[345] Fix | Delete
raise NoSectionError(section)
[346] Fix | Delete
d2 = self._dict()
[347] Fix | Delete
d = self._defaults.copy()
[348] Fix | Delete
d.update(d2)
[349] Fix | Delete
if "__name__" in d:
[350] Fix | Delete
del d["__name__"]
[351] Fix | Delete
return d.items()
[352] Fix | Delete
[353] Fix | Delete
def _get(self, section, conv, option):
[354] Fix | Delete
return conv(self.get(section, option))
[355] Fix | Delete
[356] Fix | Delete
def getint(self, section, option):
[357] Fix | Delete
return self._get(section, int, option)
[358] Fix | Delete
[359] Fix | Delete
def getfloat(self, section, option):
[360] Fix | Delete
return self._get(section, float, option)
[361] Fix | Delete
[362] Fix | Delete
_boolean_states = {'1': True, 'yes': True, 'true': True, 'on': True,
[363] Fix | Delete
'0': False, 'no': False, 'false': False, 'off': False}
[364] Fix | Delete
[365] Fix | Delete
def getboolean(self, section, option):
[366] Fix | Delete
v = self.get(section, option)
[367] Fix | Delete
if v.lower() not in self._boolean_states:
[368] Fix | Delete
raise ValueError, 'Not a boolean: %s' % v
[369] Fix | Delete
return self._boolean_states[v.lower()]
[370] Fix | Delete
[371] Fix | Delete
def optionxform(self, optionstr):
[372] Fix | Delete
return optionstr.lower()
[373] Fix | Delete
[374] Fix | Delete
def has_option(self, section, option):
[375] Fix | Delete
"""Check for the existence of a given option in a given section."""
[376] Fix | Delete
if not section or section == DEFAULTSECT:
[377] Fix | Delete
option = self.optionxform(option)
[378] Fix | Delete
return option in self._defaults
[379] Fix | Delete
elif section not in self._sections:
[380] Fix | Delete
return False
[381] Fix | Delete
else:
[382] Fix | Delete
option = self.optionxform(option)
[383] Fix | Delete
return (option in self._sections[section]
[384] Fix | Delete
or option in self._defaults)
[385] Fix | Delete
[386] Fix | Delete
def set(self, section, option, value=None):
[387] Fix | Delete
"""Set an option."""
[388] Fix | Delete
if not section or section == DEFAULTSECT:
[389] Fix | Delete
sectdict = self._defaults
[390] Fix | Delete
else:
[391] Fix | Delete
try:
[392] Fix | Delete
sectdict = self._sections[section]
[393] Fix | Delete
except KeyError:
[394] Fix | Delete
raise NoSectionError(section)
[395] Fix | Delete
sectdict[self.optionxform(option)] = value
[396] Fix | Delete
[397] Fix | Delete
def write(self, fp):
[398] Fix | Delete
"""Write an .ini-format representation of the configuration state."""
[399] Fix | Delete
if self._defaults:
[400] Fix | Delete
fp.write("[%s]\n" % DEFAULTSECT)
[401] Fix | Delete
for (key, value) in self._defaults.items():
[402] Fix | Delete
fp.write("%s = %s\n" % (key, str(value).replace('\n', '\n\t')))
[403] Fix | Delete
fp.write("\n")
[404] Fix | Delete
for section in self._sections:
[405] Fix | Delete
fp.write("[%s]\n" % section)
[406] Fix | Delete
for (key, value) in self._sections[section].items():
[407] Fix | Delete
if key == "__name__":
[408] Fix | Delete
continue
[409] Fix | Delete
if (value is not None) or (self._optcre == self.OPTCRE):
[410] Fix | Delete
key = " = ".join((key, str(value).replace('\n', '\n\t')))
[411] Fix | Delete
fp.write("%s\n" % (key))
[412] Fix | Delete
fp.write("\n")
[413] Fix | Delete
[414] Fix | Delete
def remove_option(self, section, option):
[415] Fix | Delete
"""Remove an option."""
[416] Fix | Delete
if not section or section == DEFAULTSECT:
[417] Fix | Delete
sectdict = self._defaults
[418] Fix | Delete
else:
[419] Fix | Delete
try:
[420] Fix | Delete
sectdict = self._sections[section]
[421] Fix | Delete
except KeyError:
[422] Fix | Delete
raise NoSectionError(section)
[423] Fix | Delete
option = self.optionxform(option)
[424] Fix | Delete
existed = option in sectdict
[425] Fix | Delete
if existed:
[426] Fix | Delete
del sectdict[option]
[427] Fix | Delete
return existed
[428] Fix | Delete
[429] Fix | Delete
def remove_section(self, section):
[430] Fix | Delete
"""Remove a file section."""
[431] Fix | Delete
existed = section in self._sections
[432] Fix | Delete
if existed:
[433] Fix | Delete
del self._sections[section]
[434] Fix | Delete
return existed
[435] Fix | Delete
[436] Fix | Delete
#
[437] Fix | Delete
# Regular expressions for parsing section headers and options.
[438] Fix | Delete
#
[439] Fix | Delete
SECTCRE = re.compile(
[440] Fix | Delete
r'\[' # [
[441] Fix | Delete
r'(?P<header>[^]]+)' # very permissive!
[442] Fix | Delete
r'\]' # ]
[443] Fix | Delete
)
[444] Fix | Delete
OPTCRE = re.compile(
[445] Fix | Delete
r'(?P<option>[^:=\s][^:=]*)' # very permissive!
[446] Fix | Delete
r'\s*(?P<vi>[:=])\s*' # any number of space/tab,
[447] Fix | Delete
# followed by separator
[448] Fix | Delete
# (either : or =), followed
[449] Fix | Delete
# by any # space/tab
[450] Fix | Delete
r'(?P<value>.*)$' # everything up to eol
[451] Fix | Delete
)
[452] Fix | Delete
OPTCRE_NV = re.compile(
[453] Fix | Delete
r'(?P<option>[^:=\s][^:=]*)' # very permissive!
[454] Fix | Delete
r'\s*(?:' # any number of space/tab,
[455] Fix | Delete
r'(?P<vi>[:=])\s*' # optionally followed by
[456] Fix | Delete
# separator (either : or
[457] Fix | Delete
# =), followed by any #
[458] Fix | Delete
# space/tab
[459] Fix | Delete
r'(?P<value>.*))?$' # everything up to eol
[460] Fix | Delete
)
[461] Fix | Delete
[462] Fix | Delete
def _read(self, fp, fpname):
[463] Fix | Delete
"""Parse a sectioned setup file.
[464] Fix | Delete
[465] Fix | Delete
The sections in setup file contains a title line at the top,
[466] Fix | Delete
indicated by a name in square brackets (`[]'), plus key/value
[467] Fix | Delete
options lines, indicated by `name: value' format lines.
[468] Fix | Delete
Continuations are represented by an embedded newline then
[469] Fix | Delete
leading whitespace. Blank lines, lines beginning with a '#',
[470] Fix | Delete
and just about everything else are ignored.
[471] Fix | Delete
"""
[472] Fix | Delete
cursect = None # None, or a dictionary
[473] Fix | Delete
optname = None
[474] Fix | Delete
lineno = 0
[475] Fix | Delete
e = None # None, or an exception
[476] Fix | Delete
while True:
[477] Fix | Delete
line = fp.readline()
[478] Fix | Delete
if not line:
[479] Fix | Delete
break
[480] Fix | Delete
lineno = lineno + 1
[481] Fix | Delete
# comment or blank line?
[482] Fix | Delete
if line.strip() == '' or line[0] in '#;':
[483] Fix | Delete
continue
[484] Fix | Delete
if line.split(None, 1)[0].lower() == 'rem' and line[0] in "rR":
[485] Fix | Delete
# no leading whitespace
[486] Fix | Delete
continue
[487] Fix | Delete
# continuation line?
[488] Fix | Delete
if line[0].isspace() and cursect is not None and optname:
[489] Fix | Delete
value = line.strip()
[490] Fix | Delete
if value:
[491] Fix | Delete
cursect[optname].append(value)
[492] Fix | Delete
# a section header or option header?
[493] Fix | Delete
else:
[494] Fix | Delete
# is it a section header?
[495] Fix | Delete
mo = self.SECTCRE.match(line)
[496] Fix | Delete
if mo:
[497] Fix | Delete
sectname = mo.group('header')
[498] Fix | Delete
if sectname in self._sections:
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function