
    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j0                  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jP                        Z)ejT                   G d d             Z+ejT                   G d d             Z,ejT                   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<   d>d Z4	 	 	 	 	 	 d?d!Z5d@d"Z6d@d#Z7dAd$Z8d@d%Z9d@d&Z:d@d'Z;	 	 	 	 dBd(Z< G d) d*e=      Z> G d+ d,ej~                  -      Z@ G d. d/e@      ZA ej                  d0      ZC	 	 	 	 	 	 dCd1ZDdDd2ZEdEd3ZFdFd4ZGdGd5ZHdHd6ZIdId7ZJ G d8 d9e@      ZKy)Jz
.. 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SpecifierSetc                     t         S N)__all__     G/root/searxng-venv/lib/python3.12/site-packages/packaging/specifiers.py__dir__r   0   s    Nr   c                   t        | t              xr8 t        |       dk(  xr( t        | d   t              xr t        | d   t              S )N   r   r   )
isinstancetuplelenstr)specs    r   _validate_specr&   4   sI    4 	%IN	%tAw$	% tAw$	r   c               .    | d u xs t        | t              S r   )r!   bool)pres    r   _validate_prer*   =   s    $;/*S$//r   TUnparsedVersionVar)boundz0.dev0zFinal[Version]_MIN_VERSIONc                    t        |       }|dkD  r!| |dz
     dk(  r|dz  }|dkD  r| |dz
     dk(  r|t        |       k(  r| S | d| S )zDStrip trailing zeros from a release tuple for normalized comparison.r   r   N)r#   )releaseends     r   _trim_releaser2   J   s`    
g,C
'gcAg&!+q 'gcAg&!+S\)7<wt}<r   c                  T    e Zd ZdZ ej
                         Z ej
                         Zy)_BoundaryKindz5Where a boundary marker sits in the version ordering.N)__name__
__module____qualname____doc__enumautoAFTER_LOCALSAFTER_POSTSr   r   r   r4   r4   R   s    ?499;L$))+Kr   r4   c                  D    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
y	)_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versionc                T    || _         || _        t        |j                        | _        y r   )rA   r?   r2   r0   r@   )selfrA   kinds      r   __init__z_BoundaryVersion.__init__q   s!    
 -goo >r   c                   | j                   }|j                  |j                  k(  r;t        |j                        | j                  k(  r|j
                  |j
                  k(  sy| j                  t        j                  k(  r4|j                  |j                  k(  xr |j                  |j                  k(  S |j                  |j                  k(  xs |j                  duS )z6Is ``other`` a version that this boundary sorts above?FN)rA   epochr2   r0   r@   r)   r?   r4   r;   postdev)rC   othervs      r   
_is_familyz_BoundaryVersion._is_familyv   s    LLKK177"emm,0E0EE		QUU"::333::'>EII,>>yyAEE!;UZZt%;;r   c                    t        |t              r4| j                  |j                  k(  xr | j                  |j                  k(  S t        S r   )r!   r>   rA   r?   NotImplementedrC   rJ   s     r   __eq__z_BoundaryVersion.__eq__   s8    e-.<<5==0NTZZ5;;5NNr   c                &   t        |t              r_| j                  |j                  k7  r| j                  |j                  k  S | j                  j                  |j                  j                  k  S | j                  |       xr | j                  |k  S r   )r!   r>   rA   r?   valuerL   rO   s     r   __lt__z_BoundaryVersion.__lt__   so    e-.||u}},||emm33::##ekk&7&777??5))BdllU.BBr   c                D    t        | j                  | j                  f      S r   )hashrA   r?   rC   s    r   __hash__z_BoundaryVersion.__hash__   s    T\\4::.//r   c                |    | j                   j                   d| j                  d| j                  j                   dS )N(z, ))	__class__r5   rA   r?   namerV   s    r   __repr__z_BoundaryVersion.__repr__   s4    ..))*!DLL+;2djjoo=NaPPr   N)rA   r   rD   r4   returnNone)rJ   r   r^   r(   rJ   objectr^   r(   )rJ   z_BoundaryVersion | Versionr^   r(   r^   intr^   r$   )r5   r6   r7   r8   	__slots__rE   rL   rP   rS   rW   r]   r   r   r   r>   r>   Y   s.    ( 9I?
<
C0Qr   r>   c                  <    e Zd ZdZdZd	dZd
dZddZddZddZ	y)_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.
    	inclusiverA   c                     || _         || _        y r   rA   ri   rC   rA   ri   s      r   rE   z_LowerBound.__init__       "r   c                    t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r   r!   rg   rN   rA   ri   rO   s     r   rP   z_LowerBound.__eq__   7    %-!!||u}},R5??1RRr   c                   t        |t              st        S | j                  |j                  d uS |j                  y| j                  |j                  k7  r| j                  |j                  k  S | j                  xr |j                   S )NFro   rO   s     r   rS   z_LowerBound.__lt__   sq    %-!!<<==,,== <<5==(<<%--//~~5eoo"55r   c                D    t        | j                  | j                  f      S r   rU   rA   ri   rV   s    r   rW   z_LowerBound.__hash__       T\\4>>233r   c                t    | j                   rdnd}d| j                  j                   d| | j                  dS )N[rY   < >ri   r[   r5   rA   rC   brackets     r   r]   z_LowerBound.__repr__   s8    #S4>>**+1WIdll5EQGGr   NrA   _VersionOrBoundaryri   r(   r^   r_   r`   )rJ   rg   r^   r(   rb   rd   
r5   r6   r7   r8   re   rE   rP   rS   rW   r]   r   r   r   rg   rg      )     )I#S
64Hr   rg   c                  <    e Zd ZdZdZd	dZd
dZddZddZddZ	y)_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.
    rh   c                     || _         || _        y r   rk   rl   s      r   rE   z_UpperBound.__init__   rm   r   c                    t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r   r!   r   rN   rA   ri   rO   s     r   rP   z_UpperBound.__eq__   rp   r   c                    t        |t              st        S | j                  y|j                  y| j                  |j                  k7  r| j                  |j                  k  S | j                   xr |j                  S NFTr   rO   s     r   rS   z_UpperBound.__lt__   se    %-!!<<== <<5==(<<%--//>>!5eoo5r   c                D    t        | j                  | j                  f      S r   rs   rV   s    r   rW   z_UpperBound.__hash__   rt   r   c                t    | j                   rdnd}d| j                  j                   d| j                  | dS )N]rZ   rw   rx   ry   rz   r{   s     r   r]   z_UpperBound.__repr__   s8    #S4>>**+1T\\,<WIQGGr   Nr}   r`   )rJ   r   r^   r(   rb   rd   r   r   r   r   r   r      r   r   r   Fztuple[_VersionRange]_FULL_RANGEc                    | j                   |j                   y| j                   |j                   k(  r| j                  xr |j                   S | j                   |j                   kD  S )zHTrue when the range defined by *lower* and *upper* contains no versions.Frk   )loweruppers     r   _range_is_emptyr      sQ    }} 5}}%OO788==5==((r   c                2   g }dx}}|t        |       k  r|t        |      k  rt| |   \  }}||   \  }}t        ||      }	t        ||      }
t        |	|
      s|j	                  |	|
f       ||k  r|dz  }n|dz  }|t        |       k  r|t        |      k  rt|S )zFIntersect two sorted, non-overlapping range lists (two-pointer merge).r   r   )r#   maxminr   append)leftrightresult
left_indexright_index
left_lower
left_upperright_lowerright_upperr   r   s              r   _intersect_rangesr      s    
 #%F  J
s4y
 [3u:%=!%j!1
J#(#5 [J,J,ue,MM5%.) #!OJ1K s4y
 [3u:%=  Mr   c                    g | j                   dd | j                   d   dz   }t        j                  | j                  |d      S )z5Smallest version in the next prefix: 1.2 -> 1.3.dev0.Nr   r   rG   r0   rI   )r0   r   
from_partsrG   )rA   r0   s     r   _next_prefix_dev0r     sC    >$>goob&9A&=>GGMM7JJr   c                Z    t        j                  | j                  | j                  d      S )z7The .dev0 of a version's base release: 1.2 -> 1.2.dev0.r   r   )r   r   rG   r0   rA   s    r   
_base_dev0r     s     GMM7??PQRRr   c                `    t        | t              s	 t        |       } | S | S # t        $ r Y y w xY wr   )r!   r   r   r   s    r   _coerce_versionr   $  s:    gw'	g&G N7N  		s   ! 	--c                B    | j                   | S | j                  d       S )N)local)r   __replace__r   s    r   _public_versionr   -  s%    }}T**r   c                *    | j                  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rH   rI   r   r   r   s    r   
_post_baser   3  s    
 Dd$??r   c                (    | j                  dd      S )zZEarliest pre-release of *version*.

    1.2 -> 1.2.dev0, 1.2.post1 -> 1.2.post1.dev0.
    r   NrI   r   r   r   s    r   _earliest_prereleaser   ;  s    
 1D11r   c                $   | yt        | t              r\| j                  }|j                  r|j	                  ddd      S |j
                  |j
                  dz   nd}|j	                  |d      S | j                  s| S | j	                  ddd      S )z:Smallest non-pre-release version at or above *v*, or None.N)r)   rI   r   r   r   )rH   r   )r!   r>   rA   is_prereleaser   rH   )rK   innerks      r   _nearest_non_prereleaser   C  s     	y!%&		$$4t$DD !&

 6UZZ!^A  at 44??==Tt4=88r   c                      e Zd ZdZy)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)r5   r6   r7   r8   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y	)r   r   )_strc                    t        |       S )z Internal property for match_argsr$   rV   s    r   r   zBaseSpecifier._strh  s     4yr   c                     y)z
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr   rV   s    r   __str__zBaseSpecifier.__str__m      r   c                     y)zF
        Returns a hash value for this Specifier-like object.
        Nr   rV   s    r   rW   zBaseSpecifier.__hash__t  r   r   c                     y)z
        Returns a boolean representing whether or not the two Specifier-like
        objects are equal.

        :param other: The other object to check against.
        Nr   rO   s     r   rP   zBaseSpecifier.__eq__z  r   r   c                     y)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   rV   s    r   prereleaseszBaseSpecifier.prereleases  r   r   c                     y)zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr   rC   rR   s     r   r   zBaseSpecifier.prereleases  r   r   Nc                     y)zR
        Determines if the given item is contained within this specifier.
        Nr   rC   itemr   s      r   containszBaseSpecifier.contains  r   r   c                     y r   r   rC   iterabler   keys       r   filterzBaseSpecifier.filter       (+r   c                     y r   r   r   s       r   r   zBaseSpecifier.filter       r   c                     y)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   rd   rb   r`   r^   bool | None)rR   r(   r^   r_   r   )r   r$   r   r   r^   r(   N.r   zIterable[UnparsedVersionVar]r   r   r   r_   r^   zIterator[UnparsedVersionVar]r   zIterable[T]r   r   r   zCallable[[T], UnparsedVersion]r^   zIterator[T]NNr   Iterable[Any]r   r   r   'Callable[[Any], UnparsedVersion] | Noner^   Iterator[Any])r5   r6   r7   re   __match_args__propertyr   abcabstractmethodr   rW   rP   r   setterr   typingoverloadr   r   r   r   r   r   d  s   IN  	  	 
 	       	 
 __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  	 $(7;			 !	 5		
 
	 	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<   d1d2dZd3dZd4dZd5dZd6dZd6dZed7d       Zej*                  d8d       Zd9dZd:dZed;d       Zed;d       Zd;dZd;dZed<d       Zd=d Zd>d!Zd?d"Zd@d#Z dAd$Z!d@d%Z"d@d&Z#d@d'Z$d@d(Z%dBd)Z&dBd*Z'dCd+Z(dDd,Z)dEdFd-Z*e+jX                  	 	 dG	 	 	 	 	 	 	 dHd.       Z-e+jX                  	 	 dG	 	 	 	 	 	 	 dId/       Z-	 	 dJ	 	 	 	 	 	 	 dKd0Z-y)Lr   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)~===!=<=>=rw   ry   ===r   
_operatorsNc                   | j                   j                  |      st        d|      |j                         }|j	                  d      r|dd |dd j                         }}nB|j	                  d      r|dd |dd j                         }}n|dd |dd j                         }}||f| _        || _        d| _        d| _        d| _	        y)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   )rC   r%   r   operatorrA   s        r   rE   zSpecifier.__init__=  s     {{$$T*"%8#ABBzz|??5! $Ra$qr(..*:gH__;< $Ra$qr(..*:gH $Ra$qr(..*:gH'/&9
 ( :> >B 8<r   c                    | j                   !| j                   d   |k(  r| j                   d   S t        |      }|y||f| _         |S )zDOne element cache, as only one spec Version is needed per Specifier.Nr   r   )r   r   )rC   rA   version_specifiers      r   _get_spec_versionzSpecifier._get_spec_versionc  sY    )d.@.@.Cw.N%%a((+G4$%'89  r   c                0    | j                  |      }|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  )rC   rA   spec_versions      r   _require_spec_versionzSpecifier._require_spec_versiono  s&     --g6'''r   c                   | j                   | j                   S | j                  }| j                  }|dk(  rt        | _         t        S |j	                  d      r| j                  ||      }n| j                  ||      }|| _         |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.
        r   .*)r   r   rA   r   endswith_wildcard_ranges_standard_ranges)rC   opver_strr   s       r   
_to_rangeszSpecifier._to_rangesy  s|     <<#<<]],,;&DLD!**2w7F**2w7Fr   c                    | j                  |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   rg   r   _NEG_INF_POS_INF)rC   r  r  baser   r   s         r   r	  zSpecifier._wildcard_ranges  sy    ))'#2,74 !$': -{5%/HIJJ {5%01%x0
 	
r   c                   | j                  |      }|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                  3|j                  |j                  dz   d       }t        |d      t        fgS |j                  4|j                  |j                  dz   dd       }t        |d      t        fgS t        t        |t        j                        d	      t        fgS |d
k(  r?|j                  r|n|j                  dd       }|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(  rA|j                  |j                  d d       }	t        |d      t	        t        |	      d	      fgS t!        d|      )Nr   Tr   ry   r   r   r   r   Frw   +r   r   r   r   )r0   Unknown operator: )r  rg   r  r  r   r>   r4   r;   rI   r   rH   r<   r   r.   r0   r   
ValueError)
rC   r  r  rK   	lower_verr-   	has_localafter_localsr   prefixs
             r   r
  zSpecifier._standard_ranges  s+   &&w/: D)8455:  0M4N4N OQUV  9uu  MMaeeaitMD	$Y5x@AAvv!MMqvvzqMM	$Y5x@AA   0M4M4M NPUV  9 Aammm.NE$	{5%89:: 7N	'=+E+EFL: D);ud+CDEE:;q%01UE*H5 
 :]]199Sb>]:FQ%{3DV3Le'TU  -bV455r   c                    | j                   | j                   S | j                  \  }}|dk(  ry|dk(  r|j                  d      ry| j                  |      }|y |j                  S )Nr   Fr   r  )r   r   r  r  r   )rC   r   version_strrA   s       r   r   zSpecifier.prereleases  sy     ($$$ !%

+t t 4 4T : ((5? $$$r   c                    || _         y r   )r   r   s     r   r   zSpecifier.prereleases  s
    !r   c                2    | j                   | j                  fS r   )r   r   rV   s    r   __getstate__zSpecifier.__getstate__  s     

D--..r   c                d   d | _         d | _        d | _        t        |t              rt        |      dk(  r*|\  }}t        |      rt        |      r|| _        || _	        y t        |      dk(  r`t        |d   t              rM|\  }}|j                  d      }|j                  dd      }t        |      rt        |      r|| _        || _	        y t        |t              rH|j                  d      }|j                  dd      }t        |      rt        |      r|| _        || _	        y t        d|      )Nr    r   r   r   invalidzCannot restore Specifier from )r   r   r   r!   r"   r#   r&   r*   r   r   dictget	TypeError)rC   stater%   r   _	slot_dicts         r   __setstate__zSpecifier.__setstate__  s   !#eU#5zQ$)!k!$'M+,F!%DJ(3D%5zQ:eAh#=$9 }}W-'mmNIF!$'M+,F!%DJ(3D%eT"99W%D))NI>Kd#k(B!
$/!8	BCCr   c                     | j                   d   S )z`The operator of this specifier.

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

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r   r*  rV   s    r   rA   zSpecifier.version-  r+  r   c                    | 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)>
        , prereleases= rw   rY   )>r   r   r[   r5   r$   rC   r)   s     r   r]   zSpecifier.__repr__6  sU       , T--01 	 4>>**+1SYM#bAAr   c                4     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   rV   s    r   r   zSpecifier.__str__H  s     v}}djj))r   c                    | j                   \  }}|dk(  s|j                  d      r||fS | j                  |      }t        ||dk7        }||fS )Nr   r  r   strip_trailing_zero)r   r  r  r   )rC   r   rA   r  canonical_versions        r   _canonical_speczSpecifier._canonical_specR  sc     JJ'u 0 0 6W$$11':0x4/?
 ***r   c                ,    t        | j                        S r   )rU   r9  rV   s    r   rW   zSpecifier.__hash__`  s    D(())r   c                    t        |t              r	 | j                  t        |            }nt        || j                        st        S | j
                  |j
                  k(  S # t        $ r	 t        cY S w xY w)a>  Whether or not the two Specifier-like objects are equal.

        :param other: The other object to check against.

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

        >>> Specifier("==1.2.3") == Specifier("== 1.2.3.0")
        True
        >>> (Specifier("==1.2.3", prereleases=False) ==
        ...  Specifier("==1.2.3", prereleases=True))
        True
        >>> Specifier("==1.2.3") == "==1.2.3"
        True
        >>> Specifier("==1.2.3") == Specifier("==1.2.4")
        False
        >>> Specifier("==1.2.3") == Specifier("~=1.2.3")
        False
        )r!   r$   r[   r   rN   r9  rO   s     r   rP   zSpecifier.__eq__c  si    & eS!&s5z2 E4>>2!!##u'<'<<< $ &%%&s   A" "A43A4c                >    t        | d| j                  |          }|S )N	_compare_)getattrr   )rC   r  operator_callables      r   _get_operatorzSpecifier._get_operator  s+    .5Idoob123/
 ! r   c           
         t        t        t        j                  t        t        |                  d d       }|dz  }| j                  ||      xr | j                  ||      S )Nr   r  )_version_joinlist	itertools	takewhile_is_not_suffix_version_split_compare_greater_than_equal_compare_equal)rC   prospectiver%   r  s       r   _compare_compatiblezSpecifier._compare_compatible  sd     $$^^D5IJKCRP

 	$00dC 
V4	
r   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  Fr6  )r   r   rG  _numeric_prefix_len)rC   r%   wildcard_split
normalized
split_specs        r   _get_wildcard_splitzSpecifier._get_wildcard_split  sO     --!-d3BiUSJ'
3J(*=j*IJN#1D r   c                &   |j                  d      rT| j                  |      \  }}t        t        |      d      }t	        |      }t        ||      }|d t        |       }||k(  S | j                  |      }	|	j                  st        |      }||	k(  S )Nr  Fr6  )	r  rQ  r   r   rG  	_left_padr#   r  r   )
rC   rJ  r%   rP  spec_numeric_lennormalized_prospectivesplit_prospectivepadded_prospectiveshortened_prospectiver  s
             r   rI  zSpecifier._compare_equal  s    ==+/+C+CD+I(J( &:,%&" !//E F "++<>N!O
 %77HZ$I!(J66  55d;L
  %%-k:,..r   c                (    | j                  ||       S r   )rI  rC   rJ  r%   s      r   _compare_not_equalzSpecifier._compare_not_equal  s    &&{D999r   c                <    t        |      | j                  |      k  S r   r   r  rZ  s      r   _compare_less_than_equalz"Specifier._compare_less_than_equal       {+t/I/I$/OOOr   c                <    t        |      | j                  |      k\  S r   r]  rZ  s      r   rH  z%Specifier._compare_greater_than_equal  r_  r   c                    | j                  |      }||k  sy|j                  s|j                  r|t        |      k\  ryyr   )r  r   r   rC   rJ  spec_strr%   s       r   _compare_less_thanzSpecifier._compare_less_than  sK     ))(3
 T!
 ""))3D99
 r   c                    | j                  |      }||kD  sy|j                  s|j                  rt        |      |k(  ry|j                  t	        |      |k(  ryyr   )r  is_postreleaser   r   r   rb  s       r   _compare_greater_thanzSpecifier._compare_greater_than  sg     ))(3
 T!
 ##**;'4/ (_[-IT-Q
 r   c                h    t        |      j                         t        |      j                         k(  S r   r$   r   rZ  s      r   _compare_arbitraryzSpecifier._compare_arbitrary  s&    ;%%'3t9??+<<<r   c                $    | j                  |      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   rC   r   s     r   __contains__zSpecifier.__contains__      & }}T""r   c                N    t        t        | j                  |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(   rC  r   r   s      r   r   zSpecifier.contains.  s#    2 DdVEFGGr   c                     y r   r   r   s       r   r   zSpecifier.filterI  r   r   c                     y r   r   r   s       r   r   zSpecifier.filterQ  r   r   c              #  Z  K   g }d}||n| j                   }| j                  | j                        }|D ]  }t        ||n ||            }	d}
|	0| j                  dk(  rj| j	                  || j
                        rN| nI| j                  dk(  r'| j	                  ||n ||      | j
                        }
n ||	| j
                        }
|
s|	|	j                  r|rd}| || j                  dus|j                  |        |s|| j                  dur|E d{    yyyy7 w)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   rj  rA   r   r   r   )rC   r   r   r   prereleases_versionsfound_non_prereleasesinclude_prereleasesr?  rA   parsed_versionmatchs              r   r   zSpecifier.filterY  sS    F  " % '2K8H8H 	
 !..t}}=   	9G,WWVNE%==E)d.E.ET\\/ "M%'//"{GGdll *.$,,G3%337J,0)!M (T->->e-K(//8/	98 &#!!.+++ / $ & ,s*   C	D+D+D+'D+6*D+ D)!	D+r/  N)r%   r$   r   r   r^   r_   )rA   r$   r^   Version | None)rA   r$   r^   r   r^   Sequence[_VersionRange])r  r$   r  r$   r^   list[_VersionRange]r   rR   r   r^   r_   )r^   z#tuple[tuple[str, str], bool | None]r%  ra   r^   r_   rd   )r^   ztuple[str, str]rb   r`   )r  r$   r^   CallableOperator)rJ  r   r%   r$   r^   r(   )r%   r$   r^   ztuple[list[str], int])rJ  r   rc  r$   r^   r(   )rJ  zVersion | strr%   r$   r^   r(   )r   zstr | Versionr^   r(   r   )r   UnparsedVersionr   r   r^   r(   r   r   r   r   r   ).r5   r6   r7   r8   re   _specifier_regex_strrecompileVERBOSE
IGNORECASEr   r   __annotations__rE   r  r  r  r	  r
  r   r   r   r  r(  r   rA   r]   r   r9  rW   rP   r@  rK  rQ  rI  r[  r^  rH  rd  rg  rj  rn  r   r   r   r   r   r   r   r   r     s   &IZx RZZ%%.

R]]0JF
 "	J 	$<L
!0
<6| % %6 " "/ DD    B$* + +*=:!
( "/H:PP2@=#*H6 __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  $(7;	O,O, !O, 5	O,
 
O,r   r   z([0-9]+)((?:a|b|c|rc)[0-9]+)c              #  0  K   g }g }d}| D ]v  }t        ||n ||            }|*|r| n"|j                  |       |j                  |       D|j                  s|s|E d{    d}| c|rf|j                  |       x |s|E d{    yy7 /7 w)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)##,,,"J %1&6   - 	 s*   A B"B#B1BBBBc                   g }| j                  d      \  }}}|j                  |xs d       |j                  d      D ]J  }t        j	                  |      }|r |j                  |j                                :|j                  |       L |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)rA   r   rG   r&  restr   ry  s          r   rG  rG    s~     F'',NE1d
MM%,3

3  ''-MM%,,.)MM$  Mr   c                6    | ^}}| ddj                  |       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)
componentsrG   r  s      r   rB  rB    s'     LEDWAchhtn%&&r   c                .     t         fddD               S )Nc              3  @   K   | ]  }j                  |        y wr   )r   ).0r  segments     r   	<genexpr>z!_is_not_suffix.<locals>.<genexpr>  s!      '-6"   )rI   abrcrH   )any)r  s   `r   rF  rF    s"     1P   r   c                H    d}| D ]  }|j                         s |S |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   rM  rM    s<     E  L 	
 Lr   c                T    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  )rM  )r  target_numeric_lennumeric_len
pad_neededs       r   rS  rS    sN     &e,K#k1JQNU<K NSEJ$6N%:MNNr   c                    | \  }}}|dk(  r|j                  d      sdS dS |dv ry|dk(  ry|dk(  r|j                  d      sd	S d
S |dk(  ry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   ry   rw   r   r   r   r      r   r  )r  r  )op_entryr&  verr  s       r   _operator_costr    s|     JAsB	TzT*q11	##	Tz	TzT*q11	U{
)"0
11r   c                     e Zd ZdZdZ	 	 d	 	 	 	 	 ddZddZedd       Zej                  dd       Zd dZ
d!d	Zd"d
Zd"dZd#dZd$dZd%dZd#dZd&dZd'dZd(dZd(dZd(dZd)dZ	 	 d*	 	 	 	 	 	 	 d+dZej4                  	 	 d,	 	 	 	 	 	 	 d-d       Zej4                  	 	 d,	 	 	 	 	 	 	 d.d       Z	 	 d*	 	 	 	 	 	 	 d/dZ	 d0	 	 	 	 	 	 	 d1dZy)2r   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_specsNc                   t        |t              re|j                  d      D cg c]#  }|j                         s|j                         % }}t	        t        t        |            | _        d|v | _        n1t	        |      | _        t        d | j                  D              | _        t        | j                        dk  | _        d| _        || _        d| _        yc c}w )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.
        ,r   c              3  6   K   | ]  }d t        |      v   ywr   Nr   r  ss     r   r  z(SpecifierSet.__init__.<locals>.<genexpr>t  s     %K!es1vo%K   r   N)r!   r$   r  r   r"   mapr   r  r  r  r#   r  r  r   r  )rC   
specifiersr   r  split_specifierss        r   rE   zSpecifierSet.__init__R  s    , j#& 4>3C3CC3HVaAGGI	VV16s9FV7W1XDK"':"5D
+DK #&%Kt{{%K"KD!$++.!3MQ (.2%  Ws
   CCc                    | j                   sQt        t        j                  t	        | j
                  t                          | _        d| _         d| _        d| _        | j
                  S )zBDeduplicate, sort, and cache specs for order-sensitive operations.r   TN)	r  r"   r"  fromkeyssortedr  r$   r  r  rV   s    r   _canonical_specszSpecifierSet._canonical_specs  sM    ""fT[[c.J KLDK"&D!%D%)D"{{r   c                    | j                   | j                   S | j                  sy t        d | j                  D              ryy )Nc              3  4   K   | ]  }|j                     y wr   rq  r  s     r   r  z+SpecifierSet.prereleases.<locals>.<genexpr>  s     2q}}2s   T)r   r  r  rV   s    r   r   zSpecifierSet.prereleases  sB     ($$$
 {{ 2dkk22r   c                     || _         d | _        y r   )r   r  r   s     r   r   zSpecifierSet.prereleases  s    !!%r   c                2    | j                   | j                  fS r   )r  r   rV   s    r   r  zSpecifierSet.__getstate__  s     T..//r   c                   d | _         d | _        t        |t              rft	        |      dk(  rk|\  }}t        |t              rVt        d |D              rDt        |      r9|| _        || _        t	        |      dk  | _	        t        d |D              | _        y t	        |      dk(  rt        |d   t              r|\  }}|j                  dd      }|j                  d      }t        |t              rt        t        |t                     }t        |t              rjt        d	 |D              rXt        |      rM|| _        || _        t	        | j                        dk  | _	        t        d
 | j                  D              | _        y t        |t              r|j                  dd      }|j                  d      }t        |t              rt        t        |t                     }t        |t              rjt        d |D              rXt        |      rM|| _        || _        t	        | j                        dk  | _	        t        d | j                  D              | _        y t#        d|      )Nr    c              3  <   K   | ]  }t        |t                y wr   r!   r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>       DJq)4D   r   c              3  6   K   | ]  }d t        |      v   ywr  r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s     -M!es1vo-Mr  r  r   r   r  c              3  <   K   | ]  }t        |t                y wr   r  r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  r  r  c              3  6   K   | ]  }d t        |      v   ywr  r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s     -S!es1vo-Sr  c              3  <   K   | ]  }t        |t                y wr   r  r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s     @Q
1i0@r  c              3  6   K   | ]  }d t        |      v   ywr  r   r  s     r   r  z,SpecifierSet.__setstate__.<locals>.<genexpr>  s     )Oa%3q6/)Or  z!Cannot restore SpecifierSet from )r  r  r!   r"   r#   allr*   r  r   r  r  r  r"  r#  	frozensetr  r$   r$  )rC   r%  specsr   r&  r'  s         r   r(  zSpecifierSet.__setstate__  s   !!%eU#5zQ%*"{ue,DeDD%k2"'DK(3D%*-e*/D'*--Mu-M*MD'5zQ:eAh#=$9!h3'mmN;eY/!&C"89Eue,DeDD%k2"'DK(3D%*-dkk*:a*?D'*--St{{-S*SD'eT"IIh+E))N3K%+fU455%(@%@@!+.#$/!&)$++&6!&;#&))O4;;)O&O#;E9EFFr   c                    | 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)>
        r.  r/  rw   rY   r0  r1  r2  s     r   r]   zSpecifierSet.__repr__  sU       , T--01 	 4>>**+1SYM#bAAr   c                N    dj                  d | j                         D              S )an  A string representation of the specifier set that can be round-tripped.

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

        >>> str(SpecifierSet(">=1.0.0,!=1.0.1"))
        '!=1.0.1,>=1.0.0'
        >>> str(SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False))
        '!=1.0.1,>=1.0.0'
        r  c              3  2   K   | ]  }t        |        y wr   r   r  s     r   r  z'SpecifierSet.__str__.<locals>.<genexpr>   s     @1A@s   )r  r  rV   s    r   r   zSpecifierSet.__str__  s"     xx@(=(=(?@@@r   c                4    t        | j                               S r   )rU   r  rV   s    r   rW   zSpecifierSet.__hash__  s    D))+,,r   c                    t        |t              rt        |      }nt        |t              st        S t               }| j                  |j                  z   |_        t        |j                        dk  |_        | j                  xs |j                  |_        d|_        | j                  | j                  |j                  k(  r|j                  |_	        |S |j                  | 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   rN   r  r#   r  r  r  r   r  )rC   rJ   	specifiers      r   __and__zSpecifierSet.__and__  s     eS! 'EE<0!! N	;;5	#&y'7'7#8A#=	 #'#6#6#N%:N:N	 "&	 $(9(9U=O=O(O%*%7%7I"  '%)%6%6I" 	 X r   c                    t        |t        t        f      rt        t        |            }nt        |t              st        S | j                         |j                         k(  S )a  Whether or not the two SpecifierSet-like objects are equal.

        :param other: The other object to check against.

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

        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.1")
        True
        >>> (SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False) ==
        ...  SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True))
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == ">=1.0.0,!=1.0.1"
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0")
        False
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.2")
        False
        )r!   r$   r   r   rN   r  rO   s     r   rP   zSpecifierSet.__eq__&  sN    & ec9-. U,EE<0!!$$&%*@*@*BBBr   c                ,    t        | j                        S )z7Returns the number of specifiers in this specifier set.)r#   r  rV   s    r   __len__zSpecifierSet.__len__@  s    4;;r   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  rV   s    r   __iter__zSpecifierSet.__iter__D  s     DKK  r   c                    | j                   }d}|D ]3  }||j                         }t        ||j                               }|r3 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)rC   r  r   r  s       r   _get_rangeszSpecifierSet._get_rangesN  sa     15 	A~*61<<>B	 >ABBr   c                    | j                   }||S | j                  sd| _         y| j                          }|s| j                         }|s| j                  du r| j                         }|| _         |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
        F)r  r  r  _check_arbitrary_unsatisfiabler   _check_prerelease_only_ranges)rC   cachedr   s      r   is_unsatisfiablezSpecifierSet.is_unsatisfiabled  sy     ''M{{%*D"%%''88:F$**e3779F!'r   c                    | j                         D ]Y  \  }}t        |j                        }| y|j                  ||j                  k  r y||j                  k(  sL|j                  sY y y)zWith prereleases=False, check if every range contains only
        pre-release versions (which would be excluded from matching).FT)r  r   rA   ri   )rC   r   r   nearests       r   r  z*SpecifierSet._check_prerelease_only_ranges  sh     !,,. 	LE5-emm<G}}$%--(?%--'EOO	 r   c                   | j                   D cg c]  }|j                  dk(  s| }}|sy|d   j                  j                         t	        fd|dd D              ryt        |d   j                        | j                  du rj                  ry| j                   D cg c]  }|j                  dk7  s| }}|syyt        fd|D               S c c}w c c}w )	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.
        r   Fr   c              3  X   K   | ]!  }|j                   j                         k7   # y wr   )rA   r   )r  r  firsts     r   r  z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>  s!     Aaqyy E)As   '*r   NTc              3  @   K   | ]  }|j                          y wr   rl  )r  r  	candidates     r   r  z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>  s     ?qzz),?r  )	r  r   rA   r   r  r   r   r   r  )rC   r  r   standardr  r  s       @@r   r  z+SpecifierSet._check_arbitrary_unsatisfiable  s     !%C1qzzU/BQC	C !$$**,A9QR=AA $IaL$8$89	
 %%''#{{B!ajjE.AABB?h????= D, Cs   CC'C"<C"c                $    | j                  |      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
        rl  rm  s     r   rn  zSpecifierSet.__contains__  ro  r   c                    t        |      }||r|j                  rd}|| j                  rt        |t              s|}n|}t        t        | j                  |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
        Trq  )r   r   r  r!   r   r(   rC  r   )rC   r   r   	installedrA   
