o
    j~                    @  s  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rUdd	l	mZ ne
r]dd	lmZ g d
ZdqddZdrddZdsd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< dtd 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,< dud0d1Z4dvd6d7Z5dwd:d;Z6dwd<d=Z7dxd@dAZ8dwdBdCZ9dwdDdEZ:dwdFdGZ;dydJdKZ<G dLdM dMe=Z>G dNdO dOej?dPZ@G dQdR dRe@ZAeBdSZCdzdYdZZDd{d\d]ZEd|d_d`ZFd}dbdcZGd~dfdgZHddidjZIddmdnZJG dodp dpe@ZKdS )z
.. testsetup::

    from pip._vendor.packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
    from pip._vendor.packaging.version import Version
    )annotationsN)	TYPE_CHECKINGAnyCallableFinalIterableIteratorSequenceTypeVarUnion   )canonicalize_version)InvalidVersionVersion)   
   )	TypeGuard)BaseSpecifierInvalidSpecifier	SpecifierSpecifierSetreturn	list[str]c                   C  s   t S N)__all__ r   r   a/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/pip/_vendor/packaging/specifiers.py__dir__0   s   r   specobjectTypeGuard[tuple[str, str]]c                C  s2   t | tot| dkot | d tot | d tS )N   r   r   )
isinstancetuplelenstr)r   r   r   r   _validate_spec4   s   

r&   preTypeGuard[bool | None]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_VERSIONreleasetuple[int, ...]c                 C  s\   t | }|dkr | |d  dkr |d8 }|dkr | |d  dks|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
   r2   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   r3   R   s    r3   c                   @  sP   e Zd ZdZdZdd	d
ZdddZdddZdddZd ddZ	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?   r   kindr3   r   Nonec                 C  s   || _ || _t|j| _d S r   )r?   r=   r2   r/   r>   )selfr?   r@   r   r   r   __init__q   s   z_BoundaryVersion.__init__otherr)   c                 C  sl   | j }|j|jkrt|j| jkr|j|jksdS | jtjkr+|j	|j	ko*|j
|j
kS |j
|j
kp5|j	duS )z6Is ``other`` a version that this boundary sorts above?FN)r?   epochr2   r/   r>   r'   r=   r3   r:   postdev)rB   rD   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rB   rD   r   r   r   __eq__   s   
z_BoundaryVersion.__eq___BoundaryVersion | Versionc                 C  sH   t |tr| j|jkr| j|jk S | jj|jjk S | | o#| j|k S r   )r"   r<   r?   r=   valuerI   rK   r   r   r   __lt__   s
   
z_BoundaryVersion.__lt__intc                 C     t | j| jfS r   )hashr?   r=   rB   r   r   r   __hash__      z_BoundaryVersion.__hash__r%   c                 C  s    | j j d| jd| jj dS )N(z, ))	__class__r4   r?   r=   namerS   r   r   r   __repr__   s    z_BoundaryVersion.__repr__N)r?   r   r@   r3   r   rA   )rD   r   r   r)   rD   r   r   r)   )rD   rM   r   r)   r   rP   r   r%   )r4   r5   r6   r7   	__slots__rC   rI   rL   rO   rT   rZ   r   r   r   r   r<   Y   s    




r<   c                   @  F   e Zd ZdZdZdd	d
ZdddZdddZdddZ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?   r?   _VersionOrBoundaryrb   r)   r   rA   c                 C     || _ || _d S r   r?   rb   rB   r?   rb   r   r   r   rC         
z_LowerBound.__init__rD   r   c                 C  &   t |tstS | j|jko| j|jkS r   r"   r`   rJ   r?   rb   rK   r   r   r   rL         
z_LowerBound.__eq__c                 C  sV   t |tstS | jd u r|jd uS |jd u rdS | j|jkr$| j|jk S | jo*|j S )NFri   rK   r   r   r   rO      s   



