Mercurial > hg-stable
changeset 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 | d3bb825ddae3 |
children | 11aad09a6370 |
files | mercurial/hgweb/request.py mercurial/templatefilters.py mercurial/templater.py |
diffstat | 3 files changed, 5 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/hgweb/request.py Mon Jul 25 16:24:37 2011 -0500 +++ b/mercurial/hgweb/request.py Mon Jul 25 15:30:19 2011 -0500 @@ -101,7 +101,7 @@ self.headers = [] def write(self, thing): - if hasattr(thing, "__iter__"): + if util.safehasattr(thing, "__iter__"): for part in thing: self.write(part) else:
--- a/mercurial/templatefilters.py Mon Jul 25 16:24:37 2011 -0500 +++ b/mercurial/templatefilters.py Mon Jul 25 15:30:19 2011 -0500 @@ -194,7 +194,7 @@ s = '%s: %s' % (json(k), json(v)) out.append(s) return '{' + ', '.join(out) + '}' - elif hasattr(obj, '__iter__'): + elif util.safehasattr(obj, '__iter__'): out = [] for i in obj: out.append(json(i)) @@ -279,7 +279,7 @@ """:stringify: Any type. Turns the value into text by converting values into text and concatenating them. """ - if hasattr(thing, '__iter__') and not isinstance(thing, str): + if util.safehasattr(thing, '__iter__') and not isinstance(thing, str): return "".join([stringify(t) for t in thing if t is not None]) return str(thing)
--- a/mercurial/templater.py Mon Jul 25 16:24:37 2011 -0500 +++ b/mercurial/templater.py Mon Jul 25 15:30:19 2011 -0500 @@ -203,14 +203,14 @@ '''yield a single stream from a possibly nested set of iterators''' if isinstance(thing, str): yield thing - elif not hasattr(thing, '__iter__'): + elif not util.safehasattr(thing, '__iter__'): if thing is not None: yield str(thing) else: for i in thing: if isinstance(i, str): yield i - elif not hasattr(i, '__iter__'): + elif not util.safehasattr(i, '__iter__'): if i is not None: yield str(i) elif i is not None: