Mercurial > hg
changeset 38225:d48b80d58848
templater: unify unwrapvalue() with _unwrapvalue()
All weird generators got removed from the hgweb codebase. We still have
inconsistent behavior regarding join() of a byte string, which will be
addressed later.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Wed, 04 Apr 2018 21:06:14 +0900 |
parents | 61cecab0cc20 |
children | 7824783a6d5e |
files | mercurial/templatefuncs.py mercurial/templater.py mercurial/templateutil.py |
diffstat | 3 files changed, 9 insertions(+), 19 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/templatefuncs.py Wed Apr 04 21:01:21 2018 +0900 +++ b/mercurial/templatefuncs.py Wed Apr 04 21:06:14 2018 +0900 @@ -333,8 +333,9 @@ joiner = evalstring(context, mapping, args[1]) if isinstance(joinset, templateutil.wrapped): return joinset.join(context, mapping, joiner) - # TODO: perhaps a generator should be stringify()-ed here, but we can't - # because hgweb abuses it as a keyword that returns a list of dicts. + # TODO: rethink about join() of a byte string, which had no defined + # behavior since a string may be either a bytes or a generator. + # TODO: fix type error on join() of non-iterable joinset = templateutil.unwrapvalue(context, mapping, joinset) return templateutil.joinitems(pycompat.maybebytestr(joinset), joiner)
--- a/mercurial/templater.py Wed Apr 04 21:01:21 2018 +0900 +++ b/mercurial/templater.py Wed Apr 04 21:06:14 2018 +0900 @@ -26,9 +26,6 @@ values of any printable types, and will be folded by ``stringify()`` or ``flatten()``. - BUG: hgweb overloads this type for mappings (i.e. some hgweb keywords - returns a generator of dicts.) - None sometimes represents an empty value, which can be stringified to ''.
--- a/mercurial/templateutil.py Wed Apr 04 21:01:21 2018 +0900 +++ b/mercurial/templateutil.py Wed Apr 04 21:06:14 2018 +0900 @@ -285,12 +285,6 @@ return thing return thing.show(context, mapping) -def unwrapvalue(context, mapping, thing): - """Move the inner value object out of the wrapper""" - if not isinstance(thing, wrapped): - return thing - return thing.tovalue(context, mapping) - def wraphybridvalue(container, key, value): """Wrap an element of hybrid container to be mappable @@ -455,12 +449,10 @@ def evalfuncarg(context, mapping, arg): """Evaluate given argument as value type""" - return _unwrapvalue(context, mapping, evalrawexp(context, mapping, arg)) + return unwrapvalue(context, mapping, evalrawexp(context, mapping, arg)) -# TODO: unify this with unwrapvalue() once the bug of templatefunc.join() -# is fixed. we can't do that right now because join() has to take a generator -# of byte strings as it is, not a lazy byte string. -def _unwrapvalue(context, mapping, thing): +def unwrapvalue(context, mapping, thing): + """Move the inner value object out of the wrapper""" if isinstance(thing, wrapped): return thing.tovalue(context, mapping) # evalrawexp() may return string, generator of strings or arbitrary object @@ -492,7 +484,7 @@ return unwrapdate(context, mapping, thing, err) def unwrapdate(context, mapping, thing, err=None): - thing = _unwrapvalue(context, mapping, thing) + thing = unwrapvalue(context, mapping, thing) try: return dateutil.parsedate(thing) except AttributeError: @@ -507,7 +499,7 @@ return unwrapinteger(context, mapping, thing, err) def unwrapinteger(context, mapping, thing, err=None): - thing = _unwrapvalue(context, mapping, thing) + thing = unwrapvalue(context, mapping, thing) try: return int(thing) except (TypeError, ValueError): @@ -527,7 +519,7 @@ return stringify(context, mapping, thing) _unwrapfuncbytype = { - None: _unwrapvalue, + None: unwrapvalue, bytes: stringify, date: unwrapdate, int: unwrapinteger,