]> git.ipfire.org Git - thirdparty/dnspython.git/commitdiff
py3: maketrans: use rather if statement
authorMartin <martin.basti@gmail.com>
Fri, 14 Jul 2017 18:36:54 +0000 (20:36 +0200)
committerMartin <martin.basti@gmail.com>
Fri, 14 Jul 2017 21:03:37 +0000 (23:03 +0200)
If statement is faster and it makes clear intention that difference is
due PY2 and PY3

dns/rdtypes/ANY/NSEC3.py

index 2e722de2a4965417cfd40395e19cd3e7a2465f96..93d269184ab650fee1367d9b7a4dee597a7d5270 100644 (file)
@@ -17,6 +17,7 @@ import base64
 import binascii
 import string
 import struct
+import sys
 
 import dns.exception
 import dns.rdata
@@ -24,18 +25,19 @@ import dns.rdatatype
 from dns._compat import xrange, text_type
 
 # pylint: disable=deprecated-string-function
-try:
-    b32_hex_to_normal = string.maketrans('0123456789ABCDEFGHIJKLMNOPQRSTUV',
-                                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
-    b32_normal_to_hex = string.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
-                                         '0123456789ABCDEFGHIJKLMNOPQRSTUV')
-except AttributeError:
+if sys.version_info > (3,):
     b32_hex_to_normal = bytes.maketrans(b'0123456789ABCDEFGHIJKLMNOPQRSTUV',
                                         b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
     b32_normal_to_hex = bytes.maketrans(b'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
                                         b'0123456789ABCDEFGHIJKLMNOPQRSTUV')
+else:
+    b32_hex_to_normal = string.maketrans('0123456789ABCDEFGHIJKLMNOPQRSTUV',
+                                         'ABCDEFGHIJKLMNOPQRSTUVWXYZ234567')
+    b32_normal_to_hex = string.maketrans('ABCDEFGHIJKLMNOPQRSTUVWXYZ234567',
+                                         '0123456789ABCDEFGHIJKLMNOPQRSTUV')
 # pylint: enable=deprecated-string-function
 
+
 # hash algorithm constants
 SHA1 = 1