o
    û›hÓ  ã                   @   sX   d Z ddlZddlZddlmZmZmZ ddlmZ ddl	m
Z
 eG dd„ deƒƒZdS )z=Implementation of magic functions for IPython's own logging.
é    N)ÚMagicsÚmagics_classÚ
line_magic)Úwarn)ÚBoolc                   @   sj   e Zd ZdZeddd�jdd�Zeddd	„ƒZedd
d„ƒZ	eddd„ƒZ
eddd„ƒZeddd„ƒZdS )ÚLoggingMagicsz(Magics related to all logging machinery.FzF
        Suppress output of log state when logging is enabled
        )ÚhelpT)ÚconfigÚ c                 C   s¤  |   |d¡\}}d|v }d|v }d|v }d|v }| jj}|r0z| ¡ \}	}
W n   |}	d}
Y n|j}	|j}
| jj}|	rBtj 	|	¡}	|	| j_d}z| 
|	||
|||¡ W n   || j_tdt ¡ d	  ƒ Y dS |rnd
|_|rv| jjj}n| jjj}|r©|j}| jjj}td	t|ƒd	 ƒD ]}|||  ¡ d ƒ ||v r§|t|| ƒdƒ qŽn| d |d	d… ¡¡ | d¡ |r¿d|_| jsÎ|sÐtdƒ | ¡  dS dS dS )aó  Start logging anywhere in a session.

        %logstart [-o|-r|-t|-q] [log_name [log_mode]]

        If no name is given, it defaults to a file named 'ipython_log.py' in your
        current directory, in 'rotate' mode (see below).

        '%logstart name' saves to file 'name' in 'backup' mode.  It saves your
        history up to that point and then continues logging.

        %logstart takes a second optional parameter: logging mode. This can be one
        of (note that the modes are given unquoted):

        append
            Keep logging at the end of any existing file.

        backup
            Rename any existing file to name~ and start name.

        global
            Append to  a single logfile in your home directory.

        over
            Overwrite any existing log.

        rotate
            Create rotating logs: name.1~, name.2~, etc.

        Options:

          -o
            log also IPython's output. In this mode, all commands which
            generate an Out[NN] prompt are recorded to the logfile, right after
            their corresponding input line. The output lines are always
            prepended with a '#[Out]# ' marker, so that the log remains valid
            Python code.

          Since this marker is always the same, filtering only the output from
          a log is very easy, using for example a simple awk call::

            awk -F'#\[Out\]# ' '{if($2) {print $2}}' ipython_log.py

          -r
            log 'raw' input.  Normally, IPython's logs contain the processed
            input, so that user lines are logged in their final form, converted
            into valid Python.  For example, %Exit is logged as
            _ip.run_line_magic("Exit").  If the -r flag is given, all input is logged
            exactly as typed, with no transformations applied.

          -t
            put timestamps before each input line logged (these are put in
            comments).

          -q
            suppress output of logstate message when logging is invoked
        ZortqÚoÚrÚtÚqÚbackupz# IPython log file

zCouldn't start log: %sé   FÚ
ÚoutputNTzGActivating auto-logging. Current session state plus future input saved.)Zparse_optionsÚshellÚloggerÚsplitÚlogfnameÚlogmodeZlogfileÚosÚpathÚ
expanduserÚlogstartr   ÚsysÚexc_infoÚ	timestampZhistory_managerZinput_hist_rawZinput_hist_parsedÚ	log_writeÚoutput_histÚrangeÚlenÚrstripÚreprÚjoinÚquietÚprintÚlogstate)ÚselfÚparameter_sÚoptsÚparZ
log_outputZlog_raw_inputr   r&   r   r   r   Zold_logfileZlogheadZ
input_histr   r    Ún© r.   úQc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/magics/logging.pyr   &   s`   ;ÿ

€ý

ýzLoggingMagics.logstartc                 C   ó   | j j ¡  dS )zÖFully 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.N)r   r   Úlogstop©r)   r*   r.   r.   r/   r1   ¤   s   zLoggingMagics.logstopc                 C   ó   | j j d¡ dS )zLTemporarily stop logging.

        You must have previously started logging.r   N©r   r   Z
switch_logr2   r.   r.   r/   Úlogoff­   s   zLoggingMagics.logoffc                 C   r3   )a  Restart logging.

        This function is for restarting logging which you've temporarily
        stopped with %logoff. For starting logging for the first time, you
        must use the %logstart function, which allows you to specify an
        optional log filename.r   Nr4   r2   r.   r.   r/   Úlogon´   s   	zLoggingMagics.logonc                 C   r0   )z'Print the status of the logging system.N)r   r   r(   r2   r.   r.   r/   r(   ¿   s   zLoggingMagics.logstateN)r
   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Útagr&   r   r   r1   r5   r6   r(   r.   r.   r.   r/   r      s"    ÿü}
r   )r:   r   r   ZIPython.core.magicr   r   r   Úwarningsr   Z	traitletsr   r   r.   r.   r.   r/   Ú<module>   s    