ó
¹×-]c           @   sè   d  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 d d l	 m
 Z
 d d	 l m Z d
 e e f d „  ƒ  YZ e d e e f d „  ƒ  Yƒ Z d e f d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z d S(   s¨   
    flask.debughelpers
    ~~~~~~~~~~~~~~~~~~

    Various helpers to make the development experience better.

    :copyright: 2010 Pallets
    :license: BSD-3-Clause
iÿÿÿÿN(   t   warni   (   t   implements_to_string(   t	   text_type(   t   Flask(   t	   Blueprint(   t   _request_ctx_stackt   UnexpectedUnicodeErrorc           B   s   e  Z d  Z RS(   sj   Raised in places where we want some better error reporting for
    unexpected unicode or binary data.
    (   t   __name__t
   __module__t   __doc__(    (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyR      s   t   DebugFilesKeyErrorc           B   s    e  Z d  Z d „  Z d „  Z RS(   s•   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   sk   | j  j | ƒ } d | | j f g } | rU | j d d j d „  | Dƒ ƒ ƒ n  d j | ƒ |  _ d  S(   Ns%  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.sI   

The browser instead transmitted some file names. This was submitted: %ss   , c         s   s   |  ] } d  | Vq d S(   s   "%s"N(    (   t   .0t   x(    (    s1   lib/python2.7/site-packages/flask/debughelpers.pys	   <genexpr>.   s    t    (   t   formt   getlistt   mimetypet   appendt   joint   msg(   t   selft   requestt   keyt   form_matchest   buf(    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyt   __init__!   s    c         C   s   |  j  S(   N(   R   (   R   (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyt   __str__2   s    (   R   R   R	   R   R   (    (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyR
      s   	t   FormDataRoutingRedirectc           B   s   e  Z d  Z d „  Z RS(   sÎ   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 | j f g } | j d | j j d ƒ d k rU | j d ƒ n  | j d | j ƒ | j d ƒ t j |  d j	 | ƒ j
 d	 ƒ ƒ d  S(
   Nsj   A request was sent to this URL (%s) but a redirect was issued automatically by the routing system to "%s".t   /t   ?i    s“     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.s£     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.s3   

Note: this exception is only raised in debug modeR   s   utf-8(   t   routing_exceptiont   urlt   new_urlt   base_urlt   splitR   t   methodt   AssertionErrorR   R   t   encode(   R   R   t   excR   (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyR   <   s    	#
(   R   R   R	   R   (    (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyR   6   s   c            sS   ˆ j  j ‰  d ˆ  f ‡  ‡ f d †  ƒ  Y} ˆ  j | _ ˆ  j | _ | ˆ j  _ d S(   s¨   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.
    t   newclsc              s   e  Z ‡  ‡ f d  †  Z RS(   c            sP   y ˆ  j  |  | ƒ SWn5 t k
 rK | ˆ j k r9 ‚  n  t ˆ | ƒ ‚ n Xd  S(   N(   t   __getitem__t   KeyErrorR   R
   (   R   R   (   t   oldclsR   (    s1   lib/python2.7/site-packages/flask/debughelpers.pyR(   ^   s    (   R   R   R(   (    (   R*   R   (    s1   lib/python2.7/site-packages/flask/debughelpers.pyR'   ]   s   N(   t   filest	   __class__R   R   (   R   R'   (    (   R*   R   s1   lib/python2.7/site-packages/flask/debughelpers.pyt   attach_enctype_error_multidictV   s
    	c         c   sí   d t  |  ƒ j t  |  ƒ j f VxÅ t |  j j ƒ  ƒ D]® \ } } | j d ƒ rX q7 n  t | t t	 f ƒ r² t
 d „  | Dƒ ƒ s‰ q7 n  d | Vx | D] } d | Vq™ Wq7 n$ t | t t t t t f ƒ sÖ q7 n  d | | f Vq7 Wd  S(   Ns   class: %s.%st   _c         s   s$   |  ] } t  | t t f ƒ Vq d  S(   N(   t
   isinstancet   strR   (   R   R   (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pys	   <genexpr>q   s    s   %s:s     - %ss   %s: %r(   t   typeR   R   t   sortedt   __dict__t   itemst
   startswithR/   t   tuplet   listt   allR0   R   t   intt   floatt   bool(   t   loaderR   t   valuet   item(    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyt   _dump_loader_infok   s    !"	c         C   sö  d | g } d } d } t j } | d k	 rO | j j d k	 rO | j j } n  xý t | ƒ D]ï \ } \ } }	 }
 t |	 t ƒ r d |	 j } n4 t |	 t	 ƒ r¸ d |	 j
 |	 j f } n t |	 ƒ } | j d | d | f ƒ x% t | ƒ D] } | j d | ƒ qì W|
 d k rd } n d	 |
 d p,d
 } | d 7} | j d | ƒ q\ Wt } | d k rw| j d ƒ t } n" | d k r™| j d ƒ t } n  | d k	 rÙ| rÙ| j d | ƒ | j d ƒ | j d ƒ n  |  j j d j | ƒ ƒ d S(   s2   This should help developers understand what faileds   Locating template "%s":i    s   application "%s"s   blueprint "%s" (%s)s   % 5d: trying loader of %si   s	          %ss   no matchs
   found (%r)s   <string>s          -> %ss'   Error: the template could not be found.s<   Warning: multiple loaders returned a match for the template.sQ     The template was looked up from an endpoint that belongs to the blueprint "%s".s9     Maybe you did not place a template in the right folder?s7     See http://flask.pocoo.org/docs/blueprints/#templatess   
N(   t   NoneR   t   topR   t	   blueprintt	   enumerateR/   R   t   import_nameR   t   namet   reprR   R?   t   Falset   Truet   loggert   infoR   (   t   appt   templatet   attemptsRJ   t   total_foundRB   t   reqctxt   idxR<   t   srcobjt   triplet   src_infot   linet   detailt   seems_fishy(    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyt!   explain_template_loading_attempts|   sD    	"	
		c           C   s5   t  j j d ƒ d k r1 t t d ƒ d d ƒn  d  S(   Nt   WERKZEUG_RUN_MAINt   truesÁ   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.t
   stackleveli   (   t   ost   environt   getR    t   Warning(    (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyt   explain_ignored_app_run¬   s
    	(   R	   R[   t   warningsR    t   _compatR   R   RK   R   t
   blueprintsR   t   globalsR   R$   t   UnicodeErrorR   R)   R
   R   R-   R?   RW   R_   (    (    (    s1   lib/python2.7/site-packages/flask/debughelpers.pyt   <module>
   s    			0