a
    b3jZ                    @  s0  U d Z ddlmZ ddlZddlZddlZddlZddl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 ddlmZ ddlmZmZ ejdkrdd	l	mZ ne
rdd	lmZ g d
ZddddZdddddZdddddZedZeee f Z!ede!dZ"eee ge#f Z$edZ%de&d< dddd d!Z'G d"d# d#ej(Z)ej*G d$d% d%Z+ej*G d&d' d'Z,ej*G d(d) d)Z-e	j
reee+df Z.e/e,e-f Z0e,dd*Z1e-dd*Z2e1e2ffZ3d+e&d,< d'd)d-d.d/d0Z4d1d1d2d3d4d5Z5d6d6d7d8d9Z6d6d6d7d:d;Z7d<d=d7d>d?Z8d6d6d7d@dAZ9d6d6d7dBdCZ:d6d6d7dDdEZ;dFd=dGdHdIZ<G dJdK dKe=Z>G dLdM dMej?dNZ@G dOdP dPe@ZAeBdQZCdRdSdTdUdVdWZDdXdd7dYdZZEddXd[d\d]ZFdXd-d^d_d`ZGddadbdcddZHddaddedfdgZIdhdadidjdkZJG dldm dme@ZKdS )nz
.. testsetup::

    from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
    from packaging.version import Version
    )annotationsN)	TYPE_CHECKINGAnyCallableFinalIterableIteratorSequenceTypeVarUnion   )canonicalize_version)InvalidVersionVersion)   
   )	TypeGuard)BaseSpecifierInvalidSpecifier	SpecifierSpecifierSetz	list[str]returnc                   C  s   t S N)__all__ r   r   q/www/wwwroot/dpstar/app/297b3aabda72fedb274352021c2dd8b5_venv/lib/python3.9/site-packages/packaging/specifiers.py__dir__0   s    r   objectzTypeGuard[tuple[str, str]]specr   c                C  s2   t | to0t| dko0t | d to0t | d tS )N   r   r   )
isinstancetuplelenstr)r    r   r   r   _validate_spec4   s    

r&   zTypeGuard[bool | None])prer   c                C  s   | d u pt | tS r   )r"   bool)r'   r   r   r   _validate_pre=   s    r)   TUnparsedVersionVar)boundz0.dev0zFinal[Version]_MIN_VERSIONztuple[int, ...])releaser   c                 C  sF   t | }|dkr*| |d  dkr*|d8 }q|t | kr:| S | d| S )zDStrip trailing zeros from a release tuple for normalized comparison.r   r   N)r$   )r.   endr   r   r   _trim_releaseJ   s    
r0   c                   @  s    e Zd ZdZe Ze ZdS )_BoundaryKindz5Where a boundary marker sits in the version ordering.N)__name__
__module____qualname____doc__enumautoAFTER_LOCALSAFTER_POSTSr   r   r   r   r1   R   s   r1   c                   @  sr   e Zd ZdZdZddddddZd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S )_BoundaryVersiona  A point on the version line between two real PEP 440 versions.

    Some specifier semantics imply boundaries between real versions:
    ``<=1.0`` includes ``1.0+local`` and ``>1.0`` excludes
    ``1.0.post0``.  No real :class:`Version` falls on those boundaries,
    so this class creates values that sort between the real versions
    on either side.

    Two kinds exist, shown relative to a base version V::

        V < V+local < AFTER_LOCALS(V) < V.post0 < AFTER_POSTS(V)

    ``AFTER_LOCALS`` sits after V and every V+local, but before
    V.post0.  Upper bound of ``<=V``, ``==V``, ``!=V``.

    ``AFTER_POSTS`` sits after every V.postN, but before the next
    release segment.  Lower bound of ``>V`` (final or pre-release V)
    to exclude post-releases per PEP 440.
    )_kind_trimmed_releaseversionr   r1   None)r=   kindr   c                 C  s   || _ || _t|j| _d S r   )r=   r;   r0   r.   r<   )selfr=   r?   r   r   r   __init__q   s    z_BoundaryVersion.__init__r(   otherr   c                 C  sl   | j }|j|jkr.t|j| jkr.|j|jks2dS | jtjkrV|j	|j	koT|j
|j
kS |j
|j
kpj|j	duS )z6Is ``other`` a version that this boundary sorts above?FN)r=   epochr0   r.   r<   r'   r;   r1   r8   postdev)r@   rC   vr   r   r   
_is_familyv   s    

z_BoundaryVersion._is_familyr   c                 C  s&   t |tr"| j|jko | j|jkS tS r   )r"   r:   r=   r;   NotImplementedr@   rC   r   r   r   __eq__   s    
z_BoundaryVersion.__eq__z_BoundaryVersion | Versionc                 C  sH   t |tr2| j|jkr"| j|jk S | jj|jjk S | | oF| j|k S r   )r"   r:   r=   r;   valuerH   rJ   r   r   r   __lt__   s
    
