
`Tc           @   s  d  Z  d d l Z d d l Z d d l Z d d l Z d d l Z d d l 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 m Z m Z m Z e j d  Z e j d  Z e j d	  Z d
 Z e e f Z y e e f 7Z Wn e k
 rn Xd Z d Z e d e d Z  e d e Z! d Z" d Z# d Z$ d Z% d   Z& e' e' d d  Z( d e) f d     YZ* d e) f d     YZ+ d e) f d     YZ, d S(   s   
    werkzeug.debug.tbtools
    ~~~~~~~~~~~~~~~~~~~~~~

    This module provides various traceback related utility functions.

    :copyright: (c) 2014 by the Werkzeug Team, see AUTHORS for more details.
    :license: BSD.
iN(   t
   TokenError(   t   cached_propertyt   escape(   t   Console(   t
   range_typet   PY2t	   text_typet   string_typess   coding[:=]\s*([-\w.]+)s   ^(.*?)$(?m)s+   ^(\s*def\s)|(.*(?<!\w)lambda(:|\s))|^(\s*@)s   ﻿u  <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  "http://www.w3.org/TR/html4/loose.dtd">
<html>
  <head>
    <title>%(title)s // Werkzeug Debugger</title>
    <link rel="stylesheet" href="?__debugger__=yes&amp;cmd=resource&amp;f=style.css" type="text/css">
    <!-- We need to make sure this has a favicon so that the debugger does not by
         accident trigger a request to /favicon.ico which might change the application
         state. -->
    <link rel="shortcut icon" href="?__debugger__=yes&amp;cmd=resource&amp;f=console.png">
    <script type="text/javascript" src="?__debugger__=yes&amp;cmd=resource&amp;f=jquery.js"></script>
    <script type="text/javascript" src="?__debugger__=yes&amp;cmd=resource&amp;f=debugger.js"></script>
    <script type="text/javascript">
      var TRACEBACK = %(traceback_id)d,
          CONSOLE_MODE = %(console)s,
          EVALEX = %(evalex)s,
          SECRET = "%(secret)s";
    </script>
  </head>
  <body>
    <div class="debugger">
u         <div class="footer">
        Brought to you by <strong class="arthur">DON'T PANIC</strong>, your
        friendly Werkzeug powered traceback interpreter.
      </div>
    </div>
  </body>
</html>
u  <h1>%(exception_type)s</h1>
<div class="detail">
  <p class="errormsg">%(exception)s</p>
</div>
<h2 class="traceback">Traceback <em>(most recent call last)</em></h2>
%(summary)s
<div class="plain">
  <form action="/?__debugger__=yes&amp;cmd=paste" method="post">
    <p>
      <input type="hidden" name="language" value="pytb">
      This is the Copy/Paste friendly version of the traceback.  <span
      class="pastemessage">You can also paste this traceback into
      a <a href="https://gist.github.com/">gist</a>:
      <input type="submit" value="create paste"></span>
    </p>
    <textarea cols="50" rows="10" name="code" readonly>%(plaintext)s</textarea>
  </form>
</div>
<div class="explanation">
  The debugger caught an exception in your WSGI application.  You can now
  look at the traceback which led to the error.  <span class="nojavascript">
  If you enable JavaScript you can also use additional features such as code
  execution (if the evalex feature is enabled), automatic pasting of the
  exceptions and much more.</span>
</div>
s   
<!--

%(plaintext_cs)s

-->
u+  <h1>Interactive Console</h1>
<div class="explanation">
In this console you can execute Python expressions in the context of the
application.  The initial namespace was created by the debugger automatically.
</div>
<div class="console"><div class="inner">The Console requires JavaScript.</div></div>
uU   <div class="%(classes)s">
  %(title)s
  <ul>%(frames)s</ul>
  %(description)s
</div>
u   <div class="frame" id="frame-%(id)d">
  <h4>File <cite class="filename">"%(filename)s"</cite>,
      line <em class="line">%(lineno)s</em>,
      in <code class="function">%(function_name)s</code></h4>
  <pre>%(current_line)s</pre>
</div>
u   <table class=source>%s</table>uV   <tr class="%(classes)s">
  <td class=lineno>%(lineno)s</td>
  <td>%(code)s</td>
</tr>
c         C   s+   t  i d d 6d d 6d d 6|  d 6d d 6S(	   Nt   truet   evalext   consoleR   t   titlet   secretit   traceback_id(   t   CONSOLE_HTML(   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   render_console_html   s    i    c         C   s   t  j   \ } } } |  r- | t k r-   n  x0 t |  D]" } | j d k rS Pn  | j } q: Wt | | |  } | s | j   n  | S(   s  Get the current exception info as `Traceback` object.  Per default
    calling this method will reraise system exceptions such as generator exit,
    system exit or others.  This behavior can be disabled by passing `False`
    to the function as first parameter.
    N(   t   syst   exc_infot   system_exceptionsR   t   tb_nextt   Nonet	   Tracebackt   filter_hidden_frames(   t   ignore_system_exceptionst   show_hidden_framest   skipt   exc_typet	   exc_valuet   tbt   x(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   get_current_traceback   s    t   Linec           B   s;   e  Z d  Z d Z d   Z d   Z e e  Z d   Z RS(	   s   Helper for the source renderer.t   linenot   codet   in_framet   currentc         C   s(   | |  _  | |  _ t |  _ t |  _ d  S(   N(   R    R!   t   FalseR"   R#   (   t   selfR    R!   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   __init__   s    			c         C   s?   d g } |  j  r" | j d  n  |  j r; | j d  n  | S(   Nt   lines   in-frameR#   (   R"   t   appendR#   (   R%   t   rv(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   classes   s    			c         C   s5   t  i d j |  j  d 6|  j d 6t |  j  d 6S(   Nu    R*   R    R!   (   t   SOURCE_LINE_HTMLt   joinR*   R    R   R!   (   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   render   s    
(   s   linenos   codes   in_frames   current(   t   __name__t
   __module__t   __doc__t	   __slots__R&   R*   t   propertyR-   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR      s   		R   c           B   s   e  Z d  Z d   Z d   Z d   Z e e  Z d   Z e e  Z d d  Z	 d   Z
 e d  Z e d d  Z d	   Z d
   Z e e  Z e d    Z RS(   s   Wraps a traceback.c         C   s   | |  _  | |  _ t | t  sP | j } | j d k rV | j d | } qV n | } | |  _ g  |  _ x/ | r |  j j t	 | | |   | j
 } qk Wd  S(   Nt   __builtin__t
   exceptionst   .(   s   __builtin__s
   exceptions(   R   R   t
   isinstancet   strR.   R/   t   exception_typet   framesR(   t   FrameR   (   R%   R   R   R   R8   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR&      s    						c         C   s&  |  j  s d Sg  } t } x |  j  D] } | j } | d k r_ g  } t } | d k r q# q n` | d k r t } | d k r q# q n9 | d k r t } | d k r q# q n | s# | r q# n  | j |  q# Wt |  d k r|  j  d	 j d
 k r|  j  2n  |  j  d | k r"| |  j  (n  d S(   s.   Remove the frames according to the paste spec.Nt   beforet   before_and_thist   resett   reset_and_thist   aftert   after_and_thisi   i    t   codeopi(   R;   R<   (   s   resetR>   (   s   afterR@   (   R9   R$   t   hidet   TrueR(   t   lent   module(   R%   t
   new_framest   hiddent   frameRB   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR      s4    					(
c         C   s   t  |  j t  S(   s   Is it a syntax error?(   R6   R   t   SyntaxError(   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   is_syntax_error   s    c         C   sG   t  j |  j |  j  } d j |  j   } t rC | j d d  S| S(   s'   String representation of the exception.t    s   utf-8t   replace(   t	   tracebackt   format_exception_onlyR   R   R,   t   stripR   t   decode(   R%   t   bufR)   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt	   exception  s    c         C   sU   | d k r t j } n  |  j j   d } t rD | j d d  n  | j |  d S(   s+   Log the ASCII traceback into a file object.u   
s   utf-8RL   N(   R   R   t   stderrt	   plaintextt   rstripR   t   encodet   write(   R%   t   logfileR   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   log
  s    c         C   s   t  j i d d 6t d 6i i |  j d 6d 6d 6 j d  } y d d	 l m } Wn! t k
 ru d d	 l m } n X| d
 d | } t  j	 | j
   j d   } | j   i | d d 6| d d 6S(   s'   Create a paste and return the paste id.s   Werkzeug Internal Server Errort   descriptiont   publict   contents   traceback.txtt   filess   utf-8i(   t   urlopens   https://api.github.com/gistst   datat   html_urlt   urlt   id(   t   jsont   dumpsR$   RT   RV   t   urllib2R^   t   ImportErrort   urllib.requestt   loadst   readRP   t   close(   R%   R_   R^   R)   t   resp(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   paste  s"    		
c         C   s  d } g  } d g } |  j  s. | j d  n  | rO |  j rF d } qO d } n  xJ |  j  D]? } | j d | j r d t | j  p d | j   f  qY W|  j r d	 } n d
 } t i d j |  d 6| r d | p d d 6d j |  d 6| t |  j  d 6S(   s1   Render the traceback for the interactive console.RK   RM   s   noframe-tracebacku   Syntax Erroru+   Traceback <em>(most recent call last)</em>:u   <li%s>%su    title="%s"u    u   <pre class=syntaxerror>%s</pre>u   <blockquote>%s</blockquote>u    R*   u   <h3>%s</h3>R   u   
R9   RZ   (	   R9   R(   RJ   t   infoR   R-   t   SUMMARY_HTMLR,   RR   (   R%   t   include_titleR   R9   R*   RH   t   description_wrapper(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   render_summary*  s*    								c         C   s   t  |  j  } t i
 | r! d p$ d d 6d d 6| d 6| d 6t  |  j  d 6|  j d t  d	 6|  j d
 6t j d d |  j  d 6|  j	 d 6| d 6S(   s2   Render the Full HTML page with the traceback info.R   t   falseR	   R
   R   RR   R8   Ro   t   summaryRT   s   -{2,}t   -t   plaintext_csR   R   (
   R   RR   t	   PAGE_HTMLR8   Rq   R$   RT   t   ret   subRb   (   R%   R	   R   t   exc(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   render_fullJ  s    

c         c   sR   d Vx> |  j  D]3 } d | j | j | j f Vd | j j   Vq W|  j Vd S(   s4   Like the plaintext attribute but returns a generatoru"   Traceback (most recent call last):u     File "%s", line %s, in %su       N(   R9   t   filenameR    t   function_namet   current_lineRO   RR   (   R%   RH   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   generate_plaintext_tracebackZ  s    c         C   s   d j  |  j    S(   Nu   
(   R,   R~   (   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyRT   f  s    c         C   s
   t  |   S(   N(   Rb   (   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   <lambda>j  s    N(   R.   R/   R0   R&   R   RJ   R2   RR   R   RY   Rl   RC   Rq   R$   Rz   R~   RT   R   Rb   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR      s   		#				 		R:   c           B   sz   e  Z d  Z d   Z d   Z d   Z d   Z d d  Z e d    Z	 e
 d    Z e d	    Z e
 d
    Z RS(   s   A single frame in a traceback.c         C   sb  | j  |  _ | j j j |  _ | j j |  _ | j j |  _	 t
 j |  pW t
 j |  } | d d k rw | d  } n  t j j |  r t j j |  } n  | |  _ |  j	 j d  |  _ |  j	 j d  |  _ | j j |  _ |  j j d t  |  _ |  j j d  } | d  k	 rUy t |  } WqUt k
 rQt |  j d	 d
  } qUXn  | |  _ d  S(   Nis   .pyos   .pyciR.   t
   __loader__t   __traceback_hide__t   __traceback_info__s   utf-8RL   (   s   .pyos   .pyc(   t	   tb_linenoR    t   tb_framet   f_codet   co_nameR|   t   f_localst   localst	   f_globalst   globalst   inspectt   getsourcefilet   getfilet   ost   patht   isfilet   realpathR{   t   getRE   t   loaderR!   R$   RB   R   R   t   UnicodeErrorR7   RP   Rm   (   R%   R   R   R   t   fnRm   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR&   p  s*    	c         C   sR   t  i |  j d 6t |  j  d 6|  j d 6t |  j  d 6t |  j j    d 6S(   s%   Render a single frame in a traceback.Rb   R{   R    R|   R}   (   t
   FRAME_HTMLRb   R   R{   R    R|   R}   RO   (   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR-     s    

c         C   s7  g  t  |  j  D] \ } } t | d |  ^ q } t |  j d  r|  j j d } x4 | d k r t j | | j  r Pn  | d 8} qZ Wy7 t t	 j
 g  | | D] } | j d ^ q   } Wn t k
 r d } n Xx% | | | | !D] } t | _ q Wn  y t | |  j d _ Wn t k
 r2n X| S(   s:   Helper function that returns lines with extra information.i   t   co_firstlinenoi    s   
(   t	   enumeratet   sourcelinesR   t   hasattrR!   R   t   _funcdef_ret   matchRD   R   t   getblockR    RC   R"   R    R#   t
   IndexError(   R%   t   idxR   t   linesR    t   offsetR'   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   get_annotated_lines  s&    5+
c         C   s!   t  d j d   |  j   D  S(   s   Render the sourcecode.u   
c         s   s   |  ] } | j    Vq d  S(   N(   R-   (   t   .0R'   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pys	   <genexpr>  s    (   t   SOURCE_TABLE_HTMLR,   R   (   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   render_source  s    t   singlec         C   se   t  | t  rO t r: t  | t  r: t | j d  } n  t | d |  } n  t | |  j |  j	  S(   s*   Evaluate code in the context of the frame.s   utf-8s   <interactive>(
   R6   R   R   t   unicodet   UTF8_COOKIERV   t   compilet   evalR   R   (   R%   R!   t   mode(    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR     s
    c         C   s  d } |  j d k	 r yX t |  j d  rB |  j j |  j  } n* t |  j d  rl |  j j |  j  } n  Wq t k
 r q Xn  | d k r y t |  j	  } Wn t
 k
 r g  SXz | j   } Wd | j   Xn  t | t  r | j   Sd } | j t  r| d } nj xg t t j |   D]P \ } } t j | j    } | d k	 rj| j d  } Pn  | d k r*Pq*q*Wy t j |  Wn t k
 rd } n X| j | d  j   S(   s6   The sourcecode of the file as list of unicode strings.t
   get_sourcet   get_source_by_codeNs   utf-8i   i   RL   (   R   R   R   R   RE   R   R!   t	   Exceptiont   openR{   t   IOErrorRi   Rj   R6   R   t
   splitlinest
   startswithR   R   t   _line_ret   finditert   searcht   groupt   codecst   lookupt   LookupErrorRP   (   R%   t   sourcet   ft   charsetR   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR     sD    
"
c         C   s/   y |  j  |  j d SWn t k
 r* d SXd  S(   Ni   u    (   R   R    R   (   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR}     s    c         C   s   t  |  j |  j  S(   N(   R   R   R   (   R%   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR
     s    c         C   s
   t  |   S(   N(   Rb   (   R   (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR     s    (   R.   R/   R0   R&   R-   R   R   R   R   R   R2   R}   R
   Rb   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyR:   m  s   		
		4(-   R0   Rw   R   R   Rc   R   RM   R   t   tokenizeR    t   werkzeug.utilsR   R   t   werkzeug.debug.consoleR   t   werkzeug._compatR   R   R   R   R   t
   _coding_reR   R   R   t
   SystemExitt   KeyboardInterruptR   t   GeneratorExitt	   NameErrort   HEADERt   FOOTERRv   R   Rn   R   R   R+   R   R$   R   t   objectR   R   R:   (    (    (    s\   /var/www/send.findwatt.com/datamanager/lib/python2.7/site-packages/werkzeug/debug/tbtools.pyt   <module>
   sF   "				
