3
yYðiym  ã               @   sæ   d dl mZmZmZ d dlZd dlZd dlZd dlZddlm	Z	m
Z
 ddlmZmZmZ G dd„ deƒZG dd	„ d	e
ejeƒƒZG d
d„ deƒZG dd„ deƒZdd„ ZG dd„ deƒZejdƒZdd„ Zdd„ ZG dd„ deƒZdS )é    )Úabsolute_importÚdivisionÚprint_functionNé   )Ústring_typesÚwith_metaclass)ÚVersionÚLegacyVersionÚparsec               @   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   úM/tmp/pip-build-ue6tjl93/setuptools/setuptools/_vendor/packaging/specifiers.pyr      s   r   c               @   s€   e Zd Zejdd„ ƒZejdd„ ƒZejdd„ ƒZejdd„ ƒZej	d	d
„ ƒZ
e
jdd
„ ƒZ
ejddd„ƒZejddd„ƒZdS )ÚBaseSpecifierc             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__c             C   s   dS )zq
        Returns a boolean representing whether or not the two Specifier like
        objects are equal.
        Nr   )r   Úotherr   r   r   Ú__eq__$   s    zBaseSpecifier.__eq__c             C   s   dS )zu
        Returns a boolean representing whether or not the two Specifier like
        objects are not equal.
        Nr   )r   r   r   r   r   Ú__ne__+   s    zBaseSpecifier.__ne__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   Úprereleases2   s    zBaseSpecifier.prereleasesc             C   s   dS )zd
        Sets whether or not pre-releases as a whole are allowed by this
        specifier.
        Nr   )r   Úvaluer   r   r   r   9   s    Nc             C   s   dS )zR
        Determines if the given item is contained within this specifier.
        Nr   )r   Úitemr   r   r   r   Úcontains@   s    zBaseSpecifier.containsc             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   Úiterabler   r   r   r   ÚfilterF   s    zBaseSpecifier.filter)N)N)r   r   r   ÚabcÚabstractmethodr   r   r   r   Úabstractpropertyr   Úsetterr   r   r   r   r   r   r      s   r   c               @   s    e Zd Zi Zd dd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZedd„ ƒZedd„ ƒZejdd„ ƒZdd„ Zd!dd„Zd"dd„ZdS )#Ú_IndividualSpecifierÚ Nc             C   sF   | j j|ƒ}|stdj|ƒƒ‚|jdƒjƒ |jdƒjƒ f| _|| _d S )NzInvalid specifier: '{0}'ÚoperatorÚversion)Ú_regexÚsearchr   ÚformatÚgroupÚstripÚ_specÚ_prereleases)r   Úspecr   Úmatchr   r   r   Ú__init__R   s    z_IndividualSpecifier.__init__c             C   s0   | j d k	rdj| jƒnd}dj| jjt| ƒ|ƒS )Nz, prereleases={0!r}r$   z<{0}({1!r}{2})>)r-   r)   r   Ú	__class__r   Ústr)r   Úprer   r   r   Ú__repr___   s    z_IndividualSpecifier.__repr__c             C   s   dj | jŽ S )Nz{0}{1})r)   r,   )r   r   r   r   r   l   s    z_IndividualSpecifier.__str__c             C   s
   t | jƒS )N)Úhashr,   )r   r   r   r   r   o   s    z_IndividualSpecifier.__hash__c             C   sL   t |tƒr0y| j|ƒ}W q@ tk
r,   tS X nt || jƒs@tS | j|jkS )N)Ú
isinstancer   r1   r   ÚNotImplementedr,   )r   r   r   r   r   r   r   s    
z_IndividualSpecifier.__eq__c             C   sL   t |tƒr0y| j|ƒ}W q@ tk
r,   tS X nt || jƒs@tS | j|jkS )N)r6   r   r1   r   r7   r,   )r   r   r   r   r   r   }   s    
z_IndividualSpecifier.__ne__c             C   s   t | dj| j| ƒƒS )Nz_compare_{0})Úgetattrr)   Ú
_operators)r   Úopr   r   r   Ú_get_operatorˆ   s    z"_IndividualSpecifier._get_operatorc             C   s   t |ttfƒst|ƒ}|S )N)r6   r	   r   r
   )r   r&   r   r   r   Ú_coerce_version‹   s    z$_IndividualSpecifier._coerce_versionc             C   s
   | j d S )Nr   )r,   )r   r   r   r   r%   �   s    z_IndividualSpecifier.operatorc             C   s
   | j d S )Nr   )r,   )r   r   r   r   r&   ”   s    z_IndividualSpecifier.versionc             C   s   | j S )N)r-   )r   r   r   r   r   ˜   s    z _IndividualSpecifier.prereleasesc             C   s
   || _ d S )N)r-   )r   r   r   r   r   r   œ   s    c             C   s
   | j |ƒS )N)r   )r   r   r   r   r   Ú__contains__    s    z!_IndividualSpecifier.__contains__c             C   s<   |d kr| j }| j|ƒ}|jr(| r(dS | j| jƒ|| jƒS )NF)r   r<   Úis_prereleaser;   r%   r&   )r   r   r   r   r   r   r   £   s    
