o
    ni7                     @   sd   d dl Z d dlmZ d dlmZ d dlmZ defddZG dd	 d	eZ	d
ede	defddZ
dS )    N)Enum)urlparse)is_artifact_registry_projectreturnc                 C   sX   d}t | }t|| }|std|jd^}}|jd}d| d| }|S )a  Convert an S3 HTTP(S) URL to an S3 URI.

    Arguments:
        url (str): The S3 URL to convert, in the format
                   'http(s)://<bucket>.s3.<region>.amazonaws.com/<key>'.
                   or 'http(s)://<bucket>.s3.amazonaws.com/<key>'

    Returns:
        str: The corresponding S3 URI in the format 's3://<bucket>/<key>'.

    Raises:
        ValueError: If the provided URL is not a valid S3 URL.
    z ^https?://.*s3.*amazonaws\.com.*zInvalid S3 URL./zs3://)	r   rematchgeturl
ValueErrornetlocsplitpathlstrip)url
s3_pattern
parsed_urlr	   bucket_name_keys3_uri r   U/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/apis/public/utils.pyparse_s3_url_to_s3_uri   s   r   c                   @   s   e Zd ZdZdZdZdS )PathTypezWe have lots of different paths users pass in to fetch artifacts, projects, etc.

    This enum is used for specifying what format the path is in given a string path.
    PROJECTARTIFACTN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   )   s    r   r   	path_typec                 C   sH   |  d}|tjkrdnd}t||kr"|dd \}}t|r"|S dS )a  Parse the org from a registry path.

    Essentially fetching the "entity" from the path but for Registries the entity is actually the org.

    Args:
        path (str): The path to parse. Can be a project path <entity>/<project> or <project> or an
        artifact path like <entity>/<project>/<artifact> or <project>/<artifact> or <artifact>
        path_type (PathType): The type of path to parse.
    r         N )r   r   r   lenr   )r   r!   partsexpected_partsorgprojectr   r   r   parse_org_from_registry_path3   s   

r*   )r   enumr   urllib.parser   wandb.sdk.artifacts._validatorsr   strr   r   r*   r   r   r   r   <module>   s    !
