summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAvery Pennarun <apenwarr@gmail.com>2010-10-01 14:46:34 -0700
committerAvery Pennarun <apenwarr@gmail.com>2010-10-01 14:46:34 -0700
commitb0f061e2049fe5badde4ea7f01eaa18ae178733f (patch)
treef74e1182bbc9db9b73d15311b8033500a3754ade
parentc403a83ab83c36df6938d3b4cb883999b49f5eec (diff)
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.
-rw-r--r--server.py6
1 files changed, 5 insertions, 1 deletions
diff --git a/server.py b/server.py
index ad2d21d..31cd6c4 100644
--- a/server.py
+++ b/server.py
@@ -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: