l = self._conv_key_value(i.key, i.value)
res_list.append(l)
+ # flatten the list of lists of tuples to just a list of tuples
+ res_list = [ x for y in res_list for x in y ]
MemIndex.addlist(self, res_list)
return
if not isinstance(other, type(self)): return False
return self.key == other.key and self.value == other.value
-if __name__ == "__main__":
-
- source = [ ("foo", "foo-id"), ("bar", "bar-id"), ("baz", "baz-id"),
- ("foobar", "foo-id-2"), ("barnone", "bar-id-2"),
- ("zygnax", "z-id") ]
-
- mi = MemIndex()
- mi.addlist(source)
-
- print "finding foobar:"
- res = mi.find("foobar")
- print res
-
- print "finding foo*:"
- res = mi.find("foo", 1)
- print res
-
- print "finding baz:"
- res = mi.find("baz")
- print res
-
- print "adding bork"
- mi.add("bork", "bork-id")
-
- print "finding b*:"
- res = mi.find("b", 1)
- print res
-
- ci = CidrMemIndex()
-
- ci.add("127.0.0.1/24", "net-local-1");
- ci.add("127.0.0.1/32", "net-local-2");
- ci.add(Cidr.new("216.168.224.0", 22), "net-vrsn-1")
- ci.add(Cidr.new("216.168.252.1", 32), "net-vrsn-2")
- ci.add("24.36.191.0/24", "net-foo-c")
- ci.add("24.36.191.32/27", "net-foo-sub-c")
- ci.add("24.36/16", "net-foo-b")
- ci.add("3ffe:4:5::0/48", "net-foo-d6")
- ci.add("3ffe:4:5:6::0/64", "net-foo-e6")
- ci.add("48.12.6.0 - 48.12.6.95", "net-bar-1")
-
- print "finding exactly 127.0.0.0/24"
- res = ci.find(Cidr.new("127.0.0.0/24"))
- print res
-
- print "finding exactly 127.0.0.16/32"
- res = ci.find(Cidr.new("127.0.0.16/32"))
- print res
-
- print "finding exactly 3ffe:4:5:6::0/64"
- res = ci.find(Cidr.valid_cidr("3ffe:4:5:6::/64"))
- print res
-
- print "finding supernets of 127.0.0.16/32"
- res = ci.find_supernets(Cidr.new("127.0.0.16/32"))
- print res
-
- print "finding supernets of 24.36.191.32/27"
- res = ci.find(Cidr.new("24.36.191.32/27"), 1)
- print res
-
- print "finding supernets of 24.36.191.33/27"
- res = ci.find_supernets(Cidr.new("24.36.191.33/27"))
- print res
-
- print "finding supernets of 24.36.191.64/27"
- res = ci.find_supernets(Cidr.new("24.36.191.64/27"))
- print res
-
- print "finding supernets of 3ffe:4:5:6:7::0/80"
- res = ci.find_supernets(Cidr.valid_cidr("3ffe:4:5:6:7::0/80"))
- print res
-
- print "finding supernets of 48.12.6.90"
- res = ci.find_supernets(Cidr.valid_cidr("48.12.6.90"))
- print res
-
- print "finding subnets of 127.0/16"
- res = ci.find_subnets(Cidr.new("127.0/16"))
- print res
-
- print "finding subnets of 3ffe:4::0/32"
- res = ci.find_subnets(Cidr.valid_cidr("3ffe:4::0/32"))
- print res
-
- print "finding subnets of 48.12.0.0/16"
- res = ci.find_subnets(Cidr.valid_cidr("48.12.0.0/16"))
- print res