
    ]jo"                        d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dl	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 	 d dlZej.                  j1                  ej.                  j3                  e	j4                              Zd	 Z ej:                         d
   D  cg c]
  }  e|        c} Zd Zd Z d Z!d Z"ddZ#d Z$d Z%ddZ&d Z'ddZ( G d d      Z)y# e$ r dZY w xY wc c} w )    N)import_module)chain)ImproperlyConfigured)Node)render_to_string)	mark_safe)settingsc                 8   	 t        |       }t        j                  |      }|j                  d      rt        j
                  j                  |      }t        j
                  j                  |      S # t        $ r}t        dj                  |            d }~ww xY w)Nz__init__.pyz'Error importing HIDE_IN_STACKTRACES: {})r   inspectgetsourcefileendswithospathdirnamerealpathImportErrorr   format)module_namemodulesource_pathes       =/root/env/lib/python3.12/site-packages/debug_toolbar/utils.pyget_module_pathr      s    -{+ ++F3.''//+6Kww,,  X"#L#S#STU#VWWXs   A1 1	B:BBHIDE_IN_STACKTRACESc                 4     t         fdt        D              S )Nc              3   @   K   | ]  }j                  |        y wN)
startswith).0hidden_pathr   s     r   	<genexpr>zomit_path.<locals>.<genexpr>-   s     Lt{+Ls   )anyhidden_paths)r   s   `r   	omit_pathr$   ,   s    L|LLL    c                 @   g }d | D        D ]  \  }}}}}t        t        j                  j                  |            r2|rdj	                  |      j                         nd}t        j                         d   r|j                  nd}|j                  |||||f        |S )a4  
    Clean up stacktrace and remove all entries that:
    1. Are part of Django (except contrib apps)
    2. Are part of socketserver (used by Django's dev server)
    3. Are the last entry (which is part of our stacktracing code)

    ``stack`` should be a list of frame tuples from ``inspect.stack()``
    c              3   &   K   | ]	  }|d d   y w)N    )r   fs     r   r!   z"tidy_stacktrace.<locals>.<genexpr>:   s     1GA!BQ%1Gs    ENABLE_STACKTRACES_LOCALSN)
r$   r   r   r   joinstripdt_settings
get_configf_localsappend)stacktraceframer   line_no	func_nametextframe_localss           r   tidy_stacktracer:   0   s     E1G1G 	E-tWiRWW%%d+,(,rwwt}""$" %%'(CD NN 	
 	dGYlCD	E Lr%   c                    g }| D ]|  }d t        |d   j                  t        j                  j                  d      |dd        D        }t        |      D ci c]  \  }}t        |      | }}}	 |j                  |       ~ t        t        d|t        j                         d   d            S c c}}w # t        $ r Y w xY w)Nc              3       K   | ]  }|  y wr   r)   )r   vs     r   r!   z$render_stacktrace.<locals>.<genexpr>J   s     O!Os   r      z(debug_toolbar/panels/sql_stacktrace.htmlr,   )
stacktraceshow_locals)r   rsplitr   r   sep	enumeratestrr2   KeyErrorr   r   r/   r0   )r4   r?   r5   paramsidxr=   params_dicts          r   render_stacktracerI   G   s    J OU58??277;;#BE!"INO1:61BCvsAs3x{CC	k*	 6(*5578ST	
  D  	 	s   B11B77	CCc                     d } t        j                         j                  }	 ||j                  j                  j                  d      }|j                  j                  t        j                  k(  }|r|r	 ~| S |j                  j                  dk(  r>|j                  d   }|j                  d   }t        |t              rt        ||      } 	 ~| S |j                  }|~| S # t        $ r Y ~| S w xY w)Nz/debug_toolbar/utils.pyrenderselfcontext)sys	_getframef_backf_codeco_filenamer   co_nameget_template_context__name__r1   
isinstancer   	Exception)template_info	cur_framein_utils_moduleis_get_template_contextnoderM   s         r   get_template_infor]   ^   s   M&&I#'..::CC)O   ((,@,I,II $ #:  	 !!))X5 ))&1#,,Y7dD)$8w$GM 		 "((I# #( 	  s   AC! 8AC! C! !	C/.C/c                     t        | |      \  }}}g }t        d||z
        }|dz   |z   }|D ],  \  }	}
||	cxk  r|k  sn |j                  |	|
|	|k(  d       . ||dS )Nr>   )numcontent	highlight)namerM   )'get_template_source_from_exception_infomaxr2   )r\   rM   context_lineslinesource_linesrb   debug_contextstartendline_numr`   s              r   rT   rT   z   s    FtWUD,M4-'(E
(]
"C) 'H##   WHPTDTV ]33r%   c                     |j                   j                  t        d      | j                        }|d   }|d   }|d   }|||fS )NDDTrf   rg   rb   )templateget_exception_inforW   token)r\   rM   exception_inforf   rg   rb   s         r   rc   rc      sN    %%8859I4::VN&!D!.1L&!Dt##r%   c                     t        | d      r| j                  }n| j                  j                  }t        | d      r| j                  }dj	                  ||      }|S )NrU   
__module__z{}.{})hasattrrU   	__class__rs   r   )objrb   r   s      r   get_name_from_objrw      sL    sJ||}}%%sL!~~fd+Kr%   c           	         t        j                  |       r| j                  }| j                  } n| j                  }t        j
                  |       st        d      t        j                  |       xs t        j                  |       }|dkD  rh|dz
  |dz  z
  }	 t        j                  |       \  }}t        |d      }t        dt        |t        |      |z
              }|dd }||||z    }|dz
  |z
  }ndx}x}}|rxt        |d   t              red}	|dd D ]<  }
