summaryrefslogtreecommitdiff
path: root/OpenSSL
diff options
context:
space:
mode:
authorAbraham Martin <amc203@cam.ac.uk>2015-03-25 13:56:25 +0000
committerAbraham Martin <amc203@cam.ac.uk>2015-03-25 13:56:25 +0000
commitd2f0b078b06696ec74ee43f92b82e5ea05173026 (patch)
tree4a21d355404dd7e50b075a61f2b5deeccf5fd7e9 /OpenSSL
parent82efe3e6db46c0924b5b2d6e0793a62bd48e7dcc (diff)
downloadpyopenssl-d2f0b078b06696ec74ee43f92b82e5ea05173026.tar.gz
Use six library to check python version
Diffstat (limited to 'OpenSSL')
-rw-r--r--OpenSSL/SSL.py27
-rw-r--r--OpenSSL/crypto.py26
2 files changed, 19 insertions, 34 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py
index 8972097..eb26e76 100644
--- a/OpenSSL/SSL.py
+++ b/OpenSSL/SSL.py
@@ -1,5 +1,6 @@
+import six
from warnings import warn
-from sys import platform, version_info
+from sys import platform
from functools import wraps, partial
from itertools import count
from weakref import WeakValueDictionary
@@ -314,12 +315,10 @@ class Context(object):
# Backward compatibility
if isinstance(cafile, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in cafile is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in cafile is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in cafile is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in cafile is no longer accepted, use bytes", DeprecationWarning)
cafile = cafile.encode('utf-8')
if cafile is None:
@@ -985,12 +984,10 @@ class Connection(object):
# Backward compatibility
if isinstance(buf, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in buf is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in buf is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in buf is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in buf is no longer accepted, use bytes", DeprecationWarning)
buf = buf.encode('utf-8')
if isinstance(buf, _memoryview):
@@ -1020,12 +1017,10 @@ class Connection(object):
# Backward compatibility
if isinstance(buf, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in buf is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in buf is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in buf is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in buf is no longer accepted, use bytes", DeprecationWarning)
buf = buf.encode('utf-8')
if isinstance(buf, _memoryview):
@@ -1116,12 +1111,10 @@ class Connection(object):
# Backward compatibility
if isinstance(buf, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in buf is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in vuf is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in buf is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in buf is no longer accepted, use bytes", DeprecationWarning)
buf = buf.encode("ascii")
if self._into_ssl is None:
diff --git a/OpenSSL/crypto.py b/OpenSSL/crypto.py
index b671d9e..cc99105 100644
--- a/OpenSSL/crypto.py
+++ b/OpenSSL/crypto.py
@@ -1,5 +1,5 @@
+import six
from warnings import warn
-from sys import version_info
from time import time
from base64 import b16encode
from functools import partial
@@ -1957,12 +1957,10 @@ class PKCS12(object):
# Backward compatibility
if isinstance(passphrase, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in passphrase is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in passphrase is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
passphrase = passphrase.encode('utf-8')
if self._cacerts is None:
@@ -2265,12 +2263,10 @@ def sign(pkey, data, digest):
# Backward compatibility
if isinstance(data, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in passphrase is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in passphrase is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
data = data.encode('utf-8')
digest_obj = _lib.EVP_get_digestbyname(_byte_string(digest))
@@ -2310,12 +2306,10 @@ def verify(cert, signature, data, digest):
# Backward compatibility
if isinstance(data, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in passphrase is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in passphrase is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
data = data.encode('utf-8')
digest_obj = _lib.EVP_get_digestbyname(_byte_string(digest))
@@ -2412,12 +2406,10 @@ def load_pkcs12(buffer, passphrase=None):
# Backward compatibility
if isinstance(passphrase, _text_type):
- if version_info.major == 2:
+ if six.PY2:
warn("unicode in passphrase is no longer accepted, use bytes", DeprecationWarning)
- elif version_info.major == 3:
- warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
else:
- warn("text in passphrase is no longer accepted, use bytes", DeprecationWarning)
+ warn("str in passphrase is no longer accepted, use bytes", DeprecationWarning)
passphrase = passphrase.encode('utf-8')
if isinstance(buffer, _text_type):