mercurial/httppeer.py
changeset 26587 56b2bcea2529
parent 25954 7bbdb78d2842
child 27637 b502138f5faa
equal deleted inserted replaced
26586:d51c658d3f04 26587:56b2bcea2529
    47         self.handler = None
    47         self.handler = None
    48         self.urlopener = None
    48         self.urlopener = None
    49         self.requestbuilder = None
    49         self.requestbuilder = None
    50         u = util.url(path)
    50         u = util.url(path)
    51         if u.query or u.fragment:
    51         if u.query or u.fragment:
    52             raise util.Abort(_('unsupported URL component: "%s"') %
    52             raise error.Abort(_('unsupported URL component: "%s"') %
    53                              (u.query or u.fragment))
    53                              (u.query or u.fragment))
    54 
    54 
    55         # urllib cannot handle URLs with embedded user or passwd
    55         # urllib cannot handle URLs with embedded user or passwd
    56         self._url, authinfo = u.authinfo()
    56         self._url, authinfo = u.authinfo()
    57 
    57 
    84             self.ui.debug('capabilities: %s\n' %
    84             self.ui.debug('capabilities: %s\n' %
    85                           (' '.join(self.caps or ['none'])))
    85                           (' '.join(self.caps or ['none'])))
    86         return self.caps
    86         return self.caps
    87 
    87 
    88     def lock(self):
    88     def lock(self):
    89         raise util.Abort(_('operation not supported over http'))
    89         raise error.Abort(_('operation not supported over http'))
    90 
    90 
    91     def _callstream(self, cmd, **args):
    91     def _callstream(self, cmd, **args):
    92         if cmd == 'pushkey':
    92         if cmd == 'pushkey':
    93             args['data'] = ''
    93             args['data'] = ''
    94         data = args.pop('data', None)
    94         data = args.pop('data', None)
   135             req.add_unredirected_header('Content-Length', '%d' % size)
   135             req.add_unredirected_header('Content-Length', '%d' % size)
   136         try:
   136         try:
   137             resp = self.urlopener.open(req)
   137             resp = self.urlopener.open(req)
   138         except urllib2.HTTPError as inst:
   138         except urllib2.HTTPError as inst:
   139             if inst.code == 401:
   139             if inst.code == 401:
   140                 raise util.Abort(_('authorization failed'))
   140                 raise error.Abort(_('authorization failed'))
   141             raise
   141             raise
   142         except httplib.HTTPException as inst:
   142         except httplib.HTTPException as inst:
   143             self.ui.debug('http error while sending %s command\n' % cmd)
   143             self.ui.debug('http error while sending %s command\n' % cmd)
   144             self.ui.traceback()
   144             self.ui.traceback()
   145             raise IOError(None, inst)
   145             raise IOError(None, inst)
   146         except IndexError:
   146         except IndexError:
   147             # this only happens with Python 2.3, later versions raise URLError
   147             # this only happens with Python 2.3, later versions raise URLError
   148             raise util.Abort(_('http error, possibly caused by proxy setting'))
   148             raise error.Abort(_('http error, possibly caused by proxy setting'))
   149         # record the url we got redirected to
   149         # record the url we got redirected to
   150         resp_url = resp.geturl()
   150         resp_url = resp.geturl()
   151         if resp_url.endswith(qs):
   151         if resp_url.endswith(qs):
   152             resp_url = resp_url[:-len(qs)]
   152             resp_url = resp_url[:-len(qs)]
   153         if self._url.rstrip('/') != resp_url.rstrip('/'):
   153         if self._url.rstrip('/') != resp_url.rstrip('/'):
   221             if len(vals) < 2:
   221             if len(vals) < 2:
   222                 raise error.ResponseError(_("unexpected response:"), r)
   222                 raise error.ResponseError(_("unexpected response:"), r)
   223             return vals
   223             return vals
   224         except socket.error as err:
   224         except socket.error as err:
   225             if err.args[0] in (errno.ECONNRESET, errno.EPIPE):
   225             if err.args[0] in (errno.ECONNRESET, errno.EPIPE):
   226                 raise util.Abort(_('push failed: %s') % err.args[1])
   226                 raise error.Abort(_('push failed: %s') % err.args[1])
   227             raise util.Abort(err.args[1])
   227             raise error.Abort(err.args[1])
   228         finally:
   228         finally:
   229             fp.close()
   229             fp.close()
   230             os.unlink(tempname)
   230             os.unlink(tempname)
   231 
   231 
   232     def _calltwowaystream(self, cmd, fp, **args):
   232     def _calltwowaystream(self, cmd, fp, **args):
   261         raise exception
   261         raise exception
   262 
   262 
   263 class httpspeer(httppeer):
   263 class httpspeer(httppeer):
   264     def __init__(self, ui, path):
   264     def __init__(self, ui, path):
   265         if not url.has_https:
   265         if not url.has_https:
   266             raise util.Abort(_('Python support for SSL and HTTPS '
   266             raise error.Abort(_('Python support for SSL and HTTPS '
   267                                'is not installed'))
   267                                'is not installed'))
   268         httppeer.__init__(self, ui, path)
   268         httppeer.__init__(self, ui, path)
   269 
   269 
   270 def instance(ui, path, create):
   270 def instance(ui, path, create):
   271     if create:
   271     if create:
   272         raise util.Abort(_('cannot create new http repository'))
   272         raise error.Abort(_('cannot create new http repository'))
   273     try:
   273     try:
   274         if path.startswith('https:'):
   274         if path.startswith('https:'):
   275             inst = httpspeer(ui, path)
   275             inst = httpspeer(ui, path)
   276         else:
   276         else:
   277             inst = httppeer(ui, path)
   277             inst = httppeer(ui, path)