r46788 - this is what the implementation should look like

glyph-TA+aISz0psMTMxyoc4vAAJOcrHinNvQL0E9HWUfgJXw@public.gmane.org
Newsgroups gmane.comp.python.twisted.commits
Message-ID <[email protected]>
Author: glyph
Date: Sun Feb 14 02:20:37 2016
New Revision: 46788

Modified:
   branches/hostagent-6712/twisted/web/client.py

Log:
this is what the implementation should look like

the tests are somewhat fragile though, so they fail

Modified: branches/hostagent-6712/twisted/web/client.py
==============================================================================
--- branches/hostagent-6712/twisted/web/client.py	(original)
+++ branches/hostagent-6712/twisted/web/client.py	Sun Feb 14 02:20:37 2016
@@ -37,8 +37,10 @@
 from twisted.python.deprecate import getDeprecationWarningString
 from twisted.web import http
 from twisted.internet import defer, protocol, task, reactor
+from twisted.internet.abstract import isIPAddress
 from twisted.internet.interfaces import IProtocol
-from twisted.internet.endpoints import TCP4ClientEndpoint, SSL4ClientEndpoint
+from twisted.internet.endpoints import (
+    TCP4ClientEndpoint, HostnameEndpoint, wrapClientTLS)
 from twisted.python.util import InsensitiveDict
 from twisted.python.components import proxyForInterface
 from twisted.web import error
@@ -1428,12 +1430,13 @@
 
     def endpointForURI(self, uri):
         """
-        Connect directly over TCP for C{b'http'} scheme, and TLS for C{b'https'}.
+        Connect directly over TCP for C{b'http'} scheme, and TLS for
+        C{b'https'}.
 
         @param uri: L{URI} to connect to.
 
         @return: Endpoint to connect to.
-        @rtype: L{TCP4ClientEndpoint} or L{SSL4ClientEndpoint}
+        @rtype: L{IStreamClientEndpoint}
         """
         kwargs = {}
         if self._connectTimeout is not None:
@@ -1447,13 +1450,18 @@
                               "contains non-ASCII octets, it should be ASCII "
                               "decodable.").format(uri=uri))
 
+        if isIPAddress(host):
+            endpoint = TCP4ClientEndpoint(self._reactor, host, uri.port,
+                                          **kwargs)
+        else:
+            endpoint = HostnameEndpoint(self._reactor, host, uri.port,
+                                        **kwargs)
         if uri.scheme == b'http':
-            return TCP4ClientEndpoint(self._reactor, host, uri.port, **kwargs)
+            return endpoint
         elif uri.scheme == b'https':
-            tlsPolicy = self._policyForHTTPS.creatorForNetloc(uri.host,
-                                                              uri.port)
-            return SSL4ClientEndpoint(self._reactor, host, uri.port, tlsPolicy,
-                                      **kwargs)
+            connectionCreator = self._policyForHTTPS.creatorForNetloc(uri.host,
+                                                                      uri.port)
+            return wrapClientTLS(connectionCreator, endpoint)
         else:
             raise SchemeNotSupported("Unsupported scheme: %r" % (uri.scheme,))
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.