z_LowerBound.__lt__rP   c                 C  rQ   r   rR   r?   rb   rS   r   r   r   rT      rU   z_LowerBound.__hash__r%   c                 C  s*   | j rdnd}d| jj d| | jdS )N[rV   < >rb   rX   r4   r?   rB   Zbracketr   r   r   rZ         z_LowerBound.__repr__Nr?   rc   rb   r)   r   rA   r[   )rD   r`   r   r)   r\   r]   
r4   r5   r6   r7   r^   rC   rL   rO   rT   rZ   r   r   r   r   r`          



r`   c                   @  r_   )_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.
    ra   r?   rc   rb   r)   r   rA   c                 C  rd   r   re   rf   r   r   r   rC      rg   z_UpperBound.__init__rD   r   c                 C  rh   r   r"   rv   rJ   r?   rb   rK   r   r   r   rL      rj   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r!| j|jk S | j o'|jS NFTrw   rK   r   r   r   rO      s   


z_UpperBound.__lt__rP   c                 C  rQ   r   rk   rS   r   r   r   rT      rU   z_UpperBound.__hash__r%   c                 C  s*   | j rdnd}d| jj d| j| dS )N]rW   rm   rn   ro   rp   rq   r   r   r   rZ      rr   z_UpperBound.__repr__Nrs   r[   )rD   rv   r   r)   r\   r]   rt   r   r   r   r   rv      ru   rv   Fztuple[_VersionRange]_FULL_RANGElowerupperr)   c                 C  s>   | j du s
|j du rdS | j |j kr| jo|j S | j |j kS )zHTrue when the range defined by *lower* and *upper* contains no versions.NFre   )r{   r|   r   r   r   _range_is_empty   s
   r}   leftSequence[_VersionRange]rightlist[_VersionRange]c                 C  s   g }d }}|t | k rM|t |k rM| | \}}|| \}}t||}	t||}
t|	|
s4||	|
f ||k r=|d7 }n|d7 }|t | k rM|t |k s|S )zFIntersect two sorted, non-overlapping range lists (two-pointer merge).r   r   )r$   maxminr}   append)r~   r   resultZ
left_indexZright_indexZ
left_lowerZ
left_upperZright_lowerZright_upperr{   r|   r   r   r   _intersect_ranges   s   



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   rE   r/   rG   )r/   r   
from_partsrE   )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   rE   r/   r?   r   r   r   
_base_dev0  s   r   UnparsedVersionVersion | Nonec                 C  s2   t | tszt| } W | S  ty   Y d S w | 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rF   rG   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rG   r   r   r   r   r   r   _earliest_prerelease;  s   r   rH   rc   c                 C  sr   | du rdS t | tr,| j}|jr|jddddS |jdur#|jd nd}|j|ddS | js1| S | jddddS )z:Smallest non-pre-release version at or above *v*, or None.N)r'   rG   r   r   r   )rF   r   )r"   r<   r?   is_prereleaser   rF   )rH   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)r4   r5   r6   r7   r   r   r   r   r   X  s    r   c                   @  s   e Zd ZdZdZed+ddZejd+ddZ	ejd,d
dZ
ejd-ddZeejd.ddZejd/ddZejd0d1ddZej		d2d3d!d"Zej		d2d4d&d"Zej		d5d6d*d"ZdS )7r   r   )_strr   r%   c                 C  s   t | S )z Internal property for match_argsr%   rS   r   r   r   r   h  s   zBaseSpecifier._strc                 C     dS )z
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr   rS   r   r   r   __str__m      zBaseSpecifier.__str__rP   c                 C  r   )zF
        Returns a hash value for this Specifier-like object.
        Nr   rS   r   r   r   rT   t  r   zBaseSpecifier.__hash__rD   r   r)   c                 C  r   )z
        Returns a boolean representing whether or not the two Specifier-like
        objects are equal.

        :param other: The other object to check against.
        Nr   rK   r   r   r   rL   z  r   zBaseSpecifier.__eq__bool | Nonec                 C  r   )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   rS   r   r   r   prereleases  r   zBaseSpecifier.prereleasesrN   rA   c                 C  r   )zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr   rB   rN   r   r   r   r     r   Nitemr   c                 C  r   )zR
        Determines if the given item is contained within this specifier.
        Nr   rB   r   r   r   r   r   contains  r   zBaseSpecifier.contains.iterableIterable[UnparsedVersionVar]keyIterator[UnparsedVersionVar]c                 C     d S r   r   rB   r   r   r   r   r   r   filter     zBaseSpecifier.filterIterable[T]Callable[[T], UnparsedVersion]Iterator[T]c                 C  r   r   r   r   r   r   r   r     r   Iterable[Any]'Callable[[Any], UnparsedVersion] | NoneIterator[Any]c                 C  r   )z
        Takes an iterable of items and filters them so that only items which
        are contained within this specifier are allowed in it.
        Nr   r   r   r   r   r     r   r]   r\   r[   r   r   )rN   r)   r   rA   r   )r   r%   r   r   r   r)   N.r   r   r   r   r   rA   r   r   r   r   r   r   r   r   r   r   NNr   r   r   r   r   r   r   r   )r4   r5   r6   r^   __match_args__propertyr   abcabstractmethodr   rT   rL   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< dwdxddZdyddZdzdd Zd{d"d#Zd|d'd(Zd|d)d*Zed}d+d,Zejd~d.d,Zdd0d1Zdd4d5Zedd6d7Zedd8d9Zdd:d;Zdd<d=Zedd?d@ZddBdCZddFdGZddIdJZddLdMZ ddOdPZ!ddQdRZ"ddSdTZ#ddUdVZ$ddWdXZ%ddZd[Z&dd\d]Z'dd_d`Z(ddcddZ)dddfdgZ*e+j,		hdddmdnZ-e+j,		hdddrdnZ-		dddvdn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 pip._vendor.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)~===!=<=>=rm   ro   ===r   
