a
     ñ»j>Î  ã                   @  sÞ  U d Z ddlmZ ddlZddlZddlZddl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rêd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œdd„Z&dddœdd„Z'dddœdd„Z(e
dƒZ)eee*f Z+e
de+d�Z,ej-ej.ej/ej0dœZ1d e2d!< d"d#d$d%œd&d'„Z3G d(d)„ d)e4ƒZ5G d*d+„ d+ej6d,�Z7G d-d"„ d"e7ƒZ8d.d/d$d0d1œd2d3„Z9G d4d5„ d5e7ƒZ:d.d/d0d6œd7d8„Z;dS )9zŠ
.. 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ÚSpecifierSetz	list[str]©Úreturnc                   C  s   t S ©N)Ú__all__© r%   r%   ú:E:\soccer\ml_env\Lib\site-packages\packaging/specifiers.pyÚ__dir__<   s    r'   ÚobjectzTypeGuard[tuple[str, str]])Úspecr"   c                C  s2   t | tƒo0t| ƒdko0t | d tƒo0t | d tƒS )Né   r   r	   )Ú
isinstanceÚtupleÚlenÚstr)r)   r%   r%   r&   Ú_validate_spec@   s    

ÿþür/   zTypeGuard[bool | None])Úprer"   c                C  s   | d u pt | tƒS r#   )r+   Úbool)r0   r%   r%   r&   Ú_validate_preI   s    r2   ÚTÚUnparsedVersionVar)Úbound)ú>=ú<=ú==ú!=z-dict[str, Callable[[Version, Version], bool]]Ú_DIRECT_COMPARE_OPSr   r   úbool | None)Ú	specifierÚparsedr"   c                 C  s–   | j \}}| d¡s|jdur"dS t |¡}|durD|||  |¡ƒS |dv r’|  |¡}|j|jksvt|jƒt|jƒkrŽ|dkr†||k S ||kS dS dS )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)r<   r=   Úop_strÚver_strZdirect_compareZspec_vr%   r%   r&   Ú_fast_match]   s    


