summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHugo van Kemenade <hugovk@users.noreply.github.com>2019-08-30 00:39:35 +0300
committerAlex Gaynor <alex.gaynor@gmail.com>2019-08-29 17:39:35 -0400
commit60827f82d2ad7d2a94db093c2836595b46937c07 (patch)
tree45b1fbfe4a349858490d499fad72bc57abe002a2
parenta18137385f574603535b29ad935f496d307ab3ae (diff)
downloadpyopenssl-60827f82d2ad7d2a94db093c2836595b46937c07.tar.gz
Fix for Python 4 (#862)
* Fix for Python 4 * Fix for Python 4
-rw-r--r--src/OpenSSL/_util.py16
-rw-r--r--tests/test_ssl.py6
-rw-r--r--tests/util.py8
3 files changed, 15 insertions, 15 deletions
diff --git a/src/OpenSSL/_util.py b/src/OpenSSL/_util.py
index cf8b888..cdcacc8 100644
--- a/src/OpenSSL/_util.py
+++ b/src/OpenSSL/_util.py
@@ -1,7 +1,7 @@
import sys
import warnings
-from six import PY3, binary_type, text_type
+from six import PY2, binary_type, text_type
from cryptography.hazmat.bindings.openssl.binding import Binding
@@ -81,12 +81,12 @@ def native(s):
"""
if not isinstance(s, (binary_type, text_type)):
raise TypeError("%r is neither bytes nor unicode" % s)
- if PY3:
- if isinstance(s, binary_type):
- return s.decode("utf-8")
- else:
+ if PY2:
if isinstance(s, text_type):
return s.encode("utf-8")
+ else:
+ if isinstance(s, binary_type):
+ return s.decode("utf-8")
return s
@@ -107,12 +107,12 @@ def path_string(s):
raise TypeError("Path must be represented as bytes or unicode string")
-if PY3:
+if PY2:
def byte_string(s):
- return s.encode("charmap")
+ return s
else:
def byte_string(s):
- return s
+ return s.encode("charmap")
# A marker object to observe whether some optional arguments are passed any
diff --git a/tests/test_ssl.py b/tests/test_ssl.py
index 7704c72..6b9422c 100644
--- a/tests/test_ssl.py
+++ b/tests/test_ssl.py
@@ -25,7 +25,7 @@ import pytest
from pretend import raiser
-from six import PY3, text_type
+from six import PY2, text_type
from cryptography import x509
from cryptography.hazmat.backends import default_backend
@@ -101,7 +101,7 @@ V7H54LmltOT/hEh6QWsJqb6BQgH65bswvV/XkYGja8/T0GzvbaVzAgEC
"""
-skip_if_py3 = pytest.mark.skipif(PY3, reason="Python 2 only")
+skip_if_py3 = pytest.mark.skipif(not PY2, reason="Python 2 only")
def socket_any_family():
@@ -2138,7 +2138,7 @@ class TestConnection(object):
with pytest.raises(TypeError):
conn.set_tlsext_host_name(b"with\0null")
- if PY3:
+ if not PY2:
# On Python 3.x, don't accidentally implicitly convert from text.
with pytest.raises(TypeError):
conn.set_tlsext_host_name(b"example.com".decode("ascii"))
diff --git a/tests/util.py b/tests/util.py
index 4464379..65b905a 100644
--- a/tests/util.py
+++ b/tests/util.py
@@ -6,7 +6,7 @@ Helpers for the OpenSSL test suite, largely copied from
U{Twisted<http://twistedmatrix.com/>}.
"""
-from six import PY3
+from six import PY2
# This is the UTF-8 encoding of the SNOWMAN unicode code point.
@@ -152,7 +152,7 @@ class EqualityTestsMixin(object):
# The type name expected in warnings about using the wrong string type.
-if PY3:
- WARNING_TYPE_EXPECTED = "str"
-else:
+if PY2:
WARNING_TYPE_EXPECTED = "unicode"
+else:
+ WARNING_TYPE_EXPECTED = "str"