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:
parent
0f3cadcc3e
commit
287f71d561
4 changed files with 33 additions and 20 deletions
|
|
@ -26,7 +26,7 @@ import hammer as h
|
||||||
|
|
||||||
def act_bsfdig(p, user_data=None):
|
def act_bsfdig(p, user_data=None):
|
||||||
# FIXME See the note in init_parser()
|
# 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
|
if 0x41 <= c <= 0x5A: # A-Z
|
||||||
return c - 0x41
|
return c - 0x41
|
||||||
|
|
@ -65,14 +65,14 @@ def act_base64_n(n, p, user_data=None):
|
||||||
|
|
||||||
x = 0
|
x = 0
|
||||||
bits = 0
|
bits = 0
|
||||||
for i in xrange(0, n+1):
|
for i in range(0, n+1):
|
||||||
x <<= 6
|
x <<= 6
|
||||||
x |= p[i] or 0
|
x |= p[i] or 0
|
||||||
bits += 6
|
bits += 6
|
||||||
|
|
||||||
x >>= bits % 8 # align, i.e. cut off extra bits
|
x >>= bits % 8 # align, i.e. cut off extra bits
|
||||||
|
|
||||||
for i in xrange(n):
|
for i in range(n):
|
||||||
item = x & 0xFF
|
item = x & 0xFF
|
||||||
|
|
||||||
res[n-1-i] = item # output the last byte and
|
res[n-1-i] = item # output the last byte and
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ import hammer as h
|
||||||
def bsfdig_value(p):
|
def bsfdig_value(p):
|
||||||
"""Return the numeric value of a parsed base64 digit.
|
"""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 c:
|
||||||
if 0x41 <= c <= 0x5A: # A-Z
|
if 0x41 <= c <= 0x5A: # A-Z
|
||||||
return c - 0x41
|
return c - 0x41
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,20 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
%pythoncode %{
|
%pythoncode %{
|
||||||
|
try:
|
||||||
|
INTEGER_TYPES = (int, long)
|
||||||
|
except NameError:
|
||||||
|
INTEGER_TYPES = (int,)
|
||||||
|
|
||||||
|
try:
|
||||||
|
TEXT_TYPE = unicode
|
||||||
|
def bchr(i):
|
||||||
|
return chr(i)
|
||||||
|
except NameError:
|
||||||
|
TEXT_TYPE = str
|
||||||
|
def bchr(i):
|
||||||
|
return bytes([i])
|
||||||
|
|
||||||
class Placeholder(object):
|
class Placeholder(object):
|
||||||
"""The python equivalent of TT_NONE"""
|
"""The python equivalent of TT_NONE"""
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
@ -250,36 +264,35 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
%pythoncode %{
|
%pythoncode %{
|
||||||
|
|
||||||
def action(p, act):
|
def action(p, act):
|
||||||
return _h_action(p, act)
|
return _h_action(p, act)
|
||||||
def attr_bool(p, pred):
|
def attr_bool(p, pred):
|
||||||
return _h_attr_bool(p, pred)
|
return _h_attr_bool(p, pred)
|
||||||
|
|
||||||
def ch(ch):
|
def ch(ch):
|
||||||
if isinstance(ch, str) or isinstance(ch, unicode):
|
if isinstance(ch, (bytes, TEXT_TYPE)):
|
||||||
return token(ch)
|
return token(ch)
|
||||||
else:
|
else:
|
||||||
return _h_ch(ch)
|
return _h_ch(ch)
|
||||||
|
|
||||||
def ch_range(c1, c2):
|
def ch_range(c1, c2):
|
||||||
dostr = isinstance(c1, str)
|
dostr = isinstance(c1, bytes)
|
||||||
dostr2 = isinstance(c2, str)
|
dostr2 = isinstance(c2, bytes)
|
||||||
if isinstance(c1, unicode) or isinstance(c2, unicode):
|
if isinstance(c1, TEXT_TYPE) or isinstance(c2, TEXT_TYPE):
|
||||||
raise TypeError("ch_range only works on bytes")
|
raise TypeError("ch_range only works on bytes")
|
||||||
if dostr != dostr2:
|
if dostr != dostr2:
|
||||||
raise TypeError("Both arguments to ch_range must be the same type")
|
raise TypeError("Both arguments to ch_range must be the same type")
|
||||||
if dostr:
|
if dostr:
|
||||||
return action(_h_ch_range(c1, c2), chr)
|
return action(_h_ch_range(c1, c2), bchr)
|
||||||
else:
|
else:
|
||||||
return _h_ch_range(c1, c2)
|
return _h_ch_range(c1, c2)
|
||||||
def epsilon_p(): return _h_epsilon_p()
|
def epsilon_p(): return _h_epsilon_p()
|
||||||
def end_p():
|
def end_p():
|
||||||
return _h_end_p()
|
return _h_end_p()
|
||||||
def in_(charset):
|
def in_(charset):
|
||||||
return action(_h_in(charset), chr)
|
return action(_h_in(charset), bchr)
|
||||||
def not_in(charset):
|
def not_in(charset):
|
||||||
return action(_h_not_in(charset), chr)
|
return action(_h_not_in(charset), bchr)
|
||||||
def not_(p): return _h_not(p)
|
def not_(p): return _h_not(p)
|
||||||
def int_range(p, i1, i2):
|
def int_range(p, i1, i2):
|
||||||
return _h_int_range(p, i1, i2)
|
return _h_int_range(p, i1, i2)
|
||||||
|
|
|
||||||
|
|
@ -205,7 +205,7 @@ def AddToModPaths(env, files, **kw):
|
||||||
|
|
||||||
def cscFlags(target, source, env, for_signature):
|
def cscFlags(target, source, env, for_signature):
|
||||||
listCmd = []
|
listCmd = []
|
||||||
if (env.has_key('WINEXE')):
|
if ('WINEXE' in env):
|
||||||
if (env['WINEXE'] == 1):
|
if (env['WINEXE'] == 1):
|
||||||
listCmd.append('-t:winexe')
|
listCmd.append('-t:winexe')
|
||||||
return listCmd
|
return listCmd
|
||||||
|
|
@ -245,7 +245,7 @@ def cscSourcesNoResources(target, source, env, for_signature):
|
||||||
def cscRefs(target, source, env, for_signature):
|
def cscRefs(target, source, env, for_signature):
|
||||||
listCmd = []
|
listCmd = []
|
||||||
|
|
||||||
if (env.has_key('ASSEMBLYREFS')):
|
if ('ASSEMBLYREFS' in env):
|
||||||
refs = SCons.Util.flatten(env['ASSEMBLYREFS'])
|
refs = SCons.Util.flatten(env['ASSEMBLYREFS'])
|
||||||
for ref in refs:
|
for ref in refs:
|
||||||
if SCons.Util.is_String(ref):
|
if SCons.Util.is_String(ref):
|
||||||
|
|
@ -258,7 +258,7 @@ def cscRefs(target, source, env, for_signature):
|
||||||
def cscMods(target, source, env, for_signature):
|
def cscMods(target, source, env, for_signature):
|
||||||
listCmd = []
|
listCmd = []
|
||||||
|
|
||||||
if (env.has_key('NETMODULES')):
|
if ('NETMODULES' in env):
|
||||||
mods = SCons.Util.flatten(env['NETMODULES'])
|
mods = SCons.Util.flatten(env['NETMODULES'])
|
||||||
for mod in mods:
|
for mod in mods:
|
||||||
listCmd.append('-addmodule:%s' % mod)
|
listCmd.append('-addmodule:%s' % mod)
|
||||||
|
|
@ -276,7 +276,7 @@ def alLinkSources(target, source, env, for_signature):
|
||||||
# just treat this as a generic unidentified source file
|
# just treat this as a generic unidentified source file
|
||||||
listCmd.append('-link:%s' % s.get_string(for_signature))
|
listCmd.append('-link:%s' % s.get_string(for_signature))
|
||||||
|
|
||||||
if env.has_key('VERSION'):
|
if 'VERSION' in env:
|
||||||
version = parseVersion(env)
|
version = parseVersion(env)
|
||||||
listCmd.append('-version:%d.%d.%d.%d' % version)
|
listCmd.append('-version:%d.%d.%d.%d' % version)
|
||||||
|
|
||||||
|
|
@ -298,7 +298,7 @@ def cliLinkSources(target, source, env, for_signature):
|
||||||
return listCmd
|
return listCmd
|
||||||
|
|
||||||
def add_version(target, source, env):
|
def add_version(target, source, env):
|
||||||
if env.has_key('VERSION'):
|
if 'VERSION' in env:
|
||||||
if SCons.Util.is_String(target[0]):
|
if SCons.Util.is_String(target[0]):
|
||||||
versionfile = target[0] + '_VersionInfo.cs'
|
versionfile = target[0] + '_VersionInfo.cs'
|
||||||
else:
|
else:
|
||||||
|
|
@ -321,14 +321,14 @@ def lib_emitter(target, source, env):
|
||||||
def add_depends(target, source, env):
|
def add_depends(target, source, env):
|
||||||
"""Add dependency information before the build order is established"""
|
"""Add dependency information before the build order is established"""
|
||||||
|
|
||||||
if (env.has_key('NETMODULES')):
|
if ('NETMODULES' in env):
|
||||||
mods = SCons.Util.flatten(env['NETMODULES'])
|
mods = SCons.Util.flatten(env['NETMODULES'])
|
||||||
for mod in mods:
|
for mod in mods:
|
||||||
# add as dependency
|
# add as dependency
|
||||||
for t in target:
|
for t in target:
|
||||||
env.Depends(t, mod)
|
env.Depends(t, mod)
|
||||||
|
|
||||||
if (env.has_key('ASSEMBLYREFS')):
|
if ('ASSEMBLYREFS' in env):
|
||||||
refs = SCons.Util.flatten(env['ASSEMBLYREFS'])
|
refs = SCons.Util.flatten(env['ASSEMBLYREFS'])
|
||||||
for ref in refs:
|
for ref in refs:
|
||||||
# add as dependency
|
# add as dependency
|
||||||
|
|
@ -419,7 +419,7 @@ res_action = SCons.Action.Action('$CLIRCCOM', '$CLIRCCOMSTR')
|
||||||
|
|
||||||
def res_emitter(target, source, env):
|
def res_emitter(target, source, env):
|
||||||
# prepend NAMESPACE if provided
|
# prepend NAMESPACE if provided
|
||||||
if (env.has_key('NAMESPACE')):
|
if ('NAMESPACE' in env):
|
||||||
newtargets = []
|
newtargets = []
|
||||||
for t in target:
|
for t in target:
|
||||||
tname = t.name
|
tname = t.name
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue