diff options
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r-- | Lib/configparser.py | 23 |
1 files changed, 16 insertions, 7 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py index 06d594a..66ba60d 100644 --- a/Lib/configparser.py +++ b/Lib/configparser.py @@ -118,7 +118,8 @@ ConfigParser -- responsible for parsing a list of between keys and values are surrounded by spaces. """ -from collections import MutableMapping, OrderedDict as _default_dict, _ChainMap +from collections.abc import MutableMapping +from collections import OrderedDict as _default_dict, ChainMap as _ChainMap import functools import io import itertools @@ -991,18 +992,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: |