Mercurial > public > mercurial-scm > hg
comparison mercurial/hg.py @ 372:4b0f562c61f4
Move httprangereader into its own file
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Move httprangereader into its own file
manifest hash: 7a856e4024ce5d3d305e23e418a77d3058c74ddf
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (GNU/Linux)
iD8DBQFCsPj4ywK+sNU5EO8RAizKAJ9kbYVAC+iL4cKml14BcwX9okdnJQCgjLAP
cWM5/y9FdC3THOC6DkUNic0=
=PkL6
-----END PGP SIGNATURE-----
author | mpm@selenic.com |
---|---|
date | Wed, 15 Jun 2005 19:58:48 -0800 |
parents | ae96b7e1318d |
children | e5d769afd3ef |
comparison
equal
deleted
inserted
replaced
371:6e3436082697 | 372:4b0f562c61f4 |
---|---|
7 | 7 |
8 import sys, struct, os | 8 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 byterange difflib") | 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) |
16 | 16 |
17 def set_exec(f, mode): | 17 def set_exec(f, mode): |
319 def opener(base): | 319 def opener(base): |
320 p = base | 320 p = 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 |
328 mode += "b" # for that other OS | 328 mode += "b" # for that other OS |
329 | 329 |
1414 if path and path[:11] == "old-http://": | 1414 if path and path[:11] == "old-http://": |
1415 return localrepository(ui, path.replace("old-http://", "http://")) | 1415 return localrepository(ui, path.replace("old-http://", "http://")) |
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() |