ÿrJ   c                   @  s   e Zd ZdZdS )r   a  
    Raised when attempting to create a :class:`Specifier` with a specifier
    string that is invalid.

    >>> Specifier("lolwat")
    Traceback (most recent call last):
        ...
    packaging.specifiers.InvalidSpecifier: Invalid specifier: 'lolwat'
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r%   r%   r%   r&   r   z   s   r   c                   @  s  e Zd ZdZdZdZeddœdd„ƒZej	ddœdd	„ƒZ
ej	d
dœdd„ƒZej	dddœdd„ƒZeej	ddœdd„ƒƒZejdddœdd„ƒZej	d*ddddœdd„ƒZejd+dddddœd d!„ƒZejd,d"dd#d$dœd%d!„ƒZej	d-d&dd'd(dœd)d!„ƒZdS ).r   zO
    Abstract base class for :class:`Specifier` and :class:`SpecifierSet`.
    r%   )Ú_strr.   r!   c                 C  s   t | ƒS )z Internal property for match_args©r.   ©Úselfr%   r%   r&   rO   Ž   s    zBaseSpecifier._strc                 C  s   dS )zŽ
        Returns the str representation of this Specifier-like object. This
        should be representative of the Specifier itself.
        Nr%   rQ   r%   r%   r&   Ú__str__“   s    zBaseSpecifier.__str__Úintc                 C  s   dS )zF
        Returns a hash value for this Specifier-like object.
        Nr%   rQ   r%   r%   r&   Ú__hash__š   s    zBaseSpecifier.__hash__r(   r1   ©Úotherr"   c                 C  s   dS )z«
        Returns a boolean representing whether or not the two Specifier-like
        objects are equal.

        :param other: The other object to check against.
        Nr%   ©rR   rW   r%   r%   r&   Ú__eq__    s    zBaseSpecifier.__eq__r;   c                 C  s   dS )zîWhether 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%   rQ   r%   r%   r&   Úprereleases©   s    zBaseSpecifier.prereleasesÚNone©Úvaluer"   c                 C  s   dS )zQSetter for :attr:`prereleases`.

        :param value: The value to set.
        Nr%   ©rR   r]   r%   r%   r&   rZ   ²   s    N©ÚitemrZ   r"   c                 C  s   dS )zR
        Determines if the given item is contained within this specifier.
        Nr%   )rR   r`   rZ   r%   r%   r&   Úcontains¹   s    zBaseSpecifier.contains.úIterable[UnparsedVersionVar]úIterator[UnparsedVersionVar]©ÚiterablerZ   Úkeyr"   c                 C  s   d S r#   r%   ©rR   re   rZ   rf   r%   r%   r&   Úfilter¿   s    zBaseSpecifier.filterúIterable[T]úCallable[[T], UnparsedVersion]úIterator[T]c                 C  s   d S r#   r%   rg   r%   r%   r&   rh   Ç   s    úIterable[Any]ú'Callable[[Any], UnparsedVersion] | NoneúIterator[Any]c                 C  s   dS )z•
        Takes an iterable of items and filters them so that only items which
        are contained within this specifier are allowed in it.
        Nr%   rg   r%   r%   r&   rh   Ï   s    )N)N.)N.)NN)rK   rL   rM   rN   Ú	__slots__Ú__match_args__ÚpropertyrO   ÚabcÚabstractmethodrS   rU   rY   rZ   Úsetterra   ÚtypingÚoverloadrh   r%   r%   r%   r&   r   †   s<     ü  ü  ür   )Ú	metaclassc                	   @  s¾  e Zd ZU dZdZdZe de d ejej	B ¡Z
ddddd	d
dddœZded< dVddddœdd„Zdddœdd„Zdddœdd„Zdd œd!d"„Zedd œd#d$„ƒZejddd%œd&d$„ƒZd'd œd(d)„Zd*dd+œd,d-„Zedd œd.d/„ƒZedd œd0d1„ƒZdd œd2d3„Zdd œd4d5„Zed6d œd7d8„ƒZd9d œd:d;„Zd*d<d=œd>d?„Zd@d<dAœdBdC„ZdWdDdd<dEœdFdG„Zej dXdIdddJdKœdLdM„ƒZ!ej dYdNddOdPdKœdQdM„ƒZ!dZdRddSdTdKœdUdM„Z!dS )[r   aí  This class abstracts handling of version specifiers.

    .. tip::

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

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

    .. versionchanged:: 26.2

        Added a stable pickle format. Pickles created with packaging 26.2+ can
        be unpickled with future releases.  Backward compatibility with pickles
        from 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)ú~=r8   r9   r7   r6   r?   r@   ú===r   Ú
_operatorsÚ Nr.   r;   r[   )r)   rZ   r"   c                 C  s´   | j  |¡std|›�ƒ‚| ¡ }| d¡rL|dd… |dd…  ¡  }}nH| d¡rv|dd… |dd…  ¡  }}n|dd… |dd…  ¡  }}||f| _|| _d| _d| _dS )að  Initialize a Specifier instance.

        :param spec:
            The string representation of a specifier which will be parsed and
            normalized before use.
        :param prereleases:
            This tells the specifier if it should accept prerelease versions if
            applicable or not. The default of ``None`` will autodetect it from the
            given specifiers.
        :raises InvalidSpecifier:
            If the given specifier is invalid (i.e. bad syntax).
        zInvalid specifier: r„   Nr   )rƒ   r8   r9   r7   r6   r*   r	   )	Ú_regexÚ	fullmatchr   ÚstripÚ
startswithrA   rx   rz   ry   )rR   r)   rZ   ÚoperatorÚversionr%   r%   r&   Ú__init__c  s    
 
 
zSpecifier.__init__zVersion | None)rŒ   r"   c                 C  sD   | j dur"| j d |kr"| j d S t|ƒ}|du r6dS ||f| _ |S )zDOne element cache, as only one spec Version is needed per Specifier.Nr   r	   )rz   r   )rR   rŒ   Úversion_specifierr%   r%   r&   Ú_get_spec_version†  s    

zSpecifier._get_spec_versionr   c                 C  s   |   |¡}|dusJ ‚|S )zÕGet spec version, asserting it's valid (not for === operator).

        This method should only be called for operators where version
        strings are guaranteed to be valid PEP 440 versions (not ===).
        N)r�   )rR   rŒ   Úspec_versionr%   r%   r&   rE   ’  s    
zSpecifier._require_spec_versionúSequence[Interval]r!   c                 C  sP   | j dur| j S | j}| j}|dkr*t}n|  | d¡¡}t|||ƒ}|| _ |S )zØConvert this specifier to sorted, non-overlapping version ranges.

        Each standard operator maps to one or two ranges.  ``===`` is
        modeled as full range (actual check done separately).  Cached.
        Nr„   r>   )ry   r‹   rŒ   r
   rE   Úremovesuffixr   )rR   ÚoprI   ÚresultrŒ   r%   r%   r&   Ú
_to_rangesœ  s    
zSpecifier._to_rangesc                 C  sX   | j d ur| j S | j\}}|dkr&dS |dkr<| d¡r<dS |  |¡}|d u rRd S |jS )Nr9   Fr8   r>   )rx   rA   rB   r�   Úis_prerelease)rR   r‹   Úversion_strrŒ   r%   r%   r&   rZ   ±  s    


zSpecifier.prereleasesr\   c                 C  s
   || _ d S r#   )rx   r^   r%   r%   r&   rZ   Í  s    z#tuple[tuple[str, str], bool | None]c                 C  s   | j | jfS r#   )rA   rx   rQ   r%   r%   r&   Ú__getstate__Ñ  s    zSpecifier.__getstate__r(   ©Ústater"   c                 C  sô   d | _ d | _t|tƒr¢t|ƒdkrJ|\}}t|ƒrJt|ƒrJ|| _|| _d S t|ƒdkr¢t|d t	ƒr¢|\}}| 
d¡}| 
dd¡}t|ƒr¢t|ƒr¢|| _|| _d S t|t	ƒrâ| 
d¡}| 
dd¡}t|ƒrât|ƒrâ|| _|| _d S td|›�ƒ‚d S )Nr*   r	   rA   rx   ÚinvalidzCannot restore Specifier from )rz   ry   r+   r,   r-   r/   r2   rA   rx   ÚdictrD   Ú	TypeError)rR   rš   r)   rZ   Ú_Ú	slot_dictr%   r%   r&   Ú__setstate__×  s2    



zSpecifier.__setstate__c                 C  s
   | j d S )z`The operator of this specifier.

        >>> Specifier("==1.2.3").operator
        '=='
        r   ©rA   rQ   r%   r%   r&   r‹   ø  s    zSpecifier.operatorc                 C  s
   | j d S )zaThe version of this specifier.

        >>> Specifier("==1.2.3").version
        '1.2.3'
        r	   r¡   rQ   r%   r%   r&   rŒ     s    zSpecifier.versionc                 C  s8   | j durd| j›�nd}d| jj› dt| ƒ›|› d�S )aT  A representation of the Specifier that shows all internal state.

        >>> Specifier('>=1.0.0')
        <Specifier('>=1.0.0')>
        >>> Specifier('>=1.0.0', prereleases=False)
        <Specifier('>=1.0.0', prereleases=False)>
        >>> Specifier('>=1.0.0', prereleases=True)
        <Specifier('>=1.0.0', prereleases=True)>
        Nú, prereleases=r†   r?   ú(ú)>©rx   rZ   Ú	__class__rK   r.   ©rR   r0   r%   r%   r&   Ú__repr__
  s
    ÿýzSpecifier.__repr__c                 C  s   dj | jŽ S )zÐA 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   rQ   r%   r%   r&   rS     s    zSpecifier.__str__ztuple[str, str]c                 C  sF   | j \}}|dks| d¡r$||fS |  |¡}t||dkd�}||fS )Nr„   r>   rƒ   )Ústrip_trailing_zero)rA   rB   rE   r   )rR   r‹   rŒ   r�   Úcanonical_versionr%   r%   r&   Ú_canonical_spec&  s    

