o
    UhH                     @  sV  U d dl mZ d dlZd dlZd dlZ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 er;d dlmZmZmZ edZejdkZejd	kZd
ZerUdZded< ndZddedeZeeZd-ddZeddd.ddZeddd/ddZeddd.d d!Z eddd0d"d#Z!erG d$d% d%eZ"d1d(d)Z#d2d+d,Z$dS )3    )annotationsN)	lru_cache)Path)TYPE_CHECKINGcast)	GeneratorSequence	TypedDictz(?:(?P<implementation>\w+)@)?(?P<major>\d+)(?:\.(?P<minor>\d+)(?:\.(?P<patch>[0-9]+))?)?\.?(?:(?P<prerel>[abc]|rc|dev)(?:(?P<prerelversion>\d+(?:\.\d+)*))?)?(?P<postdev>(\.post(?P<post>\d+))?(\.dev(?P<dev>\d+))?)?(?:-(?P<architecture>32|64))?win32darwin)
python
ironpythonjythonpypyanaconda	miniconda	stacklessactivepythonpystonmicropython)z.exe .pyz.batzSequence[str]
KNOWN_EXTS)r   z.shz.bashz.cshz.zshz.fishr   zb((?P<implementation>{0})(?:\d(?:\.?\d\d?[cpm]{{0,3}})?)?(?:(?<=\d)-[\d\.]+)*(?!w))(?P<suffix>{1})$|pathr   returnGenerator[Path, None, None]c              
   c  sj    t t| t jr|  sdS z
|  E dH  W dS  ty4 } z|jtjkr/W Y d}~dS  d}~ww )zqIterate over a directory, returning an empty iterator if the path
    is not a directory or is not readable.
    N)	osaccessstrR_OKis_diriterdirOSErrorerrnoEACCES)r   exc r'   d/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/findpython/utils.pysafe_iter_dir1   s   r)   i   )maxsizeboolc                 C  sN   z|   ott| tjo| jtv ptt| tjW S  ty&   Y dS w )aC  
    Returns whether a given path is a known executable from known executable extensions
    or has the executable bit toggled.

    :param path: The path to the target executable.
    :type path: :class:`~Path`
    :return: True if the path has chmod +x, or is a readable, known executable extension.
    :rtype: bool
    F)	is_filer   r   r   r    suffixr   X_OKr#   r   r'   r'   r(   path_is_known_executable?   s   r0   namer   c                   s,   t  fddtD sdS t }t|S )z
    Determine whether the supplied filename looks like a possible name of python.

    :param str name: The name of the provided file.
    :return: Whether the provided name looks like python.
    :rtype: bool
    c                 3  s    | ]
}   |V  qd S )N)lower
startswith).0py_namer1   r'   r(   	<genexpr>]   s    z$looks_like_python.<locals>.<genexpr>F)anyPYTHON_IMPLEMENTATIONS
RE_MATCHERmatchr+   )r1   r;   r'   r6   r(   looks_like_pythonT   s   	
r<   c                 C  s   t | jot| S )a  
    Determine whether the supplied path is a executable and looks like
    a possible path to python.

    :param path: The path to an executable.
    :type path: :class:`~Path`
    :return: Whether the provided path is an executable path to python.
    :rtype: bool
    )r<   r1   r0   r/   r'   r'   r(   path_is_pythonc   s   r=   c                   sb   t  }| d t fdddD ]}|| qW d   | S 1 s(w   Y  | S )z&Return the MD5 hash of the given file.rbc                     s
     dS )Ni   )readr'   fr'   r(   <lambda>v   s   
 z!get_binary_hash.<locals>.<lambda>    N)hashlibmd5openiterupdate	hexdigest)r   hasherchunkr'   r@   r(   get_binary_hashq   s   
rL   c                   @  sF   e Zd ZU ded< ded< ded< ded< ded< ded	< ded
< dS )VersionDictr+   predevz
int | Nonemajorminorpatchz
str | NonearchitectureimplementationN)__name__
__module____qualname____annotations__r'   r'   r'   r(   rM   }   s   
 rM   versionVersionDict | Nonec                 C  s   t | }|s	dS | }t|d|d< t|d|d< dD ]}|| dur1t|| ||< q!|d r?|d  d|d< td|S )	z.Parse the version dict from the version stringNprerelrN   rO   )rP   rQ   rR   rS   bitrM   )
VERSION_REr;   	groupdictr+   popintr   )rY   r;   rv
int_valuesr'   r'   r(   parse_major   s   

rc   r`   c                 C  s2   t tD ]\}}|r| |r|  S qtdS )Nr   )	enumerater   endswithindex)r1   ir-   r'   r'   r(   get_suffix_preference   s
   
rh   )r   r   r   r   )r   r   r   r+   )r1   r   r   r+   )r   r   r   r   )rY   r   r   rZ   )r1   r   r   r`   )%
__future__r   r$   rD   r   resys	functoolsr   pathlibr   typingr   r   r   r   r	   compiler]   platformWINDOWSMACOSr9   r   rX   formatjoinPY_MATCH_STRr:   r)   r0   r<   r=   rL   rM   rc   rh   r'   r'   r'   r(   <module>   sP    



	

