Mercurial > hg
changeset 31925:5b2241e84982
templatekw: add public function to wrap a dict by _hybrid object
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 05 Apr 2017 22:28:09 +0900 |
parents | 21f129354dd0 |
children | 932241b8c644 |
files | mercurial/formatter.py mercurial/templatekw.py |
diffstat | 2 files changed, 7 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- 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])