
    ^h                          S r SSKrSSKrSSKrSSKrSSKr\R                  " S5      R                  \R                  5         " S S\	5      r
g)z/Logger class for IPython's logging facilities.
    Nparsoc                   x    \ rS rSrSr  SS jrS rS r\" \\5      r	  SS jr
S rS	 rS
 rSS jrS r\rSrg)Logger   z9A Logfile class with different policies for file creationc                 z    Xl         X l        X0l        X@l        S U l        SU l        SU l        SU l        SU l        g )NF)	home_dirlogfnamelogheadlogmodelogfilelog_raw_input
log_output	timestamp
log_active)selfr   r	   r
   r   s        M/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/logger.py__init__Logger.__init__!   sD    
 !  #         c                 8    US;  a  [        SU-  5      eXl        g )N)appendbackupglobaloverrotatezinvalid log mode %s given)
ValueError_logmode)r   modes     r   	_set_modeLogger._set_mode:   s!    CC84?@@r   c                     U R                   $ )N)r   r   s    r   	_get_modeLogger._get_mode?   s    }}r   Nc                 (   U R                   b  [        SU R                  -  5      eUb  Xl        Ub  X l        Ub  X0l        XPl        X@l        X`l        [        R                  R                  nU R                  nUS:X  a'  [        R                  " U R                  SSS9U l         GOUS:X  a  U" U R                  5      (       aS  U R                  S-   nU" U5      (       a  [        R                  " U5        [        R                  " U R                  U5        [        R                  " U R                  S	SS9U l         GO
US
:X  a`  [        R                  R                  U R                   U R                  5      U l        [        R                  " U R                  SSS9U l         GOUS:X  a^  U" U R                  5      (       a   [        R                  " U R                  5        [        R                  " U R                  S	SS9U l         GO@US:X  Ga9  U" U R                  5      (       a  U" U R                  S-   5      (       a  ["        R"                  " U R                  S-   5      n	U	R%                  5         U	R'                  5         U	 Hl  n
[        R                  R)                  U
5      u  p[+        USS 5      S-   n[        R                  " XS-   [-        U5      R/                  S5      -   S-   5        Mn     [        R                  " U R                  U R                  S-   5        [        R                  " U R                  S	SS9U l         US:w  a%  U R                   R1                  U R                  5        U R                   R3                  5         SU l        g)zgGenerate 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   r1   backup_lognameoldfrootextnums                 r   logstartLogger.logstartD   s    <<#?#}} - . . ww #$* ,,h774==#HDL dmm$$!%s!2 .))IIn-		$--7774==#HDL GGLLt}}EDM774==#HDLdmm$$		$--(774==wGDL dmm$$$--/00))DMM%$78CHHJKKM $&GG$4$4Q$7	!#a)nQ.		!#Xd3iooa.@%@%DE ! 		$--w)>?774==#HDLhLLt||,r   c                    US;  a  [        SU-  5      eSSSSS.nU R                  c  [        S5        gU R                  U:X  a  [        SX!   5        g[        S	X!   5        U R                  (       + U l        U R                  U l        g)
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_logLogger.switch_log   s     && ,.12 3 3 4e6<< 1 2 #%*5:6)%*5&*oo"5&*oo#r   c                 f   U R                   c  [        S5        gU R                  =(       a    S=(       d    Sn[        SU R                  5        [        SU R                  5        [        SU R
                  5        [        SU R                  5        [        S	U R                  5        [        S
U5        g)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   rK   r   r	   r   r   r   r   )r   states     r   logstateLogger.logstate   s    <<34OO0K4KE$dmm4$dll3$doo6$d&8&89$dnn5$e,r   c                 l    U R                   (       a  U R                  U5        gU R                  U5        g)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   log
Logger.log   s%     NN8$NN8$r   c                 l   U R                   (       a  U(       a  U R                  R                  nUS:X  aJ  U R                  (       a0  U" [        R
                  " S[        R                  " 5       5      5        U" U5        OUUS:X  aO  U R                  (       a>  SR                  UR                  5        Vs/ s H  nSU-  PM
     sn5      nU" SU-  5         U R                  R                  5         gggs  snf ! [         a2    [        S5        [        SU R                   S	35        [        S
5         gf = f)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   r>   r   timestrftime	localtimer   r6   
splitlinesr?   OSErrorrK   r	   )r   datakindr>   sodatas         r   rW   Logger.log_write   s     ??tLL&&EW}>>$--(CT^^EUVWdxDOO

,0OO,=$?,=q %2A$5,=$? @go&	""$  $?$?
  56(7^_ ^s   3C2C7 79D32D3c                     U R                   b"  U R                   R                  5         SU l         O[        S5        SU l        g)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   closerK   r   r"   s    r   logstopLogger.logstop   s5     <<#LL DL01r   )r   r   r   rL   r   r   r   r	   r
   r   r   )z
Logger.log r   )NNNFFF)r]   )__name__
__module____qualname____firstlineno____doc__r   r   r#   propertyr   rF   rO   rT   rZ   rW   rl   	close_log__static_attributes__ r   r   r   r      sT    C@C 2
 y+G<@BG?B62-%(2  Ir   r   )rs   r7   r2   loggingr/   r`   	getLoggersetLevelWARNINGobjectr   rw   r   r   <module>r}      sH     	  	    '  # #GOO 4IV Ir   