B ݁[ثf@sdZddlZddlZddlZddlZddlZddlZddlZddl m Z m Z m Z m Z mZmZmZmZddlmZddlmZddlmZddlmZddlmZdd lmZdd lmZdd lmZdd lmZdd lmZm Z ddlm!Z!ddlm"Z"ddl#m$Z$ddl#m%Z%ddl#m&Z&ddl#Z#ddl'Z#e(e)Z*e+Z,e+Z-e.dZ/e.dZ0ddiZ1ddZ2ddZ3ddZ4ddZ5dd Z6d!d"Z7d#d$Z8d%d&Z9d'd(Z:d)d*Z;d+d,Zd1d2Z?d3d4Z@dd6d7ZAd8d9ZBd:d;ZCdd?ZEd@dAZFdBdCZGdDdEZHdFdGZIdHdIZJdJdKZKdLdMZLdNdOZMdPdQZNdRdSZOdTdUZPdVdWZQdXdYZRdZd[ZSd\d]ZTd^d_ZUd`daZVdbdcZWdddeZXdfdgZYdhdiZZdjdkZ[dldmZ\dndoZ]dpdqZ^drdsZ_dtduZ`dvdwZadxdyZbdzd{Zcd|d}Zdd~dZeGddde+ZfGddde+ZgddZhde2fdegdfdede-fdede-fdehfdefdefde^fdePfde6fde9fdeRfde7fde>fde`fde`fde:fde:fde:fde:fde:fde:fde=fde=fde=fde=fde=fde=fde=fde=fde=fde=fdeIfdeIfdeUfdeUfdeUfdeHfdeHfdeGfdeXfdeYfdeZfdeZfdeNfde]fde3e,fde3e,fde3e,fdeCfdeFfdeFfdeFfdeFfdeFfdeFfde5fde?fde?fde?fde?fde@fde?fde?fde?fde@fdeSfdeSfdeVfdeWfdeafdebfde_fdeddɃjifded˃jifded˃jifde[fde\fdeTdЃfdeTdЃfdedӃjifdedԃjifdedփjifded׃jifdeTdكfdedddddddddddddddg jjfdefdeOfdeOfdeOfdeOfdedjifdedjifdedjifdedjifdeOfdeOfdedjifdedjifgcZkeeekdS)z_Builtin event handlers. This module contains builtin handlers for events emitted by botocore. N)unquotejsonsix unquote_str ensure_bytesget_md5 MD5_AVAILABLE OrderedDict)AutoPopulatedParam)HideParamFromOperations)AppendParamDocumentation)add_generate_presigned_url)add_generate_presigned_post)add_generate_db_auth_token)ParamValidationError)AliasConflictParameterError)UnsupportedTLSVersionWarning)percent_encode SAFE_CHARS)switch_host_with_param)hyphenize_service_id) retryhandler)utils) translatez^[a-zA-Z0-9.\-_]{1,255}$z\?versionId=[^\s]+$zruntime.sagemakerzsagemaker-runtimecKs t||S)N)SERVICE_NAME_ALIASESget) service_namekwargsrR/Users/kashii/Desktop/Projects/Workshops/worker-safety/lambda/botocore/handlers.pyhandle_service_name_aliasBsr cKs2|dkr dS|\}}t|r.td|d|_dS)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_responseparsedrrrcheck_for_200_errorFsr(cCsJ|jdkrFtjjjtjjdd}||j|}|j dkrFdSdS)Nzutf-8)targetencodingErrorTF) r$xmletree cElementTree XMLParser TreeBuilderfeedcontentclosetag)r&parserrootrrrr!bs    r!cKsR|d}|sdS|dkr tjS|drNd}|dkr:d}|dkrJd|d <|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_typeNnonev4s3s3v4zv4-unsigned-bodyFpayload_signing_enabled)rbotocoreUNSIGNED startswith)context signing_namerr8signature_versionrrrset_operation_specific_signerns  rDc Ks^d|krZy(tt|ddd}||d<Wn(tttfk rXtj dddYnXdS)NZOutputzutf-8replacezError decoding base64T)exc_info) base64 b64decoderbdecode ValueError TypeErrorAttributeErrorr"r#)r'rvaluerrrdecode_console_outputs rOcKsBx<|jD]2}||krtt||<td|||fqWdS)Nz1injecting idempotency token (%s) into param '%s'.)idempotent_membersstruuiduuid4r"r#)paramsmodelrnamerrrgenerate_idempotent_uuids  rWc Cs>ytt|}Wn&ttfk r8tjdddYnX|S)NzError loading quoted JSONT)rF)rloadsrrKrLr"r#)rNrrrdecode_quoted_jsondocs rYc KsRd|krNytj|dtd}||d<Wn&ttfk rLtjdddYnXdS)N TemplateBody)object_pairs_hookzerror loading JSONT)rF)rrXr rKrLr"r#)r'rrNrrrjson_decode_template_bodys r\cKs`|}|dr\d|dkr\|d}t|ttfr8t|}nt|}t|d}||dd<dS)Nbodyz Content-MD5headersascii) isinstancebytes bytearray_calculate_md5_from_bytes_calculate_md5_from_filerG b64encoderJ)rTr request_dictr]Z binary_md5Z base64_md5rrr calculate_md5s rgcCst|}|S)N)rdigest)Z body_bytesmd5rrrrcsrccsF}t}x$tfdddD]}||q"W||S)Ncs dS)Ni)readr)fileobjrrsz*_calculate_md5_from_file..)tellriterupdateseekrh)rkZstart_positionrichunkr)rkrrds  rdcKstrt|f|dS)z1Only add a Content-MD5 if the system supports it.N)rrg)rTrArequest_signerrrrrconditionally_calculate_md5srtcKs>d|kr dS|d}t|dkr:d|tjf}t|ddS)NBucketz?Invalid bucket name "%s": Bucket name must match the regex "%s")report) VALID_BUCKETsearchpatternr)rTrbucket error_msgrrrvalidate_bucket_names r|cKst|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)rTrrrrsse_md5srcKst|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)r~)rTrrrrcopy_source_sse_md5srr}cCsxt||sdS|d}|d}||}t|tjr<|d}tt| d}t| d}|||<|||<dS)NKeyKeyMD5zutf-8) _needs_s3_sse_customizationr`r text_typeencoderGrerrhrJ)rTsse_member_prefixZsse_key_memberZsse_md5_memberZ key_as_bytesZ key_md5_strZkey_b64_encodedrrrr~s   r~cCs||ddk o|d|kS)Nrr)r)rTrrrrrsrc Ks|d}|did}|dkr4td|dS|did}t|}t||}|s`dStd|t||} d|} |jd|| | d t |||dS) N data_loadermetadataendpointPrefixzSNot registering retry handlers, could not endpoint prefix from model for service %s serviceIdz*Registering retry handlers for service: %szretry-config-%szneeds-retry.%s) unique_id) get_componentrr"r#r_load_retry_configrcreate_retry_handlerregister_register_for_operations) service_datasessionrrloaderendpoint_prefix service_idservice_event_nameconfighandlerrrrrregister_retries_for_services$     rcCs(|d}t||d|di}|S)N_retryretry definitions) load_datarbuild_retry_configr)rroriginal_config retry_configrrrr(s  rcCsLxF|D]>}|dkrqt||}d||f}|jd||f||dqWdS)NZ __default__zretry-config-%s-%szneeds-retry.%s.%s)r)rrr)rrrkeyrrrrrr0s   rcKstjS)zk This handler disables request signing by setting the signer name to a special sentinel value. )r>r?)rrrrdisable_signing>srcKsJ|jdddkrdSd|krF|d}t|drFtdd|dd <dS) Nmethod)PUTPOSTr]rjz-Adding expect 100 continue header to request.z 100-continuer^Expect)httprhasattrr"r#)rUrTrr]rrradd_expect_headerFs  rc Ksd|kr:|d}|d}|d}||dnJd|kr|d}|d}||d|d }||d 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_textwrite) section event_namerparent param_line value_portion param_section type_sectionZ doc_sectionrrrdocument_copy_source_formRs        rcKsJ|d}|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)rTrsourcerrrhandle_copy_source_paramos   rc Csy*|d}t|dtdd}|d}Wn4tk r^}ztdt|dWdd}~XYnXd||f}|dk r|d |7}|S) Nrur/)safeZ VersionIdzMissing required parameter: %s)rvz%s/%sz ?versionId=%s)rrrKeyErrorrrQ)Z source_dictrzr version_idefinalrrrrs"  rcCs\t|}|dkr"t|tddS|d|||d}}t|tdd|SdS)Nr)r)VERSION_ID_SUFFIXrxrrstart)rNresultfirstrrrrrs  "rcCsLt|}||dd<|d|||d<d|d<i|d<|j|||jdS)Nr]DestinationRegionurlGETrr^) region_nameoperation_name)copydeepcopyrEgenerate_presigned_urlrV)rsrfrU source_regiondestination_regionZrequest_dict_copyrrr_get_cross_region_presigned_urls   rcCs|j}|d}||fS)N SourceRegion) _region_namer)rsrTrrrrr1_get_presigned_url_source_and_destination_regionss rcKsNd|dkrdSt||d\}}t|||||}||dd<||dd<dS)N PresignedUrlr]r)rr)rTrsrUrsrcdestrrrrinject_presigned_url_ec2s  rcKs\d|dkrdSt||d\}}|dd=d|dkrOsz#fix_route53_ids..rz %s %s -> %s) input_shaperrrsplitr"r#)rTrUrrrrVZ orig_valuerrrfix_route53_idsDs rcKs|ddkrd|d<dS)N accountId-)r)rTrrrrinject_account_idYsrcKs|}|jd|dd<dS)N apiVersionr^zx-amz-glacier-version)r)rUrTrrfrrradd_glacier_versionbsrcKs(|ddddkr$|}d|dd<dS)Nr^Acceptzapplication/json)r)rUrTrrfrrradd_accept_headerhsrcKsz|}|d}|d}t|tjr*t|}|}d|krLtj|dd|d<||d|krlt||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^r]zx-amz-content-sha256T)as_hexzx-amz-sha256-tree-hashN) r`r binary_typeBytesIOrnrcalculate_sha256rqcalculate_tree_hash)rTrrfr^r]Zstarting_positionrrradd_glacier_checksumsns    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)r r)docrrr#document_glacier_tree_hash_checksums r cKsld|kr0|d}|d}||dn8d|krh|d}|d}|d}||ddS) Nzresponse-paramsrZz param-typez (*dict*) --zresponse-examplezstructure-valuez member-valuez{})rrr)rrrZtemplate_body_sectionrrrrrrr0document_cloudformation_get_template_return_types      r cKst|ddS)NZPredictEndpoint)r)requestrrrrswitch_host_machinelearningsrcKsFddl}y$|j}|dkr*td|jtWntk r@YnXdS)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_VERSIONrrM)rrZopenssl_version_tuplerrr&check_openssl_supports_tls_version_1_2s rcKs>|jdkr:d|jkr:d|jd<d|_|jdd\|_|_dS)Nr?z!application/x-www-form-urlencodedz Content-Typerr)rrr^rdata)r rrrrchange_get_to_posts rcKsd|krd|d<d|d<dS)N EncodingTypeTencoding_type_auto_setrr)rTrArrrr"set_list_objects_encoding_type_urlsrcKstdddgddg||ddS)N DelimiterZMarkerZ NextMarker)Contentsr)CommonPrefixesPrefix)top_level_keys nested_keysr'rA)_decode_list_object)r'rArrrrdecode_list_objects r#cKstdddgddg||ddS)NrrZ StartAfter)rr)rr)r r!r'rA)r")r'rArrrrdecode_list_object_v2s r$cCs~|ddkrz|drzx$|D]}||krt||||<qWx:|D]2\}}||krDx ||D]}t||||<q^WqDWdS)Nrrr)rr)r r!r'rArZtop_keyZ child_keyrrrrr"s  r"cKsVd|krRt|dtjr0tt|d|d<n"t|dtjrRt|d|d<dS)NZBody)r`rrrrr)rTrrrr convert_body_to_file_like_objects r%c Csvdddd}xd|D]X\}}|dd\}}t||}d||jtf}d|d |jf}||||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_tuplerrr_add_parameter_aliasess   r0c@s,eZdZddZddZddZddZd S) r(cCs||_||_dS)N)_original_name _alias_name)selfr/Z alias_namerrr__init__&szParameterAlias.__init__cKsR|jrN|j|jjkrN|j|krN|j|krVsr>cKsd|kr|d=dS)NZsubscribe_to_shardr)class_attributesrrrrremove_subscribe_to_shardcsrDzchoose-service-namez/getattr.mturk.list_hi_ts_for_qualification_type list_hits_for_qualification_typez$before-parameter-build.s3.UploadPartz#before-parameter-build.s3.PutObjectzcreating-client-class.kinesiszcreating-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-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.CompleteMultipartUploadzservice-data-loadedz$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.RunInstanceszrrr botocore.auth getLoggerr;r"objectr* REGISTER_LASTcompilerwrrr r(r!rDrOrWrYr\rgrcrdrtr|rrr~rrrrrrrrrrrrrrrrrrrrrrrrrr r rrrrr#r$r"r%r0r(r>rDdocument_auto_populated_param hide_paramBUILTIN_HANDLERSrrrrs(                  !                   1