
    #j>                    ^   U d Z ddlm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 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 er6ddlZdd	lmZmZmZ ej>                  d
k\  rddlm Z  nddl!m Z  ddl"m#Z# 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jZ                  ej\                  ej^                  ej`                  dZ1de2d<   d'dZ3 G d de4      Z5 G d dejl                        Z7 G d de7      Z8	 	 	 	 	 	 	 	 d(d Z9 G d! d"e7      Z:	 	 	 	 	 	 d)d#Z;y)*z
.. testsetup::

    from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier
    from packaging.version import Version
    )annotationsN)TYPE_CHECKINGAnyCallableFinalTypeVarUnion   )	
FULL_RANGEbounds_for_speccoerce_versionfilter_by_rangesintersect_specifier_boundsmatches_bounds_onlyranges_are_prerelease_onlyresolve_prereleasestrim_release)canonicalize_version)Version)IterableIteratorSequence)   
   )	TypeGuard)ranges)Interval)BaseSpecifierInvalidSpecifier	SpecifierSpecifierSetc                     t         S N)__all__     X/var/www/oz-panel.ru/ozpay-pub/venv/lib/python3.12/site-packages/packaging/specifiers.py__dir__r(   <   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_specr0   @   sI    4 	%IN	%tAw$	% tAw$	r&   c               .    | d u xs t        | t              S r#   )r+   bool)pres    r'   _validate_prer4   I   s    $;/*S$//r&   TUnparsedVersionVar)bound)>=<===!=z-dict[str, Callable[[Version, Version], bool]]_DIRECT_COMPARE_OPSr    c                   | j                   \  }}|j                  d      s|j                  yt        j	                  |      }| ||| j                  |            S |dv re| j                  |      }|j                  |j                  k7  s+t        |j                        t        |j                        k7  r|dk(  r||k  S ||kD  S yy)a!  Match ``parsed`` against ``specifier`` without building a range.

    Handles ``>=``, ``<=``, ``==``, ``!=``, ``<``, ``>`` when the spec is
    not a wildcard and ``parsed`` has no local. Returns ``None`` when the
    range path must be used. Pre-release policy is left to the caller.
    .*N)<>r?   )	_specendswithlocalr<   get_require_spec_versionepochr   release)	specifierparsedop_strver_strdirect_comparespec_vs         r'   _fast_matchrN   ]   s      ooOFG!9(,,V4N!fi&E&Eg&NOO009 <<6<<'<+G<NNL
 ,
 '-m6F?H&Hr&   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)__name__