t!        j"                  d|
      }|s|j%                  d      j'                  d      }	 n |D 
cg c]  }
|
j'                  |	d       }}
t)        t         d	      r-t        j*                  ||| j,                  j.                  ||      S ||| j,                  j.                  ||fS # t        $ r	 dx}x}}Y w xY wc c}
w )
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   r>      Nasciis   coding[:=]\s*([-\w.]+)replace	Traceback)r   istraceback	tb_linenotb_framef_linenoisframe	TypeErrorr   getfile
findsourcerd   minlenrW   rV   bytesresearchgroupdecodert   r|   rQ   rS   )r5   rM   linenofilenameri   lineslnumfirst_linesindexencodingrf   matchs               r   getframeinfor      s    5!??5!@AA$$U+Ewu/EH{
W\)		'!,,U3KE4 qME3uc%j7&:;<E)K%57?4EQJ&E&***ee z+a.%8O 	D II8$?E ;;q>009	 ?DDdXy1DDw$  65<<3G3GPUVV&%,,"6"6uEE5  	/*..K.%%	/* Es   G G!GGc                     t        | t              r*t        |       D cg c]  }|| j                  |      f c}S t        |       D cg c]  }|| j	                  |      f c}S c c}w c c}w )z?
    Get a sorted list of variables from the request data.
    )rV   dictsortedgetgetlist)variableks     r   get_sorted_request_variabler      s`     (D!.4X.>?HLLO$??282BCQH$$Q'(CC @Cs   A%A*c                     t        j                  d      }g }|r.|j                  |ft        ||       z          |j                  }|r.|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()``
    r>   )rN   rO   r2   r   rP   )rM   r5   	framelists      r   	get_stackr      sL     MM!EI
%L$@@A  r%   c                   *    e Zd Zd ZddZddZddZy)ThreadCollectorc                 4    t         t        d      i | _        y )NzGthreading module is not available, this panel cannot be used without it)	threadingNotImplementedErrorcollections)rL   s    r   __init__zThreadCollector.__init__   s$    %7  r%   Nc                     |t        j                         }|| j                  vrg | j                  |<   | j                  |   S )z
        Returns a list of collected items for the provided thread, of if none
        is provided, returns a list for the current thread.
        r   currentThreadr   rL   threads     r   get_collectionzThreadCollector.get_collection   sF    
 >,,.F)))')DV$''r%   c                 h    |t        j                         }|| j                  v r| j                  |= y y r   r   r   s     r   clear_collectionz ThreadCollector.clear_collection  s6    >,,.FT%%%  ( &r%   c                 D    | j                  |      j                  |       y r   )r   r2   )rL   itemr   s      r   collectzThreadCollector.collect
  s    F#**40r%   r   )rU   rs   __qualname__r   r   r   r   r)   r%   r   r   r      s    	()1r%   r   )   )r>   )*r   os.pathr   r   rN   	importlibr   	itertoolsr   djangodjango.core.exceptionsr   django.templater   django.template.loaderr   django.utils.safestringr   debug_toolbarr	   r/   r   r   r   r   r   __file__django_pathr   r0   r#   r$   r:   rI   r]   rT   rc   rw   r   r   r   r   )r   s   0r   <module>r      s      	 
 #   7   3 - 1 ggrwwv?@	- .{--/0EF K M..84$
4FnD"1 1}  I(s    C C&C#"C#