diff options
author | Łukasz Langa <lukasz@langa.pl> | 2012-07-07 18:58:44 +0200 |
---|---|---|
committer | Łukasz Langa <lukasz@langa.pl> | 2012-07-07 18:58:44 +0200 |
commit | 31196dd7d0d2a4241d2d2cc9cf7721f91eb9eb8b (patch) | |
tree | 179b26b865cc3aa728c02492d1d1b0c393ebcb67 /Lib/configparser.py | |
parent | 5aa43542974c32b5a2a16acf42204e7a3cfcade9 (diff) | |
parent | cba243215e8d0459e10332d44495761ddb8cfafb (diff) | |
download | cpython-git-31196dd7d0d2a4241d2d2cc9cf7721f91eb9eb8b.tar.gz |
Merge remote
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r-- | Lib/configparser.py | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py index 7bc439839b..9d5f779a12 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -993,18 +993,26 @@ class RawConfigParser(MutableMapping): indent_level = 0 e = None # None, or an exception for lineno, line in enumerate(fp, start=1): - comment_start = None + comment_start = sys.maxsize # strip inline comments - for prefix in self._inline_comment_prefixes: - index = line.find(prefix) - if index == 0 or (index > 0 and line[index-1].isspace()): - comment_start = index - break + inline_prefixes = {p: -1 for p in self._inline_comment_prefixes} + while comment_start == sys.maxsize and inline_prefixes: + next_prefixes = {} + for prefix, index in inline_prefixes.items(): + index = line.find(prefix, index+1) + if index == -1: + continue + next_prefixes[prefix] = index + if index == 0 or (index > 0 and line[index-1].isspace()): + comment_start = min(comment_start, index) + inline_prefixes = next_prefixes # strip full line comments for prefix in self._comment_prefixes: if line.strip().startswith(prefix): comment_start = 0 break + if comment_start == sys.maxsize: + comment_start = None value = line[:comment_start].strip() if not value: if self._empty_lines_in_values: |