_operators Nr   r%   r   r   r   rA   c                 C  s   | j |std|| }|dr&|dd |dd  }}n$|dr;|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   )rB   r   r   operatorr?   r   r   r   rC   =  s   
 
 

zSpecifier.__init__r?   r   c                 C  sD   | j dur| j d |kr| j d S t|}|du rdS ||f| _ |S )zDOne element cache, as only one spec Version is needed per Specifier.Nr   r   )r   r   )rB   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   )rB   r?   spec_versionr   r   r   _require_spec_versiono  s   
zSpecifier._require_spec_versionr   c                 C  s\   | j dur| j S | j}| j}|dkrt| _ tS |dr#| ||}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?   rz   endswith_wildcard_ranges_standard_ranges)rB   opver_strr   r   r   r   
_to_rangesy  s   

zSpecifier._to_rangesr   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   r`   rv   _NEG_INF_POS_INF)rB   r   r   baser{   r|   r   r   r   r     s   zSpecifier._wildcard_rangesc           
      C  s  |  |}|dkrt|dtfgS |dkr!ttt|tjdfgS |dkr`|jd ur<|j	|jd d d}t|dtfgS |j
d urT|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ri|n|j	dd d}|tkrvg S tt|d	fgS d|v }t|tj}|r|n|}|dkrt|dt|dfgS |dkrt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|)Nr   Tr   ro   r   r   r   r   Frm   +r   r   r   r   )r/   Unknown operator: )r   r`   r   r   rv   r<   r3   r:   rG   r   rF   r;   r   r.   r/   r   
ValueError)
rB   r   r   rH   Z	lower_verr-   Z	has_localZafter_localsr|   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 r)d S |jS )Nr   Fr   r   )r   r   r   r   r   )rB   r   version_strr?   r   r   r   r     s   


zSpecifier.prereleasesrN   c                 C  s
   || _ d S r   )r   r   r   r   r   r        
#tuple[tuple[str, str], bool | None]c                 C     | j | jfS r   )r   r   rS   r   r   r   __getstate__     zSpecifier.__getstate__stater   c                 C  s   d | _ d | _d | _t|trTt|dkr(|\}}t|r(t|r(|| _|| _	d S t|dkrTt|d t
rT|\}}|d}|dd}t|rTt|rT|| _|| _	d S t|t
rt|d}|dd}t|rtt|rt|| _|| _	d S td|)Nr!   r   r   r   invalidzCannot restore Specifier from )r   r   r   r"   r#   r$   r&   r*   r   r   dictget	TypeError)rB   r   r   r   _	slot_dictr   r   r   __setstate__  s4   



zSpecifier.__setstate__c                 C  
   | j d S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   r   rS   r   r   r   r   $     
zSpecifier.operatorc                 C  r   )zaThe version of this specifier.

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r   r   rS   r   r   r   r?   -  r   zSpecifier.versionc                 C  8   | 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   rm   rV   )>r   r   rX   r4   r%   rB   r'   r   r   r   rZ   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   rS   r   r   r   r   H  s   zSpecifier.__str__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   )rB   r   r?   r   Zcanonical_versionr   r   r   _canonical_specR  s   

zSpecifier._canonical_specrP   c                 C  
   t | jS r   )rR   r  rS   r   r   r   rT   `  s   
