a oe&@s8dZddlZddlZddlZddlmZmZmZmZm Z m Z m Z m Z m Z ddlmZddlmZe eefZe dedZeeegefZeed d d ZGd d d eZGdddejdZGdddeZedZeeed ddZeedddZ eeeee eeeefdddZ!GdddeZ"dS)z .. testsetup:: from packaging.specifiers import Specifier, SpecifierSet, InvalidSpecifier from packaging.version import Version N) CallableIterableIteratorListOptionalSetTupleTypeVarUnion)canonicalize_version)VersionUnparsedVersionVar)bound)versionreturncCst|tst|}|SN) isinstancer )rrKC:\Program Files\Certbot\pkgs\pkg_resources\_vendor\packaging\specifiers.py_coerce_version"s 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@seZdZejedddZejedddZeje e dddZ e eje e dd d Zeje d d d d Zejdee e e dddZejdeee e eedddZd S) BaseSpecifierrcCsdS)z Returns the str representation of this Specifier-like object. This should be representative of the Specifier itself. Nrselfrrr__str__5szBaseSpecifier.__str__cCsdS)zF Returns a hash value for this Specifier-like object. Nrrrrr__hash__<szBaseSpecifier.__hash__otherrcCsdS)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__BszBaseSpecifier.__eq__cCsdS)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 prereleasesKszBaseSpecifier.prereleasesNvaluercCsdS)zQSetter for :attr:`prereleases`. :param value: The value to set. Nrrr(rrrr&Tsitemr&rcCsdS)zR Determines if the given item is contained within this specifier. Nr)rr+r&rrrcontains[szBaseSpecifier.containsiterabler&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)rr.r&rrrfilteraszBaseSpecifier.filter)N)N)rrrabcabstractmethodstrr intr!objectboolr%propertyrr&setterr,rrrr/rrrrr4s& r) metaclassc @seZdZdZdZdZedeedejej BZ dddd d d d d dZ dFe e eddddZeedddZejeddddZee dddZee dddZe dddZe ddd Zeee e fdd!d"Zedd#d$Zeed%d&d'Ze ed(d)d*Zee ed+d,d-Z ee ed+d.d/Z!ee ed+d0d1Z"ee ed+d2d3Z#ee ed+d4d5Z$ee ed6d7d8Z%ee ed6d9d:Z&ee ed+d;d<Z'e(e efed=d>d?Z)dGe*e eed@dAdBZ+dHe,e-e ee.e-dCdDdEZ/dS)I 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. (?=<>===N)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)rrBr&matchrrr__init__s   zSpecifier.__init__rcCsR|jdur|jS|j\}}|dvrN|dkr@|dr@|dd}t|jrNdSdS)N)r;r=r<r:r@r;.*TF)rJrIendswithr is_prerelease)rrDrrrrr&s    zSpecifier.prereleasesr'cCs ||_dSrrJr)rrrr&scCs |jdS)z`The operator of this specifier. >>> Specifier("==1.2.3").operator '==' rrIrrrrrDszSpecifier.operatorcCs |jdS)zaThe version of this specifier. >>> Specifier("==1.2.3").version '1.2.3' r rRrrrrr%szSpecifier.versioncCs8|jdurd|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=rAr>()>)rJr& __class__rr2rZprerrr__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{}{})formatrIrrrrr @szSpecifier.__str__cCs*t|jd|jddkd}|jd|fS)Nr rr:Zstrip_trailing_zero)r rI)rZcanonical_versionrrr_canonical_specJs  zSpecifier._canonical_speccCs t|jSr)hashr[rrrrr!RszSpecifier.__hash__r"cCsRt|tr6z|t|}WqFty2tYS0nt||jsFtS|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 )rr2rVrNotImplementedr[r$rrrr%Us    zSpecifier.__eq__)oprcCst|d|j|}|S)NZ _compare_)getattr _operators)rr^operator_callablerrr _get_operatorrszSpecifier._get_operator) prospectiverBrcCsJdtttt|dd}|d7}|d||oH|d||S)N.rMr=r;)joinlist itertools takewhile_is_not_suffix_version_splitrb)rrcrBprefixrrr_compare_compatiblexs zSpecifier._compare_compatiblec Cs|drbt|jdd}t|dddd}t|}t|}t||\}}|dt|} | |kSt|} | jszt|j}|| kSdS)NrMFrZrN)rOr publicrk _pad_versionlenr local) rrcrBZnormalized_prospectiveZnormalized_specZ split_specZsplit_prospectiveZpadded_prospective_Zshortened_prospectiveZ spec_versionrrr_compare_equals  zSpecifier._compare_equalcCs||| Sr)rsrrcrBrrr_compare_not_equalszSpecifier._compare_not_equalcCst|jt|kSrr rnrtrrr_compare_less_than_equalsz"Specifier._compare_less_than_equalcCst|jt|kSrrvrtrrr_compare_greater_than_equalsz%Specifier._compare_greater_than_equal)rcspec_strrcCs<t|}||ksdS|js8|jr8t|jt|jkr8dSdSNFT)r rP base_versionrrcryrBrrr_compare_less_thans zSpecifier._compare_less_thancCs^t|}||ksdS|js8|jr8t|jt|jkr8dS|jdurZt|jt|jkrZdSdSrz)r Zis_postreleaser{rqr|rrr_compare_greater_thans  zSpecifier._compare_greater_thancCst|t|kSr)r2lowerrtrrr_compare_arbitraryszSpecifier._compare_arbitraryr+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 r,rr+rrr __contains__szSpecifier.__contains__r*cCs<|dur|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&rrPrbrDr)rr+r&Znormalized_itemrarrrr,s  zSpecifier.containsr-ccsd}g}d|dur|ndi}|D]D}t|}|j|fi|r |jrZ|sZ|jsZ||q d}|Vq |s~|r~|D] }|VqrdS)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)rr,rPr&append)rr.r&yieldedfound_prereleaseskwrparsed_versionrrrr/Es" zSpecifier.filter)rAN)N)N)0rrrrZ_operator_regex_strZ_version_regex_strrecompileVERBOSE IGNORECASErEr`r2rr5rLr6r&r7rDrrXr rr[r3r!r4r%CallableOperatorrbr rmrsrurwrxr}r~rr rUnparsedVersionr,rrrr/rrrrr9ksf ^   ) / r9z^([0-9]+)((?:a|b|c|rc)[0-9]+)$cCs@g}|dD],}t|}|r0||q||q|S)Nrd)split _prefix_regexrFextendgroupsr)rresultr+rKrrrrks  rk)segmentrcstfdddD S)Nc3s|]}|VqdSr) startswith).0rlrrr sz!_is_not_suffix..)devabrcZpost)anyrrrrrjs rj)leftrightrc Csgg}}|ttdd||ttdd|||t|dd||t|dd|ddgtdt|dt|d|ddgtdt|dt|dttj|ttj|fS)NcSs|Srisdigitxrrrz_pad_version..cSs|Srrrrrrrrrr 0)rrgrhrirpinsertmaxchain)rrZ left_splitZ right_splitrrrros ,,roc@seZdZdZd$eeeddddZeeeddd Z e j edd d d Z edd d Z edddZ e dddZedefddddZeedddZe dddZeedddZeedddZd%eeeeeeddd Zd&eeeeeed!d"d#ZdS)' 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. rAN) specifiersr&rcCsFdd|dD}t}|D]}|t|qt||_||_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)rHrsrrr rz)SpecifierSet.__init__..,N)rsetaddr9 frozenset_specsrJ)rrr&Zsplit_specifiersparsed specifierrrrrLs  zSpecifierSet.__init__rcCs.|jdur|jS|jsdStdd|jDS)Ncss|] }|jVqdSrr&rrrrrrz+SpecifierSet.prereleases..)rJrrrrrrr&s  zSpecifierSet.prereleasesr'cCs ||_dSrrQr)rrrr&scCs.|jdurd|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)> NrSrAz>> 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)r2rrrrrrz'SpecifierSet.__str__..)rfsortedrrrrrr s zSpecifierSet.__str__cCs t|jSr)r\rrrrrr! szSpecifierSet.__hash__r"cCst|trt|}nt|ts"tSt}t|j|jB|_|jdurX|jdurX|j|_n<|jdurv|jdurv|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.)rr2rr]rrrJ ValueError)rr#rrrr__and__ s       zSpecifierSet.__and__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 )rr2r9rr]rr$rrrr%-s  zSpecifierSet.__eq__cCs t|jS)z7Returns the number of specifiers in this specifier set.)rprrrrr__len__GszSpecifierSet.__len__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__KszSpecifierSet.__iter__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 rrrrrrUszSpecifierSet.__contains__)r+r& installedrcs\ttstdur |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&rrrrz(SpecifierSet.contains..)rr r&rPr{allr)rr+r&rrrrr,js    zSpecifierSet.containsr-cCs|dur|j}|jr:|jD]}|j|t|d}qt|Sg}g}|D]0}t|}|jrl|sl|sv||qF||qF|s|r|durt|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&rr/r5rrrPr)rr.r&rBZfilteredrr+rrrrr/s",    zSpecifierSet.filter)rAN)NN)N)rrrrr2rr5rLr6r&r7rXr r3r!r rr4r%rrr9rrrr,rrr/rrrrrs> #    : r)#rr0rhrtypingrrrrrrrr r Zutilsr rr r2rrr5rrrrABCMetarr9rrrkrjrorrrrrs,,     7  *