z_IndividualSpecifier.containsc             c   sŒ   d}g }d|d k	r|ndi}xL|D ]D}| j |ƒ}| j|f|Žr"|jr\|pL| j r\|j|ƒ q"d}|V  q"W | rˆ|rˆx|D ]
}|V  qzW d S )NFr   T)r<   r   r>   r   Úappend)r   r   r   ÚyieldedÚfound_prereleasesÚkwr&   Úparsed_versionr   r   r   r   ¶   s    




z_IndividualSpecifier.filter)r$   N)N)N)r   r   r   r9   r0   r4   r   r   r   r   r;   r<   Úpropertyr%   r&   r   r"   r=   r   r   r   r   r   r   r#   N   s    

r#   c               @   sv   e Zd ZdZejde d ejejB ƒZdddddd	d
œZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd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.
        )
        z^\s*z\s*$ÚequalÚ	not_equalÚless_than_equalÚgreater_than_equalÚ	less_thanÚgreater_than)z==z!=z<=z>=ú<ú>c             C   s   t |tƒstt|ƒƒ}|S )N)r6   r	   r2   )r   r&   r   r   r   r<   ò   s    
zLegacySpecifier._coerce_versionc             C   s   || j |ƒkS )N)r<   )r   Úprospectiver.   r   r   r   Ú_compare_equal÷   s    zLegacySpecifier._compare_equalc             C   s   || j |ƒkS )N)r<   )r   rN   r.   r   r   r   Ú_compare_not_equalú   s    z"LegacySpecifier._compare_not_equalc             C   s   || j |ƒkS )N)r<   )r   rN   r.   r   r   r   Ú_compare_less_than_equalý   s    z(LegacySpecifier._compare_less_than_equalc             C   s   || j |ƒkS )N)r<   )r   rN   r.   r   r   r   Ú_compare_greater_than_equal   s    z+LegacySpecifier._compare_greater_than_equalc             C   s   || j |ƒk S )N)r<   )r   rN   r.   r   r   r   Ú_compare_less_than  s    z"LegacySpecifier._compare_less_thanc             C   s   || j |ƒkS )N)r<   )r   rN   r.   r   r   r   Ú_compare_greater_than  s    z%LegacySpecifier._compare_greater_thanN)r   r   r   Ú
_regex_strÚreÚcompileÚVERBOSEÚ
IGNORECASEr'   r9   r<   rO   rP   rQ   rR   rS   rT   r   r   r   r   rE   Ö   s    rE   c                s   t jˆ ƒ‡ fdd„ƒ}|S )Nc                s   t |tƒsdS ˆ | ||ƒS )NF)r6   r   )r   rN   r.   )Úfnr   r   Úwrapped  s    
z)_require_version_compare.<locals>.wrapped)Ú	functoolsÚwraps)rZ   r[   r   )rZ   r   Ú_require_version_compare
  s    r^   c            	   @   s¸   e Zd ZdZejde d ejejB ƒZdddddd	d
ddœZ	e
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZe
dd„ ƒZdd„ Zedd„ ƒZejdd„ ƒZd S )!Ú	Specifiera  
        (?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
            )
        )
        z^\s*z\s*$Ú
