
    hS                        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  edddi      Z  ee!      jD                  Z# G d d      Z$ddZ% e jL                         d        Z'd Z(d Z) G d d      Z* G d d      Z+d Z,d Z-y)    N)Path)settings)Http404HttpResponseHttpResponseNotFound)ContextEngineTemplateDoesNotExist)pprint)resolve)timezone)MultiValueDict)	force_str)import_string)_lazy_re_compile)get_docs_versionTi18nzdjango.templatetags.i18n)debug	librariesc                       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     U/var/www/html/ranktracker/api/venv/lib/python3.12/site-packages/django/views/debug.py__init__zCallableSettingWrapper.__init__&   s	    (    c                 ,    t        | j                        S r   )reprr   )r   s    r   __repr__zCallableSettingWrapper.__repr__)   s    DMM""r   N)__name__
__module____qualname____doc__r   r"    r   r   r   r      s    )#r   r   c                      t        |       | |||      }| j                  d      r|j                         }t        ||d      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.
    	text/html)statuscontent_typeztext/plain; charset=utf-8)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_responser8   -   sd    
 5+G4Wh	SUVH{#**,D;OO**,DC^__r   c                  >     t        t        j                               S r   )r   r   !DEFAULT_EXCEPTION_REPORTER_FILTERr'   r   r   %get_default_exception_reporter_filterr;   ;   s     E=CCDFFr   c                 0    t               }t        | d|      S )Nexception_reporter_filter)r;   getattr)r0   default_filters     r   get_exception_reporter_filterr@   A   s    :<N77HHr   c                 N    t        t        j                        }t        | d|      S )Nexception_reporter_class)r   r   DEFAULT_EXCEPTION_REPORTERr>   )r0    default_exception_reporter_classs     r   r,   r,   F   s$    '4X5X5X'Y$768XYYr   c                   l    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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)flagsc           	      &   	 | 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 c c}}w c c}w c c}w # t        $ r |}Y 5w xY w)z
        Cleanse an individual setting key/value of sensitive content. If the
        value is a dictionary, recursively cleanse the keys in that dictionary.
         )hidden_settingssearchcleansed_substitute
isinstancedictitemscleanse_settinglisttuple	TypeErrorcallabler   )r   keyvaluecleansedkvs         r   rP   z+SafeExceptionReporterFilter.cleanse_settingS   s    
	##**3/33E4(FKkkmTdaAt33Aq99TTE4(AFGAD00Q7GGE5) u!M!$"6"6r1"=!MN 
 H-h7H UG!M  	H	s<   AD C2*D C8D 7C=
D 2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   isupperrP   r>   )r   settings_dictrX   s      r   get_safe_settingsz-SafeExceptionReporterFilter.get_safe_settingsl   sM    
 X 	QAyy{#'#7#778Q;O#Pa 	Q 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)hasattrr`   rO   rP   )r   r0   rX   rY   s       r   get_safe_request_metaz1SafeExceptionReporterFilter.get_safe_request_metaw   sJ     w'I:A,,:L:L:NO$!Q4''1--OOOs   A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   r0   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)r>   re   copyrL   )r   r0   multivaluedictrg   params        r   get_cleansed_multivaluedictz7SafeExceptionReporterFilter.get_cleansed_multivaluedict   sc     %,G5PRT$U!>>'"'@+002N2 EN*,0,D,DN5)E 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 (*********).
        rg   __ALL__)r>   re   POSTrh   rL   )r   r0   rg   rW   rX   rj   s         r   get_post_parametersz/SafeExceptionReporterFilter.get_post_parameters   s    
 ?I(/9TVX(Y%~~g&+D"<<,,.,	9% ?&*&>&>?#O "; G H,.2.F.FHUOG $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})rM   r   	Exceptionformatrk   )r   r0   rV   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                    |j                   }d}|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 (*********).
        Nsensitive_variables_wrappersensitive_variablesrm   	func_argsfunc_kwargs)	f_backf_codeco_namef_localsr>   re   rL   rO   ru   )	r   r0   tb_framecurrent_framerx   wrapperrW   namerV   s	            r   get_traceback_frame_variablesz9SafeExceptionReporterFilter.get_traceback_frame_variables   s    !"'$$,,0MM1]5K5KK (001NO&-g7Ld&S#)00M ' >>'"':"i/$-- >D%)%=%=HTN> $,#4#4#:#:#< +KD%22 $ 8 8 $ : :7E J%*HTN+  (00668 Le!%!;!;GU!KL OO##'DD-1B1BB
 %)$<$<H[!&*&>&>H]#~~r   N)r#   r$   r%   r&   rL   r   reIrJ   rP   r^   rb   re   rk   ro   ru   r   r'   r   r   rF   rF   K   sL     1&'LTVTXTXYO2	P'$20 r   rF   c                   >    e Zd ZdZd
