ó
ýGpNc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l Z d d l m Z d d l	 m
 Z
 d d l m Z d d l m Z y d d l m Z Wn! e k
 rÅ d d l m Z n Xy d d l m Z Wn! e k
 rý d d	 l m Z n Xd
 f  d „  ƒ  YZ d e f d „  ƒ  YZ d d l Z d d l Z d d l Z d d l Z d e j f d „  ƒ  YZ e d k r‰e j ƒ  n  d S(   s(   Store, load, and handle problem reports.iÿÿÿÿN(   t   encode_base64(   t   MIMEMultipart(   t   MIMEBase(   t   MIMEText(   t   StringIO(   t   UserDict(   t   IterableUserDictt   CompressedValuec           B   sJ   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   s9   Represent a ProblemReport value which is gzip compressed.c         C   s5   d |  _ | |  _ t |  _ | r1 |  j | ƒ n  d S(   sA   Initialize an empty CompressedValue object with an optional name.N(   t   Nonet	   gzipvaluet   namet   Falset   legacy_zlibt	   set_value(   t   selft   valueR
   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   __init__!   s
    			c         C   sJ   t  ƒ  } t j |  j d d d | ƒj | ƒ | j ƒ  |  _ t |  _ d S(   s   Set uncompressed value.t   modet   wbt   fileobjN(	   R   t   gzipt   GzipFileR
   t   writet   getvalueR	   R   R   (   R   R   t   out(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR   .   s    	%c         C   sE   |  j  s d S|  j r& t j |  j  ƒ St j d t |  j  ƒ ƒ j ƒ  S(   s   Return uncompressed value.R   N(	   R	   R   R   t   zlibt
   decompressR   R   R   t   read(   R   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt	   get_value6   s
    		c         C   s‡   |  j  s t ‚ |  j r5 | j t j |  j  ƒ ƒ d St j d t |  j  ƒ ƒ } x0 t	 r‚ | j
 d ƒ } | sr Pn  | j | ƒ qS Wd S(   s5   Write uncompressed value into given file-like object.NR   i   (   R	   t   AssertionErrorR   R   R   R   R   R   R   t   TrueR   (   R   t   filet   gzt   block(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR   @   s    		c         C   sI   |  j  s t ‚ |  j r( t |  j ƒ  ƒ St t j d |  j  d ƒ d ƒ S(   s$   Return length of uncompressed value.s   <Liüÿÿÿi    (   R	   R   R   t   lenR   t   intt   structt   unpack(   R   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   __len__P   s    	c         C   s   |  j  ƒ  j ƒ  S(   s.   Behaves like splitlines() for a normal string.(   R   t
   splitlines(   R   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR'   X   s    N(
   t   __name__t
   __module__t   __doc__R   R   R   R   R   R&   R'   (    (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR      s   		
		t   ProblemReportc           B   sƒ   e  Z d  d d „ Z e d „ Z d „  Z d „  Z e d „ Z	 e d „ Z
 d i  d d d „ Z d	 „  Z d
 „  Z e d „  ƒ Z RS(   t   Crashc         C   sB   | d k r t j ƒ  } n  i | d 6| d 6|  _ t ƒ  |  _ d S(   sÞ   Initialize 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.
        t   ProblemTypet   DateN(   R   t   timet   asctimet   datat   sett   old_keys(   R   t   typet   date(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR   ^   s    c   	      C   s“  |  j  j ƒ  d } d } t } d } x3| D]+} | j d ƒ rž| rT | rT q, n  | d k rl | d k sr t ‚ | rKt j | ƒ } | r£ | | j | ƒ 7} q›| d k rì | j	 d k rÚ | j d ƒ rÚ t
 | _ n  | j	 | 7_	 q›| j d ƒ r)t j t j ƒ } | j |  j | ƒ ƒ } q›t j ƒ  } | | j | ƒ 7} qWt | ƒ d k rj| d 7} n  | j d ƒ r| | d d !7} qW| | d 7} q, | rÌ| r½| | j ƒ  7} n  t } d } n  | rô| d k sät ‚ | |  j  | <n  | j d	 d ƒ \ } } | j ƒ  } | d
 k r, | d k rHt | ƒ } d | _	 n d } t
 } q, q, W| d k rw| |  j  | <n  t |  j  j ƒ  ƒ |  _ d S(   s_  Initialize 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
   compressedt    s   ‹i    s   
i   iÿÿÿÿt   :t   base64N(   R1   t   clearR   R   t
   startswithR   R:   t	   b64decodeR   R	   R   R   R   t   decompressobjt	   MAX_WBITSt   _strip_gzip_headerR"   t   endswitht   flusht   splitt   stripR   R2   t   keysR3   (	   R   R   t   binaryt   keyR   t	   b64_blockt   bdt   linet   l(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   loadl   s^    	c         C   s   d |  j  ƒ  k S(   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.pyt   has_removed_fields¹   s    c         C   s2   x+ | D]# } | d k  r | j  ƒ  r t Sq Wt S(   s0   Check if the given strings contains binary data.R6   (   t   isspaceR   R   (   R   t   stringt   c(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt
   _is_binaryÀ   s    c      
   C   s  g  } g  } xÇ |  j  j ƒ  D]¶ } | r= | |  j k r= q n  |  j  | } t | d ƒ rˆ |  j | ƒ rx | j | ƒ qÒ | j | ƒ q t | t ƒ rÅ t | ƒ d k rÅ | d rÅ | j | ƒ q | j | ƒ q W| j	 ƒ  d | k r| j
 d ƒ | j d d ƒ n  | j	 ƒ  x| D]•} |  j  | } t | d ƒ s(t | ƒ d k rn| d d k rn| d } n d } t | ƒ d k o| d } t | d d ƒ r¶| d j ƒ  } n t | d ƒ j ƒ  } | r÷t | ƒ d k r÷t d	 | ƒ ‚ n  | d k r(t | ƒ | k r(|  j  | =qq(n  t j j d
 ƒ r^t | t ƒ r^| j d ƒ } q^n  d | k r›| j d | ƒ | j d | j d d ƒ ƒ q| j d | | f ƒ qWxN| D]F} |  j  | } d } d }	 | j ƒ  }
 | j | d ƒ t | t ƒ r4| j t j | j ƒ ƒ | j d ƒ q½n  d | d } | j t j | ƒ ƒ | j d ƒ t j d ƒ } t j d t j t j t j  d ƒ } t | d ƒ r|	 t | ƒ 7}	 t j | | ƒ } | j! | ƒ } | r| j t j | ƒ ƒ | j d ƒ qnyt | ƒ d k r7| d d k r7| d } n  t | d d ƒ rW| d } n t | d ƒ } xÉ t" r2| j d ƒ } |	 t | ƒ 7}	 t j | | ƒ } | d k rê|	 | k rê| j# |
 ƒ | j$ |
 ƒ |  j  | =d } Pqên  | r.| j! | ƒ } | r/| j t j | ƒ ƒ | j d ƒ q/qjPqjWt | ƒ d k r| d r|	 d k rt d | t% | d ƒ f ƒ ‚ qn  | s”|	 | k r½| j& ƒ  } | rÝ| t' j( d | d @ƒ 7} | t' j( d |	 d @ƒ 7} n  | j t j | ƒ ƒ | j d ƒ q½q½Wd S(   sŠ  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.

        Files are written in RFC822 format.
        t   findi   i   R-   i    i   i   R   s   did not get any data for field t   2s   UTF-8s   
s   %s:
s    %s
s   
 s   %s: %s
s
   : base64
 s
   ‹    ÿt    R8   i	   i   s)   did not get any data for field %s from %ss   <Ll   ÿÿ N()   R1   RE   R3   t   hasattrRR   t   appendt
   isinstanceR   R"   t   sortt   removet   insertR   R   t   opent   IOErrort   syst   versionR<   t   unicodet   encodeR   t   replacet   tellR:   t	   b64encodeR	   R   t   crc32t   compressobjt   DEFLATEDR?   t   DEF_MEM_LEVELt   compressR   t   seekt   truncatet   strRB   R$   t   pack(   R   R   t   only_newt   asckeyst   binkeyst   kt   vt   limitt   fail_on_emptyt   sizet   curr_post   gzip_headert   crct   bct   outblockt   fR!   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR   È   s¾    -

