
    iZ                      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    rdd	l	mZ ne
rdd	lmZ g d
Zd]dZd^dZd_dZ ed          Zeee f         Z! ede!          Z"eee ge#f         Z$ ed          Z%de&d<   d`dZ' G d dej(                  Z)ej*         G d  d!                      Z+ej*         G d" d#                      Z,ej*         G d$ d%                      Z-e	j
        reee+df         Z.e/e,e-f         Z0 e,dd&          Z1 e-dd&          Z2e1e2ffZ3d'e&d(<   dad,Z4dbd1Z5dcd4Z6dcd5Z7ddd8Z8dcd9Z9dcd:Z:dcd;Z;ded>Z< G d? d@e=          Z> G dA dBej?        C          Z@ G dD dEe@          ZA ejB        dF          ZCdfdLZDdgdNZEdhdPZFdidRZGdjdUZHdkdWZIdldZZJ G d[ d\e@          ZKdS )mz
.. 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SpecifierSetreturn	list[str]c                     t           S N)__all__     [/home/ubuntu/.hermes/hermes-agent/venv/lib/python3.11/site-packages/packaging/specifiers.py__dir__r    0   s    Nr   specobjectTypeGuard[tuple[str, str]]c                   t          | t                    oHt          |           dk    o5t          | d         t                    ot          | d         t                    S )N   r   r   )
isinstancetuplelenstr)r!   s    r   _validate_specr*   4   sT    4 	%IIN	%tAw$$	% tAw$$	r   preTypeGuard[bool | None]c               4    | d u pt          | t                    S r   )r&   bool)r+   s    r   _validate_prer/   =   s    $;/*S$///r   TUnparsedVersionVar)boundz0.dev0zFinal[Version]_MIN_VERSIONreleasetuple[int, ...]c                    t          |           }|dk    r)| |dz
           dk    r|dz  }|dk    r| |dz
           dk    |t          |           k    r| n	| d|         S )zDStrip trailing zeros from a release tuple for normalized comparison.r   r   N)r(   )r4   ends     r   _trim_releaser8   J   sr    
g,,C
''gcAg&!++q ''gcAg&!++S\\))77wtt}<r   c                  N    e Zd ZdZ ej                    Z ej                    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:   r:   R   s.        ??49;;L$)++KKKr   r:   c                  F    e Zd ZdZdZdd	ZddZddZddZddZ	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versionrG   r   kindr:   r   Nonec                T    || _         || _        t          |j                  | _        d S r   )rG   rE   r8   r4   rF   )selfrG   rH   s      r   __init__z_BoundaryVersion.__init__q   s(    
 -go > >r   otherr.   c                *   | 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    p|j	        duS )z6Is ``other`` a version that this boundary sorts above?FN)rG   epochr8   r4   rF   r+   rE   r:   rA   postdev)rK   rM   vs      r   
_is_familyz_BoundaryVersion._is_familyv   s    LK17""em,,0EEE	QU""5:333:'>EI,>>yAE!;UZt%;;r   r"   c                z    t          |t                    r | j        |j        k    o| j        |j        k    S t          S r   )r&   rD   rG   rE   NotImplementedrK   rM   s     r   __eq__z_BoundaryVersion.__eq__   s9    e-.. 	O<5=0NTZ5;5NNr   _BoundaryVersion | Versionc                    t          |t                    r:| j        |j        k    r| j        |j        k     S | j        j        |j        j        k     S |                     |           o
| j        |k     S r   )r&   rD   rG   rE   valuerS   rV   s     r   __lt__z_BoundaryVersion.__lt__   si    e-.. 	8|u},,|em33:#ek&777??5)))BdlU.BBr   intc                8    t          | j        | j        f          S r   )hashrG   rE   rK   s    r   __hash__z_BoundaryVersion.__hash__   s    T\4:.///r   r)   c                J    | j         j         d| j        d| j        j         dS )N(z, ))	__class__r;   rG   rE   namer_   s    r   __repr__z_BoundaryVersion.__repr__   s,    .)PPDLPPdjoPPPPr   N)rG   r   rH   r:   r   rI   )rM   r   r   r.   rM   r"   r   r.   )rM   rX   r   r.   r   r\   r   r)   )r;   r<   r=   r>   	__slots__rL   rS   rW   r[   r`   rf   r   r   r   rD   rD   Y   s         ( 9I? ? ? ?
< < < <   
C C C C0 0 0 0Q Q Q Q Q Qr   rD   c                  >    e Zd ZdZdZdd	ZddZddZddZ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.
    	inclusiverG   rG   _VersionOrBoundaryrn   r.   r   rI   c                "    || _         || _        d S r   rG   rn   rK   rG   rn   s      r   rL   z_LowerBound.__init__       "r   rM   r"   c                z    t          |t                    st          S | j        |j        k    o| j        |j        k    S r   r&   rl   rU   rG   rn   rV   s     r   rW   z_LowerBound.__eq__   7    %-- 	"!!|u},R5?1RRr   c                    t          |t                    st          S | j        	|j        d uS |j        dS | j        |j        k    r| j        |j        k     S | j        o|j         S )NFru   rV   s     r   r[   z_LowerBound.__lt__   sl    %-- 	"!!<=,,= 5<5=((<%-//~5eo"55r   r\   c                8    t          | j        | j        f          S r   r^   rG   rn   r_   s    r   r`   z_LowerBound.__hash__       T\4>2333r   r)   c                L    | j         rdnd}d| j        j         d| | j        dS )N[rb   < >rn   rd   r;   rG   rK   brackets     r   rf   z_LowerBound.__repr__   s7    0##SG4>*GGWGdlGGGGr   NrG   ro   rn   r.   r   rI   rg   )rM   rl   r   r.   rh   ri   
r;   r<   r=   r>   rj   rL   rW   r[   r`   rf   r   r   r   rl   rl                )I# # # #S S S S
6 6 6 64 4 4 4H H H H H Hr   rl   c                  >    e Zd ZdZdZdd	ZddZddZddZ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.
    rm   rG   ro   rn   r.   r   rI   c                "    || _         || _        d S r   rq   rr   s      r   rL   z_UpperBound.__init__   rs   r   rM   r"   c                z    t          |t                    st          S | j        |j        k    o| j        |j        k    S r   r&   r   rU   rG   rn   rV   s     r   rW   z_UpperBound.__eq__   rv   r   c                    t          |t                    st          S | j        dS |j        dS | j        |j        k    r| j        |j        k     S | j         o|j        S NFTr   rV   s     r   r[   z_UpperBound.__lt__   sd    %-- 	"!!<5= 4<5=((<%-//>!5eo5r   r\   c                8    t          | j        | j        f          S r   ry   r_   s    r   r`   z_UpperBound.__hash__   rz   r   r)   c                L    | j         rdnd}d| j        j         d| j        | dS )N]rc   r}   r~   r   r   r   s     r   rf   z_UpperBound.__repr__   s7    0##SG4>*GGT\GWGGGGr   Nr   rg   )rM   r   r   r.   rh   ri   r   r   r   r   r   r      r   r   r   Fztuple[_VersionRange]_FULL_RANGElowerupperr.   c                    | j         |j         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.NFrq   )r   r   s     r   _range_is_emptyr      sF    } 5u}%%O788=5=((r   leftSequence[_VersionRange]rightlist[_VersionRange]c                   g }dx}}|t          |           k     r|t          |          k     r| |         \  }}||         \  }}t          ||          }	t          ||          }
t          |	|
          s|                    |	|
f           ||k     r|dz  }n|dz  }|t          |           k     r|t          |          k     |S )zFIntersect two sorted, non-overlapping range lists (two-pointer merge).r   r   )r(   maxminr   append)r   r   result
left_indexright_index
left_lower
left_upperright_lowerright_upperr   r   s              r   _intersect_rangesr      s    
 #%F  J
s4yy
 
 [3u::%=%=!%j!1
J#(#5 [J,,J,,ue,, 	*MM5%.))) ##!OJJ1K s4yy
 
 [3u::%=%=  Mr   rG   r   c                ~    g | j         dd         | j         d         dz   R }t          j        | j        |d          S )z5Smallest version in the next prefix: 1.2 -> 1.3.dev0.Nr   r   rO   r4   rQ   )r4   r   
from_partsrO   )rG   r4   s     r   _next_prefix_dev0r     sE    >$>gob&9A&=>>GGM7JJJJr   c                D    t          j        | j        | j        d          S )z7The .dev0 of a version's base release: 1.2 -> 1.2.dev0.r   r   )r   r   rO   r4   rG   s    r   
_base_dev0r     s    GM7?PQRRRRr   UnparsedVersionVersion | Nonec                t    t          | t                    s"	 t          |           } n# t          $ r Y d S w xY w| S r   )r&   r   r   r   s    r   _coerce_versionr   $  sO    gw'' 	g&&GG 	 	 	44	Ns   ' 
55c                @    | j         | S |                     d           S )N)local)r   __replace__r   s    r   _public_versionr   -  s&    }T***r   c                2    |                      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rP   rQ   r   r   r   s    r   
_post_baser   3  s    
 Dd$???r   c                0    |                      dd          S )zZEarliest pre-release of *version*.

    1.2 -> 1.2.dev0, 1.2.post1 -> 1.2.post1.dev0.
    r   NrQ   r   r   r   s    r   _earliest_prereleaser   ;  s    
 1D111r   rR   ro   c                   | dS t          | t                    rP| j        }|j        r|                    ddd          S |j        
|j        dz   nd}|                    |d          S | j        s| S |                     ddd          S )z:Smallest non-pre-release version at or above *v*, or None.N)r+   rQ   r   r   r   )rP   r   )r&   rD   rG   is_prereleaser   rP   )rR   innerks      r   _nearest_non_prereleaser   C  s     	yt!%&& 5	 	E$$4t$DDD !&
 6UZ!^^A  at 444? ==Tt4=888r   c                      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)r;   r<   r=   r>   r   r   r   r   r   X  s           r   r   c                     e Zd ZdZdZed$d            Zej        d$d            Z	ej        d%d            Z
ej        d&d            Zeej        d'd                        Zej        d(d            Zej        d)d*d            Zej        	 	 d+d,d            Zej        	 	 d+d-d            Zej        	 	 d.d/d#            ZdS )0r   r   )_strr   r)   c                     t          |           S )z Internal property for match_argsr)   r_   s    r   r   zBaseSpecifier._strh  s     4yyr   c                    dS )z
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr   r_   s    r   __str__zBaseSpecifier.__str__m        r   r\   c                    dS )zF
        Returns a hash value for this Specifier-like object.
        Nr   r_   s    r   r`   zBaseSpecifier.__hash__t  r   r   rM   r"   r.   c                    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   rV   s     r   rW   zBaseSpecifier.__eq__z  r   r   bool | Nonec                    dS )zWhether or not pre-releases as a whole are allowed.

        This can be set to either ``True`` or ``False`` to explicitly enable or disable
        prereleases or it can be set to ``None`` (the default) to use default semantics.
        Nr   r_   s    r   prereleaseszBaseSpecifier.prereleases  r   r   rZ   rI   c                    dS )zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr   rK   rZ   s     r   r   zBaseSpecifier.prereleases  r   r   Nitemr   c                    dS )zR
        Determines if the given item is contained within this specifier.
        Nr   rK   r   r   s      r   containszBaseSpecifier.contains  r   r   .iterableIterable[UnparsedVersionVar]keyIterator[UnparsedVersionVar]c                    d S r   r   rK   r   r   r   s       r   filterzBaseSpecifier.filter  	     (+sr   Iterable[T]Callable[[T], UnparsedVersion]Iterator[T]c                    d S r   r   r   s       r   r   zBaseSpecifier.filter  	     cr   Iterable[Any]'Callable[[Any], UnparsedVersion] | NoneIterator[Any]c                    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   s       r   r   zBaseSpecifier.filter  r   r   ri   rh   rg   r   r   )rZ   r.   r   rI   r   )r   r)   r   r   r   r.   N.r   r   r   r   r   rI   r   r   r   r   r   r   r   r   r   r   NNr   r   r   r   r   r   r   r   )r;   r<   r=   rj   __match_args__propertyr   abcabstractmethodr   r`   rW   r   setterr   typingoverloadr   r   r   r   r   r   d  s       IN   X 	    	   
 	        X     	    
 _ $(	+ + + + _+ _ $(.1	    _ 	 $(7;		 	 	 	 	 	 	r   r   )	metaclassc            	      (   e Zd ZU dZdZdZ ej        dez   dz   ej        ej	        z            Z
ddddd	d
dddZded<   dZd[dZd\dZd]dZd^dZd_d#Zd_d$Zed`d%            Zej        dad'            Zdbd)Zdcd,Zeddd-            Zeddd.            Zddd/Zddd0Zeded2            Zdfd4Zdgd7Zdhd9Zdid;Z djd=Z!did>Z"did?Z#did@Z$didAZ%dkdCZ&dkdDZ'dldFZ(dmdIZ)dndodKZ*e+j,        	 	 dpdqdQ            Z-e+j,        	 	 dpdrdU            Z-	 	 dsdtdYZ-dS )ur   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)~===!=<=>=r}   r   ===r   
_operators Nr!   r)   r   r   r   rI   c                   | j                             |          st          d|          |                                }|                    d          r'|dd         |dd                                         }}nb|                    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   )rK   r!   r   operatorrG   s        r   rL   zSpecifier.__init__=  s    {$$T** 	C"#A#A#ABBBzz||??5!! 	; $RaR$qrr(..*:*:gHH__;<< 	; $RaR$qrr(..*:*:gHH $RaR$qrr(..*:*:gH'/&9
 ( :> >B 8<r   rG   r   c                    | j         | j         d         |k    r| j         d         S t          |          }|dS ||f| _         |S )zDOne element cache, as only one spec Version is needed per Specifier.Nr   r   )r   r   )rK   rG   version_specifiers      r   _get_spec_versionzSpecifier._get_spec_versionc  sX    )d.@.Cw.N.N%a((+G44$4%'89  r   r   c                8    |                      |          }|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 ===).
        )r  )rK   rG   spec_versions      r   _require_spec_versionzSpecifier._require_spec_versiono  s)     --g66'''r   r   c                   | j         | 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  rG   r   endswith_wildcard_ranges_standard_ranges)rK   opver_strr   s       r   
_to_rangeszSpecifier._to_rangesy  s     <#<],;;&DLD!! 	8**2w77FF**2w77Fr   r  r  r   c                "   |                      |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   rl   r   _NEG_INF_POS_INF)rK   r  r  baser   r   s         r   r  zSpecifier._wildcard_ranges  s    ))'#2#,774  !$'':: --{5%/H/HIJJ {5%001%%x0
 	
r   c                   |                      |          }|dk    rt          |d          t          fgS |dk    r0t          t	          t          |t          j                  d          fgS |dk    r|j        7|	                    |j        dz   d           }t          |d          t          fgS |j
        8|	                    |j
        dz   dd           }t          |d          t          fgS t          t          |t          j                  d	          t          fgS |d
k    rE|j        r|n|	                    dd           }|t          k    rg 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    r.t          t	          |d	          ft          |d	          t          fgS |dk    rQ|	                    |j        d d                   }	t          |d          t	          t          |	          d	          fgS t!          d|          )Nr  Tr  r   r   r   r   r   Fr}   +r  r  r  r   )r4   Unknown operator: )r  rl   r   r  r   rD   r:   rA   rQ   r   rP   rB   r   r3   r4   r   
ValueError)
rK   r  r  rR   	lower_verr2   	has_localafter_localsr   prefixs
             r   r  zSpecifier._standard_ranges  sv   &&w//:: D))8455::  0M4N O OQUVV  99u  MMaeaitMDD	$Y55x@AAv!MMqvzqMMM	$Y55x@AA   0M4M N NPUVV  99 NAAammm.N.NE$$	{5%889:: 7N	'=+EFF0L:: D));ud+C+CDEE::;q%001UE**H5 
 ::]]19SbS>]::FQ%%{3DV3L3Le'T'TU  4b44555r   c                    | j         | j         S | j        \  }}|dk    rdS |dk    r|                    d          rdS |                     |          }|d S |j        S )Nr  Fr  r  )r   r   r  r  r   )rK   r  version_strrG   s       r   r   zSpecifier.prereleases  s     ($$ !%
+t5 t 4 4T : :5 ((55?4 $$r   rZ   c                    || _         d S r   )r   r   s     r   r   zSpecifier.prereleases  s    !r   #tuple[tuple[str, str], bool | None]c                    | j         | j        fS r   )r   r   r_   s    r   __getstate__zSpecifier.__getstate__  s     
D-..r   stater"   c                   d | _         d | _        d | _        t          |t                    rt          |          dk    r3|\  }}t          |          rt          |          r|| _        || _	        d S t          |          dk    ryt          |d         t                    r^|\  }}|                    d          }|                    dd          }t          |          rt          |          r|| _        || _	        d S t          |t                    rY|                    d          }|                    dd          }t          |          rt          |          r|| _        || _	        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)rK   r0  r!   r   _	slot_dicts         r   __setstate__zSpecifier.__setstate__  sx   !#eU## 	5zzQ$)!k!$'' M+,F,F !%DJ(3D%F5zzQ:eAh#=#=$9 }}W--'mmNIFF!$'' M+,F,F !%DJ(3D%FeT"" 	99W%%D))NI>>Kd## k(B(B !
$/!BBBCCCr   c                    | j         d         S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   r   r_   s    r   r  zSpecifier.operator$       z!}r   c                    | j         d         S )zaThe version of this specifier.

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r   r:  r_   s    r   rG   zSpecifier.version-  r;  r   c                l    | j         
d| j        nd}d| j        j         dt	          |           | dS )aT  A representation of the Specifier that shows all internal state.

        >>> Specifier('>=1.0.0')
        <Specifier('>=1.0.0')>
        >>> Specifier('>=1.0.0', prereleases=False)
        <Specifier('>=1.0.0', prereleases=False)>
        >>> Specifier('>=1.0.0', prereleases=True)
        <Specifier('>=1.0.0', prereleases=True)>
        N, prereleases=r  r}   rb   )>r   r   rd   r;   r)   rK   r+   s     r   rf   zSpecifier.__repr__6  sT      , 2T-111 	 B4>*AASYYA#AAAAr   c                      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   r_   s    r   r   zSpecifier.__str__H  s     v}dj))r   tuple[str, str]c                    | j         \  }}|dk    s|                    d          r||fS |                     |          }t          ||dk              }||fS )Nr  r  r  strip_trailing_zero)r   r  r  r   )rK   r  rG   r  canonical_versions        r   _canonical_speczSpecifier._canonical_specR  sw     J'u 0 0 6 6W$$11'::0x4/?
 
 
 ***r   r\   c                *    t          | j                  S r   )r^   rI  r_   s    r   r`   zSpecifier.__hash__`  s    D()))r   rM   r.   c                    t          |t                    r;	 |                     t          |                    }n3# t          $ r
 t          cY S w xY 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)   rd   r   rU   rI  rV   s     r   rW   zSpecifier.__eq__c  s    & eS!! 	"&s5zz22# & & &%%%%&E4>22 	"!!#u'<<<s   ": AACallableOperatorc                B    t          | d| j        |                    }|S )N	_compare_)getattrr  )rK   r  operator_callables      r   _get_operatorzSpecifier._get_operator  s/    .53dob133/
 /
 ! r   prospectivec           
         t          t          t          j        t          t          |                              d d                   }|dz  }|                     ||          o|                     ||          S )Nr   r  )_version_joinlist	itertools	takewhile_is_not_suffix_version_split_compare_greater_than_equal_compare_equal)rK   rR  r!   r)  s       r   _compare_compatiblezSpecifier._compare_compatible  sw     $^^D5I5IJJKKCRCP
 

 	$00dCC 
V44	
r   tuple[list[str], int]c                    | j         }|@t          |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  FrF  )r   r   rY  _numeric_prefix_len)rK   r!   wildcard_split
normalized
split_specs        r   _get_wildcard_splitzSpecifier._get_wildcard_split  sZ     -!-d3B3iUSSSJ'
33J(*=j*I*IJN#1D r   c                r   |                     d          rr|                     |          \  }}t          t          |          d          }t	          |          }t          ||          }|d t          |                   }||k    S |                     |          }	|	j        st          |          }||	k    S )Nr  FrF  )	r  rc  r   r   rY  	_left_padr(   r  r   )
rK   rR  r!   rb  spec_numeric_lennormalized_prospectivesplit_prospectivepadded_prospectiveshortened_prospectiver  s
             r   r[  zSpecifier._compare_equal  s    ==  	/+/+C+CD+I+I(J( &:,,%& & &" !//E F F "++<>N!O!O
 %77HZ7H$I!(J66  55d;;L
  % ;-k::,..r   c                0    |                      ||           S r   )r[  rK   rR  r!   s      r   _compare_not_equalzSpecifier._compare_not_equal  s    &&{D9999r   c                N    t          |          |                     |          k    S r   r   r  rl  s      r   _compare_less_than_equalz"Specifier._compare_less_than_equal  %     {++t/I/I$/O/OOOr   c                N    t          |          |                     |          k    S r   ro  rl  s      r   rZ  z%Specifier._compare_greater_than_equal  rq  r   spec_strc                    |                      |          }||k     sdS |j        s|j        r|t          |          k    rdS dS r   )r  r   r   rK   rR  rs  r!   s       r   _compare_less_thanzSpecifier._compare_less_than  sc     ))(33
 T!!5
 "	)	 3D99995
 tr   c                    |                      |          }||k    sdS |j        s|j        rt          |          |k    rdS |j        t	          |          |k    rdS dS r   )r  is_postreleaser   r   r   ru  s       r   _compare_greater_thanzSpecifier._compare_greater_than  s     ))(33
 T!!5
 #	*	 ;''4//5 (_[-I-IT-Q-Q5
 tr   Version | strc                    t          |                                          t          |                                          k    S r   r)   r   rl  s      r   _compare_arbitraryzSpecifier._compare_arbitrary  s1    ;%%''3t99??+<+<<<r   r   str | Versionc                ,    |                      |          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   rK   r   s     r   __contains__zSpecifier.__contains__      & }}T"""r   r   c                f    t          t          |                     |g|                              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.   rU  r   r   s      r   r   zSpecifier.contains.  s,    2 DdVEEFFGGGr   .r   r   r   r   c                    d S r   r   r   s       r   r   zSpecifier.filterI  r   r   r   r   r   c                    d S r   r   r   s       r   r   zSpecifier.filterQ  r   r   r   r   r   c              #  $  K   g }d}||n| j         }|                     | j                  }|D ]}t          ||n
 ||                    }	d}
|	+| j        dk    r|                     || j                  r|V  nE| j        dk    r)|                     ||n
 ||          | j                  }
n ||	| j                  }
|
r2|	0|	j        r|rd}|V  || j        dur|                    |           |s|| j        dur|E d{V  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   rQ  r  r   r}  rG   r   r   r   )rK   r   r   r   prereleases_versionsfound_non_prereleasesinclude_prereleasesrP  rG   parsed_versionmatchs              r   r   zSpecifier.filterY  s     F  " % '2KK8H 	
 !..t}==   	9 	9G,WWWVVNE%=E))d.E.ET\/ /) "MMM%''//"{GGGdl  *).$,GG 93%3 97J 9,0)!MMMM (T->e-K-K(//888
 &	,#!..++++++++++	, 	,##..r   r  N)r!   r)   r   r   r   rI   )rG   r)   r   r   )rG   r)   r   r   r   r   )r  r)   r  r)   r   r   r   rZ   r   r   rI   )r   r-  r0  r"   r   rI   ri   )r   rD  rh   rg   )r  r)   r   rL  )rR  r   r!   r)   r   r.   )r!   r)   r   r]  )rR  r   rs  r)   r   r.   )rR  rz  r!   r)   r   r.   )r   r~  r   r.   r   )r   r   r   r   r   r.   r   r   r   r   r   ).r;   r<   r=   r>   rj   _specifier_regex_strrecompileVERBOSE
IGNORECASEr
  r  __annotations__rL   r  r  r  r  r  r   r   r   r/  r8  r  rG   rf   r   rI  r`   rW   rQ  r\  rc  r[  rm  rp  rZ  rv  ry  r}  r  r   r   r   r   r   r   r   r   r     s         &IZx RZ%%.
R]0J F
 "	 	J 	 	 	 	$< $< $< $< $<L
! 
! 
! 
!      0
 
 
 
<6 <6 <6 <6| % % % X%6 " " " "/ / / / D  D  D  DD    X    XB B B B$* * * * + + + X+* * * *= = = =:! ! ! !
 
 
 
(    "/ "/ "/ "/H: : : :P P P PP P P P   2   @= = = =# # # #*H H H H H6 _ $(	+ + + + _+ _ $(.1	    _ $(7;	O, O, O, O, O, O, O,r   r   z([0-9]+)((?:a|b|c|rc)[0-9]+)r   r   r   r   r   c              #  6  K   g }g }d}| D ]}t          ||n
 ||                    }|2|r|V  n*|                    |           |                    |           R|j        s|s
|E d{V  d}|V  j|s|                    |           |s
|E d{V  dS dS )z?Filter per PEP 440: exclude prereleases unless no finals exist.FNT)r   r   r   )r   r   all_nonfinalarbitrary_stringsfound_finalr   parseds          r   _pep440_filter_prereleasesr    s      !L#%K & & ##d))DD>  *



!((...##D)))# 	 #,,,,,,,,"JJJ  	&%%%      r   r)   c                L   g }|                      d          \  }}}|                    |pd           |                    d          D ][}t                              |          }|r(|                    |                                           F|                    |           \|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)rG   r   rO   r6  restr   r  s          r   rY  rY    s     F'',,NE1d
MM%,3

3    ''-- 	 MM%,,..))))MM$Mr   
componentsc                >    | ^}}| 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  rO   r  s      r   rT  rT    s+     LED&&chhtnn&&&r   segmentc                <     t           fddD                        S )Nc              3  B   K   | ]}                     |          V  d S r   )r  ).0r)  r  s     r   	<genexpr>z!_is_not_suffix.<locals>.<genexpr>  sB        '-6""     r   )rQ   abrcrP   )any)r  s   `r   rX  rX    s@        1P      r   r  r\   c                J    d}| D ]}|                                 s n|dz  }|S )zCount leading numeric components in a :func:`_version_split` result.

    >>> _numeric_prefix_len(["0", "1", "2", "a1"])
    3
    r   r   )isdigit)r  countr  s      r   r_  r_    s?     E     	E
Lr   target_numeric_lenc                r    t          |           }||z
  }|dk    r| S g | d|         dg|z  | |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  r  numeric_len
pad_neededs       r   re  re    sW     &e,,K#k1JQNU<K< NSEJ$6N%:MNNr   op_entry!tuple[CallableOperator, str, str]c                    | \  }}}|dk    r|                     d          sdndS |dv rdS |dk    rdS |dk    r|                     d          sd	nd
S |dk    rd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  r   r}   r   r  r  r      r  r$  )r  r%  )r  r6  verr  s       r   _operator_costr    s     JAsB	TzzT**1qq1	###q	Tzzq	TzzT**1qq1	U{{q
0"00
1
11r   c                  N   e Zd ZdZdZ	 	 d<d=dZd>dZed?d            Zej	        d@d            ZdAdZ
dBdZdCdZdCdZdDdZdEdZdFdZdDd ZdGd"ZdHd$ZdId%ZdId&ZdId'ZdJd*Z	 	 dKdLd,Zej        	 	 dMdNd2            Zej        	 	 dMdOd6            Z	 	 dKdPd:Z	 dQdRd;ZdS )Sr   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   rI   c                   t          |t                    rPd |                    d          D             }t          t	          t
          |                    | _        d|v | _        n7t          |          | _        t          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                ^    g | ]*}|                                 |                                 +S r   )r  r  ss     r   
<listcomp>z)SpecifierSet.__init__.<locals>.<listcomp>k  s-    VVVaAGGIIV		VVVr   ,r  c              3  8   K   | ]}d t          |          v V  dS r  Nr   r  s     r   r  z(SpecifierSet.__init__.<locals>.<genexpr>t  s,      %K%K!es1vvo%K%K%K%K%K%Kr   r   N)r&   r)   r  r'   mapr   r  r  r  r(   r  r  r   r  )rK   r  r   split_specifierss       r   rL   zSpecifierSet.__init__R  s    , j#&& 	L  WV:3C3CC3H3HVVV16s9FV7W7W1X1XDK"':"5D
++DK #&%K%Kt{%K%K%K"K"KD!$+..!3MQ (.2r   tuple[Specifier, ...]c                    | j         sZt          t                              t	          | j        t                                        | _        d| _         d| _        d| _        | j        S )zBDeduplicate, sort, and cache specs for order-sensitive operations.r   TN)	r  r'   r3  fromkeyssortedr  r)   r  r  r_   s    r   _canonical_specszSpecifierSet._canonical_specs  sW    " 	*fT[c.J.J.J K KLLDK"&D!%D%)D"{r   c                t    | j         | j         S | j        sd S t          d | j        D                       rdS d S )Nc              3  $   K   | ]}|j         V  d S r   r  r  s     r   r  z+SpecifierSet.prereleases.<locals>.<genexpr>  s$      22q}222222r   T)r   r  r  r_   s    r   r   zSpecifierSet.prereleases  sT     ($$
 { 	4 22dk22222 	4tr   rZ   c                "    || _         d | _        d S r   )r   r  r   s     r   r   zSpecifierSet.prereleases  s    !!%r   )tuple[tuple[Specifier, ...], bool | None]c                    | j         | j        fS r   )r  r   r_   s    r   r/  zSpecifierSet.__getstate__  s     T.//r   r0  r"   c                   d | _         d | _        t          |t                    rt	          |          dk    r|\  }}t          |t                    rnt          d |D                       rUt          |          rF|| _        || _        t	          |          dk    | _	        t          d |D                       | _        d S t	          |          dk    rt          |d         t                    r|\  }}|                    dd          }|                    d          }t          |t                    r#t          t          |t                               }t          |t                    rxt          d	 |D                       r_t          |          rP|| _        || _        t	          | j                  dk    | _	        t          d
 | j        D                       | _        d S t          |t                    r|                    dd          }|                    d          }t          |t                    r#t          t          |t                               }t          |t                    rxt          d |D                       r_t          |          rP|| _        || _        t	          | j                  dk    | _	        t          d | j        D                       | _        d S t#          d|          )Nr%   c              3  @   K   | ]}t          |t                    V  d S r   r&   r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  ,      DDJq)44DDDDDDr   r   c              3  8   K   | ]}d t          |          v V  dS r  r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s,      -M-M!es1vvo-M-M-M-M-M-Mr   r  r   r   r  c              3  @   K   | ]}t          |t                    V  d S r   r  r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  r  r   c              3  8   K   | ]}d t          |          v V  dS r  r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s,      -S-S!es1vvo-S-S-S-S-S-Sr   c              3  @   K   | ]}t          |t                    V  d S r   r  r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s,      @@Q
1i00@@@@@@r   c              3  8   K   | ]}d t          |          v V  dS r  r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s,      )O)Oa%3q66/)O)O)O)O)O)Or   z!Cannot restore SpecifierSet from )r  r  r&   r'   r(   allr/   r  r   r  r  r  r3  r4  	frozensetr  r)   r5  )rK   r0  specsr   r6  r7  s         r   r8  zSpecifierSet.__setstate__  s   !!%eU## 	5zzQ%*"{ue,,	DDeDDDDD	 &k22	
 #(DK(3D%*-e**/D'*--M-Mu-M-M-M*M*MD'F5zzQ:eAh#=#=$9!h33'mmN;;eY// :!&C"8"8"899Eue,,	DDeDDDDD	 &k22	
 #(DK(3D%*-dk*:*:a*?D'*--S-St{-S-S-S*S*SD'FeT"" 	IIh++E))N33K%++ 6fU444555%((	@@%@@@@@	 "+..	
 $$/!&)$+&6&6!&;#&))O)O4;)O)O)O&O&O#EEEEFFFr   r)   c                l    | j         
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  r}   rb   r?  r@  rA  s     r   rf   zSpecifierSet.__repr__  sT      , 2T-111 	 B4>*AASYYA#AAAAr   c                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'
        r  c              3  4   K   | ]}t          |          V  d S r   r   r  s     r   r  z'SpecifierSet.__str__.<locals>.<genexpr>   s(      @@1A@@@@@@r   )r  r  r_   s    r   r   zSpecifierSet.__str__  s1     xx@@(=(=(?(?@@@@@@r   r\   c                D    t          |                                           S r   )r^   r  r_   s    r   r`   zSpecifierSet.__hash__  s    D))++,,,r   rM   SpecifierSet | strc                   t          |t                    rt          |          }nt          |t                    st          S t                      }| j        |j        z   |_        t          |j                  dk    |_        | j        p|j        |_        d|_        | j	        | j	        |j	        k    r|j	        |_	        n#|j	        | 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   rU   r  r(   r  r  r  r   r%  )rK   rM   	specifiers      r   __and__zSpecifierSet.__and__  s     eS!! 	" ''EEE<00 	"!! NN	;5	#&y'7#8#8A#=	 #'#6#N%:N	 "&	 $(9U=O(O(O%*%7I""'%)%6I""X   r   r.   c                    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   rU   r  rV   s     r   rW   zSpecifierSet.__eq__&  sk    & ec9-.. 	" U,,EEE<00 	"!!$$&&%*@*@*B*BBBr   c                *    t          | j                  S )z7Returns the number of specifiers in this specifier set.)r(   r  r_   s    r   __len__zSpecifierSet.__len__@  s    4;r   Iterator[Specifier]c                *    t          | j                  S )z
        Returns an iterator over all the underlying :class:`Specifier` instances
        in this specifier set.

        >>> sorted(SpecifierSet(">=1.0.0,!=1.0.1"), key=str)
        [<Specifier('!=1.0.1')>, <Specifier('>=1.0.0')>]
        )iterr  r_   s    r   __iter__zSpecifierSet.__iter__D  s     DK   r   r   c                    | j         }d}|D ]?}||                                }t          ||                                          }|s n@|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)r  r  r   RuntimeError)rK   r  r   r  s       r   _get_rangeszSpecifierSet._get_rangesN  sw     15 	 	A~*61<<>>BB E >ABBBr   c                    | j         }||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  r  r  _check_arbitrary_unsatisfiabler   _check_prerelease_only_ranges)rK   cachedr   s      r   is_unsatisfiablezSpecifierSet.is_unsatisfiabled  s     'M{ 	%*D"5%%''' 	;88::F 	:$*e337799F!'r   c                    |                                  D ]H\  }}t          |j                  }| dS |j        ||j        k     r dS ||j        k    r
