Current File : //proc/2/root/usr/lib/python2.7/site-packages/yum/misc.pyc
�
�v_c@s�dZddlZddlZddlZddlZddlmZddlZddlZddl Z ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlZddlZddgZyddlZejd�Wnek
rTdZnXddlmZmZddl Tyddl!Z!ddl"Z!Wnek
r�dZ!nXy+ddl#Z#e$d d
ddd
g�Z%WnNek
r&ddl&Z&ddl'Z'e$d d
g�Z%ddYd��YZ#nXe$�Z(x�e)e%�D]�Z*ye#j+e*�Wq=e,k
r�Z-e.e-e/�r�e0e-�j1d�r�e(j2e*�nej3de4e*�IJe%j5e*�q=Xq=Wx0dZD]Z*e*e%kr�e*gZ6Pq�q�Wed�ddlm7Z7m8Z8ddl9m:Z:m;Z;ia<ia=d�Z>d�Z?da@d�ZAeBd�ZCdaDd�ZEd�ZFd�ZGdaHd�ZId�ZJd�ZKdd[d ��YZLd!d\d"��YZMd]dd%�ZNd&�ZOd'd^d(��YZPd)�ZQd*d+�ZReBd,�ZSd-�ZTd.�ZUddeVd/�ZWd0�ZXdd1�ZYd2eVd3d4�ZZd5�Z[d6�Z\d7�Z]d8�Z^d9�Z_d:�Z`d;�Zad<�Zbd=�Zcd>�Zdd?d@�Zed?dA�ZfdB�ZgdCjhdD�eidE�D��ZjeBdF�ZkdG�ZleBdH�ZmdI�ZndaodJ�ZpddlqZqeVeBdK�ZrdL�ZsdM�ZtdN�ZudO�ZvdeBeBdP�ZweBdQ�ZxeVdR�ZydazdS�Z{dT�Z|dU�Z}dV�Z~dW�ZdX�Z�dS(_s%
Assorted utility functions for yum.
i����N(tStringIOtgztbz2txz(tstringToVersiontflagToString(t*tmd5tsha1tsha256tsha384tsha512thashlibcBseZed��ZRS(cCs9|dkrtj�S|dkr,tj�Std�dS(NRRsBad checksum type(Rtnewtshat
ValueError(talgo((s,/usr/lib/python2.7/site-packages/yum/misc.pyR
4s
(t__name__t
__module__tstaticmethodR
(((s,/usr/lib/python2.7/site-packages/yum/misc.pyR2ssdisabled for fipssChecksum type %s disabledsbroken hashlib(t MiscErrortFIPSNonCompliantError(tto_utf8t
to_unicodecCsGt}t|t�rt}nt|�tjkr7|S|j||�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.7/site-packages/yum/misc.pyt
share_data[s cCsiaiadS(N(RR(((s,/usr/lib/python2.7/site-packages/yum/misc.pytunshare_datakscCs+tdkr!tjd�jant|�S(s( Tests if a string is a shell wildcard. s[*?]|\[.+\]N(t_re_compiled_glob_matchtNonetretcompiletsearch(ts((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_globrscs�t��r[y5|rtjp!d}tjtj��|�jSWq[tjk
rWq[Xn|rz�j���fd�S�fd�S(s5 Compile shell wildcards, return a 'match' function. ics|j��kS(N(tlower(R)(tpat(s,/usr/lib/python2.7/site-packages/yum/misc.pyt<lambda>�scs
|�kS(N((R)(R,(s,/usr/lib/python2.7/site-packages/yum/misc.pyR-�s( R*R&tIR'tfnmatcht translatetmatchterrorR+(R,tignore_casetflags((R,s,/usr/lib/python2.7/site-packages/yum/misc.pytcompile_pattern{s
cCs+tdkr!tjd�jant|�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'R1(R)((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_filename�scCs$t|�rtS|dkr tStS(s" Tests if a filename string, can be matched against just primary.
Note that this can produce false negatives (Eg. /b?n/zsh) but not false
positives (because the former is a perf hit, and the later is a
failure). Note that this is a superset of re_primary_dirname(). s/usr/lib/sendmail(tre_primary_dirnametTruetFalse(tfilename((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_primary_filename�s
cCs'd|krtS|jd�r#tStS(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/(R9t
startswithR:(tdirname((s,/usr/lib/python2.7/site-packages/yum/misc.pyR8�s
cCsdtdkr?tjd�j}tjd�j}||fanxtD]}||�rFtSqFWtS(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'R1R9R:(R)tonettwotrec((s,/usr/lib/python2.7/site-packages/yum/misc.pytre_full_search_needed�s
cCsI|j�}|jd�rtS|jd�r2tS|jd�rEtStS(s8 Tests if a string is a "remote" URL, http, https, ftp. shttp://shttps://sftp://(R+R=R9R:(R)((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
re_remote_url�scCs,t|�}|dkrgSyt|�}Wntk
r?nXt|�Syt|�}|j�Wntk
rz~n{X|dks�t�|d}d}}xI||kr�|||kr�||||<}|d7}n|d7}q�W|| Sg}x*|D]"}||kr|j|�qqW|S(sReturn 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 TypeErrortlisttsorttAssertionErrortappend(R)tntutttlasttlastititx((s,/usr/lib/python2.7/site-packages/yum/misc.pytunique�s6
t ChecksumscBszeZdZd
eed�Zd�Zedd��Zd�Z dd�Z
d �Zd
d
�Zd�Z
d
d�ZRS(sn Generate checksum(s), on given pieces of data. Producing the
Length and the result(s) when complete. cCs|dkrt}ng|_g|_d|_t�}x�|D]�}|dkr[d}n||krmq@n|tkr�tj|�}n4|r�q@n(|t kr�t
|��n
td|�|j|�|jj
|�|jj
|�q@W|r
|r
td�ndS(NiRRs(Error Checksumming, bad checksum type %ss*Error Checksumming, no valid checksum type(R%t_default_checksumst _sumalgost _sumtypest_lenRFt_available_checksumsRR
t_fips_noncompliantRRtaddRK(tselft checksumstignore_missingtignore_nonetdonetsumtypetsumalgo((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__init__ s.
cCs|jS(N(RX(R\((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__len__%stfgetcCs|jS(N(RX(R\((s,/usr/lib/python2.7/site-packages/yum/misc.pyR-)scCs:|jt|�7_x|jD]}|j|�qWdS(N(RXRERVtupdate(R\tdataRb((s,/usr/lib/python2.7/site-packages/yum/misc.pyRf+siicCs |j|�}|j|�|S(N(treadRf(R\tfotsizeRg((s,/usr/lib/python2.7/site-packages/yum/misc.pyRh0s
cCs@i}x3t|j|j�D]\}}|j�||<qW|S(N(tzipRWRVt hexdigest(R\tretRatsumdata((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
hexdigests5s"cCsL|dkr)|jsdS|jd}n|dkr>d}n|j�|S(NiRR(R%RWRo(R\tchecksum((s,/usr/lib/python2.7/site-packages/yum/misc.pyRl;s cCs@i}x3t|j|j�D]\}}|j�||<qW|S(N(RkRWRVtdigest(R\RmRaRn((s,/usr/lib/python2.7/site-packages/yum/misc.pytdigestsDs"cCsL|dkr)|jsdS|jd}n|dkr>d}n|j�|S(NiRR(R%RWRr(R\Rp((s,/usr/lib/python2.7/site-packages/yum/misc.pyRqJs Ni(RRt__doc__R%R:RcRdtpropertytlengthRfRhRoRlRrRq(((s,/usr/lib/python2.7/site-packages/yum/misc.pyRTs tAutoFileChecksumscBs2eZdZeed�Zd�Zdd�ZRS(sk Generate checksum(s), on given file/fileobject. Pretending to be a file
object (overrrides read). cCs"||_t|||�|_dS(N(t_foRTR](R\RiR]R^R_((s,/usr/lib/python2.7/site-packages/yum/misc.pyRcXs cCst|j|�S(N(tgetattrRw(R\tattr((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__getattr__\si����cCs|jj|j|�S(N(R]RhRw(R\Rj((s,/usr/lib/python2.7/site-packages/yum/misc.pyRh_s(RRRsR:RcRzRh(((s,/usr/lib/python2.7/site-packages/yum/misc.pyRvTs iicCsy�t|�tjkr!|}nt|d�}t|g�}x5|j||�rv|dk rB|j|krBPqBqBWt|�tjkr�|j �n|dk r�||jkr�d||j
|�fS|j
|�SWn&ttfk
r}t
d|�nXdS(s�takes filename, hand back Checksum of it
sumtype = md5 or sha/sha1/sha256/sha512 (note sha == sha1)
filename = /path/to/file
CHUNK=65536 by defaulttrs!%u!%ss#Error opening file for checksum: %sN(RRtStringTypestopenRTRhR%Rut
StringTypetcloseRltIOErrortOSErrorR(RatfiletCHUNKtdatasizeRiRgte((s,/usr/lib/python2.7/site-packages/yum/misc.pyRpcs
cCs�t|�}ytj|�}Wn&tk
rG}td||f�nXx�|D]�}tjj|d|�r�t|d|||�}qO|s�||j�d|krOtjj |d|�}|j
|�qOqOW|S(sfReturn all files in path matching ext, store them in filelist,
recurse dirs return list objects Error accessing directory %s, %st/s%s(REtostlistdirR�RtpathtisdirtgetFileListR+tnormpathRK(R�texttfilelisttextlentdir_listR�tdtnewpath((s,/usr/lib/python2.7/site-packages/yum/misc.pyR��s
"t
GenericHoldercBs,eZdZdd�Zd�Zd�ZRS(s�Generic Holder class used to hold other objects of known types
It exists purely to be able to do object.somestuff, object.someotherstuff
or object[key] and pass object to another function that will
understand itcCs
||_dS(N(t_GenericHolder__iter(R\titer((s,/usr/lib/python2.7/site-packages/yum/misc.pyRc�scCs$|jdk r t||j�SdS(N(R�R%R�(R\((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__iter__�scCs)t||�rt||�St|�dS(N(thasattrRxtKeyError(R\titem((s,/usr/lib/python2.7/site-packages/yum/misc.pyt__getitem__�s
N(RRRsR%RcR�R�(((s,/usr/lib/python2.7/site-packages/yum/misc.pyR��s cCs�tjdd|�}t�}d}d}x�|jd�D]�}|jd�rXd}q:|ry|j�dkryd}q:|r�|jd�r�Pq:|r�|jd�r�Pq:|r:|j|d�q:q:Wtj|j ��S( s-Convert ASCII armoured GPG key to binary
s
?s
is$-----BEGIN PGP PUBLIC KEY BLOCK-----its"-----END PGP PUBLIC KEY BLOCK-----t=(
R&tsubRtsplitR=tstriptwritetbase64tdecodestringtgetvalue(trawkeytblocktinblocktpastheaderstline((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
procgpgkey�s icCsn|d�}tj|�}|rjgtdt|�|�D]}||||!^q;}dj|�}n|S(s� Given a key_info data from getgpgkeyinfo(), return an ascii
fingerprint. Chop every 4 ascii values, as that is what GPG does. tfingerprintit (tbinasciithexlifytrangeREtjoin(tinfotchoptfpRQ((s,/usr/lib/python2.7/site-packages/yum/misc.pytgpgkey_fingerprint_ascii�s
6c
Cs�g}ytj|�}Wn%tk
r@}tt|���nXt|�dkrbtd��nx|D]}|jj�}i|jd6t j
d|�dd6|jjd6|jjd6|j
d6td 6td
6}x�|jdD]{}t|tj�sq�n|j�|kr�t|d�r`|jtj�} | d
kr]t| d�|d<Pq]q`q�q�W|j|�qiW|r|S|dSd
S(s�Return a dict of info for the given ASCII armoured key text
Returned dict will have the following keys: 'userid', 'keyid', 'timestamp'
Will raise ValueError if there was a problem decoding the key.
isNo key found in given key datatuserids>Qtkeyidt timestampR�traw_keythas_sigt valid_sigthashed_subpaksiN(tpgpmsgtdecode_multiple_keyst ExceptionRtstrREt
public_keytkey_idtuser_idtstructtunpackR�R�R�R:tuser_idsRt signatureR�tget_hashed_subpaktSIG_SUB_TYPE_CREATE_TIMER%tintRK(
R�tmultiplet
key_info_objstkeysR�tkeyt
keyid_blobR�R�ttspkt((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
getgpgkeyinfo�s<
cCsd|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.7/site-packages/yum/misc.pyt
keyIdToRPMVerscCswt|�}xd|jdd�D]P}|d|krt|dd�}||krXdS||krhdSdSqqWd 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����(R�tdbMatchR�(ttsR�R�thdrtinstalledts((s,/usr/lib/python2.7/site-packages/yum/misc.pytkeyInstalled scCs�tdkrtS|s#d|}ntjj|�sEtj|�nt|�}|tjd<tj �}t
tjj|d�d�}|jd�|j
�|j|�|j
�|j|�}tjj||tj�|r�|d} tjj| �s�tj| dd�x[tj|d �D]F}
tjj|
�}| d
|}tj|
|�tj|d�q'Wt
| ddd�}d
}
|j|
�|j
�q�ntS(Ns %s/gpgdirt GNUPGHOMEsgpg.conftwbR�s-rotmodei�s/*R�s /gpg.conftws�lock-never
no-auto-check-trustdb
trust-model direct
no-expensive-trust-checks
no-permission-warning
preserve-permissions
(tgpgmeR%R:R�R�texiststmakedirsRtenvirontContextR}R�R�Rtimport_tget_keyteditutilt
edit_trusttVALIDITY_ULTIMATEtglobtbasenametshutiltcopytchmodR9(R�R�tcachedirtgpgdirtmake_ro_copytkey_fotctxR�tktrodirtfR�tro_ftopts((s,/usr/lib/python2.7/site-packages/yum/misc.pytimport_key_to_pubring*s<
cCs�tdkstjj|�r#gS|tjd<tj�}g}xD|j�D]6}x-|jD]"}|j r_|j
|j�q_q_WqOW|S(NR�(R�R%R�R�R�R�R�tkeylisttsubkeystcan_signRKR�(R�R�tkeyidsR�tsubkey((s,/usr/lib/python2.7/site-packages/yum/misc.pytreturn_keyids_from_pubring[s
c
CstdkrtS|r<tjj|�s,tS|tjd<nt|d�rT|}nt|d�}t|d�r{|}nt|d�}d}tj �}y|j
|||�}Wntjk
r�}tSX|s�tS|d} | s�tS| jtj
tjtjfkrtStS(sAtakes signature , file that was signed and an optional gpghomedirR�RhR{iN(R�R%R:R�R�R�R�R�R}R�tverifyt
GpgmeErrortvalidityt
VALIDITY_FULLtVALIDITY_MARGINALR�R9(
tsig_filetsigned_filetgpghometsigtsigned_textt plaintextR�tsigsR�tthissig((s,/usr/lib/python2.7/site-packages/yum/misc.pytvalid_detached_sigis6
s/var/tmpsyum-cCstj�}y,tj|�}|d}tj|�}Wntk
rLdSX|r�d||f}d||f}tt j |��}xZ|D]O}tj
|�} t| d�r�t| d�dkr�| d|kr�|Sq�Wnt
jd|d|�}
|
S( sqreturn a path to a valid and safe cachedir - only used when not running
as root or when --tempcache is setis%s%s-s%s/%s*i�itprefixtdirN(R�tgeteuidtpwdtgetpwuidturllibtquoteR�R%tsortedR�tlstattS_ISDIRtS_IMODEttempfiletmkdtemp(ttmpdirtreuseRtuidtusertuptusernametdirpatht cachedirstthisdirtstatsR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytgetCacheDir�s"
6cCs4|j|jkrdS|j|jkr,dSdSdS(s+sorts a list of yum package objects by nameiii����N(R�(tpkg1tpkg2((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
sortPkgObj�s
cCsn|j�g}|d}xN|D]F}|j|�rG|g}|}q |j|�r |j|�q q W|S(s, Return the newest in the list of packages. i(tpoptverGTtverEQRK(tpkgsRmtnewesttpkg((s,/usr/lib/python2.7/site-packages/yum/misc.pytnewestInList�s
cCsp|\}}}d}|dkr2|d|7}n|dk rO|d|7}n|dk rl|d|7}n|S( s�
Convert a tuple representing a package version to a string.
@param evrTuple: A 3-tuple of epoch, version, and release.
Return the string representation of evrTuple.
R�it0s%s:s%ss-%sN(iR,N(R%(tevrTupleR�tvR{R)((s,/usr/lib/python2.7/site-packages/yum/misc.pytversion_tuple_to_string�scCsc|\}}}idd6dd6dd6dd6d d
6}|dkrH|Sd|||t|�fS(
s7returns a text string of the prco from the tuple formatt>tGTs>=tGER�tEQt<tLTs<=tLEs%s %s %sN(R%R/(t prcoTupleR�tflagtevrR4((s,/usr/lib/python2.7/site-packages/yum/misc.pytprco_tuple_to_string�s
)c Cs�t|�tjkr'|\}}}nc|}d}}|ddkr�|jd�r�|j�}t|�dkr�|\}}}q�n|dk r |tjkr |tj kr�yt
t|��}Wqtt
fk
r�}tjd|�qXq tj |}nt|�tjtjtjfkrEt|�\}}}n0t|�tjtjfkru|\}}}n|||||ffS(s:returns a prco tuple (name, flags, (e, v, r)) for a stringiR�sgpg(isInvalid version flag: %sN(RRRR%R=R�REt constantstLETTERFLAGStSYMBOLFLAGSRR�RRGtErrorsRR~tNoneTypetUnicodeTypeRtListType( t
prcoStringRLR�R.t
prco_splitR�tprco_etprco_vtprco_r((s,/usr/lib/python2.7/site-packages/yum/misc.pytstring_to_prco_tuple�s(
$cCs7tjd|�r$tj|�}ntj|�}|S(smTakes a search string from the cli for Search or Provides
and cleans it up so it doesn't make us vomits[*{}?+]|\[.+\](R&R(R/R0tescape(targtrestring((s,/usr/lib/python2.7/site-packages/yum/misc.pytrefineSearchPatternscCsi|tkr%d|}tj|�n|dkrFtj|d�}nB|dkrgtj|d�}n!|dkr�tj|d�}nt |d�}x�t
rPy|jd�}Wn>tt
tfk
r�}d|t|�f}tj|�nX|s�Pny|j|�Wq�tt
fk
rL}d |t|�f}tj|�q�Xq�W|j�|j�dS(
Ns%s compression not availableRR{RRR�i�sError reading from file %s: %ssError writing to file %s: %s(t_available_compressionR>RRtBZ2FiletlzmatLZMAFiletgziptGzipFileR}R9RhR�R�tEOFErrorR�R�R(tsourcetdesttztypetmsgts_fntdestinationRgR�((s,/usr/lib/python2.7/site-packages/yum/misc.pyt_decompress_chunked
s2
cCst||dd�dS(s1 Extract the bzipped contents of source to dest. RURN(RY(RSRT((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
bunzipFile/scCs�tj�d}ttjd|��}x�|D]x}|jd|�}x]|D]U}|d}|dd
krxd}nt|�}|d|d||d|d fSWq0WdS(s}This takes the output of uname and figures out the pkgtup of the running
kernel (name, arch, epoch, version, release).is/boot/vmlinuz*%s*t basenamestepochR,R�tarchR�R�N(NNNNN(R�tunameRR�R�R%R�(R�tvertfnstfntmithR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytget_running_kernel_pkgtup3s
(cCs2t|�}|ddk r.|d|dfSdS(sgThis takes the output of uname and figures out the (version, release)
tuple for the running kernel.iiiN(NN(RdR%(R�tpkgtup((s,/usr/lib/python2.7/site-packages/yum/misc.pyt"get_running_kernel_version_releaseGss/var/lib/yumc Cs�g}d|df}d|df}tj|�}tj|�}xT|D]L}|jd�rfqKntjj|�}|jdd�}|j|�qKW|j�|S(s�returns a list of the timestamps from the filenames of the unfinished
transactions remaining in the yumlibpath specified.
s%s/%sstransaction-all*stransaction-done*tdisabledstransaction-all.R�(R�tendswithR�R�R�treplaceRKRI( t
yumlibpatht
timestampsttsallgttsdonegttsallsttsdonesRattransR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytfind_unfinished_transactionsOs
cCseg}d|d|f}d|d|f}g}tjj|�sH|Stjj|�r�t|d�}|j�}|j�nt|d�}|j�}|j�x-|D]%} | |kr�q�n|j| �q�Wx�|D]} | jdd�} | dkrq�ny| j�\}
}Wn)t k
rI}d|}
t
j|
�nX|j|
|f�q�W|S(sthis function takes the timestamp of the transaction to look at and
the path to the yum lib dir (defaults to /var/lib/yum)
returns a list of tuples(action, pkgspec) for the unfinished transaction
elements. Returns an empty list if none.
s%s/%s.%sstransaction-allstransaction-doneR{s
R�s(Transaction journal file %s is corrupt.(
R�R�R�R}t readlinesRtremoveRiR�RR>RRK(R�Rjtto_complete_itemst tsallpatht
tsdonepathttsdone_itemst tsdone_fottsall_fottsall_itemsR�tactiontpkgspecR�RV((s,/usr/lib/python2.7/site-packages/yum/misc.pytfind_ts_remainingcs8
cCs~g}t|�}t|�}d}xB||krh||}|j|||!�||7}||8}q'W|j||�|S(sE Given a seq, split into a list of lists of length max_entries each. i(RERHRK(tseqtmax_entriesRmtnumtbegtend((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
seq_max_split�s
R�ccs'|]}|dkrt|�VqdS(i i
i
N(i i
i
(tchr(t.0RQ((s,/usr/lib/python2.7/site-packages/yum/misc.pys <genexpr>�si cCst|�tkrRyt|d�Wq�tk
rNt|d�jd�}q�XnGt|�tkrv|jd�}n#|dkr�dStdt|��|j�}|j dt
�}|jdd�}|jdd�}|jd d
�}|r|jdd�}|jd
d�}n|S(s_ Returns xml-friendly utf-8 encoded string.
Accepts utf-8, iso-8859-1, or unicode.
sutf-8s
iso-8859-1R�sString expected, got %st&s&R4s<R0s>t"s"t's'N(RR�RtUnicodeDecodeErrortencodeR%RtreprtrstripR0t_deletecharsRi(R�tattrib((s,/usr/lib/python2.7/site-packages/yum/misc.pytto_xml�s&
cCsXytj|�Wn@tk
rS}|jtjtjtjtjfkrT�qTnXdS(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�tunlinkR�terrnotENOENTtEPERMtEACCEStEROFS(R;R�((s,/usr/lib/python2.7/site-packages/yum/misc.pytunlink_f�s
'cCsiytj|�SWnQtk
rd}|jtjtjfkrBdS|r^|jtjkr^dS�nXdS(sF Call os.stat(), but don't die if the file isn't there. Returns None. N(R�tstatR�R�R�tENOTDIRR%R�(R;t
ignore_EACCESR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytstat_f�scCsXytd�}Wntk
r$dSX|j�}yt|�SWntk
rSdSXdS(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(R}R�R%RhR�R(RiRg((s,/usr/lib/python2.7/site-packages/yum/misc.pyt_getloginuid�s
cCstdkrt�antS(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.7/site-packages/yum/misc.pytgetloginuid�scCs�y3tjtjd�|r2tjtjd�nWnCtjk
rx}tjdIJdtjd<tjtjd�nX|r�ddd��Y}|tj tj
��t_ ndS(NR�tCs%Failed to set locale, defaulting to CtLC_ALLt
UnicodeStreamcBs#eZd�Zd�Zd�ZRS(cSs||_||_dS(N(tstreamtencoding(R\R�R�((s,/usr/lib/python2.7/site-packages/yum/misc.pyRcs cSs;t|t�r'|j|jd�}n|jj|�dS(NRi(RRR�R�R�R�(R\R)((s,/usr/lib/python2.7/site-packages/yum/misc.pyR�scSst|j|�S(N(RxR�(R\R�((s,/usr/lib/python2.7/site-packages/yum/misc.pyRzs(RRRcR�Rz(((s,/usr/lib/python2.7/site-packages/yum/misc.pyR�s ((tlocalet setlocaleR�tLC_TIMEtErrortsyststderrR�R�tstdouttgetpreferredencoding(toverride_codecst
override_timeR�R�((s,/usr/lib/python2.7/site-packages/yum/misc.pytsetup_locale�s
cCsZytjtj�}Wntk
r1}d}nX|dkrGd}ndj|�}|S(NR�t.(NN(NN(R�t getlocaletLC_MESSAGESRR%R�(tmylangR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytget_my_lang_code
s
cCsgtj�}g}xNtjd�D]=}|tjj|�krFq"n|jtjj|��q"W|S(s5return list of running processids, excluding this ones/proc/[0123456789]*(R�tgetpidR�R�R�RK(tmypidtpidsRa((s,/usr/lib/python2.7/site-packages/yum/misc.pytreturn_running_pidssc
Csrg}d|}yt|d�}Wnttfk
r?}|SXx�|D]�}|jd�dkrhqGn|jdd�}|jd�}||}|jdd�}|j�}||krG|j|�qGqGWd |}yt|d�} Wnttfk
r
}|SX| j�}
|
jd
�dkrn|
jd
�}x0|D]%}|j d�rB|j|�qBqBWn|S(s returns files open from this pids
/proc/%s/mapsR{sfd:i����s
R�R�s (deleted)s/proc/%s/cmdlinet(
R}R�R�tfindRiR�RKRhR�R=(
tpidtfilestmaps_ftmapsR�R�tslashR;tcli_ftclitcmdlinetcmdsRQ((s,/usr/lib/python2.7/site-packages/yum/misc.pytget_open_files$s8
cCs�tjj|�r%t|d�j�Syddlm}Wn&tk
ratdd�j�}nXt|��}y4t|d�}|j |�|j
�|j�Wntt
fk
r�}nX|SdS(swcreate, store and return a uuid. If a stored one exists, report that
if it cannot be stored, return a random oneR{i����(tuuid4s/proc/sys/kernel/random/uuidR�N(R�R�R�R}RhtuuidR�tImportErrorR�R�tflushRR�R�(tsavepathR�tmyidtsfR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytget_uuidGs
cCs�|}|s|}n|jd�rHd}|s�|jdd�}q�n�|jd�sf|jd�r�d}|s�|jd�r�|jdd�}q�|jdd�}q�n7|jd�r�d}|s�|jdd�}q�n|S|rAt|�}t|�}|rA|rAt|j�t|j�kr1|S|r>d SqAn|s�y?t|||�|r�|r�tj||j|jf�nWq�t |��q�Xn|S(
s|take a filename and decompress it into the same relative location.
if the file is not compressed just return the files.gzRR�s.bzs.bz2Rs.xzRN(
RhRiR�R�tst_mtimeR%RYR�tutimeR�(R;RTtfn_onlytcheck_timestampstoutRUtfiRi((s,/usr/lib/python2.7/site-packages/yum/misc.pyt
decompress^sF
#
cCsstjj|�d|}yt|d|dt�SWn8ttfk
rn}|rh|jtjkrhdS�nXdS(s� This is a wrapper around decompress, where we work out a cached
generated name, and use check_timestamps. filename _must_ be from
a repo. and generated_name is the type of the file. s/gen/RTR�N(
R�R�R>R�R9R�R�R�R�R%(R;tgenerated_nametcachedRTR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytrepo_gen_decompress�scCs�g}x�tj|�D]�}x�t|�D]�}tjd|�rGq)n|j�}|j�}|skq)n|r�|jdd�}|jdd�}|j|j��q)n|j |�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
R�t,(
R�R}R&R1R�tlstripRitextendR�RK(tthisglobtline_as_listtresultstfnameR�((s,/usr/lib/python2.7/site-packages/yum/misc.pytread_in_items_from_dot_dir�s cCsMtdkrIyddlm}Wntk
r?ddl}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����(tcElementTreeN(t__cached_cElementTreeR%t xml.etreeR�R�(R�((s,/usr/lib/python2.7/site-packages/yum/misc.pyt_cElementTree_import�s
cCst�tj|�S(s) Lazily load/run: cElementTree.iterparse (R�R�t iterparse(R;((s,/usr/lib/python2.7/site-packages/yum/misc.pytcElementTree_iterparse�scCst�tj|�S(s% Lazily load/run: cElementTree.parse (R�R�tparse(R;((s,/usr/lib/python2.7/site-packages/yum/misc.pytcElementTree_xmlparse�scCs�|dkr|Sg}xo|D]g}|jdkrbd|jkrGqn|jj|krwqqwn|j|krwqn|j|�qW|S(s� Given a list of packages, filter them for those "in" the repoid.
uses from_repo for installed packages, used by repo-pkgs commands. t installedt from_repoN(R%trepoidt
yumdb_infoR�RK(R(R�RmR*((s,/usr/lib/python2.7/site-packages/yum/misc.pytfilter_pkgs_repoid�s
cCs=tjtjd}x"|D]}||kr|SqWdSdS(s;Return the first invalid char found in the repoid, or None.s-_.:N(tstringt
ascii_letterstdigitsR%(R�t
allowed_charstchar((s,/usr/lib/python2.7/site-packages/yum/misc.pytvalidate_repoid�s
cs�d���|�}tjj|�s+|SxZtj|�D]I\�}}�fd�||D�}|t�fd�|D��7}q;W|S(s>Return disk usage of the given filename, recursively for dirs.cSstj|�jdS(Ni(R�R�t st_blocks(R�((s,/usr/lib/python2.7/site-packages/yum/misc.pytusage�sc3s$|]}tjj�|�VqdS(N(R�R�R�(R�tentry(troot(s,/usr/lib/python2.7/site-packages/yum/misc.pys <genexpr>�sc3s|]}�|�VqdS(N((R�R�(R�(s,/usr/lib/python2.7/site-packages/yum/misc.pys <genexpr>�s(R�R�R�twalktsum(R�ttotaltdirsR�tpaths((R�R�s,/usr/lib/python2.7/site-packages/yum/misc.pyt
disk_usage�s $((R ssha1((i((�RsRR�R�tos.patht cStringIORR�R�R�R&R�R>R;R�RR�RR/RRPR�RR�RLRNRKR�R%trpmUtils.miscutilsRRR�R�tgpgme.editutilRRFRYRRRZRHtctypeR
R�R�RRR�RhR[R�R�RsRURRti18nRRRRR"R#R$R*R:R5R6R7R<R8R?RCRDRSRTRvRpR�R�R�R�R�R�R�R9R�R�R
R!R$R+R/R:RGRKRYRZRdRfRqR}R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�R�(((s,/usr/lib/python2.7/site-packages/yum/misc.pyt<module>s�
$
BO 2 !1 (
# " . !
# 4