U!\c@sddlmZddlmZddlZddlZddlZddlZddlm Z ddlm Z ddl m Z m Z ejeZdefdYZd efd YZd efd YZd efdYZdefdYZdefdYZdS(i(ttee(tsixN(tPaginationError(tzip(tset_value_from_jmespatht merge_dictst TokenEncodercBs;eZdZdZdZdZdZdZRS(sbEncodes 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. cCs}ytj|}WnHttfk r]|j|g\}}||d|j||St|tjr`|j||S|gfSdS(s@Encode bytes in given data, keeping track of the path traversed.N(t isinstancetdictt _encode_dicttlistt _encode_listRt binary_typet _encode_bytes(Rtdatatpath((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR Fsc Csrg}g}xYt|D]K\}}||g}|j||\}} |j||j| qW||fS(s@Encode any bytes in a list, noting the index of what is encoded.(t enumerateR tappendtextend( RRRtnew_datatencodedtitvaluetnew_patht new_valuet new_encoded((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRQs  c Csoi}g}xV|jD]H\}}||g}|j||\}} |||<|j| qW||fS(s@Encode any bytes in a dict, noting the index of what is encoded.(titemsR R!( RRRR"R#tkeyR%R&R'R(((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR\s  cCstj|jd|gfS(sBase64 encode a byte string.sutf-8(R RR(RRR((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRgs(t__name__t __module__t__doc__RR RRR(((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRs    t TokenDecodercBs2eZdZdZdZdZdZRS(sDecodes token strings back into dictionaries. This performs the inverse operation to the TokenEncoder, accepting opaque strings and decoding them into a useable form. cCsftj|jdjd}tj|}|jdd}|dkrR|S|j||SdS(sdDecodes 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. sutf-8RN( R t b64decodeRRRtloadstpoptNonet_decode(RRRt decoded_tokenR((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRss ! cCsRxK|D]C}|j||}tj|jd}|j|||qW|S(s&Find each encoded value and decode it.sutf-8(t _path_getR R/Rt _path_set(RRRR*R#tdecoded((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR3s  cCs%|}x|D]}||}q W|S(sReturn the nested data at the given path. For instance: data = {'foo': ['bar', 'baz']} path = ['foo', 0] ==> 'bar' ((RRRtdtstep((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR5s  cCs(|j||d }|||d data = {'foo': ['bar', 'bin']} iN(R5(RRRR%t container((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR6s (R+R,R-RR3R5R6(((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR.ls    tPaginatorModelcBseZdZdZRS(cCs|d|_dS(Nt pagination(t_paginator_config(Rtpaginator_config((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyt__init__scCs9y|j|}Wn!tk r4td|nX|S(Ns*Paginator for operation does not exist: %s(R=tKeyErrort ValueError(Rtoperation_nametsingle_paginator_config((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyt get_paginators  (R+R,R?RD(((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR;s t PageIteratorcBseZdZedZedZejdZedZdZdZ dZ dZ d Z d Z d Zd Zd ZdZdZdZdZdZdZRS(c Cs||_||_||_||_||_||_||_| |_| |_| |_ d|_ ||_ i|_ t|_t|_dS(N(t_methodt _input_tokent _output_tokent _more_resultst _result_keyst _max_itemst _limit_keyt_starting_tokent _page_sizet _op_kwargsR2t _resume_tokent_non_aggregate_key_exprst_non_aggregate_partRt_token_encoderR.t_token_decoder( Rtmethodt input_tokent output_tokent more_resultst result_keystnon_aggregate_keyst limit_keyt max_itemststarting_tokent page_sizet op_kwargs((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR?s              cCs|jS(N(RJ(R((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRYscCs|jS(s&Token to specify to resume pagination.(RP(R((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyt resume_tokenscCst|ts"td|nd|krGt|jdg}nt|j}t|j}||kr|jj||_ntd|dS(NsBad starting token: %stboto_truncate_amount( RRRAtsortedRGtkeysRSRRP(RR%t token_keyst dict_keys((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyR`s  cCs|jS(N(RR(R((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pytnon_aggregate_partsccs(|j}d}td|jD}|jdk rJ|jd}nd}t}|jd}d}|j|xtr#|j |}|j |} |r|jdk r|j | ||}nt }|j | nd}|j| } | dkr g} nt| } d} |jdk r?|| |j} n| dkrm|j| || |||VPqy|V|| 7}|j| }td|jDrPn|jdk r||jkr||_Pn|dk r ||kr d|} td| n|j|||}qyWdS(Ncss|]}|dfVqdS(N(R2(t.0R*((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pys sicss|]}|dkVqdS(N(R2(Rgtt((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pys !ss*The same next token was received twice: %stmessage(ROR2RRGRMt_parse_starting_tokentTrueRYt_inject_starting_paramst _make_requestt_extract_parsed_responset_handle_first_requesttFalset _record_non_aggregate_key_valuestsearchtlenRKt_truncate_responset_get_next_tokentalltvaluesR`Rt_inject_token_into_kwargs(Rtcurrent_kwargstprevious_next_tokent next_tokent total_itemst first_requesttprimary_result_keytstarting_truncationtresponsetparsedtcurrent_responsetnum_current_responsettruncate_amountRi((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyt__iter__sd              ccs`tj|}xJ|D]B}|j|}t|trSx|D] }|VqAWq|VqWdS(sApplies 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(tjmespathtcompileRrRR(Rt expressiontcompiledtpagetresultstelement((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRr1s   cCs |j|S(N(RF(RRy((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRmKscCs|S(N((RR((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRnNscCsIi}x3|jD](}|j|}t||j|qW||_dS(N(RQRrRRRR(RRRZRtresult((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRqQs cCsX|jdk r2|jd}|j||n|jdk rT|j||j|dkr>|||Wq WdS(N(RRRrR2(RRRR((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRs    (R+R,R-R?R(((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyRs  (t itertoolsRtbotocore.compatRRRR tloggingtbotocore.exceptionsRRtbotocore.utilsRRt getLoggerR+RtobjectRR.R;RERR(((s5/tmp/pip-install-usGedi/botocore/botocore/paginate.pyts     ND kd