
     h                        d dl Z 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!m"Z" d dl#m$Z$m%Z% d dl&m'Z' d dl(m)Z)m*Z* d dl+m,Z, d dl-m.Z.m/Z/m0Z0m1Z1m2Z2  e jf                  e4      Z5da6d Z7dddde%z  ddfdZ8d/dZ9 G d d      Z: G d de*      Z; G d de)      Z< G d d      Z= G d de=      Z> G d d e      Z? G d! d"      Z@ G d# d$      ZA G d% d&      ZB G d' d(      ZC G d) d*      ZD G d+ d,      ZE G d- d.      ZFy)0    N)BytesIO)AwsCredentialsAwsCredentialsProviderAwsSigningAlgorithmAwsSigningConfig)ClientBootstrapClientTlsContextDefaultHostResolverEventLoopGroupTlsContextOptions)S3ClientS3RequestTlsModeS3RequestType)UNSIGNED)urlsplit)Config)NoCredentialsError)	ArnParserInvalidArnException)FULL_OBJECT_CHECKSUM_ARGSMB)TransferNotDoneError)BaseTransferFutureBaseTransferMeta)TransferManager)CallArgsOSUtilscreate_nested_client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     j/home/developers/rajanand/mypropertyqr-fmb-refixing-v2/venv/lib/python3.12/site-packages/s3transfer/crt.pyacquire_crt_s3_process_lockr,   ;   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   )r2   crt_credentials_providernum_threadstarget_throughputr4   use_sslverifyevent_loop_grouphost_resolverr1   r6   r5   tls_ctx_optionsclient_tls_optiontarget_gbpss                  r+   create_s3_crt_clientrI   T   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)r0   rH   s     r+   r>   r>      s^    '/iiFFH;[	
 K 7:]J
LL:KHrJ   c                       e Zd Zej                  Zej
                  Zej                  ZdZej                  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 Zd ZddZd Zd Zy)CRTTransferManagerTNc                     |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rJ   c                     | S r"    r^   s    r+   	__enter__zCRTTransferManager.__enter__   s    rJ   c                 2    d}|rd}| j                  |       y )NFT	_shutdown)r^   exc_type	exc_valueargscancels        r+   __exit__zCRTTransferManager.__exit__   s    FvrJ   c                     |i }|i }| j                  || j                         | j                  |       t        |||||      }| j	                  d|      S )Nbucketkeyfileobj
extra_argssubscribers
get_object)_validate_all_known_argsALLOWED_DOWNLOAD_ARGS_validate_if_bucket_supportedr   _submit_transfer)r^   rq   rr   rs   rt   ru   callargss          r+   downloadzCRTTransferManager.download   sl     JK%%j$2L2LM**62!#
 $$\8<<rJ   c                     |i }|i }| j                  || j                         | j                  |       | j                  |       t	        |||||      }| j                  d|      S )Nrp   
put_object)rw   ALLOWED_UPLOAD_ARGSry   &_validate_checksum_algorithm_supportedr   rz   )r^   rs   rq   rr   rt   ru   r{   s          r+   uploadzCRTTransferManager.upload   sx    JK%%j$2J2JK**6233J?!#
 $$\8<<rJ   c                     |i }|i }| j                  || j                         | j                  |       t        ||||      }| j	                  d|      S )N)rq   rr   rt   ru   delete_object)rw   ALLOWED_DELETE_ARGSry   r   rz   )r^   rq   rr   rt   ru   r{   s         r+   deletezCRTTransferManager.delete  sg    JK%%j$2J2JK**62!#	
 $$_h??rJ   c                 &    | j                  |       y r"   rh   r^   rm   s     r+   shutdownzCRTTransferManager.shutdown  s    vrJ   c                     | j                   rE| j                  j                         D ]'  \  }}|j                  |      }|st	        d| d       y y )Nz'TransferManager methods do not support z+ resource. Use direct client calls instead.) VALIDATE_SUPPORTED_BUCKET_VALUES_UNSUPPORTED_BUCKET_PATTERNSitemsmatch
ValueError)r^   rq   resourcepatternr   s        r+   ry   z0CRTTransferManager._validate_if_bucket_supported  sg     00%)%F%F%L%L%N !'f-$A( LE E  1rJ   c           	      Z    |D ]&  }||vst        d| ddj                  |              y )NzInvalid extra_args key 'z', must be one of: z, )r   join)r^   actualallowedkwargs       r+   rw   z+CRTTransferManager._validate_all_known_args,  sF     	EG# .ug 6''+yy'9&:< 	rJ   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__upperr   )r^   rt   checksum_algorithmsupported_algorithmss       r+   r   z9CRTTransferManager._validate_checksum_algorithm_supported4  su    '^^,?@%#FII$A$A$M$MN##%-AA%&8%9 :--A,BD  BrJ   c                 h    | j                   D ]#  }|j                         r|j                          % y r"   )rY   donerm   r^   coordinators     r+   _cancel_transfersz$CRTTransferManager._cancel_transfers?  s/    44 	%K##%""$	%rJ   c                 F    | j                   D ]  }|j                           y r"   )rY   resultr   s     r+   _finish_transfersz$CRTTransferManager._finish_transfersD  s#    44 	!K 	!rJ   c                 F    | j                   D ]  }|j                           y r"   )rY   %wait_until_on_done_callbacks_completer   s     r+   _wait_transfers_donez'CRTTransferManager._wait_transfers_doneH  s%    44 	@K==?	@rJ   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+   ri   zCRTTransferManager._shutdownL  sg    ""$	(""$ %%' ! 	%""$ 		 %%'s-   5 AA AA AA A0c                 8    | j                   j                          y r"   )r\   releaser^   kwargss     r+   _release_semaphorez%CRTTransferManager._release_semaphoreY  s    !rJ   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   rd   )r   CRTTransferCoordinatorr]   rX   CRTTransferMetaCRTTransferFutureAfterDoneHandlerappendr\   r'   rV   get_crt_callbackget_make_request_argsrT   make_requestset_s3_requestr   set_exceptionrY   )r^   request_type	call_argson_done_after_callsr   
componentsfuture	afterdone	on_queuedcrt_callargscrt_s3_requesteon_dones                r+   rz   z#CRTTransferManager._submit_transfer\  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   rx   r   r   r   r   rb   rf   rn   r|   r   r   r   ry   rw   r   r   r   r   ri   r   rz   rd   rJ   r+   rP   rP      s    +AA)==)=='+$#2#O#O : BF=$="@	%
!@("'rJ   rP   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)r^   r   r   s      r+   rb   zCRTTransferMeta.__init__  s    '#rJ   c                     | j                   S r"   )r   re   s    r+   r   zCRTTransferMeta.call_args  s    rJ   c                     | j                   S r"   )r   re   s    r+   r   zCRTTransferMeta.transfer_id  s       rJ   c                     | j                   S r"   )r   re   s    r+   user_contextzCRTTransferMeta.user_context  s    !!!rJ   r   )	r   r   r   __doc__rb   propertyr   r   r   rd   rJ   r+   r   r     sF    4 
   ! ! " "rJ   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)r^   r   r   s      r+   rb   zCRTTransferFuture.__init__  s"     
<(*DJ'rJ   c                     | j                   S r"   )r   re   s    r+   r   zCRTTransferFuture.meta  s    zzrJ   c                 6    | j                   j                         S r"   )r   r   re   s    r+   r   zCRTTransferFuture.done  s      %%''rJ   c                 :    | j                   j                  |       y r"   )r   r   r^   timeouts     r+   r   zCRTTransferFuture.result  s      )rJ   c                 8    | j                   j                          y r"   )r   rm   re   s    r+   rm   zCRTTransferFuture.cancel  s      "rJ   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   r^   	exceptions     r+   r   zCRTTransferFuture.set_exception  s8    yy{&  	''	D'ArJ   r   r"   )
r   r   r   rb   r   r   r   r   rm   r   rd   rJ   r+   r   r     s0    (  (*#BrJ   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)r^   transfer_typer   s      r+   serialize_http_requestz/BaseCRTRequestSerializer.serialize_http_request  s     ""<==rJ   c                     t        d      )Nztranslate_crt_exception()r   r   s     r+   rW   z0BaseCRTRequestSerializer.translate_crt_exception  s    !"=>>rJ   N)r   r   r   r   rW   rd   rJ   r+   r   r     s    >?rJ   r   c                   V    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d Zy)BotocoreCRTRequestSerializerNc                 0   || _         |i }| j                  ||       t        |fi || _        | j                  j                  j
                  j                  d| j                         | 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.*zbefore-call.s3.*)_session_resolve_client_configr   _clientr   eventsregister_capture_http_request+_change_response_to_serialized_http_request_make_fake_http_response_remove_checksum_context)r^   sessionclient_kwargss      r+   rb   z%BotocoreCRTRequestSerializer.__init__  s       M##G];+GE}E  ))"D$>$>	
 	  ))tOO	
 	  )) = =	
 	  )) = =	
