
    "hj4                        d dl Z d dlZd dlZd dlm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!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l0m1Z1m2Z2m3Z3m4Z4m5Z5  e jl                  e7      Z8da9d Z:dddde(z  ddfdZ;d4dZ<d Z= G d d      Z> G d de-      Z? G d de,      Z@ G d d      ZA G d d eA      ZB G d! d"e      ZC G d# d$      ZD G d% d&      ZE ed'd(d)g      ZF G d* d+      ZG G d, d-      ZH G d. d/      ZI G d0 d1      ZJ G d2 d3      ZKy)5    N)
namedtuple)BytesIO)AwsCredentialsAwsCredentialsProviderAwsSigningAlgorithmAwsSigningConfig)ClientBootstrapClientTlsContextDefaultHostResolverEventLoopGroupTlsContextOptions)S3ClientS3RequestTlsModeS3RequestType)UNSIGNED)urlsplit)Config)InvalidConfigError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     L/root/.hermes/SkillClaw/.venv/lib/python3.12/site-packages/s3transfer/crt.pyacquire_crt_s3_process_lockr.   <   sS     "99--d3	 '  	 		s   ? 	A
A   Tc           
         t        |      }t        |      }t        ||      }	d}
|rt        j                  nt        j
                  }|mt        |t              r|j                         st        d      t               }|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.
    NzInvalid CA bundle: the configured value (ca_bundle, AWS_CA_BUNDLE, REQUESTS_CA_BUNDLE, or verify) resolved to an empty or whitespace-only string. Provide a valid path to a CA bundle file.)	error_msg)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DISABLED
isinstancestrstripr   r   &override_default_trust_store_from_pathverify_peerr
   new_connection_options_get_crt_throughput_target_gbpsr   )r5   crt_credentials_providernum_threadstarget_throughputr7   use_sslverifyevent_loop_grouphost_resolverr4   r9   r8   tls_ctx_optionsclient_tls_optiontarget_gbpss                  r-   create_s3_crt_clientrO   U   s    h &k2'(89M 0-@I! %,  1A1J1J  fc"6<<>$0  ,-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)r3   rN   s     r-   rD   rD      s^    '/iiFFH;[	
 K 7:]J
LL:KHrP   c                     t         j                  }	 t        t        |j	                  d            }t        |      }|| k\  S # t        t        f$ r Y yw xY w)N.F)r&   __version__mapintsplittuple	TypeError
ValueError)minimum_versioncrt_version_strcrt_version_intscrt_version_tuples       r-   _has_minimum_crt_versionrb      s\    ((OsO$9$9#$>?!"23 // z" s   *A AA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)a  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.

        :type config: s3transfer.manager.TransferConfig
        :param config: The transfer configuration to be used when
            making CRT S3 client requests.
        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osutilconfigs        r-   __init__zCRTTransferManager.__init__   sk    * >"9DL+ 3"LL!
 #:: 	& %'!#--c2rP   c                     | S r$    rr   s    r-   	__enter__zCRTTransferManager.__enter__   s    rP   c                 2    d}|rd}| j                  |       y )NFT	_shutdown)rr   exc_type	exc_valueargscancels        r-   __exit__zCRTTransferManager.__exit__   s    FvrP   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)rr   r   r   r   r   r   callargss          r-   downloadzCRTTransferManager.download  sl     JK%%j$2L2LM**62!#
 $$\8<<rP   c                     |i }|i }| j                  || j                         | j                  |       | j                  |       t	        |||||      }| j                  d|      S )Nr   