dZd Zd Zd Zd ZddZ	d	 Z
y)ExceptionReporterz0Organize and coordinate reporting on exceptions.c                     || _         t        | j                         | _        || _        || _        || _        || _        t        | j                  dd       | _        d| _	        d | _
        y )Ntemplate_debugF)r0   r@   filterr1   r2   r3   is_emailr>   template_infotemplate_does_not_exist
postmortem)r   r0   r1   r2   r3   r   s         r   r   zExceptionReporter.__init__   sZ    3DLLA " $T^^5EtL',$r   c           
      v   | 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|dt7        | j2                  j9                  | j(                        j;                               d| j2                  j=                         dt>        j@                  ddt>        jB                  dd z  dtE        jF                         d |       dt>        jH                  d | jJ                  d!| j                  d"| j                  }| j(                  u| j(                  jL                  j;                         |d#<   | j(                  jN                  j;                         |d$<   | j(                  jP                  j;                         |d%<   | j                   r| j                   jR                  |d&<   | j                  rt+        | j                        |d'<   |r|d(   |d)<   |S # t.        $ r d}Y w xY w)*z5Return a dictionary containing traceback information.Tvarsi   u   %s… <trimmed %d bytes string>r   rI   startNend      asciireplace)errors)get_versionz%[unable to retrieve the current user]r   unicode_hintframesr0   request_meta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_COOKIES_itemsexception_typeexception_value	lastframe)*r1   
issubclassr
   r   r2   chainr   get_traceback_frames	enumerater   lenappendUnicodeErrorr>   argsr   maxmindjangor   r0   struserrq   r   r   rb   rQ   ro   rO   r^   sys
executableversion_infor   nowpathr   GETFILESCOOKIESr#   )r   r   iframe
frame_varsrX   rY   r   r   r   unicode_strr   r   cs                 r   get_traceback_dataz$ExceptionReporter.get_traceback_data   s   ==Z7KL+/D("nn22Ft~~6FDO**,!&) 
	HAu
!&M .DAqq	A1v}=1TCPQF@SS%%q!f-. !+fF1I
	 ==Z|DDNNGT:E$..%6C S_"nn11!4(EAIq 1#cAgs;?O2PQI  	'<<HCt||001

L
 f
 t||	

 DKK==dllK
 
 "4(G(G(U([([(]#^
 557
 cnn
 
S-=-=a-B B
 8<<>
 ";=
 
 T//
 &t'C'C
  $//!
$ <<#%)\\%5%5%;%;%=A!"'+||'9'9'?'?'AA#$)-)=)=)C)C)EA%&=="&--"8"8A>>#&t~~#6A #BZAkNE  C CCs   N) )N87N8c                    t        t        dd      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.	templatesztechnical_500.htmlutf-8encodingNF)use_l10n	r   CURRENT_DIRopenDEBUG_ENGINEfrom_stringreadr   r   renderr   fhtr   s       r   r.   z$ExceptionReporter.get_traceback_htmlF  so    +{,@AFFPWFX 	4\^((3A	4D++->xx{	4 	4s   $A::Bc                    t        t        dd      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   ztechnical_500.txtr   r   NF)
autoescaper   r   r   s       r   r/   z$ExceptionReporter.get_traceback_textM  sp    +{,?@EEwEW 	4[]((3A	4D++-%%Pxx{	4 	4s   $A;;B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)ra   r   ImportError
splitlinesr   r   OSError)r   filenameloadermodule_namesourcefps         r   _get_sourcezExceptionReporter._get_sourceT  s    6<(**;7 !**,>(D) 4RWWY113F4 v  4   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   rM   bytesr   rK   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_filee  s   
 !!(FK@>T2%%
 fQi'Hr
  		"<dC$Qxw7H DJJ%c%95JFJ!Vm34},	& V4K!&>L!&1*[9L K|CC K  	&T2%%	&s   -B0B5 5CCc                 0   d }g }| j                   }|r!|j                  |        ||      }||v rn|r!g }|s|S |j                         }|s| j                  n|j                  }||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 }|j                   ||      t        |d	d
      ||
j!                  d      rdnd|||dz   | j"                  j%                  | j&                  |j
                        t)        |      ||||dz   d       |j                  s|r|j                         }|j                  }n|j                  }||S )Nc                 B    t        | dd       }t        | dd       }|xs |S )N	__cause____context__)r>   )r2   explicitimplicits      r   explicit_or_implicit_causezJExceptionReporter.get_traceback_frames.<locals>.explicit_or_implicit_cause  s)    y+t<Hy->H'x'r   __traceback_hide__r   
