From 50bad375f5dd3fbb7c7ea62896e2538dc5734be6 Mon Sep 17 00:00:00 2001 From: Eric Brown Date: Mon, 14 May 2018 20:47:57 -0700 Subject: Future proofing use of the six python version constants (#4238) * Future proofing use of the six python version constants After reading [1], noticed that cryptography uses a lot of if six.PY3 blocks. The issue with this is that whenever Python 4 is released, this code in the else block will be executed even though it was only intended for Python 2. [1] http://astrofrog.github.io/blog/2016/01/12/stop-writing-python-4-incompatible-code/ Signed-off-by: Eric Brown * Use not PY2 instead --- tests/x509/test_x509.py | 6 +++--- tests/x509/test_x509_ext.py | 44 ++++++++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 25 deletions(-) (limited to 'tests') diff --git a/tests/x509/test_x509.py b/tests/x509/test_x509.py index 720db78e..335a0fbf 100644 --- a/tests/x509/test_x509.py +++ b/tests/x509/test_x509.py @@ -1097,7 +1097,7 @@ class TestRSACertificate(object): x509.load_pem_x509_certificate, backend ) - if six.PY3: + if not six.PY2: assert repr(cert) == ( ", value='GT487" @@ -3864,7 +3864,7 @@ class TestNameAttribute(object): def test_repr(self): na = x509.NameAttribute(x509.ObjectIdentifier('2.5.4.3'), u'value') - if six.PY3: + if not six.PY2: assert repr(na) == ( ", value='value')>" @@ -4059,7 +4059,7 @@ class TestName(object): x509.NameAttribute(NameOID.ORGANIZATION_NAME, u'PyCA'), ]) - if six.PY3: + if not six.PY2: assert repr(name) == ( ", value='cryptography.io')>, , value=b'\\x03\\x02\\x01')>" @@ -267,7 +267,7 @@ class TestCertificateIssuer(object): def test_repr(self): ci = x509.CertificateIssuer([x509.DNSName(u"cryptography.io")]) - if six.PY3: + if not six.PY2: assert repr(ci) == ( "])>)>" @@ -403,7 +403,7 @@ class TestNoticeReference(object): def test_repr(self): nr = x509.NoticeReference(u"org", [1, 3, 4]) - if six.PY3: + if not six.PY2: assert repr(nr) == ( "" @@ -447,7 +447,7 @@ class TestUserNotice(object): def test_repr(self): un = x509.UserNotice(x509.NoticeReference(u"org", [1]), u"text") - if six.PY3: + if not six.PY2: assert repr(un) == ( ", explicit_text='text')>" @@ -513,7 +513,7 @@ class TestPolicyInformation(object): def test_repr(self): pq = [u"string", x509.UserNotice(None, u"hi")] pi = x509.PolicyInformation(x509.ObjectIdentifier("1.2.3"), pq) - if six.PY3: + if not six.PY2: assert repr(pi) == ( ", policy_qualifiers=['string', , policy_qualifi" @@ -1003,7 +1003,7 @@ class TestSubjectKeyIdentifier(object): binascii.unhexlify(b"092384932230498bc980aa8098456f6ff7ff3ac9") ) ext = x509.Extension(ExtensionOID.SUBJECT_KEY_IDENTIFIER, False, ski) - if six.PY3: + if not six.PY2: assert repr(ext) == ( ", critical=False, value=, value='value1')>])>)>" @@ -1756,7 +1756,7 @@ class TestDirectoryName(object): class TestRFC822Name(object): def test_repr(self): gn = x509.RFC822Name(u"string") - if six.PY3: + if not six.PY2: assert repr(gn) == "" else: assert repr(gn) == "" @@ -1868,7 +1868,7 @@ class TestUniformResourceIdentifier(object): def test_repr(self): gn = x509.UniformResourceIdentifier(u"string") - if six.PY3: + if not six.PY2: assert repr(gn) == ( "" ) @@ -1962,7 +1962,7 @@ class TestOtherName(object): def test_repr(self): gn = x509.OtherName(x509.ObjectIdentifier("1.2.3.4"), b"derdata") - if six.PY3: + if not six.PY2: assert repr(gn) == ( ", value=b'derdata')>" @@ -1974,7 +1974,7 @@ class TestOtherName(object): ) gn = x509.OtherName(x509.ObjectIdentifier("2.5.4.65"), b"derdata") - if six.PY3: + if not six.PY2: assert repr(gn) == ( ", value=b'derdata')>" @@ -2058,7 +2058,7 @@ class TestGeneralNames(object): x509.DNSName(u"cryptography.io") ] ) - if six.PY3: + if not six.PY2: assert repr(gns) == ( "])>" ) @@ -2136,7 +2136,7 @@ class TestIssuerAlternativeName(object): x509.DNSName(u"cryptography.io") ] ) - if six.PY3: + if not six.PY2: assert repr(san) == ( "])>)>" @@ -2261,7 +2261,7 @@ class TestSubjectAlternativeName(object): x509.DNSName(u"cryptography.io") ] ) - if six.PY3: + if not six.PY2: assert repr(san) == ( "])>)>" @@ -2665,7 +2665,7 @@ class TestAccessDescription(object): AuthorityInformationAccessOID.OCSP, x509.UniformResourceIdentifier(u"http://ocsp.domain.com") ) - if six.PY3: + if not six.PY2: assert repr(ad) == ( ", access_location=, acces" @@ -3266,7 +3266,7 @@ class TestNameConstraints(object): permitted_subtrees=permitted, excluded_subtrees=None ) - if six.PY3: + if not six.PY2: assert repr(nc) == ( ", ], relative" @@ -3947,7 +3947,7 @@ class TestCRLDistributionPoints(object): None ), ]) - if six.PY3: + if not six.PY2: assert repr(cdp) == ( "], relative" -- cgit v1.2.3