summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2011-02-22 01:55:36 (GMT)
committerRaymond Hettinger <python@rcn.com>2011-02-22 01:55:36 (GMT)
commitc9423109f5d1e9f4fd034f036687468de6eeb638 (patch)
treeb746259344e7d1ab6530eb9b98fb95596719c1e6 /Lib
parent16fe75e4e0bbc6eadb97c199272dd4b7616d8042 (diff)
downloadcpython-c9423109f5d1e9f4fd034f036687468de6eeb638.zip
cpython-c9423109f5d1e9f4fd034f036687468de6eeb638.tar.gz
cpython-c9423109f5d1e9f4fd034f036687468de6eeb638.tar.bz2
Factor-out common code for helper classes.
Diffstat (limited to 'Lib')
-rw-r--r--Lib/collections/__init__.py2
-rw-r--r--Lib/string.py22
2 files changed, 4 insertions, 20 deletions
diff --git a/Lib/collections/__init__.py b/Lib/collections/__init__.py
index 6c41db3..89cf2ed 100644
--- a/Lib/collections/__init__.py
+++ b/Lib/collections/__init__.py
@@ -633,7 +633,7 @@ class Counter(dict):
########################################################################
-### ChainMap (helper for configparser)
+### ChainMap (helper for configparser and string.Template)
########################################################################
class _ChainMap(MutableMapping):
diff --git a/Lib/string.py b/Lib/string.py
index ef0334c..2bc5d00 100644
--- a/Lib/string.py
+++ b/Lib/string.py
@@ -46,23 +46,7 @@ def capwords(s, sep=None):
####################################################################
import re as _re
-
-class _multimap:
- """Helper class for combining multiple mappings.
-
- Used by .{safe_,}substitute() to combine the mapping and keyword
- arguments.
- """
- def __init__(self, primary, secondary):
- self._primary = primary
- self._secondary = secondary
-
- def __getitem__(self, key):
- try:
- return self._primary[key]
- except KeyError:
- return self._secondary[key]
-
+from collections import _ChainMap
class _TemplateMetaclass(type):
pattern = r"""
@@ -116,7 +100,7 @@ class Template(metaclass=_TemplateMetaclass):
if not args:
mapping = kws
elif kws:
- mapping = _multimap(kws, args[0])
+ mapping = _ChainMap(kws, args[0])
else:
mapping = args[0]
# Helper function for .sub()
@@ -142,7 +126,7 @@ class Template(metaclass=_TemplateMetaclass):
if not args:
mapping = kws
elif kws:
- mapping = _multimap(kws, args[0])
+ mapping = _ChainMap(kws, args[0])
else:
mapping = args[0]
# Helper function for .sub()