Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 37229:05db42732fce
templatefilters: handle TypeError by count()
Prepares for removing the weird exception catcher from runfilter().
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sun, 18 Mar 2018 16:47:44 +0900 |
parents | 9bcf096a2da2 |
children | 63144f33c8bb |
comparison
equal
deleted
inserted
replaced
37228:a0b17f744cbc | 37229:05db42732fce |
---|---|
9 | 9 |
10 import os | 10 import os |
11 import re | 11 import re |
12 import time | 12 import time |
13 | 13 |
14 from .i18n import _ | |
14 from . import ( | 15 from . import ( |
15 encoding, | 16 encoding, |
16 error, | 17 error, |
17 node, | 18 node, |
18 pycompat, | 19 pycompat, |
99 return os.path.basename(path) | 100 return os.path.basename(path) |
100 | 101 |
101 @templatefilter('count') | 102 @templatefilter('count') |
102 def count(i): | 103 def count(i): |
103 """List or text. Returns the length as an integer.""" | 104 """List or text. Returns the length as an integer.""" |
104 return len(i) | 105 try: |
106 return len(i) | |
107 except TypeError: | |
108 raise error.ParseError(_('not countable')) | |
105 | 109 |
106 @templatefilter('dirname', intype=bytes) | 110 @templatefilter('dirname', intype=bytes) |
107 def dirname(path): | 111 def dirname(path): |
108 """Any text. Treats the text as a path, and strips the last | 112 """Any text. Treats the text as a path, and strips the last |
109 component of the path after splitting by the path separator. | 113 component of the path after splitting by the path separator. |