globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__')
authorAugie Fackler <durin42@gmail.com>
Mon, 25 Jul 2011 15:30:19 -0500
changeset 14944 e2c413bde8a5
parent 14943 d3bb825ddae3
child 14945 11aad09a6370
globally: use safehasattr(x, '__iter__') instead of hasattr(x, '__iter__')
mercurial/hgweb/request.py
mercurial/templatefilters.py
mercurial/templater.py
--- 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: