
    `2fy                     @   d dl Z d dlZd dlmZ d dlZd dlZd dlZd dl	Zd dl
mZmZmZmZ d dlmZmZmZmZmZ d dlmZmZmZ d dlmZ d dlmZ d dlmZ d d	lmZ d d
lm Z  d dl!m"Z" d dl#m$Z$m%Z% d dl&m'Z'm(Z(m)Z)m*Z*  e jV                  e,      Z-da.d Z/dddde z  ddfdZ0d+dZ1 G d d      Z2 G d de%      Z3 G d de$      Z4 G d d      Z5 G d de5      Z6 G d de      Z7 G d d       Z8 G d! d"      Z9 G d# d$      Z: G d% d&      Z; G d' d(      Z< G d) d*      Z=y),    N)BytesIO)AwsCredentialsAwsCredentialsProviderAwsSigningAlgorithmAwsSigningConfig)ClientBootstrapClientTlsContextDefaultHostResolverEventLoopGroupTlsContextOptions)S3ClientS3RequestTlsModeS3RequestType)UNSIGNED)urlsplit)Config)NoCredentialsError)MB)TransferNotDoneError)BaseTransferFutureBaseTransferMeta)CallArgsOSUtilsget_callbacksis_s3express_bucketc                     t         2t        j                  j                  |       }	 |j	                          |a t         S # t
        $ r Y y w xY wN)CRT_S3_PROCESS_LOCKawscrts3CrossProcessLockacquireRuntimeError)namecrt_locks     N/var/www/highfloat_scraper/venv/lib/python3.12/site-packages/s3transfer/crt.pyacquire_crt_s3_process_lockr'   7   sS     "99--d3	 '  	 		s   ? 	A
A   Tc           
      R   t        |      }t        |      }t        ||      }	d}
|rt        j                  nt        j
                  }|At               }|r|j                  |       nd|_        t        |      }|j                         }
t        |      }t        |	| ||||
|d      S )a  
    :type region: str
    :param region: The region used for signing

    :type crt_credentials_provider:
        Optional[awscrt.auth.AwsCredentialsProvider]
    :param crt_credentials_provider: CRT AWS credentials provider
        to use to sign requests. If not set, requests will not be signed.

    :type num_threads: Optional[int]
    :param num_threads: Number of worker threads generated. Default
        is the number of processors in the machine.

    :type target_throughput: Optional[int]
    :param target_throughput: Throughput target in bytes per second.
        By default, CRT will automatically attempt to choose a target
        throughput that matches the system's maximum network throughput.
        Currently, if CRT is unable to determine the maximum network
        throughput, a fallback target throughput of ``1_250_000_000`` bytes
        per second (which translates to 10 gigabits per second, or 1.16
        gibibytes per second) is used. To set a specific target
        throughput, set a value for this parameter.

    :type part_size: Optional[int]
    :param part_size: Size, in Bytes, of parts that files will be downloaded
        or uploaded in.

    :type use_ssl: boolean
    :param use_ssl: Whether or not to use SSL.  By default, SSL is used.
        Note that not all services support non-ssl connections.

    :type verify: Optional[boolean/string]
    :param verify: Whether or not to verify SSL certificates.
        By default SSL certificates are verified.  You can provide the
        following values:

        * False - do not validate SSL certificates.  SSL will still be
            used (unless use_ssl is False), but SSL certificates
            will not be verified.
        * path/to/cert/bundle.pem - A filename of the CA cert bundle to
            use. Specify this argument if you want to use a custom CA cert
            bundle instead of the default one on your system.
    N)ca_filepathF) provided_throughput_target_bytesT)	bootstrapregioncredential_provider	part_sizetls_modetls_connection_optionsthroughput_target_gbpsenable_s3express)r   r
   r   r   ENABLEDDISABLEDr   &override_default_trust_store_from_pathverify_peerr	   new_connection_options_get_crt_throughput_target_gbpsr   )r-   crt_credentials_providernum_threadstarget_throughputr/   use_sslverifyevent_loop_grouphost_resolverr,   r1   r0   tls_ctx_optionsclient_tls_optiontarget_gbpss                  r&   create_s3_crt_clientrD   P   s    h &k2'(89M 0-@I! %,  1A1J1J  +-BB" C  +0O',_=!2!I!I!K1):K 45*	 	    c                     | 9t         j                  j                         }t        j	                  d|       |d}n| dz  dz  }t        j	                  d|       |S )Nz-Recommended CRT throughput target in gbps: %sg      $@r(   i ʚ;z'Using CRT throughput target in gbps: %s)r   r    &get_recommended_throughput_target_gbpsloggerdebug)r+   rC   s     r&   r9   r9      s^    '/iiFFH;[	
 K 7:]J
LL:KHrE   c                   n    e Zd ZddZd Zd Z	 ddZddZddZddZ	d	 Z
d
 Zd Zd ZddZd Zd Zy)CRTTransferManagerNc                     |t               | _        || _        t        || j                        | _        |j
                  | _        g | _        t        j                  d      | _
        d| _        y)aF  A transfer manager interface for Amazon S3 on CRT s3 client.

        :type crt_s3_client: awscrt.s3.S3Client
        :param crt_s3_client: The CRT s3 client, handling all the
            HTTP requests and functions under then hood

        :type crt_request_serializer: s3transfer.crt.BaseCRTRequestSerializer
        :param crt_request_serializer: Serializer, generates unsigned crt HTTP
            request.

        :type osutil: s3transfer.utils.OSUtils
        :param osutil: OSUtils object to use for os-related behavior when
            using with transfer manager.
        N   r   )r   _osutil_crt_s3_clientS3ClientArgsCreator_s3_args_creatortranslate_crt_exception_crt_exception_translator_future_coordinators	threading	Semaphore
_semaphore_id_counter)selfcrt_s3_clientcrt_request_serializerosutils       r&   __init__zCRTTransferManager.__init__   sg     >"9DL+ 3"DLL!
 #:: 	& %'!#--c2rE   c                     | S r    rY   s    r&   	__enter__zCRTTransferManager.__enter__   s    rE   c                 2    d}|rd}| j                  |       y )NFT	_shutdown)rY   exc_type	exc_valueargscancels        r&   __exit__zCRTTransferManager.__exit__   s    FvrE   c                 V    |i }|i }t        |||||      }| j                  d|      S )Nbucketkeyfileobj
extra_argssubscribers
get_objectr   _submit_transfer)rY   rl   rm   rn   ro   rp   callargss          r&   downloadzCRTTransferManager.download   sH     JK!#
 $$\8<<rE   c                 x    |i }|i }| j                  |       t        |||||      }| j                  d|      S )Nrk   
put_object)&_validate_checksum_algorithm_supportedr   rs   )rY   rn   rl   rm   ro   rp   rt   s          r&   uploadzCRTTransferManager.upload   sT    JK33J?!#
 $$\8<<rE   c                 T    |i }|i }t        ||||      }| j                  d|      S )N)rl   rm   ro   rp   delete_objectrr   )rY   rl   rm   ro   rp   rt   s         r&   deletezCRTTransferManager.delete   sC    JK!#	
 $$_h??rE   c                 &    | j                  |       y r   rc   rY   rh   s     r&   shutdownzCRTTransferManager.shutdown
  s    vrE   c                     |j                  d      }|y t        t        j                  j                  j
                        }|j                         |vrt        d| d|       y )NChecksumAlgorithmzChecksumAlgorithm: z* not supported. Supported algorithms are: )getlistr   r    S3ChecksumAlgorithm__members__upper
ValueError)rY   ro   checksum_algorithmsupported_algorithmss       r&   rx   z9CRTTransferManager._validate_checksum_algorithm_supported  su    '^^,?@%#FII$A$A$M$MN##%-AA%&8%9 :--A,BD  BrE   c                 h    | j                   D ]#  }|j                         r|j                          % y r   )rT   donerh   rY   coordinators     r&   _cancel_transfersz$CRTTransferManager._cancel_transfers  s/    44 	%K##%""$	%rE   c                 F    | j                   D ]  }|j                           y r   )rT   resultr   s     r&   _finish_transfersz$CRTTransferManager._finish_transfers  s#    44 	!K 	!rE   c                 F    | j                   D ]  }|j                           y r   )rT   %wait_until_on_done_callbacks_completer   s     r&   _wait_transfers_donez'CRTTransferManager._wait_transfers_done!  s%    44 	@K==?	@rE   c                     |r| j                          	 | j                          | j	                          y # t        $ r | j                          Y ,t        $ r Y 6w xY w# | j	                          w xY wr   )r   r   KeyboardInterrupt	Exceptionr   r~   s     r&   rd   zCRTTransferManager._shutdown%  sg    ""$	(""$ %%' ! 	%""$ 		 %%'s-   5 AA AA AA A0c                 8    | j                   j                          y r   )rW   releaserY   kwargss     r&   _release_semaphorez%CRTTransferManager._release_semaphore2  s    !rE   c                    | j                   g}t        | j                  | j                        }t	        | j                  |      |d}t        d	i |}t        |      }|j                  |       	 | j                  j                          | j                  j                  |d      } |        | j                  j                  |||||      }	 | j                  j                  d	i |	}
|j                  |
       | j$                  j                  |       | xj                  dz  c_        |S # t         $ rC}|j#                  |d       | j                  j                  |d|      } ||       Y d }~yd }~ww xY w)
N)transfer_idexception_translator)metar   queuedTr   )after_subscribers)error   r_   )r   CRTTransferCoordinatorrX   rS   CRTTransferMetaCRTTransferFutureAfterDoneHandlerappendrW   r"   rQ   get_crt_callbackget_make_request_argsrO   make_requestset_s3_requestr   set_exceptionrT   )rY   request_type	call_argson_done_after_callsr   
componentsfuture	afterdone	on_queuedcrt_callargscrt_s3_requesteon_dones                r&   rs   z#CRTTransferManager._submit_transfer5  su   #667,((!%!?!?

 $D$4$4i@&

 #0Z0$[1	""9-	7OO##%-->>I K00FF#L >T00==MMN &&~6!!((5A  	%%a.++<<2E = G !	s   0A8D+ +	E749E22E7r   NNF)__name__
__module____qualname__r]   ra   ri   ru   ry   r|   r   rx   r   r   r   rd   r   rs   r_   rE   r&   rK   rK      sQ    : BF= =@	%
!@("'rE   rK   c                   H    e Zd ZdZddZed        Zed        Zed        Zy)r   z*Holds metadata about the CRTTransferFutureNc                 .    || _         || _        i | _        y r   )_transfer_id
_call_args_user_context)rY   r   r   s      r&   r]   zCRTTransferMeta.__init__b  s    '#rE   c                     | j                   S r   )r   r`   s    r&   r   zCRTTransferMeta.call_argsg  s    rE   c                     | j                   S r   )r   r`   s    r&   r   zCRTTransferMeta.transfer_idk  s       rE   c                     | j                   S r   )r   r`   s    r&   user_contextzCRTTransferMeta.user_contexto  s    !!!rE   r   )	r   r   r   __doc__r]   propertyr   r   r   r_   rE   r&   r   r   _  sF    4 
   ! ! " "rE   r   c                   >    e Zd ZddZed        Zd Zd	dZd Zd Z	y)
r   Nc                 B    || _         |t               | _         || _        y)aZ  The future associated to a submitted transfer request via CRT S3 client

        :type meta: s3transfer.crt.CRTTransferMeta
        :param meta: The metadata associated to the transfer future.

        :type coordinator: s3transfer.crt.CRTTransferCoordinator
        :param coordinator: The coordinator associated to the transfer future.
        N)_metar   _coordinator)rY   r   r   s      r&   r]   zCRTTransferFuture.__init__u  s"     
<(*DJ'rE   c                     | j                   S r   )r   r`   s    r&   r   zCRTTransferFuture.meta  s    zzrE   c                 6    | j                   j                         S r   )r   r   r`   s    r&   r   zCRTTransferFuture.done  s      %%''rE   c                 :    | j                   j                  |       y r   )r   r   rY   timeouts     r&   r   zCRTTransferFuture.result  s      )rE   c                 8    | j                   j                          y r   )r   rh   r`   s    r&   rh   zCRTTransferFuture.cancel  s      "rE   c                 t    | j                         st        d      | j                  j                  |d       y)z!Sets the exception on the future.z?set_exception can only be called once the transfer is complete.T)overrideN)r   r   r   r   rY   	exceptions     r&   r   zCRTTransferFuture.set_exception  s8    yy{&  	''	D'ArE   r   r   )
r   r   r   r]   r   r   r   r   rh   r   r_   rE   r&   r   r   t  s0    (  (*#BrE   r   c                       e Zd Zd Zd Zy)BaseCRTRequestSerializerc                     t        d      )al  Serialize CRT HTTP requests.

        :type transfer_type: string
        :param transfer_type: the type of transfer made,
            e.g 'put_object', 'get_object', 'delete_object'

        :type future: s3transfer.crt.CRTTransferFuture

        :rtype: awscrt.http.HttpRequest
        :returns: An unsigned HTTP request to be used for the CRT S3 client
        zserialize_http_request()NotImplementedError)rY   transfer_typer   s      r&   serialize_http_requestz/BaseCRTRequestSerializer.serialize_http_request  s     ""<==rE   c                     t        d      )Nztranslate_crt_exception()r   r   s     r&   rR   z0BaseCRTRequestSerializer.translate_crt_exception  s    !"=>>rE   N)r   r   r   r   rR   r_   rE   r&   r   r     s    >?rE   r   c                   P    e Zd ZddZd Zd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zy)BotocoreCRTRequestSerializerNc                    || _         |i }| j                  ||        |j                  di || _        | j                  j                  j
                  j                  d| j                         | j                  j                  j
                  j                  d| j                         | j                  j                  j
                  j                  d| j                         y)a  Serialize CRT HTTP request using botocore logic
        It also takes into account configuration from both the session
        and any keyword arguments that could be passed to
        `Session.create_client()` when serializing the request.

        :type session: botocore.session.Session

        :type client_kwargs: Optional[Dict[str, str]])
        :param client_kwargs: The kwargs for the botocore
            s3 client initialization.
        Nzrequest-created.s3.*zafter-call.s3.*zbefore-send.s3.*r_   )
_session_resolve_client_configcreate_client_clientr   eventsregister_capture_http_request+_change_response_to_serialized_http_request_make_fake_http_response)rY   sessionclient_kwargss      r&   r]   z%BotocoreCRTRequestSerializer.__init__  s       M##G];,w,,=}=  ))"D$>$>	
 	  ))tOO	
 	  )) = =	
rE   c                     d }|j                         r|j                         }d|v r|d   }t        t              }|r|j                  |      }||d<   d|d<   y )Nconfig)signature_versionr    service_name)get_default_client_configr   r   merge)rY   r   r   user_provided_configclient_configs        r&   r   z3BotocoreCRTRequestSerializer._resolve_client_config  sg    #,,.#*#D#D#F }$#0#: :066}EM"/h(,n%rE   c                    t        |j                        }|j                  }|j                  r| d|j                   }g }|j                  j                         D ]F  \  }}t        |t              r|j                  ||f       *|j                  |t        |d      f       H t        j                  j                  |      }t        j                  j                  |j                  |||j                        }|S )N?zutf-8)methodpathheadersbody_stream)r   urlr   queryr   items
isinstancestrr   r   httpHttpHeadersHttpRequestr   body)	rY   aws_request	url_partscrt_pathheaders_listr$   valuecrt_headerscrt_requests	            r&   _crt_request_from_aws_requestz:BotocoreCRTRequestSerializer._crt_request_from_aws_request  s    [__-	>>??"1Y__$56H&..446 	AKD%%%##T5M2##T3ug+>$?@		A kk--l;kk--%%#((	 . 
 rE   c                 2   | j                  |      }|j                  j                  d      ;t        |j                        }|j                  j                  d|j                         |j                  j                  d      |j                  j                  d       |j                  j                  d      (|j                  |j                  j                  dd       |j                  j                  d      |j                  j                  d       |S )NhostzContent-MD5zContent-Length0zTransfer-Encoding)
