
    f                     `    d dl mZ d dlmZ d dlmZ d dlmZ  G d de      Z	 G d de      Z
y	)
    )
HTMLParser)gettext_lazy)Panel)is_processable_html_responsec                   .     e Zd ZdZ fdZd Zd Z xZS )
FormParserzh
    HTML form parser, used to check for invalid configurations of forms that
    take file inputs.
    c                 h    t         |           d| _        i | _        g | _        g | _        g | _        y )NF)super__init__in_formcurrent_formformsform_idsreferenced_file_inputs)self	__class__s    o/var/www/teaching_timetable/msuas_timetable/my_venv/lib/python3.12/site-packages/debug_toolbar/panels/alerts.pyr   zFormParser.__init__   s3    
&(#    c                    t        |      }|dk(  rAd| _        |j                  d      }|r| j                  j	                  |       d|g d| _        y | j                  rN|dk(  rI|j                  d      dk(  r5|j                  d      r|j                  d      d	k(  rd| j
                  d
<   y | j                  ra|dk(  r|j                  d      dv s|dk(  rD|j                  d      r|j                  d      d	k(  r| j
                  d   j	                  |       y |dk(  r.|j                  d      r| j                  j	                  |       y y y )NformTidF)	file_form
form_attrssubmit_element_attrsinputtypefile r   >   imagesubmitbuttonr   )dictr   getr   appendr   r   )r   tagattrsform_ids       r   handle_starttagzFormParser.handle_starttag   s$   U&=DLiioG$$W-"#(*!D LLw		&!V+YYv&%))F*;r*A-1Dk*LLEIIf$59L$L(?YYv&%))F*;r*A45<<UCG^		& 1''..u5 !2^r   c                     |dk(  r:| j                   r-| j                  j                  | j                         d| _         y y y )Nr   F)r   r   r$   r   )r   r%   s     r   handle_endtagzFormParser.handle_endtag6   s5    &=T\\JJd//0 DL *=r   )__name__
__module____qualname____doc__r   r(   r*   __classcell__r   s   @r   r   r   	   s    
)6>!r   r   c                        e Zd ZdZ ed       ed       ed      dZ ed      ZdZ fdZe	d	        Z
d
 Zd Zd Z xZS )AlertsPanelz+
    A panel to alert users to issues.
    zlForm with id "{form_id}" contains file input, but does not have the attribute enctype="multipart/form-data".zXForm contains file input, but does not have the attribute enctype="multipart/form-data".zzInput element references form with id "{form_id}", but the form does not have the attribute enctype="multipart/form-data".)form_id_missing_enctypeform_missing_enctypeinput_refs_form_missing_enctypeAlertsz debug_toolbar/panels/alerts.htmlc                 2    t        |   |i | g | _        y N)r
   r   alerts)r   argskwargsr   s      r   r   zAlertsPanel.__init__Q   s    $)&)r   c                     | j                         j                  d      x}r"t        |      dk(  rdnd}t        |       d| S y)Nr9      alert r   )	get_statsr#   len)r   r9   
alert_texts      r   nav_subtitlezAlertsPanel.nav_subtitleU   sI    ^^%))(3363$'K1$4(J&k]!J<00r   c                 :    | j                   j                  |       y r8   )r9   r$   )r   r>   s     r   	add_alertzAlertsPanel.add_alert]   s    5!r   c                    t               }|j                  |       |j                  D ]  }|d   s	|d   j                  d      dk7  s!t	        d |d   D              r7|d   j                  d      x}r | j
                  d   j                  |	      }n| j
                  d
   }| j                  d|i        |j                  D ci c]  }|d   j                  d      |d    }}|j                  D ]  }|j                  d      }|s|j                  d      dk(  s,|j                  |      }|s@|j                  d      dk7  sU| j
                  d   j                  |	      }| j                  d|i        | j                  S c c}w )z
        Inspects HTML content for a form that includes a file input but does
        not have the encoding type set to multipart/form-data, and warns the
        user if so.
        r   r   enctypemultipart/form-datac              3   D   K   | ]  }|j                  d       dk(    yw)formenctyperH   N)r#   ).0elems     r   	<genexpr>zDAlertsPanel.check_invalid_file_form_configuration.<locals>.<genexpr>o   s'       HH]+/DDs    r   r   r3   )r'   r4   r>   r   r   r   r5   )
r   feedr   r#   anymessagesformatrE   r   r9   )	r   html_contentparserr   r'   r>   form_attrs_by_idr&   r   s	            r   %check_invalid_file_form_configurationz1AlertsPanel.check_invalid_file_form_configuration`   s    L! LL 	1D[!&**959NN  $%; < 
 #<044T::7: MM*CDKK ' L E !MM*@AE/0	1& JP
AED""4($|*<<
 
 22 	5Eii'G599V,6-11':
*..";?T"T MM*KLSS ' T E NNGU#34	5 {{
s   F	c                     t        |      sy |j                  j                  |j                        }| j	                  |       | j                  d| j                  i       y )Nr9   )r   contentdecodecharsetrU   record_statsr9   )r   requestresponserR   s       r   generate_statszAlertsPanel.generate_stats   sP    +H5''..x/?/?@22<@
 	8T[[12r   )r+   r,   r-   r.   _rP   titletemplater   propertyrC   rE   rU   r]   r/   r0   s   @r   r2   r2   <   sr    
 $%z$
 !"f!
 ,- I,

H hKE1H  "+Z
3r   r2   N)html.parserr   django.utils.translationr   r^   debug_toolbar.panelsr   debug_toolbar.utilsr   r   r2    r   r   <module>rg      s,    " 6 & <0! 0!f[3% [3r   