
    G@d                     l    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dS )
z@
Class to control a file where stanbdard output can be written.
    N)to_text_string)
get_coding)get_temp_dirc                    t          j        |           }|                    d          d         |z   }|t          j        ||          }n<	 t          j        t	                      |          }n# t
          t          f$ r d}Y nw xY w|S )zFilename to save kernel output.z.jsonr   N)ospbasenamesplitjoinr   IOErrorOSError)connection_file	extensionstd_dir	json_filefiles        Klib/python3.11/site-packages/spyder/plugins/ipythonconsole/utils/stdfile.pystd_filenamer      s    _--I??7##A&2Dx&&	8LNND11DD! 	 	 	DDD	Ks   !A. .BBc                   D    e Zd ZddZed             Zd Zd Zd Zd Z	dS )	StdFileNc                 p    ||| _         nt          |||          | _         d| _        d| _        d | _        d S )Nr   )filenamer   _mtime_cursor_handle)selfr   r   r   s       r   __init__zStdFile.__init__'   s=    +DMM()WMMDM    c                     | j         :| j        3	 t          j        | j        dd          | _         n# t          $ r Y nw xY w| j         S )zGet handle to file.Nwzutf-8)encoding)r   r   codecsopen	Exceptionr   s    r   handlezStdFile.handle0   sc     <DM$=%{M3 :  :  :   |s   !2 
??c                     	 | j         | j                                          t          j        | j                   d| _         dS # t
          $ r Y dS w xY w)z'Remove file associated with the client.N)r   closeosremover   r#   r$   s    r   r)   zStdFile.remove=   sd    		 |'""$$$Idm$$$DLLL 	 	 	DD	s   A A 
AAc                    	 t          | j        d          5 }|                                }|s	 ddd           dS t          |          }t	          ||          }|cddd           S # 1 swxY w Y   dS # t
          $ r Y dS 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   s   	dmT** a vvxx
          &d++%dH55!                 "  	 	 	44	s>   A6 A)A6  A)A6 )A--A6 0A-1A6 6
BBc                 ^   | j         %| j         j        s| j                                          	 t          j        | j                  j        }n# t          $ r Y dS w xY w|| j        k    rdS || _        | 	                                }|r%|| j
        d         }t          |          | _
        |S dS )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    <#DL,?#L   	GDM**3EE 	 	 	FF	 DKF  "" 	DLMM*Ht99DLO	 	s   A 
AA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            
 
 X
    .  $& & & & &r   r   )N)__doc__r!   r(   os.pathpathr   spyder.py3compatr   spyder.utils.encodingr   spyder.utils.programsr   r   r   r@   r   r   <module>rG      s    
  				       , + + + + + , , , , , , . . . . . .   O& O& O& O& O& O& O& O& O& O&r   