U
    Ç½„bžu  ã                   @   sž  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mZmZm	Z	m
Z
mZmZmZmZmZmZ ddlmZ ddlmZmZmZ eeef Zeeeef Zeded�Zeeegef ZG dd	„ d	eƒZG d
d„ de jd�Z G dd„ de ƒZ!G dd„ de!ƒZ"edeegef edeegef dœdd„Z#G dd„ de!ƒZ$e %d¡Z&ee
e dœdd„Z'eedœdd„Z(e
e e
e ee
e e
e f dœdd„Z)G d d!„ d!e ƒZ*dS )"é    N)ÚCallableÚDictÚIterableÚIteratorÚListÚOptionalÚPatternÚSetÚTupleÚTypeVarÚUnioné   )Úcanonicalize_version)ÚLegacyVersionÚVersionÚparseÚVersionTypeVar)Úboundc                   @   s   e Zd ZdZdS )ÚInvalidSpecifierzH
    An invalid specifier was found, users should refer to PEP 440.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   ú8/tmp/pip-unpacked-wheel-sh3cvm4r/packaging/specifiers.pyr   !   s   r   c                   @   s¼   e Zd Zejedœdd„ƒZejedœdd„ƒZeje	e
dœdd„ƒZejee
 dœd	d
„ƒZeje
ddœdd
„ƒZejdeee
 e
dœdd„ƒZejdee ee
 ee dœdd„ƒZdS )ÚBaseSpecifier©Úreturnc                 C   s   dS )zŽ
        Returns the str representation of this Specifier like object. This
        should be representative of the Specifier itself.
        Nr   ©Úselfr   r   r   Ú__str__(   s    zBaseSpecifier.__str__c                 C   s   dS )zF
        Returns a hash value for this Specifier like object.
        Nr   r   r   r   r   Ú__hash__/   s    zBaseSpecifier.__hash__©Úotherr   c                 C   s   dS )zq
        Returns a boolean representing whether or not the two Specifier like
        objects are equal.
        Nr   ©r   r#   r   r   r   Ú__eq__5   s    zBaseSpecifier.__eq__c                 C   s   dS )zg
        Returns whether or not pre-releases as a whole are allowed by this
        specifier.
        Nr   r   r   r   r   Úprereleases<   s    zBaseSpecifier.prereleasesN©Úvaluer   c                 C   s   dS )zd
        Sets whether or not pre-releases as a whole are allowed by this
        specifier.
        Nr   ©r   r(   r   r   r   r&   C   s    ©Úitemr&   r   c                 C   s   dS )zR
        Determines if the given item is contained within this specifier.
        Nr   ©r   r+   r&   r   r   r   ÚcontainsJ   s    zBaseSpecifier.contains©Úiterabler&   r   c                 C   s   dS )z•
        Takes an iterable of items and filters them so that only items which
        are contained within this specifier are allowed in it.
        Nr   )r   r/   r&   r   r   r   ÚfilterP   s    zBaseSpecifier.filter)N)N)r   r   r   ÚabcÚabstractmethodÚstrr    Úintr!   ÚobjectÚboolr%   Úabstractpropertyr   r&   Úsetterr-   r   r   r0   r   r   r   r   r   '   s&    ÿ þr   )Ú	metaclassc                   @   sR  e Zd ZU i Zeeef ed< ee ed< d+eee	 ddœdd„Z