put_object)r   ALLOWED_UPLOAD_ARGSr   &_validate_checksum_algorithm_supportedr   r   )rr   r   r   r   r   r   r   s          r-   uploadzCRTTransferManager.upload  sx    JK%%j$2J2JK**6233J?!#
 $$\8<<rP   c                     |i }|i }| j                  || j                         | j                  |       t        ||||      }| j	                  d|      S )N)r   r   r   r   delete_object)r   ALLOWED_DELETE_ARGSr   r   r   )rr   r   r   r   r   r   s         r-   deletezCRTTransferManager.delete)  sg    JK%%j$2J2JK**62!#	
 $$_h??rP   c                 &    | j                  |       y r$   r}   rr   r   s     r-   shutdownzCRTTransferManager.shutdown8  s    vrP   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matchr]   )rr   r   resourcepatternr   s        r-   r   z0CRTTransferManager._validate_if_bucket_supported;  sg     00%)%F%F%L%L%N !'f-$A( LE E  1rP   c           	      Z    |D ]&  }||vst        d| ddj                  |              y )NzInvalid extra_args key 'z', must be one of: z, )r]   join)rr   actualallowedkwargs       r-   r   z+CRTTransferManager._validate_all_known_argsH  sF     	EG# .ug 6''+yy'9&:< 	rP   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]   )rr   r   checksum_algorithmsupported_algorithmss       r-   r   z9CRTTransferManager._validate_checksum_algorithm_supportedP  su    '^^,?@%#FII$A$A$M$MN##%-AA%&8%9 :--A,BD  BrP   c                 h    | j                   D ]#  }|j                         r|j                          % y r$   )rm   doner   rr   coordinators     r-   _cancel_transfersz$CRTTransferManager._cancel_transfers[  s/    44 	%K##%""$	%rP   c                 F    | j                   D ]  }|j                           y r$   )rm   resultr   s     r-   _finish_transfersz$CRTTransferManager._finish_transfers`  s#    44 	!K 	!rP   c                 F    | j                   D ]  }|j                           y r$   )rm   %wait_until_on_done_callbacks_completer   s     r-   _wait_transfers_donez'CRTTransferManager._wait_transfers_doned  s%    44 	@K==?	@rP   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-   r~   zCRTTransferManager._shutdownh  sg    ""$	(""$ %%' ! 	%""$ 		 %%'s-   5 AA AA AA A0c                 8    | j                   j                          y r$   )rp   releaserr   kwargss     r-   _release_semaphorez%CRTTransferManager._release_semaphoreu  s    !rP   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   ry   )r   CRTTransferCoordinatorrq   rl   CRTTransferMetaCRTTransferFutureAfterDoneHandlerappendrp   r)   rj   get_crt_callbackget_make_request_argsrh   make_requestset_s3_requestr   set_exceptionrm   )rr   request_type	call_argson_done_after_callsr   
componentsfuture	afterdone	on_queuedcrt_callargscrt_s3_requesteon_dones                r-   r   z#CRTTransferManager._submit_transferx  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NNF)__name__
__module____qualname__r   r   r   r   r   r   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r~   r   r   ry   rP   r-   rd   rd      s    +AA)==)=='+$#2#O#O  JN#J BF=$="@	%
!@("'rP   rd   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)rr   r   r   s      r-   rw   zCRTTransferMeta.__init__  s    '#rP   c                     | j                   S r$   )r   rz   s    r-   r   zCRTTransferMeta.call_args  s    rP   c                     | j                   S r$   )r   rz   s    r-   r   zCRTTransferMeta.transfer_id  s       rP   c                     | j                   S r$   )r   rz   s    r-   user_contextzCRTTransferMeta.user_context  s    !!!rP   r   )	r   r   r   __doc__rw   propertyr   r   r   ry   rP   r-   r   r     sF    4 
   ! ! " "rP   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)rr   r   r   s      r-   rw   zCRTTransferFuture.__init__  s"     
