[Python-checkins] CVS: python/dist/src/Lib ConfigParser.py,1.14,1.15
Fred L. Drake
fdrake@weyr.cnri.reston.va.us
Mon, 28 Feb 2000 15:59:06 -0500 (EST)
Update of /projects/cvsroot/python/dist/src/Lib
In directory weyr:/home/fdrake/projects/python/Lib
Modified Files:
ConfigParser.py
Log Message:
(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;'
Index: ConfigParser.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/ConfigParser.py,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -r1.14 -r1.15
*** ConfigParser.py 1999/10/12 16:12:48 1.14
--- ConfigParser.py 2000/02/28 20:59:03 1.15
***************
*** 293,302 ****
SECTCRE = re.compile(
r'\[' # [
! r'(?P<header>[-\w]+)' # `-', `_' or any alphanum
r'\]' # ]
)
OPTCRE = re.compile(
! r'(?P<option>[-.\w]+)' # - . _ alphanum
! r'[ \t]*[:=][ \t]*' # any number of space/tab,
# followed by separator
# (either : or =), followed
--- 293,302 ----
SECTCRE = re.compile(
r'\[' # [
! r'(?P<header>[-\w_.*,(){}]+)' # `-', `_' or any alphanum
r'\]' # ]
)
OPTCRE = re.compile(
! r'(?P<option>[-\w_.*,(){}]+)' # - . _ alphanum
! r'[ \t]*(?P<vi>[:=])[ \t]*' # any number of space/tab,
# followed by separator
# (either : or =), followed
***************
*** 328,332 ****
continue
if string.lower(string.split(line)[0]) == 'rem' \
! and line[0] == "r": # no leading whitespace
continue
# continuation line?
--- 328,332 ----
continue
if string.lower(string.split(line)[0]) == 'rem' \
! and line[0] in "rR": # no leading whitespace
continue
# continuation line?
***************
*** 357,362 ****
mo = self.OPTCRE.match(line)
if mo:
! optname, optval = mo.group('option', 'value')
optname = string.lower(optname)
optval = string.strip(optval)
# allow empty values
--- 357,368 ----
mo = self.OPTCRE.match(line)
if mo:
! 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