Browse Source

Use m2crypto for SSL if it's installed

main
Mark Bucciarelli 21 years ago
parent
commit
07c0b13d4a
1 changed files with 11 additions and 1 deletions
  1. +11
    -1
      Utility.py

+ 11
- 1
Utility.py View File

@@ -75,7 +75,17 @@ def urlopen(url, timeout=20, redirects=None):
if frag: path = '%s#%s' % (path, frag) if frag: path = '%s#%s' % (path, frag)


if scheme == 'https': 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: else:
conn = TimeoutHTTP(host, None, timeout) conn = TimeoutHTTP(host, None, timeout)




Loading…
Cancel
Save