r  r   r   r   r   setnetlocremover  add)rY   botocore_http_requestr  r  s       r&   _convert_to_crt_http_requestz9BotocoreCRTRequestSerializer._convert_to_crt_http_request  s    889NO""6*2 !6!:!:;I##FI,<,<=""=1=&&}5 ""#34<$))1##''(8#> ""#67C&&':;rE   c                 "    ||j                   d<   y )Nhttp_request)contextrY   requestr   s      r&   r   z2BotocoreCRTRequestSerializer._capture_http_request
  s    *1'rE   c                 4    |d   }|j                         |d<   y )Nr  HTTPRequest)prepare)rY   r  parsedr   r  s        r&   r   zHBotocoreCRTRequestSerializer._change_response_to_serialized_http_request  s     .) ' 1}rE   c                 X    t         j                  j                  d di t        d            S )N   rE   )botocore
awsrequestAWSResponseFakeRawResponser  s      r&   r   z5BotocoreCRTRequestSerializer._make_fake_http_response  s,    ""..C 	
 	
rE   c                      t        | j                  |      d|j                  |j                  d|j                  d   S )N)BucketKeyr  r_   )getattrr   rl   rm   ro   )rY   client_methodr   s      r&   _get_botocore_http_requestz7BotocoreCRTRequestSerializer._get_botocore_http_request  sF    3wt||]3 
##
:C:N:N

 	rE   c                 t    | j                  ||j                  j                        }| j                  |      }|S r   )r*  r   r   r  )rY   r   r   r  r  s        r&   r   z3BotocoreCRTRequestSerializer.serialize_http_request   s;     $ ? ?6;;00!
 778MNrE   c                 n    t        |t        j                  j                        r| j	                  |      S y r   )r   r   r    S3ResponseError _translate_crt_s3_response_errorr   s     r&   rR   z4BotocoreCRTRequestSerializer.translate_crt_exception'  s*    i!:!:;88CCrE   c                 P   |j                   }|dk  ry |j                  D ci c]  \  }}||
 }}}|j                  }|<| j                  j                  j
                  }|j                  |      j                  }nd }t        j                  j                  |      ||j                  d}	| j                  j                  j                  |	|      }