compatiblerF   rG   rH   rI   rJ   rK   Ú	arbitrary)z~=z==z!=z<=z>=rL   rM   z===c             C   sN   dj ttjdd„ t|ƒƒƒd d… ƒ}|d7 }| jdƒ||ƒoL| jdƒ||ƒS )	NÚ.c             S   s   | j dƒ o| j dƒ S )NÚpostÚdev)Ú
startswith)Úxr   r   r   Ú<lambda>�  s   z/Specifier._compare_compatible.<locals>.<lambda>r   z.*z>=z==éÿÿÿÿ)ÚjoinÚlistÚ	itertoolsÚ	takewhileÚ_version_splitr;   )r   rN   r.   Úprefixr   r   r   Ú_compare_compatible‚  s    
zSpecifier._compare_compatiblec             C   sp   |j dƒrPt|jƒ}t|d d… ƒ}tt|ƒƒ}|d t|ƒ… }t||ƒ\}}nt|ƒ}|jsht|jƒ}||kS )Nz.*é   éþÿÿÿ)Úendswithr   Úpublicrm   r2   ÚlenÚ_pad_versionÚlocal)r   rN   r.   r   r   r   rO   �  s    


zSpecifier._compare_equalc             C   s   | j ||ƒ S )N)rO   )r   rN   r.   r   r   r   rP   À  s    zSpecifier._compare_not_equalc             C   s   |t |ƒkS )N)r   )r   rN   r.   r   r   r   rQ   Ä  s    z"Specifier._compare_less_than_equalc             C   s   |t |ƒkS )N)r   )r   rN   r.   r   r   r   rR   È  s    z%Specifier._compare_greater_than_equalc             C   s>   t |ƒ}||k sdS |j r:|jr:t |jƒt |jƒkr:dS dS )NFT)r   r>   Úbase_version)r   rN   r.   r   r   r   rS   Ì  s    zSpecifier._compare_less_thanc             C   s`   t |ƒ}||ksdS |j r:|jr:t |jƒt |jƒkr:dS |jd k	r\t |jƒt |jƒkr\dS dS )NFT)r   Úis_postreleaserw   rv   )r   rN   r.   r   r   r   rT   å  s    
zSpecifier._compare_greater_thanc             C   s   t |ƒjƒ t |ƒjƒ kS )N)r2   Úlower)r   rN   r.   r   r   r   Ú_compare_arbitrary  s    zSpecifier._compare_arbitraryc             C   sR   | j d k	r| j S | j\}}|d
krN|dkr@|jdƒr@|d d… }t|ƒjrNdS d	S )Nú==ú>=ú<=ú~=ú===z.*rp   TF)r{   r|   r}   r~   r   rq   )r-   r,   rr   r
   r>   )r   r%   r&   r   r   r   r     s    


zSpecifier.prereleasesc             C   s
   || _ d S )N)r-   )r   r   r   r   r   r     s    N)r   r   r   rU   rV   rW   rX   rY   r'   r9   r^   ro   rO   rP   rQ   rR   rS   rT   rz   rD   r   r"   r   r   r   r   r_     s*   ^#r_   z^([0-9]+)((?:a|b|c|rc)[0-9]+)$c             C   sD   g }x:| j dƒD ],}tj|ƒ}|r2|j|jƒ ƒ q|j|ƒ qW |S )Nrb   )ÚsplitÚ_prefix_regexr(   ÚextendÚgroupsr?   )r&   Úresultr   r/   r   r   r   rm   '  s    
rm   c          	   C   sæ   g g  }}|j ttjdd„ | ƒƒƒ |j ttjdd„ |ƒƒƒ |j | t|d ƒd … ƒ |j |t|d ƒd … ƒ |jddgtdt|d ƒt|d ƒ ƒ ƒ |jddgtdt|d ƒt|d ƒ ƒ ƒ ttj|Ž ƒttj|Ž ƒfS )Nc             S   s   | j ƒ S )N)Úisdigit)rf   r   r   r   rg   6  s    z_pad_version.<locals>.<lambda>c             S   s   | j ƒ S )N)r…   )rf   r   r   r   rg   7  s    r   r   Ú0)r?   rj   rk   rl   rt   ÚinsertÚmaxÚchain)ÚleftÚrightÚ
left_splitÚright_splitr   r   r   ru   2  s    
&&ru   c               @   sŒ   e Zd Zddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zedd„ ƒZejdd„ ƒZdd„ Zddd„Zd dd„ZdS )!ÚSpecifierSetr$   Nc             C   sr   dd„ |j dƒD ƒ}tƒ }xB|D ]:}y|jt|ƒƒ W q  tk
rX   |jt|ƒƒ Y q X q W t|ƒ| _|| _d S )Nc             S   s   g | ]}|j ƒ r|j ƒ ‘qS r   )r+   )Ú.0Úsr   r   r   ú
<listcomp>R  s    z)SpecifierSet.__init__.<locals>.<listcomp>ú,)	r€   ÚsetÚaddr_   r   rE   Ú	frozensetÚ_specsr-   )r   Ú
specifiersr   ÚparsedÚ	specifierr   r   r   r0   O  s    

