
    5i/                        d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	m
Z
 ddlmZmZmZmZmZmZ ddlZddlZddlmZ dd	lmZmZmZmZ dd
lmZ  G d de      Z G d de      Z G d de      Z G d de      Z  G d de      Z!e G d d             Z"e G d d             Z# G d de      Z$ G d de      Z% G d dejL                  jN                        Z( G d d       Z) G d! d"      Z*d#e+d$efd%Z,d& Z-d' Z.d( Z/d)ee0   fd*Z1y)+z
S3 client
    N)Future)NativeResource)HttpRequest)ClientBootstrapTlsConnectionOptions)AwsCredentialsProviderAwsSignatureTypeAwsSignedBodyHeaderTypeAwsSignedBodyValueAwsSigningAlgorithmAwsSigningConfig)	dataclass)ListOptionalTupleSequence)IntEnumc                   :     e Zd ZdZ fdZd Zd Zd Zd Z xZ	S )CrossProcessLockaU  
    Class representing an exclusive cross-process lock, scoped by `lock_scope_name`

    Recommended usage is to either explicitly call acquire() followed by release() when the lock  is no longer required, or use this in a 'with' statement.

    acquire() will throw a RuntimeError with AWS_MUTEX_CALLER_NOT_OWNER as the error code, if the lock could not be acquired.

    If the lock has not been explicitly released when the process exits, it will be released by the operating system.

    Keyword Args:
        lock_scope_name (str): Unique string identifying the caller holding the lock.
    c                 V    t         |           t        j                  |      | _        y N)super__init___awscrts3_cross_process_lock_new_binding)selflock_scope_name	__class__s     k/home/marpiech/ifpan-abm-pgxpred/analysis/marpiech-gwas-test/venv/lib/python3.12/site-packages/awscrt/s3.pyr   zCrossProcessLock.__init__$   s     99/J    c                 B    t        j                  | j                         y r   )r   s3_cross_process_lock_acquirer   r   s    r    acquirezCrossProcessLock.acquire(       --dmm<r!   c                 &    | j                          | S r   )r%   r$   s    r    	__enter__zCrossProcessLock.__enter__+   s    r!   c                 B    t        j                  | j                         y r   )r   s3_cross_process_lock_releaser   r$   s    r    releasezCrossProcessLock.release/   r&   r!   c                 $    | j                          y r   )r+   )r   exc_type	exc_valueexc_tbs       r    __exit__zCrossProcessLock.__exit__2   s    r!   )
__name__
__module____qualname____doc__r   r%   r(   r+   r0   __classcell__r   s   @r    r   r      s"    K==r!   r   c                        e Zd ZdZdZ	 dZ	 dZy)S3RequestTypezThe type of the AWS S3 requestr         N)r1   r2   r3   r4   DEFAULT
GET_OBJECT
PUT_OBJECT r!   r    r8   r8   6   s'    (G
 J Jr!   r8   c                       e Zd ZdZdZ	 dZy)S3RequestTlsModezTLS mode for S3 requestr   r9   N)r1   r2   r3   r4   ENABLEDDISABLEDr>   r!   r    r@   r@   J   s    !G Hr!   r@   c                   ,    e Zd ZdZdZ	 dZ	 dZ	 dZ	 dZy)S3ChecksumAlgorithmz
    Checksum algorithm used to verify object integrity.
    https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html
    r9   r:            N)	r1   r2   r3   r4   CRC32CCRC32SHA1SHA256	CRC64NVMEr>   r!   r    rD   rD   X   s1    
 FEDFIr!   rD   c                       e Zd ZdZdZ	 dZy)S3ChecksumLocationzWhere to put the checksum.r9   r:   N)r1   r2   r3   r4   HEADERTRAILERr>   r!   r    rN   rN   n   s    $F
 Gr!   rN   c                   L    e Zd ZU dZdZee   ed<   	 dZee	   ed<   	 dZ
eed<   y)S3ChecksumConfigz>Configures how the S3Client calculates and verifies checksums.N	algorithmlocationFvalidate_response)r1   r2   r3   r4   rS   r   rD   __annotations__rT   rN   rU   boolr>   r!   r    rR   rR      s=    H/3Ix+,3
 .2Hh)*1,#t#>r!   rR   c                   F    e Zd ZU dZdZeed<   	 dZee	   ed<   	 dZ