rJ   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)r^   r  r  user_provided_configclient_configs        r+   r   z3BotocoreCRTRequestSerializer._resolve_client_config  sg    #,,.#*#D#D#F }$#0#: :066}EM"/h(,n%rJ   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  r   
isinstancestrr   r$   httpHttpHeadersHttpRequestr  body)	r^   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--%%#((	 . 
 rJ   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)r^   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&&':;rJ   c                 "    ||j                   d<   y )Nhttp_request)contextr^   requestr   s      r+   r   z2BotocoreCRTRequestSerializer._capture_http_request4  s    *1'rJ   c                 4    |d   }|j                         |d<   y )Nr+  HTTPRequest)prepare)r^   r,  parsedr   r.  s        r+   r   zHBotocoreCRTRequestSerializer._change_response_to_serialized_http_request7  s     .) ' 1}rJ   c                 X    t         j                  j                  d di t        d            S )N   rJ   )botocore
awsrequestAWSResponseFakeRawResponser-  s      r+   r   z5BotocoreCRTRequestSerializer._make_fake_http_response=  s,    ""..C 	
 	
rJ   c                      t        | j                  |      d|j                  |j                  d|j                  d   S )N)BucketKeyr0  rd   )getattrr   rq   rr   rt   )r^   client_methodr   s      r+   _get_botocore_http_requestz7BotocoreCRTRequestSerializer._get_botocore_http_requestE  sF    3wt||]3 
##
:C:N:N

 	rJ   c                 t    | j                  ||j                  j                        }| j                  |      }|S r"   )r>  r   r   r)  )r^   r   r   r(  r  s        r+   r   z3BotocoreCRTRequestSerializer.serialize_http_requestJ  s;     $ ? ?6;;00!
 778MNrJ   c                 n    t        |t        j                  j                        r| j	                  |      S y r"   )r  r$   r%   S3ResponseError _translate_crt_s3_response_errorr   s     r+   rW   z4BotocoreCRTRequestSerializer.translate_crt_exceptionQ  s*    i!:!:;88CCrJ   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)rD  r  rH  r   r   service_modeloperation_modeloutput_shaper5  r6  HeadersDictr  _response_parserparser   
exceptions	from_code)r^   s3_response_errorrD  kvr  rH  rI  rE  response_dictparsed_response
error_codeerror_classs                r+   rB  z=BotocoreCRTRequestSerializer._translate_crt_s3_response_errorW  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"c                 8    |j                  di       }d|v r|d= y y )Nr,  checksum)r   )r^   paramsr   request_contexts       r+   r   z5BotocoreCRTRequestSerializer._remove_checksum_contexts  s'     **Y3(
+ )rJ   r"   )r   r   r   rb   r   r   r)  r   r   r   r>  r   rW   rB  r   rd   rJ   r+   r   r     s?    
<-,<22

K8,rJ   r   c                       e Zd ZddZy)r8  Nc              #   >   K   	 | j                  |      }|sy | wr"   )read)r^   amtdecode_contentchunks       r+   streamzFakeRawResponse.streamz  s&     IIcNEK	 s   )i   N)r   r   r   rb  rd   rJ   r+   r8  r8  y  s    rJ   r8  c                   $    e Zd Zd Zd Zd Zd Zy)BotocoreCRTCredentialsWrapperc                     || _         y r"   )_resolved_credentials)r^   resolved_botocore_credentialss     r+   rb   z&BotocoreCRTCredentialsWrapper.__init__  s
    %B"rJ   c                     | j                         j                         }t        |j                  |j                  |j
                        S r"   )_get_credentialsget_frozen_credentialsr   
access_key
secret_keytoken)r^   credentialss     r+   __call__z&BotocoreCRTCredentialsWrapper.__call__  s?    ++-DDF""K$:$:K<M<M
 	
