summaryrefslogtreecommitdiffstats
path: root/Lib/ConfigParser.py
diff options
context:
space:
mode:
authorFred Drake <fdrake@acm.org>2000-02-28 20:59:03 (GMT)
committerFred Drake <fdrake@acm.org>2000-02-28 20:59:03 (GMT)
commitc517b9b40646a2aac735a82a0334fbc4bff04654 (patch)
tree4047c577ebb6319056d57e9a56ac063bb2464378 /Lib/ConfigParser.py
parent048e6103f29d0720d52a64dcecdebdec9eb7c780 (diff)
downloadcpython-c517b9b40646a2aac735a82a0334fbc4bff04654.zip
cpython-c517b9b40646a2aac735a82a0334fbc4bff04654.tar.gz
cpython-c517b9b40646a2aac735a82a0334fbc4bff04654.tar.bz2
(Finally!) Changes related to the ConfigParser/INI-file topics
discussed on c.l.py last January. Specifically: - more characters allowed in section & option names - if '=' is used to separate the option & value, the value can be followed by a comment of the form '\s;'
Diffstat (limited to 'Lib/ConfigParser.py')
-rw-r--r--Lib/ConfigParser.py16
1 files changed, 11 insertions, 5 deletions
diff --git a/Lib/ConfigParser.py b/Lib/ConfigParser.py
index f0611f6..e871cc5 100644
--- a/Lib/ConfigParser.py
+++ b/Lib/ConfigParser.py
@@ -292,12 +292,12 @@ class ConfigParser:
# of \w, _ is allowed in section header names.
SECTCRE = re.compile(
r'\[' # [
- r'(?P<header>[-\w]+)' # `-', `_' or any alphanum
+ r'(?P<header>[-\w_.*,(){}]+)' # `-', `_' or any alphanum
r'\]' # ]
)
OPTCRE = re.compile(
- r'(?P<option>[-.\w]+)' # - . _ alphanum
- r'[ \t]*[:=][ \t]*' # any number of space/tab,
+ r'(?P<option>[-\w_.*,(){}]+)' # - . _ alphanum
+ r'[ \t]*(?P<vi>[:=])[ \t]*' # any number of space/tab,
# followed by separator
# (either : or =), followed
# by any # space/tab
@@ -327,7 +327,7 @@ class ConfigParser:
if string.strip(line) == '' or line[0] in '#;':
continue
if string.lower(string.split(line)[0]) == 'rem' \
- and line[0] == "r": # no leading whitespace
+ and line[0] in "rR": # no leading whitespace
continue
# continuation line?
if line[0] in ' \t' and cursect is not None and optname:
@@ -356,8 +356,14 @@ class ConfigParser:
else:
mo = self.OPTCRE.match(line)
if mo:
- optname, optval = mo.group('option', 'value')
+ optname, vi, optval = mo.group('option', 'vi', 'value')
optname = string.lower(optname)
+ if vi == '=' and ';' in optval:
+ # ';' is a comment delimiter only if it follows
+ # a spacing character
+ pos = string.find(optval, ';')
+ if pos and optval[pos-1] in string.whitespace:
+ optval = optval[:pos]
optval = string.strip(optval)
# allow empty values
if optval == '""':