ó
é©Tc           @   sí   d  d l  Z  d  d l Z d  d l Z d d d „ Z e ƒ  Z e  j e  j Be  j BZ	 e
 e  d ƒ rr e	 e  j OZ	 n  e
 e  d ƒ r‘ e	 e  j OZ	 n  e	 Z e
 e  d ƒ r¶ e e  j OZ n  d d  d „ Z d e d e d	 d  d
 „ Z d „  Z d S(   iÿÿÿÿNc         C   sk   | r( |  r d |  | f }  q( | }  n  |  rN d |  t  j d ƒ t j ƒ  f Sd t  j d ƒ t j ƒ  f S(   Ns   %s-%ss   reportbug-%s-%s-%d-s   %Y%m%ds   reportbug-%s-%d-(   t   timet   strftimet   ost   getpid(   t   packaget   extra(    (    s7   /usr/lib/python2.7/dist-packages/reportbug/tempfiles.pyt   tempfile_prefix   s    	t   O_NOINHERITt
   O_NOFOLLOWt   O_BINARYs   w+bc         C   sn   d | k r$ t  j |  t d ƒ } n t  j |  t d ƒ } y t  j | | | ƒ SWn t  j | ƒ ‚  n Xd  S(   Nt   bi€  (   R   t   opent   _bin_openflagst   _text_openflagst   fdopent   close(   t   filenamet   modet   bufsizet   fd(    (    s7   /usr/lib/python2.7/dist-packages/reportbug/tempfiles.pyt   open_write_safe6   s    t    s   w+c   	      C   s=   t  j |  | | | ƒ \ } } t j | | | ƒ } | | f S(   N(   t   tempfilet   mkstempR   R   (	   t   suffixt   prefixt   dirt   textR   R   t   fhR   R   (    (    s7   /usr/lib/python2.7/dist-packages/reportbug/tempfiles.pyt   TempFileD   s    c         C   s&   t  j j |  ƒ r" t  j |  ƒ n  d S(   sé    Clean up a temporary file.

        :parameters:
          `temp_filename`
            Full filename of the file to clean up.

        :return value:
            None

        Removes (unlinks) the named file if it exists.

        N(   R   t   patht   existst   unlink(   t   temp_filename(    (    s7   /usr/lib/python2.7/dist-packages/reportbug/tempfiles.pyt   cleanup_temp_fileJ   s    (   R   R   R    t   NoneR   t   templatet   O_RDWRt   O_CREATt   O_EXCLR   t   hasattrR   R   R   R	   R   t   TrueR   R"   (    (    (    s7   /usr/lib/python2.7/dist-packages/reportbug/tempfiles.pyt   <module>   s    	