
    fs                      >    d Z ddlZddlZddlZddlZ G d de      Zy)z/Logger class for IPython's logging facilities.
    Nc                   j    e Zd ZdZ	 	 ddZd Zd Z eee      Z	 	 ddZ	d Z
d Zd	 Zdd
Zd ZeZy)Loggerz9A Logfile class with different policies for file creationc                     || _         || _        || _        || _        d | _        d| _        d| _        d| _        d| _        y )NF)	home_dirlogfnamelogheadlogmodelogfilelog_raw_input
log_output	timestamp
log_active)selfr   r   r   r	   s        N/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/core/logger.py__init__zLogger.__init__   sL    
 !  #         c                 6    |dvrt        d|z        || _        y )N)appendbackupglobaloverrotatezinvalid log mode %s given)
ValueError_logmode)r   modes     r   	_set_modezLogger._set_mode6   s#    CC84?@@r   c                     | j                   S )N)r   r   s    r   	_get_modezLogger._get_mode;   s    }}r   Nc                    | j                   t        d| j                  z        ||| _        ||| _        ||| _        || _        || _        || _        t        j                  j                  }| j                  }|dk(  r)t        j                  | j                  dd      | _         n|dk(  r || j                        rL| j                  dz   } ||      rt        j                  |       t        j                  | j                  |       t        j                  | j                  d	d      | _         n|d
k(  rbt        j                  j                  | j                   | j                        | _        t        j                  | j                  dd      | _         n|dk(  rZ || j                        rt        j                  | j                         t        j                  | j                  d	d      | _         n4|dk(  r. || j                        r || j                  dz         rt#        j"                  | j                  dz         }	|	j%                          |	j'                          |	D ]l  }
t        j                  j)                  |
      \  }}t+        |dd       dz   }t        j                  |
|dz   t-        |      j/                  d      z   dz          n t        j                  | j                  | j                  dz          t        j                  | j                  d	d      | _         |dk7  r%| j                   j1                  | j                         | j                   j3                          d| _        y)zoGenerate a new log-file with a default header.

        Raises RuntimeError if the log has already been startedNzLog file is already active: %sr   azutf-8)encodingr   ~wr   r   r   z.001~z.*~   .   T)r
   RuntimeErrorr   r   r	   r   r   r   ospathisfileioopenremoverenamejoinr   globsortreversesplitextintreprzfillwriteflushr   )r   r   r   r	   r   r   r   r,   backup_lognameoldfrootextnums                 r   logstartzLogger.logstart@   s    <<#?#}} - . . ww #$* ,,h774==#HDL dmm$!%s!2 .)IIn-		$--7774==#HDL GGLLt}}EDM774==#HDLdmm$		$--(774==wGDL dmm$$--/0))DMM%$78CHHJKKM  F$&GG$4$4Q$7	c!#a)nQ.		!T#Xd3iooa.@%@%DEF 		$--w)>?774==#HDLhLLt||,r   c                    |dvrt        d|z        ddddd}| j                  t        d       y| j                  |k(  rt        d||          yt        d	||          | j                   | _        | j                  | _        y)
z4Switch logging on/off. val should be ONLY a boolean.)FTr   r%   z:Call switch_log ONLY with a boolean argument, not with: %sOFFON)r   r%   FTNz
Logging hasn't been started yet (use logstart for that).

%logon/%logoff are for temporarily starting and stopping logging for a logfile
which already exists. But you must first start the logging process with
%logstart (optionally giving a logfile name).zLogging is alreadyzSwitching logging)r   r
   printr   log_active_out)r   vallabels      r   
switch_logzLogger.switch_log   s     && ,.12 3 3 4e6<< 1 2 #%*5:6)%*5&*oo"5&*oo#r   c                 P   | j                   t        d       y| j                  xr dxs d}t        d| j                         t        d| j                         t        d| j
                         t        d| j                         t        d	| j                         t        d
|       y)z(Print a status message about the logger.NzLogging has not been activated.activeztemporarily suspendedzFilename       :zMode           :zOutput logging :zRaw input log  :zTimestamping   :zState          :)r
   rE   r   r   r	   r   r   r   )r   states     r   logstatezLogger.logstate   s    <<34OO0K4KE$dmm4$dll3$doo6$d&8&89$dnn5$e,r   c                 b    | j                   r| j                  |       y| j                  |       y)a^  Write the sources to a log.

        Inputs:

        - line_mod: possibly modified input, such as the transformations made
          by input prefilters or input handlers of various kinds. This should
          always be valid Python.

        - line_ori: unmodified input line from the user. This is not
          necessarily valid Python.
        N)r   	log_write)r   line_modline_oris      r   logz
Logger.log   s%     NN8$NN8$r   c                 4   | j                   r|r| j                  j                  }|dk(  rC| j                  r. |t	        j
                  dt	        j                                       ||       nL|dk(  rG| j                  r;dj                  |j                         D cg c]  }d|z  	 c}      } |d|z         	 | j                  j                          yyyc c}w # t        $ r2 t        d       t        d| j                   d	       t        d
       Y yw xY w)z%Write data to the log file, if activeinputz# %a, %d %b %Y %H:%M:%S
output
z
#[Out]# %sz%s
zFailed to flush the log file.zPlease check that z' exists and have the right permissions.zHAlso consider turning off the log with `%logstop` to avoid this warning.N)r   r
   r9   r   timestrftime	localtimer   r1   
splitlinesr:   OSErrorrE   r   )r   datakindr9   sodatas         r   rO   zLogger.log_write   s     ??tLL&&EW}>>$--(CT^^EUVWdxDOO

,0OO,=$?'( %2A$5 $? @go&	""$  $?$?
  56(7^_ ^s   C:C 8DDc                     | j                   )| j                   j                          d| _         d| _        yt        d       d| _        y)zFully stop logging and close log file.

        In order to start logging again, a new logstart() call needs to be
        made, possibly (though not necessarily) with a new filename, mode and
        other options.NzLogging hadn't been started.F)r
   closerE   r   r   s    r   logstopzLogger.logstop   s@     <<#LL DL   01r   )z
Logger.log r   )NNNFFF)rT   )__name__
__module____qualname____doc__r   r   r   propertyr	   rA   rI   rM   rR   rO   rb   	close_log r   r   r   r      sT    C@C 2
 y+G<@BG?B62-%(2  Ir   r   )rg   r2   r-   r*   rW   objectr   rj   r   r   <module>rl      s&     	 	 IV Ir   