Index: Lib/string.py =================================================================== --- Lib/string.py (revision 51012) +++ Lib/string.py (working copy) @@ -81,23 +81,6 @@ #################################################################### 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] - - class _TemplateMetaclass(type): pattern = r""" %(delim)s(?: @@ -150,7 +133,8 @@ if not args: mapping = kws elif kws: - mapping = _multimap(kws, args[0]) + mapping = args[0] + mapping.update(kws) else: mapping = args[0] # Helper function for .sub() @@ -176,7 +160,8 @@ if not args: mapping = kws elif kws: - mapping = _multimap(kws, args[0]) + mapping = args[0] + mapping.update(kws) else: mapping = args[0] # Helper function for .sub() Index: Lib/test/test_pep292.py =================================================================== --- Lib/test/test_pep292.py (revision 51012) +++ Lib/test/test_pep292.py (working copy) @@ -2,6 +2,7 @@ # Author: barry@python.org (Barry Warsaw) # License: http://www.opensource.org/licenses/PythonSoftFoundation.php +import UserDict import unittest from string import Template @@ -183,7 +184,27 @@ raises(ValueError, s.substitute, dict(gift='bud', who='you')) eq(s.safe_substitute(), 'this &gift is for &{who} &') + def test_mapping_updated_with_kws(self): + class LowerCasedMapping(UserDict.UserDict): + """A mapping in which all keys are lower-cased. + """ + def __setitem__(self, name, val): + self.data[name.lower()] = val + def __getitem__(self, name): + return self.data[name.lower()] + def update(self, dct): + for k, v in dct.items(): + self[k] = v + + eq = self.assertEqual + raises = self.assertRaises + s = Template('Greetings, $program!') + d = LowerCasedMapping(program='perl') + eq(s.substitute(d, PROGRAM='python'), 'Greetings, python!') + eq(s.safe_substitute(d, PROGRAM='python'), 'Greetings, python!') + + def test_main(): from test import test_support test_classes = [TestTemplate,]