ó +¢µRc@söddlZddlZddlmZddlmZddlmZmZm Z ddl m Z dgZ dZ dZejeƒZejeƒZejd ƒZejd ƒZe sÃe r"eƒZejd ƒesøejd d ƒdZnes"ejd dƒjddƒZq"ny#ed„ejdƒDƒƒZ Wnek reejdƒnXy#ed„ejdƒDƒƒZ Wnek r©ejdƒnXddd„Zd„Z d„Z!d„Z"d„Z#d„Z$dd„Z%dS( iÿÿÿÿN(tSafeConfigParser(tenviron(texiststdirnametjoin(t GeneratorTypeiis(-)?(\d\.\d+)(?:(-)(\d\.\d+)?)?tDEBPYTHON_SUPPORTEDtDEBPYTHON_DEFAULTs!/usr/share/python/debian_defaultstDEFAULTsdefault-versionissupported-versionstpythontccs|]}t|ƒVqdS(N(tint(t.0ti((s&/usr/share/python/debpython/version.pys 3st.scannot read debian_defaultsccs4|]*}td„|jƒjdƒDƒƒVqdS(css|]}t|ƒVqdS(N(R (R tj((s&/usr/share/python/debpython/version.pys 7sRN(ttupletstriptsplit(R R ((s&/usr/share/python/debpython/version.pys 7st,cs&t|tƒrt|ƒ}n| s=t|ƒddgkrLttƒ}n’|ddkrbdn|d‰|ddkr‚d n|d‰ˆˆkr¿tˆtkr°ˆfntƒƒ}nt‡‡fd†tDƒƒ}|rýtd„|Dƒƒ}n%|tkr"td„|Dƒƒ}n|S( s>Return 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([(2, 5), (3, 0)])) [(2, 7)] >>> sorted(get_requested_versions('')) == sorted(SUPPORTED) True >>> sorted(get_requested_versions([None, None])) == sorted(SUPPORTED) True >>> get_requested_versions([(5, 0), None]) set([]) iiicc3s1|]'}ˆ|ko ˆknr|VqdS(N((R tv(tmaxvtminv(s&/usr/share/python/debpython/version.pys Yscss%|]}td|ƒr|VqdS(s/usr/bin/python%d.%dN(R(R R((s&/usr/share/python/debpython/version.pys \scss%|]}td|ƒs|VqdS(s/usr/bin/python%d.%dN(R(R R((s&/usr/share/python/debpython/version.pys _sN(ii(icic( t isinstancet basestringt parse_vrangetlisttNonetsett SUPPORTEDRtFalse(tvranget availabletversions((RRs&/usr/share/python/debpython/version.pytget_requested_versions=s   ' cCsL|d krd Stj|ƒ}|s8td|ƒ‚n|jƒ}t|ƒjd ƒdkrŒtd„|djdƒDƒƒ}||fSd }}|dr­|d}n|d}|d}|rætd „|jdƒDƒƒnd }|rtd „|jdƒDƒƒnd }|rB|rB||krBtd|ƒ‚n||fS(sƒReturn minimum and maximum Python version from given range. >>> parse_vrange('2.4-') ((2, 4), None) >>> parse_vrange('2.4-2.6') ((2, 4), (2, 6)) >>> parse_vrange('2.4-3.0') ((2, 4), (3, 0)) >>> parse_vrange('-2.7') (None, (2, 7)) >>> parse_vrange('2.5') ((2, 5), (2, 5)) >>> parse_vrange('') == parse_vrange('-') == (None, None) True R t-sversion range is invalid: %sicss|]}t|ƒVqdS(N(R (R R ((s&/usr/share/python/debpython/version.pys ~siRicss|]}t|ƒVqdS(N(R (R R ((s&/usr/share/python/debpython/version.pys ˆscss|]}t|ƒVqdS(N(R (R R ((s&/usr/share/python/debpython/version.pys ‰s(R R#N(NN( RtRANGE_REtmatcht ValueErrortgroupsRtcountRR(tvalueR%R'RR((s&/usr/share/python/debpython/version.pyRes&  #      ++c Cs d„}t}d}}tƒ}xä|jdƒD]Ó}|jƒ}|dkrVq2n|dkrnt}q2ntjd|ƒ}|rŸd|jdƒ}q2ntjd|ƒ}|rÐd|jdƒ}q2ntjd |ƒ}|r2|j d|jd ƒƒq2q2Wt |ƒdkr=|j ƒ}t |ƒt |ƒfS| r]|r]t |ƒd }n|rÛt |d |rx|nd |r‡|nd fƒƒ} | s°td |ƒ‚nt| krÆttfS| d | d fSn|rít |ƒnd|rt |ƒndfS(s×Parse XS-Python-Version. >>> parse_pycentral_vrange('current') == (DEFAULT, DEFAULT) True >>> parse_pycentral_vrange('all') (None, None) >>> parse_pycentral_vrange('all, >= 2.4') ((2, 4), None) >>> parse_pycentral_vrange('all, << 3.0') (None, (3, 0)) >>> parse_pycentral_vrange('2.6') ((2, 6), (2, 6)) >>> parse_pycentral_vrange('2.5, 2.6') ((2, 5), None) >>> parse_pycentral_vrange('>= 2.6.3') ((2, 6), None) cSstt|ƒƒS(N(R"R(tx((s&/usr/share/python/debpython/version.pyt£sRtalltcurrents>=\s*([\d\.]+)s%.3sis<<\s*([\d\.]+)s ^[\d\.]+$is%s-%sR s9version range doesn't match installed Python versions: %sN(RRRRRtTruetreR%tgrouptaddtlentpoptgetvertsortedR&R( R)tgetR-RRt hardcodedtitemR%tverR!((s&/usr/share/python/debpython/version.pytparse_pycentral_vrange‘sJ      !    cCsõ|d|dkod knr(dS|d|dkrWdjd„|dDƒƒS|dd kr†ddjd„|dDƒƒS|dd krµdjd„|dDƒƒdSddjd „|dDƒƒdjd „|dDƒƒfSd S( sMReturn version range string from given range. >>> vrange_str(((2, 4), None)) '2.4-' >>> vrange_str(((2, 4), (2, 6))) '2.4-2.6' >>> vrange_str(((2, 4), (3, 0))) '2.4-3.0' >>> vrange_str((None, (2, 7))) '-2.7' >>> vrange_str(((2, 5), (2, 5))) '2.5' >>> vrange_str((None, None)) '-' iiR#Rcss|]}t|ƒVqdS(N(tstr(R R ((s&/usr/share/python/debpython/version.pys çscss|]}t|ƒVqdS(N(R;(R R ((s&/usr/share/python/debpython/version.pys éscss|]}t|ƒVqdS(N(R;(R R ((s&/usr/share/python/debpython/version.pys ëss%s-%scss|]}t|ƒVqdS(N(R;(R R ((s&/usr/share/python/debpython/version.pys íscss|]}t|ƒVqdS(N(R;(R R ((s&/usr/share/python/debpython/version.pys îsN(RR(R((s&/usr/share/python/debpython/version.pyt vrange_strÔs$cCs­t|tƒr|St|ttfƒ rSt|dtƒrSdjd„|DƒƒSg}xM|D]E}t|tƒr…|j|ƒq`|jdjd„|Dƒƒƒq`W|S(s¨ >>> vrepr(([2, 7], [3, 2])) ['2.7', '3.2'] >>> vrepr(('2.6', '3.1')) ['2.6', '3.1'] >>> vrepr('2.7') '2.7' >>> vrepr((2, 7)) '2.7' iRcss|]}t|ƒVqdS(N(R;(R R ((s&/usr/share/python/debpython/version.pys scss|]}t|ƒVqdS(N(R;(R R ((s&/usr/share/python/debpython/version.pys s(RRRRR Rtappend(R)tresulttversion((s&/usr/share/python/debpython/version.pytvreprñs  $cCs.|s dStd„|jddƒDƒƒd S(s•Return pair of integers that represent version. >>> getver('2.5') (2, 5) >>> getver('2.6.4') (2, 6) >>> getver(None) '' R css|]}t|ƒVqdS(N(R (R R ((s&/usr/share/python/debpython/version.pys sRi(RR(R)((s&/usr/share/python/debpython/version.pyR4 s cCs—g}g}x[t|ƒD]M}t|tƒr=t|ƒ}n|tkrY|j|ƒq|j|ƒqW|jt|ƒƒ|r“|r“t|ƒS|S(s£Return 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), (2, 5), (2, 4), (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'] ( R5RRR4RR=textendtreversedR@(R!t return_strR>t old_versionsR?((s&/usr/share/python/debpython/version.pyt debsorteds   (ii(ii(&tloggingR/t ConfigParserRtosRtos.pathRRRttypesRRRt RANGE_PATTERNtcompileR$t getLoggert__name__tlogR6t _supportedt_defaultt_configtreadtreplaceRRt Exceptiont exceptionRR"RR:R<R@R4RE(((s&/usr/share/python/debpython/version.pytsH     #   ( , C