# HG changeset patch # User Augie Fackler # Date 1311626863 18000 # Node ID 1c917bc66cccab4bdd13cd56bfae4e747f69034c # Parent 5523529bd1afe175d9072f3cd45abe4e3bee3b8b statichttprepo: replace hasattr with getattr diff -r 5523529bd1af -r 1c917bc66ccc 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)