edœd	d
„Zedœdd„Zeeeef dœdd„ƒZedœdd„Zee	dœdd„Zeedœdd„Zeedœdd„Zeedœdd„ƒZeedœdd„ƒZeee	 dœdd„ƒZeje	dd œd!d„ƒZee	d"œd#d$„Zd,eee	 e	d%œd&d'„Zd-ee  ee	 ee  d(œd)d*„Z!dS ).Ú_IndividualSpecifierÚ
_operatorsÚ_regexÚ N©Úspecr&   r   c                 C   sH   | j  |¡}|s td|› d�ƒ‚| d¡ ¡ | d¡ ¡ f| _|| _d S )NzInvalid specifier: 'ú'ÚoperatorÚversion)r<   Úsearchr   ÚgroupÚstripÚ_specÚ_prereleases)r   r?   r&   Úmatchr   r   r   Ú__init___   s    þz_IndividualSpecifier.__init__r   c                 C   s8   | j d k	rd| j›�nd}d| jj› dt| ƒ›|› d�S )Nú, prereleases=r=   ú<ú(ú)>)rG   r&   Ú	__class__r   r3   ©r   Úprer   r   r   Ú__repr__l   s
    ÿýz_IndividualSpecifier.__repr__c                 C   s   dj | jŽ S )Nz{}{})ÚformatrF   r   r   r   r   r    u   s    z_IndividualSpecifier.__str__c                 C   s   | j d t| j d ƒfS )Nr   r   )rF   r   r   r   r   r   Ú_canonical_specx   s    z$_IndividualSpecifier._canonical_specc                 C   s
   t | jƒS ©N)ÚhashrS   r   r   r   r   r!   |   s    z_IndividualSpecifier.__hash__r"   c                 C   sT   t |tƒr8z|  t|ƒ¡}W qH tk
