Details
Details
- Reviewers
yuja - Group Reviewers
hg-reviewers - Commits
- rHGa454123f5d94: keepalive: python 3 portability tweaks
Diff Detail
Diff Detail
- Repository
- rHG Mercurial
- Lint
Lint Skipped - Unit
Unit Tests Skipped
yuja |
hg-reviewers |
Lint Skipped |
Unit Tests Skipped |
Path | Packages | |||
---|---|---|---|---|
M | mercurial/keepalive.py (11 lines) |
import errno | import errno | ||||
import hashlib | import hashlib | ||||
import socket | import socket | ||||
import sys | import sys | ||||
import threading | import threading | ||||
from .i18n import _ | from .i18n import _ | ||||
from . import ( | from . import ( | ||||
pycompat, | |||||
util, | util, | ||||
) | ) | ||||
httplib = util.httplib | httplib = util.httplib | ||||
urlerr = util.urlerr | urlerr = util.urlerr | ||||
urlreq = util.urlreq | urlreq = util.urlreq | ||||
DEBUG = None | DEBUG = None | ||||
DEBUG.info("creating new connection to %s (%d)", | DEBUG.info("creating new connection to %s (%d)", | ||||
host, id(h)) | host, id(h)) | ||||
self._cm.add(host, h, 0) | self._cm.add(host, h, 0) | ||||
self._start_transaction(h, req) | self._start_transaction(h, req) | ||||
r = h.getresponse() | r = h.getresponse() | ||||
# The string form of BadStatusLine is the status line. Add some context | # The string form of BadStatusLine is the status line. Add some context | ||||
# to make the error message slightly more useful. | # to make the error message slightly more useful. | ||||
except httplib.BadStatusLine as err: | except httplib.BadStatusLine as err: | ||||
raise urlerr.urlerror(_('bad HTTP status line: %s') % err.line) | raise urlerr.urlerror( | ||||
_('bad HTTP status line: %s') % pycompat.sysbytes(err.line)) | |||||
except (socket.error, httplib.HTTPException) as err: | except (socket.error, httplib.HTTPException) as err: | ||||
raise urlerr.urlerror(err) | raise urlerr.urlerror(err) | ||||
# if not a persistent connection, don't try to reuse it | # if not a persistent connection, don't try to reuse it | ||||
if r.will_close: | if r.will_close: | ||||
self._cm.remove(h) | self._cm.remove(h) | ||||
if DEBUG: | if DEBUG: | ||||
# the read method wraps the original to accommodate buffering, | # the read method wraps the original to accommodate buffering, | ||||
# although read() never adds to the buffer. | # although read() never adds to the buffer. | ||||
# Both readline and readlines have been stolen with almost no | # Both readline and readlines have been stolen with almost no | ||||
# modification from socket.py | # modification from socket.py | ||||
def __init__(self, sock, debuglevel=0, strict=0, method=None): | def __init__(self, sock, debuglevel=0, strict=0, method=None): | ||||
extrakw = {} | |||||
if not pycompat.ispy3: | |||||
extrakw['strict'] = True | |||||
extrakw['buffering'] = True | |||||
httplib.HTTPResponse.__init__(self, sock, debuglevel=debuglevel, | httplib.HTTPResponse.__init__(self, sock, debuglevel=debuglevel, | ||||
strict=True, method=method, | method=method, **extrakw) | ||||
buffering=True) | |||||
self.fileno = sock.fileno | self.fileno = sock.fileno | ||||
self.code = None | self.code = None | ||||
self._rbuf = '' | self._rbuf = '' | ||||
self._rbufsize = 8096 | self._rbufsize = 8096 | ||||
self._handler = None # inserted by the handler later | self._handler = None # inserted by the handler later | ||||
self._host = None # (same) | self._host = None # (same) | ||||
self._url = None # (same) | self._url = None # (same) | ||||
self._connection = None # (same) | self._connection = None # (same) |