url: make logginghttphandler compatible with Python 2.7.6
authorYuya Nishihara <yuya@tcha.org>
Sat, 24 Mar 2018 13:02:27 +0900
changeset 37100 9e6d3465f17e
parent 37099 6ca5f825a0ca
child 37101 656ac240f392
url: make logginghttphandler compatible with Python 2.7.6 There wasn't a usable hook point in httplib, so we have to replace connect() to wrap the socket before self._tunnel().
mercurial/url.py
--- a/mercurial/url.py	Sat Mar 24 14:24:32 2018 +0900
+++ b/mercurial/url.py	Sat Mar 24 13:02:27 2018 +0900
@@ -12,6 +12,7 @@
 import base64
 import os
 import socket
+import sys
 
 from .i18n import _
 from . import (
@@ -304,6 +305,16 @@
         keepalive.HTTPConnection.__init__(self, *args, **kwargs)
         self._create_connection = createconn
 
+    if sys.version_info < (2, 7, 7):
+        # copied from 2.7.14, since old implementations directly call
+        # socket.create_connection()
+        def connect(self):
+            self.sock = self._create_connection((self.host, self.port),
+                                                self.timeout,
+                                                self.source_address)
+            if self._tunnel_host:
+                self._tunnel()
+
 class logginghttphandler(httphandler):
     """HTTP handler that logs socket I/O."""
     def __init__(self, logfh, name, observeropts):