changeset 14962:1c917bc66ccc

statichttprepo: replace hasattr with getattr
author Augie Fackler <durin42@gmail.com>
date Mon, 25 Jul 2011 15:47:43 -0500
parents 5523529bd1af
children c035f1c53e39
files mercurial/statichttprepo.py
diffstat 1 files changed, 5 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- 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)