o ?cy@sdZddlZddlZddlZddlZddlZddlZddlZddlm Z ddl Z ddl Z ddl m Z ddl mZmZmZmZmZmZmZmZmZmZmZddlmZmZmZddlmZmZm Z ddl!m"Z"m#Z#m$Z$dd l%m&Z&m'Z'm(Z(m)Z)dd l m*Z*dd l m+Z+dd l m,Z,dd lm-Z-ddl%m.Z.ddl%m/Z/e0e1Z2e3Z4e3Z5e6dZ7dZ8dZ9e6d:e8e9gZ;e6dZddZ?ddZ@ddZAdd ZBd!d"ZCd#d$ZDd%d&ZEd'd(ZFd)d*ZGd+d,ZHd-d.ZId/d0ZJdd2d3ZKd4d5ZLd6d7ZMd8d9ZNGd:d;d;ZOdd?ZQd@dAZRdBdCZSdDdEZTdFdGZUdHdIZVdJdKZWdLdMZXdNdOZYdPdQZZdRdSZ[dTdUZ\dVdWZ]dXdYZ^dZd[Z_d\d]Z`d^d_Zad`daZbdbdcZcdddeZddfdgZedhdiZfdjdkZgdldmZhdndoZidpdqZjdrdsZkdtduZldvdwZmdxdyZnGdzd{d{ZoGd|d}d}ZpGd~ddZqddZrddZsddZtgde>fdepdfdeme5fdeme5fde$fde#fdeffdesfdeXfdeDfdeGfdeZfdeEfdeHfdehfdehfdehfdeQfdeQfde]fde]fde]fdePfdePfde?fdeNfde`fdeafde'fde'fde@fde@fdebfdebfdeVfdetfdeefdeAe4fdeAe4fdeAe4fdeMfdeMfdeMfdeMfdeMfdeMfdeCfdeIfdeIfdeIfdeIfdeJfdeIfdeIfdeIfdeJfdeIfde[fde[fde^fde_fdeifdejfdekfdegfdeddjufdedÃjufdedÃjufdecfdedfde\dȃfde\dȃfded˃jufded̃jufded΃jufdedσjufde\dуfdeddgdԢjvfde"fdeWfdeWfdeWfdeWfdeWfded܃jufded܃jufded܃jufded܃jufded܃jufdeWfdeWfded܃jufded܃jufdeWfdeWfded܃jufded܃jufdeOdjwfderfZxenexdS)z_Builtin event handlers. This module contains builtin handlers for events emitted by botocore. N)BytesIO)utils) ETree OrderedDict XMLParseError ensure_bytesget_md5jsonquoteunquote unquote_strurlsplit urlunsplit)AppendParamDocumentationAutoPopulatedParamHideParamFromOperations)AliasConflictParameterErrorParamValidationErrorUnsupportedTLSVersionWarning)add_generate_db_auth_tokenadd_generate_presigned_postadd_generate_presigned_url) SAFE_CHARSconditionally_calculate_md5percent_encodeswitch_host_with_param) retryhandler) translate) MD5_AVAILABLE)MissingServiceIdError)hyphenize_service_id)is_global_accesspointz^[a-zA-Z0-9.\-_]{1,255}$z]^arn:(aws).*:(s3|s3-object-lambda):[a-z\-0-9]*:[0-9]{12}:accesspoint[/:][a-zA-Z0-9\-.]{1,63}$zt^arn:(aws).*:s3-outposts:[a-z\-0-9]+:[0-9]{12}:outpost[/:][a-zA-Z0-9\-]{1,63}[/:]accesspoint[/:][a-zA-Z0-9\-]{1,63}$|z\?versionId=[^\s]+$zruntime.sagemakerzsagemaker-runtimecKs t||SN)SERVICE_NAME_ALIASESget)Z service_namekwargsr'l/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/handlers.pyhandle_service_name_aliasc r)cKsNdtjv}tjd}|r!|r#|d}d|vr%t|dd|d<dSdSdSdS)NZAWS_LAMBDA_FUNCTION_NAMEZ_X_AMZN_TRACE_IDheaderszX-Amzn-Trace-Idz -=;:+&[]{}"',safe)osenvironr%r )paramsr&Zhas_lambda_nameZtrace_idr+r'r'r(add_recursion_detection_headergs  r1cKs<|d}d|vr|dd}d|vr|dd}||d<dS)Nbody s  s )replace)r0r&r2r'r'r(escape_xml_payloadps    r6cKs6|durdS|\}}t|rtd|d|_dSdS)NzWError found for response with 200 status code, errors: %s, changing status code to 500.i)_looks_like_special_case_errorloggerdebug status_code)responser& http_responseparsedr'r'r(check_for_200_errors r>cCs\|jdkr,ztjtdd}||j|}Wn ty$YdSw|jdkr,dSdS)Nutf-8targetencodingTErrorF) r:r XMLParser TreeBuilderfeedcontentclosertag)r<parserrootr'r'r(r7s     r7cKs|d}|s dS|dkrtjS|dkrdS|drL|dkr7d|d}d |vr0|d |n||d <d}nd}|d krAd |d <|d krJd |}|SdS)a'Choose the operation-specific signer. Individual operations may have a different auth type than the service as a whole. This will most often manifest as operations that should not be authenticated at all, but can include other auth modes such as sigv4 without body signing. auth_typeNnoneZbearerZv4Zv4a*)region signing_namesigningzv4-unsigned-bodyFZpayload_signing_enableds3)r%botocoreUNSIGNED startswithupdate)contextrQr&rMrRZsignature_versionr'r'r(set_operation_specific_signers*    rYc Ks`d|vr.ztt|dddd}||d<WdStttfy-tjdddYdSwdS)NOutputzlatin-1r@r5zError decoding base64Texc_info) base64 b64decodebytesdecode ValueError TypeErrorAttributeErrorr8r9r=r&valuer'r'r(decode_console_outputs rfcKs>|jD]}||vrtt||<td|||fqdS)Nz1injecting idempotency token (%s) into param '%s'.)Zidempotent_membersstruuiduuid4r8r9)r0modelr&namer'r'r(generate_idempotent_uuids  rlc Cs<z tt|}W|SttfytjdddY|Sw)NzError loading quoted JSONTr[)r loadsr rarbr8r9)rer'r'r(decode_quoted_jsondocsrnc KsTd|vr(ztj|dtd}||d<WdSttfy'tjdddYdSwdS)N TemplateBody)object_pairs_hookzerror loading JSONTr[)r rmrrarbr8r9rdr'r'r(json_decode_template_bodysrqcKsVd|vrdS|d}t|s't|s)d|dtjdtjd}t|ddSdS)NBucketzInvalid bucket name "z%": Bucket name must match the regex "z#" or be an ARN matching the regex ""report) VALID_BUCKETsearch VALID_S3_ARNpatternr)r0r&bucket error_msgr'r'r(validate_bucket_name s r|cKt|ddS)z S3 server-side encryption requires the encryption key to be sent to the server base64 encoded, as well as a base64-encoded MD5 hash of the encryption key. This handler does both if the MD5 has not been set by the caller. SSECustomerN_sse_md5r0r&r'r'r(sse_md5rcKr})a1 S3 server-side encryption requires the encryption key to be sent to the server base64 encoded, as well as a base64-encoded MD5 hash of the encryption key. This handler does both if the MD5 has not been set by the caller specifically if the parameter is for the copy-source sse-c key. ZCopySourceSSECustomerNrrr'r'r(copy_source_sse_md5#rrr~cCsvt||sdS|d}|d}||}t|tr|d}tt|d}t|d}|||<|||<dS)NKeyKeyMD5r@) _needs_s3_sse_customization isinstancergencoder] b64encoderdigestr`)r0sse_member_prefixZsse_key_memberZsse_md5_memberZ key_as_bytesZ key_md5_strZkey_b64_encodedr'r'r(r-s    rcCs||dduo|d|vS)Nrrr%)r0rr'r'r(r>s rcKstjS)zk This handler disables request signing by setting the signer name to a special sentinel value. )rTrU)r&r'r'r(disable_signingEsrcKsR|jdddvr dSd|vr%|d}t|dr'tdd|dd <dSdSdS) Nmethod)PUTPOSTr2readz-Adding expect 100 continue header to request.z 100-continuer+ZExpect)httpr%hasattrr8r9)rjr0r&r2r'r'r(add_expect_headerMs  rc@eZdZddZddZdS)DeprecatedServiceDocumentercC ||_dSr#)_replacement_service_name)selfZreplacement_service_namer'r'r(__init__Z z$DeprecatedServiceDocumenter.__init__cKs>|j|d|j|j|j|d|jdS)Nz.This service client is deprecated. Please use z instead.)styleZstart_importantwriterefrZ end_important)rsection event_namer&r'r'r(inject_deprecation_notice]s   z5DeprecatedServiceDocumenter.inject_deprecation_noticeN)__name__ __module__ __qualname__rrr'r'r'r(rYs rc Ksd|vr|d}|d}|d}||ddSd|vrE|d}|d}||d|d }||d dSdS) Nzrequest-examplestructure-value CopySource member-valuezH'string' or {'Bucket': 'string', 'Key': 'string', 'VersionId': 'string'}zrequest-params param-typez:type CopySource: str or dictzparam-documentationaqThe name of the source bucket, key name of the source object, and optional version ID of the source object. You can either provide this value as a string or a dictionary. The string form is {bucket}/{key} or {bucket}/{key}?versionId={versionId} if you want to copy a specific version. You can also provide this value as a dictionary. The dictionary format is recommended over the string format because it is more explicit. The dictionary format is: {'Bucket': 'bucket', 'Key': 'key', 'VersionId': 'id'}. Note that the VersionId key is optional and may be omitted. To specify an S3 access point, provide the access point ARN for the ``Bucket`` key in the copy source dictionary. If you want to provide the copy source for an S3 access point as a string instead of a dictionary, the ARN provided must be the full S3 access point object ARN (i.e. {accesspoint_arn}/object/{key}) get_section clear_textr) rrr&parent param_line value_portion param_section type_sectionZ doc_sectionr'r'r(document_copy_source_formhs&       rcKsN|d}|dur dSt|trt||d<dSt|tr%t||d<dSdS)aHConvert CopySource param for CopyObject/UploadPartCopy. This handler will deal with two cases: * CopySource provided as a string. We'll make a best effort to URL encode the key name as required. This will require parsing the bucket and version id from the CopySource value and only encoding the key. * CopySource provided as a dict. In this case we're explicitly given the Bucket, Key, and VersionId so we're able to encode the key and ensure this value is serialized and correctly sent to S3. rN)r%rrg_quote_source_headerdict_quote_source_header_from_dict)r0r&sourcer'r'r(handle_copy_source_params   rc Csz#|d}|d}|d}t|r|d|}n|d|}Wnty9}z tdt|dd}~wwt|tdd}|durL|d |7}|S) NrrrZ VersionIdz/object//zMissing required parameter: rtr,z ?versionId=%s)r%rxrwKeyErrorrrgrr)Z source_dictrzkey version_idfinaler'r'r(rs$    rcCsXt|}|durt|tddS|d|||d}}t|tdd|S)Nrr,)VERSION_ID_SUFFIXrwrrstart)reresultfirstrr'r'r(rs "rcCsLt|}||dd<|d|||d<d|d<i|d<|j|||jdS)Nr2DestinationRegionurlGETrr+)Z region_nameZoperation_name)copydeepcopyr5Zgenerate_presigned_urlrk)request_signer request_dictrj source_regiondestination_regionZrequest_dict_copyr'r'r(_get_cross_region_presigned_urls rcCs|j}|d}||fS)N SourceRegion)Z _region_namer%)rr0rrr'r'r(1_get_presigned_url_source_and_destination_regionss rcKsNd|dvrdSt||d\}}t|||||}||dd<||dd<dS)N PresignedUrlr2rrrr0rrjr&srcdestrr'r'r(inject_presigned_url_ec2s   rcKs\d|dvrdSt||d\}}|dd=d|dvrdSt|||||}||dd<dS)Nrr2 PreSignedUrlrrr'r'r(inject_presigned_url_rdss    rcKs"|j}|durt||jdSdSr#) output_shape_decode_policy_types)r=rjr&rr'r'r(json_decode_policies srcCsd}|jdkr3|jD]&\}}|jdkr'|j|kr'||vr't||||<q ||vr2t|||q |jdkrE|j}|D] }t||q=dSdS)NZpolicyDocumentTypeZ structurestringlist) type_namemembersitemsrkrnrmember)r=shapeZ shape_name member_nameZ member_shapeZ shape_memberitemr'r'r(rs*    rcKsJ|jdurdS|j}tjtdd}|||}|j}||d<dS)Nr@rAZLocationConstraint)rawrHrrErFrGrItext)r=r<r&Z response_bodyrKrLrPr'r'r(parse_get_bucket_location,s   rcKsHd|vr"t|dtr|dd|d<t|dd|d<dSdS)NUserDatar@)rrgrr]rr`rr'r'r(base64_encode_user_data<s rcCsd}t||}|jS)Nzw**This value will be base64 encoded automatically. Do not base64 encode this value prior to performing the operation.**rZappend_documentation)param descriptionappendr'r'r(document_base64_encodingFs rc Ksn|d}|r t|tsdS|D]"\}}z |d|dWqty4d||f}t|dwdS)aEVerify S3 Metadata only contains ascii characters. From: http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingMetadata.html "Amazon S3 stores user-defined metadata in lowercase. Each name, value pair must conform to US-ASCII when using REST and UTF-8 when using SOAP or browser-based uploads via POST." ZMetadataNasciizvNon ascii characters found in S3 metadata for key "%s", value: "%s". S3 metadata can only contain ASCII characters. rt)r%rrrrUnicodeEncodeErrorr)r0r&metadatarrer{r'r'r(validate_ascii_metadataPs    rcKsp|j}|r t|ds dSdd|jD}|D]}||vr5||}|dd||<td||||qdS)z Check for and split apart Route53 resource IDs, setting only the last piece. This allows the output of one operation (e.g. ``'foo/1234'``) to be used as input in another operation (e.g. it expects just ``'1234'``). rNcSsg|] \}}|jdvr|qS))Z ResourceIdZDelegationSetIdZChangeId)rk).0rkrr'r'r( zs z#fix_route53_ids..rz %s %s -> %s) input_shaperrrsplitr8r9)r0rjr&rrrkZ orig_valuer'r'r(fix_route53_idsosrcKs|ddur d|d<dSdS)N accountId-rrr'r'r(inject_account_ids rcKs|}|jd|dd<dS)NZ apiVersionr+zx-amz-glacier-version)rrjr0r&rr'r'r(add_glacier_versionsrcKs,|ddddur|}d|dd<dSdS)Nr+Acceptzapplication/jsonrrr'r'r(add_accept_headersrcKsv|}|d}|d}t|trt|}|}d|vr$tj|dd|d<||d|vr4t||d<||dS)zAdd glacier checksums to the http request. This will add two headers to the http request: * x-amz-content-sha256 * x-amz-sha256-tree-hash These values will only be added if they are not present in the HTTP request. r+r2zx-amz-content-sha256T)Zas_hexzx-amz-sha256-tree-hashN)rr_rtellrZcalculate_sha256seekZcalculate_tree_hash)r0r&rr+r2Zstarting_positionr'r'r(add_glacier_checksumss   rcCsd}td|jS)Na This is a required field. Ideally you will want to compute this value with checksums from previous uploaded parts, using the algorithm described in `Glacier documentation `_. But if you prefer, you can also use botocore.utils.calculate_tree_hash() to compute it from raw file by:: checksum = calculate_tree_hash(open('your_file.txt', 'rb')) checksumr)docr'r'r(#document_glacier_tree_hash_checksums rcKsrd|vr|d}|d}||ddSd|vr7|d}|d}|d}||ddSdS) Nzresponse-paramsrorz (*dict*) --zresponse-examplerrz{}r)rrr&Ztemplate_body_sectionrrrrr'r'r(0document_cloudformation_get_template_return_types     rcKst|ddS)NZPredictEndpoint)rrequestr&r'r'r(switch_host_machinelearningsrcKsJddl}z|j}|dkrtd|jtWdSWdSty$YdSw)Nr)rrzCurrently installed openssl version: %s does not support TLS 1.2, which is required for use of iot-data. Please use python installed with openssl version 1.0.1 or higher.)sslOPENSSL_VERSION_INFOwarningswarnOPENSSL_VERSIONrrc)r&r Zopenssl_version_tupler'r'r(&check_openssl_supports_tls_version_1_2s  rcKsF|jdkrd|jvr!d|jd<d|_|jdd\|_|_dSdSdS)Nr?z!application/x-www-form-urlencodedz Content-Typerr)rrr+rdatarr'r'r(change_get_to_posts  rcKs d|vrd|d<d|d<dSdS)N EncodingTypeTencoding_type_auto_setrr')r0rXr&r'r'r("set_list_objects_encoding_type_urls rcKtgdddg||ddS)N) DelimiterMarkerZ NextMarkerZContentsrZCommonPrefixesPrefixtop_level_keys nested_keysr=rX_decode_list_objectr=rXr&r'r'r(decode_list_objects   r!cKr)N)rrZ StartAfterrrrrr r'r'r(decode_list_object_v2s  r"cKstgdgd||ddS)N)Z KeyMarkerZ NextKeyMarkerrr))ZVersionsr)Z DeleteMarkersrrrrr r'r'r(decode_list_object_versions%s  r#cCsz|ddkr7|dr9|D]}||vrt||||<q|D]\}}||vr6||D] }t||||<q+qdSdSdS)Nrrr)r%r )rrr=rXrZtop_keyZ child_keyrr'r'r(r;s  rcKsXd|vr(t|dtrtt|d|d<dSt|dtr*t|d|d<dSdSdS)NZBody)rrgrrr_rr'r'r( convert_body_to_file_like_objectJsr$c Csrdddd}|D],\}}|dd\}}t||}d||jtf}d|d |jf}||||q dS) NZFiltersZfromTimeZ returnFields)z ec2.*.Filterzlogs.CreateExportTask.fromzcloudsearchdomain.Search.return.rzbefore-parameter-build.zdocs.*.z.complete-section)rrsplitParameterAliasalias_parameter_in_callREGISTER_FIRST alias_parameter_in_documentationr) Z handler_listaliasesoriginalnew_nameZ event_portion original_nameZparameter_aliasZ#parameter_build_event_handler_tupleZdocs_event_handler_tupler'r'r(_add_parameter_aliasesRs"    r/c@s,eZdZddZddZddZddZd S) r'cCs||_||_dSr#)_original_name _alias_name)rr.Z alias_namer'r'r(rts zParameterAlias.__init__cKs^|jr)|j|jjvr+|j|vr-|j|vrt|j|j|jd||j||j<dSdSdSdS)N)r,aliasZ operation)rr0rr1rrkpop)rr0rjr&r'r'r(r(xs  z&ParameterAlias.alias_parameter_in_callcKs|dr)|j|jvr dS||j}|d}|||d}||dS|drH|d}|j|jvr;dS||j}||dSdS)Nzdocs.request-paramsrz param-namezdocs.request-exampler)rVr0Zavailable_sectionsr_replace_content)rrrr&rZparam_type_sectionZparam_name_sectionr'r'r(r*s          z/ParameterAlias.alias_parameter_in_documentationcCs4|d}||j|j}|||dS)Nr@)getvaluer`r5r0r1rr)rrrHZupdated_contentr'r'r(r4s zParameterAlias._replace_contentN)rrrrr(r*r4r'r'r'r(r'ss  r'c@r)ClientMethodAliascCs ||_dS)zAliases a non-extant method to an existing method. :param actual_name: The name of the method that actually exists on the client. N)_actual)rZ actual_namer'r'r(rs zClientMethodAlias.__init__cKs t||jSr#)getattrr7)rclientr&r'r'r(__call__r*zClientMethodAlias.__call__N)rrrrr:r'r'r'r(r6s r6c@s>eZdZdZedejZddZddZ ddZ d d Z d S) HeaderToHostHoisterz;Takes a header and moves it to the front of the hoststring.z(?!-)[a-z\d-]{1,63}(?s z0HeaderToHostHoister._ensure_header_is_valid_hostcCsHt|}|jd}|g|}d|}|j||j|jdf}t|}|S)Nr%r)r netlocrjoinschemepathqueryr)rrprefixZurl_componentspartsZ new_netlocZnew_componentsrBr'r'r(r?s   z$HeaderToHostHoister._prepend_to_hostN) rrr__doc__recompile IGNORECASErDrrCr>r?r'r'r'r(r;s r;cKs|jsdS|jj|dd<dS)Nr+zx-amz-api-version)Zis_endpoint_discovery_operationZ service_model api_version)rjr0r&r'r'r(#inject_api_version_header_if_neededsrScKsd|vr |d=dSdS)z>Operation requires h2 which is currently unsupported in PythonZstart_conversationNr')Zclass_attributesr&r'r'r( remove_lex_v2_start_conversations rTc sN|jds dS|j}d|d<d}fdd|D}d||d<dS) Nretriesz invocation-idzamz-sdk-invocation-id)ttlattemptmaxcs&g|]}|vr|d|qS)=r')rrZretries_contextr'r(rs z%add_retry_headers..z; zamz-sdk-request)rXr%r+rH)rr&r+Zsdk_retry_keysZsdk_request_headersr'rZr(add_retry_headerss   r[zchoose-service-namez/getattr.mturk.list_hi_ts_for_qualification_typeZ list_hits_for_qualification_typez$before-parameter-build.s3.UploadPartz#before-parameter-build.s3.PutObjectzcreating-client-classzcreating-client-class.s3zcreating-client-class.iot-dataz$creating-client-class.lex-runtime-v2zafter-call.iamzafter-call.ec2.GetConsoleOutputz%after-call.cloudformation.GetTemplatezafter-call.s3.GetBucketLocationzbefore-parameter-buildzbefore-parameter-build.s3z%before-parameter-build.s3.ListObjectsz'before-parameter-build.s3.ListObjectsV2z,before-parameter-build.s3.ListObjectVersionsz$before-parameter-build.s3.CopyObjectz(before-parameter-build.s3.UploadPartCopyz/before-parameter-build.s3.CreateMultipartUploadz%docs.*.s3.CopyObject.complete-sectionz)docs.*.s3.UploadPartCopy.complete-sectionz before-callzbefore-call.s3zbefore-call.glacierzbefore-call.apigatewayzbefore-call.s3.PutObjectzbefore-call.s3.UploadPartzbefore-call.s3.DeleteObjectsz.before-call.s3.PutBucketLifecycleConfigurationz!before-call.glacier.UploadArchivez'before-call.glacier.UploadMultipartPartzbefore-call.ec2.CopySnapshotzrequest-createdz'request-created.machinelearning.Predictzneeds-retry.s3.UploadPartCopyzneeds-retry.s3.CopyObjectz&needs-retry.s3.CompleteMultipartUploadz$choose-signer.cognito-identity.GetIdz-choose-signer.cognito-identity.GetOpenIdTokenz-choose-signer.cognito-identity.UnlinkIdentityz8choose-signer.cognito-identity.GetCredentialsForIdentityz$choose-signer.sts.AssumeRoleWithSAMLz+choose-signer.sts.AssumeRoleWithWebIdentityz choose-signerz$before-parameter-build.s3.HeadObjectz#before-parameter-build.s3.GetObjectz-before-parameter-build.s3.SelectObjectContentz'before-parameter-build.ec2.RunInstanceszr7rYrfrlrnrqr|rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr!r"r#rr$r/r'r6r;rSrTr[Zdocument_auto_populated_paramZ hide_paramrZBUILTIN_HANDLERSr'r'r'r(sd   4           0     %     !  !21 #&'()+./0123456789:;<=>@DEFHKLMNOPQRSTUVWXZ]^_`acfnrv{ $<=>?@BGKOSW]^aeklosz