Implement our own left-shift operator to shut up python 2.3 warnings.

Apparently left-shift in python 2.3 just *always* prints a warning, even if
we weren't doing anything wrong.  Or maybe it only prints the warning
sometimes.  Anyway, let's just multiply by 2**x instead of using <<x, since
we're not performance-sensitive anyway.
This commit is contained in:
Avery Pennarun 2010-10-01 14:46:34 -07:00
parent c403a83ab8
commit b0f061e204

View File

@ -40,6 +40,10 @@ def _maskbits(netmask):
if netmask[0] & (1<<i):
return 32-i
return 0
def _shl(n, bits):
return n * int(2**bits)
def _list_routes():
@ -54,7 +58,7 @@ def _list_routes():
maskw = _ipmatch(cols[2]) # linux only
mask = _maskbits(maskw) # returns 32 if maskw is null
width = min(ipw[1], mask)
ip = ipw[0] & (((1<<width)-1) << (32-width))
ip = ipw[0] & _shl(_shl(1, width) - 1, 32-width)
routes.append((socket.inet_ntoa(struct.pack('!I', ip)), width))
rv = p.wait()
if rv != 0: