Lf7ddlZddlZddlmZddlmZddlmZddlm Z dZ eje Z ejdejZejeZej$dZej$d ZeresSeZej-d esej%d d d dZes"ej%d dj/ddZ edej3dDZ edej3dDZGddZddZdZ dZ!dZ"dZ#dZ$d dZ%y#e$rej9dYYwxYw#e$rej9dYVwxYw)!N)environexists) ConfigParser) GeneratorTypez(-)?(\d\.\d+)(?:(-)(\d\.\d+)?)?z (?P\d+)\.? (?P\d+)?\.? (?P\d+)?[.\s]? (?Palpha|beta|candidate|final)?[.\s]? (?P\d+)?DEBPYTHON3_SUPPORTEDDEBPYTHON3_DEFAULTz"/usr/share/python3/debian_defaultsDEFAULTzdefault-versionzsupported-versionspythonc#2K|]}t|ywNint.0is '/usr/share/python3/debpython/version.py r5s8$7qCF$7.zcannot read debian_defaultsc#zK|]3}td|jjdD5yw)c32K|]}t|ywrr)rjs rrz.9sA,@qCF,@rrN)tuplestripsplitrs rrr9s264!AAGGIOOC,@AA4s9;,cheZdZ ddZdZdZdZdZdZdZ d Z d Z d Z d Z d ZdZddZy)VersionNc t|ttfrdjd|D}t|trdD]}t ||t ||yt}|d=|d=|rMtj|} | r| jjngD]\}}| |||||<|jD]$\}}|dk7r | t|}t |||&|js tdy)Nrc32K|]}t|ywrstrrs rrz#Version.__init__..Cs3USVUrmajorminormicro releaselevelserialselfvaluer*zmajor component is required) isinstancerlistjoinr!setattrgetattrlocals VERSION_REmatch groupdictitemsrr' ValueError) r,r-r'r(r)r*r+namecompr5s r__init__zVersion.__init__@s eeT] +HH3U33E eW %MdGE4$89N x L M $$U+E>> str(Version(major=3, minor=2, micro=1, releaselevel='final', serial=4)) '3.2' >>> str(Version(major=2)) '2' .{})r%r'r(format)r,results r__str__zVersion.__str__Ws7TZZ :: ! ell4::. .F r<c*tt|Sr)hashrepr)r,s r__hash__zVersion.__hash__dsDJr<cdj|}dD]*}t||}|s|dzS|dj|z },|dzS)zReturn full version string. >>> repr(Version(major=3, minor=2, micro=1, releaselevel='final', serial=4)) "Version('3.2.1.final.4')" >>> repr(Version(major=2)) "Version('2')" z Version('{})r)r*r+r>z'))r?r2)r,r@r9r-s r__repr__zVersion.__repr__gs[%%d+7DD$'E} ell5) )F 8 }r<ct|}|j |xjt|z c_|S|xjt|z c_|S)zReturn next version. >>> Version('3.1') + 1 Version('3.2') >>> Version('2') + '1' Version('3') )r!r(r'r)r,otherr@s r__add__zVersion.__add__wsI ::  LLCJ &L  LLCJ &L r<ct|}|j+|xjt|zc_|j}n*|xjt|zc_|j}|dkr t d|S)zReturn previous version. >>> Version('3.1') - 1 Version('3.0') >>> Version('3') - '1' Version('2') rzcannot decrease version further)r!r(r'rr8)r,rIr@news r__sub__zVersion.__sub__se ::  LLCJ &L,,C LLCJ &L,,C 7>? ? r<c*|j|dk(SNr _Version__cmpr,rIs r__eq__zVersion.__eq__zz% A%%r<c*|j|dkSrOrPrRs r__lt__zVersion.__lt__zz% 1$$r<c*|j|dkSrOrPrRs r__le__zVersion.__le__rTr<c*|j|dkDSrOrPrRs r__gt__zVersion.__gt__rWr<c*|j|dk\SrOrPrRs r__ge__zVersion.__ge__rTr<ct|ts t|}|j |j|j|ddkS|j|ddkS)akCompare major.minor or major only (if minor is not set). >>> Version('2.6') << Version('2.7') True >>> Version('2.6') << Version('2.6.6') False >>> Version('3') << Version('2') False >>> Version('3.1') << Version('2') False >>> Version('2') << Version('3.2.1.alpha.3') True r(ignorerr)r.r!r(rQrRs r __lshift__zVersion.__lshift__Z%)ENE :: !4::eG:4q8 8::eG:4q8 8r<ct|ts t|}|j |j|j|ddkDS|j|ddkDS)aoCompare major.minor or major only (if minor is not set). >>> Version('2.6') >> Version('2.7') False >>> Version('2.6.7') >> Version('2.6.6') False >>> Version('3') >> Version('2') True >>> Version('3.1') >> Version('2') True >>> Version('2.1') >> Version('3.2.1.alpha.3') False r(r_rr)rarRs r __rshift__zVersion.__rshift__rcr<ct|ts t|}dD]k}||k(ryt||xsd}t||xsd}|dk(r+ddddd}|j|d}|j|d}||k(r`||kD||kz cSy)Nr&rr*)alphabeta candidatefinal)r.r!r2get)r,rIr`r9value1value2rmaps r__cmpz Version.__cmps%)ENEIDv~T4(-AFUD).QF~%!#Rb1M&!,&!,VO8 8Jr<)NNNNNNr)__name__ __module__ __qualname__r;rArErGrJrMrSrVrYr[r]rbrerQr<rr!r!?sNAE+/<.   &&%&%&9*9*r<r!ct|tr t|}|rt|ddgk(rt t }nU|ddn|d|ddn|dk(rt t vrfn t }nt fdt D}|rt d|D}|S|durt d |D}|S) aJReturn a set of requested and supported Python versions. :param available: if set to `True`, return installed versions only, if set to `False`, return requested versions that are not installed. By default returns all requested versions. :type available: bool >>> sorted(get_requested_versions([(3, 0), None])) [(3, 2), (3, 3)] >>> sorted(get_requested_versions('')) == sorted(SUPPORTED) True >>> sorted(get_requested_versions([None, None])) == sorted(SUPPORTED) True >>> get_requested_versions([(5, 0), None]) == set() True Nr)rr)cryc3@K|]}|cxkrksnn|ywrrv)rvmaxvminvs rrz)get_requested_versions..sDi413Ct3C1is c3<K|]}td|zr|ywz/usr/bin/python%d.%dNrrr{s rrz)get_requested_versions..s$>(Q !7!!;<(Fc3<K|]}td|zs|ywrrrs rrz)get_requested_versions..s%B(Q$%;a%?@(r)r.r% parse_vranger/set SUPPORTEDr)vrange availableversionsr|r}s @@rget_requested_versionsrs"&#f% T&\dD\1y>*vq !!9,x&) 4<di&7D7UWEHDiDDH>(>> O e B(BB Or<c|dvrytj|}|std|z|j}t |j ddk(r(t d|djdD}||fSdx}}|d r|d}n |d}|d}|r!t d |jdDnd}|r!t d |jdDnd}|r|r||kDrtd|z||fS) aReturn minimum and maximum Python version from given range. >>> parse_vrange('3.0-') ((3, 0), None) >>> parse_vrange('3.1-3.3') ((3, 1), (3, 3)) >>> parse_vrange('3.2-4.0') ((3, 2), (4, 0)) >>> parse_vrange('-3.7') (None, (3, 7)) >>> parse_vrange('3.2') ((3, 2), (3, 2)) >>> parse_vrange('') == parse_vrange('-') == (None, None) True )r -NNzversion range is invalid: %sNc32K|]}t|ywrrrs rrzparse_vrange..%s:%9SV%9rrxrrc32K|]}t|ywrrrs rrzparse_vrange../1AQrc32K|]}t|ywrrrs rrzparse_vrange..0rr)RANGE_REr5r8groupsr/countrr)r-r5rr}r|s rrr s   NN5 !E 7%?@@ \\^F F|$1$:VAY__S%9::TzD4 ayayayay5951C1 1tD5951C1 1tD 7%?@@ :r<c`dx}}t}|jdD]}|j}tjd|}|rd|j dz}@tjd|}|rd|j dz}mtjd|}|s|j d|j dzt|dk(r&|j}t|t|fS|s|rt|d}|r t|nd|r t|fSdfS) aParse X-Python3-Version. >>> parse_pycentral_vrange('>= 3.1') ((3, 1), None) >>> parse_pycentral_vrange('<< 4.0') (None, (4, 0)) >>> parse_pycentral_vrange('3.1') ((3, 1), (3, 1)) >>> parse_pycentral_vrange('3.1, 3.2') ((3, 1), None) Nrz>=\s*([\d\.]+)z%.3srxz<<\s*([\d\.]+)z ^[\d\.]+$r) rrrrer5groupaddlenpopgetversorted)r-r}r| hardcodeditemr5vers rparse_pycentral_vranger8sD4I C zz|*D1 EKKN*D *D1 EKKN*D t,  MM&5;;q>1 2! 9~mmoc{F3K'' Ii #6$>> vrange_str(((3, 4), None)) '3.4-' >>> vrange_str(((3, 4), (3, 6))) '3.4-3.6' >>> vrange_str(((3, 4), (4, 0))) '3.4-4.0' >>> vrange_str((None, (3, 7))) '-3.7' >>> vrange_str(((3, 5), (3, 5))) '3.5' >>> vrange_str((None, None)) '-' rrxrrc32K|]}t|ywrr$rs rrzvrange_str..v2 1A rc32K|]}t|ywrr$rs rrzvrange_str..xs8ic!firc32K|]}t|ywrr$rs rrzvrange_str..zrrc32K|]}t|ywrr$rs rrzvrange_str..|"=9a3q69rc32K|]}t|ywrr$rs rrzvrange_str..}rr)r0)rs r vrange_strrcs ayF1I%& ayF1Ixx2q 222  SXX8fQi8888  xx2q 22S88(("=6!9"==(("=6!9"==? ?r<cPt|tr|St|ttfs+t|dtrdj d|DSg}|D]K}t|tr|j |%|j dj d|DM|S)z >>> vrepr(([3, 4], [3, 2])) ['3.4', '3.2'] >>> vrepr(('2.6', '3.1')) ['2.6', '3.1'] >>> vrepr('3.2') '3.2' >>> vrepr((3, 2)) '3.2' rrc32K|]}t|ywrr$rs rrzvrepr..s.1Arc32K|]}t|ywrr$rs rrzvrepr..s";7a3q67r)r.r%rrrr0append)r-r@versions rvreprrs%  s3 4E!Hc9Rxx.... F gs # MM' " MM#((";7";; <  Mr<c||syt|tr|ddStd|jddDddS)zReturn pair of integers that represent version. >>> getver('3.2') (3, 2) >>> getver('3.1.4') (3, 1) >>> getver((3, 3, 1)) (3, 3) >>> getver(None) '' r Nc32K|]}t|ywrrrs rrzgetver..s5!4AQ!4rr)r.rr)r-s rrrsC %Ray 5S!!45 5bq 99r<cg}g}t|D]I}t|tr t|}|tkr|j |9|j |K|j t||r |r t|S|S)aReturn sorted list of versions starting with default Python version (if available) then list of suppored versions greater than default one followed by reversed list of older versions. List of versions sorted this way can be used in Depends field. :param vrepr: return string represenatations of versions, by default the same format is used as in :param:`versions` >>> debsorted([(2, 6), (3, 1), (3, 2), (3, 3), (2, 7)])[0] == DEFAULT True >>> debsorted(('2.4', '3.2', '2.6', '2.7'))[-1] (2, 4) >>> debsorted(set([(2, 1), (2, 2)])) [(2, 2), (2, 1)] >>> debsorted([(2, 1), (2, 2)], return_str=True) ['2.2', '2.1'] ) rr.r%rr rextendreversedr)r return_strr@ old_versionsrs r debsortedrsy&FL(# gs #WoG W     ( MM' " $ MM(<()fV} Mr<rr)&loggingrosros.pathr configparserrtypesr RANGE_PATTERNcompilerVERBOSEr4 getLoggerrslogrn _supported_default_configreadreplacerrr Exception exceptionrr!rrrrrrrrvr<rrs, %2 2::m $ RZZ  % g!W[[/ 0 7;;+ ,nG LL56 ;;y*;