Package ClusterShell :: Module NodeSet :: Class RangeSet
[hide private]
[frames] | no frames]

Class RangeSet

source code


Advanced range sets.

RangeSet creation examples:
    rset = RangeSet()            # empty RangeSet
    rset = RangeSet("5,10-42")   # contains 5, 10 to 42
    rset = RangeSet("0-10/2")    # contains 0, 2, 4, 6, 8, 10
 
Also, RangeSet provides methods like update(), intersection_update()
or difference_update(), which conform to the Python Set API.

Instance Methods [hide private]
 
__init__(self, pattern=None, autostep=None)
Initialize RangeSet with optional pdsh-like string pattern and autostep threshold.
source code
 
__iter__(self)
Iterate over each item in RangeSet.
source code
 
__len__(self)
Get the number of items in RangeSet.
source code
 
__str__(self)
Get range-based string.
source code
 
__repr__(self)
Get range-based string.
source code
 
__contains__(self, elem)
Is element contained in RangeSet? Element can be either a string with optional padding (eg.
source code
 
_contains(self, ielem)
Contains subroutine that takes an integer.
source code
 
_contains_with_padding(self, ielem, pad)
Contains subroutine that takes an integer and a padding value.
source code
 
_binary_sanity_check(self, other) source code
 
issubset(self, rangeset)
Report whether another rangeset contains this rangeset.
source code
 
issuperset(self, rangeset)
Report whether this rangeset contains another rangeset.
source code
 
__eq__(self, other)
RangeSet equality comparison.
source code
 
__le__(self, rangeset)
Report whether another rangeset contains this rangeset.
source code
 
__ge__(self, rangeset)
Report whether this rangeset contains another rangeset.
source code
 
__lt__(x, y)
x<y
source code
 
__gt__(x, y)
x>y
source code
 
__getitem__(self, i)
Return the element at index i.
source code
 
__getslice__(self, i, j)
Return the slice from index i to index j-1.
source code
 
split(self, nbr)
Split the rangeset into nbr sub-rangeset.
source code
 
_expand(self)
Expand all items.
source code
 
_fold(self, items, pad)
Fold items as ranges and group them by step.
source code
 
add_range(self, start, stop, step=1, pad=0)
Add a range (start, stop, step and padding length) to RangeSet.
source code
 
_add_range_exfold(self, start, stop, step, pad)
Add range expanding then folding all items.
source code
 
union(self, other)
s.union(t) returns a new rangeset with elements from both s and t.
source code
 
__or__(self, other)
Implements the | operator.
source code
 
add(self, elem)
Add element to RangeSet.
source code
 
update(self, rangeset)
Update a rangeset with the union of itself and another.
source code
 
clear(self)
Remove all ranges from this rangeset.
source code
 
__ior__(self, other)
Implements the |= operator.
source code
 
intersection(self, rangeset)
s.intersection(t) returns a new rangeset with elements common to s and t.
source code
 
__and__(self, other)
Implements the & operator.
source code
 
intersection_update(self, rangeset)
Intersection with provided RangeSet.
source code
 
__iand__(self, other)
Implements the &= operator.
source code
 
_intersect_exfold(self, rangeset)
Calc intersection with the expand/fold method.
source code
 
difference(self, rangeset)
s.difference(t) returns a new rangeset with elements in s but not in t.
source code
 
__sub__(self, other)
Implement the - operator.
source code
 
difference_update(self, rangeset, strict=False)
s.difference_update(t) returns rangeset s after removing elements found in t.
source code
 
__isub__(self, other)
Implement the -= operator.
source code
 
remove(self, elem)
Remove element elem from the RangeSet.
source code
 
_sub_exfold(self, rangeset, strict)
Calc sub/exclusion with the expand/fold method.
source code
 
symmetric_difference(self, other)
s.symmetric_difference(t) returns the symmetric difference of two rangesets as a new RangeSet.
source code
 
__xor__(self, other)
Implement the ^ operator.
source code
 
symmetric_difference_update(self, rangeset)
s.symmetric_difference_update(t) returns rangeset s keeping all elements that are in exactly one of the rangesets.
source code
 
__ixor__(self, other)
Implement the ^= operator.
source code
 
_xor_exfold(self, rangeset)
Calc symmetric difference (xor).
source code
Class Methods [hide private]
 
fromlist(cls, rglist, autostep=None)
Class method that returns a new RangeSet with ranges from provided list.
source code
Method Details [hide private]

__contains__(self, elem)
(In operator)

source code 

Is element contained in RangeSet? Element can be either a string with optional padding (eg. "002") or an integer (obviously, no padding check is performed for integer).

__getslice__(self, i, j)
(Slicling operator)

source code 

Return the slice from index i to index j-1. For convenience only, not optimized as of version 1.0.

split(self, nbr)

source code 

Split the rangeset into nbr sub-rangeset. Each sub-rangeset will have the same number of element more or less 1. Current rangeset remains unmodified. Returns an iterator.

>>> RangeSet("1-5").split(3) 
RangeSet("1-2")
RangeSet("3-4")
RangeSet("foo5")

_expand(self)

source code 

Expand all items. Internal use.

_fold(self, items, pad)

source code 

Fold items as ranges and group them by step. Return: (ranges, total_length)

__or__(self, other)
(Or operator)

source code 

Implements the | operator. So s | t returns a new rangeset with elements from both s and t.

__ior__(self, other)

source code 

Implements the |= operator. So s |= t returns rangeset s with elements added from t. (Python version 2.5+ required)

__and__(self, other)
(And operator)

source code 

Implements the & operator. So s & t returns a new rangeset with elements common to s and t.

__iand__(self, other)

source code 

Implements the &= operator. So s &= t returns rangeset s keeping only elements also found in t. (Python version 2.5+ required)

difference(self, rangeset)

source code 

s.difference(t) returns a new rangeset with elements in s but not in t. in t.

__sub__(self, other)
(Subtraction operator)

source code 

Implement the - operator. So s - t returns a new rangeset with elements in s but not in t.

difference_update(self, rangeset, strict=False)

source code 

s.difference_update(t) returns rangeset s after removing elements found in t. If strict is True, raise KeyError if an element cannot be removed.

__isub__(self, other)

source code 

Implement the -= operator. So s -= t returns rangeset s after removing elements found in t. (Python version 2.5+ required)

remove(self, elem)

source code 

Remove element elem from the RangeSet. Raise KeyError if elem is not contained in the RangeSet.

_sub_exfold(self, rangeset, strict)

source code 

Calc sub/exclusion with the expand/fold method. If strict is True, raise KeyError if the rangeset is not included.

symmetric_difference(self, other)

source code 

s.symmetric_difference(t) returns the symmetric difference of two rangesets as a new RangeSet.

(ie. all elements that are in exactly one of the rangesets.)

__xor__(self, other)
(Exclusive-Or operator)

source code 

Implement the ^ operator. So s ^ t returns a new rangeset with elements that are in exactly one of the rangesets.

__ixor__(self, other)

source code 

Implement the ^= operator. So s ^= t returns rangeset s after keeping all elements that are in exactly one of the rangesets. (Python version 2.5+ required)