Format: application/x-python-code
⬇ Download File (11.7 KB)
   1  o
   2  
   3  ��hU/�@s�ddlZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
   4  Z
   5  ddlmZm
   6  Z
   7  mZdZ	e�d�Z	dZ	e��Ze��ZiZe�add�ZGdd	�d	e�ZGd
   8  d�de�Zd5d
   9  d�Zefdd�Z dd�Z!e�"e!d�Z#e�"e!d�Z$e�"e!d�Z%dd�Z&d6dd�Z'd6dd�Z(d6dd�Z)ddefdd�Z*ej+d d!��Z,d"d#�Z-d$d%�Z.ed&ej/e�d'd(��0�d)d*�Z/ej1d+d,��Z2d-d.�Z3d/d0�Z4d1d2�Z5d3d4�Z6dS)7�N)�json�	timestamp�util)�debug�info�warning�errorZDEBUGPY_LOG_DIRz09.3fcCstdd�t��D��adS)Ncss �|]}|jD]}|VqqdS�N)�levels)�.0�file�level�r�Hc:\Users\shubh\Videos\agent\nova\Lib\site-packages\debugpy/common/log.py�	<genexpr>)s�z!_update_levels.<locals>.<genexpr>)�	frozenset�_files�values�_levelsrrrr�_update_levels'src@sTeZdZedfdd�Zedd��Zejdd��Zdd�Zd	d
  10  �Z	dd�Z
  11  d
  12  d�ZdS)�LogFileTcCs�tdt�|��||_||_||_t|�|_t�.|t	|j<t
  13  �tdt��t��t�
  14  �t��tjdkr6dndtj|gd�Wd�dS1sIwYdS)NzAlso logging to {0}.z%{0} {1}
  15  {2} {3} ({4}-bit)
  16  debugpy {5}l�@� )�	_to_files)rr�repr�filenamer�
  17  close_filerr�_lockrr�platform�machine�python_implementation�python_version�sys�maxsize�debugpy�__version__)�selfrrr
  18  rrrr�__init__-s&
  19  
  20  �"�zLogFile.__init__cCs|jSr	)r�r&rrrr
  21  BszLogFile.levelscCsFt�t|tur
  22  tn|�|_t�Wd�dS1swYdSr	)rr�all�LEVELSrr)r&�valuerrrr
  23  Fs"�cCs@||jvrz|j�|�|j��WdStyYdSwdSr	)r
  24  r�write�flush�	Exception)r&r
  25  �outputrrrr,Ls
  26  ��z
  27  LogFile.writecCstt�t|j=t�Wd�n1swYtdt�|j��|jr8z|j�	�WdSt
  28  y7YdSwdS)NzNot logging to {0} anymore.)rrrrrrrrr�closer.r(rrrr0Ts���z
  29  LogFile.closecC�|Sr	rr(rrr�	__enter__`�zLogFile.__enter__cCs|��dSr	)r0�r&�exc_type�exc_val�exc_tbrrr�__exit__cszLogFile.__exit__N)�__name__�
  30  __module__�__qualname__r*r'�propertyr
  31  �setterr,r0r2r8rrrrr,s
  32  
  33  rc@s8eZdZdZZdd�ZZdd�Zdd�Zdd	�Z	dS)
  34  �NoLogNcCsdS)NFrr(rrr�<lambda>j�zNoLog.<lambda>cC�dSr	rr(rrrr0lr3zNoLog.closecCr1r	rr(rrrr2or3zNoLog.__enter__cCrAr	rr4rrrr8rr3zNoLog.__exit__)
  35  r9r:r;rr�__bool__�__nonzero__r0r2r8rrrrr>gsr>rcCs6t�t�|d�Wd�dS1swYdS)N�
  36  )r�stderrr,�r
  37  rrr�newlinexs"�rGc	Cs�|tvsJ�t��}dtd}|�|d��|�}ttdd�|}ddt|�}|�	|�
  38  d��}||d}t�|turCt
  39  ��}|D]}|�||�qEWd�|S1sYwY|S)	Nz{0}+{1:z}: r�prefix�rD� �
  40  
  41  )r*r�current�timestamp_format�format�upper�getattr�_tls�len�join�splitrr)rrr,)	r
  42  �textr�t�
  43  format_stringrH�indentr/rrrrr,}s$�
  44  ��r,cOsV|dkr
  45  |tvr
  46  dSz
  47  |j|i|��}Wnty t�Ynwt|||�dt��S)Nrr)rrNr.�reraise_exceptionr,�popr))r
  48  rW�args�kwargsrUrrr�write_format�s
  49  �r]rrcOsttdg|�Ri|���S)z�Logs an error.
  50  
  51      Returns the output wrapped in AssertionError. Thus, the following::
  52  
  53          raise log.error(s, ...)
  54  
  55      has the same effect as::
  56  
  57          log.error(...)
  58          assert False, (s.format(...))
  59      r)�AssertionErrorr])r[r\rrrr�srrIcOs�|�dd�}|�dt���}|r|d7}|d7}d�tj|��}t��}|r)|jn|}zd�t�	|��}W~n~wt
  60  ||g|�R||d�|��dS)Nr
  61  r�exc_inforKz'{exception}
  62  Stack where logged:
  63  {stack}rI)�	exception�stack)rZr"r_rS�	traceback�format_exception�inspect�currentframe�f_back�format_stackr])rWr[r\r
  64  r_r`�frarrr�
  65  _exception�s(���
  66  �ricOst|g|�Ri|��dS)a�Logs an exception with full traceback.
  67  
  68      If format_string is specified, it is formatted with format(*args, **kwargs), and
  69      prepended to the exception traceback on a separate line.
  70  
  71      If exc_info is specified, the exception it describes will be logged. Otherwise,
  72      sys.exc_info() - i.e. the exception being handled currently - will be logged.
  73  
  74      If level is specified, the exception will be logged as a message of that level.
  75      The default is "error".
  76      N�ri�rWr[r\rrr�swallow_exception�s
  77  rlcOs$d|vsJ�t|g|�Ri|���)zOLike swallow_exception(), but re-raises the current exception after logging it.r_rjrkrrrrY�srYcCs�|du|duAs
  78  J�|dur3tdurt�Szt�t�Wn	ty%Ynwt�d|�dt���d�}t�|�}|durJt|t	j
  79  |ddd�|�}|S||_|S)a�Starts logging all messages at the specified levels to the designated file.
  80  
  81      Either filename or prefix must be specified, but not both.
  82  
  83      If filename is specified, it designates the log file directly.
  84  
  85      If prefix is specified, the log file is automatically created in options.log_dir,
  86      with filename computed as prefix + os.getpid(). If log_dir is None, no log file
  87      is created, and the function returns immediately.
  88  
  89      If the file with the specified or computed name is already being used as a log
  90      file, it is not overwritten, but its levels are updated as specified.
  91  
  92      The function returns an object with a close() method. When the object is closed,
  93      logs are not written into that file anymore. Alternatively, the returned object
  94      can be used in a with-statement:
  95  
  96          with log.to_file("some.log"):
  97              # now also logging to some.log
  98          # not logging to some.log anymore
  99      N�/�-z.log�wzutf-8)�encoding)�log_dirr>�os�makedirs�OSError�getpidr�getr�io�openr
 100  )rrHr
 101  rrrr�to_file�s �
 102  �rycosD�|j|i|��}ttdd�}||t_z	dVW|t_dS|t_w)znAdds a prefix to all messages logged from the current thread for the duration
 103      of the context manager.
 104      rHrIN)rNrPrQrH)rWr[r\rHZ
 105  old_prefixrrr�prefixeds�
 106  rzcs�ddl}ddl}|dg��fdd��d �fdd�	}�d�|d�|d	�|d
 107  �|d�|d�|d
 108  �dd�tjD��|�fdd�d�|��D]}d�|�}||�qJ|d�|d�|d��d�d}zddl}Wnty�zddlm	}Wn	ty�YnwYnw|dur��d�n%�d�z|�
 109  �D]
 110  }�d|j|j�q�Wnt
 111  y�tddd�Ynwd����d�S)!NrrKcs��|j|i|���dSr	)�appendrN)�sr[r\)�resultrr�report sz+get_environment_description.<locals>.reportcs�d|p|�d�}d�t|�s|��fdd�}z|�}Wn(ty*�d|�YdStyCtd�r8t��nt�|�dd�YdSwt|tt	f�sN|g}t
 112  |�D]%}�d	||�|durmtj�
 113  |�}||krm�d
 114  |��d�dt|�}qRdS)
 115  Nz    z: cs
 116  t���Sr	)r�evaluater��exprrrr?)s
 117  zCget_environment_description.<locals>.report_paths.<locals>.<lambda>z
 118  {0}<missing>
 119  zError evaluating {0}rrFz{0}{1}z({0})rDrJ)�callable�AttributeErrorr.rlrrZ	srcnameof�
 120  isinstance�list�tuple�sortedrr�path�realpathrR)�	get_paths�labelrH�paths�p�rp)r~r�r�report_paths#s:
 121  
 122  ��
 123  �z1get_environment_description.<locals>.report_pathszSystem paths:
 124  zsys.executablez
 125  sys.prefixzsys.base_prefixzsys.real_prefixzsite.getsitepackages()zsite.getusersitepackages()cSs,g|]}tj�|�rtj�|�dkr|�qS)z
 126  site-packages)rrr��exists�basename)rr�rrr�
 127  <listcomp>Ls
 128  ��z/get_environment_description.<locals>.<listcomp>cs�Sr	rr)�
 129  site_packagesrrr?Qr@z-get_environment_description.<locals>.<lambda>zsys.path (site-packages)zsysconfig.get_path({0!r})zos.__file__zthreading.__file__zdebugpy.__file__rD)�metadatazACannot enumerate installed packages - missing importlib_metadata.zInstalled packages:
 130  z
 131      {0}=={1}
 132  z+Error while enumerating installed packages.rrFrIr	)�	sysconfig�siter"r��get_path_namesrN�importlib_metadata�ImportError�	importlibr��
 133  distributions�name�versionr.rlrS�rstrip)�headerr�r�r�r�r�r��pkgr)r~r}r�r�get_environment_descriptions^!�
 134  
 135  ���
 136  �
 137  ��r�cCstdt|��dS)Nz{0})rr�)r�rrr�describe_environmentssr�z<stderr>ZDEBUGPY_LOG_STDERRz
 138  warning errorF)r
 139  rcCstt���D]}|��qdSr	)r�rrr0)rrrr�_close_filess
 140  �r�cCstd|�dS)Nz$REPR {0!r})r)r+rrr�_repr�sr�cs0t��jj�|r�fdd�|D��td��dS)Ncsi|]}|�vr|�|�qSrr)rr���localsrr�
 141  <dictcomp>�sz_vars.<locals>.<dictcomp>z$VARS {0!r})rdrerf�f_localsr)�namesrr�r�_vars�sr�cCsd�t���}td|�dS)NrDz$STACK:
 142  
 143  {0})rSrbrgr)rarrr�_stack�sr�cCs&d�dd�t��D��}td|�dS)NrDcSsg|]}t|��qSr)�str)rrVrrrr��sz_threads.<locals>.<listcomp>z$THREADS:
 144  
 145  {0})rS�	threading�	enumerater)r/rrr�_threads�sr�)r)rI)7�atexit�
 146  contextlib�	functoolsrdrwrrrr"r�rbr$Zdebugpy.commonrrrr*�getenvrqrM�RLockr�localrQr�setrr�objectrr>rGr)r,r]�partialrrrrrirlrYry�contextmanagerrzr�r�rErT�registerr�r�r�r�r�rrrr�<module>sh
 147  ;
 148  
 149  
 150  
 151  *
 152  
 153  Y�
 154