
    `i                         d Z ddlZddlmZmZmZmZmZmZm	Z	m
Z
  e
d      Ze	d   Z G d dee         Z G d d	ee         Z G d
 dee         Zy)zPagers for the GenAI List APIs.    N)AnyAsyncIterator	AwaitableCallableGenericIteratorLiteralTypeVarT)
batch_jobsmodelstuning_jobsfilescached_contentsc                       e Zd ZdZdededef   dedefdZdededef   dedefdZe	d	e
e   fd
       Ze	d	efd       Ze	d	efd       Ze	d	eeef   fd       Zd	efdZded	efdZded	dfdZy)
_BasePagerz9Base pager class for iterating through paginated results.namerequest.responseconfigc                 X   || _         || _        t        || j                         xs g | _        d| _        |si }n1t        |t              rt        j                  |      }nt        |      }t        |d      |d<   || _	        |j                  dt        | j                              | _        y )Nr   next_page_token
page_token	page_size)_name_requestgetattr_page_idx
isinstancedictcopydeepcopy_configgetlen
_page_size)selfr   r   r   r   request_configs         X/var/www/html/ts-aiml.yecor.com/venv/lib/python3.12/site-packages/google/genai/pagers.py
_init_pagez_BasePager._init_page!   s     DJDM4::.4"DJDIn	FD	!}}V,nF|n#*85F#GN< !DL$((c$**oFDO    c                 ,    | j                  ||||       y N)r+   )r(   r   r   r   r   s        r*   __init__z_BasePager.__init__9   s     	OOD'8V4r,   returnc                     | j                   S )a`  Returns a subset of the entire list of items. 

    For the number of items returned, see `pageSize()`.

    Usage:

    .. code-block:: python

      batch_jobs_pager = client.batches.list(config={'page_size': 5})
      print(f"first page: {batch_jobs_pager.page}")
      # first page: [BatchJob(name='projects/./locations/./batchPredictionJobs/1
    )r   r(   s    r*   pagez_BasePager.pageB   s     ::r,   c                     | j                   S )zReturns the type of paged item (for example, ``batch_jobs``).

    Usage:

    .. code-block:: python

      batch_jobs_pager = client.batches.list(config={'page_size': 5})
      print(f"name: {batch_jobs_pager.name}")
      # name: batch_jobs
    )r   r2   s    r*   r   z_BasePager.nameS   s     ::r,   c                     | j                   S )a  Returns the maximum number of items fetched by the pager at one time.

    Usage:

    .. code-block:: python

      batch_jobs_pager = client.batches.list(config={'page_size': 5})
      print(f"page_size: {batch_jobs_pager.page_size}")
      # page_size: 5
    )r'   r2   s    r*   r   z_BasePager.page_sizeb   s     ??r,   c                     | j                   S )a  Returns the configuration when making the API request for the next page.

    A configuration is a set of optional parameters and arguments that can be
    used to customize the API request. For example, the ``page_token`` parameter
    contains the token to request the next page.

    Usage:

    .. code-block:: python

      batch_jobs_pager = client.batches.list(config={'page_size': 5})
      print(f"config: {batch_jobs_pager.config}")
      # config: {'page_size': 5, 'page_token': 'AMEw9yO5jnsGnZJLHSKDFHJJu'}
    )r$   r2   s    r*   r   z_BasePager.configq   s    " <<r,   c                 ,    t        | j                        S )z6Returns the total number of items in the current page.)r&   r3   r2   s    r*   __len__z_BasePager.__len__   s    tyy>r,   indexc                      | j                   |   S )z$Returns the item at the given index.)r3   )r(   r9   s     r*   __getitem__z_BasePager.__getitem__   s    99Ur,   Nc                 h    | j                  | j                  | j                  || j                         y)zInitializes the next page from the response.

    This is an internal method that should be called by subclasses after
    fetching the next page.

    Args:
      response: The response object from the API request.
    N)r+   r   r   r   r(   r   s     r*   _init_next_pagez_BasePager._init_next_page   s"     	OODIIt}}hDr,   )__name__
__module____qualname____doc__	PagedItemr   r   r+   r/   propertylistr   r3   r   intr   r!   strr   r8   r;   r>    r,   r*   r   r      s   AGG S!G 	G
 G055 S!5 	5
 5 DG    I      d38n  $s s q 	Ec 	Ed 	Er,   r   c                   @    e Zd ZdZdefdZdee   fdZdee   fdZ	y)Pagerz4Pager class for iterating through paginated results.r0   c                     | j                   t        |       k\  r	 | j                          | j
                  | j                      }| xj                   dz  c_         |S # t        $ r t        w xY w)zReturns the next item.   )r   r&   	next_page
