HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //usr/lib/python3.6/site-packages/botocore/__pycache__/paginate.cpython-36.pyc
3

�T_�i�@s�ddlmZddlmZddlZddlZddlZddlZddlm	Z	ddlm
Z
ddlmZm
Z
eje�ZGdd�de�ZGd	d
�d
e�ZGdd�de�ZGd
d�de�ZGdd�de�ZGdd�de�ZdS)�)�tee)�sixN)�PaginationError)�zip)�set_value_from_jmespath�merge_dictsc@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�TokenEncoderabEncodes dictionaries into opaque strings.

    This for the most part json dumps + base64 encoding, but also supports
    having bytes in the dictionary in addition to the types that json can
    handle by default.

    This is intended for use in encoding pagination tokens, which in some
    cases can be complex structures and / or contain bytes.
    cCs`ytj|�}Wn:ttfk
rH|j|g�\}}||d<tj|�}YnXtj|jd��jd�S)a.Encodes a dictionary to an opaque string.

        :type token: dict
        :param token: A dictionary containing pagination information,
            particularly the service pagination token(s) but also other boto
            metadata.

        :rtype: str
        :returns: An opaque string
        �boto_encoded_keyszutf-8)	�json�dumps�	TypeError�UnicodeDecodeError�_encode�base64�	b64encode�encode�decode)�self�token�json_stringZ
encoded_token�encoded_keys�r�/usr/lib/python3.6/paginate.pyr)szTokenEncoder.encodecCsPt|t�r|j||�St|t�r,|j||�St|tj�rD|j||�S|gfSdS)z@Encode bytes in given data, keeping track of the path traversed.N)�
isinstance�dict�_encode_dict�list�_encode_listrZbinary_type�
_encode_bytes)r�data�pathrrrrFs

zTokenEncoder._encodec
CsTg}g}xBt|�D]6\}}||g}|j||�\}}	|j|�|j|	�qW||fS)z@Encode any bytes in a list, noting the index of what is encoded.)�	enumerater�append�extend)
rrr �new_data�encoded�i�value�new_path�	new_value�new_encodedrrrrQs

zTokenEncoder._encode_listc
CsRi}g}x@|j�D]4\}}||g}|j||�\}}	|||<|j|	�qW||fS)z@Encode any bytes in a dict, noting the index of what is encoded.)�itemsrr#)
rrr r$r%�keyr'r(r)r*rrrr\s
zTokenEncoder._encode_dictcCstj|�jd�|gfS)zBase64 encode a byte string.zutf-8)rrr)rrr rrrrgszTokenEncoder._encode_bytesN)	�__name__�
__module__�__qualname__�__doc__rrrrrrrrrrs	rc@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�TokenDecoderz�Decodes token strings back into dictionaries.

    This performs the inverse operation to the TokenEncoder, accepting
    opaque strings and decoding them into a useable form.
    cCsHtj|jd��jd�}tj|�}|jdd�}|dkr8|S|j||�SdS)adDecodes an opaque string to a dictionary.

        :type token: str
        :param token: A token string given by the botocore pagination
            interface.

        :rtype: dict
        :returns: A dictionary containing pagination information,
            particularly the service pagination token(s) but also other boto
            metadata.
        zutf-8r	N)r�	b64decoderrr
�loads�pop�_decode)rrrZ
decoded_tokenrrrrrss
zTokenDecoder.decodecCs<x6|D].}|j||�}tj|jd��}|j|||�qW|S)z&Find each encoded value and decode it.zutf-8)�	_path_getrr2r�	_path_set)rrrr,r%Zdecodedrrrr5�s

zTokenDecoder._decodecCs|}x|D]}||}q
W|S)z�Return the nested data at the given path.

        For instance:
            data = {'foo': ['bar', 'baz']}
            path = ['foo', 0]
            ==> 'bar'
        r)rrr �d�steprrrr6�s
zTokenDecoder._path_getcCs$|j||dd��}|||d<dS)z�Set the value of a key in the given data.

        Example:
            data = {'foo': ['bar', 'baz']}
            path = ['foo', 1]
            value = 'bin'
            ==> data = {'foo': ['bar', 'bin']}
        N����r;)r6)rrr r'Z	containerrrrr7�s	zTokenDecoder._path_setN)r-r.r/r0rr5r6r7rrrrr1ls
r1c@seZdZdd�Zdd�ZdS)�PaginatorModelcCs|d|_dS)NZ
pagination)�_paginator_config)rZpaginator_configrrr�__init__�szPaginatorModel.__init__cCs4y|j|}Wn tk
r.td|��YnX|S)Nz*Paginator for operation does not exist: %s)r=�KeyError�
ValueError)rZoperation_nameZsingle_paginator_configrrr�
get_paginator�szPaginatorModel.get_paginatorN)r-r.r/r>rArrrrr<�sr<c@s�eZdZdd�Zedd��Zedd��Zejdd��Zedd	��Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(S))�PageIteratorcCsb||_||_||_||_||_||_||_|	|_|
|_||_	d|_
||_i|_t
�|_t�|_dS)N)�_method�_input_token�
_output_token�
_more_results�_result_keys�
_max_items�
_limit_key�_starting_token�
_page_size�
_op_kwargs�
_resume_token�_non_aggregate_key_exprs�_non_aggregate_partr�_token_encoderr1�_token_decoder)r�method�input_token�output_token�more_results�result_keys�non_aggregate_keys�	limit_key�	max_itemsZstarting_token�	page_size�	op_kwargsrrrr>�szPageIterator.__init__cCs|jS)N)rG)rrrrrV�szPageIterator.result_keyscCs|jS)z&Token to specify to resume pagination.)rM)rrrr�resume_token�szPageIterator.resume_tokencCsnt|t�std|��d|kr0t|jdg�}n
t|j�}t|j��}||kr^|jj|�|_ntd|��dS)NzBad starting token: %s�boto_truncate_amount)	rrr@�sortedrD�keysrPrrM)rr'Z
token_keys�	dict_keysrrrr\�s

cCs|jS)N)rO)rrrr�non_aggregate_part�szPageIterator.non_aggregate_partccs�|j}d}tdd�|jD��}|jdk	r4|j�d}d}d}|jd}d}|j|��x.|j|�}|j|�}	|r�|jdk	r�|j	|	||�}d}|j
|	�nd}|j|	�}
|
dkr�g}
t|
�}d}|j
dk	r�|||j
}|dkr�|j|	||||�|VPqX|V||7}|j|	�}tdd�|j�D���r,P|j
dk	�rL||j
k�rL||_P|dk	�rr||k�rrd|}
t|
d��|j||�|}qXWdS)	Ncss|]}|dfVqdS)Nr)�.0r,rrr�	<genexpr>�sz(PageIterator.__iter__.<locals>.<genexpr>rTFcss|]}|dkVqdS)Nr)rb�trrrrc!sz*The same next token was received twice: %s)�message)rLrrDrJ�_parse_starting_tokenrV�_inject_starting_params�
_make_request�_extract_parsed_response�_handle_first_request� _record_non_aggregate_key_values�search�lenrH�_truncate_response�_get_next_token�all�valuesr\r�_inject_token_into_kwargs)r�current_kwargsZprevious_next_token�
next_tokenZtotal_itemsZ
first_request�primary_result_key�starting_truncation�response�parsedZcurrent_responseZnum_current_response�truncate_amountrerrr�__iter__�sd












zPageIterator.__iter__ccsLtj|�}x<|D]4}|j|�}t|t�r>x|D]
}|Vq.Wq|VqWdS)a�Applies a JMESPath expression to a paginator

        Each page of results is searched using the provided JMESPath
        expression. If the result is not a list, it is yielded
        directly. If the result is a list, each element in the result
        is yielded individually (essentially implementing a flatmap in
        which the JMESPath search is the mapping function).

        :type expression: str
        :param expression: JMESPath expression to apply to each page.

        :return: Returns an iterator that yields the individual
            elements of applying a JMESPath expression to each page of
            results.
        N)�jmespath�compilerlrr)r�
expressionZcompiled�page�results�elementrrrrl1s




zPageIterator.searchcCs|jf|�S)N)rC)rrsrrrrhKszPageIterator._make_requestcCs|S)Nr)rrwrrrriNsz%PageIterator._extract_parsed_responsecCs6i}x&|jD]}|j|�}t||j|�qW||_dS)N)rNrlrr}rO)rrwrWr}�resultrrrrkQs

z-PageIterator._record_non_aggregate_key_valuescCs<|jdk	r"|j�d}|j||�|jdk	r8|j||j<dS)Nr)rJrfrrrKrI)rr[rtrrrrgZs


z$PageIterator._inject_starting_paramscCsBx<|j�D]0\}}|dk	r,|dkr,|||<q
||kr
||=q
WdS)N�None)r+)rr[rt�namerrrrrrgs

z&PageIterator._inject_token_into_kwargsc	Cs�|j�d}|j|�}t|ttjf�r4||d�}nd}t||j|�xj|jD]`}||kr\qN|j|�}t|t�rvg}n*t|tj�r�d}nt|t	t
f�r�d}nd}t||j|�qNW|S)Nr:�r)rfrlrrr�string_typesrr}rV�int�float)	rrxrurvZall_datarrZsampleZempty_valuerrrrjns,


