U .e_[ @sfdZddlZddlZddlmZddlmZdddd d d d d gZee Z Gdd d e Z Gddde ZGddde ZedZddZeZGdddeZddZGdddeZeddfeddfeddfedd fed!d"fed#d"fed$d%fed&d'fed(d)fed*d+ff Zed,dfed-dfed.d%fed$d%fed/dffZed0Zd1d2Zd3d4Zed5ejZd6d6d7d6d8ddd9Zd:d;ZGdejZ"d?d@Z#dAdBZ$GdCd d eZ%GdDd d eZ&GdEdFdFe Z'e'eeee'ee!dGdHe'e$e&edIZ(e(dJe(dK<dLd Z)dS)Mz~ Implementation of a flexible versioning scheme providing support for PEP-440, setuptools-compatible and semantic versioning. N) string_typesparse_requirementNormalizedVersionNormalizedMatcher LegacyVersion LegacyMatcherSemanticVersionSemanticMatcherUnsupportedVersionError get_schemec@seZdZdZdS)r zThis is an unsupported version.N)__name__ __module__ __qualname____doc__rr?/usr/lib/python3.8/site-packages/pip/_vendor/distlib/version.pyr sc@sxeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZeddZdS)VersioncCs@||_}|||_}t|ts,tt|dksTzMatcher.cCs||kSr)rr>rrrrBUrCcCs||kp||kSr)rr>rrrrBVrCcCs||kp||kSr)rr>rrrrBWrCcCs||kSr)rr>rrrrBXrCcCs||kSr)rr>rrrrBYrCcCs||kp||kSr)rr>rrrrB[rCcCs||kSr)rr>rrrrB\rC)<><=>======~=!=cCst|Sr)rr#rrrraszMatcher.parse_requirementcCs|jdkrtd||_}||}|s:td||j|_|j|_g}|jr|jD]d\}}| dr|dkrtd||ddd}}||n||d}}| |||fq^t ||_ dS) NzPlease specify a version classz Not valid: %rz.*)rHrKz#'.*' not allowed for %r constraintsTF) version_class ValueErrorrrrnamelowerkeyZ constraintsendswithappendrr)rrrZclistopZvnprefixrrrr ds*      zMatcher.__init__cCsxt|tr||}|jD]X\}}}|j|}t|trDt||}|s`d||jjf}t |||||sdSqdS)z Check if the provided version matches the constraints. :param version: The version to match against this instance. :type version: String or :class:`Version` instance. z%r not implemented for %sFT) rrrMr _operatorsgetgetattrr7rr")rversionoperator constraintrVfmsgrrrmatchs       z Matcher.matchcCs6d}t|jdkr2|jdddkr2|jdd}|S)Nrr)rHrI)rr)rresultrrr exact_versions zMatcher.exact_versioncCs0t|t|ks|j|jkr,td||fdS)Nzcannot compare %s and %s)r$rOr%r&rrrr(szMatcher._check_compatiblecCs"|||j|jko |j|jkSr))r(rQrr&rrrr+s zMatcher.__eq__cCs || Sr)r,r&rrrr-szMatcher.__ne__cCst|jt|jSr))r3rQrr4rrrr5szMatcher.__hash__cCsd|jj|jfS)Nz%s(%r)r6r4rrrr8szMatcher.__repr__cCs|jSr)r9r4rrrr:szMatcher.__str__)rrrrMrWrr r_r<rar(r+r-r5r8r:rrrrr=Os* r=zk^v?(\d+!)?(\d+(\.\d+)*)((a|b|c|rc)(\d+))?(\.(post)(\d+))?(\.(dev)(\d+))?(\+([a-zA-Z\d]+(\.[a-zA-Z\d]+)?))?$c Cs|}t|}|s"td||}tdd|ddD}t|dkrl|ddkrl|dd}qF|dszd}n t|d}|dd }|d d }|d d }|d}|dkrd}n|dt|df}|dkrd}n|dt|df}|dkrd}n|dt|df}|dkr*d}nHg} |dD]0} | rTdt| f} nd| f} | | q8t| }|s|s|rd}nd}|sd}|sd}||||||fS)NzNot a valid version: %scss|]}t|VqdSr)int.0r?rrr sz_pep_440_key..r.r )NNr)arh)z)_)final) rPEP440_VERSION_REr_r groupsrsplitrrcisdigitrS) rmruZnumsZepochpreZpostdevZlocalrpartrrr _pep_440_keysT          r|c@s6eZdZdZddZedddddgZed d Zd S) raIA rational version. Good: 1.2 # equivalent to "1.2.0" 1.2.0 1.2a1 1.2.3a2 1.2.3b1 1.2.3c1 1.2.3.4 TODO: fill this out Bad: 1 # minimum two numbers 1.2a # release level must have a release serial 1.2.3b cCs<t|}t|}|}tdd|ddD|_|S)Ncss|]}t|VqdSr)rbrdrrrrfsz*NormalizedVersion.parse..rrg)_normalized_keyrtr_rurrv_release_clause)rrr`rxrurrrr s  zNormalizedVersion.parserpbr@rcrzcstfddjDS)Nc3s |]}|r|djkVqdS)rN) PREREL_TAGS)retr4rrrfsz2NormalizedVersion.is_prerelease..)anyrr4rr4rr;szNormalizedVersion.is_prereleaseN) rrrrrsetrr<r;rrrrrs  cCs>t|}t|}||krdS||s*dSt|}||dkS)NTFrg)str startswithr)xynrrr _match_prefixs rc @sneZdZeZddddddddd Zd d Zd d ZddZddZ ddZ ddZ ddZ ddZ ddZdS)r_match_compatible _match_lt _match_gt _match_le _match_ge _match_eq_match_arbitrary _match_ne)rJrDrErFrGrHrIrKcCsV|rd|ko|jd}n|jd o,|jd}|rN|jddd}||}||fS)N+rhrr)rrrvrM)rrZr\rVZ strip_localrrrr _adjust_local6s zNormalizedMatcher._adjust_localcCsD||||\}}||krdS|j}ddd|D}t|| S)NFrgcSsg|] }t|qSrrreirrr Isz/NormalizedMatcher._match_lt..rr~joinrrrZr\rVZrelease_clauseZpfxrrrrDs zNormalizedMatcher._match_ltcCsD||||\}}||krdS|j}ddd|D}t|| S)NFrgcSsg|] }t|qSrrrrrrrQsz/NormalizedMatcher._match_gt..rrrrrrLs zNormalizedMatcher._match_gtcCs||||\}}||kSr)rrrZr\rVrrrrTszNormalizedMatcher._match_lecCs||||\}}||kSr)rrrrrrXszNormalizedMatcher._match_gecCs.||||\}}|s ||k}n t||}|Sr)rrrrZr\rVr`rrrr\s   zNormalizedMatcher._match_eqcCst|t|kSr)rrrrrrdsz"NormalizedMatcher._match_arbitrarycCs0||||\}}|s ||k}n t|| }|Sr)rrrrrrgs   zNormalizedMatcher._match_necCsf||||\}}||krdS||kr*dS|j}t|dkrH|dd}ddd|D}t||S)NTFrrhrgcSsg|] }t|qSrrrrrrrzsz7NormalizedMatcher._match_compatible..)rr~rrrrrrrros  z#NormalizedMatcher._match_compatibleN)rrrrrMrWrrrrrrrrrrrrrr's& z[.+-]$z^[.](\d)z0.\1z^[.-]z ^\((.*)\)$\1z^v(ersion)?\s*(\d+)z\2z^r(ev)?\s*(\d+)z[.]{2,}rgz\b(alfa|apha)\balphaz\b(pre-alpha|prealpha)\bz pre.alphaz \(beta\)$betaz ^[:~._+-]+z [,*")([\]]z[~:+_ -]z\.$z (\d+(\.\d+)*)cCsL|}tD]\}}|||}q|s.d}t|}|sFd}|}n|dd}dd|D}t|dkr~| dqft|dkr|| d}n8d dd|ddD|| d}|dd}d d d|D}|}|rt D]\}}|||}q|s|}nd |kr*d nd }|||}t |sHd}|S) z Try to suggest a semantic form for a version for which _suggest_normalized_version couldn't come up with anything. z0.0.0rrgcSsg|] }t|qSrrbrrrrrsz-_suggest_semantic_version..NcSsg|] }t|qSrrrrrrrscSsg|] }t|qSrrrrrrrsrz-r)rrP _REPLACEMENTSsub_NUMERIC_PREFIXr_rurvrrSendr_SUFFIX_REPLACEMENTS is_semver)rr`ZpatreplrxrVsuffixseprrr_suggest_semantic_versions:      ,    rcCshzt||WStk r"YnX|}dD]\}}|||}q0tdd|}tdd|}tdd|}tdd |}td d |}|d r|d d}tdd |}tdd|}tdd|}tdd|}tdd|}tdd|}tdd|}tdd|}tdd|}tdd|}tdd |}z t|Wntk rbd}YnX|S)!aSuggest a normalized version close to the given version string. If you have a version string that isn't rational (i.e. NormalizedVersion doesn't like it) then you might be able to get an equivalent (or close) rational version from this function. This does a number of simple normalizations to the given string, based on observation of versions currently in use on PyPI. Given a dump of those version during PyCon 2009, 4287 of them: - 2312 (53.93%) match NormalizedVersion without change with the automatic suggestion - 3474 (81.04%) match when using this suggestion method @param s {str} An irrational version string. @returns A rational version string, or None, if couldn't determine one. ))z-alpharp)z-betar)rrp)rr)rr@)z-finalr)z-prer@)z-releaser)z.releaser)z-stabler)rrg)rrrg) r)z.finalr)rsrzpre$Zpre0zdev$Zdev0z([abc]|rc)[\-\.](\d+)$z\1\2z[\-\.](dev)[\-\.]?r?(\d+)$z.\1\2z[.~]?([abc])\.?rr?rNz\b0+(\d+)(?!\d)z (\d+[abc])$z\g<1>0z\.?(dev-r|dev\.r)\.?(\d+)$z.dev\2z-(a|b|c)(\d+)$z[\.\-](dev|devel)$z.dev0z(?![\.\-])dev$z(final|stable)$rz\.?(r|-|-r)\.?(\d+)$z.post\2z\.?(dev|git|bzr)\.?(\d+)$z\.?(pre|preview|-c)(\d+)$zc\g<2>zp(\d+)$z.post\1)r}r rPreplacererr)rZrsZorigrrrr_suggest_normalized_versions>      rz([a-z]+|\d+|[\.-])r@zfinal-@)ryZpreviewrrrzrrgcCsrdd}g}||D]T}|dr^|dkrD|rD|ddkrD|q*|r^|ddkr^|qD||qt|S)NcSstg}t|D]R}t||}|rd|ddkrBdkrRnn |d}nd|}||q|d|S)N0r9**final) _VERSION_PARTrvrP_VERSION_REPLACErXzfillrS)rr`rArrr get_partsCs     z_legacy_key..get_partsrrrhz*final-Z00000000)rpoprSr)rrr`rArrr _legacy_keyBs      rc@s eZdZddZeddZdS)rcCst|Sr))rr#rrrr]szLegacyVersion.parsecCs8d}|jD](}t|tr |dr |dkr d}q4q |S)NFrrT)rrrr)rr`rrrrr;`s zLegacyVersion.is_prereleaseNrrrrr<r;rrrrr\sc@s4eZdZeZeejZded<e dZ ddZ dS)r rrJz^(\d+(\.\d+)*)cCs`||kr dS|jt|}|s2td||dS|d}d|krV|ddd}t||S)NFzACannot compute compatible match for version %s and constraint %sTrrgr) numeric_rer_rloggerZwarningrursplitr)rrZr\rVrxrrrrrss zLegacyMatcher._match_compatibleN) rrrrrMdictr=rWrcompilerrrrrrr ks   zN^(\d+)\.(\d+)\.(\d+)(-[a-z0-9]+(\.[a-z0-9-]+)*)?(\+[a-z0-9]+(\.[a-z0-9-]+)*)?$cCs t|Sr)) _SEMVER_REr_)rrrrrsrc Csndd}t|}|st||}dd|ddD\}}}||dd||dd}}|||f||fS) NcSs8|dkr|f}n$|ddd}tdd|D}|S)NrrgcSs"g|]}|r|dn|qS)r)rwr)rerArrrrsz5_semantic_key..make_tuple..)rvr)rZabsentr`rrrr make_tuples z!_semantic_key..make_tuplecSsg|] }t|qSrrbrrrrrsz!_semantic_key..r|r)rr ru) rrrxrumajorminorZpatchryZbuildrrr _semantic_keys rc@s eZdZddZeddZdS)r cCst|Sr))rr#rrrrszSemanticVersion.parsecCs|jdddkS)Nrrr)rr4rrrr;szSemanticVersion.is_prereleaseNrrrrrr sc@seZdZeZdS)r N)rrrr rMrrrrr sc@s6eZdZd ddZddZddZdd Zd d ZdS) VersionSchemeNcCs||_||_||_dSr))rQmatcher suggester)rrQrrrrrr szVersionScheme.__init__cCs2z|j|d}Wntk r,d}YnX|SNTF)rrMr rrr`rrris_valid_versions   zVersionScheme.is_valid_versioncCs0z||d}Wntk r*d}YnX|Sr)rr rrrris_valid_matchers   zVersionScheme.is_valid_matchercCs|d|S)z: Used for processing some metadata fields zdummy_name (%s))rr#rrris_valid_constraint_listsz&VersionScheme.is_valid_constraint_listcCs|jdkrd}n ||}|Sr))rrrrrsuggests  zVersionScheme.suggest)N)rrrr rrrrrrrrrs  rcCs|Sr)rr#rrrrBrCrB) normalizedlegacyZsemanticrdefaultcCs|tkrtd|t|S)Nzunknown scheme name: %r)_SCHEMESrN)rOrrrr s )*rZloggingrcompatrutilr__all__Z getLoggerrrrNr objectrr=rrtr|r}rrrrrrrrIrrrrr rrrr r rrr rrrrs   1d =$ W               .r  $