r4   t Y S X nt || jƒsHtS | j|jkS rT   )Ú
isinstancer3   rN   r   ÚNotImplementedrS   r$   r   r   r   r%      s    
z_IndividualSpecifier.__eq__)Úopr   c                 C   s   t | d| j| › �ƒ}|S )NZ	_compare_)Úgetattrr;   )r   rX   Úoperator_callabler   r   r   Ú_get_operatorŠ   s
     ÿz"_IndividualSpecifier._get_operator©rB   r   c                 C   s   t |ttfƒst|ƒ}|S rT   )rV   r   r   r   ©r   rB   r   r   r   Ú_coerce_version�   s    z$_IndividualSpecifier._coerce_versionc                 C   s
   | j d S )Nr   ©rF   r   r   r   r   rA   •   s    z_IndividualSpecifier.operatorc                 C   s
   | j d S )Nr   r_   r   r   r   r   rB   ™   s    z_IndividualSpecifier.versionc                 C   s   | j S rT   ©rG   r   r   r   r   r&   �   s    z _IndividualSpecifier.prereleasesr'   c                 C   s
   || _ d S rT   r`   r)   r   r   r   r&   ¡   s    ©r+   r   c                 C   s
   |   |¡S rT   ©r-   ©r   r+   r   r   r   Ú__contains__¥   s    z!_IndividualSpecifier.__contains__r*   c                 C   s>   |d kr| j }|  |¡}|jr&|s&dS |  | j¡}||| jƒS ©NF)r&   r^   Úis_prereleaser[   rA   rB   )r   r+   r&   Únormalized_itemrZ   r   r   r   r-   ¨   s    

z_IndividualSpecifier.containsr.   c                 c   s€   d}g }d|d k	r|ndi}|D ]B}|   |¡}| j|f|Žr |jrX|sX| jsX| |¡ q d}|V  q |s||r||D ]
}|V  qpd S )NFr&   T)r^   r-   rf   r&   Úappend)r   r/   r&   ÚyieldedÚfound_prereleasesÚkwrB   Úparsed_versionr   r   r   r0   ¿   s"    
ÿÿz_IndividualSpecifier.filter)r=   N)N)N)"r   r   r   r;   r   r3   Ú__annotations__r   r   r6   rI   rQ   r    Úpropertyr
   rS   r4   r!   r5   r%   ÚCallableOperatorr[   ÚUnparsedVersionÚParsedVersionr^   rA   rB   r&   r8   rd   r-   r   r   r0   r   r   r   r   r:   Z   s@   
	 ÿ þ ÿ þr:   c                       sÚ   e Zd ZdZe de d ejejB ¡Zdddddd	d
œZ	d e
ee ddœ‡ fdd„Zeedœdd„Zee
edœdd„Zee
edœdd„Zee
edœdd„Zee
edœdd„Zee
edœdd„Zee
edœdd„Z‡  ZS )!ÚLegacySpecifieraÛ  
        (?P<operator>(==|!=|<=|>=|<|>))
        \s*
        (?P<version>
            [^,;\s)]* # Since this is a "legacy" specifier, and the version
                      # string can be just about anything, we match everything
                      # except for whitespace, a semi-colon for marker support,
                      # a closing paren since versions can be enclosed in
                      # them, and a comma since it's a version separator.
        )
        ú^\s*ú\s*$ÚequalÚ	not_equalÚless_than_equalÚgreater_than_equalÚ	less_thanÚgreater_than)ú==ú!=ú<=ú>=rK   ú>r=   Nr>   c                    s   t ƒ  ||¡ t dt¡ d S )NzZCreating a LegacyVersion has been deprecated and will be removed in the next major release)ÚsuperrI   ÚwarningsÚwarnÚDeprecationWarning)r   r?   r&   ©rN   r   r   rI   ü   s
    ýzLegacySpecifier.__init__r\   c                 C   s   t |tƒstt|ƒƒ}|S rT   )rV   r   r3   r]   r   r   r   r^     s    
zLegacySpecifier._coerce_version©Úprospectiver?   r   c                 C   s   ||   |¡kS rT   ©r^   ©r   r†   r?   r   r   r   Ú_compare_equal
  s    zLegacySpecifier._compare_equalc                 C   s   ||   |¡kS rT   r‡   rˆ   r   r   r   Ú_compare_not_equal  s    z"LegacySpecifier._compare_not_equalc                 C   s   ||   |¡kS rT   r‡   rˆ   r   r   r   Ú_compare_less_than_equal  s    z(LegacySpecifier._compare_less_than_equalc                 C   s   ||   |¡kS rT   r‡   rˆ   r   r   r   Ú_compare_greater_than_equal  s    z+LegacySpecifier._compare_greater_than_equalc                 C   s   ||   |¡k S rT   r‡   rˆ   r   r   r   Ú_compare_less_than  s    z"LegacySpecifier._compare_less_thanc                 C   s   ||   |¡kS rT   r‡   rˆ   r   r   r   Ú_compare_greater_than  s    z%LegacySpecifier._compare_greater_than)r=   N)r   r   r   Ú
_regex_strÚreÚcompileÚVERBOSEÚ
IGNORECASEr<   r;   r3   r   r6   rI   rp   r   r^   r‰   rŠ   r‹   rŒ   r�   rŽ   Ú__classcell__r   r   r„   r   rr   ã   s(   ú		 þrr   Ú	Specifier)Úfnr   c                    s&   t  ˆ ¡dtttdœ‡ fdd„ƒ}|S )Nr•   )r   r†   r?   r   c                    s   t |tƒsdS ˆ | ||ƒS re   )rV   r   rˆ   ©r–   r   r   Úwrapped"  s    
z)_require_version_compare.<locals>.wrapped)Ú	functoolsÚwrapsrq   r3   r6   )r–   r˜   r   r—   r   Ú_require_version_compare  s    r›   c                	   @   s  e Zd ZdZe de d ejejB ¡Zdddddd	d
ddœZ	e
eeedœdd„ƒZe
eeedœdd„ƒZe
eeedœdd„ƒZe
eeedœdd„ƒZe
eeedœdd„ƒZe
eeedœdd„ƒZe
eeedœdd„ƒZeeedœdd„Zeedœd d!„ƒZejed"d#œd$d!„ƒZd"S )%r•   a  
        (?P<operator>(~=|==|!=|<=|>=|<|>|===))
        (?P<version>
            (?:
                # The identity operators allow for an escape hatch that will
                # do an exact string match of the version you wish to install.
                # This will not be parsed by PEP 440 and we cannot determine
                # any semantic meaning from it. This operator is discouraged
                # but included entirely as an escape hatch.
                (?<====)  # Only match for the identity operator
                \s*
                [^\s]*    # We just match everything, except for whitespace
                          # since we are only testing for strict identity.
            )
            |
            (?:
                # The (non)equality operators allow for wild card and local
                # versions to be specified so we have to define these two
                # operators separately to enable that.
                (?<===|!=)            # Only match for equals and not equals

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)*   # release
                (?:                   # pre release
                    [-_\.]?
                    (a|b|c|rc|alpha|beta|pre|preview)
                    [-_\.]?
                    [0-9]*
                )?
                (?:                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?

                # You cannot use a wild card and a dev or local version
                # together so group them with a | and make them optional.
                (?:
                    (?:[-_\.]?dev[-_\.]?[0-9]*)?         # dev release
                    (?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
                    |
                    \.\*  # Wild card syntax of .*
                )?
            )
            |
            (?:
                # The compatible operator requires at least two digits in the
                # release segment.
                (?<=~=)               # Only match for the compatible operator

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)+   # release  (We have a + instead of a *)
                (?:                   # pre release
                    [-_\.]?
                    (a|b|c|rc|alpha|beta|pre|preview)
                    [-_\.]?
                    [0-9]*
                )?
                (?:                                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?
                (?:[-_\.]?dev[-_\.]?[0-9]*)?          # dev release
            )
            |
            (?:
                # All other operators only allow a sub set of what the
                # (non)equality operators do. Specifically they do not allow
                # local versions to be specified nor do they allow the prefix
                # matching wild cards.
                (?<!==|!=|~=)         # We have special cases for these
                                      # operators so we want to make sure they
                                      # don't match here.

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)*   # release
                (?:                   # pre release
                    [-_\.]?
                    (a|b|c|rc|alpha|beta|pre|preview)
                    [-_\.]?
                    [0-9]*
                )?
                (?:                                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?
                (?:[-_\.]?dev[-_\.]?[0-9]*)?          # dev release
            )
        )
        rs   rt   Ú
compatibleru   rv   rw   rx   ry   rz   Ú	arbitrary)ú~=r{   r|   r}   r~   rK   r   ú===r…   c                 C   sJ   d  tt tt|ƒ¡ƒd d… ¡}|d7 }|  d¡||ƒoH|  d¡||ƒS )NÚ.éÿÿÿÿú.*r~   r{   )ÚjoinÚlistÚ	itertoolsÚ	takewhileÚ_is_not_suffixÚ_version_splitr[   )r   r†   r?   Úprefixr   r   r   Ú_compare_compatible—  s    ÿ ÿzSpecifier._compare_compatiblec           	      C   sz   |  d¡rVt|jƒ}t|d d… ƒ}tt|ƒƒ}|d t|ƒ… }t||ƒ\}}||kS t|ƒ}|jsnt|jƒ}||kS d S )Nr¢   éþÿÿÿ)Úendswithr   Úpublicr¨   r3   ÚlenÚ_pad_versionÚlocal)	r   r†   r?   Ú
split_specÚsplit_prospectiveÚshortened_prospectiveÚpadded_specÚpadded_prospectiveÚspec_versionr   r   r   r‰   ­  s    

 ÿ
zSpecifier._compare_equalc                 C   s   |   ||¡ S rT   )r‰   rˆ   r   r   r   rŠ   Õ  s    zSpecifier._compare_not_equalc                 C   s   t |jƒt |ƒkS rT   ©r   r­   rˆ   r   r   r   r‹   Ù  s    z"Specifier._compare_less_than_equalc                 C   s   t |jƒt |ƒkS rT   r·   rˆ   r   r   r   rŒ   á  s    z%Specifier._compare_greater_than_equal)r†   Úspec_strr   c                 C   s<   t |ƒ}||k sdS |js8|jr8t |jƒt |jƒkr8dS dS ©NFT)r   rf   Úbase_version©r   r†   r¸   r?   r   r   r   r�   ë  s    zSpecifier._compare_less_thanc                 C   s^   t |ƒ}||ksdS |js8|jr8t |jƒt |jƒkr8dS |jd k	rZt |jƒt |jƒkrZdS dS r¹   )r   Úis_postreleaserº   r°   r»   r   r   r   rŽ     s    
zSpecifier._compare_greater_thanc                 C   s   t |ƒ ¡ t |ƒ ¡ kS rT   )r3   Úlowerrˆ   r   r   r   Ú_compare_arbitrary%  s    zSpecifier._compare_arbitraryr   c                 C   sR   | j d k	r| j S | j\}}|dkrN|dkr@| d¡r@|d d… }t|ƒjrNdS dS )N)r{   r~   r}   rž   rŸ   r{   r¢   r«   TF)rG   rF   r¬   r   rf   )r   rA   rB   r   r   r   r&   (  s    


zSpecifier.prereleasesNr'   c                 C   s
   || _ d S rT   r`   r)   r   r   r   r&   A  s    )r   r   r   r�   r�   r‘   r’   r“   r<   r;   r›   rq   r3   r6   rª   r‰   rŠ   r‹   rŒ   r�   rŽ   r   r¾   rn   r&   r8   r   r   r   r   r•   +  sB   ]ø' þ	z^([0-9]+)((?:a|b|c|rc)[0-9]+)$r\   c                 C   s@   g }|   d¡D ],}t |¡}|r0| | ¡ ¡ q| |¡ q|S )Nr    )ÚsplitÚ_prefix_regexrC   ÚextendÚgroupsrh   )rB   Úresultr+   rH   r   r   r   r¨   I  s    
