3 B\Ӫh@sZdZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z mZmZmZmZmZmZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lm Z ddl!m"Z"m#Z#ddl!m$Z$ddl!m%Z%ddl&m'Z'ddl&m(Z(ddl&m)Z)ddl&Z&ddl*Z&ej+e,Z-e.Z/e.Z0ej1dZ2ej1dZ3ddiZ4ddZ5ddZ6ddZ7ddZ8d d!Z9d"d#Z:d$d%Z;d&d'Zd,d-Z?d.d/Z@d0d1ZAd2d3ZBd4d5ZCdd7d8ZDd9d:ZEd;d<ZFd=d>ZGGd?d@d@e.ZHdAdBZIdCdDZJdEdFZKdGdHZLdIdJZMdKdLZNdMdNZOdOdPZPdQdRZQdSdTZRdUdVZSdWdXZTdYdZZUd[d\ZVd]d^ZWd_d`ZXdadbZYdcddZZdedfZ[dgdhZ\didjZ]dkdlZ^dmdnZ_dodpZ`dqdrZadsdtZbdudvZcdwdxZddydzZed{d|ZfGd}d~d~e.ZgGddde.ZhGddde.ZiddZjde5fdehdfdeee0fdeee0fdefdefde_fdeQfde9fdeytjt|}Wn&ttfk r8tjdddYnX|S)NzError loading quoted JSONT)rC)rloadsrrHrIr$r%)rKr r r!decode_quoted_jsondocs rTc KsRd|krNytj|dtd}||d<Wn&ttfk rLtjdddYnXdS)N TemplateBody)object_pairs_hookzerror loading JSONT)rC)rrSr rHrIr$r%)r)rrKr r r!json_decode_template_bodys rWcKs`|}|dr\d|dkr\|d}t|ttfr8t|}nt|}tj|jd}||dd<dS)Nbodyz Content-MD5headersascii) isinstancebytes bytearray_calculate_md5_from_bytes_calculate_md5_from_filerD b64encoderG)rOr request_dictrXZ binary_md5Z base64_md5r r r! calculate_md5s rbcCst|}|jS)N)rdigest)Z body_bytesmd5r r r!r^sr^csFj}t}x$tfdddD]}|j|q"Wj||jS)Ncs jdS)Nii)readr )fileobjr r!sz*_calculate_md5_from_file..)tellriterupdateseekrc)rfZstart_positionrdchunkr )rfr!r_s  r_cKstrt|f|dS)z1Only add a Content-MD5 if the system supports it.N)rrb)rOr@request_signerrr r r!conditionally_calculate_md5srocKs>d|kr dS|d}tj|dkr:d|tjf}t|ddS)NBucketz?Invalid bucket name "%s": Bucket name must match the regex "%s")report) VALID_BUCKETsearchpatternr)rOrbucket error_msgr r r!validate_bucket_names rwcKst|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_md5)rOrr r r!sse_md5srzcKst|ddS)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. ZCopySourceSSECustomerN)ry)rOrr r r!copy_source_sse_md5sr{rxcCsxt||sdS|d}|d}||}t|tjr<|jd}tjt|jj d}tj|j d}|||<|||<dS)NKeyKeyMD5zutf-8) _needs_s3_sse_customizationr[r text_typeencoderDr`rrcrG)rOsse_member_prefixZsse_key_memberZsse_md5_memberZ key_as_bytesZ key_md5_strZkey_b64_encodedr r r!rys   rycCs|j|ddk o|d|kS)Nr|r})r)rOrr r r!r~sr~cKstjS)zk This handler disables request signing by setting the signer name to a special sentinel value. )r=r>)rr r r!disable_signing srcKsJ|jjddd krdSd|krF|d}t|drFtjdd|d d <dS) NmethodPUTPOSTrXrez-Adding expect 100 continue header to request.z 100-continuerYZExpect)rr)httprhasattrr$r%)rPrOrrXr r r!add_expect_headers  rc@seZdZddZddZdS)DeprecatedServiceDocumentercCs ||_dS)N)_replacement_service_name)selfZreplacement_service_namer r r!__init__ sz$DeprecatedServiceDocumenter.__init__cKs>|jj|jd|jj|j|j|jd|jjdS)Nz.This service client is deprecated. Please use z instead.)styleZstart_importantwriterefrZ end_important)rsection event_namerr r r!inject_deprecation_notice#s   z5DeprecatedServiceDocumenter.inject_deprecation_noticeN)__name__ __module__ __qualname__rrr r r r!rsrc Ksd|kr:|jd}|jd}|jd}|j|jdnJd|kr|jd}|jd}|j|jd|jd }|j|jd dS) Nzrequest-examplezstructure-value CopySourcez member-valuezH'string' or {'Bucket': 'string', 'Key': 'string', 'VersionId': 'string'}zrequest-paramsz param-typez:type CopySource: str or dictzparam-documentationa9The 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.) get_section clear_textr) rrrparent param_line value_portion param_section type_sectionZ doc_sectionr r r!document_copy_source_form.s        rcKsJ|jd}|dkrdSt|tjr0t||d<nt|trFt||d<dS)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)rr[r string_types_quote_source_headerdict_quote_source_header_from_dict)rOrsourcer r r!handle_copy_source_paramKs   rcCsy*|d}t|dtdd}|jd}Wn4tk r^}ztdt|dWYdd}~XnXd||f}|dk r|d |7}|S) Nrpr|/)safeZ VersionIdzMissing required parameter: %s)rqz%s/%sz ?versionId=%s)rrrKeyErrorrrM)Z source_dictrukey version_idefinalr r r!rfs"  rcCs\tj|}|dkr"t|tddS|d|j||jd}}t|tdd|SdS)Nr)r)VERSION_ID_SUFFIXrsrrstart)rKresultfirstrr r r!rts  "rcCsLtj|}||dd<|dj|||d<d|d<i|d<|j|||jdS)NrXDestinationRegionurlGETrrY)Z region_nameZoperation_name)copydeepcopyrBZgenerate_presigned_urlrQ)rnrarP source_regiondestination_regionZrequest_dict_copyr r r!_get_cross_region_presigned_url}s   rcCs|j}|jd}||fS)N SourceRegion)Z _region_namer)rnrOrrr r r!1_get_presigned_url_source_and_destination_regionss rcKsNd|dkrdSt||d\}}t|||||}||dd<||dd<dS)N PresignedUrlrXr)rr)rOrnrPrsrcdestrr r r!inject_presigned_url_ec2s  rcKs\d|dkrdSt||d\}}|dd=d|dkr+sz#fix_route53_ids..rz %s %s -> %s) input_shaperrrsplitr$r%)rOrPrrrrQZ orig_valuer r r!fix_route53_ids s rcKs|jddkrd|d<dS)N accountId-)r)rOrr r r!inject_account_id5srcKs|}|jd|dd<dS)NZ apiVersionrYzx-amz-glacier-version)r)rPrOrrar r r!add_glacier_version>srcKs(|djdddkr$|}d|dd<dS)NrYAcceptzapplication/json)r)rPrOrrar r r!add_accept_headerDsrcKsz|}|d}|d}t|tjr*tj|}|j}d|krLtj|dd|d<|j|d|krltj||d<|j|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. rYrXzx-amz-content-sha256T)Zas_hexzx-amz-sha256-tree-hashN) r[r binary_typeBytesIOrirZcalculate_sha256rlZcalculate_tree_hash)rOrrarYrXZstarting_positionr r r!add_glacier_checksumsJs    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')) checksum)rr)docr r r!#document_glacier_tree_hash_checksumjs rcKsld|kr0|jd}|jd}|j|jdn8d|krh|jd}|jd}|jd}|j|jddS) Nzresponse-paramsrUz param-typez (*dict*) --zresponse-examplezstructure-valuez member-valuez{})rrr)rrrZtemplate_body_sectionrrrrr r r!0document_cloudformation_get_template_return_type{s      rcKst|ddS)NZPredictEndpoint)r)requestrr r r!switch_host_machinelearningsrc KsFddl}y$|j}|dkr*tjd|jtWntk r@YnXdS)NrrzCurrently 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.)rrr)sslOPENSSL_VERSION_INFOwarningswarnOPENSSL_VERSIONrrJ)rrZopenssl_version_tupler r r!&check_openssl_supports_tls_version_1_2s rcKs>|jdkr:d|jkr:d|jd<d|_|jjdd\|_|_dS)Nr?z!application/x-www-form-urlencodedz Content-Typerr)rrrYrdata)rrr r r!change_get_to_posts rcKsd|krd|d<d|d<dS)N EncodingTypeTencoding_type_auto_setrr )rOr@rr r r!"set_list_objects_encoding_type_urlsrcKstdddgd d g||ddS) N DelimiterMarkerZ NextMarkerContentsr|CommonPrefixesPrefix)top_level_keys nested_keysr)r@)rr|)rr)_decode_list_object)r)r@rr r r!decode_list_objects rcKstdddgdd g||ddS) NrrZ StartAfterrr|r)rrr)r@)rr|)rr)r)r)r@rr r r!decode_list_object_v2s rcCs~|jddkrz|jdrzx$|D]}||krt||||<qWx:|D]2\}}||krDx ||D]}t||||<q^WqDWdS)Nrrr)rr)rrr)r@rZtop_keyZ child_keyrr r r!rs  rcKsVd|krRt|dtjr0tjt|d|d<n"t|dtjrRtj|d|d<dS)NZBody)r[rrrrr)rOrr r r! convert_body_to_file_like_objects rc Csvdddd}xd|jD]X\}}|jdd\}}t||}d||jtf}d|d |jf}|j||j|qWdS) 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_aliasess   rc@s,eZdZddZddZddZddZd S) r cCs||_||_dS)N)_original_name _alias_name)rrZ alias_namer r r!rszParameterAlias.__init__cKsR|jrN|j|jjkrN|j|krN|j|krszClientMethodAlias.__call__N)rrrrrr r r r!r5src@s(eZdZdZddZddZddZdS) HeaderToHostHoisterz@Takes a header and moves it to the front of the hoststring. cCs ||_dS)N) _header_name)r header_namer r r!rEszHeaderToHostHoister.__init__cKs@|j|dkrdS|d|j}|d}|j||}||d<dS)aHoist a header to the hostname. Hoist a header to the beginning of the hostname with a suffix "." after it. The original header should be removed from the header map. This method is intended to be used as a target for the before-call event. rYNr)r_prepend_to_host)rrOr header_valueZ original_urlnew_urlr r r!hoistHs  zHeaderToHostHoister.hoistcCsHt|}|jjd}|g|}dj|}|j||j|jdf}t|}|S)Nrr)r netlocrjoinschemepathqueryr )rrprefixZurl_componentspartsZ new_netlocZnew_componentsr"r r r!r Vs   z$HeaderToHostHoister._prepend_to_hostN)rrr__doc__rr#r r r r r!rBsrcKs|js dS|jj|dd<dS)NrYzx-amz-api-version)Zis_endpoint_discovery_operationZ service_model api_version)rPrOrr r r!#inject_api_version_header_if_neededfsr-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-datazafter-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.ListObjectsV2zbefore-call.s3.PutBucketTaggingz!before-call.s3.PutBucketLifecyclez.before-call.s3.PutBucketLifecycleConfigurationzbefore-call.s3.PutBucketCorszbefore-call.s3.DeleteObjectsz#before-call.s3.PutBucketReplicationzbefore-call.s3.PutObjectzbefore-call.s3.UploadPartzbefore-call.s3.PutBucketAclzbefore-call.s3.PutBucketLoggingz$before-call.s3.PutBucketNotificationzbefore-call.s3.PutBucketPolicyz&before-call.s3.PutBucketRequestPaymentz"before-call.s3.PutBucketVersioningzbefore-call.s3.PutBucketWebsitezbefore-call.s3.PutObjectAclz!before-call.s3.PutObjectLegalHoldz!before-call.s3.PutObjectRetentionz)before-call.s3.PutObjectLockConfigurationz$before-parameter-build.s3.CopyObjectz(before-parameter-build.s3.UploadPartCopyz/before-parameter-build.s3.CreateMultipartUploadz%docs.*.s3.CopyObject.complete-sectionz)docs.*.s3.UploadPartCopy.complete-sectionzbefore-call.s3zbefore-call.glacierzbefore-call.apigatewayz!before-call.glacier.UploadArchivez'before-call.glacier.UploadMultipartPartzbefore-call.ec2.CopySnapshotz'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.ec2.RunInstanceszs0                   !                 1 $