z"PageIterator._handle_first_requestc	CsR|j|�}|dkrg}t|�|}|d|�}t||j|�|||d<||_dS)Nr])rlrmrr}r\)	rrxruryrvrtZoriginalZamount_to_keepZ	truncatedrrrrn�s
zPageIterator._truncate_responsecCs^|jdk	r|jj|�siSi}x:t|j|j�D](\}}|j|�}|rN|||<q.d||<q.W|S)N)rFrlrrErD)rrxZnext_tokensrTZ	input_keyrtrrrro�s


zPageIterator._get_next_tokencCs&t|t|j��}dd�t||j�D�S)NcSsg|]\}}t||��qSr)�ResultKeyIterator)rbr&�
result_keyrrr�
<listcomp>�sz1PageIterator.result_key_iters.<locals>.<listcomp>)rrmrVr)rZteed_resultsrrr�result_key_iters�szPageIterator.result_key_iterscCs�i}x�|D]�}|}t|t�r0t|�dkr0|d}x~|jD]t}|j|�}|dkrPq8|j|�}|dkrrt||j|�q8t|t�r�|j|�q8t|t	t
tjf�r8t||j||�q8Wq
Wt
||j�|jdk	r�|j|d<|S)N�r:Z	NextToken)r�tuplermrVrlrr}rr#r�r�rr�rrar\)rZcomplete_resultrwr~Zresult_expressionZresult_valueZexisting_valuerrr�build_full_result�s2





