ó
ži‚Nc           @   s  d  Z  d d l Z d d l Z d d l Z d d l m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z	 d	 e f d
 „  ƒ  YZ
 d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d d „ Z d „  Z d S(   s   exception classesiÿÿÿÿN(   t   utilt   MakoExceptionc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR      s   t   RuntimeExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR      s   c         C   s/   | d  k r d |  | f Sd | |  | f Sd  S(   Ns    at line: %d char: %ds"    in file '%s' at line: %d char: %d(   t   None(   t   linenot   post   filename(    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   _format_filepos   s    t   CompileExceptionc           B   s   e  Z d  „  Z RS(   c         C   sH   t  j |  | t | | | ƒ ƒ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   t   __init__R	   R   R   R   t   source(   t   selft   messageR   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR      s
     			(   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR
      s   t   SyntaxExceptionc           B   s   e  Z d  „  Z RS(   c         C   sH   t  j |  | t | | | ƒ ƒ | |  _ | |  _ | |  _ | |  _ d  S(   N(   R   R   R	   R   R   R   R   (   R   R   R   R   R   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   "   s
     			(   R   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   !   s   t   UnsupportedErrorc           B   s   e  Z d  Z RS(   s&   raised when a retired feature is used.(   R   R   t   __doc__(    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   )   s   t   TemplateLookupExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   ,   s   t   TopLevelLookupExceptionc           B   s   e  Z RS(    (   R   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   /   s   t   RichTracebackc           B   st   e  Z d  Z d	 d	 d „ Z e d „  ƒ Z d „  Z d „  Z e d „  ƒ Z	 e d „  ƒ Z
 e d „  ƒ Z d „  Z RS(
   sª   Pulls the current exception from the sys traceback and extracts
    Mako-specific template information.
 
    See the usage examples in :ref:`handling_exceptions`.
 
    c         C   sé   d \ |  _  |  _ | d  k s* | d  k rB t j ƒ  \ } } } n  | d  k r] | pW | } n  | d  k rr | } n  | |  _ |  j | ƒ |  _ t |  j t	 t
 f ƒ rÛ d d  l } |  j j  |  _  |  j j |  _ t |  _ n  |  j ƒ  d  S(   Nt    i    iÿÿÿÿ(   R   i    (   R   R   R   t   syst   exc_infot   errort   _initt   recordst
   isinstanceR
   R   t   mako.templatet   Truet   _has_sourcet   _init_message(   R   R   t	   tracebackt   tt   valuet   tbackt   mako(    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   9   s    		c         C   s   t  j |  j ƒ S(   N(   R    t   exception_nameR   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt	   errornameP   s    c         C   s˜   y t  |  j ƒ |  _ WnN t k
 rf y t |  j ƒ |  _ Wqg t k
 rb |  j j d |  _ qg Xn Xt |  j t  ƒ s” t  |  j d d ƒ |  _ n  d S(   s+   Find a unicode representation of self.errori    t   asciit   replaceN(   t   unicodeR   R   t   UnicodeErrort   strt   UnicodeEncodeErrort   argsR   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   T   s    c         c   s[   xT | D]L } | d d  k	 rA | d | d | d | d f Vq t | d d !ƒ Vq Wd  S(   Ni   i   i   i   i    (   R   t   tuple(   R   R   t   rec(    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   _get_reformatted_recordsb   s    $c         C   s   t  |  j |  j ƒ ƒ S(   s©   return a list of 4-tuple traceback records (i.e. normal python
        format) with template-corresponding lines remapped to the originating
        template.
 
        (   t   listR0   R   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR    i   s    c         C   s   t  |  j ƒ S(   N(   t   reversedR   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   reverse_recordsr   s    c         C   s   t  |  j |  j ƒ ƒ S(   sD   return the same data as traceback, except in reverse order.
        (   R1   R0   R3   (   R   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   reverse_tracebackv   s    c         C   sr  d d l  } i  } t j | ƒ } g  } x8| D]0\ } } } }	 |	 sO d }	 n  y | | \ }
 } Wn t k
 ry7 | j j | ƒ } | j } | j } | j p¦ | } Wnµ t k
 rat	 j
 s6y, t | d ƒ } t	 j | ƒ } | j ƒ  Wn t k
 rd } n X| r!|	 j | ƒ }	 q6|	 j d d ƒ }	 n  | j | | | |	 d d d d f ƒ q. n Xd } } i  }
 x[ | j d ƒ D]J }	 t j d	 |	 ƒ } | r¸t | j d ƒ ƒ } n  | d 7} | |
 | <q‚Wg  | j d ƒ D] }	 |	 ^ qà} |
 | f | | <n X|
 | } | t | ƒ k r3| | d } n d } | j | | | |	 | | | | f ƒ q. W|  j snx t t | ƒ d d
 d ƒ D]: } | | d rˆ| | d |  _ | | d |  _ PqˆqˆW| rnyn t | d d
 d ƒ } t	 j | ƒ } | j d
 ƒ | j ƒ  |  _ | j ƒ  | r9|  j j | ƒ |  _ n  Wn t k
 rVd |  _ n X| d d |  _ qnn  | S(   s  format a traceback from sys.exc_info() into 7-item tuples,
        containing the regular four traceback tuple items, plus the original
        template filename, the line number adjusted relative to the template
        source, and code line from that line number of the template.iÿÿÿÿNR   t   rbR'   R(   i   s   
s   \s*# SOURCE LINE (\d+)i    i   i   (   R   R    t
   extract_tbt   KeyErrort   templatet   _get_module_infot   codeR   t   template_filenameR    t   py3kt   opent   parse_encodingt   closet   IOErrorR   t   decodet   appendt   splitt   ret   matcht   intt   groupt   lent   rangeR   t   seekt   read(   R   t   trcbackR$   t   modst
   rawrecordst   new_trcbackR   R   t   functiont   linet   line_mapt   template_linest   infot   module_sourcet   template_sourceR;   t   fpt   encodingt   template_lnt	   module_lnRE   t   template_linet   l(    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   }   s„    				



		#
N(   R   R   R   R   R   t   propertyR&   R   R0   R    R3   R4   R   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyR   2   s   			c         C   s   d d l  } | j j d ƒ S(   sê   Provides a template that renders a stack trace in a similar format to
    the Python interpreter, substituting source template filenames, line
    numbers and code for that of the originating source template, as
    applicable.
 
    iÿÿÿÿNs‚  
<%page args="error=None, traceback=None"/>
<%!
    from mako.exceptions import RichTraceback
%>\
<%
    tback = RichTraceback(error=error, traceback=traceback)
%>\
Traceback (most recent call last):
% for (filename, lineno, function, line) in tback.traceback:
  File "${filename}", line ${lineno}, in ${function or '?'}
    ${line | trim}
% endfor
${tback.errorname}: ${tback.message}
(   R   R8   t   Template(   t   lookupR$   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   text_error_templateÎ   s    	c          C   s.   d d l  }  |  j j d d t j ƒ  d d ƒS(   s  Provides a template that renders a stack trace in an HTML format,
    providing an excerpt of code as well as substituting source template
    filenames, line numbers and code for that of the originating source
    template, as applicable.

    The template's default encoding_errors value is 'htmlentityreplace'. the
    template has two options. With the full option disabled, only a section of
    an HTML document is returned. with the css option disabled, the default
    stylesheet won't be included.
 
    iÿÿÿÿNsQ  
<%!
    from mako.exceptions import RichTraceback
%>
<%page args="full=True, css=True, error=None, traceback=None"/>
% if full:
<html>
<head>
    <title>Mako Runtime Error</title>
% endif
% if css:
    <style>
        body { font-family:verdana; margin:10px 30px 10px 30px;}
        .stacktrace { margin:5px 5px 5px 5px; }
        .highlight { padding:0px 10px 0px 10px; background-color:#9F9FDF; }
        .nonhighlight { padding:0px; background-color:#DFDFDF; }
        .sample { padding:10px; margin:10px 10px 10px 10px; font-family:monospace; }
        .sampleline { padding:0px 10px 0px 10px; }
        .sourceline { margin:5px 5px 10px 5px; font-family:monospace;}
        .location { font-size:80%; }
    </style>
% endif
% if full:
</head>
<body>
% endif

<h2>Error !</h2>
<%
    tback = RichTraceback(error=error, traceback=traceback)
    src = tback.source
    line = tback.lineno
    if src:
        lines = src.split('\n')
    else:
        lines = None
%>
<h3>${tback.errorname}: ${tback.message}</h3>

% if lines:
    <div class="sample">
    <div class="nonhighlight">
% for index in range(max(0, line-4),min(len(lines), line+5)):
    % if index + 1 == line:
<div class="highlight">${index + 1} ${lines[index] | h}</div>
    % else:
<div class="sampleline">${index + 1} ${lines[index] | h}</div>
    % endif
% endfor
    </div>
    </div>
% endif

<div class="stacktrace">
% for (filename, lineno, function, line) in tback.reverse_traceback:
    <div class="location">${filename}, line ${lineno}:</div>
    <div class="sourceline">${line | h}</div>
% endfor
</div>

% if full:
</body>
</html>
% endif
t   output_encodingt   encoding_errorst   htmlentityreplace(   R   R8   R^   R   t   getdefaultencoding(   R$   (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   html_error_templateæ   s    	@(   R   R    R   RD   R$   R    t	   ExceptionR   R   R	   R
   R   R   R   R   t   objectR   R   R`   Re   (    (    (    s3   /usr/lib/python2.7/dist-packages/mako/exceptions.pyt   <module>   s   $	œ