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%   úS/var/www/html/laksyashrimp/venv/lib/python3.9/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=   Zop_strÚver_strZdirect_compareZspec_vr%   r%   r&   Ú_fast_match]   s    


ÿrI   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&   rN   Ž   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%   rP   r%   r%   r&   Ú__str__“   s    zBaseSpecifier.__str__Úintc                 C  s   dS )zF
        Returns a hash value for this Specifier-like object.
        Nr%   rP   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%   ©rQ   rV   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%   rP   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%   ©rQ   r\   r%   r%   r&   rY   ²   s    N©ÚitemrY   r"   c                 C  s   dS )zR
        Determines if the given item is contained within this specifier.
        Nr%   )rQ   r_   rY   r%   r%   r&   Úcontains¹   s    zBaseSpecifier.contains.úIterable[UnparsedVersionVar]úIterator[UnparsedVersionVar]©ÚiterablerY   Úkeyr"   c                 C  s   d S r#   r%   ©rQ   rd   rY   re   r%   r%   r&   Úfilter¿   s    zBaseSpecifier.filterúIterable[T]úCallable[[T], UnparsedVersion]úIterator[T]c                 C  s   d S r#   r%   rf   r%   r%   r&   rg   Ç   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%   rf   r%   r%   r&   rg   Ï   s    )N)N.)N.)NN)rJ   rK   rL   rM   Ú	__slots__Z__match_args__ÚpropertyrN   ÚabcÚabstractmethodrR   rT   rX   rY   Úsetterr`   ÚtypingÚoverloadrg   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;   rZ   )r)   rY   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   rv   rx   rw   )rQ   r)   rY   Ú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	   )rx   r   )rQ   rŠ   Z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Œ   )rQ   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>   )rw   r‰   rŠ   r
   rE   Úremovesuffixr   )rQ   ÚoprH   Ú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>   )rv   rA   rB   rŒ   Úis_prerelease)rQ   r‰   Úversion_strrŠ   r%   r%   r&   rY   ±  s    


zSpecifier.prereleasesr[   c                 C  s
   || _ d S r#   )rv   r]   r%   r%   r&   rY   Í  s    z#tuple[tuple[str, str], bool | None]c                 C  s   | j | jfS r#   )rA   rv   rP   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   rv   ÚinvalidzCannot restore Specifier from )rx   rw   r+   r,   r-   r/   r2   rA   rv   ÚdictrD   Ú	TypeError)rQ   r—   r)   rY   Ú_Ú	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   rP   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ž   rP   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?   ú(ú)>©rv   rY   Ú	__class__rJ   r.   ©rQ   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   rP   r%   r%   r&   rR     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�   )Zstrip_trailing_zero)rA   rB   rE   r   )rQ   r‰   rŠ   r�   Zcanonical_versionr%   r%   r&   Ú_canonical_spec&  s    

ÿzSpecifier._canonical_specrS   c                 C  s
   t | jƒS r#   )Úhashr§   rP   r%   r%   r&   rT   4  s    zSpecifier.__hash__r1   rU   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§   rW   r%   r%   r&   rX   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
        ©r`   ©rQ   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‚   ©rY   NF)rA   r1   Úlistrg   r   r   rv   rY   r“   rI   r   r’   )rQ   r_   rY   r=   Úmatchr%   r%   r&   r`   i  s    "
zSpecifier.contains.ra   rb   rc   c                 C  s   d S r#   r%   rf   r%   r%   r&   rg   ¡  s    zSpecifier.filterrh   ri   rj   c                 C  s   d S r#   r%   rf   r%   r%   r&   rg   ©  s    rk   rl   rm   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_   ©re   Z
spec_lowerr%   r&   Ú	<genexpr>Þ  s    þz#Specifier.filter.<locals>.<genexpr>)	r   rv   rY   r‰   rŠ   r²   Ú_apply_prereleases_filterr   r’   )rQ   rd   rY   re   Úmatchesr%   rµ   r&   rg   ±  s    (

þ)r„   N)N)N.)N.)NN)"rJ   rK   rL   rM   rn   Z_specifier_regex_strÚreÚcompileÚVERBOSEÚ
IGNORECASEr…   rƒ   Ú__annotations__r‹   rŒ   rE   r’   ro   rY   rr   r•   r�   r‰   rŠ   r¥   rR   r§   rT   rX   r­   r`   rs   rt   rg   r%   r%   r%   r&   r   Ü   s`   
\ÿø#
!
8  ü  ü
  ürk   rl   rm   )r¸   re   rY   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³   ©re   r=   r%   r&   r¶   ö  s    ýz,_apply_prereleases_filter.<locals>.<genexpr>)Ú_pep440_filter_prereleasesÚiter)r¸   re   rY   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_unsatisfiablerv   rw   Ú_specsr„   Nzstr | Iterable[Specifier]r;   rZ   )Ú
