o
    º­§id  ã                   @   sŠ   d dl Z d dlmZmZmZmZmZmZmZ d dl	Z	ddl
mZ e	 e¡ZedƒZedƒZG dd„ deee  ƒZG d	d
„ d
ee ƒZdS )é    N)ÚCallableÚOptionalÚTypeVarÚIteratorÚIterableÚTupleÚAnyé   )Ú
AzureErrorÚ
ReturnTypeÚResponseTypec                
   @   sz   e Zd Z	ddeee gef deegeeee	 f f dee fdd„Z
deee	  fdd	„Zdee	 fd
d„ZeZdS )ÚPageIteratorNÚget_nextÚextract_dataÚcontinuation_tokenc                 C   s(   || _ || _|| _d| _d| _d| _dS )aY  Return an iterator of pages.

        :param get_next: Callable that take the continuation token and return a HTTP response
        :param extract_data: Callable that take an HTTP response and return a tuple continuation token,
         list of ReturnType
        :param str continuation_token: The continuation token needed by get_next
        FN)Ú	_get_nextÚ_extract_datar   Ú_did_a_call_alreadyÚ	_responseÚ_current_page)Úselfr   r   r   © r   úH/home/app/Keep/.python/lib/python3.10/site-packages/azure/core/paging.pyÚ__init__0   s   
zPageIterator.__init__Úreturnc                 C   ó   | S ©Nr   ©r   r   r   r   Ú__iter__D   ó   zPageIterator.__iter__c              
   C   sx   | j du r| jrtdƒ‚z	|  | j ¡| _W n ty) } z|j s$| j |_ ‚ d}~ww d| _|  | j¡\| _ | _t| jƒS )a  Get the next page in the iterator.

        :returns: An iterator of objects in the next page.
        :rtype: iterator[ReturnType]
        :raises StopIteration: If there are no more pages to return.
        :raises AzureError: If the request fails.
        NzEnd of pagingT)	r   r   ÚStopIterationr   r   r
   r   r   Úiter)r   Úerrorr   r   r   Ú__next__G   s   €ý
zPageIterator.__next__r   )Ú__name__Ú
__module__Ú__qualname__r   r   Ústrr   r   r   r   r   r   r   r#   Únextr   r   r   r   r   /   s    üþý
ür   c                   @   st   e Zd Zdededdfdd„Zddee deee  fdd	„Z	defd
d„Z
dee fdd„Zdefdd„ZeZdS )Ú	ItemPagedÚargsÚkwargsr   Nc                 O   s&   || _ || _d| _| j dt¡| _dS )zšReturn an iterator of items.

        args and kwargs will be passed to the PageIterator constructor directly,
        except page_iterator_class
        NZpage_iterator_class)Ú_argsÚ_kwargsÚ_page_iteratorÚpopr   Ú_page_iterator_class)r   r*   r+   r   r   r   r   b   s   zItemPaged.__init__r   c                 C   s   | j | jd|i| j¤ŽS )aÚ  Get an iterator of pages of objects, instead of an iterator of objects.

        :param str continuation_token:
            An opaque continuation token. This value can be retrieved from the
            continuation_token field of a previous generator object. If specified,
            this generator will begin returning results from this point.
        :returns: An iterator of pages (themselves iterator of objects)
        :rtype: iterator[iterator[ReturnType]]
        r   )r0   r,   r-   )r   r   r   r   r   Úby_pagem   s   
zItemPaged.by_pagec                 C   s   d  tt| ƒƒ¡S )Nz3<iterator object azure.core.paging.ItemPaged at {}>)ÚformatÚhexÚidr   r   r   r   Ú__repr__y   s   zItemPaged.__repr__c                 C   r   r   r   r   r   r   r   r   |   r   zItemPaged.__iter__c                 C   s&   | j du rtj |  ¡ ¡| _ t| j ƒS )z½Get the next item in the iterator.

        :returns: The next item in the iterator.
        :rtype: ReturnType
        :raises StopIteration: If there are no more items to return.
        N)r.   Ú	itertoolsÚchainÚfrom_iterabler1   r(   r   r   r   r   r#      s   

zItemPaged.__next__r   )r$   r%   r&   r   r   r   r'   r   r   r1   r5   r   r#   r(   r   r   r   r   r)   a   s     r)   )r6   Útypingr   r   r   r   r   r   r   ÚloggingÚ
exceptionsr
   Ú	getLoggerr$   Z_LOGGERr   r   r   r)   r   r   r   r   Ú<module>   s   $	
2