o
    >h1                     @   sT   d dl mZ d dlmZ d dlmZ d dlmZ G dd deZ	G dd deZ
d	S )
    )
HTMLParser)gettext_lazy)Panel)is_processable_html_responsec                       s0   e Zd ZdZ fddZdd Zdd Z  ZS )
FormParserzh
    HTML form parser, used to check for invalid configurations of forms that
    take file inputs.
    c                    s,   t    d| _i | _g | _g | _g | _d S )NF)super__init__in_formcurrent_formformsform_idsreferenced_file_inputs)self	__class__ {/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/debug_toolbar/panels/alerts.pyr      s   

zFormParser.__init__c                 C   s   t |}|dkr!d| _|d}|r| j| d|g d| _d S | jrB|dkrB|ddkrB|dr;|dd	krBd| jd
< d S | jrj|dkrP|ddv sT|dkrj|dr`|dd	krj| jd | d S |dkr{|dr}| j| d S d S d S )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_idr   r   r   handle_starttag   s:   
zFormParser.handle_starttagc                 C   s.   |dkr| j r| j| j d| _ d S d S d S )Nr   F)r	   r   r!   r
   )r   r"   r   r   r   handle_endtag6   s   
zFormParser.handle_endtag)__name__
__module____qualname____doc__r   r%   r&   __classcell__r   r   r   r   r   	   s
    r   c                       sl   e Zd ZdZedededdZedZdZdZ fd	d
Z	e
dd Zdd Zdd Zdd Z  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AlertsTz debug_toolbar/panels/alerts.htmlc                    s   t  j|i | g | _d S N)r   r   alerts)r   argskwargsr   r   r   r   S   s   
zAlertsPanel.__init__c                 C   s<   |   d }rt|dkrdnd}t| d| S dS )Nr2      alert r   )	get_statsr    len)r   r2   
alert_textr   r   r   nav_subtitleW   s   zAlertsPanel.nav_subtitlec                 C   s   | j | d S r1   )r2   r!   )r   r6   r   r   r   	add_alert_   s   zAlertsPanel.add_alertc           	      C   s  t  }|| |jD ]9}|d rD|d ddkrDtdd |d D sD|d d }r8| jd	 j|d
}n| jd }| d|i qdd |jD }|jD ].}|d}|r~|ddkr~||}|r~|ddkr~| jd j|d
}| d|i qP| j	S )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                 s   s    | ]
}| d dkV  qdS )formenctyper>   Nr    ).0elemr   r   r   	<genexpr>q   s
    
zDAlertsPanel.check_invalid_file_form_configuration.<locals>.<genexpr>r   r   r-   )r$   r.   r6   c                 S   s    i | ]}|d   d|d  qS )r   r   r@   )rA   r   r   r   r   
<dictcomp>   s    zEAlertsPanel.check_invalid_file_form_configuration.<locals>.<dictcomp>r   r   r   r/   )
r   feedr   r    anymessagesformatr<   r   r2   )	r   html_contentparserr   r$   r6   form_attrs_by_idr#   r   r   r   r   %check_invalid_file_form_configurationb   s>   







z1AlertsPanel.check_invalid_file_form_configurationc                 C   s8   t |sd S |j|j}| | | d| ji d S )Nr2   )r   contentdecodecharsetrL   record_statsr2   )r   requestresponserI   r   r   r   generate_stats   s
   
zAlertsPanel.generate_stats)r'   r(   r)   r*   _rG   titleis_asynctemplater   propertyr;   r<   rL   rS   r+   r   r   r   r   r,   <   s*    
-r,   N)html.parserr   django.utils.translationr   rT   debug_toolbar.panelsr   debug_toolbar.utilsr   r   r,   r   r   r   r   <module>   s    3