z_BoundaryVersion.__lt__intr   c                 C  s   t | j| jfS r   )hashr=   r;   r@   r   r   r   __hash__   s    z_BoundaryVersion.__hash__r%   c                 C  s    | j j d| jd| jj dS )N(z, ))	__class__r2   r=   r;   namerP   r   r   r   __repr__   s    z_BoundaryVersion.__repr__N)r2   r3   r4   r5   	__slots__rA   rH   rK   rM   rQ   rV   r   r   r   r   r:   Y   s   r:   c                   @  sb   e Zd ZdZdZdd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S )_LowerBoundzLower bound of a version range.

    A version *v* of ``None`` means unbounded below (-inf).
    At equal versions, ``[v`` sorts before ``(v`` because an inclusive
    bound starts earlier.
    	inclusiver=   _VersionOrBoundaryr(   r>   r=   rZ   r   c                 C  s   || _ || _d S r   r=   rZ   r@   r=   rZ   r   r   r   rA      s    z_LowerBound.__init__r   rB   c                 C  s&   t |tstS | j|jko$| j|jkS r   r"   rX   rI   r=   rZ   rJ   r   r   r   rK      s    
z_LowerBound.__eq__c                 C  sV   t |tstS | jd u r"|jd uS |jd u r0dS | j|jkrH| j|jk S | joT|j S )NFr_   rJ   r   r   r   rM      s    



z_LowerBound.__lt__rN   r   c                 C  s   t | j| jfS r   rO   r=   rZ   rP   r   r   r   rQ      s    z_LowerBound.__hash__r%   c                 C  s*   | j r
dnd}d| jj d| | jdS )N[rR   < >rZ   rT   r2   r=   r@   Zbracketr   r   r   rV      s    z_LowerBound.__repr__N
r2   r3   r4   r5   rW   rA   rK   rM   rQ   rV   r   r   r   r   rX      s   rX   c                   @  sb   e Zd ZdZdZdd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S )_UpperBoundzUpper bound of a version range.

    A version *v* of ``None`` means unbounded above (+inf).
    At equal versions, ``v)`` sorts before ``v]`` because an exclusive
    bound ends earlier.
    rY   r[   r(   r>   r\   c                 C  s   || _ || _d S r   r]   r^   r   r   r   rA      s    z_UpperBound.__init__r   rB   c                 C  s&   t |tstS | j|jko$| j|jkS r   r"   rh   rI   r=   rZ   rJ   r   r   r   rK      s    
z_UpperBound.__eq__c                 C  sP   t |tstS | jd u rdS |jd u r*dS | j|jkrB| j|jk S | j oN|jS NFTri   rJ   r   r   r   rM      s    


z_UpperBound.__lt__rN   r   c                 C  s   t | j| jfS r   r`   rP   r   r   r   rQ      s    z_UpperBound.__hash__r%   c                 C  s*   | j r
dnd}d| jj d| j| dS )N]rS   rb   rc   rd   re   rf   r   r   r   rV      s    z_UpperBound.__repr__Nrg   r   r   r   r   rh      s   rh   Fztuple[_VersionRange]_FULL_RANGEr(   )lowerupperr   c                 C  s>   | j du s|j du rdS | j |j kr2| jo.|j S | j |j kS )zHTrue when the range defined by *lower* and *upper* contains no versions.NFr]   )rm   rn   r   r   r   _range_is_empty   s
    ro   Sequence[_VersionRange]list[_VersionRange])leftrightr   c                 C  s   g }d }}|t | k r|t |k r| | \}}|| \}}t||}	t||}
t|	|
sh||	|
f ||k rz|d7 }q|d7 }q|S )zFIntersect two sorted, non-overlapping range lists (two-pointer merge).r   r   )r$   maxminro   append)rr   rs   resultZ
left_indexZright_indexZ
left_lowerZ
left_upperZright_lowerZright_upperrm   rn   r   r   r   _intersect_ranges   s    




rx   r   r=   r   c                 C  s4   g | j dd | j d d R }tj| j|ddS )z5Smallest version in the next prefix: 1.2 -> 1.3.dev0.Nr   r   rD   r.   rF   )r.   r   
from_partsrD   )r=   r.   r   r   r   _next_prefix_dev0  s    "r}   c                 C  s   t j| j| jddS )z7The .dev0 of a version's base release: 1.2 -> 1.2.dev0.r   r{   )r   r|   rD   r.   r=   r   r   r   
_base_dev0  s    r   UnparsedVersionVersion | Nonec                 C  s0   t | ts,zt| } W n ty*   Y d S 0 | S r   )r"   r   r   r~   r   r   r   _coerce_version$  s    
r   c                 C  s   | j d u r| S | jd dS )N)local)r   __replace__r~   r   r   r   _public_version-  s    
r   c                 C  s   | j ddddS )zyThe version that *version* is a post-release of.

    1.0.post1 -> 1.0, 1.0a1.post0 -> 1.0a1, 1.0.post0.dev1 -> 1.0.
    NrE   rF   r   r   r~   r   r   r   
_post_base3  s    r   c                 C  s   | j dddS )zZEarliest pre-release of *version*.

    1.2 -> 1.2.dev0, 1.2.post1 -> 1.2.post1.dev0.
    r   NrF   r   r   r~   r   r   r   _earliest_prerelease;  s    r   r[   )rG   r   c                 C  sr   | du rdS t | trX| j}|jr2|jddddS |jdurF|jd nd}|j|ddS | jsb| S | jddddS )z:Smallest non-pre-release version at or above *v*, or None.N)r'   rF   r   r   r   )rE   r   )r"   r:   r=   is_prereleaser   rE   )rG   innerkr   r   r   _nearest_non_prereleaseC  s    
r   c                   @  s   e Zd ZdZdS )r   a  
    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)r2   r3   r4   r5   r   r   r   r   r   X  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d Zejd+d!dd"d#dd$d Zejd,d%dd&d'dd(d ZdS )-r   r   )_strr%   r   c                 C  s   t | S )z Internal property for match_argsr%   rP   r   r   r   r   h  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   rP   r   r   r   __str__m  s    zBaseSpecifier.__str__rN   c                 C  s   dS )zF
        Returns a hash value for this Specifier-like object.
        Nr   rP   r   r   r   rQ   t  s    zBaseSpecifier.__hash__r   r(   rB   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   rJ   r   r   r   rK   z  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   rP   r   r   r   prereleases  s    zBaseSpecifier.prereleasesr>   rL   r   c                 C  s   dS )zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr   r@   rL   r   r   r   r     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   contains  s    zBaseSpecifier.contains.Iterable[UnparsedVersionVar]Iterator[UnparsedVersionVar]iterabler   keyr   c                 C  s   d S r   r   r@   r   r   r   r   r   r   filter  s    zBaseSpecifier.filterIterable[T]Callable[[T], UnparsedVersion]Iterator[T]c                 C  s   d S r   r   r   r   r   r   r     s    Iterable[Any]'Callable[[Any], UnparsedVersion] | NoneIterator[Any]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     s    )N)N.)N.)NN)r2   r3   r4   rW   Z__match_args__propertyr   abcabstractmethodr   rQ   rK   r   setterr   typingoverloadr   r   r   r   r   r   d  s:         r   )	metaclassc                	   @  s  e Zd ZU d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ded< dwdd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$d%d&Z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d0dd1d2d3Zedd d4d5Zedd d6d7Zdd d8d9Zdd d:d;Zed<d d=d>Zd?d d@dAZd0dBdCdDdEZddFdGdHdIZdddBdJdKdLZ ddMdNdOdPZ!dddBdJdQdRZ"dddBdJdSdTZ#dddBdJdUdVZ$dddBdJdWdXZ%dddBdYdZd[Z&dddBdYd\d]Z'd^ddBdJd_d`Z(dadBdbdcddZ)dxdeddBdfdgdhZ*e+j,dydjdddkdldmdnZ-e+j,dzdoddpdqdldrdnZ-d{dsddtdudldvdnZ-dS )|r   a  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).

    Instances are safe to serialize with :mod:`pickle`. They use a stable
    format so the same pickle can be loaded in future packaging releases.

    .. versionchanged:: 26.2

        Added a stable pickle format. Pickles created with packaging 26.2+ can
        be unpickled with future releases.  Backward compatibility with pickles
        from packaging < 26.2 is supported but may be removed in a future
        release.
    )_prereleases_ranges_spec_spec_version_wildcard_splita  
        (?:
            (?:
                # 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 .*
                    |
                    (?a:                                  # pre release
                        [-_\.]?
                        (alpha|beta|preview|pre|a|b|c|rc)
                        [-_\.]?
                        [0-9]*
                    )?
                    (?a:                                  # post release
                        (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                    )?
                    (?a:[-_\.]?dev[-_\.]?[0-9]*)?         # dev release
                    (?a:\+[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.
                (?:<=|>=|<|>)

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)*   # release
                (?a:                   # pre release
                    [-_\.]?
                    (alpha|beta|preview|pre|a|b|c|rc)
                    [-_\.]?
                    [0-9]*
                )?
                (?a:                                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?
                (?a:[-_\.]?dev[-_\.]?[0-9]*)?          # dev release
            )
        )
        z\s*
compatibleequal	not_equalless_than_equalgreater_than_equal	less_thangreater_than	arbitrary)~===!=<=>=rb   rd   ===r   
_operators Nr%   r   r>   )r    r   r   c                 C  s   | j |std|| }|drL|dd |dd   }}nH|drv|dd |dd   }}n|dd |dd   }}||f| _|| _d| _d| _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: r   Nr   )r   r   r   r   r   r!   r   )
_regex	fullmatchr   strip
startswithr   r   r   r   r   )r@   r    r   operatorr=   r   r   r   rA   =  s    
 
 
zSpecifier.__init__r   ry   c                 C  sD   | j dur"| j d |kr"| j d S t|}|du r6dS ||f| _ |S )zDOne element cache, as only one spec Version is needed per Specifier.Nr   r   )r   r   )r@   r=   Zversion_specifierr   r   r   _get_spec_versionc  s    