check_items         r   r   zSpecifierSet.contains  se    @ "$'91F1FK ?t22:dG;TJ JDj\{KLMMr   c                     y r   r   r   s       r   r   zSpecifierSet.filter  r   r   c                     y r   r   r   s       r   r   zSpecifierSet.filter  r   r   c                t   || j                   | j                   }| j                  rft        | j                        dk(  r&| j                  d   j                  ||dn|      }n| j	                  ||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']
        r   r   T)r   r   rq  Fc              3  j   K   | ]*  }t        |n |            x	 j                  s| , y wr   )r   r   )r  r   r   rA   s     r   r  z&SpecifierSet.filter.<locals>.<genexpr>^  sA       /T SSW"00 s   03)r   r  r#   r   _filter_versionsr  r  )rC   r   r   r   filteredrA   s      ` @r   r   zSpecifierSet.filter  s    d 4#3#3#?**K ;; 4;;1$;;q>00(3(; 1   00(3(; 1  &-h<< $>!%$  *(C88r   c              #  \  K   | j                   't        d | j                  D        t              | _         | j                   }|du }|D ]]  t	        n             t        fd|D              s/ 4|rj                  rCt        fd|D              sZ _ yw)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     K   | ]6  }|j                  |j                        |j                  |j                  f 8 y wr   )r@  r   rA   )r  r%   s     r   r  z0SpecifierSet._filter_versions.<locals>.<genexpr>{  s6       ''6dmmTs   <>r  Fc              3     K   | ]9  \  }}}|d k(  xr* t              j                         |j                         k(   ; ywr  ri  )r  r&  r  r  r   s       r   r  z0SpecifierSet._filter_versions.<locals>.<genexpr>  sA      "3 %KDCIOO$5$DDs   ?Ac              3     K   | ]J  \  }}}|d k(  r4t        n             j                         |j                         k(  n ||       L ywr  ri  )r  op_fnr  r  r   r   r  s       r   r  z0SpecifierSet._filter_versions.<locals>.<genexpr>  s\       #E3 ; CKDSY7==?399;N63'(s   AA)r  r  r  r  r   r  r   )rC   r   r   r   opsexclude_prereleasesr   r  s     `   @@r   r  zSpecifierSet._filter_versionsk  s      %!' $ #"D   )U2 	D$S[Tc$iHF~ &)  J$)=)=  '*	  
'	s   A4B,:*B,%B,rz  )r  zstr | Iterable[Specifier]r   r   r^   r_   )r^   ztuple[Specifier, ...]r   r  )r^   z)tuple[tuple[Specifier, ...], bool | None]r  rd   rb   )rJ   zSpecifierSet | strr^   r   r`   )r^   zIterator[Specifier]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   )r5   r6   r7   r8   re   rE   r  r   r   r   r  r(  r]   r   rW   r  rP   r  r  r  r  r  r  rn  r   r   r   r   r  r   r   r   r   r   6  s   $I 13#'+3-+3 !+3 
	+3Z  & & &07GrB*A-BC4 !,B%@N#0 $(!%	+N+N !+N 	+N
 
+NZ __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  $(7;	^9^9 !^9 5	^9
 
^9H $(	,, 5, !	,
 
,r   r   )r^   	list[str])r%   ra   r^   zTypeGuard[tuple[str, str]])r)   ra   r^   zTypeGuard[bool | None])r0   tuple[int, ...]r^   r  )r   rg   r   r   r^   r(   )r   r}  r   r}  r^   r~  )rA   r   r^   r   )rA   r  r^   r{  )rK   r~   r^   r{  )r   r   r   r   r^   r   )rA   r$   r^   r  )r  r  r^   r$   )r  r$   r^   r(   )r  r  r^   rc   )r  r  r  rc   r^   r  )r  z!tuple[CallableOperator, str, str]r^   rc   )Lr8   
__future__r   r   r9   	functoolsrD  r  sysr   r   r   r   r   r   r	   r
   r   r   utilsr   rA   r   r   version_infor   typing_extensionsr   r   r&   r*   r+   r$   r  r,   r(   r  r.   r  r2   Enumr4   total_orderingr>   rg   r   r~   r"   _VersionRanger  r  r   r   r   r   r   r   r   r   r   r   r  r   ABCMetar   r   r  r  r  rG  rB  rF  rM  rS  r  r   r   r   r   <module>r     sr   # 
    	 
 
 
 
 ( ,w +0 CL%1I WcND01   'x0n 0=DII  ;Q ;Q ;Q| %H %H %HP %H %H %HP 
w(8$>? +{23MtU#tU#&.%9$;! ;)
!" 4KS
+@2999*	z 	Ockk Odr, r,j 

:;' ' "I' ' T,'O26a	= a	r   