
    sg                     f    d dl mZmZ ddlmZmZ dgZ G d d      Z	 	 ddedee   dd	d
d	def
dZ	y)    )DictList   )	GlobGroupGlobPattern	Directoryc                   x    e Zd ZdZdedefdZdee   dd fdZdefd	Z	d
edefdZ
d Z	 	 ddee   dedefdZy)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                 .    || _         || _        i | _        y )N)r
   r   children)selfr
   r   s      ^/var/www/html/venv/lib/python3.12/site-packages/torch/package/file_structure_representation.py__init__zDirectory.__init__   s    	.0    dirsreturnc                     t        |      dk(  r| S |d   }|| j                  vrt        |d      | j                  |<   | 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_names      r   r   zDirectory._get_dir   s^     t9>K74==(&/$&?DMM(#}}X&//QR99r   	file_pathc                     |j                  d      ^ }}| j                  |      }t        |d      |j                  |<   y)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dirs        r   	_add_filezDirectory._add_file%   s9      ooc*tmmD!&tU3Tr   filenamec                     |j                  dd      }|d   }t        |      dkD  r|d   nd}|| j                  j                         v r!|y| j                  |   j	                  |      S y)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grandchildrens        r   r#   zDirectory.has_file0   sp     ..q.1
&)'lQ&6
DDMM&&(($}}U+44]CCr   c                 J    g }| j                  |       dj                  |      S )N )_stringify_treejoin)r   str_lists     r   __str__zDirectory.__str__B   s$     X&wwx  r   r+   preambledir_ptrc                    d}d}d}d}|j                  | | | j                   d       ||k(  r||z   }n||z   }g }g }	| j                  j                         D ]4  \  }
}|j                  r|	j                  |
       $|j                  |
       6 t        t        |	            D ]e  \  }}
|t        |	      dz
  k(  r/t        |      dk(  r!| j                  |
   j                  |||       F| j                  |
   j                  |||       g t        t        |            D ]2  \  }}|t        |      dz
  k(  r|n|}|j                  | | | d       4 y)	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   pointers                  r   r)   zDirectory._stringify_treeG   se    #$ 	8*WIdii[;< c>&(H%'H!	 ++- 	&HCzz$  %		& $F8$45 	LJE3X**I!0Cc"228XtLc"228XsK		L
 %VI%67 	<KE4$I(::dGOOxj	$r:;	<r   N)r(   u
   ─── )__name__
__module____qualname____doc__strboolr   r   r   r   r#   r,   r)    r   r   r   r   
   s    /1S 1$ 1
:T#Y :; :"	43 	4  $! ,	$<s)$< $< 	$<r   r   	file_listincluder   excluder   c                     t        ||d      }t        | d      }|D ]%  }|j                  |      s|j                  |       ' |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   )rH   	separatorT)r   r   matchesr   )r   rF   rG   rH   glob_patterntop_dirr   s          r    _create_directory_from_file_listrN   n   sP    , WgEL$'G $%d#$ Nr   N)z**rE   )
typingr   r   
glob_groupr   r   __all__r   rC   rN   rE   r   r   <module>rR      s`     . -a< a<N "	Cy  	
 r   