
    g<d                        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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# d dl$m%Z%  edddi      Z&d Z' G d de(      Z) G d d      Z*d#dZ+e jX                  d        Z-d Z.d Z/d Z0 G d d      Z1 G d d       Z2d! Z3d" Z4y)$    N)Path)settings)Http404HttpResponseHttpResponseNotFound)ContextEngineTemplateDoesNotExist)pprint)resolve)timezone)MultiValueDict)	force_str)import_string)_lazy_re_compile)PY311get_docs_version)*coroutine_functions_to_sensitive_variablesT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    j/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/views/debug.pybuiltin_template_pathr   !   s     >  ;.55    c                       e Zd Zy)ExceptionCycleWarningN)__name__
__module____qualname__ r   r   r!   r!   +   s    r   r!   c                       e Zd ZdZd Zd Zy)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                     || _         y N)_wrapped)selfcallable_settings     r   __init__zCallableSettingWrapper.__init__7   s	    (r   c                 ,    t        | j                        S r)   )reprr*   r+   s    r   __repr__zCallableSettingWrapper.__repr__:   s    DMM""r   N)r"   r#   r$   __doc__r-   r1   r%   r   r   r'   r'   /   s    )#r   r'   c                      t        |       | |||      }| j                  d      r|j                         }t        ||      S |j	                         }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   >   sg    
 5+G4Wh	SUVH{#**,D55**,3N
 	
r   c                  >     t        t        j                               S r)   )r   r   !DEFAULT_EXCEPTION_REPORTER_FILTERr%   r   r   %get_default_exception_reporter_filterrE   N   s     E=CCDFFr   c                 0    t               }t        | d|      S )Nexception_reporter_filter)rE   getattr)r:   default_filters     r   get_exception_reporter_filterrJ   T   s    :<N77HHr   c                 N    t        t        j                        }t        | d|      S )Nexception_reporter_class)r   r   DEFAULT_EXCEPTION_REPORTERrH   )r:    default_exception_reporter_classs     r   r6   r6   Y   s.    '4++($ +-M r   c                     | j                   }|	 t        | j                        }|dS |j                  S # t        $ r Y w xY w)N )resolver_matchr   pathr   
_func_path)r:   rQ   s     r   
get_callerrT   b   sR    ++N	$W\\2N  '2F^-F-FF  		s   5 	A Ac                   r    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y)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           	      V   |t         j                  k(  rd}n	 | j                  j                  |      }|r| j
                  }nt        |t              r4|j                         D ci c]  \  }}|| j                  ||       }}}nlt        |t              r |D cg c]  }| j                  d|       }}n<t        |t              r*t        |D cg c]  }| j                  d|       c}      }n|}t        |      rt        |      }|S # t        $ r d}Y w xY wc c}}w c c}w c c}w )z
        Cleanse an individual setting key/value of sensitive content. If the
        value is a dictionary, recursively cleanse the keys in that dictionary.
        TFrP   )r   SESSION_COOKIE_NAMEhidden_settingssearch	TypeErrorcleansed_substitute
isinstancedictitemscleanse_settinglisttuplecallabler'   )r+   keyvalueis_sensitivecleansedkvs          r   ra   z+SafeExceptionReporterFilter.cleanse_settingw   s   
 (...L%#33::3? //Ht$BG++-P-$!Q4//155-HPt$=BCU,,R3UHCu%5I5ad222q95IJHHH-h7H#  %$% QCIs#   D
 %DD!D&
DDc                     i }t        t              D ]6  }|j                         s| j                  |t	        t        |            ||<   8 |S )z
        Return a dictionary of the settings module with values of sensitive
        settings replaced with stars (*********).
        )dirr   isupperra   rH   )r+   settings_dictri   s      r   get_safe_settingsz-SafeExceptionReporterFilter.get_safe_settings   sF    
 XAyy{#'#7#778Q;O#Pa   r   c           	          t        |d      si S |j                  j                         D ci c]  \  }}|| j                  ||       c}}S c c}}w )zU
        Return a dictionary of request.META with sensitive values redacted.
        META)hasattrrq   r`   ra   r+   r:   ri   rj   s       r   get_safe_request_metaz1SafeExceptionReporterFilter.get_safe_request_meta   sP     w'I:A,,:L:L:NO:N$!Q4''1--:NOOO   Ac           	          t        |d      si S |j                  j                         D ci c]  \  }}|| j                  ||       c}}S c c}}w )zX
        Return a dictionary of request.COOKIES with sensitive values redacted.
        COOKIES)rr   rw   r`   ra   rs   s       r   get_safe_cookiesz,SafeExceptionReporterFilter.get_safe_cookies   sP     w	*I:A//:O:O:QR:Q$!Q4''1--:QRRRru   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   DEBUG)r+   r:   s     r   	is_activez%SafeExceptionReporterFilter.is_active   s     ~~&&r   c                     t        |dg       }| j                  |      r-|r+|j                         }|D ]  }||v s| 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{   copyr]   )r+   r:   multivaluedictr}   params        r   get_cleansed_multivaluedictz7SafeExceptionReporterFilter.get_cleansed_multivaluedict   s\     %,G5PRT$U!>>'"'@+002N2N*,0,D,DN5) 3 r   c                 
   |i S t        |dg       }| j                  |      rV|rT|j                  j                         }|dk(  r|D ]  }| j                  ||<    |S |D ]  }||v s| j                  ||<    |S |j                  S )zk
        Replace the values of POST parameters marked as sensitive with
        stars (*********).
        r}   __ALL__)rH   r{   POSTr~   r]   )r+   r:   r}   rh   ri   r   s         r   get_post_parametersz/SafeExceptionReporterFilter.get_post_parameters   s    
 ?I(/4b)% ~~g&+D"<<,,.,	9%&*&>&> &#O "; H,.2.F.FHUO "; $O||#r   c                     	 t        |t              }|r| j	                  ||      }|S # t        $ r}dj                  ||      cY d }~S d }~ww xY w)Nz{!r} while evaluating {!r})r^   r   	Exceptionformatr   )r+   r:   rf   is_multivalue_dictes        r   cleanse_special_typesz1SafeExceptionReporterFilter.cleanse_special_types   sZ    	A ",E>!B 44WeDE  	A/66q%@@	As   ( 	AAAAc                    d}|j                   j                  t        j                  z  dk7  rg|j                   j                  dk7  rNt        |j                   j                   d|j                   j                         }t        j                  |d      }|W|}|S|j                   j                  dk(  r+d|j                  v r|j                  d   }t        |dd      }n|j                  }|Si }| j                  |      rs|rq|dk(  r!|j                  D ]  }| j                  ||<    n|j                  j                         D ]-  \  }}	||v r| j                  }	n| j!                  ||	      }	|	||<   / n7|j                  j                         D ]  \  }}	| j!                  ||	      ||<    |j                   j                  dk(  r,d|j                  v r| j                  |d<   | j                  |d<   |j                         S )	ze
        Replace the values of variables marked as sensitive with
        stars (*********).
        Nr   sensitive_variables_wrapper:sensitive_variablesr   	func_argsfunc_kwargs)f_codeco_flagsinspectCO_COROUTINEco_namehashco_filenameco_firstlinenor   getf_localsrH   f_backr{   r]   r`   r   )
r+   r:   tb_framer   re   current_framewrapperrh   r   rf   s
             r   get_traceback_frame_variablesz9SafeExceptionReporterFilter.get_traceback_frame_variables   s   
 # OO$$w';';;q@''+HH??../q1O1O0PQC #M"P"PT# & %M+!((004QQ59O9OO ,445RSG*1';PRV*W' - 4 4  + >>'"':"i/$--D%)%=%=HTN . $,#4#4#:#:#<KD%22 $ 8 8 $ : :7E J%*HTN $=  (00668e!%!;!;GU!K  9 OO##'DD-1B1BB %)$<$<H[!&*&>&>H]#~~r   N)r"   r#   r$   r2   r]   r   reIrZ   ra   ro   rt   rx   r{   r   r   r   r   r%   r   r   rV   rV   l   sR    
 1&9O:	PS'$6D r   rV   c                   r    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y
)ExceptionReporterz0Organize and coordinate reporting on exceptions.c                     t        d      S )Nztechnical_500.htmlr   r0   s    r   html_template_pathz$ExceptionReporter.html_template_path9  s    $%9::r   c                     t        d      S )Nztechnical_500.txtr   r0   s    r   text_template_pathz$ExceptionReporter.text_template_path=  s    $%899r   c                     || _         t        | j                         | _        || _        || _        || _        || _        t        | j                  dd       | _        d| _	        d | _
        y )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__A  sZ    3DLLA " $T^^5EtL',$r   c                     dj                  | j                  j                  | 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_pathr0   s    r   _get_raw_insecure_uriz'ExceptionReporter._get_raw_insecure_uriM  sI    
 )//<<&&++-++- 0 
 	
r   c           
      F   | j                   rKt        | j                   t              r1d| _        | j                  j
                  xs | j                  g| _        | j                         }t        |      D ]a  \  }}d|v rSg }|d   D ]D  \  }}t        |      }t        |      dkD  rd|dd t        |      fz  }|j                  ||f       F ||d<   |||<   c d}| j                   rt        | j                   t              rt        | j                  dd      }t        | j                  d	d      }	|O|	M| j                  j                  d
   }
t        |
t!        |dz
  d      t#        |	dz   t        |
             dd      }ddlm} | j(                  d}n 	 t+        | j(                  j,                        }i d| j0                  d|d|d| j(                  d| j2                  j5                  | j(                        d| j2                  j7                  | j(                        j9                         d|dt;        | j2                  j=                  | j(                        j9                               d| j2                  j?                         dt@        jB                  ddt@        jD                  dd z  dtG        jH                         d |       d t@        jJ                  d!| jL                  d"| j                  d#| j                  }| j(                  y| j(                  jN                  j9                         |d$<   | j(                  jP                  j9                         |d%<   | jS                         |d&<   tU        | j(                        |d'<   | j                   r| j                   jV                  |d(<   | j                  rHt+        | j                        |d)<   t        | j                  d*d      x}rd+d+jY                  |      z   |d,<   |r|d-   |d.<   |S # t.        $ r d}Y lw xY w)/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   rt   rx   r`   rb   r   ro   sys
