def update(self, iterable, flags=0): """ Update the contents of this IP set with the union of itself and other IP set. :param iterable: an iterable containing IP addresses and subnets. :param flags: decides which rules are applied to the interpretation of the addr value. See the netaddr.core namespace documentation for supported constant values. """ if isinstance(iterable, IPSet): self._cidrs = dict.fromkeys( (ip for ip in cidr_merge(_dict_keys(self._cidrs) + _dict_keys(iterable._cidrs))), True) return elif isinstance(iterable, (IPNetwork, IPRange)): self.add(iterable) return if not hasattr(iterable, '__iter__'): raise TypeError('an iterable was expected!') # An iterable containing IP addresses or subnets. mergeable = [] for addr in iterable: if isinstance(addr, _int_type): addr = IPAddress(addr, flags=flags) mergeable.append(addr) for cidr in cidr_merge(_dict_keys(self._cidrs) + mergeable): self._cidrs[cidr] = True self.compact()
def update(self, iterable, flags=0): """ Update the contents of this IP set with the union of itself and other IP set. :param iterable: an iterable containing IP addresses and subnets. :param flags: decides which rules are applied to the interpretation of the addr value. See the netaddr.core namespace documentation for supported constant values. """ if isinstance(iterable, IPSet): self._cidrs = dict.fromkeys((ip for ip in cidr_merge( _dict_keys(self._cidrs) + _dict_keys(iterable._cidrs))), True) return elif isinstance(iterable, (IPNetwork, IPRange)): self.add(iterable) return if not hasattr(iterable, '__iter__'): raise TypeError('an iterable was expected!') # An iterable containing IP addresses or subnets. mergeable = [] for addr in iterable: if isinstance(addr, _int_type): addr = IPAddress(addr, flags=flags) mergeable.append(addr) for cidr in cidr_merge(_dict_keys(self._cidrs) + mergeable): self._cidrs[cidr] = True self.compact()
def update(self, iterable, flags=0): """ Update the contents of this IP set with the union of itself and other IP set. :param iterable: an iterable containing IP addresses and subnets. :param flags: decides which rules are applied to the interpretation of the addr value. See the netaddr.core namespace documentation for supported constant values. """ if not hasattr(iterable, "__iter__"): raise TypeError("an iterable was expected!") if hasattr(iterable, "_cidrs"): # Another IP set. for ip in cidr_merge(_dict_keys(self._cidrs) + _dict_keys(iterable._cidrs)): self._cidrs[ip] = True else: # An iterable contain IP addresses or subnets. mergeable = [] for addr in iterable: if isinstance(addr, _int_type): addr = IPAddress(addr, flags=flags) mergeable.append(addr) for cidr in cidr_merge(_dict_keys(self._cidrs) + mergeable): self._cidrs[cidr] = True self.compact()
def test_compat_dict_operations(): d = {'a': 0, 'b': 1, 'c': 2} assert sorted(_dict_keys(d)) == ['a', 'b', 'c'] assert sorted(_dict_items(d)) == [('a', 0), ('b', 1), ('c', 2)]
def test_compat_dict_operations(): d = { 'a' : 0, 'b' : 1, 'c' : 2 } assert sorted(_dict_keys(d)) == ['a', 'b', 'c'] assert sorted(_dict_items(d)) == [('a', 0), ('b', 1), ('c', 2)]