3
¥Yði(  ã               @   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ejdœdd„Zeddœdd„Zd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   ú3/tmp/pip-build-8om4l6ph/flask/flask/debughelpers.pyr   
   s   r   c               @   s    e Zd ZdZdd„ Zdd„ ZdS )ÚDebugFilesKeyErrorz•Raised 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 j|ƒ}d|›d|j›d�g}|rJdjdd„ |D ƒƒ}|jd|› �ƒ dj|ƒ| _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 )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 )ÚFormDataRoutingRedirectzÎThis 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jdƒd krD|jdƒ |jd|j› d	�ƒ |jd
ƒ tj| dj	|ƒj
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 )z¨Since 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                sL   yˆ j | |ƒS  tk
rF } z|ˆjkr*‚ tˆ|ƒ|‚W Y d d }~X nX d S )N)Ú__getitem__ÚKeyErrorr   r   )r   r   Úe)Úoldclsr   r   r   r-   S   s    
z:attach_enctype_error_multidict.<locals>.newcls.__getitem__N)r   r	   r
   r-   r   )r0   r   r   r   ÚnewclsR   s   r1   N)ÚfilesÚ	__class__r   r	   )r   r1   r   )r0   r   r   Úattach_enctype_error_multidictK   s
    
r4   )Úreturnc             c   sº   dt | ƒj› dt | ƒj› �V  x–t| jjƒ ƒD ]„\}}|jdƒrBq.t|tt	fƒrŽt
dd„ |D ƒƒsdq.|› d�V  x|D ]}d|› �V  qvW q.nt|ttttfƒs¢q.|› d|›�V  q.W d S )	Nzclass: r"   Ú_c             s   s   | ]}t |tƒV  qd S )N)Ú
isinstanceÚstr)r   r   r   r   r   r   g   s    z$_dump_loader_info.<locals>.<genexpr>ú:z  - z: )Útyper	   r   ÚsortedÚ__dict__ÚitemsÚ
startswithr7   ÚtupleÚlistÚallr8   ÚintÚfloatÚbool)Úloaderr   ÚvalueÚitemr   r   r   Ú_dump_loader_infoa   s    

rH   )Úappr5   c             C   sŽ  d|›d�g}d}d}t j}|dk	r8|jjdk	r8|jj}xÒt|ƒD ]Æ\}\}}	}
t|	tƒrhd|	j›�}n*t|	tƒrŠd|	j	›d|	j› d�}nt
|	ƒ}|j|d	 d
›d|› �ƒ x t|ƒD ]}|jd|› �ƒ q¶W |
dkrÜd}nd|
d	 pèd›d�}|d	7 }|jd|› �ƒ qBW d}|dk�r*|jdƒ d}n|d	k�rB|jdƒ d}|dk	�rx|�rx|jd|›d�ƒ |jdƒ |jdƒ | jjdj|ƒƒ dS )z2This should help developers understand what failedzLocating template r9   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Ú	enumerater7   r   Úimport_namer   Únamer   r   rH   ÚloggerÚinfor   )rI   ÚtemplateÚattemptsrS   Ztotal_foundrN   ZreqctxÚidxrE   ZsrcobjZtripleZsrc_infoÚlineZdetailZseems_fishyr   r   r   Ú!explain_template_loading_attemptsr   sB    







rX   c               C   s$   t jjdƒdkr ttdƒdd� d S )NZWERKZEUG_RUN_MAINÚtruezÀSilently 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
    r`   )r\   ÚtypingÚtÚwarningsr   rI   r   Z
blueprintsr   Úglobalsr   r*   ÚUnicodeErrorr   r.   r   r!   r4   Ú	GeneratorrH   rX   r`   r   r   r   r   Ú<module>   s    0