__loader__r#   rI      z<source code not available>r   Tzdjango.r   r   )	exc_causeexc_cause_explicitr3   typer   functionr   r   idr   r   r   pre_context_lineno)r2   r   popr3   __traceback__r   r~   gettb_nextr|   co_filenamer}   	tb_lineno	f_globalsr   r>   
startswithr   r   r0   r  )r   r   
exceptionsr2   r   r3   r   r  r   r   r   r  r   r   r   s                  r   r   z&ExceptionReporter.get_traceback_frames  s   	( 
NN	i(29=IJ&  M NN$	&TWWI,C,Cn {{##''(<=ZZ{{))55H{{))11H\\A%F[[**..|<F++//33J?E2KJNJcJc&!V[KG\< ")%+" <!MM7	B&-id&K$/$:$:9$E6$$ 1*AA$,,PRP[P[\f* , ,&81&< $ ::*&NN,	,,ZZS nV r   )F)NN)r#   r$   r%   r&   r   r   r.   r/   r   r   r   r'   r   r   r   r      s-    :
FP" DDDr   r   c                     	 |j                   d   d   }	 |j                   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                  }d}	 t        | j
                        }|j                   }t#        |d      r|j                  }n8t#        |d      r,t#        |j$                  d      r|j$                  j                  }t#        |d      r|j&                  }|d|}	 t+        t,        dd      j/                  d      5 }	t0        j3                  |	j5                               }
ddd       t7               }t9        |t        j                  ||t;        |      | |j=                         |d      }t?        
jA                  |      d      S # t        t        t        f$ r | j                  dd }Y 0w xY w# t        t        t        f$ r g }Y w xY w# t(        $ r Y w xY w# 1 sw Y   xY w)zBCreate a technical 404 error response. `exception` is the Http404.r   r   r   Ntried/app_namerI   	namespaceadminurlconfr#   	__class__r$   .r   ztechnical_404.htmlr   r   )r  root_urlconfrequest_pathurlpatternsreasonr0   r   raising_view_namer)   r+   )!r   r   rS   KeyError	path_infor   r   r>   default_urlconfr   ROOT_URLCONFrM   types
ModuleTyper#   r   funcra   r  r$   r   r   r   r   r   r   r   r;   r   r   r^   r   r   )r0   	exception	error_urlr  r  callerresolver_matchobjmoduler   r   reporter_filterr   s                r   technical_404_responser*    sQ   *NN1%f-	,q!'* LLCJ!OaMQE!HQKR0GE!HQKVX4Yd]dd"7++ e"7++gy(*?*?@G'5++,""F0 . !!3
#\\FS+&73==*+M]]++F3%^^F &/F	k;(<	=	B	BG	B	T 0XZ$$RWWY/0;=O --!i.#557#	 		A  +FFe 	8, *%%ab)	*
 	8, $  0 0s@   H I  I% $I4#III"!I"%	I10I14I=c                    t        t        dd      j                  d      5 }t        j	                  |j                               }ddd       t        dt               i      }t        j                  |      d      S # 1 sw Y   :xY w)	z+Create an empty URLconf 404 error response.r   zdefault_urlconf.htmlr   r   Nversionr)   r  )
r   r   r   r   r   r   r   r   r   r   )r0   r   r   r   s       r   r  r    sz    	k;(>	?	D	Dg	D	V 0Z\$$RWWY/0#% 	A +>>0 0s   $A??B)i  ).	functoolsr   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   __file__parentr   r   r8   	lru_cacher;   r@   r,   rF   r   r*  r  r'   r   r   <module>r=     s     	 
     C C A A 1  ! 6 + 5 6 1 
12
 8n### #` G G
I
Z
b  b J[ [|6Gr?r   