
    Ki0                    `   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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 g dZd6d	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<   d7dZ  G d dejB                        Z"ejF                   G d d             Z$ejF                   G d d             Z%ejF                   G d d             Z&ejN                  reee$df   Z(e)e%e&f   Z* e%dd      Z+ e&dd      Z,e+e,ffZ-ded<   d8dZ.	 	 	 	 	 	 d9dZ/d:dZ0d:dZ1d;d Z2d:d!Z3d:d"Z4d:d#Z5	 	 	 	 d<d$Z6 G d% d&e7      Z8 G d' d(ejr                  )      Z: G d* d+e:      Z; ejx                  d,      Z=	 	 	 	 	 	 d=d-Z>d>d.Z?d?d/Z@d@d0ZAdAd1ZBdBd2ZCdCd3ZD G d4 d5e:      ZEy)Dz
.. testsetup::

    from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
    from packaging.version import Version
    )annotationsN)AnyCallableFinalIterableIteratorSequenceTypeVarUnion   )canonicalize_version)InvalidVersionVersion)BaseSpecifierInvalidSpecifier	SpecifierSpecifierSetc                     t         S N)__all__     `/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/packaging/specifiers.py__dir__r       s    Nr   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)len)releaseends     r   _trim_releaser#   -   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   r%   r%   5   s    ?499;L$))+Kr   r%   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   )r2   r0   r#   r!   r1   )selfr2   kinds      r   __init__z_BoundaryVersion.__init__T   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)r2   epochr#   r!   r1   prer0   r%   r,   postdev)r4   othervs      r   
_is_familyz_BoundaryVersion._is_familyY   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   )
isinstancer/   r2   r0   NotImplementedr4   r<   s     r   __eq__z_BoundaryVersion.__eq__h   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/   r2   r0   valuer>   rB   s     r   __lt__z_BoundaryVersion.__lt__m   so    e-.||u}},||emm33::##ekk&7&777??5))BdllU.BBr   c                D    t        | j                  | j                  f      S r   )hashr2   r0   r4   s    r   __hash__z_BoundaryVersion.__hash__t   s    T\\4::.//r   c                |    | j                   j                   d| j                  d| j                  j                   dS )N(z, ))	__class__r&   r2   r0   namerI   s    r   __repr__z_BoundaryVersion.__repr__w   s4    ..))*!DLL+;2djjoo=NaPPr   N)r2   r   r5   r%   returnNone)r<   r   rQ   boolr<   objectrQ   rS   )r<   z_BoundaryVersion | VersionrQ   rS   rQ   intrQ   str)r&   r'   r(   r)   	__slots__r6   r>   rC   rF   rJ   rP   r   r   r   r/   r/   <   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.
    	inclusiver2   c                     || _         || _        y r   r2   r^   r4   r2   r^   s      r   r6   z_LowerBound.__init__       "r   c                    t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r   r@   r\   rA   r2   r^   rB   s     r   rC   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 )NFrd   rB   s     r   rF   z_LowerBound.__lt__   sq    %-!!<<==,,== <<5==(<<%--//~~5eoo"55r   c                D    t        | j                  | j                  f      S r   rH   r2   r^   rI   s    r   rJ   z_LowerBound.__hash__       T\\4>>233r   c                t    | j                   rdnd}d| j                  j                   d| | j                  dS )N[rL   < >r^   rN   r&   r2   r4   brackets     r   rP   z_LowerBound.__repr__   s8    #S4>>**+1WIdll5EQGGr   Nr2   _VersionOrBoundaryr^   rS   rQ   rR   rT   )r<   r\   rQ   rS   rV   rX   
r&   r'   r(   r)   rZ   r6   rC   rF   rJ   rP   r   r   r   r\   r\   {   )     )I#S
64H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)_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.
    r]   c                     || _         || _        y r   r`   ra   s      r   r6   z_UpperBound.__init__   rb   r   c                    t        |t              st        S | j                  |j                  k(  xr | j                  |j                  k(  S r   r@   rw   rA   r2   r^   rB   s     r   rC   z_UpperBound.__eq__   re   r   c                    t        |t              st        S | j                  y|j                  y| j                  |j                  k7  r| j                  |j                  k  S | j                   xr |j                  S NFTrz   rB   s     r   rF   z_UpperBound.__lt__   se    %-!!<<== <<5==(<<%--//>>!5eoo5r   c                D    t        | j                  | j                  f      S r   rh   rI   s    r   rJ   z_UpperBound.__hash__   ri   r   c                t    | j                   rdnd}d| j                  j                   d| j                  | dS )N]rM   rl   rm   rn   ro   rp   s     r   rP   z_UpperBound.__repr__   s8    #S4>>**+1T\\,<WIQGGr   Nrr   rT   )r<   rw   rQ   rS   rV   rX   rt   r   r   r   rw   rw      ru   r   rw   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.Fr`   )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   r8   r!   r;   )r!   r   
