MCPcopy Index your code
hub / github.com/retspen/webvirtcloud / _prefixlenToNetmask

Function _prefixlenToNetmask

vrtManager/IPy.py:1285–1296  ·  view source on GitHub ↗

Return a mask of n bits as a long integer. From 'IP address conversion functions with the builtin socket module' by Alex Martelli http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66517

(prefixlen, version)

Source from the content-addressed store, hash-verified

1283
1284
1285def _prefixlenToNetmask(prefixlen, version):
1286 """Return a mask of n bits as a long integer.
1287
1288 From 'IP address conversion functions with the builtin socket module'
1289 by Alex Martelli
1290 http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66517
1291 """
1292 if prefixlen == 0:
1293 return 0
1294 elif prefixlen < 0:
1295 raise ValueError, "Prefixlen must be > 0"
1296 return ((2L << prefixlen - 1) - 1) << (_ipVersionToLen(version) - prefixlen)
1297
1298
1299if __name__ == "__main__":

Callers 2

__init__Method · 0.85

Calls 1

_ipVersionToLenFunction · 0.85

Tested by

no test coverage detected