tensorbay.client.lazy¶
Lazy evaluation related classes.
- class tensorbay.client.lazy.LazyItem(page: tensorbay.client.lazy.LazyPage[tensorbay.client.lazy._T], data: tensorbay.client.lazy._T)[source]¶
Bases:
Generic
[tensorbay.client.lazy._T
]In paging lazy evaluation system, a LazyItem instance represents an element in a pagination.
If user wants to access the elememt, LazyItem will trigger the paging request to pull a page of elements and return the required element. All the pulled elements will be stored in different LazyItem instances and will not be requested again.
- Parameters
page – The page the item belongs to.
- data¶
The actual element stored in this item.
- classmethod from_page(page: tensorbay.client.lazy.LazyPage[tensorbay.client.lazy._T]) tensorbay.client.lazy.LazyItem[tensorbay.client.lazy._T] [source]¶
Create a LazyItem instance from page.
- Parameters
page – The page of the element.
- Returns
The LazyItem instance which stores the input page.
- classmethod from_data(data: tensorbay.client.lazy._T) tensorbay.client.lazy.LazyItem[tensorbay.client.lazy._T] [source]¶
Create a LazyItem instance from data.
- Parameters
data – The actual data needs to be stored in LazyItem.
- Returns
The LazyItem instance which stores the input data.
- get() tensorbay.client.lazy._T [source]¶
Access the actual element represented by LazyItem.
If the element is already pulled from web, it will be return directly, otherwise this function will request for a page of elements to get the required elememt.
- Returns
The actual element this LazyItem instance represents.
- class tensorbay.client.lazy.ReturnGenerator(generator: Generator[tensorbay.client.lazy._T, Any, tensorbay.client.lazy._R])[source]¶
Bases:
Generic
[tensorbay.client.lazy._T
,tensorbay.client.lazy._R
]ReturnGenerator is a generator wrap to get the return value easily.
- Parameters
generator – The generator needs to be wrapped.
- value¶
The return value of the input generator.
- Type
tensorbay.client.lazy._R
- class tensorbay.client.lazy.LazyPage(offset: int, limit: int, func: Callable[[int, int], Generator[tensorbay.client.lazy._T, None, int]])[source]¶
Bases:
Generic
[tensorbay.client.lazy._T
]In paging lazy evaluation system, a LazyPage instance represents a page with elements.
LazyPage is used for sending paging request to pull a page of elements and storing them in different
LazyItem
instances.- Parameters
offset – The offset of the page.
limit – The limit of the page.
func – A paging generator function, which takes offset<int> and limit<int> as inputs and returns a generator. The returned generator should yield the element user needs, and return the total count of the elements in the paging request.
- class tensorbay.client.lazy.InitPage(offset: int, limit: int, func: Callable[[int, int], Generator[tensorbay.client.lazy._T, None, int]])[source]¶
Bases:
tensorbay.client.lazy.LazyPage
[tensorbay.client.lazy._T
]In paging lazy evaluation system, InitPage is the page for initializing
PagingList
.InitPage will send a paging request to pull a page of elements and storing them in different
LazyItem
instances when construction. And the totalCount of the page will also be stored in the instance.- Parameters
offset – The offset of the page.
limit – The limit of the page.
func – A paging generator function, which takes offset<int> and limit<int> as inputs and returns a generator. The returned generator should yield the element user needs, and return the total count of the elements in the paging request.
- total_count¶
The totalCount of the paging request.
- class tensorbay.client.lazy.PagingList(func: Callable[[int, int], Generator[tensorbay.client.lazy._T, None, int]], limit: int)[source]¶
Bases:
MutableSequence
[tensorbay.client.lazy._T
],tensorbay.utility.repr.ReprMixin
PagingList is a wrap of web paging request.
It follows the python MutableSequence protocal, which means it can be used like a python builtin list. And it provides features like lazy evaluation and cache.
- Parameters
func – A paging generator function, which takes offset<int> and limit<int> as inputs and returns a generator. The returned generator should yield the element user needs, and return the total count of the elements in the paging request.
limit – The page size of each paging request.
- insert(index: int, value: tensorbay.client.lazy._T) None [source]¶
Insert object before index.
- Parameters
index – Position of the PagingList.
value – Element to be inserted into the PagingList.
- append(value: tensorbay.client.lazy._T) None [source]¶
Append object to the end of the PagingList.
- Parameters
value – Element to be appended to the PagingList.
- pop(index: int = - 1) tensorbay.client.lazy._T [source]¶
Return the item at index (default last) and remove it from the PagingList.
- Parameters
index – Position of the PagingList.
- Returns
Element to be removed from the PagingList.
- index(value: Any, start: int = 0, stop: Optional[int] = None) int [source]¶
Return the first index of the value.
- Parameters
value – The value to be found.
start – The start index of the subsequence.
stop – The end index of the subsequence.
- Raises
ValueError – When the value is not in the PagingList
- Returns
The first index of the value.