Package netaddr :: Package ip :: Module sets :: Class IPSet |
[hide private]
[frames] | no frames]

# Class IPSet

    object --+
             |
            IPSet

Represents an unordered collection (set) of unique IP addresses and subnets.

Instance Methods | [hide private]
__init__(self, iterable=None) Constructor. |
compact(self) Compact internal list of IPNetwork objects using a CIDR merge. |
__hash__(self) Please Note: IPSet objects are not hashable and cannot be used as dictionary keys or as members of other sets. |
__contains__(self, ip) Returns: `True` if IP address or subnet is a member of this IP set. |
__iter__(self) Returns: an iterator over the IP addresses within this IP set. |
iter_cidrs(self) Returns: an iterator over individual IP subnets within this IP set. |
add(self, ip) Adds an IP address or subnet to this IP set. |
remove(self, ip) Removes an IP address or subnet from this IP set. |
pop(self) Removes and returns an arbitrary IP address or subnet from this IP set. |
isdisjoint(self, other) Returns: `True` if this IP set has no elements (IP addresses or subnets) in common with other. |
copy(self) Returns: a shallow copy of this IP set. |
update(self, iterable) Update the contents of this IP set with the union of itself and other IP set. |
clear(self) Remove all IP addresses and subnets from this IP set. |
__eq__(self, other) Returns: `True` if this IP set is equivalent to the `other` IP set, `False` otherwise. |
__ne__(self, other) Returns: `False` if this IP set is equivalent to the `other` IP set, `True` otherwise. |
__lt__(self, other) Returns: `True` if this IP set is less than the `other` IP set, `False` otherwise. |
issubset(self, other) Returns: `True` if every IP address and subnet in this IP set is found within `other`. |
__le__(self, other) Returns: `True` if every IP address and subnet in this IP set is found within `other`. |
__gt__(self, other) Returns: `True` if this IP set is greater than the `other` IP set, `False` otherwise. |
issuperset(self, other) Returns: `True` if every IP address and subnet in other IP set is found within this one. |
__ge__(self, other) Returns: `True` if every IP address and subnet in other IP set is found within this one. |
union(self, other) Returns: the union of this IP set and another as a new IP set (combines IP addresses and subnets from both sets). |
__or__(self, other) Returns: the union of this IP set and another as a new IP set (combines IP addresses and subnets from both sets). |
intersection(self, other) Returns: the intersection of this IP set and another as a new IP set. |
__and__(self, other) Returns: the intersection of this IP set and another as a new IP set. |
symmetric_difference(self, other) Returns: the symmetric difference of this IP set and another as a new IP set (all IP addresses and subnets that are in exactly one of the sets). |
__xor__(self, other) Returns: the symmetric difference of this IP set and another as a new IP set (all IP addresses and subnets that are in exactly one of the sets). |
difference(self, other) Returns: the difference between this IP set and another as a new IP set (all IP addresses and subnets that are in this IP set but not found in the other.) |
__sub__(self, other) Returns: the difference between this IP set and another as a new IP set (all IP addresses and subnets that are in this IP set but not found in the other.) |
__len__(self) Returns: the cardinality of this IP set (i.e. |
__repr__(self) Returns: Python statement to create an equivalent object |
__str__(self) Returns: Python statement to create an equivalent object |
Inherited from `object`: `__delattr__`, `__getattribute__`, `__new__`, `__reduce__`, `__reduce_ex__`, `__setattr__`

Properties | [hide private]
| size The cardinality of this IP set (based on the number of individual IP addresses including those implicitly defined in subnets).
Inherited from `object`: `__class__`

Method Details | [hide private]

### __init__(self, iterable=None) (Constructor) |
Constructor. Parameters: `iterable` - (optional) an iterable containing IP addresses and subnets. Overrides: object.__init__

### __hash__(self) (Hashing function) |
Please Note: IPSet objects are not hashable and cannot be used as dictionary keys or as members of other sets. Raises `TypeError` if this method is called. Overrides: object.__hash__

### __contains__(self, ip) (In operator) |
Parameters: `ip` - An IP address or subnet. Returns: `True` if IP address or subnet is a member of this IP set.

### __iter__(self) |
Returns: an iterator over the IP addresses within this IP set.

### iter_cidrs(self) |
Returns: an iterator over individual IP subnets within this IP set.

### add(self, ip) |
Adds an IP address or subnet to this IP set. Has no effect if it is already present. Note that where possible the IP address or subnet is merged with other members of the set to form more concise CIDR blocks. Parameters: `ip` - An IP address or subnet.

### remove(self, ip) |
Removes an IP address or subnet from this IP set. Does nothing if it is not already a member. Note that this method behaves more like discard() found in regular Python sets because it doesn't raise KeyError exceptions if the IP address or subnet is question does not exist. It doesn't make sense to fully emulate that behaviour here as IP sets contain groups of individual IP addresses as individual set members using IPNetwork objects. Parameters: `ip` - An IP address or subnet.

### pop(self) |
Removes and returns an arbitrary IP address or subnet from this IP set. Returns: An IP address or subnet.

### isdisjoint(self, other) |
Parameters: `other` - an IP set. Returns: `True` if this IP set has no elements (IP addresses or subnets) in common with other. Intersection *must* be an empty set.

### copy(self) |
Returns: a shallow copy of this IP set.

### update(self, iterable) |
Update the contents of this IP set with the union of itself and other IP set. Parameters: `iterable` - an iterable containing IP addresses and subnets.

### __eq__(self, other) (Equality operator) |
Parameters: `other` - an IP set Returns: `True` if this IP set is equivalent to the `other` IP set, `False` otherwise.

### __ne__(self, other) |
Parameters: `other` - an IP set Returns: `False` if this IP set is equivalent to the `other` IP set, `True` otherwise.

### __lt__(self, other) (Less-than operator) |
Parameters: `other` - an IP set Returns: `True` if this IP set is less than the `other` IP set, `False` otherwise.

### issubset(self, other) |
Parameters: `other` - an IP set. Returns: `True` if every IP address and subnet in this IP set is found within `other`.

### __le__(self, other) (Less-than-or-equals operator) |
Parameters: `other` - an IP set. Returns: `True` if every IP address and subnet in this IP set is found within `other`.

### __gt__(self, other) (Greater-than operator) |
Parameters: `other` - an IP set. Returns: `True` if this IP set is greater than the `other` IP set, `False` otherwise.

### issuperset(self, other) |
Parameters: `other` - an IP set. Returns: `True` if every IP address and subnet in other IP set is found within this one.

### __ge__(self, other) (Greater-than-or-equals operator) |
Parameters: `other` - an IP set. Returns: `True` if every IP address and subnet in other IP set is found within this one.

### union(self, other) |
Parameters: `other` - an IP set. Returns: the union of this IP set and another as a new IP set (combines IP addresses and subnets from both sets).

### __or__(self, other) (Or operator) |
Parameters: `other` - an IP set. Returns: the union of this IP set and another as a new IP set (combines IP addresses and subnets from both sets).

### intersection(self, other) |
Parameters: `other` - an IP set. Returns: the intersection of this IP set and another as a new IP set. (IP addresses and subnets common to both sets).

### __and__(self, other) (And operator) |
Parameters: `other` - an IP set. Returns: the intersection of this IP set and another as a new IP set. (IP addresses and subnets common to both sets).

### symmetric_difference(self, other) |
Parameters: `other` - an IP set. Returns: the symmetric difference of this IP set and another as a new IP set (all IP addresses and subnets that are in exactly one of the sets).

### __xor__(self, other) (Exclusive-Or operator) |
Parameters: `other` - an IP set. Returns: the symmetric difference of this IP set and another as a new IP set (all IP addresses and subnets that are in exactly one of the sets).

### difference(self, other) |
Parameters: `other` - an IP set. Returns: the difference between this IP set and another as a new IP set (all IP addresses and subnets that are in this IP set but not found in the other.)

### __sub__(self, other) (Subtraction operator) |
Parameters: `other` - an IP set. Returns: the difference between this IP set and another as a new IP set (all IP addresses and subnets that are in this IP set but not found in the other.)

### __len__(self) (Length operator) |
Returns: the cardinality of this IP set (i.e. sum of individual IP addresses). Raises `IndexError` if size > sys.maxint (a Python limitation). Use the .size property for subnets of any size.

### __repr__(self) (Representation operator) |
str(x) Returns: Python statement to create an equivalent object Overrides: object.__repr__

### __str__(self) (Informal representation operator) |
str(x) Returns: Python statement to create an equivalent object Overrides: object.__str__

Property Details | [hide private]

### size The cardinality of this IP set (based on the number of individual IP addresses including those implicitly defined in subnets). Get Method: unreachable.size(self) - The cardinality of this IP set (based on the number of individual IP addresses including those implicitly defined in subnets).