mercurial/httprepo.py
changeset 2673 109a22f5434a
parent 2612 ffb895f16925
child 2740 386f04d6ecb3
equal deleted inserted replaced
2671:82864a2eb709 2673:109a22f5434a
   113     class httphandler(basehttphandler):
   113     class httphandler(basehttphandler):
   114         pass
   114         pass
   115 
   115 
   116 class httprepository(remoterepository):
   116 class httprepository(remoterepository):
   117     def __init__(self, ui, path):
   117     def __init__(self, ui, path):
       
   118         self.path = path
   118         self.caps = None
   119         self.caps = None
   119         scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
   120         scheme, netloc, urlpath, query, frag = urlparse.urlsplit(path)
   120         if query or frag:
   121         if query or frag:
   121             raise util.Abort(_('unsupported URL component: "%s"') %
   122             raise util.Abort(_('unsupported URL component: "%s"') %
   122                              (query or frag))
   123                              (query or frag))
   123         if not urlpath: urlpath = '/'
   124         if not urlpath: urlpath = '/'
   124         host, port, user, passwd = netlocsplit(netloc)
   125         host, port, user, passwd = netlocsplit(netloc)
   125 
   126 
   126         # urllib cannot handle URLs with embedded user or passwd
   127         # urllib cannot handle URLs with embedded user or passwd
   127         self.url = urlparse.urlunsplit((scheme, netlocunsplit(host, port),
   128         self._url = urlparse.urlunsplit((scheme, netlocunsplit(host, port),
   128                                         urlpath, '', ''))
   129                                          urlpath, '', ''))
   129         self.ui = ui
   130         self.ui = ui
   130 
   131 
   131         proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
   132         proxyurl = ui.config("http_proxy", "host") or os.getenv('http_proxy')
   132         proxyauthinfo = None
   133         proxyauthinfo = None
   133         handler = httphandler()
   134         handler = httphandler()
   187 
   188 
   188         # 1.0 here is the _protocol_ version
   189         # 1.0 here is the _protocol_ version
   189         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
   190         opener.addheaders = [('User-agent', 'mercurial/proto-1.0')]
   190         urllib2.install_opener(opener)
   191         urllib2.install_opener(opener)
   191 
   192 
       
   193     def url(self):
       
   194         return self.path
       
   195 
   192     # look up capabilities only when needed
   196     # look up capabilities only when needed
   193 
   197 
   194     def get_caps(self):
   198     def get_caps(self):
   195         if self.caps is None:
   199         if self.caps is None:
   196             try:
   200             try:
   211         headers = args.pop('headers', {})
   215         headers = args.pop('headers', {})
   212         self.ui.debug(_("sending %s command\n") % cmd)
   216         self.ui.debug(_("sending %s command\n") % cmd)
   213         q = {"cmd": cmd}
   217         q = {"cmd": cmd}
   214         q.update(args)
   218         q.update(args)
   215         qs = urllib.urlencode(q)
   219         qs = urllib.urlencode(q)
   216         cu = "%s?%s" % (self.url, qs)
   220         cu = "%s?%s" % (self._url, qs)
   217         try:
   221         try:
   218             resp = urllib2.urlopen(urllib2.Request(cu, data, headers))
   222             resp = urllib2.urlopen(urllib2.Request(cu, data, headers))
   219         except urllib2.HTTPError, inst:
   223         except urllib2.HTTPError, inst:
   220             if inst.code == 401:
   224             if inst.code == 401:
   221                 raise util.Abort(_('authorization failed'))
   225                 raise util.Abort(_('authorization failed'))
   232         # accept old "text/plain" and "application/hg-changegroup" for now
   236         # accept old "text/plain" and "application/hg-changegroup" for now
   233         if not proto.startswith('application/mercurial') and \
   237         if not proto.startswith('application/mercurial') and \
   234                not proto.startswith('text/plain') and \
   238                not proto.startswith('text/plain') and \
   235                not proto.startswith('application/hg-changegroup'):
   239                not proto.startswith('application/hg-changegroup'):
   236             raise hg.RepoError(_("'%s' does not appear to be an hg repository") %
   240             raise hg.RepoError(_("'%s' does not appear to be an hg repository") %
   237                                self.url)
   241                                self._url)
   238 
   242 
   239         if proto.startswith('application/mercurial'):
   243         if proto.startswith('application/mercurial'):
   240             version = proto[22:]
   244             version = proto[22:]
   241             if float(version) > 0.1:
   245             if float(version) > 0.1:
   242                 raise hg.RepoError(_("'%s' uses newer protocol %s") %
   246                 raise hg.RepoError(_("'%s' uses newer protocol %s") %
   243                                    (self.url, version))
   247                                    (self._url, version))
   244 
   248 
   245         return resp
   249         return resp
   246 
   250 
   247     def do_read(self, cmd, **args):
   251     def do_read(self, cmd, **args):
   248         fp = self.do_cmd(cmd, **args)
   252         fp = self.do_cmd(cmd, **args)