<(*DJ'rP   c                     | j                   S r$   )r   rz   s    r-   r   zCRTTransferFuture.meta  s    zzrP   c                 6    | j                   j                         S r$   )r   r   rz   s    r-   r   zCRTTransferFuture.done  s      %%''rP   c                 :    | j                   j                  |       y r$   )r   r   rr   timeouts     r-   r   zCRTTransferFuture.result  s      )rP   c                 8    | j                   j                          y r$   )r   r   rz   s    r-   r   zCRTTransferFuture.cancel  s      "rP   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   rr   	exceptions     r-   r   zCRTTransferFuture.set_exception  s8    yy{&  	''	D'ArP   r   r$   )
r   r   r   rw   r   r   r   r   r   r   ry   rP   r-   r   r     s0    (  (*#BrP   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)rr   transfer_typer   s      r-   serialize_http_requestz/BaseCRTRequestSerializer.serialize_http_request  s     ""<==rP   c                     t        d      )Nztranslate_crt_exception()r  r   s     r-   rk   z0BaseCRTRequestSerializer.translate_crt_exception  s    !"=>>rP   N)r   r   r   r  rk   ry   rP   r-   r  r    s    >?rP   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)rr   sessionclient_kwargss      r-   rw   z%BotocoreCRTRequestSerializer.__init__  s       M##G];+GE}E  ))"D$>$>	
 	  ))tOO	
 	  )) = =	
 	  )) = =	
rP   c                     d }|j                         r|j                         }d|v r|d   }t        t              }|r|j                  |      }||d<   d|d<   y )Nrv   )signature_versionr'   service_name)get_default_client_configr   r   merge)rr   r  r  user_provided_configclient_configs        r-   r  z3BotocoreCRTRequestSerializer._resolve_client_config  sg    #,,.#*#D#D#F }$#0#: :066}EM"/h(,n%rP   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   r>   r?   r   r&   httpHttpHeadersHttpRequestr   body)	rr   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--%%#((	 . 
 rP   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)
r1  r"  r   r   r$  setnetlocremover)  add)rr   botocore_http_requestr0  r+  s       r-   _convert_to_crt_http_requestz9BotocoreCRTRequestSerializer._convert_to_crt_http_request2  s    889NO""6*2 !6!:!:;I##FI,<,<=""=1=&&}5 ""#34<$))1##''(8#> ""#67C&&':;rP   c                 "    ||j                   d<   y )Nhttp_request)contextrr   requestr   s      r-   r  z2BotocoreCRTRequestSerializer._capture_http_requestP  s    *1'rP   c                 4    |d   }|j                         |d<   y )Nr<  HTTPRequest)prepare)rr   r=  parsedr   r?  s        r-   r  zHBotocoreCRTRequestSerializer._change_response_to_serialized_http_requestS  s     .) ' 1}rP   c                 X    t         j                  j                  d di t        d            S )N   rP   )botocore
awsrequestAWSResponseFakeRawResponser>  s      r-   r  z5BotocoreCRTRequestSerializer._make_fake_http_responseY  s,    ""..C 	
 	
rP   c                      t        | j                  |      d|j                  |j                  d|j                  d   S )N)BucketKeyrA  ry   )getattrr  r   r   r   )rr   client_methodr   s      r-   _get_botocore_http_requestz7BotocoreCRTRequestSerializer._get_botocore_http_requesta  sF    3wt||]3 
##
:C:N:N

 	rP   c                 t    | j                  ||j                  j                        }| j                  |      }|S r$   )rO  r   r   r:  )rr   r  r   r9  r0  s        r-   r  z3BotocoreCRTRequestSerializer.serialize_http_requestf  s;     $ ? ?6;;00!
 778MNrP   c                 n    t        |t        j                  j                        r| j	                  |      S y r$   )r>   r&   r'   S3ResponseError _translate_crt_s3_response_errorr   s     r-   rk   z4BotocoreCRTRequestSerializer.translate_crt_exceptionm  s*    i!:!:;88CCrP   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)rU  r"  rY  r  r   service_modeloperation_modeloutput_shaperF  rG  HeadersDictr)  _response_parserparser   
