equal
deleted
inserted
replaced
30 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) |
30 req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) |
31 |
31 |
32 try: |
32 try: |
33 f = self.opener.open(req) |
33 f = self.opener.open(req) |
34 data = f.read() |
34 data = f.read() |
35 # Python 2.6+ defines a getcode() function, and 2.4 and |
35 code = f.code |
36 # 2.5 appear to always have an undocumented code attribute |
|
37 # set. If we can't read either of those, fall back to 206 |
|
38 # and hope for the best. |
|
39 code = getattr(f, 'getcode', lambda : getattr(f, 'code', 206))() |
|
40 except urllib2.HTTPError, inst: |
36 except urllib2.HTTPError, inst: |
41 num = inst.code == 404 and errno.ENOENT or None |
37 num = inst.code == 404 and errno.ENOENT or None |
42 raise IOError(num, inst) |
38 raise IOError(num, inst) |
43 except urllib2.URLError, inst: |
39 except urllib2.URLError, inst: |
44 raise IOError(None, inst.reason[1]) |
40 raise IOError(None, inst.reason[1]) |