o
    Ưh	                     @   s|   d dl Z d dlZd dlmZ d dlmZ d dlmZmZm	Z	m
Z
 G dd dZG dd dZed	d
dedefddZdS )    N)	lru_cache)Path)AnyDictOptionalTuplec                   @   s0   e Zd Zddedeeeef  ddfddZdS )	TrieNode Nconfig_fileconfig_datareturnc                 C   s   |si }i | _ ||f| _d S N)nodesconfig_infoselfr
   r    r   H/var/www/Befach/backend/venv/lib/python3.10/site-packages/isort/utils.py__init__	   s   zTrieNode.__init__r	   N)__name__
__module____qualname__strr   r   r   r   r   r   r   r   r      s    (r   c                   @   st   e Zd ZdZddedeeeef  ddfddZdedeeef ddfd	d
Z	dede
eeeef f fddZdS )Triez}
    A prefix tree to store the paths of all config files and to search the nearest config
    associated with each file
    r	   Nr
   r   r   c                 C   s   t ||| _d S r   )r   rootr   r   r   r   r      s   zTrie.__init__c                 C   sN   t |j j}| j}|D ]}||jvrt |j|< |j| }q||f|_d S r   )r   parentresolvepartsr   r   r   r   )r   r
   r   resolved_config_path_as_tupletemppathr   r   r   insert   s   
zTrie.insertfilenamec                 C   sT   t | j}| j}di f}|D ]}|jd r|j}||jvr" |S |j| }q|S )z{
        Returns the closest config relative to filename by doing a depth
        first search on the prefix tree.
        r	   r   )r   r   r   r   r   r   )r   r#   resolved_file_path_as_tupler    last_stored_configr!   r   r   r   search'   s   

zTrie.searchr   )r   r   r   __doc__r   r   r   r   r   r"   r   r&   r   r   r   r   r      s
    $&r   i  )maxsizer!   r   c                 C   sH   t j| }|r"tjdstjdkr"t j| \}}|t |v }|S )aL  Returns if the given path exists and also matches the case on Windows.

    When finding files that can be imported, it is important for the cases to match because while
    file os.path.exists("module.py") and os.path.exists("MODULE.py") both return True on Windows,
    Python can only import using the case of the real file.
    windarwin)osr!   existssysplatform
startswithsplitlistdir)r!   result	directorybasenamer   r   r   exists_case_sensitive>   s
   r5   )r+   r-   	functoolsr   pathlibr   typingr   r   r   r   r   r   r   boolr5   r   r   r   r   <module>   s    	-