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

Function _checkPrefix

vrtManager/IPy.py:1213–1242  ·  view source on GitHub ↗

Check the validity of a prefix Checks if the variant part of a prefix only has 0s, and the length is correct. >>> _checkPrefix(0x7f000000L, 24, 4) 1 >>> _checkPrefix(0x7f000001L, 24, 4) 0 >>> repr(_checkPrefix(0x7f000001L, -1, 4)) 'None' >>> repr(_checkPrefix(0x

(ip, prefixlen, version)

Source from the content-addressed store, hash-verified

1211
1212
1213def _checkPrefix(ip, prefixlen, version):
1214 """Check the validity of a prefix
1215
1216 Checks if the variant part of a prefix only has 0s, and the length is
1217 correct.
1218
1219 >>> _checkPrefix(0x7f000000L, 24, 4)
1220 1
1221 >>> _checkPrefix(0x7f000001L, 24, 4)
1222 0
1223 >>> repr(_checkPrefix(0x7f000001L, -1, 4))
1224 'None'
1225 >>> repr(_checkPrefix(0x7f000001L, 33, 4))
1226 'None'
1227 """
1228
1229 # TODO: unify this v4/v6/invalid code in a function
1230 bits = _ipVersionToLen(version)
1231
1232 if prefixlen < 0 or prefixlen > bits:
1233 return None
1234
1235 if ip == 0:
1236 zbits = bits + 1
1237 else:
1238 zbits = _count0Bits(ip)
1239 if zbits < bits - prefixlen:
1240 return 0
1241 else:
1242 return 1
1243
1244
1245def _checkNetmask(netmask, masklen):

Callers

nothing calls this directly

Calls 2

_ipVersionToLenFunction · 0.85
_count0BitsFunction · 0.85

Tested by

no test coverage detected