__module____qualname____doc__r%   r&   r'   r   r   z   s    r&   r   c                     e Zd 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   zO
    Abstract base class for :class:`Specifier` and :class:`SpecifierSet`.
    r%   )_strc                    t        |       S )z Internal property for match_argsr.   selfs    r'   rU   zBaseSpecifier._str   s     4yr&   c                     y)z
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr%   rX   s    r'   __str__zBaseSpecifier.__str__       r&   c                     y)zF
        Returns a hash value for this Specifier-like object.
        Nr%   rX   s    r'   __hash__zBaseSpecifier.__hash__   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%   rY   others     r'   __eq__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%   rX   s    r'   prereleaseszBaseSpecifier.prereleases   r\   r&   c                     y)zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr%   rY   values     r'   rd   zBaseSpecifier.prereleases   r\   r&   Nc                     y)zR
        Determines if the given item is contained within this specifier.
        Nr%   )rY   itemrd   s      r'   containszBaseSpecifier.contains   r\   r&   c                     y r#   r%   rY   iterablerd   keys       r'   filterzBaseSpecifier.filter        (+r&   c                     y r#   r%   rl   s       r'   ro   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%   rl   s       r'   ro   zBaseSpecifier.filter   r\   r&   returnr.   ru   intra   objectru   r2   ru   bool | None)rg   r2   ru   Noner#   )ri   r.   rd   r{   ru   r2   N.rm   zIterable[UnparsedVersionVar]rd   r{   rn   r|   ru   zIterator[UnparsedVersionVar]rm   zIterable[T]rd   r{   rn   zCallable[[T], UnparsedVersion]ru   zIterator[T]NNrm   Iterable[Any]rd   r{   rn   'Callable[[Any], UnparsedVersion] | Noneru   Iterator[Any])rP   rQ   rR   rS   	__slots____match_args__propertyrU   abcabstractmethodr[   r^   rb   rd   setterrj   typingoverloadro   r%   r&   r'   r   r      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<   d%d&dZd'dZd(dZd)dZed*d       Zej&                  d+d       Zd,dZd-dZed.d       Zed.d       Zd.dZd.dZed/d       Zd0dZd1dZd2d Zd3d4d!Zej@                  	 	 d5	 	 	 	 	 	 	 d6d"       Z!ej@                  	 	 d5	 	 	 	 	 	 	 d7d#       Z!	 	 d8	 	 	 	 	 	 	 d9d$Z!y):r    a  This class abstracts handling of version specifiers.

    .. tip::

        It is generally not required to instantiate this manually. You should instead
        prefer to work with :class:`SpecifierSet` instead, which can parse
        comma-separated version specifiers (which is what package metadata contains).

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

    .. versionchanged:: 26.2

        Added a stable pickle format. Pickles created with packaging 26.2+ can
        be unpickled with future releases.  Backward compatibility with pickles
        from packaging < 26.2 is supported but may be removed in a future
        release.
    )_prereleases_rangesrA   _spec_versiona  
        (?:
            (?:
                # The identity operators allow for an escape hatch that will
                # do an exact string match of the version you wish to install.
                # This will not be parsed by PEP 440 and we cannot determine
                # any semantic meaning from it. This operator is discouraged
                # but included entirely as an escape hatch.
                ===  # Only match for the identity operator
                \s*
                [^\s;)]*  # The arbitrary version can be just about anything,
                          # we match everything except for whitespace, a
                          # semi-colon for marker support, and a closing paren
                          # since versions can be enclosed in them.
            )
            |
            (?:
                # The (non)equality operators allow for wild card and local
                # versions to be specified so we have to define these two
                # operators separately to enable that.
                (?:==|!=)            # Only match for equals and not equals

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)*   # release

                # You cannot use a wild card and a pre-release, post-release, a dev or
                # local version together so group them with a | and make them optional.
                (?:
                    \.\*  # Wild card syntax of .*
                    |
                    (?a:                                  # pre release
                        [-_\.]?
                        (alpha|beta|preview|pre|a|b|c|rc)
                        [-_\.]?
                        [0-9]*
                    )?
                    (?a:                                  # post release
                        (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                    )?
                    (?a:[-_\.]?dev[-_\.]?[0-9]*)?         # dev release
                    (?a:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local
                )?
            )
            |
            (?:
                # The compatible operator requires at least two digits in the
                # release segment.
                (?:~=)               # Only match for the compatible operator

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)+   # release  (We have a + instead of a *)
                (?:                   # pre release
                    [-_\.]?
                    (alpha|beta|preview|pre|a|b|c|rc)
                    [-_\.]?
                    [0-9]*
                )?
                (?:                                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?
                (?:[-_\.]?dev[-_\.]?[0-9]*)?          # dev release
            )
            |
            (?:
                # All other operators only allow a sub set of what the
                # (non)equality operators do. Specifically they do not allow
                # local versions to be specified nor do they allow the prefix
                # matching wild cards.
                (?:<=|>=|<|>)

                \s*
                v?
                (?:[0-9]+!)?          # epoch
                [0-9]+(?:\.[0-9]+)*   # release
                (?a:                   # pre release
                    [-_\.]?
                    (alpha|beta|preview|pre|a|b|c|rc)
                    [-_\.]?
                    [0-9]*
                )?
                (?a:                                   # post release
                    (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*)
                )?
                (?a:[-_\.]?dev[-_\.]?[0-9]*)?          # dev release
            )
        )
        z\s*
compatibleequal	not_equalless_than_equalgreater_than_equal	less_thangreater_than	arbitrary)~=r:   r;   r9   r8   r?   r@   ===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| _        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;   r9   r8   r*   r
   )	_regex	fullmatchr   strip
startswithrA   r   r   r   )rY   r/   rd   operatorversions        r'   __init__zSpecifier.__init__c  s     {{$$T*"%8#ABBzz|??5! $Ra$qr(..*:gH__;< $Ra$qr(..*:gH $Ra$qr(..*:gH'/&9
 ( :> 37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   )rY   r   version_specifiers      r'   _get_spec_versionzSpecifier._get_spec_version  sY    )d.@.@.Cw.N%%a((*73$%'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   )rY   r   spec_versions      r'   rE   zSpecifier._require_spec_version  s&     --g6'''r&   c                    | j                   | j                   S | j                  }| j                  }|dk(  rt        }n-| j	                  |j                  d            }t        |||      }|| _         |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   r   r   r   rE   removesuffixr   )rY   oprK   resultr   s        r'   
