o åvŽfóhã@sÖdZddlZddlZddlZddlZddlZddlZddlZddlZddl m Z ddl m Z ddl mZddlmZddlmZejddkrRdd lmZed Zndd lmZd ZGd d„dƒZGdd„deƒZdS)z(Store, load, and handle problem reports.éN)Ú encode_base64)Ú MIMEMultipart)ÚMIMEBase)ÚMIMEText)ÚBytesIOÚ3)ÚIterableUserDictT)ÚUserDictFc@sBeZdZdZddd„Zdd„Zdd„Zd d „Zd d „Zd d„Z dS)ÚCompressedValuez9Represent a ProblemReport value which is gzip compressed.NcCs(d|_||_d|_|r| |¡dSdS)zAInitialize an empty CompressedValue object with an optional name.NF)Ú gzipvalueÚnameÚ legacy_zlibÚ set_value)ÚselfÚvaluer ©rú0/usr/lib/python3/dist-packages/problem_report.pyÚ__init__"s ÿzCompressedValue.__init__cCs4tƒ}tj|jd|dd |¡| ¡|_d|_dS)zSet uncompressed value.Úwbr©ÚmodeÚfileobjÚmtimeFN)rÚgzipÚGzipFiler ÚwriteÚgetvaluer r )rrÚoutrrrr/s  zCompressedValue.set_valuecCs2|jsdS|jrt |j¡Stjt|jƒd ¡S)zReturn uncompressed value.N©r)r r ÚzlibÚ decompressrrrÚread©rrrrÚ get_value7s  zCompressedValue.get_valuecCsX|jsJ‚|jr| t |j¡¡dStjt|jƒd} | d¡}|s&dS| |¡q)z5Write uncompressed value into given file-like object.NrTé) r r rrr rrrr!)rÚfileÚgzÚblockrrrrAs   üzCompressedValue.writecCs:|jsJ‚|jrt| ¡ƒStt d|jdd…¡dƒS)z$Return length of uncompressed value.úsz.ProblemReport.extract_keys..)rIÚ isinstanceÚstrÚlistrKrVrWrXrSrYÚopenÚosÚpathÚjoinrLrMrr rrNrOrPÚIOErrorrUÚvaluesÚ ValueErrorÚitems) rr%Úbin_keysÚdirr^rÚ missing_keysr_r`rrbr'rrrÚ extract_keysÑsn        €€ë€ ÿ Ù€( ÿÿzProblemReport.extract_keysÚreturnc Cs˜t tj¡}z:z1zt tjd¡tt t |d¡¡ƒWWt tj|¡WSty8YWt tj|¡WdSwt tj|¡wtj yKYdSw)zgGet timestamp (seconds since epoch) from Date field Return None if it is not present. ÚCr7N) ÚlocaleÚ getlocaleÚLC_TIMEÚ setlocaler+r8ÚmktimeÚstrptimerUÚError)rÚ orig_ctimerrrÚ get_timestamps  ýýÿzProblemReport.get_timestampcCs d| ¡vS)z~Check if the report has any keys which were not loaded. This could happen when using binary=False in load(). N)rqr"rrrÚhas_removed_fields#s z ProblemReport.has_removed_fieldscCs4t|ƒtkr|D]}|dkrt|ƒ ¡sdSqdS)z0Check if the given strings contains binary data.é TF)r=ÚbytesÚchrÚisspace)ÚklassÚstringÚcrrrÚ _is_binary*s €zProblemReport._is_binarycCs>t|ƒtkr| |¡sz| d¡WSty|YSw|S)z)Try to convert bytearray value to unicodeúUTF-8)r=r…r‹rXÚUnicodeDecodeError)rˆrrrrrT4s  ÿzProblemReport._try_unicodeFc Cs¸| |¡g}g}|j ¡D]?}|r||jvrq|j|}t|dƒr3| |¡r-| |¡q| |¡qt|tƒsHt |ƒdkrH|dsH| |¡q| |¡q|  ¡d|vra|  d¡|  dd¡|  ¡|D]£}|j|}t|dƒsÖt |ƒdkr„|ddur„|d}nd}t |ƒdko|d}t|dd ƒrž|d  ¡}nt|dd ƒ } |   ¡}Wdƒn1s´wY|rÇt |ƒdkrÇtd |ƒ‚|durÖt |ƒ|krÖ|j|=qgt|tƒrà| d ¡}| | d ¡¡d|vrû| d¡| | dd¡¡n | d¡| |¡| d¡qg|D]K}|j|}d}d} | ¡} | | d ¡¡| d¡t|tƒr@| t |j¡¡| d¡q d| d ¡d} | t | ¡¡| d¡t d¡} t dtjtj tjd¡}t|dƒr| t |ƒ7} t || ¡} | |¡}|r| t |¡¡| d¡n˜t |ƒdkr¢|ddur¢|d}t|dd ƒr¯|d} nt|dd ƒ} |   d¡}| t |ƒ7} t || ¡} |durã| |krã| | ¡|  | ¡|j|=d} n|rü| |¡}|rû| t |¡¡| d¡nnq·t|dd ƒs |  !¡t |ƒdkr(|dr(| dkr(td|t|dƒfƒ‚|r0| |krX| "¡}| rK|t# $d| d@¡7}|t# $d| d@¡7}| t |¡¡| d¡q dS)a»Write 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. file needs to be opened in binary mode. Files are written in RFC822 format. ÚfindérDr6réNér!Úrbzdid not get any data for field rŒrGrCs: s s: s : base64 s ‹ÿórAéTr$z)did not get any data for field %s from %sr(lÿÿ)%rIr:r[r<Úhasattrr‹Úappendrir r*ÚsortrSÚinsertr!rlrprjrZrÚreplaceÚtellrLÚ b64encoder rÚcrc32Ú compressobjÚDEFLATEDrOÚ DEF_MEM_LEVELÚcompressÚseekÚtruncateÚcloserRr,Úpack)rr%Úonly_newÚasckeysÚbinkeysÚkÚvÚlimitÚ fail_on_emptyÚfÚsizeÚcurr_posÚ gzip_headerÚcrcÚbcÚoutblockr'rrrr?sÚ              ÿ              ÿ     €          €î  €µzProblemReport.writec Csˆt |¡}z*t|dƒ}t |d¡| |¡| ¡W|r't ||j|jf¡t ||j ¡dS|rs  8       @