
    !#h                        d dl m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
 d dlmZ d dlmZ d dlmZ d d	lmZ d d
lmZ dZdZe G d d             Z e
g d      dddd	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zy)    )annotations)asdict)	dataclassN)convert_positional_args)ArtifactStore)BaseStorage)Study)FrozenTrial)Trialz
artifacts:zapplication/octet-streamc                  :    e Zd ZU dZded<   ded<   ded<   ded<   y)	ArtifactMetaa  Meta information for an artifact.

    .. note::
        All the artifact meta linked to a study or trial can be listed by
        :func:`~optuna.artifacts.get_all_artifact_meta`.
        The artifact meta can be used for :func:`~optuna.artifacts.download_artifact`.

    Args:
        artifact_id:
            The identifier of the artifact.
        filename:
            The artifact file name used for the upload.
        mimetype:
            A MIME type of the artifact.
            If not specified, the MIME type is guessed from the file extension.
        encoding:
            An encoding of the artifact, which is suitable for use as a Content-Encoding header,
            e.g., gzip. If not specified, the encoding is guessed from the file extension.
    strartifact_idfilenamemimetype
str | NoneencodingN)__name__
__module____qualname____doc____annotations__     U/var/www/html/sandstorm/venv/lib/python3.12/site-packages/optuna/artifacts/_upload.pyr   r      s    ( MMr   r   )study_or_trial	file_pathartifact_store)previous_positional_arg_names)storager   r   c           	        t         j                  j                  |      }t        |t              r||j
                  }nt        |t              r||j                  }|t        d      t        t        j                               }t        j                  |      \  }}	t        |||xs
 |xs t        |xs |	      }
t         |z   }t        |t        t"        f      r<|j$                  }|j'                  ||t)        j*                  t-        |
                   n;|j.                  }|j1                  ||t)        j*                  t-        |
                   t3        |d      5 }| j5                  ||       ddd       |S # 1 sw Y   |S xY w)as  Upload an artifact to the artifact store.

    Args:
        artifact_store:
            An artifact store.
        file_path:
            A path to the file to be uploaded.
        study_or_trial:
            A :class:`~optuna.trial.Trial` object, a :class:`~optuna.trial.FrozenTrial`, or
            a :class:`~optuna.study.Study` object.
        storage:
            A storage object. This argument is required only if ``study_or_trial`` is
            :class:`~optuna.trial.FrozenTrial`.
        mimetype:
            A MIME type of the artifact. If not specified, the MIME type is guessed from the file
            extension.
        encoding:
            An encoding of the artifact, which is suitable for use as a ``Content-Encoding``
            header (e.g. gzip). If not specified, the encoding is guessed from the file extension.

    Returns:
        An artifact ID.
    Nz$storage is required for FrozenTrial.)r   r   r   r   rb)ospathbasename
isinstancer   r    r	   _storage
ValueErrorr   uuiduuid4	mimetypes
guess_typer   DEFAULT_MIME_TYPEARTIFACTS_ATTR_PREFIXr
   	_trial_idset_trial_system_attrjsondumpsr   	_study_idset_study_system_attropenwrite)r   r   r   r    r   r   r   r   guess_mimetypeguess_encodingartifactattr_keytrial_idstudy_idfs                  r   upload_artifactr>   2   sP   H ww	*H.%(W_ ((	NE	*w ))?@@djjl#K%.%9%9(%C"NN@^@/@+^	H %{2H.5+"67!++%%h$**VHEU:VW!++%%h$**VHEU:VW	i	 -![!,--s    E==F)r   r   r   r   r   zTrial | FrozenTrial | Studyr    zBaseStorage | Noner   r   r   r   returnr   )
__future__r   dataclassesr   r   r1   r+   r#   r)   optuna._convert_positional_argsr   optuna.artifacts._protocolr   optuna.storagesr   optuna.studyr	   optuna.trialr
   r   r.   r-   r   r>   r   r   r   <module>rG      s    "  !   	  C 4 '  $  % .    6 "S #'=!= = 0	=
  = = = 	==r   