rJ   c                 ,    t        j                  |       S r"   )r   new_delegatere   s    r+   to_crt_credentials_providerz9BotocoreCRTCredentialsWrapper.to_crt_credentials_provider  s    %22488rJ   c                 F    | j                   
t               | j                   S r"   )rf  r   re   s    r+   ri  z.BotocoreCRTCredentialsWrapper._get_credentials  s#    %%-$&&)))rJ   N)r   r   r   rb   ro  rr  ri  rd   rJ   r+   rd  rd    s    C
9*rJ   rd  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_requestrZ   Lock_lock
_exception_crt_futureEvent_done_event)r^   r   
s3_requestr   s       r+   rb   zCRTTransferCoordinator.__init__  sH     '%9"%^^%
$??,rJ   c                     | j                   S r"   )rw  re   s    r+   r~  z!CRTTransferCoordinator.s3_request  s    rJ   c                 8    | j                   j                          y r"   )r}  r$  re   s    r+   set_done_callbacks_completez2CRTTransferCoordinator.set_done_callbacks_complete  s    rJ   c                 :    | j                   j                  |       y r"   )r}  waitr   s     r+   r   z<CRTTransferCoordinator.wait_until_on_done_callbacks_complete  s    g&rJ   c                 x    | j                   5  | j                         r|r|| _        d d d        y # 1 sw Y   y xY wr"   )ry  r   rz  )r^   r   r   s      r+   r   z$CRTTransferCoordinator.set_exception  s0    ZZ 	,99;("+	, 	, 	,s   09c                 R    | j                   r| j                   j                          y y r"   )rw  rm   re   s    r+   rm   zCRTTransferCoordinator.cancel  s"    ##% rJ   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"   )rz  r{  r   r   rm   r   handle_exceptionrw  )r^   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)rv  r   rM   rN   )r^   exctranslated_excr   s       r+   r  z'CRTTransferCoordinator.handle_exception  sb    %%!%!;!;C!@ % c)I   =J	s   ( 	AAAc                 P    | j                   y| j                   j                         S )NF)r{  r   re   s    r+   r   zCRTTransferCoordinator.done  s&    #$$&&rJ   c                 H    || _         | j                   j                  | _        y r"   )rw  finished_futurer{  )r^   r~  s     r+   r   z%CRTTransferCoordinator.set_s3_request  s    %++;;rJ   )NNNr"   r   )r   r   r   r   rb   r   r~  r  r   r   rm   r   r  r   r   rd   rJ   r+   r   r     sM    7 GK	-    ',
&('
<rJ   r   c                   6    e Zd Zd Zd Z	 	 ddZd Zd Zd Zy)	rU   c                      || _         || _        y r"   )_request_serializer	_os_utils)r^   r`   os_utilss      r+   rb   zS3ClientArgsCreator.__init__  s    #9 !rJ   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)r^   r   r   r   r   r   request_args_handlers          r+   r   z)S3ClientArgsCreator.get_make_request_args  sF      '%l^4// 

 $%#!# 3
 	
rJ   Nc                     fd}|S )Nc                      g }|z  }|t              z  }|z  }|D ]  }dk(  r || d           || i |  y )Nprogressr   )bytes_transferred)r   )rl   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-.rJ   rd   )r^   r   r  r  r   r  s    ```` r+   r   z$S3ClientArgsCreator.get_crt_callback  s    	.  $#rJ   c                    d }t        j                  t              r7j                  }| j                  j	                  |      }|j
                  d<   nj                  j
                  d<   d }	t        fdt        D              sj
                  j                  dd      j                         }
t        j                  j                  t        j                  j                  |
   t        j                  j                  j                        }	dj
                  d<   | j!                  |||||	      }||d
<   |	|d<   |S )NContentLengthBodyc              3   :   K   | ]  }|j                   v   y wr"   )rt   ).0checksum_argr   s     r+   	<genexpr>zHS3ClientArgsCreator._get_make_request_args_put_object.<locals>.<genexpr>  s$      
 I000
s   r   CRC32)	algorithmlocationzoverride-to-be-removed
ContentMD5r  send_filepathchecksum_config)r  rs   r  r  get_file_sizert   anyr   popr   r$   r%   S3ChecksumConfigr   S3ChecksumLocationTRAILERr  )r^   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  ( 
 9
 
 "+!5!5!9!9#W"eg  %ii88 ))778JK55== 9 O .F	\* ??%#!5 3 @ 
 .;/*/>+,  rJ   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  rs   r  r  get_temp_filenamer   RenameTempFileHandlerOnBodyFileObjWriterr  )r^   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 @ 
 .;/*'.)$/>+,  rJ   c                    | j                   j                  ||      t        t        |j	                         t        j
                        | j                  |d||      | j                  |d      d}|d   t        j
                  k(  r*dj                  d |j                  d      D              |d<   t               }|j                  |j                        x}	r4|	d	   dk(  r,t        t        j                  d
dd      |d<   |	d   |_        |S t        |j                        rt        t        j                   dd      |d<   |S )Nr   r  )r.  typer   on_progressr   c              3   <   K   | ]  }|j                           y wr"   )title)r  xs     r+   r  zES3ClientArgsCreator._default_get_make_request_args.<locals>.<genexpr>y  s      :	:s   _rH  r2   *F)r  r2   use_double_uri_encodeshould_normalize_uri_pathsigning_configresource_name)r  r  r  )r  r   r<  r   r   DEFAULTr   r   split_S3ArnParamHandler
handle_arnrq   r   r   V4_ASYMMETRICr    V4_S3EXPRESS)
r^   r   r   r   r   r  r   r  arn_handleraccesspoint_arn_detailss
             r+   r  z2S3ClientArgsCreator._default_get_make_request_args`  s`    //FFf |113]5J5J ,, 46I  00D
 V$(=(==24'' :#/#5#5c#:: 3./ )*'2'='=i>N>N'OO#O%h/25
 3C-;;&+*/	3./  7GI !  !!1!12 3C-::&+*/3./
 ! rJ   r   )	r   r   r   rb   r   r   r  r  r  rd   rJ   r+   rU   rU     s*    "
