Mercurial > hg
comparison mercurial/statichttprepo.py @ 14962:1c917bc66ccc
statichttprepo: replace hasattr with getattr
author | Augie Fackler <durin42@gmail.com> |
---|---|
date | Mon, 25 Jul 2011 15:47:43 -0500 |
parents | 4bf9493e7b07 |
children | 23921c17299a |
comparison
equal
deleted
inserted
replaced
14961:5523529bd1af | 14962:1c917bc66ccc |
---|---|
29 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) | 29 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) |
30 | 30 |
31 try: | 31 try: |
32 f = self.opener.open(req) | 32 f = self.opener.open(req) |
33 data = f.read() | 33 data = f.read() |
34 if hasattr(f, 'getcode'): | 34 # Python 2.6+ defines a getcode() function, and 2.4 and |
35 # python 2.6+ | 35 # 2.5 appear to always have an undocumented code attribute |
36 code = f.getcode() | 36 # set. If we can't read either of those, fall back to 206 |
37 elif hasattr(f, 'code'): | 37 # and hope for the best. |
38 # undocumented attribute, seems to be set in 2.4 and 2.5 | 38 code = getattr(f, 'getcode', lambda : getattr(f, 'code', 206))() |
39 code = f.code | |
40 else: | |
41 # Don't know how to check, hope for the best. | |
42 code = 206 | |
43 except urllib2.HTTPError, inst: | 39 except urllib2.HTTPError, inst: |
44 num = inst.code == 404 and errno.ENOENT or None | 40 num = inst.code == 404 and errno.ENOENT or None |
45 raise IOError(num, inst) | 41 raise IOError(num, inst) |
46 except urllib2.URLError, inst: | 42 except urllib2.URLError, inst: |
47 raise IOError(None, inst.reason[1]) | 43 raise IOError(None, inst.reason[1]) |