summaryrefslogtreecommitdiff
path: root/configobj.py
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2009-09-13 22:57:43 +0000
committerfuzzyman <devnull@localhost>2009-09-13 22:57:43 +0000
commit274500300ded42687addc3892640c90eb96d6d04 (patch)
tree5c477bd2e94c2ce76a294e5c372f10afa1d4bcc9 /configobj.py
parent6c74c3e6b6abe8dbb3265faa6eebf7f6af1bf521 (diff)
downloadconfigobj-274500300ded42687addc3892640c90eb96d6d04.tar.gz
Applied ConfigObj speedup patch from Christian Heimes
Diffstat (limited to 'configobj.py')
-rw-r--r--configobj.py21
1 files changed, 14 insertions, 7 deletions
diff --git a/configobj.py b/configobj.py
index fd61bcd..db43bce 100644
--- a/configobj.py
+++ b/configobj.py
@@ -331,6 +331,7 @@ class InterpolationEngine(object):
# compiled regexp to use in self.interpolate()
_KEYCRE = re.compile(r"%\(([^)]*)\)s")
+ _cookie = '%'
def __init__(self, section):
# the Section instance that "owns" this engine
@@ -338,6 +339,10 @@ class InterpolationEngine(object):
def interpolate(self, key, value):
+ # short-cut
+ if not self._cookie in value:
+ return value
+
def recursive_interpolate(key, value, section, backtrail):
"""The function that does the actual work.
@@ -349,7 +354,7 @@ class InterpolationEngine(object):
This is similar to a depth-first-search algorithm.
"""
# Have we been here already?
- if backtrail.has_key((key, section.name)):
+ if (key, section.name) in backtrail:
# Yes - infinite loop detected
raise InterpolationLoopError(key)
# Place a marker on our backtrail so we won't come back here again
@@ -442,6 +447,7 @@ class InterpolationEngine(object):
class ConfigParserInterpolation(InterpolationEngine):
"""Behaves like ConfigParser."""
+ _cookie = '%'
_KEYCRE = re.compile(r"%\(([^)]*)\)s")
def _parse_match(self, match):
@@ -453,6 +459,7 @@ class ConfigParserInterpolation(InterpolationEngine):
class TemplateInterpolation(InterpolationEngine):
"""Behaves like string.Template."""
+ _cookie = '$'
_delimiter = '$'
_KEYCRE = re.compile(r"""
\$(?:
@@ -604,7 +611,7 @@ class Section(dict):
raise ValueError('The key "%s" is not a string.' % key)
# add the comment
- if not self.comments.has_key(key):
+ if key not in self.comments:
self.comments[key] = []
self.inline_comments[key] = ''
# remove the entry from defaults
@@ -612,13 +619,13 @@ class Section(dict):
self.defaults.remove(key)
#
if isinstance(value, Section):
- if not self.has_key(key):
+ if key not in self:
self.sections.append(key)
dict.__setitem__(self, key, value)
elif isinstance(value, dict) and not unrepr:
# First create the new depth level,
# then create the section
- if not self.has_key(key):
+ if key not in self:
self.sections.append(key)
new_depth = self.depth + 1
dict.__setitem__(
@@ -631,7 +638,7 @@ class Section(dict):
indict=value,
name=key))
else:
- if not self.has_key(key):
+ if key not in self:
self.scalars.append(key)
if not self.main.stringify:
if isinstance(value, basestring):
@@ -1560,7 +1567,7 @@ class ConfigObj(Section):
NestingError, infile, cur_index)
sect_name = self._unquote(sect_name)
- if parent.has_key(sect_name):
+ if sect_name in parent:
self._handle_error('Duplicate section name at line %s.',
DuplicateError, infile, cur_index)
continue
@@ -1638,7 +1645,7 @@ class ConfigObj(Section):
continue
#
key = self._unquote(key)
- if this_section.has_key(key):
+ if key in this_section:
self._handle_error(
'Duplicate keyword name at line %s.',
DuplicateError, infile, cur_index)