*  $2-!^"!H4!rJ   rU   c                       e Zd Zd Zd Zy)r  c                 <    || _         || _        || _        || _        y r"   )r   _final_filename_temp_filenamerS   )r^   r   final_filenametemp_filenamera   s        r+   rb   zRenameTempFileHandler.__init__  s!    '-+rJ   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   )rS   remove_filer  rename_filer  r   r   r   )r^   r   r   r   s       r+   ro  zRenameTempFileHandler.__call__  s    wLL$$T%8%893(('')=)=  3(()<)<=!!//223s   0A   	B3)A B..B3Nr   r   r   rb   ro  rd   rJ   r+   r  r    s    3rJ   r  c                       e Zd Zd Zd Zy)r   c                     || _         y r"   )r   r   s     r+   rb   zAfterDoneHandler.__init__  s
    'rJ   c                 8    | j                   j                          y r"   )r   r  r   s     r+   ro  zAfterDoneHandler.__call__  s    557rJ   Nr  rd   rJ   r+   r   r     s    (8rJ   r   c                       e Zd Zd Zd Zy)r  c                     || _         y r"   )_fileobj)r^   rs   s     r+   rb   zOnBodyFileObjWriter.__init__  s	    rJ   c                 :    | j                   j                  |       y r"   )r  write)r^   ra  r   s      r+   ro  zOnBodyFileObjWriter.__call__  s    E"rJ   Nr  rd   rJ   r+   r  r    s     #rJ   r  c                   L    e Zd ZdZ ej
                  d      Zd Zd Zd Z	d Z
y)r  a  Partial port of S3ArnParamHandler from botocore.

    This is used to make a determination on MRAP accesspoints for signing
    purposes. This should be safe to remove once we properly integrate auth
    resolution from Botocore into the CRT transfer integration.
    zA^(?P<resource_type>accesspoint|outpost)[/:](?P<resource_name>.+)$c                 "    t               | _        y r"   )r   _arn_parserre   s    r+   rb   z_S3ArnParamHandler.__init__  s    $;rJ   c                 @    | j                  |      }|y |d   dk(  r|S y )Nresource_typeaccesspoint)_get_arn_details_from_bucketr^   rq   arn_detailss      r+   r  z_S3ArnParamHandler.handle_arn  s3    77?'=8 9rJ   c                 ~    	 | j                   j                  |      }| j                  |       |S # t        $ r Y y w xY wr"   )r  	parse_arn_add_resource_type_and_namer   r  s      r+   r  z/_S3ArnParamHandler._get_arn_details_from_bucket  sF    	**44V<K,,[9" 		s   -0 	<<c                     | j                   j                  |d         }|r)|j                  d      |d<   |j                  d      |d<   y y )Nr   r  r  )_RESOURCE_REGEXr   group)r^   r  r   s      r+   r  z._S3ArnParamHandler._add_resource_type_and_name  sK    $$**;z+BC+0;;+GK(+0;;+GK( rJ   N)r   r   r   r   recompiler  rb   r  r  r  rd   rJ   r+   r  r    s1     !bjjLO'HrJ   r  r"   )Gloggingr  rZ   ior   awscrt.httpr$   	awscrt.s3botocore.awsrequestr5  botocore.sessionawscrt.authr   r   r   r   	awscrt.ior   r	   r
   r   r   r   r   r   r   botocore.compatr   botocore.configr   botocore.exceptionsr   botocore.utilsr   r   s3transfer.constantsr   r   s3transfer.exceptionsr   s3transfer.futuresr   r   s3transfer.managerr   s3transfer.utilsr   r   r   r   r    	getLoggerr   rM   r#   r,   rI   r>   rP   r   r   r   r   r8  rd  r   rU   r  r   r  r  rd   rJ   r+   <module>r     sB    	         @ ?  $ " 2 9 > 6 C .  
		8	$ 6 ""fRj$H HV"& "*#B* #BL? ?&b,#; b,Jg * *&F< F<Rv! v!r3 3,8 8# ##H #HrJ   