|j        r dS IdS )zWith prereleases=False, check if every range contains only
        pre-release versions (which would be excluded from matching).NFT)r  r   rG   rn   )rK   r   r   nearests       r   r  z*SpecifierSet._check_prerelease_only_ranges  sz     !,,.. 	 	LE5-em<<Guu}$%-(?(?uu%-''EO'uutr   c                ~   d | j         D             }|sdS |d         j                                        t          fd|dd         D                       rdS t	          |d         j                  | j        du r	j        rdS d | j         D             }|sdS dS t          f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                (    g | ]}|j         d k    |S r  r  r  s     r   r  z?SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<listcomp>  s$    CCC1qzU/B/BQ/B/B/Br   Fr   c              3  R   K   | ]!}|j                                         k    V  "d S r   )rG   r   )r  r  firsts     r   r  z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>  s4      AAaqy  E)AAAAAAr   r   NTc                (    g | ]}|j         d k    |S r  r  r  s     r   r  z?SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<listcomp>  s$    BBB!ajE.A.AA.A.A.Ar   c              3  B   K   | ]}|                               V  d S r   r  )r  r  	candidates     r   r  z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>  s/      ??qzz),,??????r   )r  rG   r   r  r   r   r   r  )rK   r   standardr  r  s      @@r   r  z+SpecifierSet._check_arbitrary_unsatisfiable  s    DCCCC	 	5 !$**,,AAAA9QRR=AAAAA 	4 $IaL$899	
 %%%' & 4BBt{BBB 	54????h???????r   r   r   c                ,    |                      |          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  s     r   r  zSpecifierSet.__contains__  r  r   	installedc                    t          |          }||r	|j        rd}|| j        rt          |t                    s|}n|}t          t          |                     |g|                              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   r  r&   r   r.   rU  r   )rK   r   r   r  rG   
check_items         r   r   zSpecifierSet.contains  sz    @ "$''91FK ?t2?:dG;T;T?JJ JDj\{KKLLMMMr   .r   r   r   r   c                    d S r   r   r   s       r   r   zSpecifierSet.filter  r   r   r   r   r   c                    d S r   r   r   s       r   r   zSpecifierSet.filter  r   r   r   r   r   c                   || j         | j         }| j        rpt          | j                  dk    r(| j        d                             ||dn|          }n|                     ||dn|          }||S t          |          S |du rt          |          S |du rf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  h   K   | ],}t          |n
 |                    x	 j        (|V  -d S r   )r   r   )r  r   r   rG   s     r   r  z&SpecifierSet.filter.<locals>.<genexpr>^  sj         /T S SSW"0    	 r   )r   r  r(   r   _filter_versionsr  r  )rK   r   r   r   filteredrG   s      ` @r   r   zSpecifierSet.filter  s%   d 4#3#?*K ; 	= 4;1$$;q>00(3(; 1    00(3(; 1   &-h<<< $>>!%    $    *(C888r   c              #  d  K   | j         *t          d | j        D             t                    | _         | j         }|du }|D ]kt	          n
                      t          fd|D                       rV  @|rj        rJt          fd|D                       rV  ld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              3  d   K   | ]+}|                     |j                  |j        |j        fV  ,d S r   )rQ  r  rG   )r  r!   s     r   r  z0SpecifierSet._filter_versions.<locals>.<genexpr>{  sQ         ''66dmT     r   r  Fc              3     K   | ]E\  }}}|d k    o6t                                                    |                                k    V  FdS r  r|  )r  r6  r  r  r   s       r   r  z0SpecifierSet._filter_versions.<locals>.<genexpr>  sc        "3 %KDCIIOO$5$5$D     r   c              3     K   | ]^\  }}}|d k    rDt          n
                                                     |                                k    n ||          V  _dS r  r|  )r  op_fnr  r  r   r   r  s       r   r  z0SpecifierSet._filter_versions.<locals>.<genexpr>  s         #E3 ;; CKDDSSYY77==??399;;NNU63''     r   )r  r  r  r  r   r  r   )rK   r   r   r   opsexclude_prereleasesr   r  s     `   @@r   r  zSpecifierSet._filter_versionsk  sG      %!'  $   #" " "D  )U2 	 	D$S[TTcc$iiHHF~    &)      JJJ$ 	)= 	       '*	      