from_partsr8   )r2   r!   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   r8   r!   r2   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r:   r;   r   r   r   s    r   
_post_baser     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r;   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)r9   r;   r   r   r   )r:   r   )r@   r/   r2   is_prereleaser   r:   )r=   innerks      r   _nearest_non_prereleaser   &  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)r&   r'   r(   r)   r   r   r   r   r   ;  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rY   rI   s    r   r   zBaseSpecifier._strK  s     4yr   c                     y)z
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr   rI   s    r   __str__zBaseSpecifier.__str__P      r   c                     y)zF
        Returns a hash value for this Specifier-like object.
        Nr   rI   s    r   rJ   zBaseSpecifier.__hash__W  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   rB   s     r   rC   zBaseSpecifier.__eq__]  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   rI   s    r   prereleaseszBaseSpecifier.prereleasesf  r   r   c                     y)zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr   r4   rE   s     r   r   zBaseSpecifier.prereleaseso  r   r   Nc                     y)zR
        Determines if the given item is contained within this specifier.
        Nr   r4   itemr   s      r   containszBaseSpecifier.containsv  r   r   c                     y r   r   r4   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   rX   rV   rT   rQ   bool | None)rE   rS   rQ   rR   r   )r   rY   r   r   rQ   rS   N.r   zIterable[UnparsedVersionVar]r   r   r   rR   rQ   zIterator[UnparsedVersionVar]r   zIterable[T]r   r   r   zCallable[[T], UnparsedVersion]rQ   zIterator[T]NNr   Iterable[Any]r   r   r   'Callable[[Any], UnparsedVersion] | NonerQ   Iterator[Any])r&   r'   r(   rZ   __match_args__propertyr   abcabstractmethodr   rJ   rC   r   setterr   typingoverloadr   r   r   r   r   r   G  s   IN  	  	 
 	       	 
 __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  	 $(7;			 !	 5		
 
	 	r   r   )	metaclassc            	      L   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<   d/d0dZd1dZd2dZd3dZd4dZd4dZed5d       Zej*                  d6d       Zed7d       Zed7d       Zd7dZd7dZed8d       Zd9d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'dAdBd+Z(e)jT                  	 	 dC	 	 	 	 	 	 	 dDd,       Z+e)jT                  	 	 dC	 	 	 	 	 	 	 dEd-       Z+	 	 dF	 	 	 	 	 	 	 dGd.Z+y)Hr   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).
    )_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)~===!=<=>=rl   rn   ===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   N   )r   r   r   r   r      r   )
_regex	fullmatchr   strip
startswithr   r   r   r   r   )r4   specr   operatorr2   s        r   r6   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   )r4   r2   version_specifiers      r   _get_spec_versionzSpecifier._get_spec_version<  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   )r4   r2   spec_versions      r   _require_spec_versionzSpecifier._require_spec_versionH  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   r2   r   endswith_wildcard_ranges_standard_ranges)r4   opver_strr   s       r   
_to_rangeszSpecifier._to_rangesR  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   r\   rw   _NEG_INF_POS_INF)r4   r  r  baser   r   s         r   r  zSpecifier._wildcard_rangesj  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   rn   r   r   r   r   Frl   +r   r   r   r   )r!   Unknown operator: )r   r\   r	  r  rw   r/   r%   r,   r;   r   r:   r-   r   r   r!   r   
ValueError)
r4   r  r  r=   	lower_verr   	has_localafter_localsr   prefixs
             r   r  zSpecifier._standard_rangesw  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   )r4   r   version_strr2   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                     | j                   d   S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   r   rI   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  rI   s    r   r2   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= rl   rL   )>r   r   rN   r&   rY   r4   r9   s     r   rP   zSpecifier.__repr__  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   rI   s    r   r   zSpecifier.__str__  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   )r4   r   r2   r   canonical_versions        r   _canonical_speczSpecifier._canonical_spec  sc     JJ'u 0 0 6W$$11':0x4/?
 ***r   c                ,    t        | j                        S r   )rH   r&  rI   s    r   rJ   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@   rY   rN   r   rA   r&  rB   s     r   rC   zSpecifier.__eq__  si    & eS!&s5z2 E4>>2!!##u'<'<<< $ &%%&s   A" "A43A4c                >    t        | d| j                  |          }|S )N	_compare_)getattrr   )r4   r  operator_callables      r   _get_operatorzSpecifier._get_operator1  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)r4   prospectiver   r  s       r   _compare_compatiblezSpecifier._compare_compatible7  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  Fr#  )r   r   r4  _numeric_prefix_len)r4   r   wildcard_split
