Your IP : 172.28.240.42


Current Path : /usr/lib/python2.7/dist-packages/
Upload File :
Current File : //usr/lib/python2.7/dist-packages/problem_report.pyc


5Oc@s7dZddlZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
ddlmZyddlmZWn!ek
rddlmZnXyddlmZWn!ek
r	dd	lmZnXd
ddYZdefd
YZdS(s(Store, load, and handle problem reports.iN(t
encode_base64(t
MIMEMultipart(tMIMEBase(tMIMEText(tStringIO(tUserDict(tIterableUserDicttCompressedValuecBsJeZdZdddZdZdZdZdZdZ	RS(s9Represent a ProblemReport value which is gzip compressed.cCs5d|_||_t|_|r1|j|ndS(sAInitialize an empty CompressedValue object with an optional name.N(tNonet	gzipvaluetnametFalsetlegacy_zlibt	set_value(tselftvalueR
((s2/usr/lib/python2.7/dist-packages/problem_report.pyt__init__!s
			cCsJt}tj|jddd|j||j|_t|_dS(sSet uncompressed value.tmodetwbtfileobjN(	RtgziptGzipFileR
twritetgetvalueR	RR(RRtout((s2/usr/lib/python2.7/dist-packages/problem_report.pyR
.s	%cCsE|js
dS|jr&tj|jStjdt|jjS(sReturn uncompressed value.RN(	R	RRtzlibt
decompressRRRtread(R((s2/usr/lib/python2.7/dist-packages/problem_report.pyt	get_value6s
		cCs|jst|jr5|jtj|jdStjdt|j}x0t	r|j
d}|srPn|j|qSWdS(s5Write uncompressed value into given file-like object.NRi(R	tAssertionErrorRRRRRRRtTrueR(Rtfiletgztblock((s2/usr/lib/python2.7/dist-packages/problem_report.pyR@s		cCsI|jst|jr(t|jSttjd|jddS(s$Return length of uncompressed value.s<Lii(R	RRtlenRtinttstructtunpack(R((s2/usr/lib/python2.7/dist-packages/problem_report.pyt__len__Ps	cCs|jjS(s.Behaves like splitlines() for a normal string.(Rt
splitlines(R((s2/usr/lib/python2.7/dist-packages/problem_report.pyR'XsN(
t__name__t
__module__t__doc__RRR
RRR&R'(((s2/usr/lib/python2.7/dist-packages/problem_report.pyRs
		
		t
ProblemReportcBseZdddZedZdZdZedZ	edZ
didddZd	Zd
Z
edZRS(
tCrashcCsB|dkrtj}ni|d6|d6|_t|_dS(sInitialize a fresh problem report.

        type can be 'Crash', 'Packaging', 'KernelCrash' or 'KernelOops'.
        date is the desired date/time string; if None (default), the
        current local time is used.
        tProblemTypetDateN(Rttimetasctimetdatatsettold_keys(Rttypetdate((s2/usr/lib/python2.7/dist-packages/problem_report.pyR^sc	Cs|jjd}d}t}d}x3|D]+}|jdr|rT|rTq,n|dkrl|dksrt|rKtj|}|r||j|7}q|dkr|j	dkr|jdrt
|_n|j	|7_	q|jdr)tj
tj}|j|j|}qtj
}||j|7}qWt|dkrj|d7}n|jdr||dd!7}qW||d7}q,|r|r||j7}nt}d}n|r|dkst||j|<n|jd	d\}}|j}|d
kr,|dkrHt|}d|_	nd}t
}q,q,W|dkrw||j|<nt|jj|_dS(sWInitialize problem report from a file-like object.

        If binary is False, binary data is not loaded; the dictionary key is
        created, but its value will be an empty string. If it is true, it is
        transparently uncompressed and available as dictionary string values.
        If binary is 'compressed', the compressed value is retained, and the
        dictionary value will be a CompressedValue object. This is useful if
        the compressed value is still useful (to avoid recompression if the
        file needs to be written back).

        Files are in RFC822 format.
        t t
compressedtsis
iit:tbase64N(R1tclearRRt
startswithRR:t	b64decodeRR	RRRt
decompressobjt	MAX_WBITSt_strip_gzip_headerR"tendswithtflushtsplittstripRR2tkeysR3(	RRtbinarytkeyRt	b64_blocktbdtlinetl((s2/usr/lib/python2.7/dist-packages/problem_report.pytloadls^




	
cCsd|jkS(s~Check if the report has any keys which were not loaded.

        This could happen when using binary=False in load().
        R8(t
itervalues(R((s2/usr/lib/python2.7/dist-packages/problem_report.pythas_removed_fieldsscCs2x+|D]#}|dkr|jrtSqWtS(s0Check if the given strings contains binary data.R6(tisspaceRR(Rtstringtc((s2/usr/lib/python2.7/dist-packages/problem_report.pyt
_is_binarys
c
Csg}g}x|jjD]}|r=||jkr=qn|j|}t|dr|j|rx|j|q|j|qt|trt|dkr|dr|j|q|j|qW|j	d|kr|j
d|jddn|j	x|D]}|j|}t|ds(t|dkrn|ddkrn|d}nd}t|dko|d}t|ddr|dj
}nt|dj
}|rt|dkrtd	|n|dkr(t||kr(|j|=qq(ntjjd
r^t|tr^|jd}q^nd|kr|jd
||jd|jddq|jd||fqWxN|D]F}|j|}d}d}	|j}
|j|dt|tr4|jtj|j|jdqnd|d}|jtj||jdtjd}tjdtjtjtj d}
t|dr|	t|7}	tj||}|
j!|}|r|jtj||jdqnyt|dkr7|ddkr7|d}nt|ddrW|d}nt|d}xt"r2|j
d}|	t|7}	tj||}|dkr|	|kr|j#|
|j$|
|j|=d}Pqn|r.|
j!|}|r/|jtj||jdq/qjPqjWt|dkr|dr|	dkrtd|t%|dfqn|s|	|kr|
j&}|r|t'j(d|d@7}|t'j(d|	d@7}n|jtj||jdqqWdS(sWrite information into the given file-like object.

        If only_new is True, only keys which have been added since the last
        load() are written (i. e. those returned by new_keys()).

        If a value is a string, it is written directly. Otherwise it must be a
        tuple of the form (file, encode=True, limit=None, fail_on_empty=False).
        The first argument can be a file name or a file-like object,
        which will be read and its content will become the value of this key.
        'encode' specifies whether the contents will be
        gzip compressed and base64-encoded (this defaults to True). If limit is
        set to a positive integer, the file is not attached if it's larger
        than the given limit, and the entire key will be removed. If
        fail_on_empty is True, reading zero bytes will cause an IOError.

        Files are written in RFC822 format.
        tfindiiR-iiiRsdid not get any data for field t2sUTF-8s
s%s:
s %s
s
 s%s: %s
s
: base64
 s
tR8i	is)did not get any data for field %s from %ss<LIN()R1RER3thasattrRRtappendt
isinstanceRR"tsorttremovetinsertRRtopentIOErrortsystversionR<tunicodetencodeRtreplacettellR:t	b64encodeR	Rtcrc32tcompressobjtDEFLATEDR?t
DEF_MEM_LEVELtcompressRtseekttruncatetstrRBR$tpack(RRtonly_newtasckeystbinkeystktvtlimitt
fail_on_emptytsizetcurr_postgzip_headertcrctbctoutblocktfR!((s2/usr/lib/python2.7/dist-packages/problem_report.pyRs
-




"

	 



"

	


&cCstj|}z:t|d}tj|d|j||jWd|rqtj||j|jfntj||j	XdS(sAdd this report's data to an already existing report file.

        The file will be temporarily chmod'ed to 000 to prevent frontends
        from picking up a hal-updated report file. If keep_times
        is True, then the file's atime and mtime restored after updating.
        taiN(
toststatR\tchmodRtclosetutimetst_atimetst_mtimetst_mode(Rt
reportfilet
keep_timeststR{((s2/usr/lib/python2.7/dist-packages/problem_report.pytadd_to_existingds
ic
Cst|jj}d}g}d|krM|jd|jddn|rd}	xG|D]<}
|
|kr`|j|
|j|	|
|	d7}	q`q`Wnx3|D]+}|r||krqn|j|}d}
t|tr|j}
nt	|dsd}
t	|ddr+|d}nt
|d}|jdrY|j}
nmt
}tj|dd	d
|}x:tr|jd}|r|j|q|jPqW|j}
|jn<|j|r|jdr|}
qt||j}
n|
rtdd
}|jdrL|jddd|n|jddd|d|j|
t||j|qt|}t|tdkr|jdd}nt|tst|jd}t|j }|dkr7|dkr7|j!}|d||f7}q|dkr||kr|d|7}|jdsy|d7}n||j"j#ddd7}qt$|dd}|jddd|d|j|qWt$|dd}|jdd|jd|t%}x*|j&D]\}}|j||q!Wx|D]}|j'|qHW|j|j(|jddS(seWrite MIME/Multipart RFC 2822 formatted data into file.

        file must be a file-like object, not a path.

        If a value is a string or a CompressedValue, it is written directly.
        Otherwise it must be a tuple containing the source file and an optional
        boolean value (in that order); the first argument can be a file name or
        a file-like object, which will be read and its content will become the
        value of this key.  The file will be gzip compressed, unless the key
        already ends in .gz.

        attach_treshold specifies the maximum number of lines for a value to be
        included into the first inline text part. All bigger values (as well as
        all non-ASCII ones) will become an attachment, as well as text
        values bigger than 1 kB.

        Extra MIME preamble headers can be specified, too, as a dictionary.

        skip_keys is a set/list specifying keys which are filtered out and not
        written to the destination file.

        priority_fields is a set/list specifying the order in which keys should
        appear in the destination file.
        R8R-iiRSRs.gzRRRitapplicationsx-gzipsContent-Dispositiont
attachmenttfilenamesUTF-8Rbis%s: %s
s%s:
 s
s
 t_charsets.txttinlineN()tsortedR1RERZR[RRXRR	RVR\RARRRRRRRRRRRt
add_headertset_payloadRRWR"R4tdecodeR`RRaR'trstripRDRbRRtitemstattacht	as_string(RRtattach_tresholdt
extra_headerst	skip_keystpriority_fieldsREttexttattachmentstcountertpriority_fieldRqRrtattach_valueR{tiotgfR!tattRutlinestmsgR|((s2/usr/lib/python2.7/dist-packages/problem_report.pyt
write_mimevs





		

	


#	
c
Cst|dst|jddjddjddjsKtt|tst|dst|drt|dkst|dkr|dttfkrt|d	dst|d	d
st|j	j
||S(Ntisalnumt.R8t-t_t__getitem__iiiR(RVRRbRRXRR"RRR1t__setitem__(RRqRr((s2/usr/lib/python2.7/dist-packages/problem_report.pyRs6:,cCst|jj|jS(sReturn newly added keys.

        Return the set of keys which have been added to the report since it
        was constructed or loaded.
        (R2R1RER3(R((s2/usr/lib/python2.7/dist-packages/problem_report.pytnew_keysscCst|d}d}|d@r5|||d7}n|d@rsx$t||dkre|d7}qBW|d7}n|d@rx$t||dkr|d7}qW|d7}n|d@r|d7}n||S(	s0Strip gzip header from line and return the rest.ii
iiiiii(tord(tklassRJtflagstoffset((s2/usr/lib/python2.7/dist-packages/problem_report.pyR@s






N(R(R)RRRRLRNRRRRRRRRtclassmethodR@(((s2/usr/lib/python2.7/dist-packages/problem_report.pyR+]sM				((R*RR:R/R^RR$R}temail.encodersRtemail.mime.multipartRtemail.mime.baseRtemail.mime.textRt	cStringIORtImportErrorRtcollectionsRRRR+(((s2/usr/lib/python2.7/dist-packages/problem_report.pyt<module>sT

?