zSpecifier.__hash__rD   r)   c                 C  sP   t |trz	| t|}W n ty   t Y S w t || js"t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%   rX   r   rJ   r  rK   r   r   r   rL   c  s   
zSpecifier.__eq__CallableOperatorc                 C  s   t | d| j|  }|S )N	_compare_)getattrr   )rB   r   operator_callabler   r   r   _get_operator  s   zSpecifier._get_operatorprospectivec                 C  s@   t tttt|d d }|d7 }| ||o| ||S )Nr   r   )_version_joinlist	itertools	takewhile_is_not_suffix_version_split_compare_greater_than_equal_compare_equal)rB   r  r   r   r   r   r   _compare_compatible  s   	
zSpecifier._compare_compatibletuple[list[str], int]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)rB   r   Zwildcard_split
normalized
split_specr   r   r   _get_wildcard_split  s   zSpecifier._get_wildcard_splitc           
      C  sr   | dr)| |\}}tt|dd}t|}t||}|d t| }||kS | |}	|	js5t|}||	kS )Nr   Fr  )	r   r  r   r   r  	_left_padr$   r   r   )
rB   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  rB   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     z"Specifier._compare_less_than_equalc                 C  s   t || |kS r   r$  r"  r   r   r   r    r&  z%Specifier._compare_greater_than_equalspec_strc                 C  s6   |  |}||k sdS |js|jr|t|krdS dS rx   )r   r   r   rB   r  r'  r   r   r   r   _compare_less_than  s   
zSpecifier._compare_less_thanc                 C  sP   |  |}||ksdS |js|jrt||krdS |jd ur&t||kr&dS dS rx   )r   is_postreleaser   r   r   r(  r   r   r   _compare_greater_than  s   
zSpecifier._compare_greater_thanVersion | strc                 C  s   t | t | kS r   r%   r{   r"  r   r   r   _compare_arbitrary  s   zSpecifier._compare_arbitraryr   str | Versionc                 C  
   |  |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   rB   r   r   r   r   __contains__     
zSpecifier.__contains__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   r   c                 C  r   r   r   r   r   r   r   r   I  r   zSpecifier.filterr   r   r   c                 C  r   r   r   r   r   r   r   r   Q  r   r   r   r   c                 c  s   g }d}|dur|n| j }| | j}|D ]^}t|du r|n||}	d}
|	du r:| jdkr9| || jr9|V  n| jdkrO| |du rG|n||| j}
n||	| j}
|
rt|	durt|	jr`|rfd}|V  q|du rt| jdurt|| q|s|du r| jdur|E dH  dS dS dS 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   r   )rB   r   r   r   Zprereleases_versionsZfound_non_prereleasesZinclude_prereleasesr  r?   parsed_versionmatchr   r   r   r   Y  sF   #



r   N)r   r%   r   r   r   rA   )r?   r%   r   r   )r?   r%   r   r   r   r   )r   r%   r   r%   r   r   r   rN   r   r   rA   )r   r   r   r   r   rA   r]   )r   r  r\   r[   )r   r%   r   r
  )r  r   r   r%   r   r)   )r   r%   r   r  )r  r   r'  r%   r   r)   )r  r,  r   r%   r   r)   )r   r/  r   r)   r   )r   r   r   r   r   r)   r   r   r   r   r   ).r4   r5   r6   r7   r^   Z_specifier_regex_strrecompileVERBOSE
IGNORECASEr   r   __annotations__rC   r   r   r   r   r   r   r   r   r   r   r   r?   rZ   r   r  rT   rL   r  r  r  r  r#  r%  r  r)  r+  r.  r3  r   r   r   r   r   r   r   r   r     sz   
 \
&




>

"









$




 

r   z([0-9]+)((?:a|b|c|rc)[0-9]+)r   r   r   r   r   c                 c  s    g }g }d}| D ]:}t |du r|n||}|du r,|r!|V  n
|| || q	|js<|s8|E dH  d}|V  q	|sC|| q	|sM|E dH  dS dS )z?Filter per PEP 440: exclude prereleases unless no finals exist.FNT)r   r   r   )r   r   Zall_nonfinalZarbitrary_stringsZfound_finalr   parsedr   r   r   _pep440_filter_prereleases  s0   



rB  r%   c                 C  s^   g }|  d\}}}||pd |dD ]}t|}|r'||  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_regexr   extendgroups)r?   r   rE   r   restr   r7  r   r   r   r    s   
r  
componentsc                 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.
    rC  rE  )join)rL  rE   rK  r   r   r   r    s   r  segmentc                   s   t  fdddD  S )Nc                 3  s    | ]}  |V  qd S r   )r   ).0r   rN  r   r   	<genexpr>  s    

z!_is_not_suffix.<locals>.<genexpr>)rG   abrcrF   )anyrP  r   rP  r   r    s   
r  rG  rP   c                 C  s(   d}| D ]}|  s |S |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)rG  countrN  r   r   r   r    s   
r  target_numeric_lenc                 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   NrD  )r  )rG  rX  Znumeric_lenZ
pad_neededr   r   r   r    s
   &r  op_entry!tuple[CallableOperator, str, str]c                 C  sp   | \}}}|dkr| dsdS dS |dv rdS |dkrdS |dkr+| ds)d	S d
S |dkr1dS td|)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   ro   rm   r   r   r   r      r   r   )r   r   )rY  r   verr   r   r   r   _operator_cost  s   
r]  c                   @  s2  e Zd ZdZdZ		dPdQddZdRddZedSddZej	dTddZdUddZ
dVddZdWddZdWddZdXd!d"ZdYd%d&ZdZd(d)ZdXd*d+Zd[d-d.Zd\d0d1Zd]d2d3Zd]d4d5Zd]d6d7Zd^d:d;Z		d_d`d=d>Zej		?dadbdDdEZej		?dadcdIdEZ		d_dddMdEZ	dedfdNdOZdS )gr   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   N
specifiersstr | Iterable[Specifier]r   r   r   rA   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   rO  sr   r   r   
<listcomp>k  s    z)SpecifierSet.__init__.<locals>.<listcomp>,r   c                 s      | ]	}d t |v V  qdS r   Nr   re  r   r   r   rQ  t      z(SpecifierSet.__init__.<locals>.<genexpr>r   N)r"   r%   rG  r#   mapr   rb  r_  rU  r$   r^  ra  r   r`  )rB   rc  r   split_specifiersr   r   r   rC   R  s   


