ó
`¾Tc           @   sÌ   d  Z  d d l Z d d l Z d d l m Z m Z m Z m Z d d l m	 Z
 m Z d d l m Z m Z d d l m Z d d l m Z d d l m Z d	 e f d
 „  ƒ  YZ d e f d „  ƒ  YZ d S(   sÐ   
    werkzeug.debug
    ~~~~~~~~~~~~~~

    WSGI application traceback debugger.

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD, see LICENSE for more details.
iÿÿÿÿN(   t   joint   dirnamet   basenamet   isfile(   t   BaseRequestt   BaseResponse(   t   get_current_tracebackt   render_console_html(   t   Console(   t   gen_salt(   t
   debug_reprt   _ConsoleFramec           B   s   e  Z d  Z d „  Z RS(   s]   Helper class so that we can reuse the frame console code for the
    standalone console.
    c         C   s   t  | ƒ |  _ d |  _ d  S(   Ni    (   R   t   consolet   id(   t   selft	   namespace(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   __init__   s    (   t   __name__t
   __module__t   __doc__R   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyR      s   t   DebuggedApplicationc           B   sn   e  Z d  Z d Z e d d d e d d „ Z d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 „  Z d „  Z RS(   sÃ  Enables debugging support for a given application::

        from werkzeug.debug import DebuggedApplication
        from myapp import app
        app = DebuggedApplication(app, evalex=True)

    The `evalex` keyword argument allows evaluating expressions in a
    traceback's frame context.

    .. versionadded:: 0.9
       The `lodgeit_url` parameter was deprecated.

    :param app: the WSGI application to run debugged.
    :param evalex: enable exception evaluation feature (interactive
                   debugging).  This requires a non-forking server.
    :param request_key: The key that points to the request object in ths
                        environment.  This parameter is ignored in current
                        versions.
    :param console_path: the URL for a general purpose console.
    :param console_init_func: the function that is executed before starting
                              the general purpose console.  The return value
                              is used as initial namespace.
    :param show_hidden_frames: by default hidden traceback frames are skipped.
                               You can show them by setting this parameter
                               to `True`.
    t   werkzeugs   werkzeug.requests   /consolec   	      C   s™   | d  k	 r/ d d l m } | t d ƒ ƒ n  | s> t } n  | |  _ | |  _ i  |  _ i  |  _ | |  _	 | |  _
 | |  _ | |  _ t d ƒ |  _ d  S(   Niÿÿÿÿ(   t   warns   Werkzeug now pastes into gists.i   (   t   Nonet   warningsR   t   DeprecationWarningt   dictt   appt   evalext   framest
   tracebackst   request_keyt   console_patht   console_init_funct   show_hidden_framesR	   t   secret(	   R   R   R   R   R    R!   R"   t   lodgeit_urlR   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyR   B   s    									c         c   sJ  d } yH |  j | | ƒ } x | D] } | Vq" Wt | d ƒ rM | j ƒ  n  Wnõ t k
 rEt | d ƒ rz | j ƒ  n  t d d d |  j d t ƒ } x! | j D] } | |  j | j	 <q¢ W| |  j
 | j	 <y | d d d g ƒ Wn" t k
 r| d j d ƒ n* X| j d |  j d |  j ƒ j d d ƒ V| j | d ƒ n Xd S(   s6   Run the application and conserve the traceback frames.t   closet   skipi   R"   t   ignore_system_exceptionss   500 INTERNAL SERVER ERRORs   Content-Types   text/html; charset=utf-8s   X-XSS-Protectiont   0s   wsgi.errorssp   Debugging middleware caught exception in streamed response at a point where response headers were already sent.
R   R#   s   utf-8t   replaceN(   s   Content-Types   text/html; charset=utf-8(   s   X-XSS-ProtectionR(   (   R   R   t   hasattrR%   t	   ExceptionR   R"   t   TrueR   R   R   t   writet   render_fullR   R#   t   encodet   log(   R   t   environt   start_responset   app_itert   itemt	   tracebackt   frame(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   debug_applicationT   s6    			
c         C   s   t  | j j | ƒ d d ƒS(   s   Execute a command in a console.t   mimetypes	   text/html(   t   ResponseR   t   eval(   R   t   requestt   commandR6   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   execute_command~   s    c         C   sG   d |  j  k r+ t |  j ƒ  ƒ |  j  d <n  t t d |  j ƒ d d ƒS(   s   Display a standalone shell.i    R#   R8   s	   text/html(   R   R   R!   R9   R   R#   (   R   R;   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   display_console‚   s    c         C   s%   | j  ƒ  } t t j | ƒ d d ƒS(   s/   Paste the traceback and return a JSON response.R8   s   application/json(   t   pasteR9   t   jsont   dumps(   R   R;   R5   t   rv(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   paste_traceback‰   s    c         C   s   t  | j ƒ  d d ƒS(   s   Render the source viewer.R8   s	   text/html(   R9   t   render_source(   R   R;   R6   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt
   get_sourceŽ   s    c         C   s   t  t t ƒ d t | ƒ ƒ } t | ƒ r} t j | ƒ d p@ d } t | d ƒ } z t | j	 ƒ  d | ƒSWd | j
 ƒ  Xn  t d d d	 ƒS(
   s0   Return a static resource from the shared folder.t   sharedi    s   application/octet-streamt   rbR8   Ns	   Not Foundt   statusi”  (   R    R   t   __file__R   R   t	   mimetypest
   guess_typet   openR9   t   readR%   (   R   R;   t   filenameR8   t   f(    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   get_resource’   s    c   
      C   sØ  t  | ƒ } |  j } | j j d ƒ d k r| j j d ƒ } | j j d ƒ } | j j d ƒ } |  j j | j j d d t ƒƒ } |  j j | j j d d t ƒƒ }	 | d	 k rÒ | rÒ |  j | | ƒ } qË| d
 k r| d k	 r| |  j	 k r|  j
 | | ƒ } qË| d k rD|	 rD|  j	 | k rD|  j | |	 ƒ } qË|  j rË| d k	 rË|	 d k	 rË|  j	 | k rË|  j | | |	 ƒ } qËn< |  j rË|  j d k	 rË| j |  j k rË|  j | ƒ } n  | | | ƒ S(   s   Dispatch the requests.t   __debugger__t   yest   cmdRO   t   st   tbt   typet   frmt   resourceR?   t   sourceN(   t   RequestR7   t   argst   getR   t   intR   RP   R   R#   RC   RE   R   R=   R    t   pathR>   (
   R   R1   R2   R;   t   responseRS   t   argR#   R5   R6   (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   __call__Ÿ   s,    	$$!!N(   R   R   R   t   FalseR   R   R7   R=   R>   RC   RE   RP   Ra   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyR   #   s   	*					(   R   R@   RJ   t   os.pathR    R   R   R   t   werkzeug.wrappersR   RZ   R   R9   t   werkzeug.debug.tbtoolsR   R   t   werkzeug.debug.consoleR   t   werkzeug.securityR	   t   werkzeug.debug.reprR
   t   objectR   R   (    (    (    s]   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/__init__.pyt   <module>
   s   "
