Patchwork url: drop compatibility wrapper of socket.create_connection()

login
register
mail settings
Submitter Yuya Nishihara
Date Aug. 2, 2016, 1:02 p.m.
Message ID <76f8aecf37ee6a7508a8.1470142942@mimosa>
Download mbox | patch
Permalink /patch/16032/
State Accepted
Headers show

Comments

Yuya Nishihara - Aug. 2, 2016, 1:02 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1468851129 -32400
#      Mon Jul 18 23:12:09 2016 +0900
# Node ID 76f8aecf37ee6a7508a84394b0eb427df9806cd4
# Parent  7eb9ee3e6b148210cb84dace2cb792167238e410
url: drop compatibility wrapper of socket.create_connection()

It should be available on Python 2.6+.
Pierre-Yves David - Aug. 2, 2016, 2:35 p.m.
On 08/02/2016 03:02 PM, Yuya Nishihara wrote:
> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1468851129 -32400
> #      Mon Jul 18 23:12:09 2016 +0900
> # Node ID 76f8aecf37ee6a7508a84394b0eb427df9806cd4
> # Parent  7eb9ee3e6b148210cb84dace2cb792167238e410
> url: drop compatibility wrapper of socket.create_connection()

Pushed, thanks

Patch

diff --git a/mercurial/url.py b/mercurial/url.py
--- a/mercurial/url.py
+++ b/mercurial/url.py
@@ -151,35 +151,6 @@  def _gen_sendfile(orgsend):
     return _sendfile
 
 has_https = util.safehasattr(urlreq, 'httpshandler')
-if has_https:
-    try:
-        _create_connection = socket.create_connection
-    except AttributeError:
-        _GLOBAL_DEFAULT_TIMEOUT = object()
-
-        def _create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
-                               source_address=None):
-            # lifted from Python 2.6
-
-            msg = "getaddrinfo returns an empty list"
-            host, port = address
-            for res in socket.getaddrinfo(host, port, 0, socket.SOCK_STREAM):
-                af, socktype, proto, canonname, sa = res
-                sock = None
-                try:
-                    sock = socket.socket(af, socktype, proto)
-                    if timeout is not _GLOBAL_DEFAULT_TIMEOUT:
-                        sock.settimeout(timeout)
-                    if source_address:
-                        sock.bind(source_address)
-                    sock.connect(sa)
-                    return sock
-
-                except socket.error as msg:
-                    if sock is not None:
-                        sock.close()
-
-            raise socket.error(msg)
 
 class httpconnection(keepalive.HTTPConnection):
     # must be able to send big bundle as stream.
@@ -337,7 +308,7 @@  if has_https:
             self.cert_file = cert_file
 
         def connect(self):
-            self.sock = _create_connection((self.host, self.port))
+            self.sock = socket.create_connection((self.host, self.port))
 
             host = self.host
             if self.realhostport: # use CONNECT proxy