ÿzSpecifier._canonical_specrT   c                 C  s
   t | jƒS r#   )Úhashr¬   rQ   r%   r%   r&   rU   4  s    zSpecifier.__hash__r1   rV   c                 C  sR   t |tƒr6z|  t|ƒ¡}W qF ty2   t Y S 0 nt || jƒsFtS | j|jkS )a>  Whether or not the two Specifier-like objects are equal.

        :param other: The other object to check against.

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

        >>> Specifier("==1.2.3") == Specifier("== 1.2.3.0")
        True
        >>> (Specifier("==1.2.3", prereleases=False) ==
        ...  Specifier("==1.2.3", prereleases=True))
        True
        >>> Specifier("==1.2.3") == "==1.2.3"
        True
        >>> Specifier("==1.2.3") == Specifier("==1.2.4")
        False
        >>> Specifier("==1.2.3") == Specifier("~=1.2.3")
        False
        )r+   r.   r¦   r   ÚNotImplementedr¬   rX   r%   r%   r&   rY   7  s    
zSpecifier.__eq__zstr | Version©r`   r"   c                 C  s
   |   |¡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
        ©ra   ©rR   r`   r%   r%   r&   Ú__contains__T  s    zSpecifier.__contains__ÚUnparsedVersionr_   c                 C  s†   | j d dkr&tt| j|g|d�ƒƒS t|ƒ}|du r:dS |du rPt| j| jƒ}|du rb|jrbdS t	| |ƒ}|durx|S t
