
    Χg                     t    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	dS )    )DictList   )	GlobGroupGlobPattern	Directoryc                       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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                 0    || _         || _        i | _        d S )N)r
   r   children)selfr
   r   s      g/var/www/html/ai-engine/env/lib/python3.11/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        |                             |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   sg     t99>>K74=((&/$&?&?DM(#}X&//QRR999r   	file_pathc                     |                     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dirs        r   	_add_filezDirectory._add_file%   sF      ooc**tmmD!!&tU33Tr   filenamec                     |                     dd          }|d         }t          |          dk    r|d         nd}|| j                                        v 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grandchildrens        r   r#   zDirectory.has_file0   s     ..q.11
&)'llQ&6&6

DDM&&(((($t}U+44]CCCur   c                 Z    g }|                      |           d                    |          S )N )_stringify_treejoin)r   str_lists     r   __str__zDirectory.__str__B   s-     X&&&wwx   r   r(   
   ─── r+   preambledir_ptrc                    d}d}d}d}|                     | | | j         d           ||k    r||z   }n||z   }g }g }	| j                                        D ]7\  }
}|j        r|	                     |
           "|                     |
           8t          t          |	                    D ]s\  }}
|t          |	          dz
  k    r6t          |          dk    r#| j        |
                             |||           Q| j        |
                             |||           tt          t          |                    D ];\  }}|t          |          dz
  k    r|n|}|                     | | | d           <d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   pointers                  r   r)   zDirectory._stringify_treeG   s    #$ 	8;W;di;;;<<< c>>&(HH%'H!	 ++-- 	& 	&HCz &$$$$  %%%%#F8$4$455 	L 	LJE3X***I!0C0Cc"228XtLLLLc"228XsKKKK$VI%6%677 	< 	<KE4$I(:::ddGOOx::$:::;;;;	< 	<r   N)r(   r-   )__name__
__module____qualname____doc__strboolr   r   r   r   r#   r,   r)    r   r   r   r   
   s        / /1S 1$ 1 1 1 1
:T#Y :; : : : :"	43 	4 	4 	4 	4     $! ! ! ,	$< $<s)$< $< 	$< $< $< $< $< $<r   **rF   r   	file_listincluder   excluder   c                     t          ||d          }t          | d          }|D ],}|                    |          r|                    |           -|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   )rJ   	separatorT)r   r   matchesr   )r   rH   rI   rJ   glob_patterntop_dirr   s          r    _create_directory_from_file_listrP   n   sf    , WgEEEL$''G $ $%% 	$d###Nr   N)rG   rF   )
typingr   r   
glob_groupr   r   __all__r   rD   rP   rF   r   r   <module>rT      s            . . . . . . . . -a< a< a< a< a< a< a< a<N "	 Cy  	
      r   