_to_rangeszSpecifier._to_ranges  sk     <<#<<]],,;)3F001E1Ed1KLG$R':Fr&   c                    | j                   | j                   S | j                  \  }}|dk(  ry|dk(  r|j                  d      ry| j                  |      }|y |j                  S )Nr;   Fr:   r>   )r   rA   rB   r   is_prerelease)rY   r   version_strr   s       r'   rd   zSpecifier.prereleases  sy     ($$$ !%

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

D--..r&   c                V   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
   rA   r   invalidzCannot restore Specifier from )r   r   r+   r,   r-   r0   r4   rA   r   dictrD   	TypeError)rY   stater/   rd   _	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   rA   rX   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   rX   s    r'   r   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= r?   ()>r   rd   	__class__rP   r.   rY   r3   s     r'   __repr__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{}{})formatrA   rX   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)rA   rB   rE   r   )rY   r   r   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#   )hashr   rX   s    r'   r^   zSpecifier.__hash__4  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   NotImplementedr   r`   s     r'   rb   zSpecifier.__eq__7  si    & eS!&s5z2 E4>>2!!##u'<'<<< $ &%%&s   A" "A43A4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
        rj   rY   ri   s     r'   __contains__zSpecifier.__contains__T      & }}T""r&   c                H   | j                   d   dk(  r&t        t        | j                  |g|                  S t	        |      }|y| t        | j                  | j                        }|du r|j                  ryt        | |      }||S t        | j                         |      S )a'  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:`~packaging.version.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

        .. versionchanged:: 26.0

            With ``prereleases=None``, a prerelease now matches. A single
            version has no alternatives, so the :pep:`440` rule to accept
            prereleases when nothing else satisfies the specifier applies.
            Earlier versions rejected it. An unparsable version now returns
            ``False`` instead of raising :exc:`~packaging.version.InvalidVersion`.
        r   r   rd   F)rA   r2   listro   r   r   r   rd   r   rN   r   r   )rY   ri   rd   rI   matchs        r'   rj   zSpecifier.containsi  s    D ::a=E!T[[$[[IJKK%>-d.?.?AQAQRK%F$8$8 D&)L"4??#4f==r&   c                     y r#   r%   rl   s       r'   ro   zSpecifier.filter  rp   r&   c                     y r#   r%   rl   s       r'   ro   zSpecifier.filter  rr   r&   c                   | t        | j                  | j                        }| j                  dk(  r3| j                  j                         fd|D        }t        ||      S t        | j                         ||      S )a  Filter items in the given iterable, that match the specifier.

        :param iterable:
            An iterable that can contain version strings and
            :class:`~packaging.version.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:`~packaging.version.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'}]

        .. versionchanged:: 26.1

            Added the ``key`` parameter.
        r   c              3  n   K   | ],  }t        |n |            j                         k(  r| . y wr#   )r.   lower).0ri   rn   
spec_lowers     r'   	<genexpr>z#Specifier.filter.<locals>.<genexpr>  s9      s{tD	:@@BjP s   25)	r   r   rd   r   r   r   _apply_prereleases_filterr   r   )rY   rm   rd   rn   matchesr   s      ` @r'   ro   zSpecifier.filter  sz    P -d.?.?AQAQRK==E!++-J$G
 -Wc;GG 18S+NNr&   r   N)r/   r.   rd   r{   ru   r|   )r   r.   ru   zVersion | None)r   r.   ru   r   ru   zSequence[Interval]rz   rg   r{   ru   r|   )ru   z#tuple[tuple[str, str], bool | None]r   ry   ru   r|   rt   )ru   ztuple[str, str]rv   rx   )ri   zstr | Versionru   r2   r#   )ri   UnparsedVersionrd   r{   ru   r2   r}   r~   r   r   r   )"rP   rQ   rR   rS   r   _specifier_regex_strrecompileVERBOSE
IGNORECASEr   r   __annotations__r   r   rE   r   r   rd   r   r   r   r   r   r   r[   r   r^   rb   r   rj   r   r   ro   r%   r&   r'   r    r       s   &IZx RZZ%%.

R]]0JF "	J 	!7F
!* % %6 " "/DB    B$* + +*=:#*6>p __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  $(7;	4O4O !4O 5	4O
 
