o
    Vù¡i€(  ã                   @  s  U d Z ddlm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
mZ ejdkr2ddddœnd	diZe
r>dd
lmZ e dej¡Zded< e dej¡Zded< ddddœZded< edi e¤ŽG dd„ dƒƒZedi e¤ŽG dd„ dƒƒZedi e¤ŽG dd„ dƒƒZg d¢ZdS )zKVersion specifier support using only standard library (PEP 440 compatible).é    )ÚannotationsN)Ú	dataclass)ÚTYPE_CHECKINGÚFinal)é   é
   T)ÚfrozenÚkw_onlyÚslotsr   )ÚIteratorz¹
    ^
    (\d+)               # major
    (?:\.(\d+))?        # optional minor
    (?:\.(\d+))?        # optional micro
    (?:(a|b|rc)(\d+))?  # optional pre-release suffix
    $
    zFinal[re.Pattern[str]]Ú_VERSION_REzr
    ^
    (===|==|~=|!=|<=|>=|<|>)  # operator
    \s*
    (.+)                       # version string
    $
    Ú_SPECIFIER_REé   é   r   )ÚaÚbÚrczFinal[dict[str, int]]Ú
_PRE_ORDERc                   @  s¨   e Zd ZU dZded< ded< ded< ded< ded	< d
ed< ded< ed%dd„ƒZd&dd„Zd'dd„Zd&dd„Z	d&dd„Z
d&dd„Zd&dd„Zd(d d!„Zd(d"d#„Zd$S ))ÚSimpleVersionaË  
    Simple PEP 440-like version parser using only standard library.

    :param version_str: the original version string.
    :param major: major version number.
    :param minor: minor version number.
    :param micro: micro (patch) version number.
    :param pre_type: pre-release label (``"a"``, ``"b"``, or ``"rc"``), or ``None``.
    :param pre_num: pre-release sequence number, or ``None``.
    :param release: the ``(major, minor, micro)`` tuple.
    ÚstrÚversion_strÚintÚmajorÚminorÚmicroz
str | NoneÚpre_typeú
int | NoneÚpre_numztuple[int, int, int]ÚreleaseÚreturnc              
   C  s¨   |  ¡ }t |¡ }sd|› }t|ƒ‚t| d¡ƒ}| d¡r't| d¡ƒnd}| d¡r5t| d¡ƒnd}| ||||| d¡| d¡rLt| d¡ƒnd|||fd	S )
z}
        Parse a PEP 440 version string (e.g. ``3.12.1``).

        :param version_str: the version string to parse.
        zInvalid version: r   r   r   r   é   é   N)r   r   r   r   r   r   r   )Ústripr   ÚmatchÚ
ValueErrorr   Úgroup)Úclsr   Ústrippedr#   Úmsgr   r   r   © r)   úO/home/ubuntu/.local/lib/python3.10/site-packages/python_discovery/_specifier.pyÚfrom_string?   s    
ùzSimpleVersion.from_stringÚotherÚobjectÚboolc                 C  s2   t |tƒstS | j|jko| j|jko| j|jkS ©N)Ú
isinstancer   ÚNotImplementedr   r   r   ©Úselfr,   r)   r)   r*   Ú__eq__W   s   
$zSimpleVersion.__eq__c                 C  s   t | j| j| jfƒS r/   )Úhashr   r   r   ©r3   r)   r)   r*   Ú__hash__\   s   zSimpleVersion.__hash__c                 C  s–   t |tƒstS | j|jkr| j|jk S | jd u r|jd u rdS | jd u r&dS |jd u r-dS t| j t|j krAt| j t|j k S | jpEd|jpIdk S )NFTr   )r0   r   r1   r   r   r   r   r2   r)   r)   r*   Ú__lt___   s   


zSimpleVersion.__lt__c                 C  s   | |kp| |k S r/   r)   r2   r)   r)   r*   Ú__le__n   s   zSimpleVersion.__le__c                 C  s   t |tƒstS | |k S r/   )r0   r   r1   r2   r)   r)   r*   Ú__gt__q   s   

zSimpleVersion.__gt__c                 C  s
   | |k  S r/   r)   r2   r)   r)   r*   Ú__ge__v   ó   
