o
    'a(                     @   s   d dl Z d dlZ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eZG d	d
 d
eeZG dd deZdd ZdejfddZdeddfddZdddZdS )    N)warn   )Flask)	Blueprint)_request_ctx_stackc                   @   s   e Zd ZdZdS )UnexpectedUnicodeErrorzjRaised in places where we want some better error reporting for
    unexpected unicode or binary data.
    N)__name__
__module____qualname____doc__ r   r   `/home/rieder/labs.polsys.net/tools/diffstream/lib/python3.10/site-packages/flask/debughelpers.pyr   
   s    r   c                   @   s    e Zd ZdZdd Zdd ZdS )DebugFilesKeyErrorzRaised from request.files during debugging.  The idea is that it can
    provide a better error message than just a generic KeyError/BadRequest.
    c                 C   sZ   |j |}d|d|jdg}|r%ddd |D }|d|  d|| _d S )	NzYou tried to access the file zX in the request.files dictionary but it does not exist. The mimetype for the request is z instead of 'multipart/form-data' which means that no file contents were transmitted. To fix this error you should provide enctype="multipart/form-data" in your form.z, c                 s   s    | ]}t |V  qd S N)repr.0xr   r   r   	<genexpr>    s    z.DebugFilesKeyError.__init__.<locals>.<genexpr>zG

The browser instead transmitted some file names. This was submitted:  )formgetlistmimetypejoinappendmsg)selfrequestkeyZform_matchesbufnamesr   r   r   __init__   s   zDebugFilesKeyError.__init__c                 C   s   | j S r   )r   )r   r   r   r   __str__'   s   zDebugFilesKeyError.__str__N)r   r	   r
   r   r!   r"   r   r   r   r   r      s    r   c                   @   s   e Zd ZdZdd ZdS )FormDataRoutingRedirectzThis exception is raised by Flask in debug mode if it detects a
    redirect caused by the routing system when the request method is not
    GET, HEAD or OPTIONS.  Reasoning: form data will be dropped.
    c                 C   s~   |j }d|j d|jdg}|j d|jdd kr"|d |d|j d	 |d
 t| d	|
d d S )Nz A request was sent to this URL (zC) but a redirect was issued automatically by the routing system to ./?r   z  The URL was defined with a trailing slash so Flask will automatically redirect to the URL with the trailing slash if it was accessed without one.z"  Make sure to directly send your z-request to this URL since we can't make browsers or HTTP clients redirect with form data reliably or without user interaction.z3

Note: this exception is only raised in debug moder   zutf-8)Zrouting_exceptionurlnew_urlbase_urlsplitr   methodAssertionErrorr!   r   encode)r   r   excr   r   r   r   r!   1   s    

z FormDataRoutingRedirect.__init__N)r   r	   r
   r   r!   r   r   r   r   r#   +   s    r#   c                    s:   j j G  fddd } j|_ j|_|j _dS )zSince Flask 0.8 we're monkeypatching the files object in case a
    request is detected that does not use multipart form data but the files
    object is accessed.
    c                       s   e Zd Z fddZdS )z.attach_enctype_error_multidict.<locals>.newclsc              
      s@   z  | |W S  ty } z|jvr t||d }~ww r   )__getitem__KeyErrorr   r   )r   r   eZoldclsr   r   r   r/   S   s   
z:attach_enctype_error_multidict.<locals>.newcls.__getitem__N)r   r	   r
   r/   r   r2   r   r   newclsR   s    r3   N)files	__class__r   r	   )r   r3   r   r2   r   attach_enctype_error_multidictK   s
   
r6   returnc                 c   s    dt | j dt | j V  t| j D ]?\}}|dr!qt|tt	frDt
dd |D s2q| dV  |D ]}d| V  q:qt|ttttfsNq| d|V  qd S )	Nzclass: r$   _c                 s   s    | ]}t |tV  qd S r   )
isinstancestrr   r   r   r   r   g   s    z$_dump_loader_info.<locals>.<genexpr>:z  - z: )typer	   r   sorted__dict__items
startswithr9   tuplelistallr:   intfloatbool)loaderr   valueitemr   r   r   _dump_loader_infoa   s    
rJ   appc                 C   s~  d|dg}d}d}t j}|dur|jjdur|jj}t|D ]a\}\}}	}
t|	tr3d|	j}nt|	trDd|	j	d|	j d}nt
|	}||d	 d
d|  t|D ]
}|d|  qY|
du rkd}nd|
d	 pqdd}|d	7 }|d|  q d}|dkr|d d}n|d	kr|d d}|dur|r|d|d |d |d | jd| dS )z2This should help developers understand what failedzLocating template r;   r   Nzapplication z
blueprint z ()r   5z: trying loader of z       zno matchzfound (z<string>z
       -> Fz'Error: the template could not be found.Tz<Warning: multiple loaders returned a match for the template.zL  The template was looked up from an endpoint that belongs to the blueprint r$   z9  Maybe you did not place a template in the right folder?z=  See https://flask.palletsprojects.com/blueprints/#templates
)r   topr   	blueprint	enumerater9   r   import_namer   namer   r   rJ   loggerinfor   )rK   templateZattemptsrU   Ztotal_foundrP   ZreqctxidxrG   srcobjZtripleZsrc_infolineZdetailZseems_fishyr   r   r   !explain_template_loading_attemptsr   sH   





rZ   c                   C   s(   t jddkrttddd d S d S )NZWERKZEUG_RUN_MAINtruezSilently ignoring app.run() because the application is run from the flask command line executable. Consider putting app.run() behind an if __name__ == "__main__" guard to silence this warning.   )
stacklevel)osenvirongetr   Warningr   r   r   r   explain_ignored_app_run   s   
rb   )r7   N)r^   typingtwarningsr   rK   r   Z
blueprintsr   globalsr   r,   UnicodeErrorr   r0   r   r#   r6   	GeneratorrJ   rZ   rb   r   r   r   r   <module>   s     0