From: Martin Date: Fri, 14 Jul 2017 18:36:54 +0000 (+0200) Subject: py3: maketrans: use rather if statement X-Git-Tag: v1.16.0~34^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2844d249dc4709e8c7b9e9a2fc1a503548e1515b;p=thirdparty%2Fdnspython.git py3: maketrans: use rather if statement If statement is faster and it makes clear intention that difference is due PY2 and PY3 --- diff --git a/dns/rdtypes/ANY/NSEC3.py b/dns/rdtypes/ANY/NSEC3.py index 2e722de2..93d26918 100644 --- a/dns/rdtypes/ANY/NSEC3.py +++ b/dns/rdtypes/ANY/NSEC3.py @@ -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