[PATCH] url: make logginghttphandler compatible with Python 2.7.6

Yuya Nishihara yuya at tcha.org
Sat Mar 24 04:09:06 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1521864147 -32400
#      Sat Mar 24 13:02:27 2018 +0900
# Node ID f40b6e7fc011715b209774c0d1fbc5b8a6694401
# Parent  db114320df7ee744047fe9a92a01afc40f9d0e87
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().

diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -12,6 +12,7 @@ from __future__ import absolute_import
 import base64
 import os
 import socket
+import sys
 
 from .i18n import _
 from . import (
@@ -304,6 +305,16 @@ class logginghttpconnection(keepalive.HT
         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):


More information about the Mercurial-devel mailing list