4Or&   c                T    |t        |       S |rt        |       S fd| D        S )zApply ``prereleases=`` handling to an already-matched iterable.

    ``None`` means PEP 440 default (buffer pre-releases until a final
    appears); ``True`` yields everything; ``False`` drops pre-releases.
    c              3  h   K   | ])  }t        |n |            xj                  s| + y wr#   )r   r   )r   ri   rn   rI   s     r'   r   z,_apply_prereleases_filter.<locals>.<genexpr>  s<      $S[Tc$iHHFQ## 	s   /2)_pep440_filter_prereleasesiter)r   rn   rd   rI   s    ` @r'   r   r     s7     )'377G} r&   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Zd.dZd.dZd/dZ	 	 d0	 	 	 	 	 	 	 d1dZej<                  	 	 d2	 	 	 	 	 	 	 d3d       Zej<                  	 	 d2	 	 	 	 	 	 	 d4d       Z	 	 d0	 	 	 	 	 	 	 d5dZy)6r!   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   r   _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   NrW   r   ss     r'   r   z(SpecifierSet.__init__.<locals>.<genexpr><  s     %K!es1vo%K   r
   N)r+   r.   splitr   r,   mapr    r   r   anyr-   r   r   r   r   )rY   
specifiersrd   r   split_specifierss        r'   r   zSpecifierSet.__init__  s    , j#& 4>3C3CC3HVaAGGI	VV16s9FV7W1XDK"':"5D
+DK #&%Kt{{%K"KD!$++.!3.226 (#  Ws
   CCc                    | j                   sCt        t        j                  t	        | j
                  t                          | _        d| _         | j
                  S )zBDeduplicate, sort, and cache specs for order-sensitive operations.rn   T)r   r,   r   fromkeyssortedr   r.   rX   s    r'   _canonical_specszSpecifierSet._canonical_specsF  s=    ""fT[[c.J KLDK"&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  rX   s    r'   rd   zSpecifierSet.prereleasesM  sB     ($$$
 {{ 2dkk22r&   c                     || _         d | _        y r#   )r   r   rf   s     r'   rd   zSpecifierSet.prereleasesa  s    !!%r&   c                2    | j                   | j                  fS r#   )r   r   rX   s    r'   r   zSpecifierSet.__getstate__f  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>w       DJq)4D   r
   c              3  6   K   | ]  }d t        |      v   ywr   rW   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   rW   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   rW   r   s     r'   r   z,SpecifierSet.__setstate__.<locals>.<genexpr>  s     )Oa%3q6/)Or  z!Cannot restore SpecifierSet from )r   r   r+   r,   r-   allr4   r   r   r   r  r   r   rD   	frozensetr
  r.   r   )rY   r   specsrd   r   r   s         r'   r   zSpecifierSet.__setstate__l  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   r?   r   r   r   r   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#   rW   r   s     r'   r   z'SpecifierSet.__str__.<locals>.<genexpr>  s     @1A@s   )joinr  rX   s    r'   r[   zSpecifierSet.__str__  s"     xx@(=(=(?@@@r&   c                4    t        | j                               S r#   )r   r  rX   s    r'   r^   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                  |_        | 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
   zFCannot combine SpecifierSets with True and False prerelease overrides.)
