U
    aÊ¹j"›  ã                   @  s(  d Z ddlm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 ddlmZ ddlmZ eeef Ze
ded	�Zeeegef Zd
ddœdd„ZG dd„ deƒZG dd„ dejd�ZG dd„ deƒZe d¡Zdddœdd„Zdddœdd„Zdddœd d!„Zddd"d#œd$d%„Z G d&d'„ d'eƒZ!dS )(zŠ
.. testsetup::

    from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
    from packaging.version import Version
é    )ÚannotationsN)ÚCallableÚIterableÚIteratorÚTypeVarÚUnioné   )Úcanonicalize_version)ÚVersionÚUnparsedVersionVar)ÚboundÚUnparsedVersionr
   )ÚversionÚreturnc                 C  s   t | tƒst| ƒ} | S ©N)Ú
isinstancer
   )r   © r   úf/var/www/html/bwave/python/venv/lib/python3.8/site-packages/setuptools/_vendor/packaging/specifiers.pyÚ_coerce_version   s    
r   c                   @  s   e Zd ZdZdS )ÚInvalidSpecifiera  
    Raised when attempting to create a :class:`Specifier` with a specifier
    string that is invalid.

    >>> Specifier("lolwat")
    Traceback (most recent call last):
        ...
    packaging.specifiers.InvalidSpecifier: Invalid specifier: 'lolwat'
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r       s   r   c                   @  s¬   e Zd Zejddœdd„ƒZejddœdd„ƒZejdd	d
œdd„ƒZeejddœdd„ƒƒZ	e	j
d	ddœdd„ƒZ	ejdddd	dœdd„ƒZejdddddœdd„ƒZdS )ÚBaseSpecifierÚstr©r   c                 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__Úintc                 C  s   dS )zF
        Returns a hash value for this Specifier-like object.
        Nr   r   r   r   r   Ú__hash__4   s    zBaseSpecifier.__hash__ÚobjectÚbool©Úotherr   c                 C  s   dS )z«
        Returns a boolean representing whether or not the two Specifier-like
        objects are equal.

        :param other: The other object to check against.
        Nr   ©r   r%   r   r   r   Ú__eq__:   s    zBaseSpecifier.__eq__úbool | Nonec                 C  s   dS )zîWhether or not pre-releases as a whole are allowed.

        This can be set to either ``True`` or ``False`` to explicitly enable or disable
        prereleases or it can be set to ``None`` (the default) to use default semantics.
        Nr   r   r   r   r   ÚprereleasesC   s    zBaseSpecifier.prereleasesÚNone©Úvaluer   c                 C  s   dS )zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr   ©r   r,   r   r   r   r)   L   s    N©Ú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   ÚcontainsS   s    zBaseSpecifier.containsúIterable[UnparsedVersionVar]úIterator[UnparsedVersionVar]©Ú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   r4   r)   r   r   r   ÚfilterY   s    zBaseSpecifier.filter)N)N)r   r   r   ÚabcÚabstractmethodr   r!   r'   Úpropertyr)   Úsetterr0   r5   r   r   r   r   r   ,   s     ÿr   )Ú	metaclassc                	   @  sÒ  e Zd ZdZdZdZe de e d ejej	B ¡Z
