mercurial/hg.py
changeset 372 4b0f562c61f4
parent 363 ae96b7e1318d
child 377 e5d769afd3ef
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()