summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Paul Calderone <exarkun@twistedmatrix.com>2013-12-30 08:35:49 -0500
committerJean-Paul Calderone <exarkun@twistedmatrix.com>2013-12-30 08:35:49 -0500
commit8fb5318f2c9ec550452b22269884992b45b6b987 (patch)
tree1533303604a59872b7a1a3f1e1ac9703c3ed11fa
parenta9f84ad2c19b213dfb57fdaa5133658b0a4ff853 (diff)
downloadpyopenssl-8fb5318f2c9ec550452b22269884992b45b6b987.tar.gz
Python 2.6 compatibility
-rw-r--r--OpenSSL/SSL.py11
-rw-r--r--OpenSSL/test/util.py23
2 files changed, 32 insertions, 2 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index f1c1d68..a35c299 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -14,6 +14,13 @@ from OpenSSL.crypto import (
_unspecified = object()
+try:
+ _memoryview = memoryview
+except NameError:
+ class _memoryview(object):
+ pass
+
+
OPENSSL_VERSION_NUMBER = _lib.OPENSSL_VERSION_NUMBER
SSLEAY_VERSION = _lib.SSLEAY_VERSION
SSLEAY_CFLAGS = _lib.SSLEAY_CFLAGS
@@ -906,7 +913,7 @@ class Connection(object):
API, the value is ignored
:return: The number of bytes written
"""
- if isinstance(buf, memoryview):
+ if isinstance(buf, _memoryview):
buf = buf.tobytes()
if not isinstance(buf, bytes):
raise TypeError("data must be a byte string")
@@ -930,7 +937,7 @@ class Connection(object):
API, the value is ignored
:return: The number of bytes written
"""
- if isinstance(buf, memoryview):
+ if isinstance(buf, _memoryview):
buf = buf.tobytes()
if not isinstance(buf, bytes):
raise TypeError("buf must be a byte string")
diff --git a/OpenSSL/test/util.py b/OpenSSL/test/util.py
index a1a0cd9..b58a0f2 100644
--- a/OpenSSL/test/util.py
+++ b/OpenSSL/test/util.py
@@ -175,6 +175,29 @@ class TestCase(TestCase):
self.fail("Left over errors in OpenSSL error queue: " + repr(e))
+ def assertIsInstance(self, instance, classOrTuple, message=None):
+ """
+ Fail if C{instance} is not an instance of the given class or of
+ one of the given classes.
+
+ @param instance: the object to test the type (first argument of the
+ C{isinstance} call).
+ @type instance: any.
+ @param classOrTuple: the class or classes to test against (second
+ argument of the C{isinstance} call).
+ @type classOrTuple: class, type, or tuple.
+
+ @param message: Custom text to include in the exception text if the
+ assertion fails.
+ """
+ if not isinstance(instance, classOrTuple):
+ if message is None:
+ suffix = ""
+ else:
+ suffix = ": " + message
+ self.fail("%r is not an instance of %s%s" % (
+ instance, classOrTuple, suffix))
+
def failUnlessIn(self, containee, container, msg=None):
"""