dddd	d
ddddœZdSddddœdd„Zeddœdd„ƒZejdddœdd„ƒZeddœdd„ƒZeddœdd „ƒZddœd!d"„Zddœd#d$„Zed%dœd&d'„ƒZd(dœd)d*„Zd+dd,œd-d.„Zdd/d0œd1d2„Zd3ddd4œd5d6„Zd3ddd4œd7d8„Zd3ddd4œd9d:„Zd3ddd4œd;d<„Zd3ddd4œd=d>„Zd3ddd?œd@dA„Zd3ddd?œdBdC„Zd3ddd4œdDdE„ZdFddGœdHdI„Z dTdJdddKœdLdM„Z!dUdNddOdPœdQdR„Z"dS )VÚ	Specifiera?  This class abstracts handling of version specifiers.

    .. tip::

        It is generally not required to instantiate this manually. You should instead
        prefer to work with :class:`SpecifierSet` instead, which can parse
        comma-separated version specifiers (which is what package metadata contains).
    z8
        (?P<operator>(~=|==|!=|<=|>=|<|>|===))
        aÈ  
        (?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;)]*  # The arbitrary version can be just about anything,
                          # we match everything except for whitespace, a
                          # semi-colon for marker support, and a closing paren
                          # since versions can be enclosed in them.
            )
            |
            (?:
                # 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

                # You cannot use a wild card and a pre-release, post-release, a dev or
                # local version together so group them with a | and make them optional.
                (?:
                    \.\*  # Wild card syntax of .*
                    |
                    (?:                                  # pre release
                        [-_\.]?
                        (alpha|beta|preview|pre|a|b|c|rc)
                        [-_\.]?
                        [0-9]*
                    )?
                    (?:                                  # post release
                        (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                    )?
                    (?:[-_\.]?dev[-_\.]?[0-9]*)?         # dev release
                    (?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
                )?
            )
            |
            (?:
                # 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
                    [-_\.]?
                    (alpha|beta|preview|pre|a|b|c|rc)
                    [-_\.]?
                    [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
                    [-_\.]?
                    (alpha|beta|preview|pre|a|b|c|rc)
                    [-_\.]?
                    [0-9]*
                )?
                (?:                                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?
                (?:[-_\.]?dev[-_\.]?[0-9]*)?          # dev release
            )
        )
        z^\s*z\s*$Ú
compatibleÚequalÚ	not_equalÚless_than_equalÚgreater_than_equalÚ	less_thanÚgreater_thanÚ	arbitrary)ú~=ú==z!=ú<=ú>=ú<ú>ú===Ú Nr   r(   r*   )Úspecr)   r   c                 C  sH   | j  |¡}|s td|› d�ƒ‚| d¡ ¡ | d¡ ¡ f| _|| _dS )að  Initialize a Specifier instance.

        :param spec:
            The string representation of a specifier which will be parsed and
            normalized before use.
        :param prereleases:
            This tells the specifier if it should accept prerelease versions if
            applicable or not. The default of ``None`` will autodetect it from the
            given specifiers.
        :raises InvalidSpecifier:
            If the given specifier is invalid (i.e. bad syntax).
        zInvalid specifier: 'ú'Úoperatorr   N)Ú_regexÚsearchr   ÚgroupÚstripÚ_specÚ_prereleases)r   rL   r)   Úmatchr   r   r   Ú__init__Þ   s    þzSpecifier.__init__r#   r   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)rE   rG   rF   rD   rJ   rE   ú.*éþÿÿÿTF)rT   rS   Úendswithr
   Úis_prerelease)r   rN   r   r   r   r   r)   ø   s    


