diff --git a/mercurial/formatter.py b/mercurial/formatter.py --- a/mercurial/formatter.py +++ b/mercurial/formatter.py @@ -321,8 +321,8 @@ class _templateconverter(object): 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''' diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -62,6 +62,11 @@ class _hybrid(object): 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])