zSpecifierSet.__init__tuple[Specifier, ...]c                 C  s8   | j sttt| jtd| _d| _ d| _d| _| jS )zBDeduplicate, sort, and cache specs for order-sensitive operations.r   TN)	r^  r#   r   fromkeyssortedrb  r%   ra  r`  rS   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 rdS d S )Nc                 s  s    | ]}|j V  qd S r   r5  re  r   r   r   rQ    s    z+SpecifierSet.prereleases.<locals>.<genexpr>T)r   rb  rU  rS   r   r   r   r     s   
zSpecifierSet.prereleasesrN   c                 C  s   || _ d | _d S r   )r   r`  r   r   r   r   r     s   
)tuple[tuple[Specifier, ...], bool | None]c                 C  r   r   )rb  r   rS   r   r   r   r     r   zSpecifierSet.__getstate__r   r   c                 C  s  d | _ d | _t|trt|dkr@|\}}t|tr@tdd |D r@t|r@|| _|| _t|dk| _	t
dd |D | _d S t|dkrt|d tr|\}}|dd}|d}t|tritt|td	}t|trtd
d |D rt|r|| _|| _t| jdk| _	t
dd | jD | _d S t|tr|dd}|d}t|trtt|td	}t|trtdd |D rt|r|| _|| _t| jdk| _	t
dd | jD | _d S td|)Nr!   c                 s      | ]}t |tV  qd S r   r"   r   re  r   r   r   rQ        z,SpecifierSet.__setstate__.<locals>.<genexpr>r   c                 s  ri  rj  r   re  r   r   r   rQ    rk  rb  r   r   ro  c                 s  rt  r   ru  re  r   r   r   rQ    rv  c                 s  ri  rj  r   re  r   r   r   rQ    rk  c                 s  rt  r   ru  re  r   r   r   rQ    rv  c                 s  ri  rj  r   re  r   r   r   rQ    rk  z!Cannot restore SpecifierSet from )ra  r`  r"   r#   r$   allr*   rb  r   r^  rU  r_  r   r   	frozensetrq  r%   r   )rB   r   specsr   r   r   r   r   r   r     sd   