|  ¡ |ƒ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„   ©rZ   NF)rA   r1   Úlistrh   r   r   rx   rZ   r–   rJ   r   r•   )rR   r`   rZ   r=   Úmatchr%   r%   r&   ra   i  s    "
zSpecifier.contains.rb   rc   rd   c                 C  s   d S r#   r%   rg   r%   r%   r&   rh   ¡  s    zSpecifier.filterri   rj   rk   c                 C  s   d S r#   r%   rg   r%   r%   r&   rh   ©  s    rl   rm   rn   c                   s\   |du rt | j| jƒ}| jdkrJ| j ¡ ‰‡ ‡fdd„|D ƒ}t|ˆ |ƒS t|  ¡ |ˆ |ƒ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.
        Nr„   c                 3  s2   | ]*}t ˆ d u r|nˆ |ƒƒ ¡ ˆkr|V  qd S r#   )r.   Úlower©Ú.0r`   ©rf   Z
spec_lowerr%   r&   Ú	<genexpr>Þ  s    þz#Specifier.filter.<locals>.<genexpr>)	r   rx   rZ   r‹   rŒ   r·   Ú_apply_prereleases_filterr   r•   )rR   re   rZ   rf   Úmatchesr%   rº   r&   rh   ±  s    (

þ)r†   N)N)N.)N.)NN)"rK   rL   rM   rN   ro   Z_specifier_regex_strÚreÚcompileÚVERBOSEÚ
IGNORECASEr‡   r…   Ú__annotations__r�   r�   rE   r•   rq   rZ   rt   r˜   r    r‹   rŒ   r¨   rS   r¬   rU   rY   r²   ra   ru   rv   rh   r%   r%   r%   r&   r   Ü   s`   
\ÿø#
!
8  ü  ü
  ürl   rm   rn   )r½   rf   rZ   r"   c                   s2   |du rt | ˆ ƒS |rt| ƒS ‡ ‡fdd„| D ƒS )zÓApply ``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.
    Nc                 3  s8   | ]0}t ˆ d u r|nˆ |ƒƒ ‰d u s,ˆjs|V  qd S r#   )r   r–   r¸   ©rf   r=   r%   r&   r»   ö  s    ýz,_apply_prereleases_filter.<locals>.<genexpr>)Ú_pep440_filter_prereleasesÚiter)r½   rf   rZ   r%   rÃ   r&   r¼   è  s    

þr¼   c                   @  sÎ  e Zd ZdZdZdUddddœd	d
„Zddœdd„Zeddœdd„ƒZej	dddœdd„ƒZddœdd„Z
dddœdd„Zddœdd„Zddœdd„Zddœd d!„Zd"d d#œd$d%„Zdd&d#œd'd(„Zddœd)d*„Zd+dœd,d-„Zd.dœd/d0„Zd&dœd1d2„Zd&dœd3d4„Zd5dœd6d7„Zddd#œd8d9„Zd d&d#œd:d;„Zd d&d#œd<d=„Zd d&d#œd>d?„Zd@d&dAœdBdC„ZdVd@ddd&dDœdEdF„ZejdWdHdddIdJœdKdL„ƒZejdXdMddNdOdJœdPdL„ƒZdYdQddRdSdJœdTdL„ZdS )Zr    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_unsatisfiablerx   ry   Ú_specsr†   Nzstr | Iterable[Specifier]r;   r[   )Ú
specifiersrZ   r"   c                 C  s€   t |tƒr:dd„ | d¡D ƒ}ttt|ƒƒ| _d|v | _n t|ƒ| _tdd„ | jD ƒƒ| _t	| jƒdk| _
d| _d| _|| _dS )	a´  Initialize a SpecifierSet instance.

        :param specifiers:
            The string representation of a specifier or a comma-separated list of
            specifiers which will be parsed and normalized before use.
            May also be an iterable of ``Specifier`` instances, which will be used
            as is.
        :param prereleases:
            This tells the SpecifierSet if it should accept prerelease versions if
            applicable or not. The default of ``None`` will autodetect it from the
            given specifiers.

        :raises InvalidSpecifier:
            If the given ``specifiers`` are not parseable than this exception will be
            raised.
        c                 S  s   g | ]}|  ¡ r|  ¡ ‘qS r%   )r‰   ©r¹   Úsr%   r%   r&   Ú
<listcomp>3  ó    z)SpecifierSet.__init__.<locals>.<listcomp>ú,r„   c                 s  s   | ]}d t |ƒv V  qdS ©r„   NrP   rË   r%   r%   r&   r»   <  rÎ   z(SpecifierSet.__init__.<locals>.<genexpr>r	   N)r+   r.   Úsplitr,   Úmapr   rÉ   rÇ   Úanyr-   rÆ   rÈ   ry   rx   )rR   rÊ   rZ   Úsplit_specifiersr%   r%   r&   r�     s    

zSpecifierSet.__init__ztuple[Specifier, ...]r!   c                 C  s,   | j s&tt t| jtd�¡ƒ| _d| _ | jS )zBDeduplicate, sort, and cache specs for order-sensitive operations.©rf   T)rÆ   r,   rœ   ÚfromkeysÚsortedrÉ   r.   rQ   r%   r%   r&   Ú_canonical_specsF  s    zSpecifierSet._canonical_specsc                 C  s6   | j d ur| j S | jsd S tdd„ | jD ƒƒr2dS d S )Nc                 s  s   | ]}|j V  qd S r#   r´   rË   r%   r%   r&   r»   \  rÎ   z+SpecifierSet.prereleases.<locals>.<genexpr>T)rx   rÉ   rÓ   rQ   r%   r%   r&   rZ   M  s    
zSpecifierSet.prereleasesr\   c                 C  s   || _ d | _d S r#   )rx   rÈ   r^   r%   r%   r&   rZ   a  s    z)tuple[tuple[Specifier, ...], bool | None]c                 C  s   | j | jfS r#   )rÉ   rx   rQ   r%   r%   r&   r˜   f  s    zSpecifierSet.__getstate__r(   r™   c                 C  sè  d | _ d | _t|tƒ�r8t|ƒdkr‚|\}}t|tƒr‚tdd„ |D ƒƒr‚t|ƒr‚|| _|| _t|ƒdk| _	t
dd„ |D ƒƒ| _d S t|ƒdk�r8t|d tƒ�r8|\}}| dd¡}| d¡}t|tƒrØtt|td	�ƒ}t|tƒ�r8td
d„ |D ƒƒ�r8t|ƒ�r8|| _|| _t| jƒdk| _	t
dd„ | jD ƒƒ| _d S t|tƒ�rÖ| dd¡}| d¡}t|tƒ�rvtt|td	�ƒ}t|tƒ�rÖtdd„ |D ƒƒ�rÖt|ƒ�rÖ|| _|| _t| jƒdk| _	t
dd„ | jD ƒƒ| _d S td|›�ƒ‚d S )Nr*   c                 s  s   | ]}t |tƒV  qd S r#   ©r+   r   rË   r%   r%   r&   r»   w  rÎ   z,SpecifierSet.__setstate__.<locals>.<genexpr>r	   c                 s  s   | ]}d t |ƒv V  qdS rÐ   rP   rË   r%   r%   r&   r»   }  rÎ   rÉ   r%   rx   rÕ   c                 s  s   | ]}t |tƒV  qd S r#   rÙ   rË   r%   r%   r&   r»   ‰  rÎ   c                 s  s   | ]}d t |ƒv V  qdS rÐ   rP   rË   r%   r%   r&   r»   �  rÎ   c                 s  s   | ]}t |tƒV  qd S r#   rÙ   rË   r%   r%   r&   r»   š  rÎ   c                 s  s   | ]}d t |ƒv V  qdS rÐ   rP   rË   r%   r%   r&   r»      rÎ   z!Cannot restore SpecifierSet from )ry   rÈ   r+   r,   r-   Úallr2   rÉ   rx   rÆ   rÓ   rÇ   rœ   rD   Ú	frozensetr×   r.   r�   )rR   rš   ÚspecsrZ   rž   rŸ   r%   r%   r&   r    l  sd    ÿþý

ÿþý
ÿþýzSpecifierSet.__setstate__r.   c                 C  s8   | j durd| j›�nd}d| jj› dt| ƒ›|› d�S )a  A representation of the specifier set that shows all internal state.

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

        >>> SpecifierSet('>=1.0.0,!=2.0.0')
        <SpecifierSet('!=2.0.0,>=1.0.0')>
        >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=False)
        <SpecifierSet('!=2.0.0,>=1.0.0', prereleases=False)>
        >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=True)
        <SpecifierSet('!=2.0.0,>=1.0.0', prereleases=True)>
        Nr¢   r†   r?   r£   r¤   r¥   r§   r%   r%   r&   r¨   ¥  s
    ÿýzSpecifierSet.__repr__c                 C  s   d  dd„ |  ¡ D ƒ¡S )an  A string representation of the specifier set that can be round-tripped.

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

        >>> str(SpecifierSet(">=1.0.0,!=1.0.1"))
        '!=1.0.1,>=1.0.0'
        >>> str(SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False))
        '!=1.0.1,>=1.0.0'
        rÏ   c                 s  s   | ]}t |ƒV  qd S r#   rP   rË   r%   r%   r&   r»   Å  rÎ   z'SpecifierSet.__str__.<locals>.<genexpr>)ÚjoinrØ   rQ   r%   r%   r&   rS   º  s    zSpecifierSet.__str__rT   c                 C  s   t |  ¡ ƒS r#   )r­   rØ   rQ   r%   r%   r&   rU   Ç  s    zSpecifierSet.__hash__zSpecifierSet | strrV   c                 C  s”   t |tƒrt|ƒ}nt |tƒs"tS tƒ }| j|j |_t|jƒdk|_| jpP|j|_| jdu sj| j|jkrt|j|_n|jdu rˆ| j|_nt	dƒ‚|S )a‚  Return a SpecifierSet which is a combination of the two sets.

        :param other: The other object to combine with.

        >>> SpecifierSet(">=1.0.0,!=1.0.1") & '<=2.0.0,!=2.0.1'
        <SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
        >>> SpecifierSet(">=1.0.0,!=1.0.1") & SpecifierSet('<=2.0.0,!=2.0.1')
        <SpecifierSet('!=1.0.1,!=2.0.1,<=2.0.0,>=1.0.0')>
        r	   NzFCannot combine SpecifierSets with True and False prerelease overrides.)
r+   r.   r    r®   rÉ   r-   rÆ   rÇ   rx   Ú
ValueError)rR   rW   r<   r%   r%   r&   Ú__and__Ê  s     






ÿzSpecifierSet.__and__r1   c                 C  s:   t |ttfƒrtt|ƒƒ}nt |tƒs*tS |  ¡ | ¡ kS )a¡  Whether or not the two SpecifierSet-like objects are equal.

        :param other: The other object to check against.

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

        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.1")
        True
        >>> (SpecifierSet(">=1.0.0,!=1.0.1", prereleases=False) ==
        ...  SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True))
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == ">=1.0.0,!=1.0.1"
        True
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0")
        False
        >>> SpecifierSet(">=1.0.0,!=1.0.1") == SpecifierSet(">=1.0.0,!=1.0.2")
        False
        )r+   r.   r   r    r®   rØ   rX   r%   r%   r&   rY   ê  s
    
zSpecifierSet.__eq__c                 C  s
   t | jƒS )z7Returns the number of specifiers in this specifier set.)r-   rÉ   rQ   r%   r%   r&   Ú__len__  s    zSpecifierSet.__len__zIterator[Specifier]c                 C  s
   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É   rQ   r%   r%   r&   Ú__iter__  s    zSpecifierSet.__iter__r‘   c                 C  s,   | j dur| j S tdd„ | jD ƒƒ| _ | j S )z¨Intersect all specifiers into a single sequence of version ranges.

        Empty when unsatisfiable. Callers must ensure ``self._specs``
        is non-empty.
        Nc                 s  s   | ]}|  ¡ V  qd S r#   )r•   rË   r%   r%   r&   r»     rÎ   z+SpecifierSet._get_ranges.<locals>.<genexpr>)ry   r   rÉ   rQ   r%   r%   r&   Ú_get_ranges  s    
zSpecifierSet._get_rangesc                 C  s\   | j }|dur|S | js"d| _ dS |  ¡  }|s8|  ¡ }|sR| jdu rRt|  ¡ ƒ}|| _ |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
        NF)rÈ   rÉ   râ   Ú_check_arbitrary_unsatisfiablerZ   r   )rR   Úcachedr”   r%   r%   r&   Úis_unsatisfiable  s    
zSpecifierSet.is_unsatisfiablec                   s®   dd„ | j D ƒ}|sdS |d j ¡ ‰t‡fdd„|dd… D ƒƒrHd	S t|d jƒ‰ | jdu rrˆ durrˆ jrrd	S d
d„ | j D ƒ}|sŠdS ˆ du r–d	S t‡ fdd„|D ƒƒ S )a  Check === (arbitrary equality) specs for unsatisfiability.

        === uses case-insensitive string comparison, so the only candidate
        that can match ``===V`` is the literal string V.  This method
        checks whether that candidate is excluded by other specifiers.
        c                 S  s   g | ]}|j d kr|‘qS ©r„   ©r‹   rË   r%   r%   r&   rÍ   H  rÎ   z?SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<listcomp>Fr   c                 3  s   | ]}|j  ¡ ˆ kV  qd S r#   )rŒ   r·   rË   )Úfirstr%   r&   r»   N  rÎ   z>SpecifierSet._check_arbitrary_unsatisfiable.<locals>.<genexpr>r	   NTc                 S  s   g | ]}|j d kr|‘qS ræ   rç   rË   r%   r%   r&   rÍ   ^  rÎ   c                 3  s   | ]}|  ˆ ¡V  qd S r#   r°   rË   )Ú	candidater%   r&   r»   f  rÎ   )rÉ   rŒ   r·   rÓ   r   rZ   r–   rÚ   )rR   r‚   Ústandardr%   )ré   rè   r&   rã   A  s(    ÿþýz+SpecifierSet._check_arbitrary_unsatisfiablezranges.VersionRangec                 C  s   ddl m} | | ¡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   rë   Z_from_specifier_set)rR   rë   r%   r%   r&   Úto_rangeh  s    zSpecifierSet.to_rangec                 C  s*   t |tƒstdƒ‚| js|jr&tdƒ‚d S )Nzexpected a SpecifierSetz+set relations do not support === specifiers)r+   r    r�   rÇ   rÞ   rX   r%   r%   r&   Ú_check_relation_operandw  s    
z$SpecifierSet._check_relation_operandc                 C  s   |   |¡ |  ¡  | ¡ ¡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_subsetrX   r%   r%   r&   rî   }  s    
zSpecifierSet.is_subsetc                 C  s   |   |¡ |  ¡  | ¡ ¡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_supersetrX   r%   r%   r&   rï   ‘  s    
zSpecifierSet.is_supersetc                 C  s   |   |¡ |  ¡  | ¡ ¡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_disjointrX   r%   r%   r&   rð   £  s    
zSpecifierSet.is_disjointr³   r¯   c                 C  s
   |   |¡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±   r%   r%   r&   r²   ·  s    zSpecifierSet.__contains__)r`   rZ   Ú	installedr"   c           	      C  sð   t |ƒ}|dur|r|jrd}|du s6| jr<t|tƒs<|}n|}|durØ| jsØ|jdu rØ| jrØ|jr‚|du s~|du r‚| jdu r‚dS | j}|du rÎ| jD ]$}t	||ƒ}|du r° qÀ|s– dS q–dS |  
