U
    42i]                     @  sP  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mZ ddlmZ ddlmZ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ddddd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FinalIterableIteratorTypeVarUnion   )canonicalize_version)InvalidVersionVersionUnparsedVersionVar)boundUnparsedVersionVersion | Noneversionreturnc                 C  s2   t | ts.zt| } W n tk
r,   Y d S X | S N)
isinstancer   r   r    r   8/tmp/pip-unpacked-wheel-7wv4vqcv/packaging/specifiers.py_coerce_version   s    
r   r   c                 C  s   | j d dS )N)localZ__replace__r   r   r   r   _public_version#   s    r   c                 C  s   | j d d d d dS )N)prepostdevr   r   r   r   r   r   _base_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dZdZeddd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 )"BaseSpecifierr   )_strstrr   c                 C  s   t | S )z Internal property for match_argsr(   selfr   r   r   r'   ;   s    zBaseSpecifier._strc                 C  s   dS )z
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr   r+   r   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__G   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,   r3   r   r   r   __eq__M   s    zBaseSpecifier.__eq__bool | Nonec                 C  s   dS )zWhether 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   prereleasesV   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   r7   _   s    Nitemr7   r   c                 C  s   dS )zR
        Determines if the given item is contained within this specifier.
        Nr   r,   r=   r7   r   r   r   containsf   s    zBaseSpecifier.containsIterable[UnparsedVersionVar]Iterator[UnparsedVersionVar]iterabler7   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,   rC   r7   r   r   r   filterl   s    zBaseSpecifier.filter)N)N)r"   r#   r$   	__slots__Z__match_args__propertyr'   abcabstractmethodr-   r/   r5   r7   setterr?   rD   r   r   r   r   r&   7   s(    r&   )	metaclassc                	   @  s   e Zd ZU 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ded< d\ddddddZdddddZ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d0d d1d2Zd3d4d5d6d7Zdd8d9d:d;Zddd4d<d=d>Zddd4d<d?d@Zddd4d<dAdBZddd4d<dCdDZddd4d<dEdFZ ddd4dGdHdIZ!ddd4dGdJdKZ"dLdd4d<dMdNZ#dOd4dPdQdRZ$d]dSdd4dTdUdVZ%d^dWddXdYdZd[Z&dS )_	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).
    )_prereleases_spec_spec_versionz8
        (?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*
compatibleequal	not_equalless_than_equalgreater_than_equal	less_thangreater_than	arbitrary)~===!=z<=>=<>===r   
_operators Nr(   r6   r8   )specr7   r   c                 C  sL   | j |}|std||d |d f| _|| _d| _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	fullmatchr!   groupstriprM   rL   rN   )r,   r`   r7   matchr   r   r   __init__   s    zSpecifier.__init__r   r   c                 C  sD   | j dk	r"| j d |kr"| j d S t|}|dkr6dS ||f| _ |S )zDOne element cache, as only one spec Version is needed per Specifier.Nr   r	   )rN   r   )r,   r   Zversion_specifierr   r   r   _get_spec_version  s    

zSpecifier._get_spec_versionr   c                 C  s   |  |}|dk	st|S )zGet spec version, asserting it's valid (not for === operator).

        This method should only be called for operators where version
        strings are guaranteed to be valid PEP 440 versions (not ===).
        N)rh   AssertionError)r,   r   spec_versionr   r   r   _require_spec_version  s    
zSpecifier._require_spec_versionr)   c                 C  s\   | j d k	r| j S | j\}}|dkrX|dkr8|dr8dS | |}|d krNd S |jrXdS dS )NrY   rX   .*FT)rL   rM   endswithrh   is_prerelease)r,   ra   version_strr   r   r   r   r7   %  s    


zSpecifier.prereleasesr9   c                 C  s
   || _ d S r   rL   r;   r   r   r   r7   B  s    c                 C  s
   | j d S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   rM   r+   r   r   r   ra   F  s    zSpecifier.operatorc                 C  s
   | j d S )zaThe version of this specifier.

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r	   rq   r+   r   r   r   r   O  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=r_   r[   ()>)rL   r7   	__class__r"   r(   r,   r   r   r   r   __repr__X  s
    zSpecifier.__repr__c                 C  s   dj | j S )zA 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{}{})formatrM   r+   r   r   r   r-   j  s    zSpecifier.__str__ztuple[str, str]c                 C  sF   | j \}}|dks|dr$||fS | |}t||dkd}||fS )Nr]   rl   rW   Zstrip_trailing_zero)rM   rm   rk   r
   )r,   ra   r   rj   Zcanonical_versionr   r   r   _canonical_spect  s    

 zSpecifier._canonical_specr.   c                 C  s
   t | jS r   )hashrz   r+   r   r   r   r/     s    zSpecifier.__hash__r0   r1   r2   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(   ru   r!   NotImplementedrz   r4   r   r   r   r5     s    
zSpecifier.__eq__CallableOperator)opr   c                 C  s   t | d| j|  }|S )NZ	_compare_)getattrr^   )r,   r~   operator_callabler   r   r   _get_operator  s
     zSpecifier._get_operator)prospectiver`   r   c                 C  sH   t tttt|d d }|d7 }| d||oF| d||S )Nrl   rZ   rX   )_version_joinlist	itertools	takewhile_is_not_suffix_version_splitr   )r,   r   r`   prefixr   r   r   _compare_compatible  s    	 zSpecifier._compare_compatiblec                 C  s   | drdtt|dd}t|d d dd}t|}t|}t||\}}|d t| }	|	|kS | |}
|
js|t|}||
kS d S )Nrl   Fry   )rm   r
   r   r   _pad_versionlenrk   r   )r,   r   r`   Znormalized_prospectiveZnormalized_spec
