
    [Th                         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_contentsc            
       *   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         X/home/www/backend.miabetepe.com/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)r2   )r/   r   r   r   r   s        r1   __init__z_BasePager.__init__=   s     	OOD'8V4r3   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$   r/   s    r1   pagez_BasePager.pageF   s     ::r3   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!   r8   s    r1   r   z_BasePager.nameW   s     ::r3   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.   r8   s    r1   r    z_BasePager.page_sizef   s     ??r3   c                     | j                   S )z.Returns the http response of the API response.)r&   r8   s    r1   r   z_BasePager.sdk_http_responseu   s     """r3   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+   r8   s    r1   r   z_BasePager.config{   s    " <<r3   c                 ,    t        | j                        S )z6Returns the total number of items in the current page.)r-   r9   r8   s    r1   __len__z_BasePager.__len__   s    tyy>r3   indexc                      | j                   |   S )z$Returns the item at the given index.)r9   )r/   r@   s     r1   __getitem__z_BasePager.__getitem__   s    99Ur3   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)r2   r   r"   r   r/   r   s     r1   _init_next_pagez_BasePager._init_next_page   s"     	OODIIt}}hDr3   )__name__
__module____qualname____doc__	PagedItemr   r   r2   r6   propertylistr   r9   r   intr    r   r   HttpResponser   r   
StringDictr   r?   rB   rE    r3   r1   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r3   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StopIterationr9   r/   items     r1   __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%   r8   s    r1   __iter__zPager.__iter__       DIKr3   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,   rU   r"   rE   r9   rD   s     r1   rT   zPager.next_page   sL     ;;??<(011}}DKK}0H"99r3   N)
rF   rG   rH   rI   r   rY   r   r\   rL   rT   rP   r3   r1   rR   rR      s1    <
 
 
a r3   rR   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 r5   )superr6   )r/   r   r   r   r   	__class__s        r1   r6   zAsyncPager.__init__   s     
GT7Hf5r3   r   c                     d| _         | S )z)Returns an async iterator over the items.r   r[   r8   s    r1   	__aiter__zAsyncPager.__aiter__   r]   r3   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-   rT   rU   StopAsyncIterationr9   rW   s     r1   	__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   r_   r`   Nra   rD   s     r1   rT   zAsyncPager.next_page   sX     . ;;??<(011]]$++]66H"99 7s   AA,A*	"A,)rF   rG   rH   rI   rJ   r   r   r   r6   r   r   rh   rk   rL   rT   __classcell__)rf   s   @r1   rc   rc      sl    A66 Ys^+,6 	6
 6q) 

q 
tAw r3   rc   )rI   r)   typingr   r   r   r   r   r   r	   r
   r    r   r   r   rJ   r   rR   rc   rP   r3   r1   <module>rp      sj     &  f f f  CLE	
E ED(JqM (V9A 9r3   