eed<   y)S3FileIoOptionsa  
    WARNING: experimental/unstable, the default behavior is subjected to change in the future.
    Controls how client performance file I/O operations.
    Only applies to the file based workload.
    Notes: only applies when `send_filepath` is set from the request.
    Fshould_stream        disk_throughput_gbps	direct_ioN)r1   r2   r3   r4   rZ   rW   rV   r\   r   floatr]   r>   r!   r    rY   rY      s?      M4 /28E?1	 Itr!   rY   c                        e Zd ZdZdZdddddddddddddddeee      ded   d	ee   f fd
Z	ddddddddddddddddZ
 xZS )S3Clienta  S3 client

    Keyword Args:
        bootstrap (Optional [ClientBootstrap]): Client bootstrap to use when initiating socket connection.
            If None is provided, the default singleton is used.

        region (str): Region that the S3 bucket lives in.

        tls_mode (Optional[S3RequestTlsMode]):  How TLS should be used while performing the request

            If this is :attr:`S3RequestTlsMode.ENABLED`:
                If `tls_connection_options` is set, then those TLS options will be used
                If `tls_connection_options` is unset, then default TLS options will be used

            If this is :attr:`S3RequestTlsMode.DISABLED`:
                No TLS options will be used, regardless of `tls_connection_options` value.

        signing_config (Optional[AwsSigningConfig]): Configuration for signing of the client.
            Use :func:`create_default_s3_signing_config()` to create the default config.

            If not set, a default config will be used with anonymous credentials and skip signing the request.

            If set:
                Credentials provider is required. Other configs are all optional, and will be default to what
                    needs to sign the request for S3, only overrides when Non-zero/Not-empty is set.

                S3 Client will derive the right config for signing process based on this.

            Notes:

                1. For SIGV4_S3EXPRESS, S3 client will use the credentials in the config to derive the S3 Express
                    credentials that are used in the signing process.
                2. Client may make modifications to signing config before passing it on to signer.

        credential_provider (Optional[AwsCredentialsProvider]): Deprecated, prefer `signing_config` instead.
            Credentials providers source the :class:`~awscrt.auth.AwsCredentials` needed to sign an authenticated AWS request.
            If None is provided, the request will not be signed.

        tls_connection_options (Optional[TlsConnectionOptions]): Optional TLS Options to be used
            for each connection, unless `tls_mode` is :attr:`S3RequestTlsMode.DISABLED`

        part_size (Optional[int]): Size, in bytes, of parts that files will be downloaded or uploaded in.
            If not set, a dynamic default part size will be used based on the throughput target, memory_limit_in_bytes.
            Note: for :attr:`S3RequestType.PUT_OBJECT` request, client will adjust the part size to meet the service limits.
            (max number of parts per upload is 10,000, minimum upload part size is 5 MiB)

        multipart_upload_threshold (Optional[int]): The size threshold in bytes, for when to use multipart uploads.
            This only affects :attr:`S3RequestType.PUT_OBJECT` request.
            Uploads over this size will use the multipart upload strategy.
            Uploads this size or less will use a single request.
            If not set, maximal of `part_size` and 5 MiB will be used.

        throughput_target_gbps (Optional[float]): Throughput target in
            Gigabits per second (Gbps) that we are trying to reach.
            You can also use `get_recommended_throughput_target_gbps()` to get recommended value for your system.
            10.0 Gbps by default (may change in future)

        enable_s3express (Optional[bool]): To enable S3 Express support for the client.
            The typical usage for a S3 Express request is to set this to true and let the request to be
            signed with `AwsSigningAlgorithm.V4_S3EXPRESS`, either from the client-level `signing_config`
            or the request-level override.

        memory_limit (Optional[int]): Memory limit, in bytes, of how much memory
            client can use for buffering data for requests.
            If not set, client will try to pick up from environment variable before chose the default.
            Default values scale with target throughput and are currently
            between 2GiB and 24GiB (may change in future)

        network_interface_names (Optional[Sequence(str)]):
            **THIS IS AN EXPERIMENTAL AND UNSTABLE API.**
            A sequence of network interface names. The client will distribute the
            connections across network interfaces. If any interface name is invalid, goes down,
            or has any issues like network access, you will see connection failures.
            This option is only supported on Linux, MacOS, and platforms that have either SO_BINDTODEVICE or IP_BOUND_IF. It
            is not supported on Windows. `AWS_ERROR_PLATFORM_NOT_SUPPORTED` will be raised on unsupported platforms. On
            Linux, SO_BINDTODEVICE is used and requires kernel version >= 5.7 or root privileges.

        fio_options (Optional[S3FileIoOptions]):
            If set, this controls how the client interact with file I/O.
            If not set, a default options will be created to avoid memory issue based on the size of file.
            Note: Only applies when the request created with `send_filepath`

        max_active_connections_override (Optional[int]):
            When set, this will cap the number of active connections for the meta request.
            When not set, the client will determine this value based on `throughput_target_gbps`. (Recommended)
    )shutdown_event_regionNF)	bootstraptls_modesigning_configcredential_providertls_connection_options	part_sizemultipart_upload_thresholdthroughput_target_gbpsenable_s3expressmemory_limitnetwork_interface_namesfio_optionsmax_active_connections_overriderm   rn   rY   ro   c                   t        |t              s|J t        |t              sJ t        |t              s|J t        |t              s|J t        |t
              s|J t        |t              s|J t        |	t              st        |	t              s|	J t        |
t              s|
J t        |t              s|J t        |t              s|J t        |t              s|J |r|rt        d      t        | 5          t        j                         fd}|| _        | _        |st        j$                         }t'        ||||      }|d}|d}|d}|	d}	|d}|t        |t(              st)        |      }|d}d}d}d}d}|&d}|j*                  }|j,                  }|j.                  }t1        j2                  ||||||||||	|
||||||||      | _        y )Nzh'credential_provider' has been deprecated in favor of 'signing_config'.  Both parameters may not be set.c                  &     j                          y r   )set)ra   s   r    on_shutdownz&S3Client.__init__.<locals>.on_shutdown;  s     r!   r   Fr[   T)
isinstancer   strr   r   r   intr^   rW   r   rY   
ValueErrorr   r   	threadingEventrb   ra   get_or_create_static_default_S3ClientCorelistrZ   r\   r]   r   s3_client_newr   )r   rc   regionrd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rs   s3_client_corefio_options_setrZ   r\   r]   ra   r   s                        @r    r   zS3Client.__init__  sm   " )_59JJJ&#&&&.*:;~?UUU-/EFJ]Jeee02FGKaKiii)S)Y->>>"",4		5 5
 *D15E5MMM18<@W@___+7;;NNN93?CbCjjj> ? @ @ 	"*	! ,'DDFI&"	$ HI%-)*&!)%&"L".5t<*./F*G'*2./+"	""O'55M#.#C#C #--I--"&"# +'r!   )operation_namerecv_filepathsend_filepathre   rf   checksum_configrh   ri   rn   ro   
on_headerson_bodyon_doneon_progressc                    t        di d| d|d|d|d|d|d|d|d	|d
|	d|
d|d|d|d|d|d|d| j                  S )a&  Create the Request to the the S3 server,
        :attr:`~S3RequestType.GET_OBJECT`/:attr:`~S3RequestType.PUT_OBJECT` requests are split it into multi-part
        requests under the hood for acceleration.

        Keyword Args:
            type (S3RequestType): The type of S3 request passed in,
                :attr:`~S3RequestType.GET_OBJECT`/:attr:`~S3RequestType.PUT_OBJECT` can be accelerated

            request (HttpRequest): The overall outgoing API request for S3 operation.
                If the request body is a file, set send_filepath for better performance.

            operation_name(Optional[str]): S3 operation name (e.g. "CreateBucket").
                This MUST be set when `type` is :attr:`~S3RequestType.DEFAULT`.
                It is ignored for other types, since the operation is implicitly known.
                See `S3 API documentation
                <https://docs.aws.amazon.com/AmazonS3/latest/API/API_Operations_Amazon_Simple_Storage_Service.html>`_
                for the canonical list of names.

                This name is used to fill out details in metrics and error reports.
                It also drives some operation-specific behavior.
                If you pass the wrong name, you risk getting the wrong behavior.

                For example, every operation except "GetObject" has its response checked
                for error, even if the HTTP status-code was 200 OK
                (see `knowledge center <https://repost.aws/knowledge-center/s3-resolve-200-internalerror>`_).
                If you used the :attr:`~S3RequestType.DEFAULT` type to do
                `GetObject <https://docs.aws.amazon.com/AmazonS3/latest/API/API_GetObject.html>`_,
                but mis-named it "Download", and the object looked like XML with an error code,
                then the request would fail. You risk logging the full response body,
                and leaking sensitive data.

            recv_filepath (Optional[str]): Optional file path. If set, the
                response body is written directly to a file and the
                `on_body` callback is not invoked. This should give better
                performance than writing to file from the `on_body` callback.

            send_filepath (Optional[str]): Optional file path. If set, the
                request body is read directly from a file and the
                request's `body_stream` is ignored. This should give better
                performance than reading a file from a stream.

            signing_config (Optional[AwsSigningConfig]): Configuration for signing of the request to override the configuration from client.
                Use :func:`create_default_s3_signing_config()` to create the default config.

                If None is provided, the client configuration will be used.

                If set:
                    All fields are optional. The credentials will be resolve from client if not set.
                    S3 Client will derive the right config for signing process based on this.

                Notes:

                    1. For SIGV4_S3EXPRESS, S3 client will use the credentials in the config to derive the S3 Express
                        credentials that are used in the signing process.
                    2. Client may make modifications to signing config before passing it on to signer.

            credential_provider (Optional[AwsCredentialsProvider]):  Deprecated, prefer `signing_config` instead.
                Credentials providers source the :class:`~awscrt.auth.AwsCredentials` needed to sign an authenticated AWS request, for this request only.
                If None is provided, the client configuration will be used.

            checksum_config (Optional[S3ChecksumConfig]): Optional checksum settings.

            part_size (Optional[int]): Size, in bytes, of parts that files will be downloaded or uploaded in.
                If not set, the part size configured for the client will be used, which defaults to a dynamic value based on
                the throughput target, memory_limit_in_bytes and the requested object size.
                Note: for :attr:`S3RequestType.PUT_OBJECT` request, client will adjust the part size to meet the service limits.
                (max number of parts per upload is 10,000, minimum upload part size is 5 MiB)

            multipart_upload_threshold (Optional[int]): The size threshold in bytes, for when to use multipart uploads.
                This only affects :attr:`S3RequestType.PUT_OBJECT` request.
                Uploads over this size will use the multipart upload strategy.
                Uploads this size or less will use a single request.
                If set, this should be at least `part_size`.
                If not set, `part_size` adjusted by client will be used as the threshold.
                If both `part_size` and `multipart_upload_threshold` are not set,
                the values from `aws_s3_client_config` are used.

            fio_options (Optional[S3FileIoOptions]):
                If set, this overrides the client fio_options to control how this request interact with file I/O.
                If not set, a default options will be created to avoid memory issue based on the size of file.
                Note: Only applies when the request created with `send_filepath`

            max_active_connections_override (Optional[int]):
                When set, this will cap the number of active connections for the meta request.
                When not set, the client will determine it based on client side settings. (Recommended)

            on_headers: Optional callback invoked as the response received, and even the API request
                has been split into multiple parts, this callback will only be invoked once as
                it's just making one API request to S3.
                The function should take the following arguments and return nothing:

                    *   `status_code` (int): Response status code.

                    *   `headers` (List[Tuple[str, str]]): Response headers as a
                        list of (name,value) pairs.

                    *   `**kwargs` (dict): Forward-compatibility kwargs.

            on_body: Optional callback invoked 0+ times as the response body received from S3 server.
                If simply writing to a file, use `recv_filepath` instead of `on_body` for better performance.
                The function should take the following arguments and return nothing:

                    *   `chunk` (buffer): Response body data (not necessarily
                        a whole "chunk" of chunked encoding).

                    *   `offset` (int): The offset of the chunk started in the whole body.

                    *   `**kwargs` (dict): Forward-compatibility kwargs.

            on_done: Optional callback invoked when the request has finished the job.
                The function should take the following arguments and return nothing:

                    *   `error` (Optional[Exception]): None if the request was
                        successfully sent and valid response received, or an Exception
                        if it failed.

                    *   `error_headers` (Optional[List[Tuple[str, str]]]): If request
                        failed because server side sent an unsuccessful response, the headers
                        of the response is provided here. Else None will be returned.

                    *   `error_body` (Optional[bytes]): If request failed because server
                        side sent an unsuccessful response, the body of the response is
                        provided here. Else None will be returned.

                    *   `error_operation_name` (Optional[str]): If request failed
                        because server side sent and unsuccessful response, this
                        is the name of the S3 operation it was responding to.
                        For example, if a :attr:`~S3RequestType.PUT_OBJECT` fails
                        this could be "PutObject", "CreateMultipartUpload", "UploadPart",
                        "CompleteMultipartUpload", or others. For :attr:`~S3RequestType.DEFAULT`,
                        this is the `operation_name` passed to :meth:`S3Client.make_request()`.
                        This will be None if the request failed for another reason,
                        or the S3 operation name is unknown.

                    *   `status_code` (Optional[int]): HTTP response status code (if available).
                        If request failed because server side sent an unsuccessful response,
                        this is its status code. If the operation was successful,
                        this is the final response's status code. If the operation
                        failed for another reason, None is returned.

                    *   `did_validate_checksum` (bool):
                            Was the server side checksum compared against a calculated checksum of the response body.
                            This may be false even if :attr:`S3ChecksumConfig.validate_response` was set because
                            the object was uploaded without a checksum, or downloaded differently from how it's uploaded.

                    *   `checksum_validation_algorithm` (Optional[S3ChecksumAlgorithm]): The checksum algorithm used to validate the response.

                    *   `**kwargs` (dict): Forward-compatibility kwargs.

            on_progress: Optional callback invoked when part of the transfer is done to report the progress.
                The function should take the following arguments and return nothing:

                    *   `progress` (int): Number of bytes of data that just get transferred

                    *   `**kwargs` (dict): Forward-compatibility kwargs.

        Returns:
            S3Request
        clienttyperequestr   r   r   re   rf   r   rh   ri   rn   ro   r   r   r   r   r~   r>   )	S3Requestrb   )r   r   r   r   r   r   re   rf   r   rh   ri   rn   ro   r   r   r   r   s                    r    make_requestzS3Client.make_requestz  s    d  !!! ! *	!
 (! (! *! !4! ,!  ! (B! $! -L! "! !  !!" $#!$ <<%! 	!r!   )r1   r2   r3   r4   	__slots__r   r   ru   rv   r   r   r5   r6   s   @r    r`   r`      s    Un .I
  $#''+#'"?C7;=A!f &.hsm%<f ""34f  .6c]!fZ   $ '+,0%D! D!r!   r`   c                   ^     e Zd ZdZdZdddddddddddddddd fd
Zed        Zd Z xZ	S )r   aN  S3 request
    Create a new S3Request with :meth:`S3Client.make_request()`

    Attributes:
        finished_future (concurrent.futures.Future): Future that will
            resolve when the s3 request has finished successfully.
            If the error happens, the Future will contain an exception
            indicating why it failed. Note: Future will set before on_done invoked

        shutdown_event (threading.Event): Signals when underlying threads and
            structures have all finished shutting down. Shutdown begins when the
            S3Request object is destroyed.
    )_finished_futurera   N)r   r   r   re   rf   r   rh   ri   rn   ro   r   r   r   r   r~   c                   t        |t              sJ t        |t              sJ t        |      s|J t        |      s|J t        |      s|J t        |
t              s|
J t        |t              s|J t        |t
              s|J t        |t              s|J |t        j                  k(  r|st        d      t        | )          t               | _        t        j                         | _        |
d}
|d}d}d}d}|	P|	j                   |	j                   j"                  }|	j$                  |	j$                  j"                  }|	j&                  }d}d}d}d}|&d}|j(                  }|j*                  }|j,                  }|d}t/        || j                  | j                  ||||||	      }t1        j2                  | |||||||||||||
|||||||      | _        y )Nz='operation_name' must be set when using S3RequestType.DEFAULTr   Fr[   T)rt   r`   r   callablerv   rY   r8   r;   rw   r   r   r   r   rx   ry   ra   rS   valuerT   rU   rZ   r\   r]   _S3RequestCorer   s3_client_make_meta_requestr   )r   r   r   r   r   r   r   re   rf   r   rh   ri   rn   ro   r   r   r   r   r~   checksum_algorithmchecksum_locationvalidate_response_checksumr   rZ   r\   r]   s3_request_corer   s                              r    r   zS3Request.__init__Q  s?   * &(+++';///
#z'999 GO33 GO33)S)Y->>>4c:>X>```+7;;NNN93?CbCjjj=(((\]] &'oo/ I%-)*&%*"&((4%4%>%>%D%D"''3$3$<$<$B$B!)8)J)J&"	""O'55M#.#C#C #--I*2./+(!!	  ;;&& ++r!   c                     | j                   S r   )r   r$   s    r    finished_futurezS3Request.finished_future  s    $$$r!   c                 .    t        j                  |        y r   )r   s3_meta_request_cancelr$   s    r    cancelzS3Request.cancel  s    &&t,r!   )
r1   r2   r3   r4   r   r   propertyr   r   r5   r6   s   @r    r   r   A  s^     7I   $ '+,0)aF % %-r!   r   c                   x     e Zd ZdZddddddedededeeeef      deeeef      d	ee	   d
ee   f fdZ
 xZS )S3ResponseErroraf  
    An error response from S3.

    Subclasses :class:`awscrt.exceptions.AwsCrtError`.

    Attributes:
        status_code (int): HTTP response status code.
        headers (list[tuple[str, str]]): Headers from HTTP response.
        body (Optional[bytes]): Body of HTTP response (if any).
            This is usually XML. It may be None in the case of a HEAD response.
        operation_name: Name of the S3 operation that failed.
            For example, if a :attr:`~S3RequestType.PUT_OBJECT` fails
            this could be "PutObject", "CreateMultipartUpload", "UploadPart",
            "CompleteMultipartUpload", or others. For :attr:`~S3RequestType.DEFAULT`,
            this is the `operation_name` passed to :meth:`S3Client.make_request()`.
        code (int): CRT error code.
        name (str): CRT error name.
        message (str): CRT error message.
    N)status_codeheadersbodyr   codenamemessager   r   r   r   c                `    t         |   |||       || _        || _        || _        || _        y r   )r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   s	           r    r   zS3ResponseError.__init__  s4     	tW-&	,r!   )r1   r2   r3   r4   rv   ru   r   r   r   bytesr   r5   r6   s   @r    r   r     s    0 7;26)-15--- - #5c?3	-
 uS#X/-  - "*#- -r!   r   c                       e Zd ZdZ	 	 	 ddZy)r{   zf
    Private class to keep all the related Python object alive until C land clean up for S3Client
    Nc                 <    || _         || _        || _        || _        y r   )
_bootstrap_credential_provider_signing_config_tls_connection_options)r   rc   rf   re   rg   s        r    r   z_S3ClientCore.__init__  s#     $$7!-'=$r!   )NNN)r1   r2   r3   r4   r   r>   r!   r    r{   r{     s    
 &* $(,>r!   r{   c                   B    e Zd ZdZ	 	 	 	 	 	 d	dZd Zd Zd Zd Zd Z	y)
r   zg
    Private class to keep all the related Python object alive until C land clean up for S3Request
    Nc
                     d | _         || _        || _        || _        || _        || _        || _        |	| _        || _        || _	        y r   )
_python_callback_exception_requestr   r   _on_headers_cb_on_body_cb_on_done_cb_on_progress_cbr   _shutdown_event)
r   r   finish_futurera   re   rf   r   r   r   r   s
             r    r   z_S3RequestCore.__init__  sS     +/'-$7!(""* --r!   c                     | j                   r	 | j                  ||       yy # t        $ r}|| _        Y d }~yd }~ww xY w)N)r   r   TF)r   BaseExceptionr   )r   r   r   es       r    _on_headersz_S3RequestCore._on_headers  sH    ##W#M  ! 23/   # 	=8=c                     | j                   r	 | j                  ||       yy # t        $ r}|| _        Y d }~yd }~ww xY w)N)chunkoffsetTF)r   r   r   )r   r   r   r   s       r    _on_bodyz_S3RequestCore._on_body  sH      uV <  ! 23/r   c                 8    | j                   j                          y r   )r   rr   r$   s    r    _on_shutdownz_S3RequestCore._on_shutdown   s      "r!   c           	      0   |dk(  rd }d }|rt         j                  j                  |      }t        |t         j                  j                        r\|j
                  dk(  r| j                  | j                  }n4|2|0t        |j                  |j
                  |j                  ||||      }| j                  j                  |       n| j                  j                  d        |rt        |      }nd }| j                  r| j                  |||||||       y y )Nr    AWS_ERROR_CRT_CALLBACK_EXCEPTION)r   r   r   r   r   r   r   )errorerror_headers
error_bodyerror_operation_namer   did_validate_checksumchecksum_validation_algorithm)awscrt
exceptions	from_codert   AwsCrtErrorr   r   r   r   r   r   set_exception
set_resultrD   r   )	r   
error_coder   r   r   r   r   r   r   s	            r    
_on_finishz_S3RequestCore._on_finish#  s    !K%%//
;E%!2!2!>!>?JJ"DD ;;G ;;E !,)5+"ZZ"ZZ %$/ -'';=E !!//6!!,,T2(,?@],^),0)+%%9'&;.K  M r!   c                 @    | j                   r| j                  |       y y r   )r   )r   progresss     r    _on_progressz_S3RequestCore._on_progressV  s      *  r!   )NNNNNN)
r1   r2   r3   r4   r   r   r   r   r   r   r>   r!   r    r   r     s;       $.4#1Mf+r!   r   r~   rf   c                     t        t        j                  t        j                  dt
        j                  t        j                  | |dd	      S )al  Create a default `AwsSigningConfig` for S3 service.

        Attributes:
            region (str): The region to sign against.

            credential_provider (AwsCredentialsProvider): Credentials provider
                to fetch signing credentials with.

            `**kwargs`: Forward compatibility kwargs.

        Returns:
            AwsSigningConfig
    s3F)	rS   signature_typeservicesigned_body_header_typesigned_body_valuer~   credentials_provideruse_double_uri_encodeshould_normalize_uri_path)	r   r   V4r	   HTTP_REQUEST_HEADERSr
   X_AMZ_CONTENT_SHA_256r   UNSIGNED_PAYLOAD)r~   rf   kwargss      r     create_default_s3_signing_configr   [  sD     %(('<< 7 M M,==0#"'
 
r!   c                  *    t        j                         S )a  
        First this function will check it's running on EC2 via. attempting to read DMI info to avoid making IMDS calls.

        If the function detects it's on EC2, and it was able to detect the instance type without a call to IMDS
        it will return it.

        Finally, it will call IMDS and return the instance type from there.
        Note that in the case of the IMDS call, a new client stack is spun up using 1 background thread. The call is made
        synchronously with a 1 second timeout: It's not cheap. To make this easier, the underlying result is cached
        internally and will be freed when this module is unloaded is called.

        Returns:
           A string indicating the instance type or None if it could not be determined.
    )r   s3_get_ec2_instance_typer>   r!   r    get_ec2_instance_typer   v  s     ++--r!   c                  *    t        j                         S )z
        Returns:
            true if the current build of this module has an optimized configuration
            for the current system.
    )r   !s3_is_crt_s3_optimized_for_systemr>   r!   r    is_optimized_for_systemr     s     4466r!   c                  *    t        j                         S )a<  
    Returns:
        A list[str] of platform identifiers, such as EC2 instance types, for which S3 client is pre-optimized
        and have a recommended throughput_target_gbps. You can use `get_recommended_throughput_target_gbps()`
        to obtain the recommended throughput_target_gbps for those platforms.
    )r   s3_get_optimized_platformsr>   r!   r    get_optimized_platformsr     s     --//r!   returnc                  :    t        j                         } | dkD  r| S y)z
    Returns:
        Recommended throughput, in gigabits per second, based on detected system configuration.
        If the best throughput configuration is unknown, returns None.
        Use this as the S3Client's `throughput_target_gbps`.
    r   N)r   )s3_get_recommended_throughput_target_gbps)	max_values    r    &get_recommended_throughput_target_gbpsr     s"     AACI1}r!   )2r4   r   concurrent.futuresr   r   r   awscrt.httpr   	awscrt.ior   r   awscrt.authr   r	   r
   r   r   r   awscrt.exceptionsrx   dataclassesr   typingr   r   r   r   enumr   r   r8   r@   rD   rN   rR   rY   r`   r   r   r   r   r{   r   ru   r   r   r   r   r^   r   r>   r!   r    <module>r      s(    % ! # ;* *   ! 2 2 ~ @G (w ' , $ ? ? ?  # # #LF!~ F!Rx- x-v!-f''33 !-H> >i+ i+X J` 6.$70 r!   