r+   r.   r!   r   r   r-   r   r   r   
ValueError)rY   ra   rH   s      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!   r   r  r`   s     r'   rb   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   rX   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')>]
        )r   r   rX   s    r'   __iter__zSpecifierSet.__iter__  s     DKK  r&   c                    | j                   | j                   S t        d | j                  D              | _         | j                   S )zIntersect all specifiers into a single sequence of version ranges.

        Empty when unsatisfiable. Callers must ensure ``self._specs``
        is non-empty.
        c              3  <   K   | ]  }|j                           y wr#   )r   r   s     r'   r   z+SpecifierSet._get_ranges.<locals>.<genexpr>  s     1VQ!,,.1Vr  )r   r   r   rX   s    r'   _get_rangeszSpecifierSet._get_ranges  s8     <<#<<11V$++1VV||r&   c                    | j                   }||S | j                  sd| _         y| j                          }|s| j                         }|s'| j                  du rt        | 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

        .. versionadded:: 26.1
        F)r   r   r,  _check_arbitrary_unsatisfiablerd   r   )rY   cachedr   s      r'   is_unsatisfiablezSpecifierSet.is_unsatisfiable  s~      ''M{{%*D"%%''88:F$**e3/0@0@0BCF!'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#   )r   r   )r   r   firsts     r'   r   z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>N  s!     Aaqyy E)A   '*r
   NTc              3  @   K   | ]  }|j                          y wr#   r   )r   r   	candidates     r'   r   z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>f  s     ?qzz),?s   )	r   r   r   r   r  r   rd   r   r  )rY   r   r   standardr6  r3  s       @@r'   r.  z+SpecifierSet._check_arbitrary_unsatisfiableA  s     !%C1qzzU/BQC	C !$$**,A9QR=AA #9Q<#7#78	
 %%''#{{B!ajjE.AABB?h????= D, Cs   CC'C"<C"c                0    ddl m} |j                  |       S )ac  Return the :class:`~packaging.ranges.VersionRange` this set accepts.

        An empty set yields the full range; an unsatisfiable set yields the
        empty range. ``===`` specifiers contribute literal-string admission.

        >>> SpecifierSet(">=1.0,<2.0").to_range()
        <VersionRange '[1.0, 2.0.dev0)'>

        .. versionadded:: 26.3
        r
   )VersionRange)r   r9  _from_specifier_set)rY   r9  s     r'   to_rangezSpecifierSet.to_rangeh  s     	)//55r&   c                    t        |t              st        d      | j                  s|j                  rt	        d      y )Nzexpected a SpecifierSetz+set relations do not support === specifiers)r+   r!   r   r   r#  r`   s     r'   _check_relation_operandz$SpecifierSet._check_relation_operandw  s:    %.566%"6"6JKK #7r&   c                ~    | j                  |       | j                         j                  |j                               S )a=  Return whether every version matching this set also matches other.

        :raises ValueError:
            If either set uses ``===`` specifiers, or the two sets were
            given different ``prereleases`` arguments (unset on one side
            counts as different).
        :raises TypeError:
            If other is not a :class:`SpecifierSet`.

        >>> SpecifierSet(">=3.12,<3.13").is_subset(SpecifierSet(">=3.12"))
        True
        >>> SpecifierSet(">=3.12").is_subset(SpecifierSet(">=3.12,<3.13"))
        False

        .. versionadded:: 26.3
        )r=  r;  	is_subsetr`   s     r'   r?  zSpecifierSet.is_subset}  s0    " 	$$U+}}(()9::r&   c                ~    | j                  |       | j                         j                  |j                               S )a  Return whether every version matching other also matches this set.

        :raises ValueError:
            If either set uses ``===`` specifiers, or the two sets were
            given different ``prereleases`` arguments (unset on one side
            counts as different).
        :raises TypeError:
            If other is not a :class:`SpecifierSet`.

        >>> SpecifierSet(">=3.12").is_superset(SpecifierSet(">=3.12,<3.13"))
        True

        .. versionadded:: 26.3
        )r=  r;  is_supersetr`   s     r'   rA  zSpecifierSet.is_superset  s0     	$$U+}}**5>>+;<<r&   c                ~    | j                  |       | j                         j                  |j                               S )a.  Return whether this set and other share no matching versions.

        :raises ValueError:
            If either set uses ``===`` specifiers, or the two sets were
            given different ``prereleases`` arguments (unset on one side
            counts as different).
        :raises TypeError:
            If other is not a :class:`SpecifierSet`.

        >>> SpecifierSet("<3.12").is_disjoint(SpecifierSet(">=3.12"))
        True
        >>> SpecifierSet("<3.12").is_disjoint(SpecifierSet(">=3.11"))
        False

        .. versionadded:: 26.3
        )r=  r;  is_disjointr`   s     r'   rC  zSpecifierSet.is_disjoint  s0    " 	$$U+}}**5>>+;<<r&   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
        r   r   s     r'   r   zSpecifierSet.__contains__  r   r&   c                
   t        |      }||r|j                  rd}|| j                  rt        |t              s|}n|}|| j                  s|j
                  | j                  rx|j                  r|du s|| j                  du ry| j                  }|=| j                  D ]  }t        ||      }| n|r y y| j                         x}| _        t        ||      S 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:`~packaging.version.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

        .. versionchanged:: 26.0

            With ``prereleases=None``, a prerelease now matches. A single
            version has no alternatives, so the :pep:`440` rule to accept
            prereleases when nothing else satisfies the specifiers applies.
            Earlier versions rejected it. An unparsable version now returns
            ``False`` instead of raising :exc:`~packaging.version.InvalidVersion`.
        TFr   )r   r   r   r+   r   rC   r   r   r   rN   r,  r   r2   r   ro   )	rY   ri   rd   	installedr   
