--- a/mercurial/formatter.py Wed Apr 05 22:25:36 2017 +0900
+++ b/mercurial/formatter.py Wed Apr 05 22:28:09 2017 +0900
@@ -321,8 +321,8 @@
data = util.sortdict(_iteritems(data))
def f():
yield _plainconverter.formatdict(data, key, value, fmt, sep)
- return templatekw._hybrid(f(), data, lambda k: {key: k, value: data[k]},
- lambda d: fmt % (d[key], d[value]))
+ return templatekw.hybriddict(data, key=key, value=value, fmt=fmt,
+ gen=f())
@staticmethod
def formatlist(data, name, fmt, sep):
'''build object that can be evaluated as either plain string or list'''
--- a/mercurial/templatekw.py Wed Apr 05 22:25:36 2017 +0900
+++ b/mercurial/templatekw.py Wed Apr 05 22:28:09 2017 +0900
@@ -62,6 +62,11 @@
raise AttributeError(name)
return getattr(self._values, name)
+def hybriddict(data, key='key', value='value', fmt='%s=%s', gen=None):
+ """Wrap data to support both dict-like and string-like operations"""
+ return _hybrid(gen, data, lambda k: {key: k, value: data[k]},
+ lambda d: fmt % (d[key], d[value]))
+
def hybridlist(data, name, fmt='%s', gen=None):
"""Wrap data to support both list-like and string-like operations"""
return _hybrid(gen, data, lambda x: {name: x}, lambda d: fmt % d[name])