r¨   )Úsegmentr   c                    s   t ‡ fdd„dD ƒƒ S )Nc                 3   s   | ]}ˆ   |¡V  qd S rT   )Ú
startswith)Ú.0r©   ©rÄ   r   r   Ú	<genexpr>U  s    z!_is_not_suffix.<locals>.<genexpr>)ÚdevÚaÚbÚrcÚpost)ÚanyrÇ   r   rÇ   r   r§   T  s    ÿr§   )ÚleftÚrightr   c              
   C   sæ   g g  }}|  tt dd„ | ¡ƒ¡ |  tt dd„ |¡ƒ¡ |  | t|d ƒd … ¡ |  |t|d ƒd … ¡ | ddgtdt|d ƒt|d ƒ ƒ ¡ | ddgtdt|d ƒt|d ƒ ƒ ¡ ttj|Ž ƒttj|Ž ƒfS )Nc                 S   s   |   ¡ S rT   ©Úisdigit©Úxr   r   r   Ú<lambda>^  ó    z_pad_version.<locals>.<lambda>c                 S   s   |   ¡ S rT   rÑ   rÓ   r   r   r   rÕ   _  rÖ   r   r   Ú0)rh   r¤   r¥   r¦   r®   ÚinsertÚmaxÚchain)rÏ   rÐ   Ú
