o
    
۾i
                     @   s  d dl Z d dlmZ d dlmZ erd dlmZ zd dlZW n ey+   edZY nw de	e
 de	e
 de	e
 fd	d
Zde	e
 de	e
 de	e
 fddZ			dddde
de	e
 dB de	e
 fddZ		dddde
de	e
 dB de	e
 dB dee
e
e	e
 f f
ddZdS )    N)TYPE_CHECKING)PlaceholderModule)
BaseClientboto3pathspatternsreturnc                        fdd| D S )Nc                    s&   g | ] t  fd dD r qS )c                 3       | ]	}t   |V  qd S Nfnmatch.0patternpath T/home/ubuntu/.local/lib/python3.10/site-packages/vllm/transformers_utils/s3_utils.py	<genexpr>       z+_filter_allow.<locals>.<listcomp>.<genexpr>anyr   r   r   r   
<listcomp>       z!_filter_allow.<locals>.<listcomp>r   r   r   r   r   r   _filter_allow      
r   c                    r	   )Nc                    s&   g | ] t  fd dD s qS )c                 3   r
   r   r   r   r   r   r   r      r   z,_filter_ignore.<locals>.<listcomp>.<genexpr>r   r   r   r   r   r      r   z"_filter_ignore.<locals>.<listcomp>r   r   r   r   r   _filter_ignore   r   r     s3zBaseClient | Noner   allow_patternc                    sJ   | du r	t d} |ds|d }t| ||d\ }} fdd|D S )a)  
    List full file names from S3 path and filter by allow pattern.

    Args:
        s3: S3 client to use.
        path: The S3 path to list from.
        allow_pattern: A list of patterns of which files to pull.

    Returns:
        list[str]: List of full S3 paths allowed by the pattern
    Nr"   /)r   r#   c                    s   g | ]
}d   d| qS )s3://r$   r   )r   r   bucket_namer   r   r   7   s    zglob.<locals>.<listcomp>)r   clientendswith
list_files)r"   r   r#   _r   r   r&   r   glob"   s   

r,   r   ignore_patternc           	      C   s   | dd}d|dd }|d }| j||d}dd |d	g D }t|d
g}|dur6t||}|dur?t||}|||fS )aZ  
    List files from S3 path and filter by pattern.

    Args:
        s3: S3 client to use.
        path: The S3 path to list from.
        allow_pattern: A list of patterns of which files to pull.
        ignore_pattern: A list of patterns of which files not to pull.

    Returns:
        tuple[str, str, list[str]]: A tuple where:
            - The first element is the bucket name
            - The second element is string represent the bucket
              and the prefix as a dir like string
            - The third element is a list of files allowed or
              disallowed by pattern
    r%   r$      Nr   )BucketPrefixc                 S   s   g | ]}|d  qS )Keyr   )r   objr   r   r   r   V   s    zlist_files.<locals>.<listcomp>Contentsz*/)removeprefixsplitjoinlist_objects_v2getr    r   )	r"   r   r#   r-   partsprefixr'   objectsr   r   r   r   r*   :   s   


r*   )Nr!   N)NN)r   typingr   vllm.utils.import_utilsr   botocore.clientr   r   ImportErrorliststrr   r    r,   tupler*   r   r   r   r   <module>   sJ   ""	



