--- a/mercurial/statichttprepo.py Sun May 24 18:30:59 2009 +0200
+++ b/mercurial/statichttprepo.py Sun May 24 18:31:01 2009 +0200
@@ -30,14 +30,31 @@
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
except urllib2.HTTPError, inst:
num = inst.code == 404 and errno.ENOENT or None
raise IOError(num, inst)
except urllib2.URLError, inst:
raise IOError(None, inst.reason[1])
- if bytes:
+ if code == 200:
+ # HTTPRangeHandler does nothing if remote does not support
+ # Range headers and returns the full entity. Let's slice it.
+ if bytes:
+ data = data[self.pos:self.pos + bytes]
+ else:
+ data = data[self.pos:]
+ elif bytes:
data = data[:bytes]
+ self.pos += len(data)
return data
def build_opener(ui, authinfo):