Returns an iterator that returns data until it's exhausted. Then will request more data (same amount as the original request) to the server until this data is exhausted as well. Stops when no more data exists or limit is reached. :param parent: the parent class. Mus
(self, *, parent=None, data=None, constructor=None,
next_link=None, limit=None, **kwargs)
| 504 | """ Utility class that allows batching requests to the server """ |
| 505 | |
| 506 | def __init__(self, *, parent=None, data=None, constructor=None, |
| 507 | next_link=None, limit=None, **kwargs): |
| 508 | """ Returns an iterator that returns data until it's exhausted. |
| 509 | Then will request more data (same amount as the original request) |
| 510 | to the server until this data is exhausted as well. |
| 511 | Stops when no more data exists or limit is reached. |
| 512 | |
| 513 | :param parent: the parent class. Must implement attributes: |
| 514 | con, api_version, main_resource |
| 515 | :param data: the start data to be return |
| 516 | :param constructor: the data constructor for the next batch. |
| 517 | It can be a function. |
| 518 | :param str next_link: the link to request more data to |
| 519 | :param int limit: when to stop retrieving more data |
| 520 | :param kwargs: any extra key-word arguments to pass to the |
| 521 | construtctor. |
| 522 | """ |
| 523 | if parent is None: |
| 524 | raise ValueError('Parent must be another Api Component') |
| 525 | |
| 526 | super().__init__(protocol=parent.protocol, |
| 527 | main_resource=parent.main_resource) |
| 528 | |
| 529 | self.parent = parent |
| 530 | self.con = parent.con |
| 531 | self.constructor = constructor |
| 532 | self.next_link = next_link |
| 533 | self.limit = limit |
| 534 | self.data = data = list(data) if data else [] |
| 535 | |
| 536 | data_count = len(data) |
| 537 | if limit and limit < data_count: |
| 538 | self.data_count = limit |
| 539 | self.total_count = limit |
| 540 | else: |
| 541 | self.data_count = data_count |
| 542 | self.total_count = data_count |
| 543 | self.state = 0 |
| 544 | self.extra_args = kwargs |
| 545 | |
| 546 | def __str__(self): |
| 547 | return self.__repr__() |