
    7 f.                        d dl Z d dlZd dlZd dlZd dlZd dlmZmZ d dl	m
Z
mZmZmZmZmZmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZmZ d d	lmZmZ   e            Z!d
e
deee"                  de#fdZ$d'dZ%deej&                 dej'        fdZ(dej'        defdZ)deee"e
f                  fdZ*	 d(dedej+        de,dee"e
f         fdZ-dedej+        dee,eee,e"f                  e"f         fdZ.de
de"fdZ/d)d
e
de,de j0        fdZ1deee"e
f         ef         dee"eeee"e
f                  e
f         f         fdZ2d)deej&                 fd Z3d d!d"Z4 G d# d$          Z5d d!d%Z6d& Z7dS )*    N)PrettyPrinterpformat)AnyDictListOptionalSequenceTupleUnion)Local)	QueryDict)Node)format_html)
SafeString	mark_safe)_stubssettingsframeexcluded_modulesreturnc                     |sdS | j                             d          t          t                    sdS t	          fd|D                       S )NF__name__c              3   T   K   | ]"}|k    p                     |d z             V  #dS ).N)
startswith).0excluded_moduleframe_modules     I/var/www/equiseq/venv/lib/python3.11/site-packages/debug_toolbar/utils.py	<genexpr>z%_is_excluded_frame.<locals>.<genexpr>   sY          	' 	:""?S#899         )	f_globalsget
isinstancestrany)r   r   r   s     @r   _is_excluded_framer'      sv     u?&&z22LlC(( u      0     r!   c                  >    t          j        dt          d           d S )NzNget_stack() and tidy_stacktrace() are deprecated in favor of get_stack_trace()   )
stacklevel)warningswarnDeprecationWarning r!   r    _stack_trace_deprecation_warningr/   !   s0    M		     r!   stackc                    t                       g }t          j                    d         }d | D             D ]\  }}}}}t          ||          r|r'd                    |                                          nd}t          j                    d         rt          |j                  nd}|                    |||||f           |S )z
    Clean up stacktrace and remove all entries that are excluded by the
    HIDE_IN_STACKTRACES setting.

    ``stack`` should be a list of frame tuples from ``inspect.stack()`` or
    ``debug_toolbar.utils.get_stack()``.
    HIDE_IN_STACKTRACESc              3   *   K   | ]}|d d         V  d S )N   r.   )r   fs     r   r    z"tidy_stacktrace.<locals>.<genexpr>6   s*      1G1GA!BQB%1G1G1G1G1G1Gr!    ENABLE_STACKTRACES_LOCALSN)	r/   dt_settings
get_configr'   joinstripr   f_localsappend)	r0   tracer   r   pathline_no	func_nametextframe_localss	            r   tidy_stacktracerD   *   s     %&&&E"-//0EF1G1G1G1G1G 	E 	E-tWie%566 	(,4rwwt}}""$$$" %''(CDGEN### 	
 	dGYlCDDDDLr!   r>   c           
      v   t          j                    d         }d}| D ]\  }}}}}t          j        j        |v r=|                    t          j        j        d          \  }}	|t          j        j        z  }nd}|}	|t          d||	|||          z  }|r|t          d|          z  }|dz  }t          |          S )Nr7   r6      z<span class="djdt-path">{}</span><span class="djdt-file">{}</span> in <span class="djdt-func">{}</span>(<span class="djdt-lineno">{}</span>)
  <span class="djdt-code">{}</span>
z$  <pre class="djdt-locals">{}</pre>

)r8   r9   osr?   seprsplitr   r   )
r>   show_localshtmlabspathlinenofunccodelocals_	directoryfilenames
             r   render_stacktracerT   C   s    (**+FGKD05  ,tW7;'!!")..a"@"@Ix$II IH: 
 
 	
  	K7  D 	T??r!   c                     d } t          j                    j        }	 ||j        j                            d          }|j        j        t          j        k    }|r|rnY|j        j        dk    r@|j	        d         }|j	        d         }t          |t                    rt          ||          } n	|j        }|n# t          $ r Y nw xY w~| S )Nz/debug_toolbar/utils.pyrenderselfcontext)sys	_getframef_backf_codeco_filenameendswithco_nameget_template_contextr   r<   r$   r   	Exception)template_info	cur_framein_utils_moduleis_get_template_contextnoderX   s         r   get_template_inforg   f   s    M&I#'.:CC) O  (,@,II $  	#: 	 !)X55 )&1#,Y7dD)) $8w$G$GM!(I# #$    s   BB6 6
