コード例 #1
0
ファイル: sets.py プロジェクト: drkjam/netaddr
    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()
コード例 #2
0
ファイル: sets.py プロジェクト: 571451370/devstack_mitaka
    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()
コード例 #3
0
ファイル: sets.py プロジェクト: embr/nonce
    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()
コード例 #4
0
ファイル: test_compat.py プロジェクト: sc68cal/netaddr
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)]
コード例 #5
0
ファイル: test_compat.py プロジェクト: drkjam/netaddr
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)]