B
    ;=[O                 @   s   d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ G d	d
 d
eeZeG dd deeZG dd deZdd Zdd Zdd Zdd ZdS )u   
    flask.debughelpers
    ~~~~~~~~~~~~~~~~~~

    Various helpers to make the development experience better.

    :copyright: © 2010 by the Pallets team.
    :license: BSD, see LICENSE for more details.
    N)warn   )implements_to_string	text_type)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   1lib/python3.7/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   sN   |j |}d||jf g}|r>|dddd |D   d|| _d S )Na%  You tried to access the file "%s" in the request.files dictionary but it does not exist.  The mimetype for the request is "%s" 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.zI

The browser instead transmitted some file names. This was submitted: %sz, c             s   s   | ]}d | V  qdS )z"%s"Nr   ).0xr   r   r   	<genexpr>+   s   z.DebugFilesKeyError.__init__.<locals>.<genexpr> )formZgetlistZmimetypeappendjoinmsg)selfrequestkeyZform_matchesbufr   r   r   __init__!   s    
zDebugFilesKeyError.__init__c             C   s   | j S )N)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   sr   |j }d|j|jf g}|jd |jdd kr<|d |d|j  |d t| d	|
d	 d S )
NzjA request was sent to this URL (%s) but a redirect was issued automatically by the routing system to "%s"./?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 %s-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_exceptionZurlZnew_urlZbase_urlsplitr   methodAssertionErrorr   r   encode)r   r   excr   r   r   r   r   9   s    


z FormDataRoutingRedirect.__init__N)r
   r   r   r   r   r   r   r   r   r   3   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<   y  | |S  tk
r6   |jkr( t|Y nX d S )N)__getitem__KeyErrorr   r   )r   r   )oldclsr   r   r   r'   U   s    
z:attach_enctype_error_multidict.<locals>.newcls.__getitem__N)r
   r   r   r'   r   )r)   r   r   r   newclsT   s   r*   N)files	__class__r
   r   )r   r*   r   )r)   r   r   attach_enctype_error_multidictN   s
    r-   c             c   s   dt | jt | jf V  xt| j D ]\}}|dr>q*t|tt	frt
dd |D s`q*d| V  x|D ]}d| V  qpW q*nt|tttttfsq*d||f V  q*W d S )Nzclass: %s.%s_c             s   s   | ]}t |ttfV  qd S )N)
isinstancestrr   )r   r   r   r   r   r   g   s    z$_dump_loader_info.<locals>.<genexpr>z%s:z  - %sz%s: %r)typer   r
   sorted__dict__items
startswithr/   tuplelistallr0   r   intfloatbool)loaderr   valueitemr   r   r   _dump_loader_infoa   s    


r?   c             C   sr  d| g}d}d}t j}|dk	r4|jjdk	r4|jj}xt|D ]\}\}}	}
t|	trbd|	j }n$t|	tr~d|	j	|	jf }nt
|	}|d|d |f  xt|D ]}|d|  qW |
dkrd	}nd
|
d pd }|d7 }|d|  q>W d}|dkr|d d}n|dkr*|d d}|dk	r\|r\|d|  |d |d | jd| dS )z2This should help developers understand what failedzLocating template "%s":r   Nzapplication "%s"zblueprint "%s" (%s)z% 5d: trying loader of %sr   z	       %szno matchz
found (%r)z<string>z       -> %sFz'Error: the template could not be found.Tz<Warning: multiple loaders returned a match for the template.zQ  The template was looked up from an endpoint that belongs to the blueprint "%s".z9  Maybe you did not place a template in the right folder?z7  See http://flask.pocoo.org/docs/blueprints/#templates
)r   topr   	blueprint	enumerater/   r   Zimport_namer   namereprr   r?   Zloggerinfor   )apptemplateZattemptsrF   Ztotal_foundrB   Zreqctxidxr<   ZsrcobjZtripleZsrc_infolineZdetailZseems_fishyr   r   r   !explain_template_loading_attemptsr   sF    








rK   c               C   s$   t jddkr ttddd 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    rS   )r   rO   warningsr   Z_compatr   r   rG   r   Z
blueprintsr   globalsr   r$   UnicodeErrorr	   r(   r   r   r-   r?   rK   rS   r   r   r   r   <module>
   s   
0