o
    h\                     @   s`   d dl mZmZ ddlmZmZ dgZG dd dZ		dded	ee d
ddddef
ddZ	dS )    )DictList   )	GlobGroupGlobPattern	Directoryc                   @   s~   e Zd ZdZdedefddZdee dd fdd	Zd
efddZ	dedefddZ
dd Z	ddee dedefddZdS )r   zA file structure representation. Organized as Directory nodes that have lists of
    their Directory children. Directories for a package are created by calling
    :meth:`PackageImporter.file_structure`.nameis_dirc                 C   s   || _ || _i | _d S )N)r   r	   children)selfr   r	    r   a/var/www/html/ai/venv/lib/python3.10/site-packages/torch/package/file_structure_representation.py__init__   s   
zDirectory.__init__dirsreturnc                 C   sJ   t |dkr| S |d }|| jvrt|d| j|< | j| |dd S )a$  Builds path of Directories if not yet built and returns last directory
        in list.

        Args:
            dirs (List[str]): List of directory names that are treated like a path.

        Returns:
            :class:`Directory`: The last Directory specified in the dirs list.
        r   Tr   N)lenr
   r   _get_dir)r   r   dir_namer   r   r   r      s   

zDirectory._get_dir	file_pathc                 C   s.   | d^ }}| |}t|d|j|< dS )zAdds a file to a Directory.

        Args:
            file_path (str): Path of file to add. Last element is added as a file while
                other paths items are added as directories.
        /FN)splitr   r   r
   )r   r   r   filedirr   r   r   	_add_file#   s   
zDirectory._add_filefilenamec                 C   s\   |j ddd}|d }t|dkr|d nd}|| j v r,|du r$dS | j| |S dS )zChecks if a file is present in a :class:`Directory`.

        Args:
            filename (str): Path of file to search for.
        Returns:
            bool: If a :class:`Directory` contains the specified file.
        r   r   )maxsplitr   NTF)r   r   r
   keyshas_file)r   r   lineagechildgrandchildrenr   r   r   r   .   s   zDirectory.has_filec                 C   s   g }|  | d|S )N )_stringify_treejoin)r   str_listr   r   r   __str__@   s   

zDirectory.__str__r!   
   ─── r$   preambledir_ptrc                 C   s"  d}d}d}d}| | | | j d ||kr|| }n|| }g }g }	| j D ]\}
}|jr8|	 |
 q+| |
 q+tt|	D ]'\}}
|t|	d krat|dkra| j|
 ||| qD| j|
 ||| qDtt|D ]\}}|t|d kr|n|}| | | | d qrdS )	zCRecursive method to generate print-friendly version of a Directory.z    u   │   u
   ├── u
   └── 
r   r   N)	appendr   r
   itemsr	   	enumeratesortedr   r"   )r   r$   r'   r(   spacebranchteelast	file_keysdir_keyskeyvalindexr   pointerr   r   r   r"   E   s,   
zDirectory._stringify_treeN)r!   r&   )__name__
__module____qualname____doc__strboolr   r   r   r   r   r%   r"   r   r   r   r   r      s    **r   r   	file_listincluder   excluder   c                 C   s:   t ||dd}t| d}|D ]}||r|| q|S )a  Return a :class:`Directory` file structure representation created from a list of files.

    Args:
        filename (str): The name given to the top-level directory that will be the
            relative root for all file paths found in the file_list.

        file_list (List[str]): List of files to add to the top-level directory.

        include (Union[List[str], str]): An optional pattern that limits what is included from the file_list to
            files whose name matches the pattern.

        exclude (Union[List[str], str]): An optional pattern that excludes files whose name match the pattern.

    Returns:
            :class:`Directory`: a :class:`Directory` file structure representation created from a list of files.
    r   )rA   	separatorT)r   r   matchesr   )r   r?   r@   rA   glob_patterntop_dirr   r   r   r    _create_directory_from_file_listi   s   


rF   N)r>   r   )
typingr   r   
glob_groupr   r   __all__r   r<   rF   r   r   r   r   <module>   s"    d