
    +j                         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dS )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            
       N   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dS )
_BasePagerz9Base pager class for iterating through paginated results.namerequest.responseconfigreturnNc                    || _         || _        t          || j                   pg | _        d| _        t          |dd           | _        |si }n9t          |t                    rt          j	        |          }nt          |          }t          |d          |d<   || _
        |                    dt          | j                            | _        d S )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         W/home/wildlama/visual-decline/.venv/lib/python3.11/site-packages/google/genai/pagers.py
_init_pagez_BasePager._init_page)   s     DJDM4:..4"DJDI%h0CTJJD $nn	FD	!	! $}V,,nnF||n#*85F#G#GN< !DL)--k3tz??KKDOOO    c                 6    |                      ||||           d S N)r4   )r1   r   r   r   r   s        r3   __init__z_BasePager.__init__C   s"     	OOD'8V4444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    ty>>r5   indexc                     | j         |         S )z$Returns the item at the given index.)r;   )r1   rB   s     r3   __getitem__z_BasePager.__getitem__   s    9Ur5   c                 T    |                      | j        | j        || j                   dS )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(     	OODIt}hDDDD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   &   s       AALL S!L 	L
 L L L L L455 S!5 	5
 5 5 5 5 DG    8  I    8     8 #u'94'?!@ # # # 8#
 g(    8$s    s q    	Ec 	Ed 	E 	E 	E 	E 	E 	Er5   r   c                   N    e Zd ZdZdefdZdee         fdZdee         fdZ	dS )Pagerz4Pager class for iterating through paginated results.r   c                     | j         t          |           k    r+	 |                                  n# t          $ r t          w xY w| j        | j                  }| xj         dz  c_         |S )zReturns the next item.r   )r'   r/   	next_page
IndexErrorStopIterationr;   r1   items     r3   __next__zPager.__next__   sr    yCII    9TYDIINIIKs	   / Ac                     d| _         | S )z#Returns an iterator over the items.r   r'   r:   s    r3   __iter__zPager.__iter__       DIKr5   c                     | j                             d          st          d          |                     | 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   sZ     ;??<(( 20111}}DK}00H"""9r5   N)
rH   rI   rJ   rK   r   r[   r   r^   rN   rV   rR   r5   r3   rT   rT      ss        <<
 
 
 
 
    
a      r5   rT   c                        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                 P    t                                          ||||           d S r7   )superr8   )r1   r   r   r   r   	__class__s        r3   r8   zAsyncPager.__init__   s)     
GGT7Hf5555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    r1	 |                                  d{V  n# t          $ r t          w xY w| j        | j                  }| xj         dz  c_         |S )z%Returns the next item asynchronously.Nr   )r'   r/   rV   rW   StopAsyncIterationr;   rY   s     r3   	__anext__zAsyncPager.__anext__   s      yCII!nn ! ! !  ! 9TYDIINIIKs	   7 A	c                    K   | j                             d          st          d          |                     | j                    d{V }|                     |           | j        S )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   sp      . ;??<(( 20111]]$+]66666666H"""9r5   )rH   rI   rJ   rK   rL   r   r   r   r8   r   r   rj   rm   rN   rV   __classcell__)rh   s   @r3   re   re      s        AA66 Ys^+,6 	6
 6 6 6 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      s@    & %  f f f f f f f f f f f f f f f f f f f f f f            GCLL	E E E E E E E ED( ( ( ( (JqM ( ( (V9 9 9 9 9A 9 9 9 9 9r5   