|
j                  di       j                  d      }| j                  j                  j!                  |      } ||
|      S c c}}w )Ni-  )r   status_coder  )shapeErrorCode)operation_name)r0  r   r4  r   r   service_modeloperation_modeloutput_shaper!  r"  HeadersDictr  _response_parserparser   
exceptions	from_code)rY   s3_response_errorr0  kvr   r4  r5  r1  response_dictparsed_response
error_codeerror_classs                r&   r.  z=BotocoreCRTRequestSerializer._translate_crt_s3_response_error-  s   '33 $5$=$=>DAq1a4>>*99% LL--;;M!11.ANNEE  **66w?&%**

 ,,77== > 
 %(("599&A
ll--77
C?>JJ' ?s   D"r   )r   r   r   r]   r   r  r  r   r   r   r*  r   rR   r.  r_   rE   r&   r   r     s:    
6-,<22

KrE   r   c                       e Zd ZddZy)r$  Nc              #   >   K   	 | j                  |      }|sy | wr   )read)rY   amtdecode_contentchunks       r&   streamzFakeRawResponse.streamK  s&     IIcNEK	 s   )i   N)r   r   r   rJ  r_   rE   r&   r$  r$  J  s    rE   r$  c                   $    e Zd Zd Zd Zd Zd Zy)BotocoreCRTCredentialsWrapperc                     || _         y r   )_resolved_credentials)rY   resolved_botocore_credentialss     r&   r]   z&BotocoreCRTCredentialsWrapper.__init__T  s
    %B"rE   c                     | j                         j                         }t        |j                  |j                  |j
                        S r   )_get_credentialsget_frozen_credentialsr   
access_key
secret_keytoken)rY   credentialss     r&   __call__z&BotocoreCRTCredentialsWrapper.__call__W  s?    ++-DDF""K$:$:K<M<M
 	
rE   c                 ,    t        j                  |       S r   )r   new_delegater`   s    r&   to_crt_credentials_providerz9BotocoreCRTCredentialsWrapper.to_crt_credentials_provider]  s    %22488rE   c                 F    | j                   
t               | j                   S r   )rN  r   r`   s    r&   rQ  z.BotocoreCRTCredentialsWrapper._get_credentials`  s#    %%-$&&)))rE   N)r   r   r   r]   rW  rZ  rQ  r_   rE   r&   rL  rL  S  s    C
9*rE   rL  c                   `    e Zd ZdZ	 ddZed        Zd ZddZddZ	d Z
dd	Zd
 Zd Zd Zy)r   z-A helper class for managing CRTTransferFutureNc                     || _         || _        || _        t        j                         | _        d | _        d | _        t        j                         | _	        y r   )
