
    Je                     d    d 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 d	dZ G d d      Zy)
z@
Class to control a file where stanbdard output can be written.
    N)to_text_string)
get_coding)get_temp_dirc                     t        j                  |       }|j                  d      d   |z   }|t        j                  ||      }|S 	 t        j                  t	               |      }|S # t
        t        f$ r d}Y |S w xY w)zFilename to save kernel output.z.jsonr   N)ospbasenamesplitjoinr   IOErrorOSError)connection_file	extensionstd_dir	json_filefiles        M/usr/lib/python3/dist-packages/spyder/plugins/ipythonconsole/utils/stdfile.pystd_filenamer      s    _-I??7#A&2Dxx& K		88LND1D K ! 	DK	s   A( (A=<A=c                   <    e Zd ZddZed        Zd Zd Zd Zd Z	y)	StdFileNc                 f    ||| _         nt        |||      | _         d| _        d| _        d | _        y )Nr   )filenamer   _mtime_cursor_handle)selfr   r   r   s       r   __init__zStdFile.__init__'   s4    +DM()WMDM    c                     | j                   @| j                  4	 t        j                  | j                  dd      | _         | j                   S | j                   S # t        $ r Y | j                   S w xY w)zGet handle to file.wzutf-8)encoding)r   r   codecsopen	Exceptionr   s    r   handlezStdFile.handle0   sj     <<DMM$=%{{MM3 : ||t||  ||s   'A 	A0/A0c                     	 | j                   | j                   j                          t        j                  | j                         d| _         y# t
        $ r Y yw xY w)z'Remove file associated with the client.N)r   closeosremover   r#   r$   s    r   r)   zStdFile.remove=   sL    		 ||'""$IIdmm$DL 		s   AA 	AAc                     	 t        | j                  d      5 }|j                         }|s
	 ddd       yt        |      }t	        ||      }|cddd       S # 1 sw Y   yxY w# t
        $ r Y yw xY w)z(Get the contents of the std kernel file.rbN )r"   r   readr   r   r#   )r   ftextr    s       r   get_contentszStdFile.get_contentsJ   sy    	dmmT* a vvx
   &d+%dH5!  "  		s8   A# AA# A	A# A A#  A# #	A/.A/c                    | j                   0| j                   j                  s| j                   j                          	 t        j                  | j
                        j                  }|| j                  k(  ry|| _        | j                         }|r!|| j                  d }t        |      | _
        |S y# t        $ r Y yw xY w)z*Check if the std kernel file just changed.N)r   closedflushr(   statr   st_mtimer#   r   r0   r   len)r   mtimer/   ret_texts       r   poll_file_changezStdFile.poll_file_changea   s    <<#DLL,?,?LL 	GGDMM*33E DKK  "DLLM*Ht9DLO   		s   )B2 2	B>=B>c                 ,    t        | j                        S )zReturn a copy.)r   r   r$   s    r   copyzStdFile.copys   s    t}}%%r   )NN)
__name__
__module____qualname__r   propertyr%   r)   r0   r9   r;    r   r   r   r   &   s/     
 
.$&r   r   )N)__doc__r!   r(   os.pathpathr   spyder.py3compatr   spyder.utils.encodingr   spyder.utils.programsr   r   r   r@   r   r   <module>rG      s1   
  	  , , .O& O&r   