exceptions	from_code)rr   s3_response_errorrU  kvr"  rY  rZ  rV  response_dictparsed_response
error_codeerror_classs                r-   rS  z=BotocoreCRTRequestSerializer._translate_crt_s3_response_errors  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   )rr   paramsr   request_contexts       r-   r  z5BotocoreCRTRequestSerializer._remove_checksum_context  s'     **Y3(
+ )rP   r$   )r   r   r   rw   r  r1  r:  r  r  r  rO  r  rk   rS  r  ry   rP   r-   r
  r
    s?    
<-,<22

K8,rP   r
  c                       e Zd ZddZy)rI  Nc              #   >   K   	 | j                  |      }|sy | wr$   )read)rr   amtdecode_contentchunks       r-   streamzFakeRawResponse.stream  s&     IIcNEK	 s   )i   N)r   r   r   rs  ry   rP   r-   rI  rI    s    rP   rI  c                   $    e Zd Zd Zd Zd Zd Zy)BotocoreCRTCredentialsWrapperc                     || _         y r$   )_resolved_credentials)rr   resolved_botocore_credentialss     r-   rw   z&BotocoreCRTCredentialsWrapper.__init__  s
    %B"rP   c                     | j                         j                         }t        |j                  |j                  |j
                        S r$   )_get_credentialsget_frozen_credentialsr   
access_key
secret_keytoken)rr   credentialss     r-   __call__z&BotocoreCRTCredentialsWrapper.__call__  s?    ++-DDF""K$:$:K<M<M
 	