zSpecifier._get_spec_versionr   c                 C  s   |  |}|dusJ |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)r   )r@   r=   spec_versionr   r   r   _require_spec_versiono  s    
zSpecifier._require_spec_versionrp   r   c                 C  s\   | j dur| j S | j}| j}|dkr.t| _ tS |drF| ||}n| ||}|| _ |S )zConvert this specifier to sorted, non-overlapping version ranges.

        Each standard operator maps to one or two ranges.  ``===`` is
        modeled as full range (actual check done separately).  Cached.
        Nr   .*)r   r   r=   rl   endswith_wildcard_ranges_standard_ranges)r@   opver_strrw   r   r   r   
_to_rangesy  s    

zSpecifier._to_rangesrq   )r   r   r   c                 C  s\   |  |d d }t|}t|}|dkr@t|dt|dfgS tt|dft|dtfgS )Nr   TF)r   r   r}   rX   rh   _NEG_INF_POS_INF)r@   r   r   baserm   rn   r   r   r   r     s    zSpecifier._wildcard_rangesc           
      C  s  |  |}|dkr"t|dtfgS |dkrBttt|tjdfgS |dkr|jd urx|j	|jd d d}t|dtfgS |j
d ur|j	|j
d dd d}t|dtfgS tt|tjd	tfgS |d
kr|jr|n|j	dd d}|tkrg S tt|d	fgS d|v }t|tj}|r|n|}|dkr>t|dt|dfgS |dkrdtt|d	ft|d	tfgS |dkr|j	|jd d d}	t|dtt|	d	fgS td|d S )Nr   Tr   rd   r   r   r   r   Frb   +r   r   r   rz   )r.   Unknown operator: )r   rX   r   r   rh   r:   r1   r8   rF   r   rE   r9   r   r-   r.   r}   
ValueError)
r@   r   r   rG   Z	lower_verr,   Z	has_localZafter_localsrn   prefixr   r   r   r     sL    





