
     ha                        d dl Z 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 d dlm	Z	 d dl
mZmZmZ d dl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 d dlmZ d dlmZ d dl m!Z!m"Z"  edddi          Z#d Z$ G d de%          Z& G d d          Z'd#dZ(e j)        d             Z*d Z+d Z,d Z- G d d          Z. G d d           Z/d! Z0d" Z1dS )$    N)Path)settings)Http404HttpResponseHttpResponseNotFound)ContextEngineTemplateDoesNotExist)pprint)resolve)timezone)MultiValueDict)	force_str)import_string)_lazy_re_compile)PY311get_docs_versionTi18nzdjango.templatetags.i18n)debug	librariesc                 @    t          t                    j        dz  | z  S )z
    Return a path to a builtin template.

    Avoid calling this function at the module level or in a class-definition
    because __file__ may not exist, e.g. in frozen environments.
    	templates)r   __file__parent)names    Q/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/django/views/debug.pybuiltin_template_pathr      s     >> ;.55    c                       e Zd ZdS )ExceptionCycleWarningN)__name__
__module____qualname__ r   r   r    r    )   s        Dr   r    c                       e Zd ZdZd Zd ZdS )CallableSettingWrapperz
    Object to wrap callable appearing in settings.
    * Not to call in the debug page (#21345).
    * Not to break the debug page if the callable forbidding to set attributes
      (#23070).
    c                     || _         d S N)_wrapped)selfcallable_settings     r   __init__zCallableSettingWrapper.__init__5   s    (r   c                 *    t          | j                  S r(   )reprr)   r*   s    r   __repr__zCallableSettingWrapper.__repr__8   s    DM"""r   N)r!   r"   r#   __doc__r,   r0   r$   r   r   r&   r&   -   s<         ) ) )# # # # #r   r&     c                      t          |           | |||          }|                     d          r%|                                }t          ||          S |                                }t          ||d          S )z
    Create a technical server error response. The last three arguments are
    the values returned from sys.exc_info() and friends.
    z	text/html)statusztext/plain; charset=utf-8)r4   content_type)get_exception_reporter_classacceptsget_traceback_htmlr   get_traceback_text)requestexc_type	exc_valuetbstatus_codereporterhtmltexts           r   technical_500_responserB   <   s    
 5+G44Wh	SUVVH{## 
**,,D5555**,,3N
 
 
 	
r   c                  D     t          t          j                              S r(   )r   r   !DEFAULT_EXCEPTION_REPORTER_FILTERr$   r   r   %get_default_exception_reporter_filterrE   L   s     E=CDDFFFr   c                 @    t                      }t          | d|          S )Nexception_reporter_filter)rE   getattr)r:   default_filters     r   get_exception_reporter_filterrJ   R   s     :<<N77HHHr   c                 V    t          t          j                  }t          | d|          S )Nexception_reporter_class)r   r   DEFAULT_EXCEPTION_REPORTERrH   )r:    default_exception_reporter_classs     r   r6   r6   W   s5    '4+( ($ +-M  r   c                 v    | j         }|&	 t          | j                  }n# t          $ r Y nw xY w|dn|j        S )N )resolver_matchr   pathr   
_func_path)r:   rQ   s     r   
get_callerrT   `   sX    +N	$W\22NN 	 	 	D	'22^-FFs     
--c                   p    e Zd ZdZdZ edej                  Zd Z	d Z
d Zd Zd	 Zd
 Zd Zd Zd ZdS )SafeExceptionReporterFilterz
    Use annotations made by the sensitive_post_parameters and
    sensitive_variables decorators to filter out sensitive information.
    z********************z/API|TOKEN|KEY|SECRET|PASS|SIGNATURE|HTTP_COOKIE)flagsc                     |t           j        k    rd}n.	  j                            |          }n# t          $ r d}Y nw xY w|r j        }nt          |t                    r! fd|                                D             }nWt          |t                    r fd|D             }n3t          |t                    rt           fd|D                       }n|}t          |          rt          |          }|S )z
        Cleanse an individual setting key/value of sensitive content. If the
        value is a dictionary, recursively cleanse the keys in that dictionary.
        TFc                 D    i | ]\  }}|                     ||          S r$   cleanse_setting.0kvr*   s      r   
<dictcomp>z?SafeExceptionReporterFilter.cleanse_setting.<locals>.<dictcomp>   s/    PPP$!Q4//155PPPr   c                 <    g | ]}                     d |          S rP   rZ   r]   r_   r*   s     r   
<listcomp>z?SafeExceptionReporterFilter.cleanse_setting.<locals>.<listcomp>   s)    CCC,,R33CCCr   c                 <    g | ]}                     d |          S rb   rZ   rc   s     r   rd   z?SafeExceptionReporterFilter.cleanse_setting.<locals>.<listcomp>   s)    IIIad222q99IIIr   )r   SESSION_COOKIE_NAMEhidden_settingssearch	TypeErrorcleansed_substitute
isinstancedictitemslisttuplecallabler&   )r*   keyvalueis_sensitivecleanseds   `    r   r[   z+SafeExceptionReporterFilter.cleanse_settingu   s.   
 (...LL%#3::3?? % % %$%  		/HHt$$ 	PPPP%++--PPPHHt$$ 	CCCCUCCCHHu%% 	IIII5IIIJJHHHH 	8-h77Hs   1 A A c                     i }t          t                    D ]B}|                                r,|                     |t	          t          |                    ||<   C|S )z
        Return a dictionary of the settings module with values of sensitive
        settings replaced with stars (*********).
        )dirr   isupperr[   rH   )r*   settings_dictr^   s      r   get_safe_settingsz-SafeExceptionReporterFilter.get_safe_settings   s\    
 X 	Q 	QAyy{{ Q#'#7#778Q;O;O#P#Pa r   c                 r     t          |d          si S  fd|j                                        D             S )zU
        Return a dictionary of request.META with sensitive values redacted.
        METAc                 D    i | ]\  }}|                     ||          S r$   rZ   r\   s      r   r`   zESafeExceptionReporterFilter.get_safe_request_meta.<locals>.<dictcomp>   s/    OOO$!Q4''1--OOOr   )hasattrr{   rm   r*   r:   s   ` r   get_safe_request_metaz1SafeExceptionReporterFilter.get_safe_request_meta   sD     w'' 	IOOOO',:L:L:N:NOOOOr   c                 r     t          |d          si S  fd|j                                        D             S )zX
        Return a dictionary of request.COOKIES with sensitive values redacted.
        COOKIESc                 D    i | ]\  }}|                     ||          S r$   rZ   r\   s      r   r`   z@SafeExceptionReporterFilter.get_safe_cookies.<locals>.<dictcomp>   s/    RRR$!Q4''1--RRRr   )r}   r   rm   r~   s   ` r   get_safe_cookiesz,SafeExceptionReporterFilter.get_safe_cookies   sD     w	** 	IRRRR'/:O:O:Q:QRRRRr   c                     t           j        du S )a  
        This filter is to add safety in production environments (i.e. DEBUG
        is False). If DEBUG is True then your site is not safe anyway.
        This hook is provided as a convenience to easily activate or
        deactivate the filter on a per request basis.
        F)r   DEBUGr~   s     r   	is_activez%SafeExceptionReporterFilter.is_active   s     ~&&r   c                     t          |dg           }|                     |          r)|r'|                                }|D ]}||v r
| j        ||<   |S )z
        Replace the keys in a MultiValueDict marked as sensitive with stars.
        This mitigates leaking sensitive POST parameters if something like
        request.POST['nonexistent_key'] throws an exception (#21098).
        sensitive_post_parameters)rH   r   copyrj   )r*   r:   multivaluedictr   params        r   get_cleansed_multivaluedictz7SafeExceptionReporterFilter.get_cleansed_multivaluedict   sw     %,G5PRT$U$U!>>'"" 	E'@ 	E+0022N2 E EN**,0,DN5)r   c                     |i S t          |dg           }|                     |          rG|rE|j                                        }|dk    r|D ]}| j        ||<   |S |D ]}||v r
| j        ||<   |S |j        S )zk
        Replace the values of POST parameters marked as sensitive with
        stars (*********).
        Nr   __ALL__)rH   r   POSTr   rj   )r*   r:   r   rt   r^   r   s         r   get_post_parametersz/SafeExceptionReporterFilter.get_post_parameters   s    
 ?I(/4b) )% ~~g&& $+D $"<,,..,	99% ? ?&*&>#O "; G G H,,.2.FHUO#O|#r   c                     	 t          |t                    }n-# t          $ r }d                    ||          cY d }~S d }~ww xY w|r|                     ||          }|S )Nz{!r} while evaluating {!r})rk   r   	Exceptionformatr   )r*   r:   rr   is_multivalue_dictes        r   cleanse_special_typesz1SafeExceptionReporterFilter.cleanse_special_types   s    	A ",E>!B!B 	A 	A 	A/66q%@@@@@@@@	A  	E44WeDDEs    
A=AAc                    |j         }d}|A|j        j        dk    r(d|j        v r|j        d         }t	          |dd          }n	|j         }|Ai }|                     |          rd|rb|dk    r|j        D ]}| j        ||<   n|j                                        D ],\  }}||v r| j        }n|                     ||          }|||<   -n8|j                                        D ]\  }}|                     ||          ||<   |j        j        dk    rd|j        v r| j        |d<   | j        |d<   |                                S )ze
        Replace the values of variables marked as sensitive with
        stars (*********).
        Nsensitive_variables_wrappersensitive_variablesr   	func_argsfunc_kwargs)	f_backf_codeco_namef_localsrH   r   rj   rm   r   )	r*   r:   tb_framecurrent_framer   wrapperrt   r   rr   s	            r   get_traceback_frame_variablesz9SafeExceptionReporterFilter.get_traceback_frame_variables   s    !"'$,0MMM1]5KKK (01NO&-g7Ld&S&S#)0M ' >>'"" 	L': 	L"i//$- > >D%)%=HTNN> $,#4#:#:#<#< + +KD%222 $ 8 $ : :7E J J%*HTNN+  (06688 L Le!%!;!;GU!K!K O#'DDD-1BBB %)$<H[!&*&>H]#~~r   N)r!   r"   r#   r1   rj   r   reIrg   r[   ry   r   r   r   r   r   r   r   r$   r   r   rV   rV   j   s         
 1&&9  O  :	 	 	P P PS S S' ' '  $ $ $6  4  4  4  4  4 r   rV   c                       e Zd ZdZed             Zed             ZddZd Zd Z	d Z
d	 Zd
 Z	 ddZd Zd Zd ZdS )ExceptionReporterz0Organize and coordinate reporting on exceptions.c                      t          d          S )Nztechnical_500.htmlr   r/   s    r   html_template_pathz$ExceptionReporter.html_template_path'  s    $%9:::r   c                      t          d          S )Nztechnical_500.txtr   r/   s    r   text_template_pathz$ExceptionReporter.text_template_path+  s    $%8999r   Fc                     || _         t          | j                   | _        || _        || _        || _        || _        t          | j        dd           | _        d| _	        d | _
        d S )Ntemplate_debugF)r:   rJ   filterr;   r<   r=   is_emailrH   template_infotemplate_does_not_exist
postmortem)r*   r:   r;   r<   r=   r   s         r   r,   zExceptionReporter.__init__/  s`    3DLAA " $T^5EtLL',$r   c                     d                     | j        j        | j                                        | j                                                  S )z
        Return an absolute URI from variables available in this request. Skip
        allowed hosts protection, so may return insecure URI.
        z{scheme}://{host}{path})schemehostrR   )r   r:   r   _get_raw_hostget_full_pathr/   s    r   _get_raw_insecure_uriz'ExceptionReporter._get_raw_insecure_uri;  sK    
 )//<&++--++-- 0 
 
 	
r   c           
         | j         r:t          | j         t                    r d| _        | j        j        p| j        g| _        |                                 }t          |          D ]x\  }}d|v rjg }|d         D ]Z\  }}t          |          }t          |          dk    rd|dd         t          |          fz  }|                    ||f           [||d<   |||<   yd}| j         rt          | j         t                    rt          | j        dd          }t          | j        d	d          }	|]|	[| j        j        d
         }
t          |
t!          |dz
  d          t#          |	dz   t          |
                             dd          }ddlm} | j        d}n-	 t+          | j        j                  }n# t.          $ r d}Y nw xY wi d| j        d|d|d| j        d| j                            | j                  d| j                            | j                                                  d|dt;          | j                            | j                                                            d| j                                        dt@          j!        ddt@          j"        dd         z  dtG          j$                    d |            d t@          j%        d!| j&        d"| j        d#| j        }| j        p| j        j'                                        |d$<   | j        j(                                        |d%<   | )                                |d&<   tU          | j                  |d'<   | j         r| j         j+        |d(<   | j        rJt+          | j                  |d)<   t          | j        d*d          x}rd+d+,                    |          z   |d,<   |r|d-         |d.<   |S )/z5Return a dictionary containing traceback information.Tvarsi   u   %s… <trimmed %d bytes string>r   rP   startNend      asciireplace)errors)get_versionz%[unable to retrieve the current user]r   unicode_hintframesr:   request_metarequest_COOKIES_itemsuser_strfiltered_POST_itemsr   sys_executablesys_version_infoz%d.%d.%d   server_timedjango_version_infosys_pathr   r   r   request_GET_itemsrequest_FILES_itemsrequest_insecure_uriraising_view_nameexception_typeexception_value	__notes__
exception_notes	lastframe)-r;   
issubclassr
   r   r<   chainr   get_traceback_frames	enumerater   lenappendUnicodeErrorrH   argsr   maxmindjangor   r:   struserr   r   r   r   r   rm   rn   r   ry   sys
executableversion_infor   nowrR   r   GETFILESr   rT   r!   join)r*   r   iframe
frame_varsr^   r_   r   r   r   unicode_strr   r   c	exc_notess                  r   get_traceback_dataz$ExceptionReporter.get_traceback_dataF  sm   = 	GZ7KLL 	G+/D("n2Ft~6FDO**,,!&)) 
	 
	HAu
!&M . .DAqq		A1vv}}=1T6CPQFF@SS%%q!f---- *fF1II= 		Z|DD 		DNGT::E$.%66C S_"n1!4(EAIq 1 1Ca[AQAQ4R4R RS$     
 	'&&&&&<HHCt|011 C C C CC


L
 f
 t|	

 DK==dlKK
 $T[%A%A$,%O%O%U%U%W%W
 
 "4//==CCEE$ $
 5577
 cn
 
S-=ac-B B
 8<>>
 ";;==
  !
" T/#
$ &t'C%
& $/'
* <#%)\%5%;%;%=%=A!"'+|'9'?'?'A'AA#$(,(B(B(D(DA$%%/%=%=A!" = 	9"&-"8A> 	C#&t~#6#6A #DNKFFFy C'+dii	.B.B'B#$ 	(#BZAkNs   F7 7GGc                 0   | j                             d          5 }t                              |                                          }ddd           n# 1 swxY w Y   t          |                                 d          }|                    |          S )z1Return HTML version of debug 500 HTTP error page.utf-8encodingNF)use_l10n)r   openDEBUG_ENGINEfrom_stringreadr   r   renderr*   fhtr   s       r   r8   z$ExceptionReporter.get_traceback_html  s    $))7);; 	4r((33A	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4D++-->>>xx{{   -AAAc                 2   | j                             d          5 }t                              |                                          }ddd           n# 1 swxY w Y   t          |                                 dd          }|                    |          S )z7Return plain text version of debug 500 HTTP error page.r   r   NF)
autoescaper   )r   r   r   r   r   r   r   r   r   s       r   r9   z$ExceptionReporter.get_traceback_text  s    $))7);; 	4r((33A	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4 	4D++--%%PPPxx{{r  c                 h   d }t          |d          r=	 |                    |          }n# t          $ r Y nw xY w||                                }|`	 t	          |d          5 }|                                                                }d d d            n# 1 swxY w Y   n# t          $ r Y nw xY w|S )N
get_sourcerb)r}   r  ImportError
splitlinesr   r   OSError)r*   filenameloadermodule_namesourcefps         r   _get_sourcezExceptionReporter._get_source  s   6<(( 	-**;77   !**,,>(D)) 4RWWYY1133F4 4 4 4 4 4 4 4 4 4 4 4 4 4 4   sB   * 
77B" #'B
B" BB" BB" "
B/.B/Nc                    |                      |||          }|dg dg fS t          |d         t                    rQd|dd         D ]6}t          j        d|          }|r|d                             d           n7fd|D             }t          d||z
            }	||z   }
	 ||	|         }||         }||dz   |
         }n# t          $ r	 dg dg fcY S w xY w|	|||fS )z
        Return context_lines before and after lineno from file.
        Return (pre_context_lineno, pre_context, context_line, post_context).
        Nr   r      s   coding[:=]\s*([-\w.]+)r   c                 2    g | ]}t          |d           S )r   )r   )r]   sliner   s     r   rd   z:ExceptionReporter._get_lines_from_file.<locals>.<listcomp>  s%    JJJ%c%955JJJr   )r  rk   bytesr   rh   decoder   
IndexError)r*   r  linenocontext_linesr  r  r  linematchlower_boundupper_boundpre_contextcontext_linepost_contextr   s                 @r   _get_lines_from_filez&ExceptionReporter._get_lines_from_file  sK    !!(FK@@>T2%%
 fQi'' 		KHrr
   	"<dCC $Qxw77HE KJJJ6JJJF!Vm344},	& V!34K!&>L!&1*{":;LL 	& 	& 	&T2%%%%	&K|CCs   &C CCc                 x    t          |dd           }t          |dd           }t          |dd           }|p|rd n|S )N	__cause____suppress_context____context__)rH   )r*   r<   explicitsuppress_contextimplicits        r   _get_explicit_or_implicit_causez1ExceptionReporter._get_explicit_or_implicit_cause  sL    9k488"9.DdKK9mT::C$4BDD(Cr   c                    g }| j         }|rN|                    |           |                     |          }||v rt          j        d|z  t
                     n|Ng }|s|S |                                }|s| j        n|j        }	 |	                    | 
                    ||                     	 |                                }n# t          $ r Y nw xY w|j        }W|S )NzHCycle in the exception chain detected: exception '%s' encountered again.)r<   r   r*  warningswarnr    popr=   __traceback__extendget_exception_traceback_framesr  )r*   
exceptionsr<   r   r=   s        r   r   z&ExceptionReporter.get_traceback_frames  s$   
N	 
	i(((<<YGGIJ&&)+45)     
	  	M NN$$	&CTWWI,C	)MM$==iLLMMM&NN,,		   (B	) s   /C 
CCc              #   h  K   |                      |          }t          |dd          }|	||d ddV  ||j        j                            d          r|j        }*|j        j        j        }|j        j        j        }|j	        dz
  }|j        j
                            d          }|j        j
                            d          pd	}	|                     ||d
||	          \  }
}}}|
|}
g }d}g }d	x}}t          rt          t          j        |j        j                                        |j        dz  d                     \  }}}}|rz|rxd||z
  z  }d|t%          t'          |dz                       z   dz   z  }d| | }dd|z   t%          |          t%          |                                          z
  z
  z  }d| | }||||	                    d          rdnd|||dz   | j                            | j        |j                  t3          |          ||||
dz   ||dV  |j        }|d S d S )Nr$  Tr   )	exc_causeexc_cause_explicitr=   type__traceback_hide__r   
__loader__r!   rP      z<source code not available>r  ^ r      zdjango.r   )r4  r5  r=   r6  r  functionr  r   idr  r   r!  pre_context_linenocolnotb_area_colno)r*  rH   r   r   gettb_nextr   co_filenamer   	tb_lineno	f_globalsr"  r   next	itertoolsisliceco_positionstb_lastir   r   lstrip
startswithr   r   r:   r>  )r*   r<   r=   r4  r5  r  r=  r  r  r  r?  r  r   r!  r@  rA  _start_column
end_column	underlinespacestb_area_spacess                         r   r1  z0ExceptionReporter.get_exception_traceback_frames   s     88CC	$YTBB:&&8	     n {#''(<== Z{)5H{)1H\A%F[*..|<<F+/33J??E2K )) " ")%+" <!$&&EM E15$*77992;!;KT 2 2.1lJ
   	EJ 	E #zL'@ AI L3s6A:3G3G$G!$KLF4444E%(&'|,,s<3F3F3H3H/I/IIK&N
 %E$D$D$DM&&8$/$:$:9$E$EQ6$$ 1*AAL"+  ff* , ,&81&<!.#    & BC nnnnnr   )F)NN)r!   r"   r#   r1   propertyr   r   r,   r   r   r8   r9   r  r"  r*  r   r1  r$   r   r   r   r   $  s       ::; ; X; : : X:
 
 
 
	
 	
 	
N N N`      $ IM"D "D "D "DHD D D  BK K K K Kr   r   c                 z   	 |j         d         d         }n,# t          t          t          f$ r | j        dd         }Y nw xY w	 |j         d         d         }d}|r}| j        dk    rt          |          dk    rnt          |d                   dk    rUt          |d         d         dd	          t          |d         d         d
d	          cxk    rdk    rn nDt          |           S n4# t          t          t          f$ r d}| j	        r| j	        j
        nd}Y nw xY wt          | dt          j                  }t          |t          j                  r|j        }t#          d                              d          5 }t&                              |                                          }ddd           n# 1 swxY w Y   t-                      }t/          |t          j        |||t1          |          | |                                t5          |           d	          }	t7          |                    |	                    S )zBCreate a technical 404 error response. `exception` is the Http404.r   rR   r   NtriedF/app_namerP   	namespaceadminTurlconfztechnical_404.htmlr   r   )	r[  root_urlconfrequest_pathurlpatternsresolvedreasonr:   r   r   )r   r  ri   KeyError	path_inforR   r   rH   default_urlconfrQ   rV  r   ROOT_URLCONFrk   types
ModuleTyper!   r   r   r   r   r   rE   r   r   ry   rT   r   r   )
r:   	exception	error_urlrV  r_  r[  r  r  reporter_filterr   s
             r   technical_404_responserj  N  s   *N1%f-			8, * * *%abb)			*,q!'*
  	,LCE

aE!H""aZ44uQx{K44        #7+++ 	8, Q Q Q070FP&,,DQ gy(*?@@G'5+,, #"	3	4	4	9	97	9	K	K 0r$$RWWYY//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;==O$1%  )nn'99;;!+G!4!4
	
 
	
	 	A  ,,,s0    &??C' '.DD:-F33F7:F7c                 N   t          d                              d          5 }t                              |                                          }ddd           n# 1 swxY w Y   t          dt                      i          }t          |                    |                    S )z+Create an empty URLconf 404 error response.zdefault_urlconf.htmlr   r   Nversion)	r   r   r   r   r   r   r   r   r   )r:   r  r  r   s       r   rc  rc  }  s    	5	6	6	;	;W	;	M	M 0QS$$RWWYY//0 0 0 0 0 0 0 0 0 0 0 0 0 0 0'))	
	 	A $$$s   -AA!$A!)r2   )2	functoolsrH  r   r   re  r,  pathlibr   django.confr   django.httpr   r   r   django.templater   r	   r
   django.template.defaultfiltersr   django.urlsr   django.utilsr   django.utils.datastructuresr   django.utils.encodingr   django.utils.module_loadingr   django.utils.regex_helperr   django.utils.versionr   r   r   r   UserWarningr    r&   rB   	lru_cacherE   rJ   r6   rT   rV   r   rj  rc  r$   r   r   <module>r|     s           				 



                     C C C C C C C C C C A A A A A A A A A A 1 1 1 1 1 1       ! ! ! ! ! ! 6 6 6 6 6 6 + + + + + + 5 5 5 5 5 5 6 6 6 6 6 6 8 8 8 8 8 8 8 8 v
12  6 6 6	 	 	 	 	K 	 	 	# # # # # # # #
 
 
 
  G G G
I I I
  G G Gw  w  w  w  w  w  w  w tg g g g g g g gT	,- ,- ,-^
% 
% 
% 
% 
%r   