left_splitÚright_splitr   r   r   r¯   Z  s    
,,r¯   c                   @   s
  e Zd Zd#eee ddœdd„Zedœdd„Zedœd	d
„Ze	dœdd„Z
ed ef d dœdd„Zeedœdd„Ze	dœdd„Zee dœdd„Zeee dœdd„ƒZejeddœdd„ƒZeedœdd„Zd$eee edœdd„Zd%ee ee ee d œd!d"„ZdS )&ÚSpecifierSetr=   N)Ú
specifiersr&   r   c              	   C   sn   dd„ |  d¡D ƒ}tƒ }|D ]:}z| t|ƒ¡ W q tk
rV   | t|ƒ¡ Y qX qt|ƒ| _|| _d S )Nc                 S   s   g | ]}|  ¡ r|  ¡ ‘qS r   )rE   ©rÆ   Úsr   r   r   Ú
<listcomp>s  s      z)SpecifierSet.__init__.<locals>.<listcomp>ú,)	r¿   ÚsetÚaddr•   r   rr   Ú	frozensetÚ_specsrG   )r   rÞ   r&   Úsplit_specifiersÚparsedÚ	specifierr   r   r   rI   m  s    
zSpecifierSet.__init__r   c                 C   s.   | j d k	rd| j›�nd}dt| ƒ›|› d�S )NrJ   r=   z<SpecifierSet(rM   )rG   r&   r3   rO   r   r   r   rQ   …  s
    ÿýzSpecifierSet.__repr__c                 C   s   d  tdd„ | jD ƒƒ¡S )Nrâ   c                 s   s   | ]}t |ƒV  qd S rT   )r3   rß   r   r   r   rÈ   �  s     z'SpecifierSet.__str__.<locals>.<genexpr>)r£   Úsortedræ   r   r   r   r   r    Ž  s    zSpecifierSet.__str__c                 C   s
   t | jƒS rT   )rU   ræ   r   r   r   r   r!   ‘  s    zSpecifierSet.__hash__r"   c                 C   s˜   t |tƒrt|ƒ}nt |tƒs"tS tƒ }t| j|jB ƒ|_| jd krX|jd k	rX|j|_n<| jd k	rv|jd krv| j|_n| j|jkrŒ| j|_ntdƒ‚|S )NzFCannot combine SpecifierSets with True and False prerelease overrides.)rV   r3   rÝ   rW   rå   ræ   rG   Ú