"
	 "	
&c         C   s‰   t  j | ƒ } z: t | d ƒ } t  j | d ƒ |  j | ƒ | j ƒ  Wd | rq t  j | | j | j f ƒ n  t  j | | j	 ƒ Xd S(   s  Add 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.
        t   ai    N(
   t   ost   statR\   t   chmodR   t   closet   utimet   st_atimet   st_mtimet   st_mode(   R   t
   reportfilet
   keep_timest   stR{   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   add_to_existingd  s    i   c         C   s_  t  |  j j ƒ  ƒ } d } g  } d | k rM | j d ƒ | j d d ƒ n  | r£ d }	 xG | D]< }
 |
 | k r` | j |
 ƒ | j |	 |
 ƒ |	 d 7}	 q` q` Wn  x| D]} | rÈ | | k rÈ qª n  |  j | } d } t | t ƒ rö | j } nt	 | d ƒ sÓd } t	 | d d ƒ r+| d } n t
 | d ƒ } | j d ƒ rY| j ƒ  } nm t ƒ  } t j | d d	 d
 | ƒ} x: t r¹| j d ƒ } | r«| j | ƒ q€| j ƒ  Pq€W| j ƒ  } | j ƒ  n< |  j | ƒ r| j d ƒ rú| } qt | | ƒ j } n  | rt d d ƒ } | j d ƒ rL| j d d d | ƒn | j d d d | d ƒ| j | ƒ t | ƒ | j | ƒ qª t | ƒ t d ƒ k rº| j d d ƒ } n  t | t ƒ sÏt ‚ | j d ƒ } t | j  ƒ  ƒ } | d k r| j! ƒ  } | d | | f 7} qª | | k rx| d | 7} | j d ƒ sU| d 7} n  | | j" ƒ  j# d d ƒ d 7} qª t$ | d d ƒ} | j d d d | d ƒ| j | ƒ qª Wt$ | d d ƒ} | j d d ƒ | j d | ƒ t% ƒ  } x* | j& ƒ  D] \ } } | j | | ƒ qýWx | D] } | j' | ƒ q$W| j | j( ƒ  ƒ | j d ƒ d S(   s4  Write 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.

        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.
        R8   R-   i    i   RS   R   s   .gzR   R   R   i   t   applications   x-gzips   Content-Dispositiont
   attachmentt   filenames   UTF-8Rb   s   %s: %s
s   %s:
 s   
s   
 t   _charsets   .txtt   inlineN()   t   sortedR1   RE   RZ   R[   R   RX   R   R	   RV   R\   RA   R   R   R   R   R   R   R€   R   RR   R   t
   add_headert   set_payloadR    RW   R4   t   decodeR`   R   Ra   R"   R'   t   rstripRD   Rb   R   R   t   itemst   attacht	   as_string(   R   R   t   attach_tresholdt   extra_headerst	   skip_keyst   priority_fieldsRE   t   textt   attachmentst   countert   priority_fieldRq   Rr   t   attach_valueR{   t   iot   gfR!   t   attt   linest   msgR|   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt
   write_mimev  s–    		
	
