U
    -es                      @   s8   d Z ddlZddlZddlZddlZG dd deZdS )z/Logger class for IPython's logging facilities.
    Nc                   @   sl   e Zd ZdZdddZdd Zd	d
 ZeeeZdddZ	dd Z
dd Zdd ZdddZdd ZeZdS )Loggerz9A Logfile class with different policies for file creation
Logger.log overc                 C   s:   || _ || _|| _|| _d | _d| _d| _d| _d| _d S )NF)	home_dirlogfnamelogheadlogmodelogfilelog_raw_input
log_output	timestamp
log_active)selfr   r   r   r	    r   T/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/IPython/core/logger.py__init__   s    zLogger.__init__c                 C   s   |dkrt d| || _d S )N)appendbackupglobalr   rotatezinvalid log mode %s given)
ValueError_logmode)r   moder   r   r   	_set_mode6   s    zLogger._set_modec                 C   s   | j S )N)r   r   r   r   r   	_get_mode;   s    zLogger._get_modeNFc                 C   s.  | j dk	rtd| j |dk	r&|| _|dk	r4|| _|dk	rB|| _|| _|| _|| _tj	j
}| j}|dkrtj| jddd| _ n|dkr|| jr| jd }||rt| t| j| tj| jd	dd| _ n,|d
kr
tj	| j| j| _tj| jddd| _ n|dkrB|| jr,t| j tj| jd	dd| _ n|dkr|| jr|| jd rt| jd }	|	  |	  |	D ]L}
tj	|
\}}t|dd d }t|
|d t|d d  qt| j| jd  tj| jd	dd| _ |dkr| j | j | j   d| _dS )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(   Zbackup_lognameoldfrootextnumr   r   r   logstart@   s^    
   





&

zLogger.logstartc                 C   st   |dkrt d| ddddd}| jdkr6td n:| j|krPtd||  n td	||  | j | _| j| _dS )
z4Switch logging on/off. val should be ONLY a boolean.)FTr   r!   z:Call switch_log ONLY with a boolean argument, not with: %sZ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   Zlog_active_out)r   vallabelr   r   r   
switch_log   s    



zLogger.switch_logc                 C   sl   | j dkrtd nT| jrdp d}td| j td| j td| j td| j td	| j td
| dS )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
   r>   r   r   r	   r   r   r   )r   stater   r   r   logstate   s    

zLogger.logstatec                 C   s    | j r| | n
| | dS )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   Zline_modZline_orir   r   r   log   s    inputc                 C   s   | j r|r| jj}|dkr>| jr4|tdt  || n2|dkrp| jrpddd |	 D }|d|  z| j
  W n6 tk
r   td td	| j d
 td Y nX dS )z%Write data to the log file, if activerG   z# %a, %d %b %Y %H:%M:%S
output
c                 S   s   g | ]}d | qS )z
#[Out]# %sr   ).0sr   r   r   
<listcomp>   s   z$Logger.log_write.<locals>.<listcomp>z%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
   r5   r   timestrftime	localtimer   r-   
splitlinesr6   OSErrorr>   r   )r   datakindr5   odatar   r   r   rE      s*    


zLogger.log_writec                 C   s.   | j dk	r| j   d| _ ntd d| _dS )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
   closer>   r   r   r   r   r   logstop   s
    

zLogger.logstop)r   r   r   )NNNFFF)rG   )__name__
__module____qualname____doc__r   r   r   propertyr	   r<   rA   rD   rF   rE   rV   Z	close_logr   r   r   r   r      s$     

      
A
r   )rZ   r.   r)   r&   rM   objectr   r   r   r   r   <module>   s
   