HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/projects/env/lib/python3.10/site-packages/s3transfer/__pycache__/crt.cpython-310.pyc
o

+we{x�@s�ddlZddlZddlmZddlZddlZddlZddl	m
Z
mZddlm
Z
mZmZmZmZddlmZmZmZmZmZddlmZddlmZddlmZdd	lmZdd
lm Z ddl!m"Z"ddl#m$Z$m%Z%dd
l&m'Z'm(Z(m)Z)e�*e+�Z,da-dd�Z.dddde ddfdd�Z/d.dd�Z0Gdd�d�Z1Gdd�de%�Z2Gdd�de$�Z3Gdd�d�Z4Gdd�de4�Z5Gd d!�d!e�Z6Gd"d#�d#�Z7Gd$d%�d%�Z8Gd&d'�d'�Z9Gd(d)�d)�Z:Gd*d+�d+�Z;Gd,d-�d-�Z<dS)/�N)�BytesIO)�AwsCredentials�AwsCredentialsProvider)�ClientBootstrap�ClientTlsContext�DefaultHostResolver�EventLoopGroup�TlsContextOptions)�S3Client�S3RequestTlsMode�
S3RequestType�S3ResponseError�&get_recommended_throughput_target_gbps)�UNSIGNED)�urlsplit)�Config)�NoCredentialsError)�MB)�TransferNotDoneError)�BaseTransferFuture�BaseTransferMeta)�CallArgs�OSUtils�
get_callbackscCs>tdurtj�|�}z|��Wn
tyYdSw|atS�N)�CRT_S3_PROCESS_LOCK�awscrt�s3�CrossProcessLock�acquire�RuntimeError)�name�crt_lock�r#�G/home/arjun/projects/env/lib/python3.10/site-packages/s3transfer/crt.py�acquire_crt_s3_process_lock2s�r%�Tc	Cs�t|�}t|�}t||�}	d}
|rtjntj}|dur2t�}|r'|j|d�nd|_t	|�}
|
�
�}
t|d�}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_bytes)�	bootstrap�region�credential_provider�	part_size�tls_mode�tls_connection_options�throughput_target_gbps)
rrrr�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)r.r-�tls_ctx_options�client_tls_option�target_gbpsr#r#r$�create_s3_crt_clientKs65
����r@cCsD|durt�}t�d|�|durd}n|dd}t�d|�|S)Nz-Recommended CRT throughput target in gbps: %sg$@r&iʚ;z'Using CRT throughput target in gbps: %s)r�logger�debug)r(r?r#r#r$r5�s��r5c@s�eZdZddd�Zdd�Zdd�Z	d dd	�Zd d
d�Zd dd
�Zd!dd�Z	dd�Z
dd�Zdd�Zdd�Z
d!dd�Zdd�Zdd�ZdS)"�CRTTransferManagerNcCsH|durt�|_||_t||j�|_|j|_g|_t�	d�|_
d|_dS)aFA 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�osutilr#r#r$�__init__�s��
zCRTTransferManager.__init__cCs|Srr#�rPr#r#r$�	__enter__�szCRTTransferManager.__enter__cGsd}|rd}|�|�dS)NFT��	_shutdown)rP�exc_type�	exc_value�args�cancelr#r#r$�__exit__�szCRTTransferManager.__exit__cCs6|duri}|duri}t|||||d�}|�d|�S)N��bucket�key�fileobj�
extra_args�subscribers�
get_object�r�_submit_transfer)rPr_r`rarbrc�callargsr#r#r$�download�s�zCRTTransferManager.downloadcCs@|duri}|duri}|�|�t|||||d�}|�d|�S)Nr^�
put_object)�&_validate_checksum_algorithm_supportedrrf)rPrar_r`rbrcrgr#r#r$�upload�s
�zCRTTransferManager.uploadcCs4|duri}|duri}t||||d�}|�d|�S)N)r_r`rbrc�
delete_objectre)rPr_r`rbrcrgr#r#r$�delete�s�zCRTTransferManager.deleteFcCs|�|�dSrrW�rPr\r#r#r$�shutdown�zCRTTransferManager.shutdowncCsH|�d�}|durdSttjjj�}|��|vr"td|�d|����dS)N�ChecksumAlgorithmzChecksumAlgorithm: z* not supported. Supported algorithms are: )�get�listrr�S3ChecksumAlgorithm�__members__�upper�
ValueError)rPrb�checksum_algorithm�supported_algorithmsr#r#r$rjs
���z9CRTTransferManager._validate_checksum_algorithm_supportedcCs |jD]
}|��s
|��qdSr)rK�doner\�rP�coordinatorr#r#r$�_cancel_transferss

��z$CRTTransferManager._cancel_transferscC�|jD]}|��qdSr)rK�resultr{r#r#r$�_finish_transfers�

�z$CRTTransferManager._finish_transferscCr~r)rK�%wait_until_on_done_callbacks_completer{r#r#r$�_wait_transfers_doner�z'CRTTransferManager._wait_transfers_donecCsz|r|��z1z|��Wnty|��Ynty"YnwW|��dSW|��dSW|��dS|��wr)r}r��KeyboardInterrupt�	Exceptionr�rnr#r#r$rX s����zCRTTransferManager._shutdowncK�|j��dSr)rN�release�rP�kwargsr#r#r$�_release_semaphore-rpz%CRTTransferManager._release_semaphorec

Cs|jg}t|j|jd�}t|j|�|d�}td	i|��}t|�}|�|�z$|j�	�|j
�|d�}|�|j
�|||||�}	|j
jd	i|	��}
Wn&tyo}z|�|d�|j
j|d|d�}||d�WYd}~n
d}~ww|�|
�|j�|�|jd7_|S)
N)�transfer_id�exception_translator)�metar|�queuedTrz)�after_subscribers)�error�r#)r��CRTTransferCoordinatorrOrJ�CRTTransferMeta�CRTTransferFuture�AfterDoneHandler�appendrNrrH�get_crt_callback�get_make_request_argsrF�make_requestr��
set_exception�set_s3_requestrK)
rP�request_type�	call_args�on_done_after_callsr|�
components�future�	afterdone�	on_queued�crt_callargs�crt_s3_request�e�on_doner#r#r$rf0sJ�
�

�����
z#CRTTransferManager._submit_transferr�NN�F)�__name__�
__module__�__qualname__rTrVr]rhrkrmrorjr}r�r�rXr�rfr#r#r#r$rC�s 

�





rCc@s>eZdZdZddd�Zedd��Zedd��Zed	d
��ZdS)r�z*Holds metadata about the CRTTransferFutureNcCs||_||_i|_dSr)�_transfer_id�
_call_args�
_user_context)rPr�r�r#r#r$rT]s
zCRTTransferMeta.__init__cC�|jSr)r�rUr#r#r$r�b�zCRTTransferMeta.call_argscCr�r)r�rUr#r#r$r�fr�zCRTTransferMeta.transfer_idcCr�r)r�rUr#r#r$�user_contextjr�zCRTTransferMeta.user_contextr�)	r�r�r��__doc__rT�propertyr�r�r�r#r#r#r$r�Zs


r�c@sDeZdZddd�Zedd��Zdd�Zddd	�Zd
d�Zdd
�Z	dS)r�NcCs ||_|durt�|_||_dS)aZThe 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)rPr�r|r#r#r$rTps	
zCRTTransferFuture.__init__cCr�r)r�rUr#r#r$r�~r�zCRTTransferFuture.metacCs
|j��Sr)r�rzrUr#r#r$rz��
zCRTTransferFuture.donecC�|j�|�dSr)r�r�rP�timeoutr#r#r$r��zCRTTransferFuture.resultcCr�r)r�r\rUr#r#r$r\�rpzCRTTransferFuture.cancelcCs$|��std��|jj|dd�dS)z!Sets the exception on the future.z?set_exception can only be called once the transfer is complete.T)�overrideN)rzrr�r��rP�	exceptionr#r#r$r��s
�zCRTTransferFuture.set_exceptionr�r)
r�r�r�rTr�r�rzrr\r�r#r#r#r$r�os


r�c@�eZdZdd�Zdd�ZdS)�BaseCRTRequestSerializercC�td��)alSerialize 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
        zserialize_http_request()��NotImplementedError)rP�
transfer_typer�r#r#r$�serialize_http_request�sz/BaseCRTRequestSerializer.serialize_http_requestcCr�)Nztranslate_crt_exception()r�r�r#r#r$rI�sz0BaseCRTRequestSerializer.translate_crt_exceptionN)r�r�r�r�rIr#r#r#r$r��sr�c@sfeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�BotocoreCRTRequestSerializerNcCsp||_|dur	i}|�||�|jdi|��|_|jjj�d|j�|jjj�d|j�|jjj�d|j	�dS)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.
        Nzrequest-created.s3.*zafter-call.s3.*zbefore-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)rP�session�
client_kwargsr#r#r$rT�s
�
�
�z%BotocoreCRTRequestSerializer.__init__cCsPd}|��r
|��}d|vr|d}ttd�}|r|�|�}||d<d|d<dS)N�config)�signature_versionr�service_name)�get_default_client_configrr�merge)rPr�r��user_provided_config�
client_configr#r#r$r��s

z3BotocoreCRTRequestSerializer._resolve_client_configc	Cs�t|j�}|j}|jr|�d|j��}g}|j��D]\}}t|t�r+|�||f�q|�|t|d�f�qt	j
�|�}t	j
j|j
|||jd�}|S)N�?zutf-8)�method�path�headers�body_stream)r�urlr��queryr��items�
isinstance�strr�r�http�HttpHeaders�HttpRequestr��body)	rP�aws_request�	url_parts�crt_path�headers_listr!�value�crt_headers�crt_requestr#r#r$�_crt_request_from_aws_request�s"

�z:BotocoreCRTRequestSerializer._crt_request_from_aws_requestcCs�|�|�}|j�d�durt|j�}|j�d|j�|j�d�dur(|j�d�|j�d�dur<|jdur<|j�	dd�|j�d�durJ|j�d�|S)N�hostzContent-MD5zContent-Length�0zTransfer-Encoding)
r�r�rrrr��set�netloc�remover��add)rP�botocore_http_requestr�r�r#r#r$�_convert_to_crt_http_request�s


z9BotocoreCRTRequestSerializer._convert_to_crt_http_requestcKs||jd<dS)N�http_request)�context�rP�requestr�r#r#r$r�rpz2BotocoreCRTRequestSerializer._capture_http_requestcKs|d}|��|d<dS)Nr��HTTPRequest)�prepare)rPr��parsedr�r�r#r#r$r�szHBotocoreCRTRequestSerializer._change_response_to_serialized_http_requestcKstj�dditd��S)N���)�botocore�
awsrequest�AWSResponse�FakeRawResponser�r#r#r$r�s�z5BotocoreCRTRequestSerializer._make_fake_http_responsecCs&t|j|�d|j|jd�|j��dS)N)�Bucket�Keyr�r#)�getattrr�r_r`rb)rP�
client_methodr�r#r#r$�_get_botocore_http_requests���z7BotocoreCRTRequestSerializer._get_botocore_http_requestcCs|�||jj�}|�|�}|Sr)rr�r�r�)rPr�r�r�r�r#r#r$r�s
�
z3BotocoreCRTRequestSerializer.serialize_http_requestcCst|t�r
|�|�SdSr)r�r
� _translate_crt_s3_response_errorr�r#r#r$rI"s

z4BotocoreCRTRequestSerializer.translate_crt_exceptioncCs�|j}|dkr	dSdd�|jD�}|j}|dur$|jjj}|�|�j}nd}tj	�
|�||jd�}|jjj
||d�}|�di��d�}	|jj�|	�}
|
||d�S)	Ni-cSsi|]\}}||�qSr#r#)�.0�k�vr#r#r$�
<dictcomp>/szQBotocoreCRTRequestSerializer._translate_crt_s3_response_error.<locals>.<dictcomp>)r��status_coder�)�shape�Error�Code)�operation_name)r
r�rr�r��
service_model�operation_model�output_shaper�r�HeadersDictr��_response_parser�parserr�
exceptions�	from_code)rP�s3_response_errorr
r�rrr�
response_dict�parsed_response�
error_code�error_classr#r#r$r(s&

��z=BotocoreCRTRequestSerializer._translate_crt_s3_response_errorr)r�r�r�rTr�r�r�r�r�r�rr�rIrr#r#r#r$r��s

r�c@seZdZddd�ZdS)r�Nccs�	|�|�}|sdS|Vqr)�read)rP�amt�decode_content�chunkr#r#r$�streamFs�
�zFakeRawResponse.stream)rN)r�r�r�r$r#r#r#r$rEsrc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�BotocoreCRTCredentialsWrappercC�
||_dSr)�_resolved_credentials)rP�resolved_botocore_credentialsr#r#r$rTOr�z&BotocoreCRTCredentialsWrapper.__init__cCs|����}t|j|j|j�Sr)�_get_credentials�get_frozen_credentialsr�
access_key�
secret_key�token)rP�credentialsr#r#r$�__call__Rs�z&BotocoreCRTCredentialsWrapper.__call__cCs
t�|�Sr)r�new_delegaterUr#r#r$�to_crt_credentials_providerXr�z9BotocoreCRTCredentialsWrapper.to_crt_credentials_providercCs|jdurt��|jSr)r'rrUr#r#r$r)[s
z.BotocoreCRTCredentialsWrapper._get_credentialsN)r�r�r�rTr/r1r)r#r#r#r$r%Ns
r%c@sneZdZdZ	ddd�Zedd��Zdd�Zdd	d
�Zddd
�Z	dd�Z
ddd�Zdd�Zdd�Z
dd�ZdS)r�z-A helper class for managing CRTTransferFutureNcCs6||_||_||_t��|_d|_d|_t��|_	dSr)
r��_exception_translator�_s3_requestrL�Lock�_lock�
_exception�_crt_future�Event�_done_event)rPr��
s3_requestr�r#r#r$rTds
zCRTTransferCoordinator.__init__cCr�r)r3rUr#r#r$r:or�z!CRTTransferCoordinator.s3_requestcCr�r)r9r�rUr#r#r$�set_done_callbacks_completesrpz2CRTTransferCoordinator.set_done_callbacks_completecCr�r)r9�waitr�r#r#r$r�vr�z<CRTTransferCoordinator.wait_until_on_done_callbacks_completeFcCsN|j�|��r
|r||_Wd�dSWd�dS1s wYdSr)r5rzr6)rPr�r�r#r#r$r�ys�"�z$CRTTransferCoordinator.set_exceptioncCs|jr
|j��dSdSr)r3r\rUr#r#r$r\~s�zCRTTransferCoordinator.cancelc
Cs�|jr|j�z<z|j�|�Wn(ty!|��|j�|��ty7}z|�|�WYd}~nd}~wwW|jrAd|_dSdS|jrId|_wr)r6r7rr�r\r��handle_exceptionr3)rPr�r�r#r#r$r�s"���

�zCRTTransferCoordinator.resultc
Cs^d}|jr&z|�|�}Wnty%}z
tjd|d�WYd}~nd}~ww|dur-||�|�)NzUnable to translate exception.)�exc_info)r2r�rArB)rP�exc�translated_excr�r#r#r$r=�s��z'CRTTransferCoordinator.handle_exceptioncCs|jdurdS|j��S)NF)r7rzrUr#r#r$rz�s

zCRTTransferCoordinator.donecCs||_|jj|_dSr)r3�finished_futurer7)rPr:r#r#r$r��sz%CRTTransferCoordinator.set_s3_request)NNNrr�)r�r�r�r�rTr�r:r;r�r�r\rr=rzr�r#r#r#r$r�as
�



r�c@sBeZdZdd�Zdd�Z		ddd�Zdd	�Zd
d�Zdd
�ZdS)rGcCs||_||_dSr)�_request_serializer�	_os_utils)rPrR�os_utilsr#r#r$rT�s
zS3ClientArgsCreator.__init__cCs(t|d|��|j�}|||||g|d�S)N�_get_make_request_args_�r�r�r|r��on_done_before_callsr�)r�_default_get_make_request_args)rPr�r�r|r�r��request_args_handlerr#r#r$r��s��z)S3ClientArgsCreator.get_make_request_argsNcs����fdd�}|S)Ncsfg}�dur
|�7}|t���7}�dur|�7}|D]}�dkr)||dd�q||i|��qdS)N�progressr)�bytes_transferred)r)r[r��callbacks_list�callback�r��before_subscribers�
callback_typer�r#r$�invoke_all_callbacks�s�zBS3ClientArgsCreator.get_crt_callback.<locals>.invoke_all_callbacksr#)rPr�rPrOr�rQr#rNr$r��sz$S3ClientArgsCreator.get_crt_callbackcCs�d}t|jt�r|j}|j�|�}||jd<n|j|jd<|j�dd���}	tj	j
tj	j|	tj	jj
d�}
d|jd<|j||||||d�}||d	<|
|d
<|S)N�
ContentLength�Bodyrq�CRC32)�	algorithm�locationzoverride-to-be-removed�
ContentMD5rF�
send_filepath�checksum_config)r�rar�rC�
get_file_sizerb�poprvrr�S3ChecksumConfigrt�S3ChecksumLocation�TRAILERrH)rPr�r�r|r�rGr�rX�data_lenrxrY�make_request_argsr#r#r$�!_get_make_request_args_put_object�s6	��
�
�z5S3ClientArgsCreator._get_make_request_args_put_objectcCs�d}d}tjjdd�}	t|jt�r&|j}
|j�|
�}|�t	||
||j��nt
|j�}|j||||||d�}||d<||d<|	|d<|S)NT)�validate_responserF�
recv_filepath�on_bodyrY)rrr\r�rar�rC�get_temp_filenamer��RenameTempFileHandler�OnBodyFileObjWriterrH)rPr�r�r|r�rGr�rcrdrY�final_filepathr`r#r#r$�!_get_make_request_args_get_objects0	
��
�z5S3ClientArgsCreator._get_make_request_args_get_objectcCs:|j�||�tt|��tj�|�|d||�|�|d�d�S)NrzrJ)r��typer��on_progress)rBr�rrrv�DEFAULTr�)rPr�r�r|r�rGr�r#r#r$rH's
���
�z2S3ClientArgsCreator._default_get_make_request_argsr�)	r�r�r�rTr�r�rarirHr#r#r#r$rG�s
�*$rGc@r�)rfcCs||_||_||_||_dSr)r��_final_filename�_temp_filenamerE)rPr|�final_filename�
temp_filenamerSr#r#r$rT?s
zRenameTempFileHandler.__init__c
Ksx|d}|r|j�|j�dSz|j�|j|j�WdSty;}z|j�|j�|j�|�WYd}~dSd}~ww)Nr�)rE�remove_filern�rename_filermr�r�r�)rPr�r�r�r#r#r$r/Es
���zRenameTempFileHandler.__call__N�r�r�r�rTr/r#r#r#r$rf>srfc@r�)r�cCr&r)r�r{r#r#r$rTUr�zAfterDoneHandler.__init__cKr�r)r�r;r�r#r#r$r/XrpzAfterDoneHandler.__call__Nrsr#r#r#r$r�T�r�c@r�)rgcCr&r)�_fileobj)rPrar#r#r$rT]r�zOnBodyFileObjWriter.__init__cKr�r)ru�write)rPr#r�r#r#r$r/`r�zOnBodyFileObjWriter.__call__Nrsr#r#r#r$rg\rtrgr)=�loggingrL�ior�awscrt.httpr�botocore.awsrequestr��botocore.session�awscrt.authrr�	awscrt.iorrrrr	�	awscrt.s3r
rrr
rr�botocore.compatr�botocore.configr�botocore.exceptionsr�s3transfer.constantsr�s3transfer.exceptionsr�s3transfer.futuresrr�s3transfer.utilsrrr�	getLoggerr�rArr%r@r5rCr�r�r�r�rr%r�rGrfr�rgr#r#r#r$�<module>sV

�
U)&	I