split_specsplit_prospectivepadded_prospective_shortened_prospectiverj   r   r   r   _compare_equal  s    
 
zSpecifier._compare_equalc                 C  s   |  || S r   )r   r,   r   r`   r   r   r   _compare_not_equal  s    zSpecifier._compare_not_equalc                 C  s   t || |kS r   r   rk   r   r   r   r   _compare_less_than_equal  s    z"Specifier._compare_less_than_equalc                 C  s   t || |kS r   r   r   r   r   r   _compare_greater_than_equal  s    z%Specifier._compare_greater_than_equal)r   spec_strr   c                 C  s:   |  |}||k sdS |js6|jr6t|t|kr6dS dS NFT)rk   rn   r    r,   r   r   r`   r   r   r   _compare_less_than  s    
zSpecifier._compare_less_thanc                 C  sX   |  |}||ksdS |js6|jr6t|t|kr6dS |jd k	rTt|t|krTdS dS r   )rk   is_postreleaser    r   r   r   r   r   _compare_greater_than  s"    
zSpecifier._compare_greater_thanzVersion | strc                 C  s   t | t | kS r   )r(   lowerr   r   r   r   _compare_arbitrary0  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")
        True
        >>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True)
        True
        r?   r,   r=   r   r   r   __contains__3  s    zSpecifier.__contains__r   r<   c                 C  s   t t| j|g|dS )as  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 will follow the recommendation from
            :pep:`440` and match prereleases, as there are no other versions.

        >>> 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")
        True
        >>> Specifier(">=1.2.3", prereleases=False).contains("1.3.0a1")
        False
        >>> Specifier(">=1.2.3").contains("1.3.0a1")
        True
        r7   )r1   r   rD   r>   r   r   r   r?   H  s    zSpecifier.containsr@   rA   rB   c           	      c  s   g }d}|dk	r|n| j }| | j}|D ]r}t|}|dkr^| jdkr| || jr|V  q*||| jr*|jrt|rd}|V  q*|dkr*| jdk	r*|| q*|s|dkr| jdk	r|E dH  dS )a  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 follow the recommendation from :pep:`440`
            and match prereleases if there are no other versions.

        >>> 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']
        FNr]   T)	r7   r   ra   r   r   r   rn   rL   append)	r,   rC   r7   Zprereleases_versionsZfound_non_prereleasesZinclude_prereleasesr   r   parsed_versionr   r   r   rD   c  s4     
zSpecifier.filter)r_   N)N)N)'r"   r#   r$   r%   rE   Z_operator_regex_strZ_version_regex_strrecompileVERBOSE
IGNORECASErb   r^   __annotations__rg   rh   rk   rF   r7   rI   ra   r   rw   r-   rz   r/   r5   r   r   r   r   r   r   r   r   r   r   r?   rD   r   r   r   r   rK   v   s^   
	^


