arjuna.tpi.helper.extract module¶
- class arjuna.tpi.helper.extract.Extractor(*, strict=True, target_types)¶
Bases:
object
Abstract class for extractors. Given an object, a concrete implementation extracts objects from the given object.
- Keyword Arguments
strict – The extractors can choose what strict mode means for them and related behavior. For strict mode, in certain situations, exception is raised by an exractor.
Note
In strict mode, Exception is raised if the target object is empty (returns bool(obj) is False)
- extract(obj)¶
Extracts objects from the given object as per concrete Extractor implementations.
- Parameters
obj – Extraction target.
- property is_strict¶
Bool property that indicates whether this extractor is in strict mode or not.
- class arjuna.tpi.helper.extract.pos¶
Bases:
object
Factory Class with various factory methods to create objects for a single position and multiple positions.
- classmethod at(*pos, strict: bool = True)¶
Create Extractor object to extract objects at one or more positions from tuple/list.
- Parameters
pos – (int) Arbitrary positions in a sequence
- Keyword Arguments
strict – If True, exception is raised if no element is found at provided position.
- classmethod even(strict: bool = True)¶
Create Extractor object to extract objects at even positions from given tuple/list.
- Keyword Arguments
strict – If True, exception is raised if extracted sequence is empty.
- classmethod first(strict: bool = True)¶
Create Extractor object to extract objects at first position from tuple/list.
- Keyword Arguments
strict – If True, exception is raised if no element is found at provided position.
- classmethod last(strict: bool = True)¶
Create Extractor object to extract objects at last position from tuple/list.
- Keyword Arguments
strict – If True, exception is raised if no element is found at provided position.
- classmethod odd(strict: bool = True)¶
Create Extractor object to extract objects at odd positions from given tuple/list.
- Keyword Arguments
strict – If True, exception is raised if extracted sequence is empty.
- classmethod random(count=1, strict: bool = True)¶
Create Extractor object to extract objects at random position(s) fom tuple/list.
- Parameters
count – Number of unique random positions to be used.
- Keyword Arguments
strict – If True, exception is raised if input sequence is empty or number of random samples requested > length of sequence.
- classmethod slice(*vargs, strict: bool = True, **kwargs)¶
Create Extractor object to extract a slice of the provided tuple/list.
- Parameters
*vargs – (int) 1,2,or 3 arguments are accepted. See Notes.
- Keyword Arguments
kwargs – One or more of start/stop/step passed as keyword argument.
strict – If True, exception is raised if extracted sequence is empty.
Note
Following is the meaning of 1,2,3 arg signatures:
slice(stop) slice(start, stop) slice(start, stop, step)
You can also use the keyword arguments instead of positional arguments:
slice(stop=4) slice(start=2, stop=4) slice(start=2, stop=7, step=2)
You can not mix these styles of calling. Either use vargs or kwargs, else an Exception is raised.