IndexErrorStopIterationr3   r(   items     r*   __next__zPager.__next__   s^    yyCI 99TYYDIINIK  s   A A*c                     d| _         | S )z#Returns an iterator over the items.r   r   r2   s    r*   __iter__zPager.__iter__       DIKr,   c                     | j                   j                  d      st        d      | j                  | j                         }| j	                  |       | j
                  S )a  Fetches the next page of items. This makes a new API request.

    Usage:

    .. code-block:: python

      batch_jobs_pager = client.batches.list(config={'page_size': 5})
      print(f"current page: {batch_jobs_pager.page}")
      batch_jobs_pager.next_page()
      print(f"next page: {batch_jobs_pager.page}")
      # current page: [BatchJob(name='projects/.../batchPredictionJobs/1
      # next page: [BatchJob(name='projects/.../batchPredictionJobs/6
    r   No more pages to fetch.r   r   r%   rN   r   r>   r3   r=   s     r*   rM   zPager.next_page   sL     ;;??<(011}}DKK}0H"99r,   N)
r?   r@   rA   rB   r   rR   r   rU   rE   rM   rH   r,   r*   rJ   rJ      s1    <
 
 
a r,   rJ   c                   t     e Zd ZdZdededee   f   dedef fdZde	e
   fd	Zde
fd
Zdee
   fdZ xZS )
AsyncPagerz9AsyncPager class for iterating through paginated results.r   r   .r   r   c                 *    t         |   ||||       y r.   )superr/   )r(   r   r   r   r   	__class__s        r*   r/   zAsyncPager.__init__   s     
GT7Hf5r,   r0   c                     d| _         | S )z)Returns an async iterator over the items.r   rT   r2   s    r*   	__aiter__zAsyncPager.__aiter__   rV   r,   c                    K   | j                   t        |       k\  r	 | j                          d{    | j
                  | j                      }| xj                   dz  c_         |S 7 4# t        $ r t        w xY ww)z%Returns the next item asynchronously.NrL   )r   r&   rM   rN   StopAsyncIterationr3   rP   s     r*   	__anext__zAsyncPager.__anext__   sj     yyCI!nn 99TYYDIINIK 	 !  !s+   A9A& A$A& 0A9$A& &A66A9c                    K   | j                   j                  d      st        d      | j                  | j                          d{   }| j	                  |       | j
                  S 7 !w)aS  Fetches the next page of items asynchronously.

    This makes a new API request.

    Returns:
      The next page of items.

    Raises:
      IndexError: No more pages to fetch.

    Usage:

    .. code-block:: python

      batch_jobs_pager = await client.aio.batches.list(config={'page_size': 5})
      print(f"current page: {batch_jobs_pager.page}")
      await batch_jobs_pager.next_page()
      print(f"next page: {batch_jobs_pager.page}")
      # current page: [BatchJob(name='projects/.../batchPredictionJobs/1
      # next page: [BatchJob(name='projects/.../batchPredictionJobs/6
    r   rX   rY   NrZ   r=   s     r*   rM   zAsyncPager.next_page   sX     . ;;??<(011]]$++]66H"99 7s   AA,A*	"A,)r?   r@   rA   rB   rC   r   r   r   r/   r   r   ra   rd   rE   rM   __classcell__)r_   s   @r*   r\   r\      sl    A66 Ys^+,6 	6
 6q) 

q 
tAw r,   r\   )rB   r"   typingr   r   r   r   r   r   r	   r
   r   rC   r   rJ   r\   rH   r,   r*   <module>rh      sd     &  ^ ^ ^CLE	
wE wEt(JqM (V9A 9r,   