zSimpleVersion.__ge__c                 C  ó   | j S r/   ©r   r6   r)   r)   r*   Ú__str__y   ó   zSimpleVersion.__str__c                 C  ó   d| j › dS )NzSimpleVersion('ú')r>   r6   r)   r)   r*   Ú__repr__|   ó   zSimpleVersion.__repr__N)r   r   r   r   ©r,   r-   r   r.   ©r   r   ©r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__Úclassmethodr+   r4   r7   r8   r9   r:   r;   r?   rC   r)   r)   r)   r*   r   )   s&   
 






r   c                   @  s    e Zd ZU dZded< ded< ded< ded< ded	< d
ed< ed%dd„ƒZd&dd„Zd'dd„Zd'dd„Z	d'dd„Z
d(dd„Zd)dd„Zd*d d!„Zd*d"d#„Zd$S )+ÚSimpleSpecifiera+  
    Simple PEP 440-like version specifier using only standard library.

    :param spec_str: the original specifier string (e.g. ``>=3.10``).
    :param operator: the comparison operator (``==``, ``>=``, ``<``, etc.).
    :param version_str: the version portion of the specifier, without the operator.
    :param is_wildcard: ``True`` if the specifier uses a wildcard suffix (``.*``).
    :param wildcard_precision: number of version components before the wildcard, or ``None``.
    :param version: the parsed version, or ``None`` if parsing failed.
    r   Úspec_strÚoperatorr   r.   Úis_wildcardr   Úwildcard_precisionzSimpleVersion | NoneÚversionr   c           
      C  s¦   |  ¡ }t |¡ }sd|› }t|ƒ‚| d¡}| d¡  ¡ }| d¡}d}|r6|dd… }t| d¡ƒ}zt 	|¡}	W n tyH   d}	Y nw | ||||||	dS )	z~
        Parse a single PEP 440 specifier (e.g. ``>=3.10``).

        :param spec_str: the specifier string to parse.
        zInvalid specifier: r   r   z.*NéþÿÿÿÚ.)rO   rP   r   rQ   rR   rS   )
r"   r   r#   r$   r%   ÚendswithÚlenÚsplitr   r+   )
r&   rO   r'   r#   r(   Úopr   rQ   rR   rS   r)   r)   r*   r+   ”   s0   


ÿúzSimpleSpecifier.from_stringc                 C  sZ   zt |tƒrt |¡n|}W n
 ty   Y dS w | jdu r dS | jr(|  |¡S |  |¡S )z~
        Check if a version string satisfies this specifier.

        :param version_str: the version string to test.
        FN)	r0   r   r   r+   r$   rS   rQ   Ú_check_wildcardÚ_check_standard)r3   r   Ú	candidater)   r)   r*   Úcontains³   s   ÿ


zSimpleSpecifier.containsr\   r   c                 C  sj   | j d u rdS | jdkr|jd | j… | j jd | j… kS | jdkr3|jd | j… | j jd | j… kS dS )NFú==ú!=)rS   rP   r   rR   )r3   r\   r)   r)   r*   rZ   Ã   s   

"
"zSimpleSpecifier._check_wildcardc                 C  s|   | j d u rdS | jdkrt|ƒt| j ƒkS | jdkr|  |¡S tjtjtjtjtjtj	dœ}| j|v r<|| j || j ƒS dS )NFz===z~=)r^   r_   ú<z<=ú>z>=)
rS   rP   r   Ú_check_compatible_releaseÚeqÚneÚltÚleÚgtÚge)r3   r\   Úcmp_opsr)   r)   r*   r[   Ì   s    



ú
zSimpleSpecifier._check_standardc                 C  sv   | j d u rdS || j k rdS t| j jƒdkr9t| j jd d… ƒ}|d  d7  < t d dd„ |D ƒ¡¡}||k S dS )	NFr   éÿÿÿÿr   rU   c                 s  s    | ]}t |ƒV  qd S r/   )r   )Ú.0Úpr)   r)   r*   Ú	<genexpr>ç   s   € z<SimpleSpecifier._check_compatible_release.<locals>.<genexpr>T)rS   rW   r   Úlistr   r+   Újoin)r3   r\   Úupper_partsÚupperr)   r)   r*   rb   ß   s   

