summaryrefslogtreecommitdiffstats
path: root/Lib/configparser.py
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-02-21 19:38:53 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-02-21 19:38:53 (GMT)
commite66036063bc2adc5297a6148b19781fa2f1b7db9 (patch)
treef199ec634fdf8b3d0dc6007c04526a12b99dd242 /Lib/configparser.py
parentbf709fe08c04e279d77af83f7d9f577087fe86d9 (diff)
downloadcpython-e66036063bc2adc5297a6148b19781fa2f1b7db9.zip
cpython-e66036063bc2adc5297a6148b19781fa2f1b7db9.tar.gz
cpython-e66036063bc2adc5297a6148b19781fa2f1b7db9.tar.bz2
Issue #11089: Fix performance issue limiting the use of ConfigParser()
with large config files.
Diffstat (limited to 'Lib/configparser.py')
-rw-r--r--Lib/configparser.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/Lib/configparser.py b/Lib/configparser.py
index f1866eb..1bfdac8 100644
--- a/Lib/configparser.py
+++ b/Lib/configparser.py
@@ -119,7 +119,7 @@ ConfigParser -- responsible for parsing a list of
between keys and values are surrounded by spaces.
"""
-from collections import MutableMapping, OrderedDict as _default_dict
+from collections import MutableMapping, OrderedDict as _default_dict, _ChainMap
import functools
import io
import itertools
@@ -1099,23 +1099,24 @@ class RawConfigParser(MutableMapping):
return exc
def _unify_values(self, section, vars):
- """Create a copy of the DEFAULTSECT with values from a specific
- `section' and the `vars' dictionary. If provided, values in `vars'
- take precendence.
+ """Create a sequence of lookups with 'vars' taking priority over
+ the 'section' which takes priority over the DEFAULTSECT.
+
"""
- d = self._defaults.copy()
+ sectiondict = {}
try:
- d.update(self._sections[section])
+ sectiondict = self._sections[section]
except KeyError:
if section != self.default_section:
raise NoSectionError(section)
# Update with the entry specific variables
+ vardict = {}
if vars:
for key, value in vars.items():
if value is not None:
value = str(value)
- d[self.optionxform(key)] = value
- return d
+ vardict[self.optionxform(key)] = value
+ return _ChainMap(vardict, sectiondict, self._defaults)
def _convert_to_boolean(self, value):
"""Return a boolean value translating from other types if necessary.