CC   rf   rX   context_linesc                     t          | |          \  }}}g }t          d||z
            }|dz   |z   }|D ]2\  }	}
||	cxk    r|k    r n |                    |	|
|	|k    d           3||dS )NrF   )numcontent	highlight)namerX   )'get_template_source_from_exception_infomaxr=   )rf   rX   ri   linesource_linesrn   debug_contextstartendline_numrl   s              r   r`   r`      s      GtWUUD,M4-'((E
(]
"C)  'H#########   WHPTDTVV   ]333r!   c                 &   |j         j        | j        k    r.|j                             t          d          | j                  }n2|j        j                             t          d          | j                  }|d         }|d         }|d         }|||fS )NDDTrq   rr   rn   )templateoriginget_exception_infora   tokenrender_context)rf   rX   exception_inforq   rr   rn   s         r   ro   ro      s     $+-- )<<edj
 
 !/8KKedj
 
 &!D!.1L&!Dt##r!   objc                     t          | d          r| j        n| j        j        }t          | d          r| j        }| d| }|S )Nr   
__module__r   )hasattrr   	__class__r   )r   rn   modules      r   get_name_from_objr      sR    "3
33O3<<9ODsL!! "!!4!!Kr!   rF   c           	      Z   t          j        |           r| j        }| j        } n| j        }t          j        |           st          d          t          j        |           pt          j        |           }|dk    r|dz
  |dz  z
  }	 t          j	        |           \  }}t          |d          }t          dt          |t          |          |z
                      }||||z            }|dz
  |z
  }n# t          $ r dx}}Y nw xY wdx}}t          j        ||| j        j        ||          S )a  
    Get information about a frame or traceback object.

    A tuple of five things is returned: the filename, the line number of
    the current line, the function name, a list of lines of context from
    the source code, and the index of the current line within that list.
    The optional second argument specifies the number of lines of context
    to return, which are centered around the current line.

    This originally comes from ``inspect`` but is modified to handle issues
    with ``findsource()``.
    z&arg is not a frame or traceback objectr   rF   r)   N)inspectistraceback	tb_linenotb_framef_linenoisframe	TypeErrorgetsourcefilegetfile
findsourcerp   minlenra   	Tracebackr\   r_   )r   rX   rN   rS   rt   lineslnumindexs           r   getframeinfor      sN    5!!  ?5!! B@AAA$U++Ewu/E/EH{{
W\)	'!,U33KE4 qMME3uc%jj7&:;;<<E%57?34EQJ&EE  	! 	! 	!  EEEE	! Xvu|/CUERRRs   C3 3DDvariablec                      	 t           t                    rd fdt                     D             iS d fdt                     D             iS # t          $ r d icY S w xY w)z`
    Get a data structure for showing a sorted list of variables from the
    request data.
    listc                 >    g | ]}|                     |          fS r.   )r#   r   kr   s     r   
