[docs]classPaginatorTable:""" A PaginatorTable maps multiple methods of an SDK client to paginated variants. Given a method, client.foo annotated with the `has_paginator` decorator, the table will gain a function attribute `foo` (name matching is automatic) which returns a Paginator. Clients automatically build and attach paginator tables under the ``paginated`` attribute. That is, if `client` has two methods `foo` and `bar` which are marked as paginated, that will let us call >>> client.paginated.foo() >>> client.paginated.bar() where ``client.paginated`` is a ``PaginatorTable``. Paginators are iterables of response pages, so ultimate usage is like so: >>> paginator = client.paginated.foo() # returns a paginator >>> for page in paginator: # a paginator is an iterable of pages (response objects) >>> print(json.dumps(page.data)) # you can handle each response object in turn A ``PaginatorTable`` is built automatically as part of client instantiation. Creation of ``PaginatorTable`` objects is considered a private API. """def__init__(self,client:t.Any)->None:self._client=client# _bindings is a lazily loaded table of names -> callables which# return paginatorsself._bindings:dict[str,t.Callable[...,Paginator[t.Any]]]={}def_add_binding(self,methodname:str,bound_method:t.Callable[...,t.Any])->None:self._bindings[methodname]=Paginator.wrap(bound_method)def__getattr__(self,attrname:str)->t.Callable[...,Paginator[t.Any]]:ifattrnamenotinself._bindings:# this could raise AttributeError -- in which case, let it!method=getattr(self._client,attrname)try:self._bindings[attrname]=Paginator.wrap(method)# ValueError is raised if the method being wrapped is not paginatedexceptValueErrorase:raiseAttributeError(f"'{attrname}' is not a paginated method")fromereturnself._bindings[attrname]# customize pickling methods to ensure that the object is pickle-safedef__getstate__(self)->dict[str,t.Any]:# when pickling, drop any bound methodsd=dict(self.__dict__)# copyd["_bindings"]={}returnd# custom __setstate__ to avoid an infinite loop on `getattr` before `_bindings` is# populated# see: https://docs.python.org/3/library/pickle.html#object.__setstate__def__setstate__(self,d:dict[str,t.Any])->None:self.__dict__.update(d)