3 9fym@sddlmZmZmZddlZddlZddlZddlZddlm Z m Z ddl m Z m Z mZGdddeZGdd d e ejeZGd d d eZGd d d eZddZGdddeZejdZddZddZGdddeZdS))absolute_importdivisionprint_functionN) string_typeswith_metaclass)Version LegacyVersionparsec@seZdZdZdS)InvalidSpecifierzH An invalid specifier was found, users should refer to PEP 440. N)__name__ __module__ __qualname____doc__rr /usr/lib/python3.6/specifiers.pyr sr c@seZdZejddZejddZejddZejddZej d d Z e j d d Z ejdd dZ ejdddZ d S) BaseSpecifiercCsdS)z Returns the str representation of this Specifier like object. This should be representative of the Specifier itself. Nr)selfrrr__str__szBaseSpecifier.__str__cCsdS)zF Returns a hash value for this Specifier like object. Nr)rrrr__hash__szBaseSpecifier.__hash__cCsdS)zq Returns a boolean representing whether or not the two Specifier like objects are equal. Nr)rotherrrr__eq__$szBaseSpecifier.__eq__cCsdS)zu Returns a boolean representing whether or not the two Specifier like objects are not equal. Nr)rrrrr__ne__+szBaseSpecifier.__ne__cCsdS)zg Returns whether or not pre-releases as a whole are allowed by this specifier. Nr)rrrr prereleases2szBaseSpecifier.prereleasescCsdS)zd Sets whether or not pre-releases as a whole are allowed by this specifier. Nr)rvaluerrrr9sNcCsdS)zR Determines if the given item is contained within this specifier. Nr)ritemrrrrcontains@szBaseSpecifier.containscCsdS)z Takes an iterable of items and filters them so that only items which are contained within this specifier are allowed in it. Nr)riterablerrrrfilterFszBaseSpecifier.filter)N)N)r r rabcabstractmethodrrrrabstractpropertyrsetterrrrrrrrs rc@seZdZiZd ddZddZddZd d Zd d Zd dZ ddZ ddZ e ddZ e ddZe ddZejddZddZd!ddZd"ddZdS)#_IndividualSpecifierNcCsF|jj|}|stdj||jdj|jdjf|_||_dS)NzInvalid specifier: '{0}'operatorversion)_regexsearchr formatgroupstrip_spec _prereleases)rspecrmatchrrr__init__Rs   z_IndividualSpecifier.__init__cCs0|jdk rdj|jnd}dj|jjt||S)Nz, prereleases={0!r}r$z<{0}({1!r}{2})>)r-r)r __class__r str)rprerrr__repr___s z_IndividualSpecifier.__repr__cCs dj|jS)Nz{0}{1})r)r,)rrrrrlsz_IndividualSpecifier.__str__cCs t|jS)N)hashr,)rrrrrosz_IndividualSpecifier.__hash__c CsLt|tr0y|j|}Wq@tk r,tSXnt||js@tS|j|jkS)N) isinstancerr1r NotImplementedr,)rrrrrrrs  z_IndividualSpecifier.__eq__c CsLt|tr0y|j|}Wq@tk r,tSXnt||js@tS|j|jkS)N)r6rr1r r7r,)rrrrrr}s  z_IndividualSpecifier.__ne__cCst|dj|j|S)Nz _compare_{0})getattrr) _operators)roprrr _get_operatorsz"_IndividualSpecifier._get_operatorcCst|ttfst|}|S)N)r6r rr )rr&rrr_coerce_versionsz$_IndividualSpecifier._coerce_versioncCs |jdS)Nr)r,)rrrrr%sz_IndividualSpecifier.operatorcCs |jdS)Nr)r,)rrrrr&sz_IndividualSpecifier.versioncCs|jS)N)r-)rrrrrsz _IndividualSpecifier.prereleasescCs ||_dS)N)r-)rrrrrrscCs |j|S)N)r)rrrrr __contains__sz!_IndividualSpecifier.__contains__cCs<|dkr|j}|j|}|jr(| r(dS|j|j||jS)NF)rr< is_prereleaser;r%r&)rrrrrrrs   z_IndividualSpecifier.containsccsd}g}d|dk r|ndi}xL|D]D}|j|}|j|f|r"|jr\|pL|j r\|j|q"d}|Vq"W| r|rx|D] }|VqzWdS)NFrT)r<rr>rappend)rrrZyieldedfound_prereleaseskwr&parsed_versionrrrrs       z_IndividualSpecifier.filter)r$N)N)N)r r rr9r0r4rrrrr;r<propertyr%r&rr"r=rrrrrrr#Ns         r#c@sveZdZdZejdedejejBZdddddd d Z d d Z d dZ ddZ ddZ ddZddZddZdS)LegacySpecifiera (?P(==|!=|<=|>=|<|>)) \s* (?P [^,;\s)]* # Since this is a "legacy" specifier, and the version # string can be just about anything, we match everything # except for whitespace, a semi-colon for marker support, # a closing paren since versions can be enclosed in # them, and a comma since it's a version separator. ) z^\s*z\s*$equal not_equalless_than_equalgreater_than_equal less_than greater_than)z==z!=z<=z>=<>cCst|tstt|}|S)N)r6r r2)rr&rrrr<s  zLegacySpecifier._coerce_versioncCs||j|kS)N)r<)r prospectiver.rrr_compare_equalszLegacySpecifier._compare_equalcCs||j|kS)N)r<)rrMr.rrr_compare_not_equalsz"LegacySpecifier._compare_not_equalcCs||j|kS)N)r<)rrMr.rrr_compare_less_than_equalsz(LegacySpecifier._compare_less_than_equalcCs||j|kS)N)r<)rrMr.rrr_compare_greater_than_equalsz+LegacySpecifier._compare_greater_than_equalcCs||j|kS)N)r<)rrMr.rrr_compare_less_thansz"LegacySpecifier._compare_less_thancCs||j|kS)N)r<)rrMr.rrr_compare_greater_thansz%LegacySpecifier._compare_greater_thanN)r r r _regex_strrecompileVERBOSE IGNORECASEr'r9r<rNrOrPrQrRrSrrrrrDs  rDcstjfdd}|S)Ncst|tsdS|||S)NF)r6r)rrMr.)fnrrwrapped s z)_require_version_compare..wrapped) functoolswraps)rYrZr)rYr_require_version_compare sr]c @seZdZdZejdedejejBZdddddd d d d Z e d dZ e ddZ e ddZ e ddZe ddZe ddZe ddZddZeddZejddZd S)! Specifiera (?P(~=|==|!=|<=|>=|<|>|===)) (?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]* # We just match everything, except for whitespace # since we are only testing for strict identity. ) | (?: # 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 (?: # pre release [-_\.]? (a|b|c|rc|alpha|beta|pre|preview) [-_\.]? [0-9]* )? (?: # post release (?:-[0-9]+)|(?:[-_\.]?(post|rev|r)[-_\.]?[0-9]*) )? # You cannot use a wild card and a dev or local version # together so group them with a | and make them optional. (?: (?:[-_\.]?dev[-_\.]?[0-9]*)? # dev release (?:\+[a-z0-9]+(?:[-_\.][a-z0-9]+)*)? # local | \.\* # Wild card syntax of .* )? ) | (?: # 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 [-_\.]? (a|b|c|rc|alpha|beta|pre|preview) [-_\.]? [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. (?=rKrLz===cCsNdjttjddt|dd}|d7}|jd||oL|jd||S) N.cSs|jd o|jd S)NZpostZdev) startswith)xrrrs z/Specifier._compare_compatible..rz.*z>=z==)joinlist itertools takewhile_version_splitr;)rrMr.prefixrrr_compare_compatibles   zSpecifier._compare_compatiblecCsp|jdrPt|j}t|dd}tt|}|dt|}t||\}}nt|}|jsht|j}||kS)Nz.*)endswithrZpublicrhr2len _pad_versionlocal)rrMr.rrrrNs    zSpecifier._compare_equalcCs|j|| S)N)rN)rrMr.rrrrOszSpecifier._compare_not_equalcCs |t|kS)N)r)rrMr.rrrrPsz"Specifier._compare_less_than_equalcCs |t|kS)N)r)rrMr.rrrrQsz%Specifier._compare_greater_than_equalcCs>t|}||ksdS|j r:|jr:t|jt|jkr:dSdS)NFT)rr> base_version)rrMr.rrrrRszSpecifier._compare_less_thancCs`t|}||ksdS|j r:|jr:t|jt|jkr:dS|jdk r\t|jt|jkr\dSdS)NFT)rZis_postreleaserqrp)rrMr.rrrrSs zSpecifier._compare_greater_thancCst|jt|jkS)N)r2lower)rrMr.rrr_compare_arbitraryszSpecifier._compare_arbitrarycCsR|jdk r|jS|j\}}|d krN|dkr@|jdr@|dd }t|jrNdSd S) N==>=<=~====z.*rkTF)rtrurvrwrxrl)r-r,rmr r>)rr%r&rrrrs    zSpecifier.prereleasescCs ||_dS)N)r-)rrrrrrsN)r r rrTrUrVrWrXr'r9r]rjrNrOrPrQrRrSrsrCrr"rrrrr^s*^  #      r^z^([0-9]+)((?:a|b|c|rc)[0-9]+)$cCsDg}x:|jdD],}tj|}|r2|j|jq|j|qW|S)Nr_)split _prefix_regexr(extendgroupsr?)r&resultrr/rrrrh's rhc Csgg}}|jttjdd||jttjdd||j|t|dd|j|t|dd|jddgtdt|dt|d|jddgtdt|dt|dttj|ttj|fS)NcSs|jS)N)isdigit)rarrrrb6sz_pad_version..cSs|jS)N)r~)rarrrrb7srr0)r?rerfrgrninsertmaxchain)leftrightZ left_splitZ right_splitrrrro2s && roc@seZdZdddZddZddZd d Zd d Zd dZddZ ddZ ddZ e ddZ e jddZ ddZdddZd ddZdS)! SpecifierSetr$Nc Csrdd|jdD}t}xB|D]:}y|jt|Wq tk rX|jt|Yq Xq Wt||_||_dS)NcSsg|]}|jr|jqSr)r+).0srrr Rsz)SpecifierSet.__init__..,) rysetaddr^r rD frozenset_specsr-)rZ specifiersrZparsed specifierrrrr0Os  zSpecifierSet.__init__cCs*|jdk rdj|jnd}djt||S)Nz, prereleases={0!r}r$z)r-r)rr2)rr3rrrr4dszSpecifierSet.__repr__cCsdjtdd|jDS)Nrcss|]}t|VqdS)N)r2)rrrrr nsz'SpecifierSet.__str__..)rdsortedr)rrrrrmszSpecifierSet.__str__cCs t|jS)N)r5r)rrrrrpszSpecifierSet.__hash__cCst|trt|}nt|ts"tSt}t|j|jB|_|jdkrX|jdk rX|j|_n<|jdk rv|jdkrv|j|_n|j|jkr|j|_ntd|S)NzFCannot combine SpecifierSets with True and False prerelease overrides.)r6rrr7rrr- ValueError)rrrrrr__and__ss       zSpecifierSet.__and__cCsFt|trt|}n&t|tr,tt|}nt|ts:tS|j|jkS)N)r6rrr#r2r7r)rrrrrrs    zSpecifierSet.__eq__cCsFt|trt|}n&t|tr,tt|}nt|ts:tS|j|jkS)N)r6rrr#r2r7r)rrrrrrs    zSpecifierSet.__ne__cCs t|jS)N)rnr)rrrr__len__szSpecifierSet.__len__cCs t|jS)N)iterr)rrrr__iter__szSpecifierSet.__iter__cCs.|jdk r|jS|jsdStdd|jDS)Ncss|] }|jVqdS)N)r)rrrrrrsz+SpecifierSet.prereleases..)r-rany)rrrrrs  zSpecifierSet.prereleasescCs ||_dS)N)r-)rrrrrrscCs |j|S)N)r)rrrrrr=szSpecifierSet.__contains__csNtttfstdkr$|j r4jr4dStfdd|jDS)NFc3s|]}|jdVqdS))rN)r)rr)rrrrrsz(SpecifierSet.contains..)r6r rr rr>allr)rrrr)rrrrs  zSpecifierSet.containscCs|dkr|j}|jr:x |jD]}|j|t|d}qW|Sg}g}xZ|D]R}t|ttfsdt|}n|}t|trtqH|jr| r|s|j |qH|j |qHW| r|r|dkr|S|SdS)N)r) rrrboolr6r rr r>r?)rrrr.Zfilteredr@rrBrrrrs*      zSpecifierSet.filter)r$N)N)N)r r rr0r4rrrrrrrrCrr"r=rrrrrrrMs      r)Z __future__rrrrr[rfrUZ_compatrrr&rr r rr ABCMetaobjectrr#rDr]r^rVrzrhrorrrrrs&9 4