zSpecifierSet.__init__c             C   s*   | j d k	rdj| jƒnd}djt| ƒ|ƒS )Nz, prereleases={0!r}r$   z<SpecifierSet({0!r}{1})>)r-   r)   r   r2   )r   r3   r   r   r   r4   d  s    zSpecifierSet.__repr__c             C   s   dj tdd„ | jD ƒƒƒS )Nr’   c             s   s   | ]}t |ƒV  qd S )N)r2   )r�   r�   r   r   r   ú	<genexpr>n  s    z'SpecifierSet.__str__.<locals>.<genexpr>)ri   Úsortedr–   )r   r   r   r   r   m  s    zSpecifierSet.__str__c             C   s
   t | jƒS )N)r5   r–   )r   r   r   r   r   p  s    zSpecifierSet.__hash__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.)r6   r   rŽ   r7   r•   r–   r-   Ú
ValueError)r   r   r™   r   r   r   Ú__and__s  s    





zSpecifierSet.__and__c             C   sF   t |tƒrt|ƒ}n&t |tƒr,tt|ƒƒ}nt |tƒs:tS | j|jkS )N)r6   r   rŽ   r#   r2   r7   r–   )r   r   r   r   r   r   Š  s    



zSpecifierSet.__eq__c             C   sF   t |tƒrt|ƒ}n&t |tƒr,tt|ƒƒ}nt |tƒs:tS | j|jkS )N)r6   r   rŽ   r#   r2   r7   r–   )r   r   r   r   r   r   ”  s    



zSpecifierSet.__ne__c             C   s
   t | jƒS )N)rt   r–   )r   r   r   r   Ú__len__ž  s    zSpecifierSet.__len__c             C   s
   t | jƒS )N)Ú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 )N)r   )r�   r�   r   r   r   rš   ³  s    z+SpecifierSet.prereleases.<locals>.<genexpr>)r-   r–   Úany)r   r   r   r   r   ¤  s
    
zSpecifierSet.prereleasesc             C   s
   || _ d S )N)r-   )r   r   r   r   r   r   µ  s    c             C   s
   | j |ƒS )N)r   )r   r   r   r   r   r=   ¹  s    zSpecifierSet.__contains__c                sN   t ˆ ttfƒstˆ ƒ‰ ˆd kr$| j‰ˆ r4ˆ jr4dS t‡ ‡fdd„| jD ƒƒS )NFc             3   s   | ]}|j ˆ ˆd �V  qdS ))r   N)r   )r�   r�   )r   r   r   r   rš   Õ  s   z(SpecifierSet.contains.<locals>.<genexpr>)r6   r	   r   r
   r   r>   Úallr–   )r   r   r   r   )r   r   r   r   ¼  s    zSpecifierSet.containsc             C   s¼   |d kr| j }| jr:x | jD ]}|j|t|ƒd�}qW |S g }g }xZ|D ]R}t|ttfƒsdt|ƒ}n|}t|tƒrtqH|jr�| r�|sš|j	|ƒ qH|j	|ƒ qHW | r´|r´|d kr´|S |S d S )N)r   )
r   r–   r   Úboolr6   r	   r   r
   r>   r?   )r   r   r   r.   ÚfilteredrA   r   rC   r   r   r   r   Ù  s*    


zSpecifierSet.filter)r$   N)N)N)r   r   r   r0   r4   r   r   r�   r   r   rž   r    rD   r   r"   r=   r   r   r   r   r   r   rŽ   M  s   
	


rŽ   )Ú
__future__r   r   r   r   r\   rk   rV   Ú_compatr   r   r&   r   r	   r
   rœ   r   ÚABCMetaÚobjectr   r#   rE   r^   r_   rW   r�   rm   ru   rŽ   r   r   r   r   Ú<module>   s&   9 	4	  