zSpecifier.prereleasesr+   c                 C  s
   || _ d S r   ©rT   r-   r   r   r   r)     s    c                 C  s
   | j d S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   ©rS   r   r   r   r   rN     s    zSpecifier.operatorc                 C  s
   | j d S )zaThe version of this specifier.

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r   r\   r   r   r   r   r     s    zSpecifier.versionc                 C  s8   | j dk	rd| j›�nd}d| jj› dt| ƒ›|› d�S )aT  A representation of the Specifier that shows all internal state.

        >>> Specifier('>=1.0.0')
        <Specifier('>=1.0.0')>
        >>> Specifier('>=1.0.0', prereleases=False)
        <Specifier('>=1.0.0', prereleases=False)>
        >>> Specifier('>=1.0.0', prereleases=True)
        <Specifier('>=1.0.0', prereleases=True)>
        Nú, prereleases=rK   rH   ú(ú)>)rT   r)   Ú	__class__r   r   ©r   Úprer   r   r   Ú__repr__&  s
    ÿýzSpecifier.__repr__c                 C  s   dj | jŽ S )zÐA string representation of the Specifier that can be round-tripped.

        >>> str(Specifier('>=1.0.0'))
        '>=1.0.0'
        >>> str(Specifier('>=1.0.0', prereleases=False))
        '>=1.0.0'
        z{}{})ÚformatrS   r   r   r   r   r   8  s    zSpecifier.__str__ztuple[str, str]c                 C  s*   t | jd | jd dkd�}| jd |fS )Nr   r   rD   ©Ústrip_trailing_zero)r	   rS   )r   Úcanonical_versionr   r   r   Ú_canonical_specB  s
    þzSpecifier._canonical_specr    c                 C  s
   t | jƒS r   )Úhashrh   r   r   r   r   r!   J  s    zSpecifier.__hash__r"   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 )a>  Whether or not the two Specifier-like objects are equal.

        :param other: The other object to check against.

        The value of :attr:`prereleases` is ignored.

        >>> Specifier("==1.2.3") == Specifier("== 1.2.3.0")
        True
        >>> (Specifier("==1.2.3", prereleases=False) ==
        ...  Specifier("==1.2.3", prereleases=True))
        True
        >>> Specifier("==1.2.3") == "==1.2.3"
        True
        >>> Specifier("==1.2.3") == Specifier("==1.2.4")
        False
        >>> Specifier("==1.2.3") == Specifier("~=1.2.3")
        False
        )r   r   r`   r   ÚNotImplementedrh   r&   r   r   r   r'   M  s    
zSpecifier.__eq__ÚCallableOperator)Úopr   c                 C  s   t | d| j| › �ƒ}|S )NÚ	_compare_)ÚgetattrÚ
_operators)r   rl   Úoperator_callabler   r   r   Ú_get_operatorj  s
     ÿzSpecifier._get_operatorr
   )ÚprospectiverL   r   c                 C  sH   t tt tt|ƒ¡ƒd d… ƒ}|d7 }|  d¡||ƒoF|  d¡||ƒS )NéÿÿÿÿrW   rG   rE   )Ú_version_joinÚlistÚ	itertoolsÚ	takewhileÚ_is_not_suffixÚ_version_splitrq   )r   rr   rL   Úprefixr   r   r   Ú_compare_compatiblep  s    	ÿ ÿzSpecifier._compare_compatiblec                 C  s†   |  d¡rbt|jdd�}t|d d… dd�}t|ƒ}t|ƒ}t||ƒ\}}|d t|ƒ… }	|	|kS t|ƒ}
|
jszt|jƒ}||
kS d S )NrW   Fre   rX   )rY   r	   Úpublicry   Ú_pad_versionÚlenr
   Úlocal)r   rr   rL   Únormalized_prospectiveÚnormalized_specÚ
split_specÚsplit_prospectiveÚpadded_prospectiveÚ_Úshortened_prospectiveÚspec_versionr   r   r   Ú_compare_equal„  s    
 ÿ
zSpecifier._compare_equalc                 C  s   |   ||¡ S r   )rˆ   ©r   rr   rL   r   r   r   Ú_compare_not_equal¬  s    zSpecifier._compare_not_equalc                 C  s   t |jƒt |ƒkS r   ©r
   r|   r‰   r   r   r   Ú_compare_less_than_equal¯  s    z"Specifier._compare_less_than_equalc                 C  s   t |jƒt |ƒkS r   r‹   r‰   r   r   r   Ú_compare_greater_than_equalµ  s    z%Specifier._compare_greater_than_equal)rr   Úspec_strr   c                 C  s<   t |ƒ}||k sdS |js8|jr8t |jƒt |jƒkr8dS dS ©NFT)r
   rZ   Úbase_version©r   rr   rŽ   rL   r   r   r   Ú_compare_less_than»  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   Ú_compare_greater_thanÓ  s    
zSpecifier._compare_greater_thanc                 C  s   t |ƒ ¡ t |ƒ ¡ kS r   )r   Úlowerr‰   r   r   r   Ú_compare_arbitraryñ  s    zSpecifier._compare_arbitraryzstr | Version©r/   r   c                 C  s
   |   |¡S )a;  Return whether or not the item is contained in this specifier.

        :param item: The item to check for.

        This is used for the ``in`` operator and behaves the same as
        :meth:`contains` with no ``prereleases`` argument passed.

        >>> "1.2.3" in Specifier(">=1.2.3")
        True
        >>> Version("1.2.3") in Specifier(">=1.2.3")
        True
        >>> "1.0.0" in Specifier(">=1.2.3")
        False
        >>> "1.3.0a1" in Specifier(">=1.2.3")
        False
        >>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True)
        True
        ©r0   ©r   r/   r   r   r   Ú__contains__ô  s    zSpecifier.__contains__r   r.   c                 C  s<   |dkr| j }t|ƒ}|jr$|s$dS |  | j¡}||| jƒS )al  Return whether or not the item is contained in this specifier.

        :param item:
            The item to check for, which can be a version string or a
            :class:`Version` instance.
        :param prereleases:
            Whether or not to match prereleases with this Specifier. If set to
            ``None`` (the default), it uses :attr:`prereleases` to determine
            whether or not prereleases are allowed.

        >>> Specifier(">=1.2.3").contains("1.2.3")
        True
        >>> Specifier(">=1.2.3").contains(Version("1.2.3"))
        True
        >>> Specifier(">=1.2.3").contains("1.0.0")
        False
        >>> Specifier(">=1.2.3").contains("1.3.0a1")
        False
        >>> Specifier(">=1.2.3", prereleases=True).contains("1.3.0a1")
        True
        >>> Specifier(">=1.2.3").contains("1.3.0a1", prereleases=True)
        True
        NF)r)   r   rZ   rq   rN   r   )r   r/   r)   Únormalized_itemrp   r   r   r   r0   	  s    
zSpecifier.containsr1   r2   r3   c                 c  s~   d}g }d|dk	r|ndi}|D ]@}t |ƒ}| j|f|Žr |jrV|sV| jsV| |¡ q d}|V  q |sz|rz|D ]
}|V  qndS )aO  Filter items in the given iterable, that match the specifier.

        :param iterable:
            An iterable that can contain version strings and :class:`Version` instances.
            The items in the iterable will be filtered according to the specifier.
        :param prereleases:
            Whether or not to allow prereleases in the returned iterator. If set to
            ``None`` (the default), it will be intelligently decide whether to allow
            prereleases or not (based on the :attr:`prereleases` attribute, and
            whether the only versions matching are prereleases).

        This method is smarter than just ``filter(Specifier().contains, [...])``
        because it implements the rule from :pep:`440` that a prerelease item
        SHOULD be accepted if no other versions match the given specifier.

        >>> list(Specifier(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
        ['1.3']
        >>> list(Specifier(">=1.2.3").filter(["1.2", "1.2.3", "1.3", Version("1.4")]))
        ['1.2.3', '1.3', <Version('1.4')>]
        >>> list(Specifier(">=1.2.3").filter(["1.2", "1.5a1"]))
        ['1.5a1']
        >>> list(Specifier(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
        ['1.3', '1.5a1']
        >>> list(Specifier(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
        ['1.3', '1.5a1']
        Fr)   NT)r   r0   rZ   r)   Úappend)r   r4   r)   ÚyieldedÚfound_prereleasesÚkwr   Úparsed_versionr   r   r   r5   5  s"    ÿÿzSpecifier.filter)rK   N)N)N)#r   r   r   r   Ú_operator_regex_strÚ_version_regex_strÚreÚcompileÚVERBOSEÚ
IGNORECASErO   ro   rV   r8   r)   r9   rN   r   rc   r   rh   r!   r'   rq   r{   rˆ   rŠ   rŒ   r�   r’   r”   r–   rš   r0   r5   r   r   r   r   r;   c   sX   	^
þø
(- ÿr;   z^([0-9]+)((?:a|b|c|rc)[0-9]+)$r   z	list[str]c                 C  s^   g }|   d¡\}}}| |pd¡ | d¡D ],}t |¡}|rN| | ¡ ¡ q,| |¡ q,|S )a  Split version into components.

    The split components are intended for version comparison. The logic does
    not attempt to retain the original version string, so joining the
    components back with :func:`_version_join` may not produce the original
    version string.
    ú!Ú0Ú.)Ú
rpartitionrœ   ÚsplitÚ_prefix_regexrP   ÚextendÚgroups)r   ÚresultÚepochr…   Úrestr/   rU   r   r   r   ry   v  s    
ry   )Ú
componentsr   c                 C  s   | ^}}|› dd  |¡› �S )zñJoin split version components into a version string.

    This function assumes the input came from :func:`_version_split`, where the
    first component must be the epoch (either empty or numeric), and all other
    components numeric.
    r§   r©   )Újoin)r²   r°   r±   r   r   r   rt   Œ  s    rt   r#   )Úsegmentr   c                   s   t ‡ fdd„dD ƒƒ S )Nc                 3  s   | ]}ˆ   |¡V  qd S r   )Ú
startswith)Ú.0rz   ©r´   r   r   Ú	<genexpr>˜  s    z!_is_not_suffix.<locals>.<genexpr>)ÚdevÚaÚbÚrcÚpost)Úanyr·   r   r·   r   rx   —  s    ÿrx   ztuple[list[str], list[str]])Ú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 r   ©Úisdigit©Úxr   r   r   Ú<lambda>¡  ó    z_pad_version.<locals>.<lambda>c                 S  s   |   ¡ S r   rÁ   rÃ   r   r   r   rÅ   ¢  rÆ   r   r   r¨   )	rœ   ru   rv   rw   r~   ÚinsertÚmaxÚchainÚfrom_iterable)r¿   rÀ   Ú
left_splitÚright_splitr   r   r   r}   �  s    
,,þr}   c                   @  sì   e Zd ZdZd/ddddœdd	„Zedd
œdd„ƒZejdddœdd„ƒZdd
œdd„Zdd
œdd„Z	dd
œdd„Z
dd dœdd„Zdddœdd„Zdd
œdd„Zd d
œd!d"„Zd#dd$œd%d&„Zd0d#dddd'œd(d)„Zd1d*dd+d,œd-d.„ZdS )2ÚSpecifierSetzÌThis class abstracts handling of a set of version specifiers.

    It can be passed a single specifier (``>=3.0``), a comma-separated list of
    specifiers (``>=3.0,!=3.1``), or no specifier at all.
    rK   Nr   r(   r*   )Ú
specifiersr)   r   c                 C  s.   dd„ |  d¡D ƒ}ttt|ƒƒ| _|| _dS )aN  Initialize a SpecifierSet instance.

        :param specifiers:
            The string representation of a specifier or a comma-separated list of
            specifiers which will be parsed and normalized before use.
        :param prereleases:
            This tells the SpecifierSet if it should accept prerelease versions if
            applicable or not. The default of ``None`` will autodetect it from the
            given specifiers.

        :raises InvalidSpecifier:
            If the given ``specifiers`` are not parseable than this exception will be
            raised.
        c                 S  s   g | ]}|  ¡ r|  ¡ ‘qS r   )rR   ©r¶   Úsr   r   r   Ú
<listcomp>Ë  s      z)SpecifierSet.__init__.<locals>.<listcomp>ú,N)r«   Ú	frozensetÚmapr;   Ú_specsrT   )r   rÎ   r)   Úsplit_specifiersr   r   r   rV   ¹  s    zSpecifierSet.__init__r   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 r   ©r)   rÏ   r   r   r   r¸   ã  s     z+SpecifierSet.prereleases.<locals>.<genexpr>)rT   rÕ   r¾   r   r   r   r   r)   Ô  s
    
zSpecifierSet.prereleasesr#   r+   c                 C  s
   || _ d S r   r[   r-   r   r   r   r)   å  s    c                 C  s.   | j dk	rd| j›�nd}dt| ƒ›|› d�S )a  A representation of the specifier set that shows all internal state.

        Note that the ordering of the individual specifiers within the set may not
        match the input string.

        >>> SpecifierSet('>=1.0.0,!=2.0.0')
        <SpecifierSet('!=2.0.0,>=1.0.0')>
        >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=False)
        <SpecifierSet('!=2.0.0,>=1.0.0', prereleases=False)>
        >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=True)
        <SpecifierSet('!=2.0.0,>=1.0.0', prereleases=True)>
        Nr]   rK   z<SpecifierSet(r_   )rT   r)   r   ra   r   r   r   rc   é  s
    ÿýzSpecifierSet.__repr__c                 C  s   d  tdd„ | jD ƒƒ¡S )an  A string representation of the specifier set that can be round-tripped.

        Note that the ordering of the individual specifiers within the set may not
        match the input string.

        >>> str(SpecifierSet(">=1.0.0,!=1.0.1"))
        '!=1.0.1,>=1.0.0'
        >>> str(SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False))
        '!=1.0.1,>=1.0.0'
        rÒ   c                 s  s   | ]}t |ƒV  qd S r   )r   rÏ   r   r   r   r¸   	  s     z'SpecifierSet.__str__.<locals>.<genexpr>)r³   ÚsortedrÕ   r   r   r   r   r   þ  s    zSpecifierSet.__str__r    c                 C  s
   t | jƒS r   )ri   rÕ   r   r   r   r   r!     s    zSpecifierSet.__hash__zSpecifierSet | strr$   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 )a‚  Return a SpecifierSet which is a combination of the two sets.

        :param other: The other object to combine with.

        >>> SpecifierSet(">=1.0.0,!=1.0.1") & '<=2.0.0,!=2.0.1'
        <SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
        >>> SpecifierSet(">=1.0.0,!=1.0.1") & SpecifierSet('<=2.0.0,!=2.0.1')
        <SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
        NzFCannot combine SpecifierSets with True and False prerelease overrides.)r   r   rÍ   rj   rÓ   rÕ   rT   Ú
ValueError)r   r%   Ú	specifierr   r   r   Ú__and__  s     






ÿzSpecifierSet.__and__r"   c                 C  s6   t |ttfƒrtt|ƒƒ}nt |tƒs*tS | j|jkS )a¡  Whether or not the two SpecifierSet-like objects are equal.

        :param other: The other object to check against.

        The value of :attr:`prereleases` is ignored.

        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.1")
        True
        >>> (SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False) ==
        ...  SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True))
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == ">=1.0.0,!=1.0.1"
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0")
        False
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.2")
        False
        )r   r   r;   rÍ   rj   rÕ   r&   r   r   r   r'   .  s
    
zSpecifierSet.__eq__c                 C  s
   t | jƒS )z7Returns the number of specifiers in this specifier set.)r~   rÕ   r   r   r   r   Ú__len__H  s    zSpecifierSet.__len__zIterator[Specifier]c                 C  s
   t | jƒS )zð
        Returns an iterator over all the underlying :class:`Specifier` instances
        in this specifier set.

        >>> sorted(SpecifierSet(">=1.0.0,!=1.0.1"), key=str)
        [<Specifier('!=1.0.1')>, <Specifier('>=1.0.0')>]
        )ÚiterrÕ   r   r   r   r   Ú__iter__L  s    zSpecifierSet.__iter__r   r—   c                 C  s
   |   |¡S )ar  Return whether or not the item is contained in this specifier.

        :param item: The item to check for.

        This is used for the ``in`` operator and behaves the same as
        :meth:`contains` with no ``prereleases`` argument passed.

        >>> "1.2.3" in SpecifierSet(">=1.0.0,!=1.0.1")
        True
        >>> Version("1.2.3") in SpecifierSet(">=1.0.0,!=1.0.1")
        True
        >>> "1.0.1" in SpecifierSet(">=1.0.0,!=1.0.1")
        False
        >>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1")
        False
        >>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True)
        True
        r˜   r™   r   r   r   rš   V  s    zSpecifierSet.__contains__)r/   r)   Ú	installedr   c                   s\   t ˆ tƒstˆ ƒ‰ ˆdkr | j‰ˆs.ˆ jr.dS |rBˆ jrBtˆ jƒ‰ t‡ ‡fdd„| jD ƒƒS )a´  Return whether or not the item is contained in this SpecifierSet.

        :param item:
            The item to check for, which can be a version string or a
            :class:`Version` instance.
        :param prereleases:
            Whether or not to match prereleases with this SpecifierSet. If set to
            ``None`` (the default), it uses :attr:`prereleases` to determine
            whether or not prereleases are allowed.

        >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.2.3")
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1").contains(Version("1.2.3"))
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.0.1")
        False
        >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1")
        False
        >>> SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True).contains("1.3.0a1")
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1", prereleases=True)
        True
        NFc                 3  s   | ]}|j ˆ ˆd �V  qdS )r×   Nr˜   rÏ   ©r/   r)   r   r   r¸   ¢  s     z(SpecifierSet.contains.<locals>.<genexpr>)r   r
   r)   rZ   r�   ÚallrÕ   )r   r/   r)   rß   r   rà   r   r0   k  s    



zSpecifierSet.containsr1   r2   r3   c                 C  sœ   |dkr| j }| jr:| jD ]}|j|t|ƒd�}qt|ƒS g }g }|D ]0}t|ƒ}|jrl|sl|sv| |¡ qF| |¡ qF|s�|r�|dkr�t|ƒS t|ƒS dS )a.  Filter items in the given iterable, that match the specifiers in this set.

        :param iterable:
            An iterable that can contain version strings and :class:`Version` instances.
            The items in the iterable will be filtered according to the specifier.
        :param prereleases:
            Whether or not to allow prereleases in the returned iterator. If set to
            ``None`` (the default), it will be intelligently decide whether to allow
            prereleases or not (based on the :attr:`prereleases` attribute, and
            whether the only versions matching are prereleases).

        This method is smarter than just ``filter(SpecifierSet(...).contains, [...])``
        because it implements the rule from :pep:`440` that a prerelease item
        SHOULD be accepted if no other versions match the given specifier.

        >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.3", "1.5a1"]))
        ['1.3']
        >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.3", Version("1.4")]))
        ['1.3', <Version('1.4')>]
        >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "1.5a1"]))
        []
        >>> list(SpecifierSet(">=1.2.3").filter(["1.3", "1.5a1"], prereleases=True))
        ['1.3', '1.5a1']
        >>> list(SpecifierSet(">=1.2.3", prereleases=True).filter(["1.3", "1.5a1"]))
        ['1.3', '1.5a1']

        An "empty" SpecifierSet will filter items based on the presence of prerelease
        versions in the set.

        >>> list(SpecifierSet("").filter(["1.3", "1.5a1"]))
        ['1.3']
        >>> list(SpecifierSet("").filter(["1.5a1"]))
        ['1.5a1']
        >>> list(SpecifierSet("", prereleases=True).filter(["1.3", "1.5a1"]))
        ['1.3', '1.5a1']
        >>> list(SpecifierSet("").filter(["1.3", "1.5a1"], prereleases=True))
        ['1.3', '1.5a1']
        Nr×   )r)   rÕ   r5   r#   rÝ   r   rZ   rœ   )r   r4   r)   rL   Úfilteredrž   r/   r    r   r   r   r5   ¤  s"    ,

zSpecifierSet.filter)rK   N)NN)N)r   r   r   r   rV   r8   r)   r9   rc   r   r!   rÛ   r'   rÜ   rÞ   rš   r0   r5   r   r   r   r   rÍ   ²  s&    
  ü: ÿrÍ   )"r   Ú
__future__r   r6   rv   r£   Útypingr   r   r   r   r   Úutilsr	   r   r
   r   r   r   r#   rk   r   rÙ   r   ÚABCMetar   r;   r¤   r¬   ry   rt   rx   r}   rÍ   r   r   r   r   Ú<module>   s0   7    
