mercurial/url.py
changeset 40018 f80db6adabbe
parent 37735 126998dcfb08
child 40031 f2dffa1359c6
equal deleted inserted replaced
40017:426cb2859013 40018:f80db6adabbe
   593     else:
   593     else:
   594         path = util.normpath(os.path.abspath(url_))
   594         path = util.normpath(os.path.abspath(url_))
   595         url_ = 'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
   595         url_ = 'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
   596         authinfo = None
   596         authinfo = None
   597     return opener(ui, authinfo).open(pycompat.strurl(url_), data)
   597     return opener(ui, authinfo).open(pycompat.strurl(url_), data)
       
   598 
       
   599 def wrapresponse(resp):
       
   600     """Wrap a response object with common error handlers.
       
   601 
       
   602     This ensures that any I/O from any consumer raises the appropriate
       
   603     error and messaging.
       
   604     """
       
   605     origread = resp.read
       
   606 
       
   607     class readerproxy(resp.__class__):
       
   608         def read(self, size=None):
       
   609             try:
       
   610                 return origread(size)
       
   611             except httplib.IncompleteRead as e:
       
   612                 # e.expected is an integer if length known or None otherwise.
       
   613                 if e.expected:
       
   614                     got = len(e.partial)
       
   615                     total = e.expected + got
       
   616                     msg = _('HTTP request error (incomplete response; '
       
   617                             'expected %d bytes got %d)') % (total, got)
       
   618                 else:
       
   619                     msg = _('HTTP request error (incomplete response)')
       
   620 
       
   621                 raise error.PeerTransportError(
       
   622                     msg,
       
   623                     hint=_('this may be an intermittent network failure; '
       
   624                            'if the error persists, consider contacting the '
       
   625                            'network or server operator'))
       
   626             except httplib.HTTPException as e:
       
   627                 raise error.PeerTransportError(
       
   628                     _('HTTP request error (%s)') % e,
       
   629                     hint=_('this may be an intermittent network failure; '
       
   630                            'if the error persists, consider contacting the '
       
   631                            'network or server operator'))
       
   632 
       
   633     resp.__class__ = readerproxy