o .&a.@sdZddlZddlmZddlmZddlmZmZddlm Z ddl m Z e e ZdZd Zd Zd d Zd dZddZddZddZddZddZddZddZddZdd ZGd!d"d"e ZdS)#a'This module has customizations to unify paging paramters. For any operation that can be paginated, we will: * Hide the service specific pagination params. This can vary across services and we're going to replace them with a consistent set of arguments. The arguments will still work, but they are not documented. This allows us to add a pagination config after the fact and still remain backwards compatible with users that were manually doing pagination. * Add a ``--starting-token`` and a ``--max-items`` argument. N)partial) xform_name)DataNotFoundErrorPaginationError)model)BaseCLIArgumenta/

A token to specify where to start paginating. This is the NextToken from a previously truncated response.

For usage examples, see Pagination in the AWS Command Line Interface User Guide.

a`

The total number of items to return in the command's output. If the total number of items available is more than the value specified, a NextToken is provided in the command's output. To resume pagination, provide the NextToken value in the starting-token argument of a subsequent command. Do not use the NextToken response element directly outside of the AWS CLI.

For usage examples, see Pagination in the AWS Command Line Interface User Guide.

a

The size of each page to get in the AWS service call. This does not affect the number of items returned in the command's output. Setting a smaller page size results in more calls to the AWS service, retrieving fewer items in each call. This can help prevent the AWS service calls from timing out.

For usage examples, see Pagination in the AWS Command Line Interface User Guide.

cCs|dt|dtdS)Nzbuilding-argument-tablezdoc-description)registerunify_paging_params register_lastadd_paging_description)event_handlersr @/usr/lib/python3/dist-packages/awscli/customizations/paginate.pyregister_paginationLs rcCsJz||}Wn tyYdSwz||}W|Sty$YdSwN)get_paginator_modelr get_paginator ValueError)session service_nameoperation_namepaginator_modeloperation_paginator_configr r rget_paginator_configQs  rcKst|jtjs dS|jjj}t|j||jj}|sdS|j j |j d|j| drP|d}t|tur<|g}ddd|D}|j d|dSdS)Nz``%s`` is a paginated operation. Multiple API calls may be issued in order to retrieve the entire data set of results. You can disable pagination by providing the ``--no-paginate`` argument. result_key, cSsg|]}d|qS)z``%s``r ).0sr r r ssz*add_paging_description..zWhen using ``--output text`` and the ``--query`` argument on a paginated response, the ``--query`` argument must extract data from the results of the following query expressions: %s) isinstanceobjrOperationModel service_modelrrrnamedocstyle new_paragraphwritelngettypelistjoin) help_commandkwargsrpaginator_configqueriesr r rr ^s2     r c Kst||jj|j}|durdStd|jt|||dd}i}t|dt dt ddd||j j }d} d |vra||d } | j } | t jvrTtd | |j|d t|d t d t| d d|t|d t d t| dd|||tttt|||dS)Nz-Modifying paging parameters for operation: %szbuilding-argument-table.zoperation-args-parsed.zstarting-tokenstring StartingToken) parse_typeserialized_nameinteger limit_keyzCUnsupported pagination type {0} for operation {1} and parameter {2}z page-sizePageSizez max-itemsMaxItems)rr"rr#loggerdebug!_remove_existing_paging_argumentsreplaceadd_paging_argument PageArgumentSTARTING_TOKEN_HELP input_shapemembers type_nametype_map TypeErrorformatPAGE_SIZE_HELPMAX_ITEMS_HELPrrcheck_should_enable_paginationr*_get_all_cli_input_tokens) argument_tableoperation_model event_namerr-r.parsed_args_event shadowed_args input_membersrAlimit_key_shaper r rr {sn    r cCs ||vr ||||<|||<dSrr )rIarg_nameargumentrMr r rr<s  r<c Ksvddg}|D]}|dd}t||dur!||vr!tdd|_q|js7t|||D] \} } | || <q.dSdS)N start_token max_items-_zPUser has specified a manual pagination arg. Automatically setting --no-paginate.F)r;getattrr8r9paginateensure_paging_params_not_setitems) input_tokensrMrI parsed_argsparsed_globalsr-normalized_paging_argstokenpy_namekeyvaluer r rrGs     rGcs`gd}dd|Dfdd|D}t|dkr.ddd|D}td|d dS) N)starting_token page_sizerScSsg|]}|ddqS)rTrUr;rpr r rrsz0ensure_paging_params_not_set..cs$g|]}|vrt|dr|qSr)rVrer[shadowed_paramsr rrsrrcSsg|] }d|ddqS)--rUrTrdrer r rrsz@Cannot specify --no-paginate along with pagination arguments: %s)message)keyslenr+r)r[rM paging_params params_usedconverted_paramsr rgrrXs  rXcCst|D]}d||_qdS)NT)rH _UNDOCUMENTED)rIpagination_configcli_namer r rr:s  r:ccsLt|}|D] }t|d}|Vqd|vr$|d}t|d}|VdSdS)NrTr5)_get_input_tokensr)rqtokens token_namerrkey_namer r rrHs   rHcCs|d}t|ts |gS|S)N input_token)rr*)rqrtr r rrss rscCs(|D]}|j|kr|jdSqdS)NrT)r#rrlstrip) param_objectsruparamr r r _get_cli_names  r{c@sneZdZeeedZddZeddZeddZ edd Z e j d d Z ed d Z d dZ ddZdS)r=)r0r4longcCs4tdddi|_||_||_||_||_d|_dS)Nr=r)r0F)rShapeargument_model_name_serialized_name_documentation _parse_type _required)selfr# documentationr2r3r r r__init__s  zPageArgument.__init__cCs d|jS)Nri)rrr r rrr  zPageArgument.cli_namecC|jSr)rrr r r cli_type_namezPageArgument.cli_type_namecCrrrrr r rrequiredrzPageArgument.requiredcCs ||_dSrr)rrar r rrrcCrr)rrr r rrrzPageArgument.documentationcCs |j|j|j|j|jddS)N)destr)) add_argumentrrr_rBr)rparserr r r add_to_parser!s   zPageArgument.add_to_parsercCs.|dur|di}|||j<||d<dSdS)NPaginationConfig)r(r)r parametersrarqr r r add_to_params%s    zPageArgument.add_to_paramsN)__name__ __module__ __qualname__strintrBrpropertyrrrrsetterrrrr r r rr=s$      r=)__doc__logging functoolsrbotocorerbotocore.exceptionsrrrawscli.argumentsr getLoggerrr8r>rFrErrr r r<rGrXr:rHrsr{r=r r r rs.         0