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)
| 1283 | |
| 1284 | |
| 1285 | def _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 | |
| 1299 | if __name__ == "__main__": |
no test coverage detected