specifiersrY   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‚   NrO   rÆ   r%   r%   r&   r¶   <  rÉ   z(SpecifierSet.__init__.<locals>.<genexpr>r	   N)r+   r.   Úsplitr,   Úmapr   rÄ   rÂ   Úanyr-   rÁ   rÃ   rw   rv   )rQ   rÅ   rY   Ú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.©re   T)rÁ   r,   r™   ÚfromkeysÚsortedrÄ   r.   rP   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)rv   rÄ   rÎ   rP   r%   r%   r&   rY   M  s    
zSpecifierSet.prereleasesr[   c                 C  s   || _ d | _d S r#   )rv   rÃ   r]   r%   r%   r&   rY   a  s    z)tuple[tuple[Specifier, ...], bool | None]c                 C  s   | j | jfS r#   )rÄ   rv   rP   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Ë   rO   rÆ   r%   r%   r&   r¶   }  rÉ   rÄ   r%   rv   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Ë   rO   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Ë   rO   rÆ   r%   r%   r&   r¶      rÉ   z!Cannot restore SpecifierSet from )rw   rÃ   r+   r,   r-   Úallr2   rÄ   rv   rÁ   rÎ   rÂ   r™   rD   Ú	frozensetrÒ   r.   rš   )rQ   r—   ÚspecsrY   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#   rO   rÆ   r%   r%   r&   r¶   Å  rÉ   z'SpecifierSet.__str__.<locals>.<genexpr>)ÚjoinrÓ   rP   r%   r%   r&   rR   º  s    zSpecifierSet.__str__rS   c                 C  s   t |  ¡ ƒS r#   )r¨   rÓ   rP   r%   r%   r&   rT   Ç  s    zSpecifierSet.__hash__zSpecifierSet | strrU   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Â   rv   Ú
ValueError)rQ   rV   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Ó   rW   r%   r%   r&   rX   ê  s
    
zSpecifierSet.__eq__c                 C  s
   t | jƒS )z7Returns the number of specifiers in this specifier set.)r-   rÄ   rP   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Ä   rP   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>)rw   r   rÄ   rP   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_unsatisfiablerY   r   )rQ   Ú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   rY   r“   rÕ   )rQ   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)rQ   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Ù   rW   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_subsetrW   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_supersetrW   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_disjointrW   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_   rY   Ú	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Ä   rv   rw   rI   rÝ   r   r1   r°   rg   )	rQ   r_   rY   rì   rŠ   Z
check_itemZboundsr)   r±   r%   r%   r&   r`   Ì  sD    (ÿþýüÿþþ


zSpecifierSet.contains.ra   rb   rc   c                 C  s   d S r#   r%   rf   r%   r%   r&   rg   $  s    zSpecifierSet.filterrh   ri   rj   c                 C  s   d S r#   r%   rf   r%   r%   r&   rg   ,  s    rk   rl   rm   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_   re   r%   r&   r¶   z  s   ÿz0SpecifierSet.filter.<locals>.<genexpr>.<genexpr>N)rÕ   )r´   ©re   r×   )r_   r&   r¶   w  s
   þþz&SpecifierSet.filter.<locals>.<genexpr>)rY   rÄ   rÂ   r·   rw   rÝ   r   )rQ   rd   rY   re   r¸   r   r%   rí   r&   rg   4  s    <þ)r„   N)NN)N.)N.)NN) rJ   rK   rL   rM   rn   r‹   rÓ   ro   rY   rr   r•   r�   r¥   rR   rT   rÚ   rX   rÛ   rÜ   rÝ   rà   rÞ   rç   rè   ré   rê   rë   r­   r`   rs   rt   rg   r%   r%   r%   r&   r    þ  sT     ý,9 
#'  üX  ü  ü
  ür    )rd   re   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“   )rd   re   Zall_nonfinalZarbitrary_stringsZfound_finalr_   r=   r%   r%   r&   r¿   Š  s*    


r¿   )<rM   Ú
__future__r   rp   r¹   rs   r   r   r   r   r   r   rw   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__rX   Ú__ne__r:   r½   rI   rÙ   r   ÚABCMetar   r   r·   r    r¿   r%   r%   r%   r&   Ú<module>   sX    	,
	üV         