¡  }| _t||ƒS tt| j|g|d�ƒƒS )a<  Return whether or not the item is contained in this SpecifierSet.

        :param item:
            The item to check for, which can be a version string or a
            :class:`~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`.
        NTFr´   )r   r–   rÇ   r+   r   rC   rÉ   rx   ry   rJ   râ   r   r1   rµ   rh   )	rR   r`   rZ   rñ   rŒ   Ú
check_itemZboundsr)   r¶   r%   r%   r&   ra   Ì  sD    (ÿþýüÿþþ


zSpecifierSet.contains.rb   rc   rd   c                 C  s   d S r#   r%   rg   r%   r%   r&   rh   $  s    zSpecifierSet.filterri   rj   rk   c                 C  s   d S r#   r%   rg   r%   r%   r&   rh   ,  s    rl   rm   rn   c                   sz   |du r| j dur| j }| jrn| jrJ| j‰‡ ‡fdd„|D ƒ}t|ˆ |ƒS | j}|du r`|  ¡ }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.
        Nc                 3  s*   | ]"‰ t ‡ ‡fd d„ˆD ƒƒrˆ V  qdS )c                 3  s,   | ]$}|j ˆd u rˆ nˆˆ ƒdd�V  qd S )NTr´   r°   rË   )r`   rf   r%   r&   r»   z  s   ÿz0SpecifierSet.filter.<locals>.<genexpr>.<genexpr>N)rÚ   )r¹   ©rf   rÜ   )r`   r&   r»   w  s
   þþz&SpecifierSet.filter.<locals>.<genexpr>)rZ   rÉ   rÇ   r¼   ry   râ   r   )rR   re   rZ   rf   r½   r   r%   ró   r&   rh   4  s    <þ)r†   N)NN)N.)N.)NN) rK   rL   rM   rN   ro   r�   rØ   rq   rZ   rt   r˜   r    r¨   rS   rU   rß   rY   rà   rá   râ   rå   rã   rì   rí   rî   rï   rð   r²   ra   ru   rv   rh   r%   r%   r%   r&   r    þ  sT     ý,9 
#'  üX  ü  ü
  ür    )re   rf   r"   c                 c  s˜   g }g }d}| D ]t}t |du r"|n||ƒƒ}|du rV|r@|V  q| |¡ | |¡ q|jsv|sn|E dH  d}|V  q|s| |¡ q|s”|E dH  dS )z?Filter per PEP 440: exclude prereleases unless no finals exist.FNT)r   Úappendr–   )re   rf   Zall_nonfinalZarbitrary_stringsZfound_finalr`   r=   r%   r%   r&   rÄ   Š  s*    


rÄ   )<rN   Ú
__future__r   rr   r¾   ru   r   r   r   r   r   r   ry   r
   r   r   r   r   r   r   r   r   Úutilsr   rŒ   r   ÚsysÚcollections.abcr   r   r   Úversion_infor   Ztyping_extensionsr†   r   r   r$   r'   r/   r2   r3   r.   r³   r4   Ú__ge__Ú__le__rY   Ú__ne__r:   rÂ   rJ   rÞ   r   ÚABCMetar   r   r¼   r    rÄ   r%   r%   r%   r&   Ú<module>   sX    	,
	üV         