z)SimpleSpecifier._check_compatible_releaser,   r-   c                 C  ó   t |tƒstS | j|jkS r/   )r0   rN   r1   rO   r2   r)   r)   r*   r4   ë   ó   
zSimpleSpecifier.__eq__r   c                 C  ó
   t | jƒS r/   )r5   rO   r6   r)   r)   r*   r7   ð   r<   zSimpleSpecifier.__hash__c                 C  r=   r/   ©rO   r6   r)   r)   r*   r?   ó   r@   zSimpleSpecifier.__str__c                 C  rA   )NzSimpleSpecifier('rB   ru   r6   r)   r)   r*   rC   ö   rD   zSimpleSpecifier.__repr__N)rO   r   r   rN   ©r   r   r   r.   )r\   r   r   r.   rE   rF   rG   )rH   rI   rJ   rK   rL   rM   r+   r]   rZ   r[   rb   r4   r7   r?   rC   r)   r)   r)   r*   rN   €   s$   
 


	



rN   c                   @  sn   e Zd ZU dZded< ded< edddd	„ƒZddd„Zd dd„Zd!dd„Z	d"dd„Z
d#dd„Zd#dd„ZdS )$ÚSimpleSpecifierSetzÌ
    Simple PEP 440-like specifier set using only standard library.

    :param specifiers_str: the original comma-separated specifier string.
    :param specifiers: the parsed individual specifiers.
    r   Úspecifiers_strztuple[SimpleSpecifier, ...]Ú
specifiersÚ r   c              	   C  sv   |  ¡ }g }|r3| d¡D ]%}|  ¡ }|r2t t¡ | t |¡¡ W d  ƒ n1 s-w   Y  q| |t|ƒdS )z—
        Parse a comma-separated PEP 440 specifier string (e.g. ``>=3.10,<4``).

        :param specifiers_str: the specifier string to parse.
        ú,N)rx   ry   )	r"   rX   Ú
contextlibÚsuppressr$   ÚappendrN   r+   Útuple)r&   rx   r'   ÚspecsÚ	spec_itemÚitemr)   r)   r*   r+     s   ÿ€zSimpleSpecifierSet.from_stringr   r.   c                   s"   | j sdS t‡ fdd„| j D ƒƒS )z‚
        Check if a version satisfies all specifiers in the set.

        :param version_str: the version string to test.
        Tc                 3  s    | ]}|  ˆ ¡V  qd S r/   )r]   )rk   Úspecr>   r)   r*   rm     s   € z.SimpleSpecifierSet.contains.<locals>.<genexpr>)ry   Úall)r3   r   r)   r>   r*   r]     s   zSimpleSpecifierSet.containsúIterator[SimpleSpecifier]c                 C  rt   r/   )Úiterry   r6   r)   r)   r*   Ú__iter__!  r<   zSimpleSpecifierSet.__iter__r,   r-   c                 C  rr   r/   )r0   rw   r1   rx   r2   r)   r)   r*   r4   $  rs   zSimpleSpecifierSet.__eq__r   c                 C  rt   r/   )r5   rx   r6   r)   r)   r*   r7   )  r<   zSimpleSpecifierSet.__hash__c                 C  r=   r/   ©rx   r6   r)   r)   r*   r?   ,  r@   zSimpleSpecifierSet.__str__c                 C  rA   )NzSimpleSpecifierSet('rB   rˆ   r6   r)   r)   r*   rC   /  rD   zSimpleSpecifierSet.__repr__N)rz   )rx   r   r   rw   rv   )r   r…   rE   rF   rG   )rH   rI   rJ   rK   rL   rM   r+   r]   r‡   r4   r7   r?   rC   r)   r)   r)   r*   rw   ú   s   
 





rw   )rN   rw   r   r)   )rK   Ú
__future__r   r|   rP   ÚreÚsysÚdataclassesr   Útypingr   r   Úversion_infoÚ_DC_KWÚcollections.abcr   ÚcompileÚVERBOSEr   rL   r   r   r   rN   rw   Ú__all__r)   r)   r)   r*   Ú<module>   s6    ÷ø
Vy8