Mercurial > public > mercurial-scm > hg
comparison mercurial/templatefilters.py @ 14944:e2c413bde8a5
globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__')
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 15:30:19 -0500 |
parents | 1f46be4689ed |
children | 376091a4ad23 |
comparison
equal
deleted
inserted
replaced
14943:d3bb825ddae3 | 14944:e2c413bde8a5 |
---|---|
192 out = [] | 192 out = [] |
193 for k, v in obj.iteritems(): | 193 for k, v in obj.iteritems(): |
194 s = '%s: %s' % (json(k), json(v)) | 194 s = '%s: %s' % (json(k), json(v)) |
195 out.append(s) | 195 out.append(s) |
196 return '{' + ', '.join(out) + '}' | 196 return '{' + ', '.join(out) + '}' |
197 elif hasattr(obj, '__iter__'): | 197 elif util.safehasattr(obj, '__iter__'): |
198 out = [] | 198 out = [] |
199 for i in obj: | 199 for i in obj: |
200 out.append(json(i)) | 200 out.append(json(i)) |
201 return '[' + ', '.join(out) + ']' | 201 return '[' + ', '.join(out) + ']' |
202 else: | 202 else: |
277 | 277 |
278 def stringify(thing): | 278 def stringify(thing): |
279 """:stringify: Any type. Turns the value into text by converting values into | 279 """:stringify: Any type. Turns the value into text by converting values into |
280 text and concatenating them. | 280 text and concatenating them. |
281 """ | 281 """ |
282 if hasattr(thing, '__iter__') and not isinstance(thing, str): | 282 if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): |
283 return "".join([stringify(t) for t in thing if t is not None]) | 283 return "".join([stringify(t) for t in thing if t is not None]) |
284 return str(thing) | 284 return str(thing) |
285 | 285 |
286 def strip(text): | 286 def strip(text): |
287 """:strip: Any text. Strips all leading and trailing whitespace.""" | 287 """:strip: Any text. Strips all leading and trailing whitespace.""" |