From 07c0b13d4a5bf5a2e46db9b5190d8348a830bfdd Mon Sep 17 00:00:00 2001 From: Mark Bucciarelli Date: Tue, 14 Oct 2003 16:08:58 +0000 Subject: [PATCH] Use m2crypto for SSL if it's installed --- Utility.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/Utility.py b/Utility.py index 1c2a786..5e07651 100755 --- a/Utility.py +++ b/Utility.py @@ -75,7 +75,17 @@ def urlopen(url, timeout=20, redirects=None): if frag: path = '%s#%s' % (path, frag) if scheme == 'https': - conn = TimeoutHTTPS(host, None, timeout) + # If ssl is not compiled into Python, you will not get an exception + # until a conn.endheaders() call. We need to know sooner, so use + # getattr. + if hasattr(socket, 'ssl'): + conn = TimeoutHTTPS(host, None, timeout) + else: + import M2Crypto + ctx = M2Crypto.SSL.Context() + ctx.set_session_timeout(timeout) + conn = M2Crypto.httpslib.HTTPSConnection(host, ssl_context=ctx) + #conn.set_debuglevel(1) else: conn = TimeoutHTTP(host, None, timeout)