zSpecifier._standard_rangesc                 C  sX   | j d ur| j S | j\}}|dkr&dS |dkr<|dr<dS | |}|d u rRd S |jS )Nr   Fr   r   )r   r   r   r   r   )r@   r   version_strr=   r   r   r   r     s    


zSpecifier.prereleasesr   c                 C  s
   || _ d S r   )r   r   r   r   r   r     s    z#tuple[tuple[str, str], bool | None]c                 C  s   | j | jfS r   )r   r   rP   r   r   r   __getstate__  s    zSpecifier.__getstate__r   stater   c                 C  s   d | _ d | _d | _t|trt|dkrP|\}}t|rPt|rP|| _|| _	d S t|dkrt|d t
r|\}}|d}|dd}t|rt|r|| _|| _	d S t|t
r|d}|dd}t|rt|r|| _|| _	d S td|d S )Nr!   r   r   r   invalidzCannot restore Specifier from )r   r   r   r"   r#   r$   r&   r)   r   r   dictget	TypeError)r@   r   r    r   _	slot_dictr   r   r   __setstate__  s4    



zSpecifier.__setstate__c                 C  s
   | j d S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   r   rP   r   r   r   r   $  s    zSpecifier.operatorc                 C  s
   | j d S )zaThe version of this specifier.

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r   r   rP   r   r   r   r=   -  s    zSpecifier.versionc                 C  s8   | j du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   rb   rR   )>r   r   rT   r2   r%   r@   r'   r   r   r   rV   6  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{}{})formatr   rP   r   r   r   r   H  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   r   r   Zstrip_trailing_zero)r   r   r   r   )r@   r   r=   r   Zcanonical_versionr   r   r   _canonical_specR  s    

