Show More
@@ -8,34 +8,61 b'' | |||
|
8 | 8 | # of the GNU General Public License, incorporated herein by reference. |
|
9 | 9 | |
|
10 | 10 | from i18n import _ |
|
11 |
import changelog, |
|
|
11 | import changelog, byterange, url | |
|
12 | 12 | import repo, localrepo, manifest, util, store |
|
13 | 13 | import urllib, urllib2, errno |
|
14 | 14 | |
|
15 | class rangereader(httprangereader.httprangereader): | |
|
16 |
def |
|
|
15 | class httprangereader(object): | |
|
16 | def __init__(self, url, opener): | |
|
17 | # we assume opener has HTTPRangeHandler | |
|
18 | self.url = url | |
|
19 | self.pos = 0 | |
|
20 | self.opener = opener | |
|
21 | def seek(self, pos): | |
|
22 | self.pos = pos | |
|
23 | def read(self, bytes=None): | |
|
24 | req = urllib2.Request(self.url) | |
|
25 | end = '' | |
|
26 | if bytes: | |
|
27 | end = self.pos + bytes - 1 | |
|
28 | req.add_header('Range', 'bytes=%d-%s' % (self.pos, end)) | |
|
29 | ||
|
17 | 30 | try: |
|
18 | return httprangereader.httprangereader.read(self, size) | |
|
31 | f = self.opener.open(req) | |
|
32 | data = f.read() | |
|
19 | 33 | except urllib2.HTTPError, inst: |
|
20 | 34 | num = inst.code == 404 and errno.ENOENT or None |
|
21 | 35 | raise IOError(num, inst) |
|
22 | 36 | except urllib2.URLError, inst: |
|
23 | 37 | raise IOError(None, inst.reason[1]) |
|
24 | 38 | |
|
25 | def opener(base): | |
|
26 | """return a function that opens files over http""" | |
|
27 | p = base | |
|
28 | def o(path, mode="r"): | |
|
29 | f = "/".join((p, urllib.quote(path))) | |
|
30 | return rangereader(f) | |
|
31 | return o | |
|
39 | if bytes: | |
|
40 | data = data[:bytes] | |
|
41 | return data | |
|
42 | ||
|
43 | def build_opener(ui, authinfo): | |
|
44 | # urllib cannot handle URLs with embedded user or passwd | |
|
45 | urlopener = url.opener(ui, authinfo) | |
|
46 | urlopener.add_handler(byterange.HTTPRangeHandler()) | |
|
47 | ||
|
48 | def opener(base): | |
|
49 | """return a function that opens files over http""" | |
|
50 | p = base | |
|
51 | def o(path, mode="r"): | |
|
52 | f = "/".join((p, urllib.quote(path))) | |
|
53 | return httprangereader(f, urlopener) | |
|
54 | return o | |
|
55 | ||
|
56 | return opener | |
|
32 | 57 | |
|
33 | 58 | class statichttprepository(localrepo.localrepository): |
|
34 | 59 | def __init__(self, ui, path): |
|
35 | 60 | self._url = path |
|
36 | 61 | self.ui = ui |
|
37 | 62 | |
|
38 | self.path = path.rstrip('/') + "/.hg" | |
|
63 | self.path, authinfo = url.getauthinfo(path.rstrip('/') + "/.hg") | |
|
64 | ||
|
65 | opener = build_opener(ui, authinfo) | |
|
39 | 66 | self.opener = opener(self.path) |
|
40 | 67 | |
|
41 | 68 | # find requirements |
|
1 | NO CONTENT: file was removed |
General Comments 0
You need to be logged in to leave comments.
Login now