
    -ji                       % S SK Jr  S SKrS SKrS SKJr  S SKJr  S SKJ	r	  \(       a  S SKJ
r
  S SKJr  \" 5        rS SKrS SKJr  SSS5         " S	 S
5      rSS jr\(       a  S SKJr  \" S5      rS\S'   gg! , (       d  f       N9= f)    )annotationsN)TYPE_CHECKING)
try_import)ArtifactNotFound)BinaryIO)S3Client)ClientErrorc                  \    \ rS rSrSr SSS.       SS jjjrSS jrSS jrSS	 jrS
r	g)Boto3ArtifactStore   a3  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                   [         R                  5         Xl        U=(       d    [        R                  " S5      U l        X0l        g )Ns3)_importscheckbucketboto3client_avoid_buf_copy)selfbucket_namer   r   s       Q/home/james-whalen/.local/lib/python3.13/site-packages/optuna/artifacts/_boto3.py__init__Boto3ArtifactStore.__init__;   s0     	!2T 2  .    c                     U R                   R                  U R                  US9nUR                  S5      nUc   eU$ ! [         a3  n[	        U5      (       a  [        SU R                   SU S35      Uee S nAff = f)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_readerBoto3ArtifactStore.open_readerE   s    	++(((MC wwv  	"1%%&4T[[MQ\P] ^! !  	s   $> 
A;.A66A;c                    UnU R                   (       d>  [        R                  " 5       n[        R                  " X$5        UR                  S5        UnU R                  R                  X0R                  U5        g )Nr   )	r   ioBytesIOshutilcopyfileobjseekr   upload_fileobjr   )r   r$   content_bodyfsrcbufs        r   writeBoto3ArtifactStore.writeS   sQ    %##**,C|1HHQKD""4kBr   c                L    U R                   R                  U R                  US9  g )Nr   )r   delete_objectr   )r   r$   s     r   removeBoto3ArtifactStore.remove\   s    !!+!Fr   )r   r   r   )N)r   strr   zS3Client | Noner   boolreturnNone)r$   r:   r<   r   )r$   r:   r1   r   r<   r=   )r$   r:   r<   r=   )
__name__
__module____qualname____firstlineno____doc__r   r(   r4   r8   __static_attributes__ r   r   r   r      sK    #L ;?.Z_..(7.SW.	.CGr   r   c                    U R                   R                  S0 5      R                  S5      nU R                   R                  S0 5      R                  S5      nUS:H  =(       d    US:H  $ )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 rN   _)r&   r	   r<   r;   )
__future__r   r+   r-   typingr   optuna._importsr   optuna.artifacts.exceptionsr   r   mypy_boto3_s3r   r   r   botocore.exceptionsr	   r   r"   optuna.artifacts._protocolrN   rP   __annotations__rD   r   r   <module>rY      sp    " 	    & 8 &\X/ 
HG HGV@  9)"-A}- m \s   A::
B