########################################################################
-### ChainMap (helper for configparser)
+### ChainMap (helper for configparser and string.Template)
########################################################################
class _ChainMap(MutableMapping):
####################################################################
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"""
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()
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()