zSpecifier._canonical_specrN   c                 C  s
   t | jS r   )rO   r   rP   r   r   r   rQ   `  s    zSpecifier.__hash__r(   rB   c                 C  sR   t |tr6z| t|}W qF ty2   t Y S 0 nt || jsFt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%   rT   r   rI   r   rJ   r   r   r   rK   c  s    
zSpecifier.__eq__CallableOperator)r   r   c                 C  s   t | d| j|  }|S )N	_compare_)getattrr   )r@   r   operator_callabler   r   r   _get_operator  s    zSpecifier._get_operator)prospectiver    r   c                 C  s@   t tttt|d d }|d7 }| ||o>| ||S )Nrz   r   )_version_joinlist	itertools	takewhile_is_not_suffix_version_split_compare_greater_than_equal_compare_equal)r@   r   r    r   r   r   r   _compare_compatible  s    	
zSpecifier._compare_compatibleztuple[list[str], int]r   c                 C  s@   | j }|du r<t|dd dd}t|}|t|f}|| _ |S )zCached split of a wildcard spec into components and numeric length.

        >>> Specifier("==1.*")._get_wildcard_split("1.*")
        (['0', '1'], 2)
        >>> Specifier("==3.10.*")._get_wildcard_split("3.10.*")
        (['0', '3', '10'], 3)
        Nr   Fr   )r   r   r   _numeric_prefix_len)r@   r    Zwildcard_split
normalized
split_specr   r   r   _get_wildcard_split  s    zSpecifier._get_wildcard_splitc           
      C  sv   | drR| |\}}tt|dd}t|}t||}|d t| }||kS | |}	|	jsjt|}||	kS d S )Nr   Fr   )	r   r   r   r   r   	_left_padr$   r   r   )
r@   r   r    r   Zspec_numeric_lenZnormalized_prospectivesplit_prospectivepadded_prospectiveshortened_prospectiver   r   r   r   r     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   r   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   r     s    z%Specifier._compare_greater_than_equal)r   spec_strr   c                 C  s6   |  |}||k sdS |js2|jr2|t|kr2dS dS rj   )r   r   r   r@   r   r  r    r   r   r   _compare_less_than  s    

zSpecifier._compare_less_thanc                 C  sP   |  |}||ksdS |js2|jr2t||kr2dS |jd urLt||krLdS dS rj   )r   is_postreleaser   r   r   r	  r   r   r   _compare_greater_than  s    

zSpecifier._compare_greater_thanzVersion | strc                 C  s   t | t | kS r   r%   rm   r  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")
        True
        >>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True)
        True
        r   r@   r   r   r   r   __contains__  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
        r   )r(   r   r   r   r   r   r   r   .  s    zSpecifier.contains.r   r   r   c                 C  s   d S r   r   r   r   r   r   r   I  s    zSpecifier.filterr   r   r   c                 C  s   d S r   r   r   r   r   r   r   Q  s    r   r   r   c                 c  s  g }d}|dur|n| j }| | j}|D ]}t|du r<|n||}	d}
|	du rr| jdkr| || jr|V  n6| jdkr| |du r|n||| j}
n||	| j}
|
r*|	dur*|	jr|rd}|V  q*|du r*| jdur*|| q*|s|du r| jdu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.
        :param key:
            A callable that takes a single argument (an item from the iterable) and
            returns a version string or :class:`Version` instance to be used for
            filtering.

        >>> 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']
        >>> list(Specifier(">=1.2.3").filter(
        ... [{"ver": "1.2"}, {"ver": "1.3"}],
        ... key=lambda x: x["ver"]))
        [{'ver': '1.3'}]
        FNr   T)	r   r   r   r   r  r=   r   r   rv   )r@   r   r   r   Zprereleases_versionsZfound_non_prereleasesZinclude_prereleasesr   r=   parsed_versionmatchr   r   r   r   Y  s>    #

)r   N)N)N.)N.)NN).r2   r3   r4   r5   rW   Z_specifier_regex_strrecompileVERBOSE
IGNORECASEr   r   __annotations__rA   r   r   r   r   r   r   r   r   r   r   r   r=   rV   r   r   rQ   rK   r   r   r   r   r  r  r   r
  r  r  r  r   r   r   r   r   r   r   r   r     sx   
\&
>"
$     
  r   z([0-9]+)((?:a|b|c|rc)[0-9]+)r   r   r   )r   r   r   c                 c  s   g }g }d}| D ]t}t |du r"|n||}|du rV|r@|V  q|| || q|jsv|sn|E dH  d}|V  q|s|| q|s|E dH  dS )z?Filter per PEP 440: exclude prereleases unless no finals exist.FNT)r   rv   r   )r   r   Zall_nonfinalZarbitrary_stringsZfound_finalr   parsedr   r   r   _pep440_filter_prereleases  s*    


r  r%   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.)
rpartitionrv   split_prefix_regexr   extendgroups)r=   rw   rD   r   restr   r  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&  rD   r%  r   r   r   r     s    r   )segmentr   c                   s   t  fdddD  S )Nc                 3  s   | ]}  |V  qd S r   )r   ).0r   r(  r   r   	<genexpr>  s   z!_is_not_suffix.<locals>.<genexpr>)rF   abrcrE   )anyr*  r   r*  r   r     s    r   rN   )r!  r   c                 C  s&   d}| D ]}|  s q"|d7 }q|S )zCount leading numeric components in a :func:`_version_split` result.

    >>> _numeric_prefix_len(["0", "1", "2", "a1"])
    3
    r   r   )isdigit)r!  countr(  r   r   r   r     s    
r   )r!  target_numeric_lenr   c                 C  sB   t | }|| }|dkr| S g | d| dg| | |d S )zPad a :func:`_version_split` result with ``"0"`` segments to reach
    ``target_numeric_len`` numeric components.  Suffix segments are preserved.

    >>> _left_pad(["0", "1", "a1"], 4)
    ['0', '1', '0', '0', 'a1']
    r   Nr  )r   )r!  r2  Znumeric_lenZ
pad_neededr   r   r   r     s
    r   z!tuple[CallableOperator, str, str])op_entryr   c                 C  st   | \}}}|dkr$| ds dS dS |dv r0dS |dkr<dS |dkrV| dsRd	S d
S |dkrbdS td|dS )aL  Sort key for Cost Based Ordering of specifier operators in _filter_versions.

    Operators run sequentially on a shrinking candidate set, so operators that
    reject the most versions should run first to minimize work for later ones.

    Tier 0: Exact equality (==, ===), likely to narrow candidates to one version
    Tier 1: Range checks (>=, <=, >, <), cheap and usually reject a large portion
    Tier 2: Wildcard equality (==.*) and compatible release (~=), more expensive
    Tier 3: Exact !=, cheap but rarely rejects
    Tier 4: Wildcard !=.*, expensive and rarely rejects
    r   r   r   r!   )r   r   rd   rb   r   r   r   r      r   r   N)r   r   )r3  r   verr   r   r   r   _operator_cost  s    
r6  c                   @  s  e Zd ZdZdZdOddddd	d
Z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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/d0Zd&dd1d2Zd&dd3d4Zd&dd5d6Zd7d&d8d9d:ZdPd7ddd&d;d<d=ZejdQd?ddd@dAdBdCZejdRdDddEdFdAdGdCZdSdHddIdJdAdKdCZdTdHdIddJdLdMdNZdS )Ur   a  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.

    Instances are safe to serialize with :mod:`pickle`. They use a stable
    format so the same pickle can be loaded in future packaging
    releases.

    .. versionchanged:: 26.2

        Added a stable pickle format. Pickles created with
        packaging 26.2+ can be unpickled with future releases.
        Backward compatibility with pickles from
        packaging < 26.2 is supported but may be removed in a future
        release.
    )_canonicalized_has_arbitrary_is_unsatisfiabler   _resolved_ops_specsr   Nzstr | Iterable[Specifier]r   r>   )
specifiersr   r   c                 C  s   t |tr:dd |dD }ttt|| _d|v | _n t|| _tdd | jD | _t	| jdk| _
d| _|| _d| _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   )r   r)  sr   r   r   
<listcomp>k      z)SpecifierSet.__init__.<locals>.<listcomp>,r   c                 s  s   | ]}d t |v V  qdS r   Nr   r=  r   r   r   r+  t  r@  z(SpecifierSet.__init__.<locals>.<genexpr>r   N)r"   r%   r!  r#   mapr   r;  r8  r/  r$   r7  r:  r   r9  )r@   r<  r   split_specifiersr   r   r   rA   R  s    

zSpecifierSet.__init__ztuple[Specifier, ...]r   c                 C  s8   | j s2ttt| jtd| _d| _ d| _d| _| jS )zBDeduplicate, sort, and cache specs for order-sensitive operations.r   TN)	r7  r#   r   fromkeyssortedr;  r%   r:  r9  rP   r   r   r   _canonical_specs  s    zSpecifierSet._canonical_specsc                 C  s6   | j d u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+    r@  z+SpecifierSet.prereleases.<locals>.<genexpr>T)r   r;  r/  rP   r   r   r   r     s    
zSpecifierSet.prereleasesr   c                 C  s   || _ d | _d S r   )r   r9  r   r   r   r   r     s    z)tuple[tuple[Specifier, ...], bool | None]c                 C  s   | j | jfS r   )r;  r   rP   r   r   r   r     s    zSpecifierSet.__getstate__r   r   c                 C  s  d | _ d | _t|tr8t|dkr|\}}t|trtdd |D rt|r|| _|| _t|dk| _	t
dd |D | _d S t|dkr8t|d tr8|\}}|dd}|d}t|trtt|td	}t|tr8td
d |D r8t|r8|| _|| _t| jdk| _	t
dd | jD | _d S t|tr|dd}|d}t|trvtt|td	}t|trtdd |D rt|r|| _|| _t| jdk| _	t
dd | jD | _d S td|d S )Nr!   c                 s  s   | ]}t |tV  qd S r   r"   r   r=  r   r   r   r+    r@  z,SpecifierSet.__setstate__.<locals>.<genexpr>r   c                 s  s   | ]}d t |v V  qdS rB  r   r=  r   r   r   r+    r@  r;  r   r   rE  c                 s  s   | ]}t |tV  qd S r   rI  r=  r   r   r   r+    r@  c                 s  s   | ]}d t |v V  qdS rB  r   r=  r   r   r   r+    r@  c                 s  s   | ]}t |tV  qd S r   rI  r=  r   r   r   r+    r@  c                 s  s   | ]}d t |v V  qdS rB  r   r=  r   r   r   r+    r@  z!Cannot restore SpecifierSet from )r:  r9  r"   r#   r$   allr)   r;  r   r7  r/  r8  r   r   	frozensetrG  r%   r   )r@   r   specsr   r   r   r   r   r   r     sd    


zSpecifierSet.__setstate__r%   c                 C  s8   | j durd| jnd}d| jj 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   r   rb   rR   r   r   r   r   r   r   rV     s
    zSpecifierSet.__repr__c                 C  s   d dd |  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'
        rA  c                 s  s   | ]}t |V  qd S r   r   r=  r   r   r   r+     r@  z'SpecifierSet.__str__.<locals>.<genexpr>)r'  rH  rP   r   r   r   r     s    zSpecifierSet.__str__rN   c                 C  s   t |  S r   )rO   rH  rP   r   r   r   rQ     s    zSpecifierSet.__hash__zSpecifierSet | strrB   c                 C  s   t |trt|}nt |ts"tS t }| j|j |_t|jdk|_| jpP|j|_d|_| j	du sp| j	|j	krz|j	|_	n|j	du 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')>
        r   NzFCannot combine SpecifierSets with True and False prerelease overrides.)r"   r%   r   rI   r;  r$   r7  r8  r:  r   r   )r@   rC   	specifierr   r   r   __and__  s"    






zSpecifierSet.__and__r(   c                 C  s:   t |ttfrtt|}nt |ts*tS |  | 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   rI   rH  rJ   r   r   r   rK   &  s
    
zSpecifierSet.__eq__c                 C  s
   t | jS )z7Returns the number of specifiers in this specifier set.)r$   r;  rP   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;  rP   r   r   r   __iter__D  s    zSpecifierSet.__iter__rp   c                 C  sP   | j }d}|D ],}|du r$| }qt|| }|s q<q|du rLtd|S )a  Intersect all specifiers into a single list of version ranges.

        Returns an empty list when unsatisfiable.  ``===`` specs are
        modeled as full range; string matching is checked separately
        by :meth:`_check_arbitrary_unsatisfiable`.
        Nz _get_ranges called with no specs)r;  r   rx   RuntimeError)r@   rL  rw   r>  r   r   r   _get_rangesN  s    
zSpecifierSet._get_rangesc                 C  sX   | j }|dur|S | js"d| _ dS |   }|s8|  }|sN| jdu rN|  }|| _ |S )a  Check whether this specifier set can never be satisfied.

        Returns True if no version can satisfy all specifiers simultaneously.

        >>> SpecifierSet(">=2.0,<1.0").is_unsatisfiable()
        True
        >>> SpecifierSet(">=1.0,<2.0").is_unsatisfiable()
        False
        >>> SpecifierSet("").is_unsatisfiable()
        False
        >>> SpecifierSet("==1.0,!=1.0").is_unsatisfiable()
        True
        NF)r9  r;  rS  _check_arbitrary_unsatisfiabler   _check_prerelease_only_ranges)r@   cachedrw   r   r   r   is_unsatisfiabled  s    
zSpecifierSet.is_unsatisfiablec                 C  s^   |   D ]P\}}t|j}|du r( dS |jdu s<||jk rB dS ||jkr|jr dS qdS )zWith prereleases=False, check if every range contains only
        pre-release versions (which would be excluded from matching).NFT)rS  r   r=   rZ   )r@   rm   rn   Znearestr   r   r   rU    s    
z*SpecifierSet._check_prerelease_only_rangesc                   s   dd | j D }|sdS |d j tfdd|dd D rHd	S t|d j | jdu rr durr jrrd	S d
d | j D }|sdS  du rd	S t fdd|D  S )a  Check === (arbitrary equality) specs for unsatisfiability.

        === uses case-insensitive string comparison, so the only candidate
        that can match ``===V`` is the literal string V.  This method
        checks whether that candidate is excluded by other specifiers.
        c                 S  s   g | ]}|j d kr|qS r   r   r=  r   r   r   r?    r@  z?SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<listcomp>Fr   c                 3  s   | ]}|j   kV  qd S r   )r=   rm   r=  )firstr   r   r+    r@  z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>r   NTc                 S  s   g | ]}|j d kr|qS rX  rY  r=  r   r   r   r?    r@  c                 3  s   | ]}|  V  qd S r   r  r=  )	candidater   r   r+    r@  )r;  r=   rm   r/  r   r   r   rJ  )r@   r   standardr   )r[  rZ  r   rT    s(    z+SpecifierSet._check_arbitrary_unsatisfiabler   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   r   	installedr   c                 C  sX   t |}|dur|r|jrd}|du s6| jr<t|ts<|}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   r   r8  r"   r   r(   r   r   )r@   r   r   r]  r=   Z
check_itemr   r   r   r     s     zSpecifierSet.contains.r   r   r   c                 C  s   d S r   r   r   r   r   r   r     s    zSpecifierSet.filterr   r   r   c                 C  s   d S r   r   r   r   r   r   r     s    r   r   r   c                   s   |du r| j dur| j }| jrt| jdkrP| jd j||du rDdn| d}n| j| |du rddn|d}|durx|S t| S |du rt|S |du r fdd	|D S t| S )
ac  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.
        :param key:
            A callable that takes a single argument (an item from the iterable) and
            returns a version string or :class:`Version` instance to be used for
            filtering.

        >>> 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']
        >>> list(SpecifierSet(">=1.2.3").filter(
        ... [{"ver": "1.2"}, {"ver": "1.3"}],
        ... key=lambda x: x["ver"]))
        [{'ver': '1.3'}]

        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   T)r   r   r  Fc                 3  s8   | ]0}t  d u r|n | d u s,js|V  qd S r   )r   r   )r)  r   r   r=   r   r   r+  ^  s   z&SpecifierSet.filter.<locals>.<genexpr>)r   r;  r$   r   _filter_versionsr  rP  )r@   r   r   r   filteredr   r^  r   r     s0    2

)r   r   r   r   c                 #  s   | j du r$tdd | jD td| _ | j }|du }|D ]n tdu rH n du rxt fdd|D r V  q6|rjrq6t fdd|D r6 V  q6dS )a?  Filter versions against all specifiers in a single pass.

        Uses Cost Based Ordering: specifiers are sorted by _operator_cost so
        that cheap range operators reject versions early, avoiding expensive
        wildcard or compatible operators on versions that would have been
        rejected anyway.
        Nc                 s  s$   | ]}| |j|j|jfV  qd S r   )r   r   r=   )r)  r    r   r   r   r+  {  s   z0SpecifierSet._filter_versions.<locals>.<genexpr>rE  Fc                 3  s0   | ](\}}}|d ko&t   | kV  qdS rB  r  )r)  r   r5  r   )r   r   r   r+    s   c                 3  sJ   | ]B\}}}|d kr8t du r" n  | kn||V  qdS rB  r  )r)  Zop_fnr5  r   r   r   r  r   r   r+    s   &)r:  rG  r;  r6  r   rJ  r   )r@   r   r   r   opsZexclude_prereleasesr   ra  r   r_  k  s,    

zSpecifierSet._filter_versions)r   N)NN)N.)N.)NN)N)r2   r3   r4   r5   rW   rA   rH  r   r   r   r   r   rV   r   rQ   rN  rK   rO  rQ  rS  rW  rU  rT  r  r   r   r   r   r_  r   r   r   r   r   6  sP     -	9!
!'  -    
  d r   )Lr5   
__future__r   r   r6   	functoolsr   r  sysr   r   r   r   r   r   r   r	   r
   r   utilsr   r=   r   r   version_infor   Ztyping_extensionsr   r   r&   r)   r*   r%   r   r+   r(   r   r-   r  r0   Enumr1   total_orderingr:   rX   rh   r[   r#   Z_VersionRanger   r   rl   ro   rx   r}   r   r   r   r   r   r   r   r   ABCMetar   r   r  r"  r  r   r   r   r   r   r6  r   r   r   r   r   <module>   s   ,
	>((

		R     z
*