rP   c                 ,    t        j                  |       S r$   )r   new_delegaterz   s    r-   to_crt_credentials_providerz9BotocoreCRTCredentialsWrapper.to_crt_credentials_provider  s    %22488rP   c                 F    | j                   
t               | j                   S r$   )rw  r   rz   s    r-   rz  z.BotocoreCRTCredentialsWrapper._get_credentials  s#    %%-$&&)))rP   N)r   r   r   rw   r  r  rz  ry   rP   r-   ru  ru    s    C
9*rP   ru  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_requestrn   Lock_lock
_exception_crt_futureEvent_done_event)rr   r   
s3_requestr   s       r-   rw   zCRTTransferCoordinator.__init__  sH     '%9"%^^%
$??,rP   c                     | j                   S r$   )r  rz   s    r-   r  z!CRTTransferCoordinator.s3_request  s    rP   c                 8    | j                   j                          y r$   )r  r5  rz   s    r-   set_done_callbacks_completez2CRTTransferCoordinator.set_done_callbacks_complete  s    rP   c                 :    | j                   j                  |       y r$   )r  waitr   s     r-   r   z<CRTTransferCoordinator.wait_until_on_done_callbacks_complete  s    g&rP   c                 x    | j                   5  | j                         r|r|| _        d d d        y # 1 sw Y   y xY wr$   )r  r   r  )rr   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  r   rz   s    r-   r   zCRTTransferCoordinator.cancel  s"    ##% rP   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$   )r  r  r   r   r   r   handle_exceptionr  )rr   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   rS   rT   )rr   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   rz   s    r-   r   zCRTTransferCoordinator.done  s&    #$$&&rP   c                 H    || _         | j                   j                  | _        y r$   )r  finished_futurer  )rr   r  s     r-   r   z%CRTTransferCoordinator.set_s3_request  s    %++;;rP   )NNNr$   r   )r   r   r   r   rw   r   r  r  r   r   r   r   r  r   r   ry   rP   r-   r   r     sM    7 GK	-    ',
&('
<rP   r   CRTConfigParameterr+   min_versionc                   `    e Zd Zd edd      iZddZd Zd Zd Zd	 Z		 	 dd
Z
d Zd Zd Zy)ri   max_active_connections_overridemax_request_concurrency)r      r   Nc                 .    || _         || _        || _        y r$   )_request_serializer	_os_utils_config)rr   rt   os_utilsrv   s       r-   rw   zS3ClientArgsCreator.__init__  s    #9 !rP   c                    | j                   j                  | j                   j                  d}| j                   j                  d      | j                   j                  u rd |d<   | j                   j                  d      | j                   j                  u rd |d<   t        | d|       r#|j                   t        | d|                     | j                  |       |S )N)r7   r  multipart_chunksizer7   r  r  _get_crt_options_)	r  r  r  get_deep_attrUNSET_DEFAULThasattrupdaterM  $_remove_param_if_not_min_crt_version)rr   r   
crt_configs      r-    _get_crt_transfer_config_optionsz4S3ClientArgsCreator._get_crt_transfer_config_options	  s    99/3||/S/S

 LL&&'<=||))* '+J{#LL&&'@A||))* =AJ894,\N;<A 1,@AC 	11*=rP   c                 2    d| j                   j                  iS )Nmultipart_upload_threshold)r  multipart_thresholdrz   s    r-   _get_crt_options_put_objectz/S3ClientArgsCreator._get_crt_options_put_object"  s    ,dll.N.NOOrP   c           
         g }|D ]  }|| j                   vr| j                   |   }t        |j                        r7| j                  j	                  |j
                        | j                  j                  urUdj                  d |j                  D              }t        j                  d|j
                   d| d|j
                   d       |j                  |        |D ]  }||=  y )NrV   c              3   2   K   | ]  }t        |        y wr$   )r?   ).0is     r-   	<genexpr>zKS3ClientArgsCreator._remove_param_if_not_min_crt_version.<locals>.<genexpr>3  s     &I!s1v&Is   zTransfer config parameter z requires minimum CRT version: z. z! will not be used in the request.)_CRT_ARG_TO_CONFIG_PARAMrb   r  r  r  r+   r  r   rS   warningr   )rr   r  	to_removerequest_argparammin_ver_strs         r-   r  z8S3ClientArgsCreator._remove_param_if_not_min_crt_version%  s    	% 	*K$"?"??11+>E'(9(9: **5::6||112 "hh&Iu7H7H&II0 =55@Mzzl"CE
 [)%	*& % 	(K;'	(rP   c                 R    t        | d| | j                        } |||||g |      S )N_get_make_request_args_r   r   r   r   on_done_before_callsr   )rM  _default_get_make_request_args)rr   r   r   r   r   r   request_args_handlers          r-   r   z)S3ClientArgsCreator.get_make_request_args=  sF      '%l^4// 

 $%#!# 3
 	
rP   c                     fd}|S )Nc                      g }|z  }|t              z  }|z  }|D ]  }dk(  r || d           || i |  y )Nprogressr   )bytes_transferred)r!   )r   r   callbacks_listcallbackr   before_subscriberscallback_typer   s       r-   invoke_all_callbackszBS3ClientArgsCreator.get_crt_callback.<locals>.invoke_all_callbacksU  sm    N!-"44mFMBBN ,"33* . !J.tAw7d-f-.rP   ry   )rr   r   r  r  r   r  s    ```` r-   r   z$S3ClientArgsCreator.get_crt_callbackN  s    	.  $#rP   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<   | j"                   |j%                  | j'                  |             |S )NContentLengthBodyc              3   :   K   | ]  }|j                   v   y wr$   )r   )r  checksum_argr   s     r-   r  zHS3ClientArgsCreator._get_make_request_args_put_object.<locals>.<genexpr>y  s$      
 I000
s   r   CRC32)	algorithmlocationzoverride-to-be-removed
ContentMD5r  send_filepathchecksum_config)r>   r   r?   r  get_file_sizer   anyr   popr   r&   r'   S3ChecksumConfigr   S3ChecksumLocationTRAILERr  r  r  r  )rr   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_objectg  sd    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 @ 
 .;/*/>+,<<#$$55lC ! rP   c                    d }d }t         j                  j                  d      }	t        |j                  t
              rO|j                  }
| j                  j                  |
      }|j                  t        ||
|| j                               nt        |j                        }| j                  ||||||      }||d<   ||d<   |	|d<   | j                   |j                  | j                  |             |S )NT)validate_responser  recv_filepathon_bodyr  )r&   r'   r  r>   r   r?   r  get_temp_filenamer   RenameTempFileHandlerOnBodyFileObjWriterr  r  r  r  )rr   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 @ 
 .;/*'.)$/>+,<<#$$55lC ! rP   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>  s      :	:s   _rY  r5   *F)r  r5   use_double_uri_encodeshould_normalize_uri_pathsigning_configresource_name)r  r  r  )r  r  rM  r   r   DEFAULTr   r   rZ   _S3ArnParamHandler
handle_arnr   r   r   V4_ASYMMETRICr"   V4_S3EXPRESS)
rr   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./
 ! rP   r$   r   )r   r   r   r  r  rw   r  r  r  r   r   r  r  r  ry   rP   r-   ri   ri     sR    )+=%z,
 
2P(0
*  $21!f&!P4!rP   ri   c                       e Zd Zd Zd Zy)r  c                 <    || _         || _        || _        || _        y r$   )r   _final_filename_temp_filenamerg   )rr   r   final_filenametemp_filenameru   s        r-   rw   zRenameTempFileHandler.__init__  s!    '-+rP   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   )rg   remove_filer  rename_filer  r   r   r   )rr   r   r   r   s       r-   r  zRenameTempFileHandler.__call__   s    wLL$$T%8%893(('')=)=  3(()<)<=!!//223s   0A   	B3)A B..B3Nr   r   r   rw   r  ry   rP   r-   r  r    s    3rP   r  c                       e Zd Zd Zd Zy)r   c                     || _         y r$   )r   r   s     r-   rw   zAfterDoneHandler.__init__  s
    'rP   c                 8    | j                   j                          y r$   )r   r  r   s     r-   r  zAfterDoneHandler.__call__  s    557rP   Nr  ry   rP   r-   r   r     s    (8rP   r   c                       e Zd Zd Zd Zy)r  c                     || _         y r$   )_fileobj)rr   r   s     r-   rw   zOnBodyFileObjWriter.__init__  s	    rP   c                 :    | j                   j                  |       y r$   )r  write)rr   rr  r   s      r-   r  zOnBodyFileObjWriter.__call__  s    E"rP   Nr  ry   rP   r-   r  r    s     #rP   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_parserrz   s    r-   rw   z_S3ArnParamHandler.__init__+  s    $;rP   c                 @    | j                  |      }|y |d   dk(  r|S y )Nresource_typeaccesspoint)_get_arn_details_from_bucketrr   r   arn_detailss      r-   r  z_S3ArnParamHandler.handle_arn.  s3    77?'=8 9rP   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_bucket5  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)rr   r  r   s      r-   r!  z._S3ArnParamHandler._add_resource_type_and_name>  sK    $$**;z+BC+0;;+GK(+0;;+GK( rP   N)r   r   r   r   recompiler#  rw   r  r  r!  ry   rP   r-   r  r    s1     !bjjLO'HrP   r  r$   )Lloggingr%  rn   collectionsr   ior   awscrt.httpr&   	awscrt.s3botocore.awsrequestrF  botocore.sessionawscrt.authr   r   r   r   	awscrt.ior	   r
   r   r   r   r   r   r   r   botocore.compatr   botocore.configr   botocore.exceptionsr   r   botocore.utilsr   r   s3transfer.constantsr   r   s3transfer.exceptionsr   s3transfer.futuresr   r   s3transfer.managerr   s3transfer.utilsr   r   r    r!   r"   	getLoggerr   rS   r%   r.   rO   rD   rb   rd   r   r   r  r
  rI  ru  r   r  ri   r  r   r  r  ry   rP   r-   <module>r:     s_    	  "        @ ?  $ " F 9 > 6 C .  
		8	$ 6 ""f[|$0P Pf"& "*#B* #BL? ?&b,#; b,Jg * *&F< F<R   4v}6MN y! y!x3 3,8 8# ##H #HrP   