zSpecifierSet.__setstate__r%   c                 C  r   )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   rm   rV   r  r  r  r   r   r   rZ     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'
        rh  c                 s  s    | ]}t |V  qd S r   r   re  r   r   r   rQ     s    z'SpecifierSet.__str__.<locals>.<genexpr>)rM  rr  rS   r   r   r   r     s   zSpecifierSet.__str__rP   c                 C  s   t |  S r   )rR   rr  rS   r   r   r   rT     s   zSpecifierSet.__hash__rD   SpecifierSet | strc                 C  s   t |tr
t|}nt |tstS t }| j|j |_t|jdk|_| jp(|j|_d|_| j	du s8| j	|j	kr>|j	|_	|S |j	du rI| j	|_	|S t
d)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   rJ   rb  r$   r^  r_  ra  r   r   )rB   rD   	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   rJ   rr  rK   r   r   r   rL   &  s
   
zSpecifierSet.__eq__c                 C  r	  )z7Returns the number of specifiers in this specifier set.)r$   rb  rS   r   r   r   __len__@  r   zSpecifierSet.__len__Iterator[Specifier]c                 C  r	  )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')>]
        )iterrb  rS   r   r   r   __iter__D  s   
zSpecifierSet.__iter__r   c                 C  sP   | j }d}|D ]}|du r| }qt|| }|s nq|du r&t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)rb  r   r   RuntimeError)rB   ry  r   rf  r   r   r   _get_rangesN  s   
zSpecifierSet._get_rangesc                 C  sX   | j }|dur	|S | jsd| _ dS |   }|s|  }|s'| jdu r'|  }|| _ |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)r`  rb  r  _check_arbitrary_unsatisfiabler   _check_prerelease_only_ranges)rB   cachedr   r   r   r   is_unsatisfiabled  s   
zSpecifierSet.is_unsatisfiablec                 C  s^   |   D ](\}}t|j}|du r dS |jdu s||jk r! 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)r  r   r?   rb   )rB   r{   r|   Znearestr   r   r   r    s   
z*SpecifierSet._check_prerelease_only_rangesc                   s   dd | j D }|sdS |d j tfdd|dd D r$d	S t|d j | jdu r9 dur9 jr9d	S d
d | j D }|sEdS  du rKd	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   re  r   r   r   rg        z?SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<listcomp>Fr   c                 3  s    | ]
}|j   kV  qd S r   )r?   r{   re  )firstr   r   rQ    s    z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>r   NTc                 S  s   g | ]	}|j d kr|qS r  r  re  r   r   r   rg    r  c                 3  s    | ]}|  V  qd S r   r1  re  )	candidater   r   rQ    rv  )rb  r?   r{   rU  r   r   r   rw  )rB   r   standardr   )r  r  r   r    s$   
z+SpecifierSet._check_arbitrary_unsatisfiabler   r   c                 C  r0  )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
        r1  r2  r   r   r   r3    r4  zSpecifierSet.__contains__	installedc                 C  sX   t |}|dur|r|jrd}|du s| 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
        NTr5  )r   r   r_  r"   r   r)   r  r   )rB   r   r   r  r?   Z
check_itemr   r   r   r     s    zSpecifierSet.contains.r   r   r   r   c                 C  r   r   r   r   r   r   r   r     r   zSpecifierSet.filterr   r   r   c                 C  r   r   r   r   r   r   r   r     r   r   r   r   c                   s   |du r| j dur| j }| jrAt| jdkr(| jd j||du r"dn| d}n| j| |du r2dn|d}|dur<|S t| S |du rIt|S |du rW 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   r5  Fc                 3  s:    | ]}t  d u r|n | d u sjs|V  qd S r   )r   r   )rO  r   r   r?   r   r   rQ  ^  s    z&SpecifierSet.filter.<locals>.<genexpr>)r   rb  r$   r   _filter_versionsrB  r  )rB   r   r   r   filteredr   r  r   r     s0   2


c                 #  s    | j du rtdd | jD td| _ | j }|du }|D ]7 tdu r% n du r=t fdd|D r< V  q|rCjrCqt fdd|D rS V  qd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?   )rO  r   r   r   r   rQ  {  s
    
z0SpecifierSet._filter_versions.<locals>.<genexpr>ro  Fc                 3  s2    | ]\}}}|d kot   | kV  qdS rj  r-  )rO  r   r\  r   )r   r   r   rQ    s
    
c                 3  sL    | ]!\}}}|d krt du r n  | kn||V  qdS rj  r-  )rO  Zop_fnr\  r   r   r   rA  r   r   rQ    s    $
)ra  rq  rb  r]  r   rw  r   )rB   r   r   r   opsZexclude_prereleasesr   r  r   r  k  s4   

zSpecifierSet._filter_versionsr8  )rc  rd  r   r   r   rA   )r   rn  r   r:  )r   rs  r;  r]   r\   )rD   rz  r   r   r[   )r   r~  r9  )r   r)   )r   r   r   r)   r   )r   r   r   r   r  r   r   r)   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r4   r5   r6   r7   r^   rC   rr  r   r   r   r   r   rZ   r   rT   r|  rL   r}  r  r  r  r  r  r3  r   r   r   r   r  r   r   r   r   r   6  sR    
-	


9



!





!

'-
dr   )r   r   )r   r   r   r    )r'   r   r   r(   )r/   r0   r   r0   )r{   r`   r|   rv   r   r)   )r~   r   r   r   r   r   )r?   r   r   r   )r?   r   r   r   )rH   rc   r   r   )r   r   r   r   r   r   )r?   r%   r   r   )rL  r   r   r%   )rN  r%   r   r)   )rG  r   r   rP   )rG  r   rX  rP   r   r   )rY  rZ  r   rP   )Lr7   
__future__r   r   r8   	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@  r2   Enumr3   total_orderingr<   r`   rv   rc   r#   Z_VersionRanger   r   rz   r}   r   r   r   r   r   r   r   r   r   r   ABCMetar   r   r=  rH  rB  r  r  r  r  r  r]  r   r   r   r   r   <module>   s   ,



	
>((



	



	


R     
z

*




