
    L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
mZ ddlmZ ddl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Union   )_common)typesT)
batch_jobsmodelstuning_jobsfilescached_contentsfile_search_stores	documentsc            
       *   e Zd ZdZdededef   dededd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j$                  df   fd       Ze	dej*                  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configreturnNc                 |   || _         || _        t        || j                         xs g | _        d| _        t        |dd       | _        |si }n1t        |t              rt        j                  |      }nt        |      }t        |d      |d<   || _
        |j                  dt        | j                              | _        y )Nr   sdk_http_responsenext_page_token
page_token	page_size)_name_requestgetattr_page_idx_sdk_http_response
isinstancedictcopydeepcopy_configgetlen
_page_size)selfr   r   r   r   request_configs         Q/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/google/genai/pagers.py
_init_pagez_BasePager._init_page)   s     DJDM4::.4"DJDI%h0CTJDn	FD	!}}V,nF|n#*85F#GN< !DL)--k3tzz?KDO    c                 ,    | j                  ||||       y N)r4   )r1   r   r   r   r   s        r3   __init__z_BasePager.__init__C   s     	OOD'8V4r5   c                     | 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&   r1   s    r3   pagez_BasePager.pageL   s     ::r5   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#   r:   s    r3   r   z_BasePager.name]   s     ::r5   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
    )r0   r:   s    r3   r"   z_BasePager.page_sizel   s     ??r5   c                     | j                   S )z.Returns the http response of the API response.)r(   r:   s    r3   r   z_BasePager.sdk_http_response{   s     """r5   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-   r:   s    r3   r   z_BasePager.config   s    " <<r5   c                 ,    t        | j                        S )z6Returns the total number of items in the current page.)r/   r;   r:   s    r3   __len__z_BasePager.__len__   s    tyy>r5   indexc                      | j                   |   S )z$Returns the item at the given index.)r;   )r1   rB   s     r3   __getitem__z_BasePager.__getitem__   s    99Ur5   c                 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)r4   r   r$   r   r1   r   s     r3   _init_next_pagez_BasePager._init_next_page   s"     	OODIIt}}hDr5   )__name__
__module____qualname____doc__	PagedItemr   r   r4   r8   propertylistr   r;   r   intr"   r   r   HttpResponser   r   
StringDictr   rA   rD   rG    r5   r3   r   r   &   sS   ALL S!L 	L
 L L455 S!5 	5
 5 DG    I      #u'9'94'?!@ # #
 g((  $s s q 	Ec 	Ed 	Er5   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.r   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'   r/   	next_page
IndexErrorStopIterationr;   r1   items     r3   __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'   r:   s    r3   __iter__zPager.__iter__       DIKr5   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.   rW   r$   rG   r;   rF   s     r3   rV   zPager.next_page   sL     ;;??<(011}}DKK}0H"99r5   N)
rH   rI   rJ   rK   r   r[   r   r^   rN   rV   rR   r5   r3   rT   rT      s1    <
 
 
a r5   rT   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 r7   )superr8   )r1   r   r   r   r   	__class__s        r3   r8   zAsyncPager.__init__   s     
GT7Hf5r5   r   c                     d| _         | S )z)Returns an async iterator over the items.r   r]   r:   s    r3   	__aiter__zAsyncPager.__aiter__   r_   r5   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.Nr   )r'   r/   rV   rW   StopAsyncIterationr;   rY   s     r3   	__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!   ra   rb   Nrc   rF   s     r3   rV   zAsyncPager.next_page   sX     . ;;??<(011]]$++]66H"99 7s   AA,A*	"A,)rH   rI   rJ   rK   rL   r   r   r   r8   r   r   rj   rm   rN   rV   __classcell__)rh   s   @r3   re   re      sl    A66 Ys^+,6 	6
 6q) 

q 
tAw r5   re   )rK   r+   typingr   r   r   r   r   r   r	   r
   r    r   r   r   rL   r   rT   re   rR   r5   r3   <module>rr      sl     &  f f f  CL	E ED(JqM (V9A 9r5   