ValueError)r   r#   ré   r   r   r   Ú__and__”  s     





ÿzSpecifierSet.__and__c                 C   s6   t |ttfƒrtt|ƒƒ}nt |tƒs*tS | j|jkS rT   )rV   r3   r:   rÝ   rW   ræ   r$   r   r   r   r%   «  s
    
zSpecifierSet.__eq__c                 C   s
   t | jƒS rT   )r®   ræ   r   r   r   r   Ú__len__³  s    zSpecifierSet.__len__c                 C   s
   t | jƒS rT   )Úiterræ   r   r   r   r   Ú__iter__¶  s    zSpecifierSet.__iter__c                 C   s.   | j d k	r| j S | jsd S tdd„ | jD ƒƒS )Nc                 s   s   | ]}|j V  qd S rT   ©r&   rß   r   r   r   rÈ   É  s     z+SpecifierSet.prereleases.<locals>.<genexpr>)rG   ræ   rÎ   r   r   r   r   r&   ¹  s
    
zSpecifierSet.prereleasesr'   c                 C   s
   || _ d S rT   r`   r)   r   r   r   r&   Ë  s    ra   c                 C   s
   |   |¡S rT   rb   rc   r   r   r   rd   Ï  s    zSpecifierSet.__contains__r*   c                    sL   t ˆ ttfƒstˆ ƒ‰ ˆd kr$| j‰ˆs2ˆ jr2dS t‡ ‡fdd„| jD ƒƒS )NFc                 3   s   | ]}|j ˆ ˆd �V  qdS )rð   Nrb   rß   ©r+   r&   r   r   rÈ   í  s     z(SpecifierSet.contains.<locals>.<genexpr>)rV   r   r   r   r&   rf   Úallræ   r,   r   rñ   r   r-   Ò  s    
zSpecifierSet.containsr.   c                 C   s°   |d kr| j }| jr6| jD ]}|j|t|ƒd�}q|S g }g }|D ]P}t|ttfƒs^t|ƒ}n|}t|tƒrnqB|jrˆ|sˆ|s’| 	|¡ qB| 	|¡ qB|s¨|r¨|d kr¨|S |S d S )Nrð   )
r&   ræ   r0   r6   rV   r   r   r   rf   rh   )r   r/   r&   r?   Úfilteredrj   r+   rl   r   r   r   r0   ï  s*    



zSpecifierSet.filter)r=   N)N)N)r   r   r   r3   r   r6   rI   rQ   r    r4   r!   r   rì   r5   r%   rí   r   r:   rï   rn   r&   r8   rp   rd   r-   r   r   r0   r   r   r   r   rÝ   l  s>      ÿ þ	 ÿ þ ÿ þrÝ   )+r1   r™   r¥   r�   r�   Útypingr   r   r   r   r   r   r   r	   r
   r   r   Úutilsr   rB   r   r   r   rq   r3   rp   r   r6   ro   rë   r   ÚABCMetar   r:   rr   r›   r•   r‘   rÀ   r¨   r§   r¯   rÝ   r   r   r   r   Ú<module>   s6   43 
=þ  
*