##// END OF EJS Templates
url: move _wraphttpresponse() from httpeer...
Gregory Szorc -
r40054:f80db6ad default
parent child Browse files
Show More
@@ -69,42 +69,6 b' def encodevalueinheaders(value, header, '
69 69
70 70 return result
71 71
72 def _wraphttpresponse(resp):
73 """Wrap an HTTPResponse with common error handlers.
74
75 This ensures that any I/O from any consumer raises the appropriate
76 error and messaging.
77 """
78 origread = resp.read
79
80 class readerproxy(resp.__class__):
81 def read(self, size=None):
82 try:
83 return origread(size)
84 except httplib.IncompleteRead as e:
85 # e.expected is an integer if length known or None otherwise.
86 if e.expected:
87 got = len(e.partial)
88 total = e.expected + got
89 msg = _('HTTP request error (incomplete response; '
90 'expected %d bytes got %d)') % (total, got)
91 else:
92 msg = _('HTTP request error (incomplete response)')
93
94 raise error.PeerTransportError(
95 msg,
96 hint=_('this may be an intermittent network failure; '
97 'if the error persists, consider contacting the '
98 'network or server operator'))
99 except httplib.HTTPException as e:
100 raise error.PeerTransportError(
101 _('HTTP request error (%s)') % e,
102 hint=_('this may be an intermittent network failure; '
103 'if the error persists, consider contacting the '
104 'network or server operator'))
105
106 resp.__class__ = readerproxy
107
108 72 class _multifile(object):
109 73 def __init__(self, *fileobjs):
110 74 for f in fileobjs:
@@ -325,7 +289,7 b' def sendrequest(ui, opener, req):'
325 289 % (util.timer() - start, code))
326 290
327 291 # Insert error handlers for common I/O failures.
328 _wraphttpresponse(res)
292 urlmod.wrapresponse(res)
329 293
330 294 return res
331 295
@@ -595,3 +595,39 b' def open(ui, url_, data=None):'
595 595 url_ = 'file://' + pycompat.bytesurl(urlreq.pathname2url(path))
596 596 authinfo = None
597 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
General Comments 0
You need to be logged in to leave comments. Login now