Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templateutil.py @ 43106:d783f945a701
py3: finish porting iteritems() to pycompat and remove source transformer
This commit finishes porting .iteritems() to pycompat.iteritems()
for the mercurial package.
The translation of .iteritems() to .items() was the last conversion
performed by the source transformer. With the porting to pycompat
complete, we no longer have a need for the source transformer. So
the source transformer has been removed. Good riddance! The code
base is now compatible with Python 2 and Python 3.
For the record, as the person who introduced the source transformer,
it brings me joy to delete it. It accomplished its goal to facilitate
a port to Python 3 without overly burdening people on some painful
low-level differences between Python 2 and 3. It is unfortunate we
still have to wallpaper over many differences with the pycompat
shim. But it is what it is.
Differential Revision: https://phab.mercurial-scm.org/D7015
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 07 Oct 2019 00:04:04 -0400 |
parents | c59eb1560c44 |
children | 3e57809d3251 |
comparison
equal
deleted
inserted
replaced
43105:649d3ac37a12 | 43106:d783f945a701 |
---|---|
306 | 306 |
307 def filter(self, context, mapping, select): | 307 def filter(self, context, mapping, select): |
308 if util.safehasattr(self._values, b'get'): | 308 if util.safehasattr(self._values, b'get'): |
309 values = { | 309 values = { |
310 k: v | 310 k: v |
311 for k, v in self._values.iteritems() | 311 for k, v in pycompat.iteritems(self._values) |
312 if select(self._wrapvalue(k, v)) | 312 if select(self._wrapvalue(k, v)) |
313 } | 313 } |
314 else: | 314 else: |
315 values = [v for v in self._values if select(self._wrapvalue(v, v))] | 315 values = [v for v in self._values if select(self._wrapvalue(v, v))] |
316 return hybrid(None, values, self._makemap, self._joinfmt, self._keytype) | 316 return hybrid(None, values, self._makemap, self._joinfmt, self._keytype) |
339 def tovalue(self, context, mapping): | 339 def tovalue(self, context, mapping): |
340 # TODO: make it non-recursive for trivial lists/dicts | 340 # TODO: make it non-recursive for trivial lists/dicts |
341 xs = self._values | 341 xs = self._values |
342 if util.safehasattr(xs, b'get'): | 342 if util.safehasattr(xs, b'get'): |
343 return { | 343 return { |
344 k: unwrapvalue(context, mapping, v) for k, v in xs.iteritems() | 344 k: unwrapvalue(context, mapping, v) |
345 for k, v in pycompat.iteritems(xs) | |
345 } | 346 } |
346 return [unwrapvalue(context, mapping, x) for x in xs] | 347 return [unwrapvalue(context, mapping, x) for x in xs] |
347 | 348 |
348 | 349 |
349 class hybriditem(mappable, wrapped): | 350 class hybriditem(mappable, wrapped): |
459 # drop internal resources (recursively) which shouldn't be displayed | 460 # drop internal resources (recursively) which shouldn't be displayed |
460 lm = context.overlaymap(mapping, nm) | 461 lm = context.overlaymap(mapping, nm) |
461 items.append( | 462 items.append( |
462 { | 463 { |
463 k: unwrapvalue(context, lm, v) | 464 k: unwrapvalue(context, lm, v) |
464 for k, v in nm.iteritems() | 465 for k, v in pycompat.iteritems(nm) |
465 if k not in knownres | 466 if k not in knownres |
466 } | 467 } |
467 ) | 468 ) |
468 return items | 469 return items |
469 | 470 |
637 """Wrap data like hybriddict(), but also supports old-style list template | 638 """Wrap data like hybriddict(), but also supports old-style list template |
638 | 639 |
639 This exists for backward compatibility with the old-style template. Use | 640 This exists for backward compatibility with the old-style template. Use |
640 hybriddict() for new template keywords. | 641 hybriddict() for new template keywords. |
641 """ | 642 """ |
642 c = [{key: k, value: v} for k, v in data.iteritems()] | 643 c = [{key: k, value: v} for k, v in pycompat.iteritems(data)] |
643 f = _showcompatlist(context, mapping, name, c, plural, separator) | 644 f = _showcompatlist(context, mapping, name, c, plural, separator) |
644 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) | 645 return hybriddict(data, key=key, value=value, fmt=fmt, gen=f) |
645 | 646 |
646 | 647 |
647 def compatlist( | 648 def compatlist( |