'	 	r   r  )r  r  r   r   r   rI   )r   r  r   r  )r   r  r  ri   rh   )rM   r  r   r   rg   )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>   rj   rL   r  r   r   r   r/  r8  rf   r   r`   r  rW   r  r  r  r   r  r  r  r   r   r   r   r  r   r   r   r   r   6  s        $I 13#'+3 +3 +3 +3 +3Z       X& & & & &0 0 0 07G 7G 7G 7GrB B B B*A A A A- - - -   BC C C C4       ! ! ! !   ,   B   %@ %@ %@ %@N# # # #0 $(!%	+N +N +N +N +NZ _ $(	+ + + + _+ _ $(.1	    _ $(7;	^9 ^9 ^9 ^9 ^9H $(	, , , , , , ,r   r   )r   r   )r!   r"   r   r#   )r+   r"   r   r,   )r4   r5   r   r5   )r   rl   r   r   r   r.   )r   r   r   r   r   r   )rG   r   r   r   )rG   r   r   r   )rR   ro   r   r   )r   r   r   r   r   r   )rG   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\   )Lr>   
__future__r   r   r?   	functoolsrV  r  sysr   r   r   r   r   r   r	   r
   r   r   utilsr   rG   r   r   version_infor   typing_extensionsr   r    r*   r/   r0   r)   r   r1   r.   rL  r3   r  r8   Enumr:   total_orderingrD   rl   r   ro   r'   _VersionRanger  r   r   r   r   r   r   r   r   r   r   r   r%  r   ABCMetar   r   r  r  r  rY  rT  rX  r_  re  r  r   r   r   r   <module>r(     s     # " " " " " 



          				 



 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 ( ' ' ' ' ' , , , , , , , ,w        ,++++++        0 0 0 0 GCLL%W1III WcND01   'wx00 0 0 0 0= = = =    DI    ;Q ;Q ;Q ;Q ;Q ;Q ;Q ;Q| %H %H %H %H %H %H %H %HP %H %H %H %H %H %H %H %HP 
 4w(8$>? +{23M;tU##;tU##&.%9$; ; ; ; ;) ) ) )   4K K K KS S S S
   + + + +@ @ @ @2 2 2 29 9 9 9*	 	 	 	 	z 	 	 	O O O O Ock O O O Odr, r, r, r, r, r, r, r,j 
:;;'  '  '  ' T   ,' ' ' '      O O O O2 2 2 26a	 a	 a	 a	 a	= a	 a	 a	 a	 a	r   