diff options
-rw-r--r-- | contrib/isaac.httpslib.py | 161 | ||||
-rw-r--r-- | contrib/smimeplus.py | 11 | ||||
-rw-r--r-- | demo/Zope/z2s.py | 31 | ||||
-rw-r--r-- | tests/test_authcookie.py | 4 |
4 files changed, 74 insertions, 133 deletions
diff --git a/contrib/isaac.httpslib.py b/contrib/isaac.httpslib.py index 1415e4f..e09e633 100644 --- a/contrib/isaac.httpslib.py +++ b/contrib/isaac.httpslib.py @@ -1,111 +1,78 @@ from __future__ import print_function -"""M2Crypto support for Python 1.5.2 and Python 2.x's httplib. +"""M2Crypto support for Python 2.x's httplib. Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.""" -import string, sys -from httplib import * -import SSL - -if sys.version[0] == '2': - - if sys.version[:3] in ['2.1', '2.2']: - # In 2.1 and above, httplib exports "HTTP" only. - from httplib import HTTPConnection, HTTPS_PORT - # ISS Added: - from httplib import HTTPResponse,FakeSocket - - class HTTPSConnection(HTTPConnection): - - """ - This class allows communication via SSL using M2Crypto. - """ - - default_port = HTTPS_PORT - - def __init__(self, host, port=None, **ssl): - keys = ssl.keys() - try: - keys.remove('key_file') - except ValueError: - pass - try: - keys.remove('cert_file') - except ValueError: - pass - try: - keys.remove('ssl_context') - except ValueError: - pass - if keys: - raise IllegalKeywordArgument() - try: - self.ssl_ctx = ssl['ssl_context'] - assert isinstance(self.ssl_ctx, SSL.Context) - except KeyError: - self.ssl_ctx = SSL.Context('sslv23') - HTTPConnection.__init__(self, host, port) - - def connect(self): - self.sock = SSL.Connection(self.ssl_ctx) - self.sock.connect((self.host, self.port)) - - def close(self): - # This kludges around line 545 of httplib.py, - # which closes the connection in this object; - # the connection remains open in the response - # object. - # - # M2Crypto doesn't close-here-keep-open-there, - # so, in effect, we don't close until the whole - # business is over and gc kicks in. - # - # Long-running callers beware leakage. - # - # 05-Jan-2002: This module works with Python 2.2, - # but I've not investigated if the above conditions - # remain. - pass +import string +import SSL - class HTTPS(HTTP): - - _connection_class = HTTPSConnection +from httplib import FakeSocket, HTTP, HTTPConnection, HTTPResponse, HTTPS_PORT - def __init__(self, host='', port=None, **ssl): - HTTP.__init__(self, host, port) - try: - self.ssl_ctx = ssl['ssl_context'] - except KeyError: - self.ssl_ctx = SSL.Context('sslv23') +class HTTPSConnection(HTTPConnection): -elif sys.version[:3] == '1.5': + """ + This class allows communication via SSL using M2Crypto. + """ - class HTTPS(HTTP): + default_port = HTTPS_PORT - def __init__(self, ssl_context, host='', port=None): - assert isinstance(ssl_context, SSL.Context) - self.debuglevel=0 - self.file=None - self.ssl_ctx=ssl_context - if host: - self.connect(host, port) + def __init__(self, host, port=None, **ssl): + keys = ssl.keys() + try: + keys.remove('key_file') + except ValueError: + pass + try: + keys.remove('cert_file') + except ValueError: + pass + try: + keys.remove('ssl_context') + except ValueError: + pass + if keys: + raise ValueError() + try: + self.ssl_ctx = ssl['ssl_context'] + assert isinstance(self.ssl_ctx, SSL.Context) + except KeyError: + self.ssl_ctx = SSL.Context('sslv23') + HTTPConnection.__init__(self, host, port) - def connect(self, host, port=None): - # Cribbed from httplib.HTTP. - if not port: - i = string.find(host, ':') - if i >= 0: - host, port = host[:i], host[i+1:] - try: port = string.atoi(port) - except string.atoi_error: - raise socket.error("nonnumeric port") - if not port: port = HTTPS_PORT - self.sock = SSL.Connection(self.ssl_ctx) - if self.debuglevel > 0: print('connect:', (host, port)) - self.sock.connect((host, port)) + def connect(self): + self.sock = SSL.Connection(self.ssl_ctx) + self.sock.connect((self.host, self.port)) + + def close(self): + # This kludges around line 545 of httplib.py, + # which closes the connection in this object; + # the connection remains open in the response + # object. + # + # M2Crypto doesn't close-here-keep-open-there, + # so, in effect, we don't close until the whole + # business is over and gc kicks in. + # + # Long-running callers beware leakage. + # + # 05-Jan-2002: This module works with Python 2.2, + # but I've not investigated if the above conditions + # remain. + pass + +class HTTPS(HTTP): + + _connection_class = HTTPSConnection + + def __init__(self, host='', port=None, **ssl): + HTTP.__init__(self, host, port) + try: + self.ssl_ctx = ssl['ssl_context'] + except KeyError: + self.ssl_ctx = SSL.Context('sslv23') # ISS Added. # From here, starts the proxy patch @@ -209,8 +176,8 @@ class HTTPSProxyConnection(HTTPProxyConnection): def __init__(self, proxy, host, port=None, username=None, password=None, **x509): for key in x509.keys(): - if key not in ['cert_file', 'key_file','ssl_context']: - raise IllegalKeywordArgument() + if key not in ['cert_file', 'key_file', 'ssl_context']: + raise ValueError() self.key_file = x509.get('key_file') self.cert_file = x509.get('cert_file') #ISS Added diff --git a/contrib/smimeplus.py b/contrib/smimeplus.py index 2cb7fd7..00ab038 100644 --- a/contrib/smimeplus.py +++ b/contrib/smimeplus.py @@ -1,13 +1,10 @@ -import sys, os, tempfile import UserDict -from email import Message +import os +import tempfile + import M2Crypto -if not (sys.version_info[0] >= 2 and sys.version_info[1] >= 2): - class object: - pass - True=1 - False=0 +from email import Message class smimeplus(object): diff --git a/demo/Zope/z2s.py b/demo/Zope/z2s.py index 5ee9474..18b00cd 100644 --- a/demo/Zope/z2s.py +++ b/demo/Zope/z2s.py @@ -408,32 +408,11 @@ def server_info(old, v, offset=0): try: - python_version = sys.version.split()[0] - if python_version < '2.1': - raise 'Invalid python version', python_version - if python_version[:3] == '2.1': - if python_version[4:5] < '3': - import warnings - err = ('You are running Python version %s. This Python version ' - 'has known bugs that may cause Zope to run improperly. ' - 'Consider upgrading to a Python in the 2.1 series ' - 'with at least version number 2.1.3. (Note that Zope does ' - 'not yet run under any Python 2.2 version).' % - python_version) - warnings.warn(err) - if python_version[:3] == '2.2': - import warnings - err = ('You are running Python version %s. This Python version ' - 'has not yet been tested with Zope and you may experience ' - 'operational problems as a result. Consider using ' - 'Python 2.1.3 instead.' % python_version) - warnings.warn(err) - - - opts, args = getopt.getopt(sys.argv[1:], - 'hz:Z:t:i:a:d:u:w:W:y:Y:x:f:p:m:Sl:2DP:rF:L:XM:C', - ['icp=', 'force-http-connection-close' - ]) + opts, args = getopt.getopt( + sys.argv[1:], + 'hz:Z:t:i:a:d:u:w:W:y:Y:x:f:p:m:Sl:2DP:rF:L:XM:C', + ['icp=', 'force-http-connection-close' + ]) DEBUG=0 READ_ONLY=0 diff --git a/tests/test_authcookie.py b/tests/test_authcookie.py index e5c00ce..88c92e1 100644 --- a/tests/test_authcookie.py +++ b/tests/test_authcookie.py @@ -4,7 +4,7 @@ Copyright (c) 1999-2002 Ng Pheng Siong. All rights reserved.""" -import Cookie, binascii, time, sys +import Cookie, binascii, time try: import unittest2 as unittest except ImportError: @@ -16,8 +16,6 @@ from M2Crypto import Rand, EVP class AuthCookieTestCase(unittest.TestCase): _format = 'Set-Cookie: _M2AUTH_="exp=%s&data=%s&digest=%s"' - if sys.version_info < (2,5): - _format += ';' _token = '_M2AUTH_' def setUp(self): |