U cf:@s(dZddlmZddlZddlZddlZddlmZmZm Z m Z m Z ddl m Z ddlmZe eefZe ded ZeeegefZd d d d dZGdddeZGdddejdZGdddeZedZddd ddZdddddZdddd d!Zddd"d#d$d%Z Gd&d'd'eZ!dS)(z .. testsetup:: from pip._vendor.packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier from pip._vendor.packaging.version import Version ) annotationsN)CallableIterableIteratorTypeVarUnion)canonicalize_version)VersionUnparsedVersionVar)boundUnparsedVersionr )versionreturncCst|tst|}|SN) isinstancer )rrN/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/packaging/specifiers.py_coerce_versions rc@seZdZdZdS)InvalidSpecifiera 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__rrrrr src@seZdZejddddZejddddZejdd d d d Zeejd dddZ e j d ddddZ ejddd d dddZ ejddd ddddZ dS) BaseSpecifierstrrcCsdS)z Returns the str representation of this Specifier-like object. This should be representative of the Specifier itself. Nrselfrrr__str__-szBaseSpecifier.__str__intcCsdS)zF Returns a hash value for this Specifier-like object. Nrrrrr__hash__4szBaseSpecifier.__hash__objectboolotherrcCsdS)z Returns a boolean representing whether or not the two Specifier-like objects are equal. :param other: The other object to check against. Nrrr%rrr__eq__:szBaseSpecifier.__eq__ bool | NonecCsdS)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. Nrrrrr prereleasesCszBaseSpecifier.prereleasesNonevaluercCsdS)zQSetter for :attr:`prereleases`. :param value: The value to set. Nrrr,rrrr)LsNitemr)rcCsdS)zR Determines if the given item is contained within this specifier. Nr)rr/r)rrrcontainsSszBaseSpecifier.containsIterable[UnparsedVersionVar]Iterator[UnparsedVersionVar]iterabler)rcCsdS)z Takes an iterable of items and filters them so that only items which are contained within this specifier are allowed in it. Nr)rr4r)rrrfilterYszBaseSpecifier.filter)N)N) rrrabcabstractmethodrr!r'propertyr)setterr0r5rrrrr,s r) metaclassc @seZdZdZdZdZedeedejej BZ dddd d d d d dZ dSddddddZ e ddddZejdddddZe ddddZe dddd Zddd!d"Zddd#d$Ze d%dd&d'Zd(dd)d*Zd+dd,d-d.Zdd/d0d1d2Zd3ddd4d5d6Zd3ddd4d7d8Zd3ddd4d9d:Zd3ddd4d;d<Zd3ddd4d=d>Zd3ddd?d@dAZd3ddd?dBdCZd3ddd4dDdEZdFddGdHdIZ dTdJdddKdLdMZ!dUdNddOdPdQdRZ"dS)V Specifiera?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). z8 (?P(~=|==|!=|<=|>=|<|>|===)) a (?P (?: # 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 .* | (?: # 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 (?:\+[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. (?=<>===Nrr(r*)specr)rcCsH|j|}|s td|d|d|df|_||_dS)aInitialize 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). zInvalid specifier: ''operatorrN)_regexsearchrgroupstrip_spec _prereleases)rrLr)matchrrr__init__s   zSpecifier.__init__r#rcCsR|jdk r|jS|j\}}|dkrN|dkr@|dr@|dd}t|jrNdSdS)N)rErGrFrDrJrE.*TF)rTrSendswithr is_prerelease)rrNrrrrr)s    zSpecifier.prereleasesr+cCs ||_dSrrTr-rrrr)scCs |jdS)z`The operator of this specifier. >>> Specifier("==1.2.3").operator '==' rrSrrrrrNszSpecifier.operatorcCs |jdS)zaThe version of this specifier. >>> Specifier("==1.2.3").version '1.2.3' rr\rrrrrszSpecifier.versioncCs8|jdk rd|jnd}d|jjdt||dS)aTA representation of the Specifier that shows all internal state. >>> Specifier('>=1.0.0') =1.0.0')> >>> Specifier('>=1.0.0', prereleases=False) =1.0.0', prereleases=False)> >>> Specifier('>=1.0.0', prereleases=True) =1.0.0', prereleases=True)> N, prereleases=rKrH()>)rTr) __class__rrrprerrr__repr__&s zSpecifier.__repr__cCs dj|jS)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{}{})formatrSrrrrr8szSpecifier.__str__ztuple[str, str]cCs*t|jd|jddkd}|jd|fS)NrrrDZstrip_trailing_zero)r rS)rZcanonical_versionrrr_canonical_specBs  zSpecifier._canonical_specr cCs t|jSr)hashrfrrrrr!JszSpecifier.__hash__r"r$cCsTt|tr8z|t|}WqHtk r4tYSXnt||jsHtS|j|jkS)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 )rrr`rNotImplementedrfr&rrrr'Ms   zSpecifier.__eq__CallableOperator)oprcCst|d|j|}|S)N _compare_)getattr _operators)rrjoperator_callablerrr _get_operatorjs zSpecifier._get_operatorr ) prospectiverLrcCsHttttt|dd}|d7}|d||oF|d||S)NrWrGrE) _version_joinlist itertools takewhile_is_not_suffix_version_splitro)rrprLprefixrrr_compare_compatibleps zSpecifier._compare_compatiblec Cs|drbt|jdd}t|dddd}t|}t|}t||\}}|dt|} | |kSt|} | jszt|j}|| kSdS)NrWFrerX)rYr publicrw _pad_versionlenr local) rrprLZnormalized_prospectiveZnormalized_spec split_specsplit_prospectivepadded_prospective_shortened_prospective spec_versionrrr_compare_equals  zSpecifier._compare_equalcCs||| Sr)rrrprLrrr_compare_not_equalszSpecifier._compare_not_equalcCst|jt|kSrr rzrrrr_compare_less_than_equalsz"Specifier._compare_less_than_equalcCst|jt|kSrrrrrr_compare_greater_than_equalsz%Specifier._compare_greater_than_equal)rpspec_strrcCs<t|}||ksdS|js8|jr8t|jt|jkr8dSdSNFT)r rZ base_versionrrprrLrrr_compare_less_thans zSpecifier._compare_less_thancCs^t|}||ksdS|js8|jr8t|jt|jkr8dS|jdk rZt|jt|jkrZdSdSr)r is_postreleaserr}rrrr_compare_greater_thans  zSpecifier._compare_greater_thancCst|t|kSr)rlowerrrrr_compare_arbitraryszSpecifier._compare_arbitraryz str | Versionr/rcCs ||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") False >>> "1.3.0a1" in Specifier(">=1.2.3", prereleases=True) True r0rr/rrr __contains__szSpecifier.__contains__r r.cCs<|dkr|j}t|}|jr$|s$dS||j}|||jS)alReturn whether or not the item is contained in this specifier. :param item: The item to check for, which can be a version string or a :class:`Version` instance. :param prereleases: Whether or not to match prereleases with this Specifier. If set to ``None`` (the default), it uses :attr:`prereleases` to determine whether or not prereleases are allowed. >>> 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") False >>> Specifier(">=1.2.3", prereleases=True).contains("1.3.0a1") True >>> Specifier(">=1.2.3").contains("1.3.0a1", prereleases=True) True NF)r)rrZrorNr)rr/r)normalized_itemrnrrrr0 s  zSpecifier.containsr1r2r3ccs~d}g}d|dk r|ndi}|D]@}t|}|j|f|r |jrV|sV|jsV||q d}|Vq |sz|rz|D] }|VqndS)aOFilter items in the given iterable, that match the specifier. :param iterable: An iterable that can contain version strings and :class:`Version` instances. The items in the iterable will be filtered according to the specifier. :param prereleases: Whether or not to allow prereleases in the returned iterator. If set to ``None`` (the default), it will be intelligently decide whether to allow prereleases or not (based on the :attr:`prereleases` attribute, and whether the only versions matching are prereleases). This method is smarter than just ``filter(Specifier().contains, [...])`` because it implements the rule from :pep:`440` that a prerelease item SHOULD be accepted if no other versions match the given specifier. >>> 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', ] >>> 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'] Fr)NT)rr0rZr)append)rr4r)yieldedfound_prereleaseskwrparsed_versionrrrr55s" zSpecifier.filter)rKN)N)N)#rrrrZ_operator_regex_strZ_version_regex_strrecompileVERBOSE IGNORECASErOrmrVr8r)r9rNrrcrrfr!r'roryrrrrrrrrr0r5rrrrr;csX ^   (-r;z^([0-9]+)((?:a|b|c|rc)[0-9]+)$rz list[str]cCs^g}|d\}}}||pd|dD],}t|}|rN||q,||q,|S)aSplit version into components. The split components are intended for version comparison. The logic does not attempt to retain the original version string, so joining the components back with :func:`_version_join` may not produce the original version string. !0.) rpartitionrsplit _prefix_regexrPextendgroups)rresultepochrrestr/rUrrrrwvs  rw) componentsrcCs|^}}|dd|S)zJoin split version components into a version string. This function assumes the input came from :func:`_version_split`, where the first component must be the epoch (either empty or numeric), and all other components numeric. rr)join)rrrrrrrrsrrr#)segmentrcstfdddD S)Nc3s|]}|VqdSr) startswith).0rxrrr sz!_is_not_suffix..)devabrcpost)anyrrrrrvs rvztuple[list[str], list[str]])leftrightrc Csgg}}|ttdd||ttdd|||t|dd||t|dd|ddgtdt|dt|d|ddgtdt|dt|dttj|ttj|fS)NcSs|Srisdigitxrrrz_pad_version..cSs|Srrrrrrrrrrr) rrsrtrur|insertmaxchain from_iterable)rr left_split right_splitrrrr{s ,,r{c@seZdZdZd/dddddd Zedd d d Zejd dddd Zdd ddZdd ddZ dd ddZ dddddZ dd dddZ dd ddZ d d d!d"Zd#d d$d%d&Zd0d#ddd d'd(d)Zd1d*dd+d,d-d.ZdS)2 SpecifierSetzThis 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. rKNrr(r*) specifiersr)rcCs.dd|dD}ttt||_||_dS)aNInitialize 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. :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. cSsg|]}|r|qSr)rRrsrrr sz)SpecifierSet.__init__..,N)r frozensetmapr;_specsrT)rrr)split_specifiersrrrrVszSpecifierSet.__init__rcCs.|jdk r|jS|jsdStdd|jDS)Ncss|] }|jVqdSrr)rrrrrsz+SpecifierSet.prereleases..)rTrrrrrrr)s  zSpecifierSet.prereleasesr#r+cCs ||_dSrr[r-rrrr)scCs.|jdk rd|jnd}dt||dS)aA 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') =1.0.0')> >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=False) =1.0.0', prereleases=False)> >>> SpecifierSet('>=1.0.0,!=2.0.0', prereleases=True) =1.0.0', prereleases=True)> Nr]rKz>> 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' rcss|]}t|VqdSr)rrrrrr sz'SpecifierSet.__str__..)rsortedrrrrrrs zSpecifierSet.__str__r cCs t|jSr)rgrrrrrr! szSpecifierSet.__hash__zSpecifierSet | strr$cCst|trt|}nt|ts"tSt}t|j|jB|_|jdkrX|jdk rX|j|_n<|jdk rv|jdkrv|j|_n|j|jkr|j|_ntd|S)aReturn 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' =1.0.0')> >>> SpecifierSet(">=1.0.0,!=1.0.1") & SpecifierSet('<=2.0.0,!=2.0.1') =1.0.0')> NzFCannot combine SpecifierSets with True and False prerelease overrides.)rrrrhrrrT ValueError)rr% specifierrrr__and__s       zSpecifierSet.__and__r"cCs6t|ttfrtt|}nt|ts*tS|j|jkS)aWhether 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 )rrr;rrhrr&rrrr'.s  zSpecifierSet.__eq__cCs t|jS)z7Returns the number of specifiers in this specifier set.)r|rrrrr__len__HszSpecifierSet.__len__zIterator[Specifier]cCs t|jS)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) [, =1.0.0')>] )iterrrrrr__iter__LszSpecifierSet.__iter__r rcCs ||S)arReturn 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") False >>> "1.3.0a1" in SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True) True rrrrrrVszSpecifierSet.__contains__)r/r) installedrcs\ttstdkr |js.jr.dS|rBjrBtjtfdd|jDS)aReturn whether or not the item is contained in this SpecifierSet. :param item: The item to check for, which can be a version string or a :class:`Version` instance. :param prereleases: Whether or not to match prereleases with this SpecifierSet. If set to ``None`` (the default), it uses :attr:`prereleases` to determine whether or not prereleases are allowed. >>> 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") False >>> SpecifierSet(">=1.0.0,!=1.0.1", prereleases=True).contains("1.3.0a1") True >>> SpecifierSet(">=1.0.0,!=1.0.1").contains("1.3.0a1", prereleases=True) True NFc3s|]}|jdVqdS)rNrrr/r)rrrsz(SpecifierSet.contains..)rr r)rZrallr)rr/r)rrrrr0ks    zSpecifierSet.containsr1r2r3cCs|dkr|j}|jr:|jD]}|j|t|d}qt|Sg}g}|D]0}t|}|jrl|sl|sv||qF||qF|s|r|dkrt|St|SdS)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:`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 be intelligently decide whether to allow prereleases or not (based on the :attr:`prereleases` attribute, and whether the only versions matching are prereleases). This method is smarter than just ``filter(SpecifierSet(...).contains, [...])`` because it implements the rule from :pep:`440` that a prerelease item SHOULD be accepted if no other versions match the given specifier. >>> 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', ] >>> list(SpecifierSet(">=1.2.3").filter(["1.2", "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'] 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'] Nr)r)rr5r#rrrZr)rr4r)rLfilteredrr/rrrrr5s",    zSpecifierSet.filter)rKN)NN)N)rrrrrVr8r)r9rcrr!rr'rrrr0r5rrrrrs&   :r)"r __future__rr6rtrtypingrrrrrutilsr rr rr r r#rirrrABCMetarr;rrrwrrrvr{rrrrrs0      7