o ˆü?cü;ã@s”dZddlZddlZddlZddlmZddlmZmZddl m Z ddl m Z m Z ddlmZddlmZmZe rAdd lmZndZe e¡ZGd d „d ƒZGd d „d eƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„deƒZGdd„dƒZGdd„deƒZ dd„Z! d/dd„Z"dd„Z#d d!„Z$d"d#„Z% d/d$d%„Z&d&d'„Z'd(d)„Z(d*d+„Z)eeed,œZ*e r¾e* +eed-œ¡e,e* -¡ƒZ.gd.¢Z/dS)0aC The interfaces in this module are not intended for public use. This module defines interfaces for applying checksums to HTTP requests within the context of botocore. This involves both resolving the checksum to be used based on client configuration and environment, as well as application of the checksum to the request. éN)Úcrc32)Úsha1Úsha256)ÚHAS_CRT)ÚAwsChunkedWrapperErrorÚFlexibleChecksumError)Ú StreamingBody)Úconditionally_calculate_md5Údetermine_content_length)Ú checksumsc@s8eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd S) Ú BaseChecksumécCódS©N©©ÚselfÚchunkrrúp/private/var/folders/cw/wlscbxl13mj6wd668h7l9g9sllkg5j/T/pip-target-b31awkwq/lib/python/botocore/httpchecksum.pyÚupdate.ózBaseChecksum.updatecCrrr©rrrrÚdigest1rzBaseChecksum.digestcCs| ¡}t |¡ d¡S)NÚascii)rÚbase64Ú b64encodeÚdecode)rÚbsrrrÚ b64digest4szBaseChecksum.b64digestcs:ˆ ¡}t‡‡fdd„dƒD]}ˆ |¡qˆ |¡dS)Ncs ˆ ˆj¡Sr)ÚreadÚ _CHUNK_SIZEr©ÚfileobjrrrÚ:s z.BaseChecksum._handle_fileobj..ó)ÚtellÚiterrÚseek)rr"Zstart_positionrrr!rÚ_handle_fileobj8s zBaseChecksum._handle_fileobjcCs2t|ttfƒr| |¡| ¡S| |¡| ¡Sr)Ú isinstanceÚbytesÚ bytearrayrr(r)rÚbodyrrrÚhandle>s   ÿzBaseChecksum.handleN) Ú__name__Ú __module__Ú __qualname__r rrrr(r-rrrrr +s r c@ó$eZdZdd„Zdd„Zdd„ZdS)Ú Crc32ChecksumcCó d|_dS©Nr©Ú _int_crc32rrrrÚ__init__Gó zCrc32Checksum.__init__cCst||jƒd@|_dS©Nlÿÿ)rr6rrrrrJszCrc32Checksum.updatecCó|jjdddS©NéÚbig)Ú byteorder©r6Úto_bytesrrrrrMózCrc32Checksum.digestN©r.r/r0r7rrrrrrr2Fó r2c@r1)ÚCrtCrc32ChecksumcCr3r4r5rrrrr7Sr8zCrtCrc32Checksum.__init__cCót ||j¡}|d@|_dSr9)Ú crt_checksumsrr6©rrZ new_checksumrrrrVózCrtCrc32Checksum.updatecCr:r;r?rrrrrZrAzCrtCrc32Checksum.digestNrBrrrrrDQó rDc@r1)ÚCrtCrc32cChecksumcCr3r4)Ú _int_crc32crrrrr7`r8zCrtCrc32cChecksum.__init__cCrEr9)rFÚcrc32crKrGrrrrcrHzCrtCrc32cChecksum.updatecCr:r;)rKr@rrrrrgrAzCrtCrc32cChecksum.digestNrBrrrrrJ^rIrJc@r1)Ú Sha1ChecksumcCó tƒ|_dSr)rÚ _checksumrrrrr7ló zSha1Checksum.__init__cCó|j |¡dSr©rOrrrrrrorAzSha1Checksum.updatecCó |j ¡Sr©rOrrrrrrrr8zSha1Checksum.digestNrBrrrrrMkrCrMc@r1)ÚSha256ChecksumcCrNr)rrOrrrrr7wrPzSha256Checksum.__init__cCrQrrRrrrrrzrAzSha256Checksum.updatecCrSrrTrrrrr}r8zSha256Checksum.digestNrBrrrrrUvrCrUc@sLeZdZdZ   ddd„Zdd„Zdd d „Zdd d „Zd d„Zdd„Z dS)ÚAwsChunkedWrapperr Núx-amz-checksumcCs2||_||_||_| ¡|dur|j}||_dSr)Ú_rawÚ_checksum_nameÚ _checksum_clsÚ_resetÚ_DEFAULT_CHUNK_SIZEÚ _chunk_size)rÚrawÚ checksum_clsÚ checksum_nameÚ chunk_sizerrrr7„s zAwsChunkedWrapper.__init__cCs*d|_d|_d|_|jr| ¡|_dSdS)Nr$F)Ú _remainingÚ _completerOrZrrrrr[”s ÿzAwsChunkedWrapper._resetrcCs2|dks|dkr tdd‚| ¡|j d¡dS)Nrz Can only seek to start of stream©Ú error_msg)rr[rXr')rÚoffsetÚwhencerrrr'›s ÿzAwsChunkedWrapper.seekcCsª|dur |dkr d}|jr|jsdS|dup|t|jƒk}|js;|r;|j| ¡7_|dup5|t|jƒk}|js;|s"|durDt|jƒ}|jd|…}|j|d…|_|S)Nrr$)rcrbÚlenÚ _make_chunk)rÚsizeZwant_more_bytesZ to_returnrrrr£s   þ zAwsChunkedWrapper.readcCs‚|j |j¡}tt|ƒƒdd… d¡}| |_|jr!|j |¡|jr;|jr;|j  d¡}|j  ¡ d¡}d||fSd||fS)Nérs 0 %s:%s s%s %s ) rXrr]ÚhexrhÚencodercrOrrYr)rZ raw_chunkÚhex_lenÚnameÚchecksumrrrri¼s     zAwsChunkedWrapper._make_chunkccs |js| ¡V|jrdSdSr)rcrirrrrÚ__iter__Îs€ ÿzAwsChunkedWrapper.__iter__)NrWN)rr) r.r/r0r\r7r[r'rrirqrrrrrVs û   rVcs2eZdZ‡fdd„Zd‡fdd„ Zdd„Z‡ZS) ÚStreamingChecksumBodycstƒ ||¡||_||_dSr)Úsuperr7rOÚ _expected)rZ raw_streamÚcontent_lengthrpÚexpected©Ú __class__rrr7Ôs zStreamingChecksumBody.__init__Ncs:tƒj|d}|j |¡|dus|s|dkr| ¡|S)N)Úamtr)rsrrOrÚ_validate_checksum)rryrrwrrrÙs  zStreamingChecksumBody.readcCs<|j ¡t |j¡krd|j›d|j ¡›}t|d‚dS)NzExpected checksum z$ did not match calculated checksum: rd)rOrrÚ b64decodertrr)rrerrrrzàs ÿÿ ûz(StreamingChecksumBody._validate_checksumr)r.r/r0r7rrzÚ __classcell__rrrwrrrÓs rrcCst|||ƒt|||ƒdSr)Ú"resolve_request_checksum_algorithmÚ$resolve_response_checksum_algorithms)ÚrequestÚoperation_modelÚparamsrrrÚresolve_checksum_contextés r‚c Csî|j}| d¡}|rY||vrY|durt}|| ¡}||vr%td|d‚d}|jr3|d d¡r3d}||d|d œ}|d |d vrEdS|d  d i¡} || d<| |d d <dS|jsa| d¡ru|d  d i¡} d| d<| |d d <dSdS)NZrequestAlgorithmMemberz"Unsupported checksum algorithm: %srdÚheaderÚurlzhttps:Útrailerúx-amz-checksum-%s)Ú algorithmÚinroroÚheadersÚcontextrpÚrequest_algorithmZrequestChecksumRequiredúconditional-md5)Ú http_checksumÚgetÚ_SUPPORTED_CHECKSUM_ALGORITHMSÚlowerrZhas_streaming_inputÚ startswithZhttp_checksum_required) rr€rÚsupported_algorithmsrZalgorithm_memberZalgorithm_nameZ location_typer‡Úchecksum_contextrrrr}îs<   ÿý ÿúr}cCs|| di¡ di¡}| d¡}|sdS|dkrt|ƒdS|ddkr)t|ƒdS|ddkr5t|ƒdStd|dd ‚) NrŠrpr‹rŒrˆrƒr…zUnknown checksum variant: %srd)rŽr Ú_apply_request_header_checksumÚ_apply_request_trailer_checksumr)rr“r‡rrrÚapply_request_checksum s       ÿr–cCsd| di¡ di¡}| d¡}|d}||dvrdSt |d¡}|ƒ |d¡}||d|<dS)NrŠrpr‹ror‰r‡r,)rŽÚ _CHECKSUM_CLSr-)rr“r‡Ú location_namer_rrrrr”4s  r”cCs²| di¡ di¡}| d¡}|d}t |d¡}|d}|d}||vr(dSd|d <d |d <||d <t|ƒ}|durBt|ƒ|d <t|ttfƒrNt |¡}t |||d|d<dS)NrŠrpr‹ror‡r‰r,ÚchunkedzTransfer-Encodingz aws-chunkedzContent-Encodingz X-Amz-TrailerzX-Amz-Decoded-Content-Length)r_r`) rŽr—r Ústrr)r*r+ÚioÚBytesIOrV)rr“r‡r˜r_r‰r,rurrrr•@s*   ýr•c Cs˜|j}| d¡}|rH||vrJ|durt}dd„| dg¡Dƒ}g}tD]}||vr*q#||vr3| |¡q#|d di¡} || d<| |dd<dSdSdS)NZrequestValidationModeMembercSsh|]}| ¡’qSr)r)Ú.0ÚarrrÚ isÿz7resolve_response_checksum_algorithms..ZresponseAlgorithmsrŠrpÚresponse_algorithms)rrŽrÚ_ALGORITHMS_PRIORITY_LISTÚappend) rr€rr’rZ mode_memberr Zusable_algorithmsr‡r“rrrr~as&   ÿ €ðr~c Cs¶|d}| di¡}| d¡}|sdS|D]:}d|}||vr qd||vr'q|jr3t|||ƒ|d<nt|||ƒ|d<|d di¡}||d<||dd<dSt d |›d ¡dS) Nr‰rpr r†ú-r,rŠZresponse_algorithmzXSkipping checksum validation. Response did not contain one of the following algorithms: Ú.)rŽZhas_streaming_outputÚ_handle_streaming_responseÚ_handle_bytes_responseÚloggerÚinfo) Ú http_responseÚresponserŠr€r‰r“Z algorithmsr‡Ú header_namerrrÚhandle_checksum_bodyys6    ÿÿ ÿÿr¬cCs6t |¡}d|}t|j|d d¡|ƒ|d|ƒS)Nr†r‰zcontent-length)r—rŽrrr^)r©rªr‡r_r«rrrr¥¢s   ür¥c Csd|j}d|}t |¡}|ƒ}| |¡|d|}| ¡t |¡kr0d|| ¡f}t|d‚|S)Nr†r‰z:Expected checksum %s did not match calculated checksum: %srd) Úcontentr—rŽrrrr{rr) r©rªr‡r,r«r_rprvrerrrr¦­s   þÿÿ r¦)rrr)rrL)rLrrrr)0Ú__doc__rr›ÚloggingÚbinasciirÚhashlibrrZbotocore.compatrZbotocore.exceptionsrrZbotocore.responserZbotocore.utilsr r Zawscrtr rFÚ getLoggerr.r§r r2rDrJrMrUrVrrr‚r}r–r”r•r~r¬r¥r¦r—rÚlistÚkeysrr¡rrrrÚsV          R ü2 " ÿ) ýÿ