r   _exception_translator_s3_requestrU   Lock_lock
_exception_crt_futureEvent_done_event)rY   r   
s3_requestr   s       r&   r]   zCRTTransferCoordinator.__init__i  sH     '%9"%^^%
$??,rE   c                     | j                   S r   )r_  r`   s    r&   rf  z!CRTTransferCoordinator.s3_requestt  s    rE   c                 8    | j                   j                          y r   )re  r  r`   s    r&   set_done_callbacks_completez2CRTTransferCoordinator.set_done_callbacks_completex  s    rE   c                 :    | j                   j                  |       y r   )re  waitr   s     r&   r   z<CRTTransferCoordinator.wait_until_on_done_callbacks_complete{  s    g&rE   c                 x    | j                   5  | j                         r|r|| _        d d d        y # 1 sw Y   y xY wr   )ra  r   rb  )rY   r   r   s      r&   r   z$CRTTransferCoordinator.set_exception~  s0    ZZ 	,99;("+	, 	, 	,s   09c                 R    | j                   r| j                   j                          y y r   )r_  rh   r`   s    r&   rh   zCRTTransferCoordinator.cancel  s"    ##% rE   c                 |   | j                   r| j                   	 | j                  j                  |       | j                  rd | _        y y # t        $ r- | j	                          | j                  j                  |        t
        $ r}| j                  |       Y d }~hd }~ww xY w# | j                  rd | _        w w xY wr   )rb  rc  r   r   rh   r   handle_exceptionr_  )rY   r   r   s      r&   r   zCRTTransferCoordinator.result  s    ??//!
	(##G, #'    ! 	KKM##G, 	%!!!$$	% #'   s)   A
 
=B"BB% B""B% %B;c                     d }| j                   r	 | j                  |      }||||# t        $ r!}t        j                  d|       Y d }~,d }~ww xY w)NzUnable to translate exception.)exc_info)r^  r   rH   rI   )rY   exctranslated_excr   s       r&   ro  z'CRTTransferCoordinator.handle_exception  sb    %%!%!;!;C!@ % c)I   =J	s   ( 	AAAc                 P    | j                   y| j                   j                         S )NF)rc  r   r`   s    r&   r   zCRTTransferCoordinator.done  s&    #$$&&rE   c                 H    || _         | j                   j                  | _        y r   )r_  finished_futurerc  )rY   rf  s     r&   r   z%CRTTransferCoordinator.set_s3_request  s    %++;;rE   )NNNr   r   )r   r   r   r   r]   r   rf  ri  r   r   rh   r   ro  r   r   r_   rE   r&   r   r   f  sM    7 GK	-    ',
&('
<rE   r   c                   6    e Zd Zd Zd Z	 	 ddZd Zd Zd Zy)	rP   c                      || _         || _        y r   )_request_serializer	_os_utils)rY   r[   os_utilss      r&   r]   zS3ClientArgsCreator.__init__  s    #9 !rE   c                 R    t        | d| | j                        } |||||g |      S )N_get_make_request_args_r   r   r   r   on_done_before_callsr   )r(  _default_get_make_request_args)rY   r   r   r   r   r   request_args_handlers          r&   r   z)S3ClientArgsCreator.get_make_request_args  sF      '%l^4// 

 $%#!# 3
 	
rE   Nc                     fd}|S )Nc                      g }|z  }|t              z  }|z  }|D ]  }dk(  r || d           || i |  y )Nprogressr   )bytes_transferred)r   )rg   r   callbacks_listcallbackr   before_subscriberscallback_typer   s       r&   invoke_all_callbackszBS3ClientArgsCreator.get_crt_callback.<locals>.invoke_all_callbacks  sm    N!-"44mFMBBN ,"33* . !J.tAw7d-f-.rE   r_   )rY   r   r  r  r   r  s    ```` r&   r   z$S3ClientArgsCreator.get_crt_callback  s    	.  $#rE   c                 N   d }t        |j                  t              r7|j                  }| j                  j	                  |      }||j
                  d<   n|j                  |j
                  d<   |j
                  j                  dd      j                         }	t        j                  j                  t        j                  j                  |	   t        j                  j                  j                        }
d|j
                  d<   | j                  ||||||      }||d	<   |
