[Python-checkins] r88492 - in python/branches/py3k/Lib: collections/__init__.py string.py

raymond.hettinger python-checkins at python.org
Tue Feb 22 02:55:36 CET 2011


Author: raymond.hettinger
Date: Tue Feb 22 02:55:36 2011
New Revision: 88492

Log:
Factor-out common code for helper classes.

Modified:
   python/branches/py3k/Lib/collections/__init__.py
   python/branches/py3k/Lib/string.py

Modified: python/branches/py3k/Lib/collections/__init__.py
==============================================================================
--- python/branches/py3k/Lib/collections/__init__.py	(original)
+++ python/branches/py3k/Lib/collections/__init__.py	Tue Feb 22 02:55:36 2011
@@ -633,7 +633,7 @@
 
 
 ########################################################################
-###  ChainMap (helper for configparser)
+###  ChainMap (helper for configparser and string.Template)
 ########################################################################
 
 class _ChainMap(MutableMapping):

Modified: python/branches/py3k/Lib/string.py
==============================================================================
--- python/branches/py3k/Lib/string.py	(original)
+++ python/branches/py3k/Lib/string.py	Tue Feb 22 02:55:36 2011
@@ -46,23 +46,7 @@
 
 ####################################################################
 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 @@
         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 @@
         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()


More information about the Python-checkins mailing list