[c)@sdZddkZddkZddkZddklZddkZddkZddkZddk Z ddk Z ddk Z ddk Z ddk Z ddkZddkZddkZddkZddkZddkZddgZyddkZeidWnej o dZnXddklZlZddkTyddkZddkZWnej o dZnXy4ddkZe d d d d d gZ!d gZ"WnYej oMddk#Z#ddk$Z$e d d gZ!d gZ"ddPdYZnXddk l%Z%ddk&l'Z'l(Z(ha)ha*dZ+dZ,da-dZ.da/dZ0dZ1dZ2da3dZ4dZ5dZ6ddQdYZ7ddRdYZ8dSdd!Z9d"Z:d#dTd$YZ;d%Z<e=d&Z>d'Z?d(Z@ddeAd)ZBd*ZCdd+ZDd,eAd-d.ZEd/ZFd0ZGd1ZHd2ZId3ZJd4ZKd5ZLd6ZMd7ZNd8ZOd9d:ZPd9d;ZQd<ZRd=iSd>eTd?DZUe=d@ZVdAZWdBZXdCZYdaZdDZ[ddk\Z\ddk]Z]eAe=dEZ^dFZ_dGZ`dHZadIZbde=e=dJZce=dKZdeAdLZedafdMZgdNZhdOZidS(Us% Assorted utility functions for yum. iN(tStringIOtgztbz2txz(tstringToVersiont flagToString(t*tmd5tsha1tsha256tsha384tsha512thashlibcBseZedZRS(cCs=|djo tiS|djo tiStddS(NRRsBad checksum type(Rtnewtshat ValueError(talgo((s,/usr/lib/python2.6/site-packages/yum/misc.pyR 2s     (t__name__t __module__t staticmethodR (((s,/usr/lib/python2.6/site-packages/yum/misc.pyR 0s(t MiscError(tto_utf8t to_unicodecCsKt}t|to t}nt|tijo|S|i||S(s Take a value and use the same value from the store, if the value isn't in the store this one becomes the shared version. (t_share_data_storet isinstancetunicodet_share_data_store_uttypettypest TupleTypet setdefault(tvaluetstore((s,/usr/lib/python2.6/site-packages/yum/misc.pyt share_dataBs  cCshahadS(N(RR(((s,/usr/lib/python2.6/site-packages/yum/misc.pyt unshare_dataRscCs-tdjotidiant|S(s( Tests if a string is a shell wildcard. s [*?]|\[.+\]N(t_re_compiled_glob_matchtNonetretcompiletsearch(ts((s,/usr/lib/python2.6/site-packages/yum/misc.pytre_globYs cCs-tdjotidiant|S(s Tests if a string could be a filename. We still get negated character classes wrong (are they supported), and ranges in character classes. s[/*?]|\[[^]]*/[^]]*\]N(t_re_compiled_filename_matchR$R%R&tmatch(R(((s,/usr/lib/python2.6/site-packages/yum/misc.pyt re_filenamecs cCs(t|otS|djotStS(s Tests if a filename string, can be matched against just primary. Note that this can produce false negatives (but not false positives). Note that this is a superset of re_primary_dirname(). s/usr/lib/sendmail(tre_primary_dirnametTruetFalse(tfilename((s,/usr/lib/python2.6/site-packages/yum/misc.pytre_primary_filenameks   cCs+d|jotS|idotStS(s~ Tests if a dirname string, can be matched against just primary. Note that this is a subset of re_primary_filename(). sbin/s/etc/(R.t startswithR/(tdirname((s,/usr/lib/python2.6/site-packages/yum/misc.pyR-us  cCshtdjo4tidi}tidi}||fanx tD]}||otSqHWtS(sC Tests if a string needs a full nevra match, instead of just name. s.*([-.*?]|\[.+\]).s[0-9]+:N(t_re_compiled_full_matchR$R%R&R+R.R/(R(tonettwotrec((s,/usr/lib/python2.6/site-packages/yum/misc.pytre_full_search_neededs   cCsO|i}|idotS|idotS|idotStS(s8 Tests if a string is a "remote" URL, http, https, ftp. shttp://shttps://sftp://(tlowerR2R.R/(R(((s,/usr/lib/python2.6/site-packages/yum/misc.pyt re_remote_urls c Cs&t|}|djogSyt|}Wntj on Xt|Syt|}|iWntj o ~nnX|d}d}}xM||jo?|||jo ||||<}|d7}n|d7}qW|| Sg}x,|D]$}||jo|i|qqW|S(s Return a list of the elements in s, but without duplicates. For example, unique([1,2,3,1,2,3]) is some permutation of [1,2,3], unique("abcabc") some permutation of ["a", "b", "c"], and unique(([1, 2], [2, 3], [1, 2])) some permutation of [[2, 3], [1, 2]]. For best speed, all sequence elements should be hashable. Then unique() will usually work in linear time. If not possible, the sequence elements should enjoy a total ordering, and if list(s).sort() doesn't raise TypeError it's assumed that they do enjoy a total ordering. Then unique() will usually work in O(N*log2(N)) time. If that's not possible either, the sequence elements must support equality-testing. Then unique() will usually work in quadratic time. ii(tlentsett TypeErrortlisttsorttappend(R(tntutttlasttlastititx((s,/usr/lib/python2.6/site-packages/yum/misc.pytuniques8        t ChecksumscBszeZdZd eedZdZeddZdZ ddZ d Z d d Z d Z d d ZRS(sn Generate checksum(s), on given pieces of data. Producing the Length and the result(s) when complete. cCs|djo t}ng|_g|_d|_t}x|D]}|djo d}n||joqBn|tjoti|}n|oqBnt d||i ||ii ||ii |qBW| o| o t dndS(NiRRs(Error Checksumming, bad checksum type %ss*Error Checksumming, no valid checksum type( R$t_default_checksumst _sumalgost _sumtypest_lenR<t_available_checksumsR R RtaddR@(tselft checksumstignore_missingt ignore_nonetdonetsumtypetsumalgo((s,/usr/lib/python2.6/site-packages/yum/misc.pyt__init__s,            cCs|iS(N(RM(RP((s,/usr/lib/python2.6/site-packages/yum/misc.pyt__len__stfgetcCs|iS((RM(RP((s,/usr/lib/python2.6/site-packages/yum/misc.pytscCs:|it|7_x|iD]}|i|qWdS(N(RMR;RKtupdate(RPtdataRV((s,/usr/lib/python2.6/site-packages/yum/misc.pyR[s iicCs |i|}|i||S(N(treadR[(RPtfotsizeR\((s,/usr/lib/python2.6/site-packages/yum/misc.pyR]s cCs@h}x3t|i|iD]\}}|i||Qtkeyidt timestampt fingerprinttraw_keythas_sigt valid_sigthashed_subpaksiN(tpgpmsgtdecode_multiple_keyst ExceptionRtstrR;t public_keytkey_idtuser_idtstructtunpackRRRR/tuser_idsRt signatureRtget_hashed_subpaktSIG_SUB_TYPE_CREATE_TIMER$tintR@( Rtmultiplet key_info_objstkeysRztkeyt keyid_blobtinfoRttspkt((s,/usr/lib/python2.6/site-packages/yum/misc.pyt getgpgkeyinfos@      cCs d|d@S(s[Convert an integer representing a GPG key ID to the hex version string used by RPM s%08xl((R((s,/usr/lib/python2.6/site-packages/yum/misc.pyt keyIdToRPMVerscCs}t|}xj|iddD]V}|d|jo?t|dd}||jodS||jodSdSqqWd S( sd Return if the GPG key described by the given keyid and timestamp are installed in the rpmdb. The keyid and timestamp should both be passed as integers. The ts is an rpm transaction set object Return values: - -1 key is not installed - 0 key with matching ID and timestamp is installed - 1 key with matching ID is installed but has a older timestamp - 2 key with matching ID is installed but has a newer timestamp No effort is made to handle duplicates. The first matching keyid is used to calculate the return result. tnames gpg-pubkeytversiontreleaseiiiii(RtdbMatchR(ttsRRthdrt installedts((s,/usr/lib/python2.6/site-packages/yum/misc.pyt keyInstalleds    cCstdjotS|pd|}ntii|pti|nt|}|tid          cCstdjptii| ogS|tidtGTs>=tGERtEQtR@(tseqt max_entriesRbtnumtbegtend((s,/usr/lib/python2.6/site-packages/yum/misc.pyt seq_max_split[s     Rccs0x)|]"}|djot|VqqWdS(i i i N(i i i (tchr(t.0RF((s,/usr/lib/python2.6/site-packages/yum/misc.pys is i cCs(t|tjoCyt|dWqtj ot|did}qXnLt|tjo|id}n&|djodStdt||i}|i dt }|i dd}|i dd}|i d d }|o(|i d d }|i d d}n|S(s_ Returns xml-friendly utf-8 encoded string. Accepts utf-8, iso-8859-1, or unicode. sutf-8s iso-8859-1RsString expected, got %st&s&R!s<Rs>t"s"t's'N( RRRtUnicodeDecodeErrortencodeR$RtreprtrstripR7t _deletecharsRX(Rtattrib((s,/usr/lib/python2.6/site-packages/yum/misc.pytto_xmlks&!  cCsGyti|Wn/tj o#}|itijoqCnXdS(s| Call os.unlink, but don't die if the file isn't there. This is the main difference between "rm -f" and plain "rm". N(R|tunlinkRvterrnotENOENT(R0Rz((s,/usr/lib/python2.6/site-packages/yum/misc.pytunlink_fs cCsQyti|SWn9tj o-}|ititifjondSXdS(sF Call os.stat(), but don't die if the file isn't there. Returns None. N(R|tstatRvRRtENOTDIRR$(R0Rz((s,/usr/lib/python2.6/site-packages/yum/misc.pytstat_fs cCs\ytd}Wntj odSX|i}yt|SWntj odSXdS(s Get the audit-uid/login-uid, if available. None is returned if there was a problem. Note that no caching is done here. s/proc/self/loginuidN(RrRuR$R]RR(R^R\((s,/usr/lib/python2.6/site-packages/yum/misc.pyt _getloginuids cCstdjo tantS(s Get the audit-uid/login-uid, if available. None is returned if there was a problem. The value is cached, so you don't have to save it. N(t_cached_getloginuidR$R(((s,/usr/lib/python2.6/site-packages/yum/misc.pyt getloginuids  cCsy5titid|otitidnWnEtij o6}tidIJdtid|idd}|idd}|i|iq)n|i |q)WqW|S(s'takes a glob of a dir (like /etc/foo.d/*.foo) returns a list of all the lines in all the files matching that glob, ignores comments and blank lines, optional paramater 'line_as_list tells whether to treat each line as a space or comma-separated list, defaults to Trues\s*(#|$)s t t,( RRrR%R+R{tlstripRXtextendRR@(tthisglobt line_as_listtresultstfnameR((s,/usr/lib/python2.6/site-packages/yum/misc.pytread_in_items_from_dot_dir]s$   cCsQtdjo@yddkl}Wntj oddk}nX|andS(s Importing xElementTree all the time, when we often don't need it, is a huge timesink. This makes python -c 'import yum' suck. So we hide it behind this function. And have accessors. i(t cElementTreeN(t__cached_cElementTreeR$t xml.etreeRR(R((s,/usr/lib/python2.6/site-packages/yum/misc.pyt_cElementTree_importus  cCstti|S(s) Lazily load/run: cElementTree.iterparse (RRt iterparse(R0((s,/usr/lib/python2.6/site-packages/yum/misc.pytcElementTree_iterparsescCstti|S(s% Lazily load/run: cElementTree.parse (RRtparse(R0((s,/usr/lib/python2.6/site-packages/yum/misc.pytcElementTree_xmlparses(((i((jRhRR|tos.patht cStringIORRRR%RR,R)RRRRR6RR@RR<R>R@RR$trpmUtils.miscutilsRRRRtgpgme.editutilR R<RNRJRRRti18nRRRRR!R"R#R)R*R,R1R-R4R8R:RHRIRkReRRRR/RRRR.RRRRRRRR(R5R;RHRIRSRUR`RlRrRtrangeR|R~RRRRRRRRRRRRRRRRRRR(((s,/usr/lib/python2.6/site-packages/yum/misc.pyts                                     BM   2  !1  (  # !     .  !    # +