summaryrefslogtreecommitdiffstats
path: root/Lib/configparser.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2010-07-29 11:56:20 (GMT)
committerGeorg Brandl <georg@python.org>2010-07-29 11:56:20 (GMT)
commitf206d0e3931b64aa3c8219badb9e0fbb81f1eb38 (patch)
tree21841c861a430f4067269363dd453f9bc1b5f3b2 /Lib/configparser.py
parentc62a704189518ecd0c7420c61b41750c7984312a (diff)
downloadcpython-f206d0e3931b64aa3c8219badb9e0fbb81f1eb38.zip
cpython-f206d0e3931b64aa3c8219badb9e0fbb81f1eb38.tar.gz
cpython-f206d0e3931b64aa3c8219badb9e0fbb81f1eb38.tar.bz2
Fix for r83202: improve the handling of empty lines.
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r--Lib/configparser.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py
index d979e6c..8c0546a 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -558,7 +558,7 @@ class RawConfigParser:
indent_level = 0
e = None # None, or an exception
for lineno, line in enumerate(fp, start=1):
- # strip prefix-only comments
+ # strip full line comments
comment_start = None
for prefix in self._startonly_comment_prefixes:
if line.strip().startswith(prefix):
@@ -572,11 +572,14 @@ class RawConfigParser:
break
value = line[:comment_start].strip()
if not value:
- if self._empty_lines_in_values and comment_start is None:
+ if self._empty_lines_in_values:
# add empty line to the value, but only if there was no
# comment on the line
- if cursect is not None and optname:
- cursect[optname].append('\n')
+ if (comment_start is None and
+ cursect is not None and
+ optname and
+ cursect[optname] is not None):
+ cursect[optname].append('') # newlines added at join
else:
# empty line marks end of value
indent_level = sys.maxsize
@@ -643,9 +646,7 @@ class RawConfigParser:
for options in all_sections:
for name, val in options.items():
if isinstance(val, list):
- if val[-1] == '\n':
- val = val[:-1]
- options[name] = '\n'.join(val)
+ options[name] = '\n'.join(val).rstrip()
def _handle_error(self, exc, fpname, lineno, line):
if not exc: