
    (^i                        U d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 erd dlm
Z
 d dlmZ  e       5 Zd dlZd dlmZ ddd        G d	 d
      ZddZerd dlmZ  ed      Zded<   yy# 1 sw Y   .xY w)    )annotationsN)TYPE_CHECKING)
try_import)ArtifactNotFound)BinaryIO)S3Client)ClientErrorc                  H    e Zd ZdZ	 d	dd	 	 	 	 	 	 	 d
dZddZddZddZy)Boto3ArtifactStorea  An artifact backend for Boto3.

    Args:
        bucket_name:
            The name of the bucket to store artifacts.

        client:
            A Boto3 client to use for storage operations. If not specified, a new client will
            be created.

        avoid_buf_copy:
            If True, skip procedure to copy the content of the source file object to a buffer
            before uploading it to S3 ins. This is default to False because using
            ``upload_fileobj()`` method of Boto3 client might close the source file object.

    Example:
        .. code-block:: python

            import optuna
            from optuna.artifacts import upload_artifact
            from optuna.artifacts import Boto3ArtifactStore


            artifact_store = Boto3ArtifactStore("my-bucket")


            def objective(trial: optuna.Trial) -> float:
                ... = trial.suggest_float("x", -10, 10)
                file_path = generate_example(...)
                upload_artifact(
                    artifact_store=artifact_store,
                    file_path=file_path,
                    study_or_trial=trial,
                )
                return ...
    NF)avoid_buf_copyc                   t         j                          || _        |xs t        j                  d      | _        || _        y )Ns3)_importscheckbucketboto3client_avoid_buf_copy)selfbucket_namer   r   s       X/var/www/html/hubwallet-dev/venv/lib/python3.12/site-packages/optuna/artifacts/_boto3.py__init__zBoto3ArtifactStore.__init__;   s4     	!2T 2  .    c                    	 | j                   j                  | j                  |      }|j                  d      }|J |S # t        $ r.}t	        |      rt        d| j                   d| d      | d }~ww xY w)NBucketKeyzArtifact storage with bucket: z, artifact_id: z was not foundBody)r   
get_objectr   r	   _is_not_found_errorr   get)r   artifact_idobjebodys        r   open_readerzBoto3ArtifactStore.open_readerE   s    	++(((MC wwv  	"1%&4T[[MQ\P] ^! !  	s   'A   	A7	)A22A7c                    |}| j                   s=t        j                         }t        j                  ||       |j                  d       |}| j                  j                  || j                  |       y )Nr   )	r   ioBytesIOshutilcopyfileobjseekr   upload_fileobjr   )r   r"   content_bodyfsrcbufs        r   writezBoto3ArtifactStore.writeS   sU    %##**,C|S1HHQKD""4kBr   c                R    | j                   j                  | j                  |       y )Nr   )r   delete_objectr   )r   r"   s     r   removezBoto3ArtifactStore.remove\   s    !!+!Fr   )N)r   strr   zS3Client | Noner   boolreturnNone)r"   r5   r7   r   )r"   r5   r.   r   r7   r8   )r"   r5   r7   r8   )__name__
__module____qualname____doc__r   r&   r1   r4    r   r   r   r      sK    #L ;?.Z_..(7.SW.	.CGr   r   c                    | j                   j                  di       j                  d      }| j                   j                  di       j                  d      }|dk(  xs |dk(  S )NErrorCodeResponseMetadataHTTPStatusCode	NoSuchKeyi  )responser!   )r$   
error_codehttp_status_codes      r   r    r    `   sY    ,008Jzz~~&8"=AABRS$?(8C(??r   )ArtifactStore rG   _)r$   r	   r7   r6   )
__future__r   r(   r*   typingr   optuna._importsr   optuna.artifacts.exceptionsr   r   mypy_boto3_s3r   r   r   botocore.exceptionsr	   r   r    optuna.artifacts._protocolrG   rI   __annotations__r=   r   r   <module>rR      sx    " 	    & 8 &\ 0X/0
HG HGV@  9)"-A}- m0 0s   A//A8