normalized
split_specs        r   _get_wildcard_splitzSpecifier._get_wildcard_splitK  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   Fr#  )	r   r>  r   r   r4  	_left_padr    r   r   )
r4   r7  r   r=  spec_numeric_lennormalized_prospectivesplit_prospectivepadded_prospectiveshortened_prospectiver   s
             r   r6  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   )r6  r4   r7  r   s      r   _compare_not_equalzSpecifier._compare_not_equal  s    &&{D999r   c                <    t        |      | j                  |      k  S r   r   r   rG  s      r   _compare_less_than_equalz"Specifier._compare_less_than_equal       {+t/I/I$/OOOr   c                <    t        |      | j                  |      k\  S r   rJ  rG  s      r   r5  z%Specifier._compare_greater_than_equal  rL  r   c                    | j                  |      }||k  sy|j                  s|j                  r|t        |      k\  ryyr|   )r   r   r   r4   r7  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   rO  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   rY   r   rG  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   r4   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   )rS   r0  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.filter  r   r   c                     y r   r   r   s       r   r   zSpecifier.filter  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   rW  r2   r   r   r   )r4   r   r   r   prereleases_versionsfound_non_prereleasesinclude_prereleasesr,  r2   parsed_versionmatchs              r   r   zSpecifier.filter
  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   rY   r   r   rQ   rR   )r2   rY   rQ   Version | None)r2   rY   rQ   r   rQ   Sequence[_VersionRange])r  rY   r  rY   rQ   list[_VersionRange]r   rE   r   rQ   rR   rX   )rQ   ztuple[str, str]rV   rT   )r  rY   rQ   CallableOperator)r7  r   r   rY   rQ   rS   )r   rY   rQ   ztuple[list[str], int])r7  r   rP  rY   rQ   rS   )r7  zVersion | strr   rY   rQ   rS   )r   zstr | VersionrQ   rS   r   )r   UnparsedVersionr   r   rQ   rS   r   r   r   r   r   ),r&   r'   r(   r)   rZ   _specifier_regex_strrecompileVERBOSE
IGNORECASEr   r   __annotations__r6   r   r   r  r  r  r   r   r   r   r2   rP   r   r&  rJ   rC   r-  r8  r>  r6  rH  rK  r5  rQ  rT  rW  r[  r   r   r   r   r   r   r   r   r     s   IZx RZZ%%.

R]]0JF
 "	J 	$<L
!0
<6| % %6 " "    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_prereleasesrz  _  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)r2   r   r8   _restr   rf  s          r   r4  r4    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)
componentsr8   r  s      r   r/  r/    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"   )r;   abrcr:   )any)r  s   `r   r3  r3    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   r:  r:    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}  )r:  )r  target_numeric_lennumeric_len
pad_neededs       r   r@  r@    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   rn   rl   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'dZej0                  	 	 d(	 	 	 	 	 	 	 d)d       Zej0                  	 	 d(	 	 	 	 	 	 	 d*d       Z	 	 d&	 	 	 	 	 	 	 d+dZ	 d,	 	 	 	 	 	 	 d-dZy).r   zThis 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.
    )_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>  s     %K!es1vo%Ks   r   N)r@   rY   r  r   tuplemapr   r  r  r  r    r  r  r   r  )r4   