<listcomp>z/get_sorted_request_variable.<locals>.<listcomp>   s(    LLLaaa1LLLr!   c                 >    g | ]}|                     |          fS r.   )getlistr   s     r   r   z/get_sorted_request_variable.<locals>.<listcomp>   s,    PPP!a!1!1!!4!45PPPr!   raw)r$   dictsortedr   )r   s   `r   get_sorted_request_variabler      s    !h%% 	RLLLL6(;K;KLLLMMPPPPvh?O?OPPPQQ ! ! !x    !s   1A A A#"A#c                     t                       t          j        d          }g }|r0|                    |ft	          ||           z              |j        }|0|S )a.  
    Get a list of records for a frame and all higher (calling) frames.

    Each record contains a frame object, filename, line number, function
    name, a list of lines of context, and index within the context.

    Modified version of ``inspect.stack()`` which calls our own ``getframeinfo()``
    rF   )r/   rY   rZ   r=   r   r[   )rX   r   	framelists      r   	get_stackr      sj     %&&&M!EI
 %L$@$@@AAA   r!   skipc              #   t   K   | dz  } t          j                    }|| dk    r| dz  } n|V  |j        }|d S d S )NrF   r   )r   currentframer[   )r   r   s     r   _stack_framesr      s[      AID ""E

!88AIDDKKK 




r!   c                   d    e Zd Z e            Zd Zd Zdddddeee	                  de
d	efd
ZdS )_StackTraceRecorderc                     i | _         d S )N)filename_cache)rW   s    r   __init__z_StackTraceRecorder.__init__  s     r!   c                     |j         j        }| j                            |          }|?t	          j        |          }|d}|}nd}t          j        |           ||f}|| j        |<   |S )NFT)r\   r]   r   r#   r   r   	linecache
checkcache)rW   r   frame_filenamevaluerS   	is_sources         r   get_source_filez#_StackTraceRecorder.get_source_file	  s}    1#''77=,U33H!	) 	 $X...y)E27D/r!   NFr   r   include_localsr   r   r   r   c                   g }|dz  }t          |          D ]}t          ||          r|                     |          \  }}|j        }|j        j        }	|rIt          j        ||          }
|
|
j        nd }t          j
        |||                                          }nd}|r | j                            |j                  }nd }|                    |||	||f           |                                 |S )NrF   r   r6   )r   r'   r   r   r\   r_   r   	getmodule__dict__r   getliner;   pretty_printerr   r<   r=   reverse)rW   r   r   r   r>   r   rS   r   r@   rA   r   module_globalssource_linerC   s                 r   get_stack_tracez#_StackTraceRecorder.get_stack_trace  s    	"--- 	T 	TE!%)9:: "&"6"6u"="=HinG,I ! *5(;;4:4FD'/g~ %''  ! $#2::5>JJ#LL(GY\RSSSSr!   )r   r   __qualname__r   r   r   r   r   r	   r%   boolintr   r.   r!   r   r   r     s        "]__N! ! !  , 59$" " " #8C=1" 	"
 " " " " " "r!   r   c                     t          j                    }|d         sg S | dz  } t          t          dd          }|t	                      }|t          _        |                    |d         |d         |           S )a  
    Return a processed stack trace for the current call stack.

    If the ``ENABLE_STACKTRACES`` setting is False, return an empty :class:`list`.
    Otherwise return a :class:`list` of processed stack frame tuples (file name, line
    number, function name, source line, frame locals) for the current call stack.  The
    first entry in the list will be for the bottom of the stack and the last entry will
    be for the top of the stack.

    ``skip`` is an :class:`int` indicating the number of stack frames above the frame
    for this function to omit from the stack trace.  The default value of ``0`` means
    that the entry for the caller of this function will be the last entry in the
    returned stack trace.
    ENABLE_STACKTRACESrF   stack_trace_recorderNr2   r7   r   )r8   r9   getattr_local_datar   r   r   )r   configr   s      r   r   r   A  s     #%%F&' 	AID";0FMM#244+?(// 569: 0   r!   c                  B    t          t          d          r	t          `d S d S )Nr   )r   r   r   r.   r!   r   clear_stack_trace_cachesr   _  s+    {233 -,,,- -r!   )r   N)rh   )rF   )8r   r   os.pathrH   rY   r+   pprintr   r   typingr   r   r   r   r	   r
   r   asgiref.localr   django.httpr   django.templater   django.utils.htmlr   django.utils.safestringr   r   debug_toolbarr   stubsr   r8   r   r%   r   r'   r/   InspectStackTidyStackTracerD   rT   rg   RequestContextr   r`   ro   r   r   r   r   r   r   r   r   r   r.   r!   r   <module>r      s         



  ) ) ) ) ) ) ) ) D D D D D D D D D D D D D D D D D D       ! ! ! ! ! !             ) ) ) ) ) ) 9 9 9 9 9 9 9 9 B B B B B B B Begg
c 
Xhsm5L 
QU 
 
 
 
   4 23 8L    2 U1  j        F8DcN3    : EF4 4
4-4>A4	#s(^4 4 4 4"$
$-$
3U38_%s*+$ $ $ $"3 3    $S $S $Sc $S'2C $S $S $S $SN!DcNI-.!	#uT%S/*C/0
01! ! ! !  D!34    &      ; ; ; ; ; ; ; ;|      <- - - - -r!   