(" rK   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_regexrc   extendgroups)r   resultepochr   restr=   rf   r   r   r   r     s    
r   )
componentsr   c                 C  s   | ^}}| dd | S )zJoin 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   r     s    r   r1   )segmentr   c                   s   t  fdddD  S )Nc                 3  s   | ]}  |V  qd S r   )
startswith).0r   r   r   r   	<genexpr>  s    z!_is_not_suffix.<locals>.<genexpr>)r   abrcr   )anyr   r   r   r   r     s    r   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   r   r   r   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Zd1d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d2d%dddd)d*d+Zd3d,dd-d.d/d0ZdS )4SpecifierSetzThis 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.
    )rL   _specsr_   Nzstr | Iterable[Specifier]r6   r8   )
specifiersr7   r   c                 C  sD   t |tr0dd |dD }ttt|| _n
t|| _|| _dS )a  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.
            May also be an iterable of ``Specifier`` instances, which will be used
            as is.
        :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   )re   r   sr   r   r   
<listcomp>  s      z)SpecifierSet.__init__.<locals>.<listcomp>,N)r   r(   r   	frozensetmaprK   r   rL   )r,   r   r7   split_specifiersr   r   r   rg     s
    

zSpecifierSet.__init__r)   c                 C  s6   | j d k	r| j S | jsd S tdd | jD r2dS d S )Nc                 s  s   | ]}|j V  qd S r   r   r   r   r   r   r     s     z+SpecifierSet.prereleases.<locals>.<genexpr>T)rL   r   r   r+   r   r   r   r7     s    
zSpecifierSet.prereleasesr9   c                 C  s
   || _ d S r   rp   r;   r   r   r   r7   $  s    r(   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)>
        Nrr   r_   z<SpecifierSet(rt   )rL   r7   r(   rv   r   r   r   rw   (  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   H  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   )r{   r   r+   r   r   r   r/   J  s    zSpecifierSet.__hash__zSpecifierSet | strr2   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|_n2| jdk	rl|jdksx| 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   r|   r   r   rL   
ValueError)r,   r3   	specifierr   r   r   __and__M  s&    






zSpecifierSet.__and__r0   r1   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(   rK   r   r|   r   r4   r   r   r   r5   l  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__  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__  s    zSpecifierSet.__iter__r   r   c                 C  s
   |  |S )aq  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")
        True
        >>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True)
        True
        r   r   r   r   r   r     s    zSpecifierSet.__contains__)r=   r7   	installedr   c                 C  sF   t |}|dk	r|r|jrd}|dkr*|n|}tt| j|g|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 will follow the recommendation from :pep:`440`
            and match prereleases, as there are no other versions.
        :param installed:
            Whether or not the item is installed. If set to ``True``, it will
            accept prerelease versions even if the specifier does not allow them.

        >>> 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")
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False).contains("1.3.0a1")
        False
        >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1", prereleases=True)
        True
        NTr   )r   rn   r1   r   rD   )r,   r=   r7   r   r   Z
check_itemr   r   r   r?     s
     zSpecifierSet.containsr@   rA   rB   c           	        s   |dkr| j dk	r| j }| jrV| jD ]}|j||dkr:dn|d}q$|dk	rt|S n*|dkrft|S |dkr fdd|D S g }g }d}|D ]J}t|}|dkr|| || q|jr|| q|| d}qt|r|n|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 follow the recommendation from :pep:`440`
            and match prereleases if there are no other versions.

        >>> 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"]))
        ['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']
        NTr   Fc                 3  s(   | ] }t |  d ks js|V  qd S r   )r   rn   )r   r=   r   r   r   r     s   z&SpecifierSet.filter.<locals>.<genexpr>)r7   r   rD   r   r   r   rn   )	r,   rC   r7   r`   Zfiltered_itemsfound_prereleasesZfound_final_releaser=   r   r   r   r   rD     s:    '
 

	

zSpecifierSet.filter)r_   N)NN)N)r"   r#   r$   r%   rE   rg   rF   r7   rI   rw   r-   r/   r   r5   r   r   r   r?   rD   r   r   r   r   r     s,     &
  ) r   )&r%   
__future__r   rG   r   r   typingr   r   r   r   r   r   utilsr
   r   r   r   r(   r   r   r1   r}   r   r   r    r   r!   ABCMetar&   rK   r   r   r   r   r   r   r   r   r   r   r   <module>   s4    	?    0
