Show More
@@ -0,0 +1,24 b'' | |||||
|
1 | # httprangereader.py - just what it says | |||
|
2 | # | |||
|
3 | # Copyright 2005 Matt Mackall <mpm@selenic.com> | |||
|
4 | # | |||
|
5 | # This software may be used and distributed according to the terms | |||
|
6 | # of the GNU General Public License, incorporated herein by reference. | |||
|
7 | ||||
|
8 | import byterange, urllib2 | |||
|
9 | ||||
|
10 | class httprangereader: | |||
|
11 | def __init__(self, url): | |||
|
12 | self.url = url | |||
|
13 | self.pos = 0 | |||
|
14 | def seek(self, pos): | |||
|
15 | self.pos = pos | |||
|
16 | def read(self, bytes=None): | |||
|
17 | opener = urllib2.build_opener(byterange.HTTPRangeHandler()) | |||
|
18 | urllib2.install_opener(opener) | |||
|
19 | req = urllib2.Request(self.url) | |||
|
20 | end = '' | |||
|
21 | if bytes: end = self.pos + bytes | |||
|
22 | req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) | |||
|
23 | f = urllib2.urlopen(req) | |||
|
24 | return f.read() |
@@ -9,7 +9,7 b' import sys, struct, os' | |||||
9 | from revlog import * |
|
9 | from revlog import * | |
10 | from demandload import * |
|
10 | from demandload import * | |
11 | demandload(globals(), "re lock urllib urllib2 transaction time socket") |
|
11 | demandload(globals(), "re lock urllib urllib2 transaction time socket") | |
12 |
demandload(globals(), "tempfile |
|
12 | demandload(globals(), "tempfile httprangereader difflib") | |
13 |
|
13 | |||
14 | def is_exec(f): |
|
14 | def is_exec(f): | |
15 | return (os.stat(f).st_mode & 0100 != 0) |
|
15 | return (os.stat(f).st_mode & 0100 != 0) | |
@@ -321,7 +321,7 b' def opener(base):' | |||||
321 | def o(path, mode="r"): |
|
321 | def o(path, mode="r"): | |
322 | if p[:7] == "http://": |
|
322 | if p[:7] == "http://": | |
323 | f = os.path.join(p, urllib.quote(path)) |
|
323 | f = os.path.join(p, urllib.quote(path)) | |
324 | return httprangereader(f) |
|
324 | return httprangereader.httprangereader(f) | |
325 |
|
325 | |||
326 | f = os.path.join(p, path) |
|
326 | f = os.path.join(p, path) | |
327 |
|
327 | |||
@@ -1416,18 +1416,3 b' def repository(ui, path=None, create=0):' | |||||
1416 | else: |
|
1416 | else: | |
1417 | return localrepository(ui, path, create) |
|
1417 | return localrepository(ui, path, create) | |
1418 |
|
1418 | |||
1419 | class httprangereader: |
|
|||
1420 | def __init__(self, url): |
|
|||
1421 | self.url = url |
|
|||
1422 | self.pos = 0 |
|
|||
1423 | def seek(self, pos): |
|
|||
1424 | self.pos = pos |
|
|||
1425 | def read(self, bytes=None): |
|
|||
1426 | opener = urllib2.build_opener(byterange.HTTPRangeHandler()) |
|
|||
1427 | urllib2.install_opener(opener) |
|
|||
1428 | req = urllib2.Request(self.url) |
|
|||
1429 | end = '' |
|
|||
1430 | if bytes: end = self.pos + bytes |
|
|||
1431 | req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) |
|
|||
1432 | f = urllib2.urlopen(req) |
|
|||
1433 | return f.read() |
|
General Comments 0
You need to be logged in to leave comments.
Login now