Fix uses of retired builtins and builtin methods

In Python 3.x

- int and long types are unified. The unified type is called int.
- the text string type (unicode) is renamed to str.
- the byte string type (str) is renamed to bytes.
- chr returns a text string (i.e. str)
- xrange is renamed to range.
- dict.has_key() is removed
-
This commit is contained in:
Alex Willmer 2019-05-10 21:28:35 +01:00
parent 0f3cadcc3e
commit 287f71d561
4 changed files with 33 additions and 20 deletions

View file

@ -26,7 +26,7 @@ import hammer as h
def act_bsfdig(p, user_data=None):
# FIXME See the note in init_parser()
c = p if isinstance(p, (int, long)) else ord(p)
c = p if isinstance(p, h.INTEGER_TYPES) else ord(p)
if 0x41 <= c <= 0x5A: # A-Z
return c - 0x41
@ -65,14 +65,14 @@ def act_base64_n(n, p, user_data=None):
x = 0
bits = 0
for i in xrange(0, n+1):
for i in range(0, n+1):
x <<= 6
x |= p[i] or 0
bits += 6
x >>= bits % 8 # align, i.e. cut off extra bits
for i in xrange(n):
for i in range(n):
item = x & 0xFF
res[n-1-i] = item # output the last byte and

View file

@ -28,7 +28,7 @@ import hammer as h
def bsfdig_value(p):
"""Return the numeric value of a parsed base64 digit.
"""
c = p if isinstance(p, (int, long)) else ord(p)
c = p if isinstance(p, h.INTEGER_TYPES) else ord(p)
if c:
if 0x41 <= c <= 0x5A: # A-Z
return c - 0x41