Fix Issue 9991: xmlrpc client ssl check faulty

This commit is contained in:
Senthil Kumaran 2010-11-18 15:00:53 +00:00
parent b10089edba
commit 8ce1f1ff83
2 changed files with 26 additions and 1 deletions

View file

@ -149,6 +149,31 @@ class XMLRPCTestCase(unittest.TestCase):
('host.tld',
[('Authorization', 'Basic dXNlcg==')], {}))
def test_ssl_presence(self):
#Check for ssl support
have_ssl = False
if hasattr(socket, 'ssl'):
have_ssl = True
else:
try:
import ssl
except:
pass
else:
have_ssl = True
try:
xmlrpc.client.ServerProxy('https://localhost:9999').bad_function()
except:
exc = sys.exc_info()
if exc[0] == socket.error:
self.assertTrue(have_ssl,
"No SSL support, but xmlrpclib reports supported.")
elif exc[0] == NotImplementedError and str(exc[1]) == \
"your version of http.client doesn't support HTTPS":
self.assertFalse(have_ssl,
"SSL supported, but xmlrpclib reports not.")
else:
self.fail("Unable to determine status of SSL check.")
class HelperTestCase(unittest.TestCase):

View file

@ -1330,7 +1330,7 @@ class SafeTransport(Transport):
if self._connection and host == self._connection[0]:
return self._connection[1]
if not hasattr(socket, "ssl"):
if not hasattr(http.client, "ssl"):
raise NotImplementedError(
"your version of http.client doesn't support HTTPS")
# create a HTTPS connection object from a host descriptor