#	c      
   C   sñ   t  | d ƒ s t ‚ | j d d ƒ j d d ƒ j d d ƒ j ƒ  sK t ‚ t | t ƒ sÞ t  | d ƒ sÞ t  | d ƒ rØ t | ƒ d k s² t | ƒ d k rØ | d t t f k rØ t  | d	 d ƒ sÞ t  | d	 d
 ƒ sÞ t ‚ |  j	 j
 | | ƒ S(   Nt   isalnumt   .R8   t   -t   _t   __getitem__i   i   i    R   (   RV   R   Rb   R¥   RX   R   R"   R   R   R1   t   __setitem__(   R   Rq   Rr   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyRª   ù  s    6:,c         C   s   t  |  j j ƒ  ƒ |  j S(   s‘   Return newly added keys.

        Return the set of keys which have been added to the report since it
        was constructed or loaded.
        (   R2   R1   RE   R3   (   R   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   new_keys  s    c         C   sÐ   t  | d ƒ } d } | d @r5 | | | d 7} n  | d @rs x$ t  | | ƒ d k re | d 7} qB W| d 7} n  | d @r± x$ t  | | ƒ d k r£ | d 7} q€ W| d 7} n  | d @rÈ | d 7} n  | | S(	   s0   Strip gzip header from line and return the rest.i   i
   i   i   i   i    i   i   (   t   ord(   t   klassRJ   t   flagst   offset(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR@     s    



N(   R(   R)   R   R   R   RL   RN   RR   R   R   Rˆ   R¤   Rª   R«   t   classmethodR@   (    (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR+   ]   s   M		œ‚		t   _Tc           B   sé   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z	 d „  Z
 d	 „  Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   sÑ   t  ƒ  } d | d <d | d <d | d <d | d <d | d <|  j | d d ƒ |  j | d d ƒ |  j | d d	 ƒ |  j t j | d
 ƒ ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ d S(   s   basic creation and operation.t   bart   foos    foo   bar
baz
   blip  t   1s   dash-keys   dot.keyt   underscore_keyR-   R,   R.   N(   R+   t   assertEqualt
   assertTrueR/   t   strptime(   R   t   pr(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_basic_operations)  s    	




c         C   sG   t  d ƒ } |  j | d d ƒ t  d d ƒ } |  j | d d ƒ d S(   s"   non-default constructor arguments.t   KernelCrashR-   R5   s   19801224 12:34R.   N(   R+   R¶   (   R   R¹   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_ctor_arguments:  s    c         C   s    t  ƒ  } |  j t | j d d ƒ |  j t | j d d ƒ |  j t | j d d ƒ |  j t | j d d	 ƒ |  j t | j d d
 ƒ |  j t | j d ƒ d S(   s   various error conditions.s   a bR´   R|   i   s   /tmp/nonexistantR8   t   NonexistantN(   i   (   s   /tmp/nonexistantR8   (   R+   t   assertRaisesR   Rª   t   KeyErrorR©   (   R   R¹   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_sanity_checksB  s    	c         C   sS  d d } t  ƒ  } t d ƒ | d <t ƒ  | d <| d j d d d	 ƒ t | ƒ | d
 <|  j t | d t ƒ ƒ |  j t | d t ƒ ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d d d	 ƒ |  j | d
 j ƒ  | ƒ |  j t | d ƒ d ƒ |  j t | d ƒ d ƒ |  j t | d
 ƒ t | ƒ ƒ t ƒ  } | d j	 | ƒ |  j | j
 ƒ  d d d	 ƒ t ƒ  } | d
 j	 | ƒ |  j | j
 ƒ  | ƒ t d ƒ | d <|  j | d j ƒ  d d d g ƒ t ƒ  } | j	 | ƒ | j d ƒ t  ƒ  } | j | ƒ |  j | d d ƒ |  j | d d d d	 ƒ |  j | d
 | ƒ d S(   s#   handling of CompressedValue values.t   Ai@KL s   FooFoo!t   Foot   Bint   ABi
   RU   t   Zt   Largei   i   s
   

t	   Multilines   s   s   i    Nt   ABABABABABABABABABABt
             RÈ   RÉ   RÈ   RÉ   RÈ   RÉ   (   R+   R   R   R·   RX   R¶   R   R"   R   R   R   R'   Rj   RL   (   R   t	   large_valR¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_compressed_valuesM  s>    
	" 				c         C   sÜ   t  d d ƒ } d | d <t j j d ƒ rq d | d <d j d ƒ | d	 <d
 j d ƒ | d <d
 j d ƒ | d <n1 d j d ƒ | d <d | d	 <d
 | d <d
 | d <d | d <t ƒ  } | j | ƒ |  j | j	 ƒ  d ƒ d S(   s   write() and proper formatting.R5   s   now!R²   t   SimpleRT   s	   1Ã¤Ã¶2Î¦3t
   SimpleUTF8s   UTF-8t   SimpleUnicodes   pi-Ï€
nu-Î·t   TwoLineUnicodet   TwoLineUTF8s'    foo   bar
baz
  blip  

afteremptylinet
   WhiteSpacesË   ProblemType: Crash
Date: now!
Simple: bar
SimpleUTF8: 1Ã¤Ã¶2Î¦3
SimpleUnicode: 1Ã¤Ã¶2Î¦3
TwoLineUTF8:
 pi-Ï€
 nu-Î·
TwoLineUnicode:
 pi-Ï€
 nu-Î·
WhiteSpace:
  foo   bar
 baz
   blip  
 
 afteremptyline
N(
   R+   R^   R_   R<   R‘   Ra   R   R   R¶   R   (   R   R¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt
   test_writev  s     





	c         C   sf  t  d d ƒ } d | d <d | d <t ƒ  } | j | ƒ | j ƒ  d | d <| j | ƒ |  j | j ƒ  d	 ƒ t j ƒ  } | j d d d ƒ | j ƒ  t  d d ƒ } | j	 f | d <t ƒ  } | j | ƒ | j
 ƒ  | j ƒ  d | d <| j | ƒ | j d ƒ t  ƒ  } | j | ƒ |  j | d d ƒ |  j | d d d d ƒ |  j | d d ƒ d S(   s+   write() with appending to an existing file.R5   s   now!R²   RÌ   s    foo   bar
baz
  blip  RÑ   t   appendedt   Extrasa   ProblemType: Crash
Date: now!
Simple: bar
WhiteSpace:
  foo   bar
 baz
   blip  
Extra: appended
RÄ   i
   RU   RÅ   t   Filei    R.   NRÈ   RÉ   RÈ   RÉ   (   R+   R   R   R;   R¶   R   t   tempfilet   NamedTemporaryFileRB   R
   R€   Rj   RL   (   R   R¹   RŸ   t   temp(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_appendœ  s6    

	

	
	


	c         C   s  t  ƒ  } | j t d ƒ ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d	 ƒ | j t d
 ƒ ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ | j t d ƒ ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ t  ƒ  } | j t d ƒ ƒ |  j | d d ƒ |  j | d d ƒ | j t d ƒ ƒ |  j | d d	 ƒ |  j | d d ƒ t d ƒ } t  ƒ  } |  j t | j | ƒ | j t d ƒ ƒ |  j t | j ƒ  ƒ d g ƒ d S(   s   load() with various formatting.sQ   ProblemType: Crash
Date: now!
Simple: bar
WhiteSpace:
  foo   bar
 baz
   blip  
R-   R,   R.   s   now!RÌ   R²   RÑ   s    foo   bar
baz
  blip  sS   ProblemType: Crash
Date: now!
Simple: bar
WhiteSpace:
  foo   bar
 baz
   blip  
 
s    foo   bar
baz
  blip  
s?   ProblemType: Crash
Date: now!
Simple: bar
WhiteSpace:
 foo
 bars   foo
barsF   ProblemType: Crash
WhiteSpace:
  foo   bar
 baz
 
   blip  
Last: foo
s    foo   bar
baz

  blip  t   LastR³   sF   ProblemType: Crash
WhiteSpace:
  foo   bar
 baz
   blip  
Last: foo
 
s   foo
s   WhiteSpace:
 first

 second
s   ProblemType: CrashN(   R+   RL   R   R¶   R¾   t
   ValueErrort   listRE   (   R   R¹   t   invalid_spacing(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt	   test_loadÊ  sD    		
		
	
		
	
		c         C   sN  t  j ƒ  } | j d d d ƒ | j ƒ  t d d ƒ } | j f | d <| j f | d <t ƒ  } | j | ƒ | j ƒ  |  j | j	 ƒ  d	 ƒ t  j ƒ  } | j d
 ƒ | j ƒ  t d d ƒ } | j t
 f | d <t ƒ  } | j | ƒ |  j | j	 ƒ  d ƒ | j t f | d <t ƒ  } | j | ƒ |  j | j	 ƒ  d ƒ | j ƒ  d S(   s'   writing a report with binary file data.RÄ   i
   RU   RÅ   R5   s   now!RÕ   t   Afiles   ProblemType: Crash
Date: now!
Afile: base64
 H4sICAAAAAAC/0FmaWxlAA==
 c3RyxIAMcBAFAK/2p9MfAAAA
File: base64
 H4sICAAAAAAC/0ZpbGUA
 c3RyxIAMcBAFAK/2p9MfAAAA
t   foo bars,   ProblemType: Crash
Date: now!
File: foo bar
s[   ProblemType: Crash
Date: now!
File: base64
 H4sICAAAAAAC/0ZpbGUA
 S8vPZ0hKLAIACq50HgcAAAA=
NRÈ   RÉ   (   RÖ   R×   R   RB   R+   R
   R   R€   R¶   R   R   R   (   R   RØ   R¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_file  s4    
	
	
		c         C   s½   t  d d d ƒ } t  d ƒ } t d d ƒ } | f | d <| t f | d	 <t  ƒ  } | j | ƒ | j d
 ƒ t ƒ  } | j | ƒ |  j | d | j ƒ  ƒ |  j | d	 | j ƒ  ƒ d S(   s6   writing a report with a pointer to a file-like object.RÄ   i
   RU   RÅ   s   Hello WorldR5   s   now!t   BinFilet   AscFilei    NRÈ   RÉ   (   R   R+   R   R   Rj   RL   R¶   R   (   R   t   tempbint   tempascR¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_fileobjT  s    		c         C   s¤   t  d ƒ } t  d ƒ } t d d ƒ } | t d t f | d <t  ƒ  } |  j t | j | ƒ t d d ƒ } | t d t f | d <t  ƒ  } |  j t | j | ƒ d S(   sS   writing a report with a pointer to a file-like object with enforcing non-emptyness.R8   R5   s   now!Râ   Rã   N(   R   R+   R   R   R¾   R]   R   R   (   R   Rä   Rå   R¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_empty_fileobjf  s    		c         C   sv  t  j ƒ  \ } } t  j ƒ  d k r­ t  j | ƒ t j d ƒ t  j | d d d ƒ t j d ƒ t  j | d ƒ t j d ƒ t  j | d ƒ t  j | ƒ t  j d ƒ n  t  j | ƒ t d d	 ƒ } t  j	 | ƒ f | d
 <t
 ƒ  } | j | ƒ t  j ƒ  d d k st ‚ | j d ƒ t ƒ  } | j | ƒ |  j | d
 j d ƒ ƒ |  j t | d
 ƒ d t d ƒ ƒ d S(   s5   writing a report with file pointers and delayed data.i    g333333Ó?t   abi   i   t   hellos    worldR5   s   now!Râ   i   s   abhello worldi   s   hello worldN(   R}   t   pipet   forkR€   R/   t   sleepR   t   _exitR+   t   fdopenR   t   waitR   Rj   RL   R·   RA   R¶   R"   (   R   t   foutt   finR¹   RŸ   t   pr2(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_delayed_fileobjv  s,    		c         C   s  d } t  ƒ  } | j t | ƒ ƒ |  j | d d d d ƒ |  j | j ƒ  t ƒ | j t | ƒ d t ƒ|  j | d d ƒ |  j | j ƒ  t ƒ | j t | ƒ d d	 ƒ|  j | d
 d ƒ |  j | j ƒ  t ƒ |  j t | d t	 ƒ ƒ |  j | d j
 ƒ  d d d ƒ d S(   s"   reading a report with binary data.sd   ProblemType: Crash
Date: now!
File: base64
 H4sICAAAAAAC/0ZpbGUA
 c3RyxIAMcBAFAK/2p9MfAAAA
Foo: Bar
RÕ   RÄ   i
   RU   RÅ   RF   R8   R7   RÂ   t   BarNRÈ   RÉ   RÈ   RÉ   (   R+   RL   R   R¶   RN   R   R   R·   RX   R   R   (   R   t
   bin_reportR¹   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_read_file•  s    		c         C   sG  d } d d d } t  ƒ  } | j t | ƒ ƒ |  j | d | ƒ |  j | j ƒ  t ƒ | j t | ƒ d t ƒ|  j | d d ƒ |  j | j ƒ  t ƒ | j t | ƒ d d	 ƒ|  j | j ƒ  t ƒ |  j t | d ƒ t | ƒ ƒ |  j | d j ƒ  | ƒ t ƒ  } | d j	 | ƒ | j
 d
 ƒ |  j | j ƒ  | ƒ d S(   sO   reading a report with binary data in legacy format without gzip
        header.sP   ProblemType: Crash
Date: now!
File: base64
 eJw=
 c3RyxIAMcBAFAG55BXk=
Foo: Bar
RÄ   i
   RU   RÅ   RÕ   RF   R8   R7   i    NRÈ   RÉ   (   R+   RL   R   R¶   RN   R   R   R"   R   R   Rj   R   (   R   Rõ   R1   R¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_read_file_legacy³  s"    
	 	c         C   s]  t  j ƒ  } t j d ƒ } | j | ƒ | j ƒ  t ƒ  } | j f | d <d | d <d | d <t ƒ  } | j | ƒ | j	 ƒ  | j
 d ƒ t ƒ  } | j | ƒ |  j | d | k ƒ |  j | d d ƒ |  j | d d ƒ t ƒ  } | j | ƒ |  j | j ƒ  | j ƒ  k ƒ | j
 d ƒ t ƒ  } | j | d d	 ƒ|  j | d j ƒ  | ƒ d
 S(   s*   writing and re-decoding a big random file.i   RÕ   t   xtestxt   Beforet   ytestyt   ZAfteri    RF   R7   N(   RÖ   R×   R}   t   urandomR   RB   R+   R
   R   R€   Rj   RL   R·   R¶   R   R   (   R   RØ   R1   R¹   RŸ   t   io2(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_big_fileÖ  s0    
	

	
			c         C   s  t  j ƒ  } t j d ƒ } | j | ƒ | j ƒ  t ƒ  } | j t d f | d <| j t d f | d <| j t d f | d <| j t d f | d <| j t d f | d	 <d
 | d <d | d <t
 ƒ  } | j | ƒ | j ƒ  | j d ƒ t ƒ  } | j | ƒ |  j | j d ƒ ƒ |  j | j d ƒ ƒ |  j | d | k ƒ |  j | d | k ƒ |  j | d	 | k ƒ |  j | d d
 ƒ |  j | d d ƒ d S(   s4   writing and a big random file with a size limit key.i   id   t   FileSmallLimitiÿÿ t   FileLimitMinus1t   FileExactLimiti  t   FileLimitPlus1t   FileLimitNoneRø   Rù   Rú   Rû   i    N(   RÖ   R×   R}   Rü   R   RB   R+   R
   R   R   R   R€   Rj   RL   t   assertFalset   has_keyR·   R¶   (   R   RØ   R1   R¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_size_limitü  s2    
	

	
	c         C   s“   t  ƒ  } d | d <g  } x | D] } | j | ƒ q  W| j ƒ  |  j d j | ƒ d ƒ |  j t g  | D] } | d k rj | ^ qj ƒ d ƒ d S(   s   ProblemReport iteration.R²   R³   R6   s   Date ProblemType fooi   N(   R+   RW   RY   R¶   t   joinR"   (   R   R¹   RE   Rq   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt	   test_iter  s    	

c         C   s¦   d } t  ƒ  } | j t | ƒ ƒ |  j | d d ƒ t ƒ  } | j | ƒ |  j | j ƒ  | ƒ d | d <d | d <t ƒ  } | j | ƒ |  j | j ƒ  d ƒ d S(	   s,   reading, modifying fields, and writing back.sy   ProblemType: Crash
Date: now!
Long:
 xxx
 .
 yyy
Short: Bar
File: base64
 H4sICAAAAAAC/0ZpbGUA
 c3RyxIAMcBAFAK/2p9MfAAAA
t   Longs	   xxx
.
yyys   aaa
bbbt   Shortt   123sv   ProblemType: Crash
Date: now!
Long: 123
Short:
 aaa
 bbb
File: base64
 H4sICAAAAAAC/0ZpbGUA
 c3RyxIAMcBAFAK/2p9MfAAAA
N(   R+   RL   R   R¶   R   R   (   R   t   reportR¹   RŸ   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_modify-  s    		

	
c         C   s  t  ƒ  } d | d <d | d <t j ƒ  \ } } t j | ƒ | j t | d ƒ ƒ t j | ƒ } t  ƒ  } | j ƒ  d | d <| j	 | d t
 ƒt j | ƒ } |  j | j | j ƒ |  j | j | j d	 ƒ |  j | j | j d	 ƒ t  ƒ  } | j t | ƒ ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ t j d	 ƒ t | ƒ j ƒ  t j d	 ƒ t  ƒ  } | j ƒ  d
 | d <| j	 | ƒ t j | ƒ } |  j | j | j ƒ |  j | j | j ƒ t } | } x¥ t | ƒ d	 k r‚t j j | ƒ \ } }	 t j j | ƒ rÞx^ t d ƒ D]P }
 |
 j d ƒ d	 d !\ } } } | | k r'd | j d ƒ k r't
 } Pq'q'WPqÞqÞW| s¢|  j | j | j ƒ n  t  ƒ  } | j t | ƒ ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d ƒ |  j | d d
 ƒ t j | ƒ d S(   s)   adding information to an existing report.t   11t   old1t   22t   old2t   wt   33t   new1R†   i   t   44t   new2s   /proc/mountsR6   i   t   noatimet   ,N(   R+   RÖ   t   mkstempR}   R€   R   R\   R~   R;   Rˆ   R   R¶   R„   t   assertAlmostEqualR‚   Rƒ   RL   R/   Rì   R   t   assertNotEqualR   R"   t   pathRC   t   ismountt   unlink(   R   R¹   t   fdt   rept   origstatt   newstatt   newprt
   skip_atimet   dirR‹   RJ   t   mountt   fst   options(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_add_to_existingV  sd    	

	

		

!	c         C   sX  t  d d ƒ } d | d <t j j d ƒ rq d | d <d j d ƒ | d	 <d
 j d ƒ | d <d
 j d ƒ | d <n1 d j d ƒ | d <d | d	 <d
 | d <d
 | d <d | d <d | d <d | d <d | d <t ƒ  } | j | ƒ | j d ƒ t	 j
 | ƒ } g  | j ƒ  D] } | ^ q	} |  j t | ƒ d ƒ |  j | d j ƒ  ƒ |  j | d j ƒ  ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j d t ƒ d ƒ |  j | d j ƒ  ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j d t ƒ d ƒ d S(   s   write_mime() for text values.R5   s   now!R²   RÌ   RT   s	   1Ã¤Ã¶2Î¦3RÍ   s   UTF-8RÎ   s   pi-Ï€
nu-Î·
RÏ   RÐ   s   bar
t   SimpleLineEnds   first
second
t   TwoLines    first
second
third
fourth
fifth
t   InlineMargins7    foo   bar
baz
  blip  
line4
lineâ™¥5!!
Å‚Ä±Âµâ‚¬ â…
RÇ   i    i   i   s
   text/plains   utf-8R‘   sð   ProblemType: Crash
Date: now!
InlineMargin:
 first
 second
 third
 fourth
 fifth
Simple: bar
SimpleLineEnd: bar
SimpleUTF8: 1Ã¤Ã¶2Î¦3
SimpleUnicode: 1Ã¤Ã¶2Î¦3
TwoLine:
 first
 second
TwoLineUTF8:
 pi-Ï€
 nu-Î·
TwoLineUnicode:
 pi-Ï€
 nu-Î·
i   s   Multiline.txtN(   R+   R^   R_   R<   R‘   Ra   R   R¤   Rj   t   emailt   message_from_filet   walkR¶   R"   R·   t   is_multipartt   get_content_typet   get_content_charsett   get_filenameR   t   get_payloadR   (   R   R¹   RŸ   R£   t   pt   parts(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_mime_text¡  sD    








	c         C   s<  d! d" d } t  j ƒ  } | j | ƒ | j ƒ  t  j ƒ  } t j d d d | ƒ} | j | ƒ | j ƒ  | j ƒ  t d d	 ƒ } d
 | d <| j f | d <| j f | d <| | d <t	 | j ƒ j
 ƒ  | d <t | ƒ | d <t ƒ  } | j | ƒ | j d ƒ t j | ƒ } g  | j ƒ  D] } | ^ q!}	 |  j t |	 ƒ d ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d  ƒ |  j |	 d j d t ƒ d ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d ƒ t  j ƒ  }
 |
 j |	 d j d t ƒ ƒ |
 j d ƒ |  j t j d d d |
 ƒ j
 ƒ  | ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d ƒ t  j ƒ  }
 |
 j |	 d j d t ƒ ƒ |
 j d ƒ |  j t j d d d |
 ƒ j
 ƒ  | ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d ƒ t  j ƒ  }
 |
 j |	 d j d t ƒ ƒ |
 j d ƒ |  j t j d d d |
 ƒ j
 ƒ  | ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d ƒ t  j ƒ  }
 |
 j |	 d j d t ƒ ƒ |
 j d ƒ |  j t j d d d |
 ƒ j
 ƒ  | ƒ |  j |	 d j ƒ  ƒ |  j |	 d j ƒ  d ƒ |  j |	 d j ƒ  d ƒ t  j ƒ  }
 |
 j |	 d j d t ƒ ƒ |
 j d ƒ |  j t j d d d |
 ƒ j
 ƒ  | ƒ d  S(#   s3   write_mime() for binary values and file references.RÄ   i
   RU   RÅ   t   File1R  R   R5   s   now!s
   Test suitet   Contexts   File1.gzt   Value1s	   Value1.gzt   ZValuei    i   i   s
   text/plains   utf-8R‘   s2   ProblemType: Crash
Context: Test suite
Date: now!
i   s   application/x-gzipR   t   rbi   i   i   i   s	   ZValue.gzNRÈ   RÉ   (   RÖ   R×   R   RB   R   R   R€   R+   R
   R\   R   R   R   R¤   Rj   R-  R.  R/  R¶   R"   R·   R0  R1  R2  R3  R   R4  R   t   TemporaryFile(   R   t	   bin_valueRØ   t   tempgzR    R¹   RŸ   R£   R5  R6  R{   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_mime_binaryé  s€    




	((((c         C   s6  t  d d ƒ } d | d <d | d <t ƒ  } | j | d i d d	 6d
 d 6ƒ| j d ƒ t j | ƒ } |  j | d	 d ƒ |  j | d d
 ƒ g  | j ƒ  D] } | ^ qž } |  j t | ƒ d ƒ |  j	 | d j
 ƒ  ƒ |  j	 | d j
 ƒ  ƒ |  j | d j ƒ  d ƒ |  j	 d | d j d t ƒ k ƒ d S(   s    write_mime() with extra headers.R5   s   now!R²   RÌ   s   first
second
R+  R—   s   hello worldt   GreetingRô   RÂ   i    i   i   s
   text/plains   Simple: barR‘   N(   R+   R   R¤   Rj   R-  R.  R¶   R/  R"   R·   R0  R1  R4  R   (   R   R¹   RŸ   R£   R5  R6  (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_mime_extra_headersC  s     

	c         C   s×  d d d } t  d d ƒ } d | d <d	 | d
 <| | d <d d d | d <t ƒ  } | j | d d
 d g ƒ| j d ƒ t j | ƒ } g  | j ƒ  D] } | ^ q˜ } |  j t | ƒ d ƒ |  j	 | d j
 ƒ  ƒ |  j	 | d j
 ƒ  ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j d t ƒ d ƒ |  j	 | d j
 ƒ  ƒ t j ƒ  } | j | d j d t ƒ ƒ | j d ƒ |  j t j d d d | ƒ j ƒ  | ƒ d S(    s   write_mime() with key filters.RÄ   i
   RU   RÅ   R5   s   now!t   Hit   GoodTextt   YouDontSeeMet   BadTextt   GoodBint   Ys   R§   t   BadBinR˜   i    i   i   s
   text/plains   utf-8R‘   s+   ProblemType: Crash
Date: now!
GoodText: Hi
i   R   R<  R   NRÈ   RÉ   s
   (   R+   R   R¤   Rj   R-  R.  R/  R¶   R"   R·   R0  R1  R2  R3  R   R4  R   RÖ   R=  R   R   R   R   (   R   R>  R¹   RŸ   R£   R5  R6  R{   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_mime_filter]  s0    


	c         C   sb  d d d } t  d d ƒ } d | d <d	 | d
 <d | d <d | d <t ƒ  } | j | d d
 d d d d g ƒ| j d ƒ t j | ƒ } g  | j ƒ  D] } | ^ q™ } |  j t | ƒ d ƒ |  j	 | d j
 ƒ  ƒ |  j	 | d j
 ƒ  ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j ƒ  d ƒ |  j | d j d t ƒ d ƒ d S(   s   write_mime() with keys ordered.RÄ   i
   RU   RÅ   R5   s   now!t   Whatt
   SecondTextt   Whot	   FirstTextt   Todayt
   FourthTexts   I Don't Knowt	   ThirdTextR™   t   Unknowni    i   i   s
   text/plains   utf-8R‘   sh   FirstText: Who
SecondText: What
ThirdText: I Don't Know
FourthText: Today
ProblemType: Crash
Date: now!
NRÈ   RÉ   (   R+   R   R¤   Rj   R-  R.  R/  R¶   R"   R·   R0  R1  R2  R3  R   R4  R   (   R   R>  R¹   RŸ   R£   R5  R6  (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_write_mime_order„  s(    



	c         C   sÀ   t  ƒ  } |  j | j ƒ  t d d g ƒ ƒ | j t d ƒ ƒ |  j | j ƒ  t ƒ  ƒ d | d <d | d <|  j | j ƒ  t d g ƒ ƒ t ƒ  } | j | d t ƒ|  j | j ƒ  d	 ƒ d
 S(   s*   new_keys() and write() with only_new=True.R-   R.   s1   ProblemType: Crash
Date: now!
Foo: bar
Baz: blob
t   changedRÂ   s   new newt   NewKeyRn   s   NewKey: new new
N(	   R+   R¶   R«   R2   RL   R   R   R   R   (   R   R¹   R   (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_updating¨  s    	"	


	c         C   sÐ   t  ƒ  } d | d <d d d | d <d | d	 <i  } d
 | d <d | d <d | d	 <| j | ƒ |  j | d d ƒ |  j | d d d d ƒ |  j | d d
 ƒ |  j | d d ƒ |  j | d	 d ƒ d S(   s%   importing a dictionary with update().s   Hello worldt   oldtextRÄ   i
   RU   RÅ   t   oldbins	   I am crapt	   overwrites   Goodbye worldt   newtextt   11 ÿZZt   newbins	   I am goodNRÈ   RÉ   RÈ   RÉ   (   R+   t   updateR¶   (   R   R¹   t   d(    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   test_import_dict¾  s    	




(   R(   R)   Rº   R¼   RÀ   RË   RÒ   RÙ   RÞ   Rá   Ræ   Rç   Ró   Rö   R÷   Rþ   R  R  R  R)  R7  R@  RB  RJ  RS  RV  R_  (    (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyR±   (  s2   				)	&	.	U	5					#	&	#		)	K	H	Z		'	$	t   __main__(    R*   R   R:   R/   R^   R   R$   t   email.encodersR    t   email.mime.multipartR   t   email.mime.baseR   t   email.mime.textR   t	   cStringIOR   t   ImportErrorRŸ   t   collectionsR   R   R   R+   t   unittestRÖ   R}   R-  t   TestCaseR±   R(   t   main(    (    (    s2   /usr/lib/python2.7/dist-packages/problem_report.pyt   <module>   s.   H?ÿ Ê0ÿ ÿ ÿ ­