zPageIterator.build_full_resultcCsn|jdkrdS|j}y,|jj|�}d}d|kr>|jd�}|d=Wn$ttfk
rd|j�\}}YnX||fS)Nrr])rJrQr�getr@r� _parse_starting_token_deprecated)rrt�indexrrrrf�s


z"PageIterator._parse_starting_tokencCs�tjd|j�|jdkrdS|jjd�}g}d}t|�t|j�dkrvyt|j��}Wntk
rt|jg}YnXx*|D]"}|dkr�|j	d�q||j	|�q|W|j
|�|fS)z|
        This handles parsing of old style starting tokens, and attempts to
        coerce them into the new style.
        zCAttempting to fall back to old starting token parser. For token: %sNZ___rr:r�)�log�debugrJ�splitrmrDr�r4r@r"�"_convert_deprecated_starting_token)r�partsrtr��partrrrr��s"


z-PageIterator._parse_starting_token_deprecatedcCslt|�}t|j�}||kr*td|j��n2||kr\tjd�xt||�D]}|jd�qJWtt	|j|��S)zb
        This attempts to convert a deprecated starting token into the new
        style.
        zBad starting token: %szaOld format starting token does not contain all input tokens. Setting the rest, in order, as None.N)
rmrDr@rJr�r��ranger"rr)rZdeprecated_tokenZlen_deprecated_tokenZlen_input_tokenr&rrrr�s