executableversion_infor   nowrR   r   GETFILESr   rT   r"   join)r+   r   iframe
frame_varsri   rj   r   r   r   unicode_strr   r   c	exc_notess                  r   get_traceback_dataz$ExceptionReporter.get_traceback_dataX  s   ==Z7KL+/D("nn22Ft~~6FDO**,!&)HAu
!&MDAqq	A1v}=1TCPQF@SS%%q!f- * !+fF1I * ==Z|DDNNGT:E$..%6C S_"nn11!4(EAIq 1Ca[AQ4RS$ 
 	'<<HCt||001

L
 f
 t||	

 DKK==dllK
 $T[[%A%A$,,%O%U%U%W
 
 "4//=CCE$
 557
 cnn
 
S-=-=a-B B
 8<<>
 ";=
  !
" T//#
$ &t'C'C%
& $//'
* <<#%)\\%5%5%;%;%=A!"'+||'9'9'?'?'AA#$(,(B(B(DA$%%/%=A!" =="&--"8"8A>>#&t~~#6A #DNNKFFyF'+dii	.B'B#$#BZAkNS  C CCs   P P P c                    | j                   j                  d      5 }t        j                  |j	                               }ddd       t        | j                         d      }j                  |      S # 1 sw Y   5xY w)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  sb    $$))7);r((3A <D++->xx{ <;s   $A55A>c                    | j                   j                  d      5 }t        j                  |j	                               }ddd       t        | j                         dd      }j                  |      S # 1 sw Y   6xY w)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  sd    $$))7);r((3A <D++-%%Pxx{ <;s   $A66A?c                 2   d }t        |d      r$	 |j                  |      }||j                         }|6	 t	        |d      5 }|j                         j                         }d d d        |S |S # t        $ r Y Ww xY w# 1 sw Y   |S xY w# t        $ r Y |S w xY w)N
get_sourcerb)rr   r  ImportError
splitlinesr   r   OSError)r+   filenameloadermodule_namesourcefps         r   _get_sourcezExceptionReporter._get_source  s    6<(**;7 !**,>(D)RWWY113F * v   *   s@   A- B	 A<!B	 -	A98A9<BB	 B	 		BBNc                    | j                  |||      }|dg dg fS t        |d   t              rTd}|dd D ]0  }t        j                  d|      }	|	s|	d   j                  d      } n |D 
cg c]  }
t        |
|d       }}
t        d||z
        }||z   }	 ||| }||   }||dz   | }||||fS c c}
w # t        $ r	 dg dg fcY S w xY w)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   r   )	r  r^   bytesr   r[   decoder   r   
IndexError)r+   r  linenocontext_linesr	  r
  r  r   linematchslinelower_boundupper_boundpre_contextcontext_linepost_contexts                   r   _get_lines_from_filez&ExceptionReporter._get_lines_from_file  s    !!(FK@>T2%%
 fQi'Hr
 		"<dC$Qxw7H # DJJ6%c%956FJ!Vm34},	& V4K!&>L!&1*{;L K|CC K  	&T2%%	&s   -B0B5 5CCc                 d    t        |dd       }t        |dd       }t        |dd       }|xs |rd S |S )N	__cause____suppress_context____context__)rH   )r+   r<   explicitsuppress_contextimplicits        r   _get_explicit_or_implicit_causez1ExceptionReporter._get_explicit_or_implicit_cause  sA    9k48"9.DdK9mT:C$4DC(Cr   c                    g }| j                   }|rG|j                  |       | j                  |      }||v rt        j                  d|z  t
               n|rGg }|s|S |j                         }|s| j                  n|j                  }	 |j                  | j                  ||             	 |j                         }|j                  }?# t        $ r Y |S w xY w)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    