check_itemboundsr/   r   s	            r'   rj   zSpecifierSet.contains  s   P !&91F1FK ?t22:dG;TJ J ''%$$u$'D,=,=,F\\F~
 !KK  D'g6E} $   (,(8(8(::&vw77Dj\{KLMMr&   c                     y r#   r%   rl   s       r'   ro   zSpecifierSet.filter$  rp   r&   c                     y r#   r%   rl   s       r'   ro   zSpecifierSet.filter,  rr   r&   c                &   || j                   | j                   }| j                  r]| j                  r%| j                  fd|D        }t        ||      S | j                  }|| j                         }t        |||      S t        ||      S )a  Filter items in the given iterable, that match the specifiers in this set.

        :param iterable:
            An iterable that can contain version strings and
            :class:`~packaging.version.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:`~packaging.version.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']

        .. versionchanged:: 26.0

            Prerelease filtering now follows the PEP 440 recommendation of
            yielding prereleases only when no final release is present.

        .. versionchanged:: 26.1

            Added the ``key`` parameter.
        c              3  N   K   | ]  t        fd D              r  yw)c              3  X   K   | ]!  }|j                  n       d       # y w)NTr   r   )r   r   ri   rn   s     r'   r   z0SpecifierSet.filter.<locals>.<genexpr>.<genexpr>z  s1       

3;4CISW
Xr4  N)r  )r   ri   rn   r  s    @r'   r   z&SpecifierSet.filter.<locals>.<genexpr>w  s.       !&  s   !%)rd   r   r   r   r   r,  r   )rY   rm   rd   rn   r   r   r  s      `  @r'   ro   zSpecifierSet.filter4  s    x 4#3#3#?**K;;"" ( 1#{KK\\F~))+#FHc;GG )3DDr&   r   )r  zstr | Iterable[Specifier]rd   r{   ru   r|   )ru   ztuple[Specifier, ...]rz   r   )ru   z)tuple[tuple[Specifier, ...], bool | None]r   rt   rv   )ra   zSpecifierSet | strru   r!   rx   )ru   zIterator[Specifier]r   )ru   r2   )ru   zranges.VersionRange)ra   ry   ru   r|   )ra   r!   ru   r2   )ri   r   ru   r2   r   )ri   r   rd   r{   rF  r{   ru   r2   r}   r~   r   r   ) rP   rQ   rR   rS   r   r   r  r   rd   r   r   r   r   r[   r^   r$  rb   r'  r)  r,  r0  r.  r;  r=  r?  rA  rC  r   rj   r   r   ro   r%   r&   r'   r!   r!     s   $I 13#'*(-*( !*( 
	*(X  & & &07GrB*A-@C4 !
!F%@N6L;(=$=(#0 $(!%	VNVN !VN 	VN
 
VNp __ $(	+.+ !+ 	+
 
&+ + __ $(.1	 ! ,	
 
  $(7;	SESE !SE 5	SE
 
SEr&   r!   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   appendr   )rm   rn   all_nonfinalarbitrary_stringsfound_finalri   rI   s          r'   r   r     s      !L#%K &TC> 
!((.##D)##,,,"J %1&6   - 	 s*   A B"B#B1BBBB)ru   z	list[str])r/   ry   ru   zTypeGuard[tuple[str, str]])r3   ry   ru   zTypeGuard[bool | None])rH   r    rI   r   ru   r{   )r   r   rn   r   rd   r{   ru   r   )rm   r   rn   r   ru   r   )<rS   
__future__r   r   r   r   r   r   r   r   r   r	   r   r   r   r   r   r   r   r   r   r   utilsr   r   r   syscollections.abcr   r   r   version_infor   typing_extensionsr   r   r   r$   r(   r0   r4   r5   r.   r   r6   __ge____le__rb   __ne__r<   r   rN   r#  r   ABCMetar   r    r   r!   r   r%   r&   r'   <module>r]     sW   # 
 	  
 
 
 ( <<
7"$/!0 CL%1I  ..
..
..
..	F B :	z 	Sckk SlIO IOX	0  	,I
E= I
EX' ' "I' ' r&   