z/PageIterator._convert_deprecated_starting_tokenN)r-r.r/r>�propertyrVr\�setterrarzrlrhrirkrgrrrjrnror�r�rfr�r�rrrrrB�s(C	
!-rBc@sdeZdZeZdd�Zedd��Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
dd�Zdd�ZdS)�	PaginatorcCsj||_||_||_|j|j�|_|j|j�|_|j|j�|_|j	|j�|_
|j|j�|_|j
|j�|_dS)N)�_modelrC�_pagination_cfg�_get_output_tokensrE�_get_input_tokensrD�_get_more_results_tokenrF�_get_non_aggregate_keys�_non_aggregate_keys�_get_result_keysrG�_get_limit_keyrI)rrR�pagination_configZmodelrrrr>,s
zPaginator.__init__cCs|jS)N)rG)rrrrrV8szPaginator.result_keyscCs.g}x$|jdg�D]}|jtj|��qW|S)NrW)r�r"r{r|)r�configr_r,rrrr�<sz!Paginator._get_non_aggregate_keyscCs>g}|d}t|t�s|g}x|D]}|jtj|��q"W|S)NrT)rrr"r{r|)rr��outputrTrrrr�Bs

zPaginator._get_output_tokenscCs|jd}t|t�s|g}|S)NrS)r�rr)rr�rSrrrr�Ks

zPaginator._get_input_tokenscCs |jd�}|dk	rtj|�SdS)NrU)r�r{r|)rr�rUrrrr�Qs
z!Paginator._get_more_results_tokencCs8|jd�}|dk	r4t|t�s"|g}dd�|D�}|SdS)Nr�cSsg|]}tj|��qSr)r{r|)rbZrkrrrr�[sz.Paginator._get_result_keys.<locals>.<listcomp>)r�rr)rr�r�rrrr�Vs

zPaginator._get_result_keyscCs
|jd�S)NrX)r�)rr�rrrr�^szPaginator._get_limit_keycKsB|j|�}|j|j|j|j|j|j|j|j|d|d|d|�S)z�Create paginator object for an operation.

        This returns an iterable object.  Iterating over
        this object will yield a single page of a response
        at a time.

        �MaxItems�
StartingToken�PageSize)	�_extract_paging_params�PAGE_ITERATOR_CLSrCrDrErFrGr�rI)r�kwargsZpage_paramsrrr�paginateas
zPaginator.paginatecCs�|jdi�}|jdd�}|dk	r(t|�}|jdd�}|dk	r�|jdkrPtdd��|jjj}|j|j�}|jdkr�t	|t
j�s�t|�}nt|�}||jdd�|d�S)	NZPaginationConfigr�r�zTPageSize parameter is not supported for the pagination interface for this operation.)re�stringr�)r�r�r�)
r4r�r�rIrr�Zinput_shape�membersZ	type_namerrr��str)rr�r�rYrZZ
input_membersZlimit_key_shaperrrr�ts$




z Paginator._extract_paging_paramsN)r-r.r/rBr�r>r�rVr�r�r�r�r�r�r�r�rrrrr�)s	r�c@s eZdZdZdd�Zdd�ZdS)r�a�Iterates over the results of paginated responses.

    Each iterator is associated with a single result key.
    Iterating over this object will give you each element in
    the result key list.

    :param pages_iterator: An iterator that will give you
        pages of results (a ``PageIterator`` class).
    :param result_key: The JMESPath expression representing
        the result key.

    cCs||_||_dS)N)�_pages_iteratorr�)rZpages_iteratorr�rrrr>�szResultKeyIterator.__init__ccs@x:|jD]0}|jj|�}|dkr$g}x|D]
}|Vq*WqWdS)N)r�r�rl)rr~rr�rrrrz�s
zResultKeyIterator.__iter__N)r-r.r/r0r>rzrrrrr��sr�)�	itertoolsrZbotocore.compatrr{r
rZloggingZbotocore.exceptionsrrZbotocore.utilsrrZ	getLoggerr-r��objectrr1r<rBr�r�rrrr�<module>s"
ND
nd