summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorMatěj Cepl <mcepl@cepl.eu>2015-11-18 18:43:13 +0100
committerMatěj Cepl <mcepl@cepl.eu>2015-11-19 18:11:30 +0100
commitecbeca2b75502b49119d713ac38f2b5ddb97fcd8 (patch)
treea6d20cbc3efc316bc08127d54b2a233f301950d8 /contrib
parentef45a18ebcb2d1d1f53410defff8b0713aad6598 (diff)
downloadm2crypto-ecbeca2b75502b49119d713ac38f2b5ddb97fcd8.tar.gz
I mean, compatibility with python < 2.0 or similar ... really?
Diffstat (limited to 'contrib')
-rw-r--r--contrib/isaac.httpslib.py161
-rw-r--r--contrib/smimeplus.py11
2 files changed, 68 insertions, 104 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):