本文整理汇总了Python中IPy._intToBin方法的典型用法代码示例。如果您正苦于以下问题:Python IPy._intToBin方法的具体用法?Python IPy._intToBin怎么用?Python IPy._intToBin使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IPy
的用法示例。
在下文中一共展示了IPy._intToBin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testKnownValues
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import _intToBin [as 别名]
def testKnownValues(self):
"""conversion of known values values should give known results"""
for x in self.knownValues:
(question, answer) = x
result = IPy._intToBin(question)
self.assertEqual(answer, result, str(question))
示例2: testMisc
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import _intToBin [as 别名]
def testMisc(self):
ip = IPy.IP("195.114.80/24")
self.assertEqual(ip.int(), 3279048704L)
self.assertEqual(ip.reverseName(), "80.114.195.in-addr.arpa.")
self.assertEqual(ip.strBin(), "11000011011100100101000000000000")
self.assertEqual(str(ip.net()), "195.114.80.0")
self.assertEqual(str(ip), "195.114.80.0/24")
self.assertEqual(ip.prefixlen(), 24)
self.assertEqual(ip.version(), 4)
self.assertEqual(ip.len(), 256)
self.assertEqual(IPy._intToBin(ip.netmask().int()), "11111111111111111111111100000000")
self.assertEqual(ip.strNetmask(), "255.255.255.0")
self.assertEqual(ip.iptype(), "PUBLIC")
self.assertEqual(ip.broadcast().strBin(), "11000011011100100101000011111111")
self.assertEqual(str(ip.broadcast()), "195.114.80.255")
ip = IPy.IP("202.31.4/24")
self.assertEqual(str(ip.net()), "202.31.4.0")
self.failUnlessRaises(ValueError, IPy.IP, "234.245.252.253/2")
# because we ar using integer representation we don't need a special "binadd"
ip = IPy.IP("62.33.41.9")
ip2 = IPy.IP("0.1.0.5")
self.assertEqual(str(IPy.IP(ip.int() + ip2.int())), "62.34.41.14")
# $T->ok_eq ($ip->binadd($ip2)->ip(),'62.34.41.14',$ip->error());
ip = IPy.IP("133.45.0/24")
ip2 = IPy.IP("133.45.1/24")
self.assertEqual((ip + ip2).prefixlen(), 23)
ip2 = IPy.IP("133.44.255.255")
# $T->ok_eqnum ($ip->bincomp('gt',$ip2),1,$ip->error());
# this is something we can't do with IPy
# ip = IPy.IP('133.44.255.255-133.45.0.42');
# $T->ok_eq (($ip->find_prefixes())[3],'133.45.0.40/31',$ip->error());
ip = IPy.IP("201.33.128.0/22")
ip2 = IPy.IP("201.33.129.0/24")
# $T->ok_eqnum ($ip->overlaps($ip2),$IP_B_IN_A_OVERLAP,$ip->error());
ip = IPy.IP("dead:beef:0::/48")
self.assertEqual(str(ip.net()), "dead:beef::")
self.assertEqual(ip.int(), 295990755014133383690938178081940045824L)
self.assertEqual(
ip.strBin(),
"11011110101011011011111011101111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
)
self.assertEqual(ip.strCompressed(), "dead:beef::/48")
self.assertEqual(ip.prefixlen(), 48)
self.assertEqual(ip.version(), 6)
self.assertEqual(ip.strNetmask(), "/48")
self.assertEqual(str(ip.netmask()), "ffff:ffff:ffff::")
self.assertEqual(ip.iptype(), "UNASSIGNED")
self.assertEqual(ip.reverseName(), "0.0.0.0.f.e.e.b.d.a.e.d.ip6.arpa.")
self.assertEqual(str(ip.broadcast()), "dead:beef:0:ffff:ffff:ffff:ffff:ffff")
ip = IPy.IP("202.31.4/24")
self.assertEqual(str(ip.net()), "202.31.4.0")
# TODO: fix this in IPy ... after rereading the RfC
# ip = IPy.IP(':1/128');
# $T->ok_eq ($ip->error(),'Invalid address :1 (starts with :)',$ip->error());
# $T->ok_eqnum ($ip->errno(),109,$ip->error());
ip = IPy.IP("ff00:0:f000::")
ip2 = IPy.IP("0:0:1000::")
self.assertEqual(IPy.IP(ip.int() + ip2.int()).strCompressed(), "ff00:1::")
ip = IPy.IP("::e000:0/112")
ip2 = IPy.IP("::e001:0/112")
self.assertEqual(ip.__add__(ip2).prefixlen(), 111)
ip2 = IPy.IP("::dfff:ffff")
# $T->ok_eqnum ($ip->bincomp('gt',$ip2),1,$ip->error());
# ip = IPy.IP('::e000:0 - ::e002:42')
# $T->ok_eq (($ip->find_prefixes())[2],'0000:0000:0000:0000:0000:0000:e002:0040/127',$ip->error());
ip = IPy.IP("ffff::/16")
ip2 = IPy.IP("8000::/16")
示例3: testMisc
# 需要导入模块: import IPy [as 别名]
# 或者: from IPy import _intToBin [as 别名]
def testMisc(self):
ip = IPy.IP('195.114.80/24')
self.assertEqual(ip.int(), 3279048704)
self.assertEqual(ip.reverseName(),'80.114.195.in-addr.arpa.')
self.assertEqual(ip.strBin(),'11000011011100100101000000000000')
self.assertEqual(str(ip.net()),'195.114.80.0')
self.assertEqual(str(ip),'195.114.80.0/24')
self.assertEqual(ip.prefixlen(),24)
self.assertEqual(ip.version(),4)
self.assertEqual(ip.len(),256)
self.assertEqual(IPy._intToBin(ip.netmask().int()),'11111111111111111111111100000000')
self.assertEqual(ip.strNetmask(),'255.255.255.0')
self.assertEqual(ip.iptype(), 'PUBLIC')
self.assertEqual(ip.broadcast().strBin(),'11000011011100100101000011111111')
self.assertEqual(str(ip.broadcast()),'195.114.80.255')
ip = IPy.IP('202.31.4/24')
self.assertEqual(str(ip.net()),'202.31.4.0')
self.assertRaises(ValueError, IPy.IP, '234.245.252.253/2')
# because we ar using integer representation we don't need a special "binadd"
ip = IPy.IP('62.33.41.9')
ip2 = IPy.IP('0.1.0.5')
self.assertEqual(str(IPy.IP(ip.int() + ip2.int())),'62.34.41.14')
#$T->ok_eq ($ip->binadd($ip2)->ip(),'62.34.41.14',$ip->error());
ip = IPy.IP('133.45.0/24')
ip2 = IPy.IP('133.45.1/24')
ip3 = IPy.IP('133.45.2/24')
self.assertEqual((ip + ip2).prefixlen(),23)
# Non-adjacent ranges
self.assertRaises(ValueError, IPy.IP.__add__, ip, ip3)
# Resulting invalid prefix
self.assertRaises(ValueError, IPy.IP.__add__, ip2, ip3)
ip2 = IPy.IP('133.44.255.255');
#$T->ok_eqnum ($ip->bincomp('gt',$ip2),1,$ip->error());
# this is something we can't do with IPy
#ip = IPy.IP('133.44.255.255-133.45.0.42');
#$T->ok_eq (($ip->find_prefixes())[3],'133.45.0.40/31',$ip->error());
ip = IPy.IP('201.33.128.0/22');
ip2 = IPy.IP('201.33.129.0/24');
#$T->ok_eqnum ($ip->overlaps($ip2),$IP_B_IN_A_OVERLAP,$ip->error());
ip = IPy.IP('dead:beef:0::/48')
self.assertEqual(str(ip.net()),'dead:beef::')
self.assertEqual(ip.int(), 295990755014133383690938178081940045824)
self.assertEqual(ip.strBin(),'11011110101011011011111011101111000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000')
self.assertEqual(ip.strCompressed(),'dead:beef::/48')
self.assertEqual(ip.prefixlen(), 48)
self.assertEqual(ip.version(), 6)
self.assertEqual(ip.strNetmask(),'/48')
self.assertEqual(str(ip.netmask()),'ffff:ffff:ffff::')
self.assertEqual(ip.iptype(),'RESERVED')
self.assertEqual(ip.reverseName(),'0.0.0.0.f.e.e.b.d.a.e.d.ip6.arpa.')
self.assertEqual(str(ip.broadcast()),'dead:beef:0:ffff:ffff:ffff:ffff:ffff')
ip = IPy.IP('202.31.4/24')
self.assertEqual(str(ip.net()),'202.31.4.0')
# TODO: fix this in IPy ... after rereading the RfC
# ip = IPy.IP(':1/128');
#$T->ok_eq ($ip->error(),'Invalid address :1 (starts with :)',$ip->error());
#$T->ok_eqnum ($ip->errno(),109,$ip->error());
ip = IPy.IP('ff00:0:f000::')
ip2 = IPy.IP('0:0:1000::')
self.assertEqual(IPy.IP(ip.int() + ip2.int()).strCompressed(), 'ff00:1::')
ip = IPy.IP('::e000:0/112')
ip2 = IPy.IP('::e001:0/112')
self.assertEqual(ip.__add__(ip2).prefixlen(),111)
self.assertEqual(ip.__add__(ip2).version(),6)
ip2 = IPy.IP('::dfff:ffff')
#$T->ok_eqnum ($ip->bincomp('gt',$ip2),1,$ip->error());
#ip = IPy.IP('::e000:0 - ::e002:42')
#$T->ok_eq (($ip->find_prefixes())[2],'0000:0000:0000:0000:0000:0000:e002:0040/127',$ip->error());
ip = IPy.IP('ffff::/16')
ip2 = IPy.IP('8000::/16')