- # terribly efficient supernet searches (O[32 * log2N]), because we
- # have to potentially do 32 exact matches. If we want efficient
- # supernet searches, we will probably have to use some sort of
- # general (i.e., not binary) search tree datastructure, as there
- # is no sorted ordering that will efficiently give supernets that
- # I can think of.
+ # terribly efficient supernet searches (O[32 * log2N] or O[128 *
+ # log2N] for IPv6), because we have to potentially do 32 (or 128!)
+ # exact matches. If we want efficient supernet searches, we will
+ # probably have to use some sort of general (i.e., not binary)
+ # search tree datastructure, as there is no sorted ordering that
+ # will efficiently give supernets that I can think of.
+
+ # convert a key, value pair into a list of (cidr, value) tuples.
+ # It can be a list with more than one element if key is actually a
+ # netblock.
+ def _conv_key_value(self, key, value):
+ res = []
+ if isinstance(key, Cidr.Cidr):
+ res.append((key, value))
+ return res
+ if self.is_netblock(key):
+ cidrs = self.parse_netblock(key)
+ for c in cidrs:
+ res.append((c, value))
+ else:
+ c = Cidr.valid_cidr(key)
+ res.append((c, value))
+ return res
+
+ # convert a (key, value) tuple into a list of (cidr, value)
+ # tuples.
+ def _conv_tuple(self, tuple):
+ return self._conv_key_value(tuple[0], tuple[1])