Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/templateutil.py @ 37323:8c31b434697f
templater: define interface for objects which act as iterator of mappings
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 17 Mar 2018 21:21:50 +0900 |
parents | 26f6fc179e62 |
children | c2f74b8f6b7f |
comparison
equal
deleted
inserted
replaced
37322:a67fd1fe5109 | 37323:8c31b434697f |
---|---|
34 Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain the inner | 34 Use unwrapvalue(), unwrapastype(), or unwraphybrid() to obtain the inner |
35 object. | 35 object. |
36 """ | 36 """ |
37 | 37 |
38 __metaclass__ = abc.ABCMeta | 38 __metaclass__ = abc.ABCMeta |
39 | |
40 @abc.abstractmethod | |
41 def itermaps(self): | |
42 """Yield each template mapping""" | |
39 | 43 |
40 @abc.abstractmethod | 44 @abc.abstractmethod |
41 def show(self, context, mapping): | 45 def show(self, context, mapping): |
42 """Return a bytes or (possibly nested) generator of bytes representing | 46 """Return a bytes or (possibly nested) generator of bytes representing |
43 the underlying object | 47 the underlying object |
491 % (fn, sym)) | 495 % (fn, sym)) |
492 | 496 |
493 def runmap(context, mapping, data): | 497 def runmap(context, mapping, data): |
494 darg, targ = data | 498 darg, targ = data |
495 d = evalrawexp(context, mapping, darg) | 499 d = evalrawexp(context, mapping, darg) |
496 if util.safehasattr(d, 'itermaps'): | 500 if isinstance(d, wrapped): |
497 diter = d.itermaps() | 501 diter = d.itermaps() |
498 else: | 502 else: |
499 try: | 503 try: |
500 diter = iter(d) | 504 diter = iter(d) |
501 except TypeError: | 505 except TypeError: |