|d
<   |S )NContentLengthBodyr   CRC32)	algorithmlocationzoverride-to-be-removed
ContentMD5r~  send_filepathchecksum_config)r   rn   r   rz  get_file_sizero   popr   r   r    S3ChecksumConfigr   S3ChecksumLocationTRAILERr  )rY   r   r   r   r   r  r   r  data_lenr   r  make_request_argss               r&   !_get_make_request_args_put_objectz5S3ClientArgsCreator._get_make_request_args_put_object  s    i''-%--M~~33MBH4<I  1+4+<+<I  (&1155

%' 	 !))44ii334FGYY1199 5 
 .F	\* ??%#!5 3 @ 
 .;/*/>+,  rE   c                    d }d }t         j                  j                  d      }	t        |j                  t
              rO|j                  }
| j                  j                  |
      }|j                  t        ||
|| j                               nt        |j                        }| j                  ||||||      }||d<   ||d<   |	|d<   |S )NT)validate_responser~  recv_filepathon_bodyr  )r   r    r  r   rn   r   rz  get_temp_filenamer   RenameTempFileHandlerOnBodyFileObjWriterr  )rY   r   r   r   r   r  r   r  r  r  final_filepathr  s               r&   !_get_make_request_args_get_objectz5S3ClientArgsCreator._get_make_request_args_get_object  s      ))44t4Li''-&..N NN<<^LM ''% *)*;*;<G ??%#!5 3 @ 
 .;/*'.)$/>+,  rE   c                 F   | j                   j                  ||      t        t        |j	                         t        j
                        | j                  |d||      | j                  |d      d}t        |j                        rt        t        j                        |d<   |S )Nr   r  )r  typer   on_progress)r  signing_config)ry  r   r(  r   r   DEFAULTr   r   rl   r   r   V4_S3EXPRESS)rY   r   r   r   r   r  r   r  s           r&   r  z2S3ClientArgsCreator._default_get_make_request_args,  s     //FFf |113]5J5J ,, 46I  00D
 y//02B-::3./ ! rE   r   )	r   r   r   r]   r   r   r  r  r  r_   rE   r&   rP   rP     s*    "
*  $2(!T"!H!rE   rP   c                       e Zd Zd Zd Zy)r  c                 <    || _         || _        || _        || _        y r   )r   _final_filename_temp_filenamerN   )rY   r   final_filenametemp_filenamer\   s        r&   r]   zRenameTempFileHandler.__init__I  s!    '-+rE   c                 l   |d   }|r&| j                   j                  | j                         y 	 | j                   j                  | j                  | j                         y # t
        $ rJ}| j                   j                  | j                         | j                  j                  |       Y d }~y d }~ww xY w)Nr   )rN   remove_filer  rename_filer  r   r   r   )rY   r   r   r   s       r&   rW  zRenameTempFileHandler.__call__O  s    wLL$$T%8%893(('')=)=  3(()<)<=!!//223s   0A   	B3)A B..B3Nr   r   r   r]   rW  r_   rE   r&   r  r  H  s    3rE   r  c                       e Zd Zd Zd Zy)r   c                     || _         y r   )r   r   s     r&   r]   zAfterDoneHandler.__init___  s
    'rE   c                 8    | j                   j                          y r   )r   ri  r   s     r&   rW  zAfterDoneHandler.__call__b  s    557rE   Nr  r_   rE   r&   r   r   ^  s    (8rE   r   c                       e Zd Zd Zd Zy)r  c                     || _         y r   )_fileobj)rY   rn   s     r&   r]   zOnBodyFileObjWriter.__init__g  s	    rE   c                 :    | j                   j                  |       y r   )r  write)rY   rI  r   s      r&   rW  zOnBodyFileObjWriter.__call__j  s    E"rE   Nr  r_   rE   r&   r  r  f  s     #rE   r  r   )>loggingrU   ior   awscrt.httpr   	awscrt.s3botocore.awsrequestr!  botocore.sessionawscrt.authr   r   r   r   	awscrt.ior   r	   r
   r   r   r   r   r   r   botocore.compatr   botocore.configr   botocore.exceptionsr   s3transfer.constantsr   s3transfer.exceptionsr   s3transfer.futuresr   r   s3transfer.utilsr   r   r   r   	getLoggerr   rH   r   r'   rD   r9   rK   r   r   r   r   r$  rL  r   rP   r  r   r  r_   rE   r&   <module>r     s/            @ ?  $ " 2 # 6 C  
		8	$ 6 ""fRj$e eP"& "*#B* #BL? ?&ZK#; ZKzg * *&F< F<RV! V!r3 3,8 8# #rE   