statichttprepo: replace hasattr with getattr
authorAugie Fackler <durin42@gmail.com>
Mon, 25 Jul 2011 15:47:43 -0500
changeset 14962 1c917bc66ccc
parent 14961 5523529bd1af
child 14963 c035f1c53e39
statichttprepo: replace hasattr with getattr
mercurial/statichttprepo.py
--- a/mercurial/statichttprepo.py	Mon Jul 25 15:45:11 2011 -0500
+++ b/mercurial/statichttprepo.py	Mon Jul 25 15:47:43 2011 -0500
@@ -31,15 +31,11 @@
         try:
             f = self.opener.open(req)
             data = f.read()
-            if hasattr(f, 'getcode'):
-                # python 2.6+
-                code = f.getcode()
-            elif hasattr(f, 'code'):
-                # undocumented attribute, seems to be set in 2.4 and 2.5
-                code = f.code
-            else:
-                # Don't know how to check, hope for the best.
-                code = 206
+            # Python 2.6+ defines a getcode() function, and 2.4 and
+            # 2.5 appear to always have an undocumented code attribute
+            # set. If we can't read either of those, fall back to 206
+            # and hope for the best.
+            code = getattr(f, 'getcode', lambda : getattr(f, 'code', 206))()
         except urllib2.HTTPError, inst:
             num = inst.code == 404 and errno.ENOENT or None
             raise IOError(num, inst)