NN	i(<<YGIJ&)+45)   M NN$	&TWWI,C,CMM$==iLM&NN,	 ((B   s   +C 	CCc              #     K   | j                  |      }t        |dd      }|	||d dd |.|j                  j                  j	                  d      r|j
                  }5|j                  j                  j                  }|j                  j                  j                  }|j                  dz
  }|j                  j                  j	                  d      }|j                  j                  j	                  d      xs d	}	| j                  ||d
||	      \  }
}}}|
|}
g }d}g }d	x}}t        rt        t        j                  |j                  j                  j!                         |j"                  dz  d             \  }}}}|rf|rdd||z
  z  }d|t%        t'        |dz               z   dz   z  }d| | }dd|z   t%        |      t%        |j)                               z
  z
  z  }d| | }||||	j+                  d      rdnd|||dz   | j,                  j/                  | j0                  |j                        t3        |      ||||
dz   ||d |j
                  }|-y y w)Nr  Tr   )	exc_causeexc_cause_explicitr=   type__traceback_hide__r   
__loader__r"   rP      z<source code not available>r  ^ r      zdjango.r   )r/  r0  r=   r1  r  functionr  r   idr  r  r  pre_context_linenocolnotb_area_colno)r%  rH   r   r   r   tb_nextr   r   r   	tb_lineno	f_globalsr  r   next	itertoolsisliceco_positionstb_lastir   r   lstrip
startswithr   r   r:   r9  )r+   r<   r=   r/  r0  r  r8  r  r	  r
  r:  r  r  r  r;  r<  _start_column
end_column	underlinespacestb_area_spacess                         r   r,  z0ExceptionReporter.get_exception_traceback_frames  s    88C	$YTB:&&8	  n {{##''(<=ZZ{{))55H{{))11H\\A%F[[**..|<F++//33J?E2K ))" ")%+" <!$&&EM15$$**7792;;!;KT2.1lJ
  J #zL'@ AI L3s6A:3G$G!$KLF 4E%(&'|,s<3F3F3H/IIK&N
 ')(8$DM&&8$/$:$:9$E6$$ 1*AALL"++ f* , ,&81&<!.# & BC ns   III)F)NN)r"   r#   r$   r2   propertyr   r   r-   r   r   r8   r9   r  r  r%  r   r,  r%   r   r   r   r   6  sk    :; ; : :
	
N`$ IM"DHDBKr   r   c                    	 |j                   d   d   }	 |j                   d   d   }d}|rh| j
                  dk(  rdt        |      dk(  rVt        |d         dk(  rEt        |d   d   dd	      t        |d   d   d
d	      cxk(  rdk(  rt        |       S  nt        |       S t        | dt        j                        }t        |t        j                        r|j                   }t#        d      j%                  d      5 }t&        j)                  |j+                               }ddd       t-               }t/        |t        j                  |||t1        |      | |j3                         t5        |       d	      }	t7        j9                  |	            S # t        t        t        f$ r | j                  dd }Y w xY w# t        t        t        f$ r* d}| j                  r| j                  j                  nd}Y Vw xY w# 1 sw Y   xY w)zBCreate a technical 404 error response. `exception` is the Http404.r   rR   r   NtriedF/app_namerP   	namespaceadminTurlconfztechnical_404.htmlr   r   )	rT  root_urlconfrequest_pathurlpatternsresolvedreasonr:   r   r   )r   r  r\   KeyError	path_inforR   r   rH   default_urlconfrQ   rO  r   ROOT_URLCONFr^   types
ModuleTyper"   r   r   r   r   r   rE   r   r   ro   rT   r   r   )
r:   	exception	error_urlrO  rX  rT  r   r   reporter_filterr   s
             r   technical_404_responserc  `  s   *NN1%f-	,q!'*
 LLCE
aE!H"aZ4uQx{K4 #7++	 #7++gy(*?*?@G'5++,""	3	4	9	97	9	Kr$$RWWY/ 
L;=O$11%  )n'99;!+G!4
	
	A  ,,Q 	8, *%%ab)	*
 	8, Q070F0F&&,,DQ& 
L	Ks.   F F7 :$G8#F43F47:G54G58Hc                    t        d      j                  d      5 }t        j                  |j	                               }ddd       t        dt               i      }t        j                  |            S # 1 sw Y   8xY w)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   r\  r\    so    	5	6	;	;W	;	MQS$$RWWY/ 
N')	
	A $$ 
N	Ms   $A77B )i  )5	functoolsr   rA  r   r   r^  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   django.views.decorators.debugr   r   r   UserWarningr!   r'   rB   	lru_cacherE   rJ   r6   rT   rV   r   rc  r\  r%   r   r   <module>rv     s       	 
      C C A A 1  ! 6 + 5 6 8 T 
126	K 	# #
  G G
I
GG  G Tg gT	,-^
%r   