specifiersr   r  split_specifierss        r   r6   zSpecifierSet.__init__  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  dictfromkeyssortedr  rY   r  r  rI   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   r^  r  s     r   r  z+SpecifierSet.prereleases.<locals>.<genexpr><  s     2q}}2s   T)r   r  r  rI   s    r   r   zSpecifierSet.prereleases-  sB     ($$$
 {{ 2dkk22r   c                     || _         d | _        y r   )r   r  r   s     r   r   zSpecifierSet.prereleasesA  s    !!%r   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  rl   rL   r  r  r  s     r   rP   zSpecifierSet.__repr__F  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>f  s     @1A@s   )r  r  rI   s    r   r   zSpecifierSet.__str__[  s"     xx@(=(=(?@@@r   c                4    t        | j                               S r   )rH   r  rI   s    r   rJ   zSpecifierSet.__hash__h  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@   rY   r   rA   r  r    r  r  r  r   r  )r4   r<   	specifiers      r   __and__zSpecifierSet.__and__k  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@   rY   r   r   rA   r  rB   s     r   rC   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  rI   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  rI   s    r   __iter__zSpecifierSet.__iter__  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)r4   specsr   r  s       r   _get_rangeszSpecifierSet._get_ranges  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)r4   cachedr   s      r   is_unsatisfiablezSpecifierSet.is_unsatisfiable  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   r2   r^   )r4   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   )r2   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   rY  )r  r  	candidates     r   r  z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>  s     ?qzz),?r  )	r  r   r2   r   r  r   r   r   all)r4   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
        rY  rZ  s     r   r[  zSpecifierSet.__contains__  r\  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
        Tr^  )r   r   r  r@   r   rS   r0  r   )r4   r   r   	installedr2   
check_items         r   r   zSpecifierSet.contains4  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.filtera  r   r   c                     y r   r   r   s       r   r   zSpecifierSet.filteri  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   r^  Fc              3  j   K   | ]*  }t        |n |            x	 j                  s| , y wr   )r   r   )r  r   r   r2   s     r   r  z&SpecifierSet.filter.<locals>.<genexpr>  sA       /T SSW"00 s   03)r   r  r    r   _filter_versionsrz  r  )r4   r   r   r   filteredr2   s      ` @r   r   zSpecifierSet.filterq  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   r2   )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  rV  )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  rV  )r  op_fnr  r  r   r   ry  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   )r4   r   r   r   opsexclude_prereleasesr   ry  s     `   @@r   r  zSpecifierSet._filter_versions  s      %!' $ #"D   )U2 	D$S[Tc$iHF~ &)  J$)=)=  '*	  
'	s   A4B,:*B,%B,rg  )r  zstr | Iterable[Specifier]r   r   rQ   rR   )rQ   ztuple[Specifier, ...]r   rl  rX   rV   )r<   zSpecifierSet | strrQ   r   rT   )rQ   zIterator[Specifier]ri  )rQ   rS   )r   rn  rQ   rS   r   )r   rn  r   r   r  r   rQ   rS   r   r   r   r   r   )r   r   r   r   r   r   rQ   r   )r&   r'   r(   r)   rZ   r6   r  r   r   r   rP   r   rJ   r  rC   r  r  r  r  r  r  r[  r   r   r   r   r  r   r   r   r   r     s   I 13#'+3-+3 !+3 
	+3Z  & & &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   )rQ   	list[str])r!   tuple[int, ...]rQ   r  )r   r\   r   rw   rQ   rS   )r   rj  r   rj  rQ   rk  )r2   r   rQ   r   )r2   rn  rQ   rh  )r=   rs   rQ   rh  )r   r   r   r   rQ   r   )r2   rY   rQ   r  )r  r  rQ   rY   )r  rY   rQ   rS   )r  r  rQ   rW   )r  r  r  rW   rQ   r  )r  z!tuple[CallableOperator, str, str]rQ   rW   )Fr)   
__future__r   r   r*   	functoolsr1  rp  r   r   r   r   r   r   r	   r
   r   utilsr   r2   r   r   r   r   r   rY   rn  r   rS   rm  r   rt  r#   Enumr%   total_orderingr/   r\   rw   TYPE_CHECKINGrs   r  _VersionRanger  r	  r   r   r   r   r   r   r   r   r   r   r  r   ABCMetar   r   rq  r  rz  r4  r/  r3  r:  r@  r  r   r   r   r   <module>r     sF   # 
    	  U U U ' , 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@, @,F 

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