diff options
author | Avery Pennarun <apenwarr@gmail.com> | 2010-10-01 14:46:34 -0700 |
---|---|---|
committer | Avery Pennarun <apenwarr@gmail.com> | 2010-10-01 14:46:34 -0700 |
commit | b0f061e2049fe5badde4ea7f01eaa18ae178733f (patch) | |
tree | f74e1182bbc9db9b73d15311b8033500a3754ade | |
parent | c403a83ab83c36df6938d3b4cb883999b49f5eec (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.py | 6 |
1 files changed, 5 insertions, 1 deletions
@@ -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: |