o
    h0                     @   s   d Z ddlZddlZddlmZ ddlmZ G dd deZG dd deZd	d
 Z	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd dZd#ddZdd Zdd Zdd  Ze  d!d" ZdS )$zexception classes    N)compat)utilc                   @      e Zd ZdS )MakoExceptionN__name__
__module____qualname__ r
   r
   c/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/mako/exceptions.pyr          r   c                   @   r   )RuntimeExceptionNr   r
   r
   r
   r   r      r   r   c                 C   s"   |d u r
d| |f S d|| |f S )Nz at line: %d char: %dz" in file '%s' at line: %d char: %dr
   )linenoposfilenamer
   r
   r   _format_filepos   s   r   c                   @      e Zd Zdd ZdS )CompileExceptionc                 C   4   t | |t|||  || _|| _|| _|| _d S Nr   __init__r   r   r   r   sourceselfmessager   r   r   r   r
   r
   r   r          
zCompileException.__init__Nr   r   r	   r   r
   r
   r
   r   r          r   c                   @   r   )SyntaxExceptionc                 C   r   r   r   r   r
   r
   r   r   +   r   zSyntaxException.__init__Nr   r
   r
   r
   r   r   *   r   r   c                   @      e Zd ZdZdS )UnsupportedErrorz&raised when a retired feature is used.Nr   r   r	   __doc__r
   r
   r
   r   r!   5       r!   c                   @   r    )NameConflictErrorz3raised when a reserved word is used inappropriatelyNr"   r
   r
   r
   r   r%   :   r$   r%   c                   @   r   )TemplateLookupExceptionNr   r
   r
   r
   r   r&   ?   r   r&   c                   @   r   )TopLevelLookupExceptionNr   r
   r
   r
   r   r'   C   r   r'   c                   @   sb   e Zd ZdZdddZedd Zdd Zd	d
 Zedd Z	edd Z
edd Zdd ZdS )RichTracebackzPull the current exception from the ``sys`` traceback and extracts
    Mako-specific template information.

    See the usage examples in :ref:`handling_exceptions`.

    Nc                 C   s   d\| _ | _|d u s|d u rt \}}}|d u r|p|}|d u r#|}|| _| || _t| jtt	frA| jj | _ | jj| _d| _
|   d S )N) r   T)r   r   sysexc_infoerror_initrecords
isinstancer   r   _has_source_init_message)r   r,   	tracebacktvaluetbackr
   r
   r   r   P   s   

zRichTraceback.__init__c                 C   s   t | jS r   )r   exception_namer,   r   r
   r
   r   	errornamef   s   zRichTraceback.errornamec                 C   sz   zt | j| _W n" ty*   zt | j| _W n ty'   | jjd | _Y nw Y nw t| jt s;t | jdd| _dS dS )z+Find a unicode representation of self.errorr   asciireplaceN)strr,   r   UnicodeErrorUnicodeEncodeErrorargsr/   r7   r
   r
   r   r1   j   s   zRichTraceback._init_messagec                 c   sN    |D ]!}|d d ur|d |d |d |d fV  qt |dd V  qd S )N            r   )tuple)r   r.   recr
   r
   r   _get_reformatted_recordsx   s    z&RichTraceback._get_reformatted_recordsc                 C      t | | jS )zReturn a list of 4-tuple traceback records (i.e. normal python
        format) with template-corresponding lines remapped to the originating
        template.

        )listrE   r.   r7   r
   r
   r   r2      s   zRichTraceback.tracebackc                 C   s
   t | jS r   )reversedr.   r7   r
   r
   r   reverse_records   s   
zRichTraceback.reverse_recordsc                 C   rF   )z;Return the same data as traceback, except in reverse order.)rG   rE   rI   r7   r
   r
   r   reverse_traceback   s   zRichTraceback.reverse_tracebackc                 C   s2  ddl }i }t|}g }|D ]\}}}}	|	sd}	z	|| \}
}}W nY ty{   z|j|}|j}|j}|jp=|j	p=|}W n tyV   |
||||	ddddf Y Y qw d}|jj}|j|dd}|d }
dd	 |d
D }|
||f||< Y nw |
|d  }|t|kr||d  }nd}|
||||	||||f q| jstt|d ddD ]}|| d r|| d | _|| d | _ |S q|rz8t|d d d}t|}|sd}|d | | _W d   n1 sw   Y  |r| j|| _W n ty   d| _Y nw |d d | _|S )a  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.r   Nr)      T)full_line_maprL   c                 S   s   g | ]}|qS r
   r
   ).0line_r
   r
   r   
<listcomp>   s    z'RichTraceback._init.<locals>.<listcomp>
rA      rbzutf-8)mako.templater2   
extract_tbKeyErrortemplate_get_module_infocoder   template_filenametemplate_uriappend
ModuleInfoget_module_source_metadatasplitlenranger   openr   parse_encodingseekreaddecodeIOError)r   trcbackmakomods
rawrecordsnew_trcbackr   r   functionlineline_maptemplate_linesrZ   infomodule_sourcetemplate_sourcetemplate_lnmtm
source_maptemplate_linelfpencodingr
   r
   r   r-      s   
%


zRichTraceback._init)NN)r   r   r	   r#   r   propertyr8   r1   rE   r2   rI   rJ   r-   r
   r
   r
   r   r(   G   s    




r(   c                 C   s   ddl }|jdS )zProvides 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.

    r   Na  
<%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}
)rT   rW   Template)lookupri   r
   r
   r   text_error_template   s   r~   c                   C   s   ddl ma ddl ma d S )Nr   )syntax_highlight)pygments_html_formatter)mako.ext.pygmentpluginr   r   r
   r
   r
   r   _install_pygments  s   r   c                      s"   ddl m  d ad fdd	ad S )Nr   html_escaper)   c                    s    S r   r
   )r   languager   r
   r   r     s   r   )r)   N)mako.filtersr   r   r   r
   r
   r   r   _install_fallback  s   r   c                   C   s(   zt   W d S  ty   t  Y d S w r   )r   ImportErrorr   r
   r
   r
   r   _install_highlighting  s
   r   c                  C   s   ddl } | jjdt ddS )a  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.

    r   Na  
<%!
    from mako.exceptions import RichTraceback, syntax_highlight,\
            pygments_html_formatter
%>
<%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%; }
        .highlight { white-space:pre; }
        .sampleline { white-space:pre; }

    % if pygments_html_formatter:
        ${pygments_html_formatter.get_style_defs()}
        .linenos { min-width: 2.5em; text-align: right; }
        pre { margin: 0; }
        .syntax-highlighted { padding: 0 10px; }
        .syntax-highlightedtable { border-spacing: 1px; }
        .nonhighlight { border-top: 1px solid #DFDFDF;
                        border-bottom: 1px solid #DFDFDF; }
        .stacktrace .nonhighlight { margin: 5px 15px 10px; }
        .sourceline { margin: 0 0; font-family:monospace; }
        .code { background-color: #F8F8F8; width: 100%; }
        .error .code { background-color: #FFBDBD; }
        .error .syntax-highlighted { background-color: #FFBDBD; }
    % endif

    </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|h}</h3>

% if lines:
    <div class="sample">
    <div class="nonhighlight">
% for index in range(max(0, line-4),min(len(lines), line+5)):
    <%
       if pygments_html_formatter:
           pygments_html_formatter.linenostart = index + 1
    %>
    % if index + 1 == line:
    <%
       if pygments_html_formatter:
           old_cssclass = pygments_html_formatter.cssclass
           pygments_html_formatter.cssclass = 'error ' + old_cssclass
    %>
        ${lines[index] | syntax_highlight(language='mako')}
    <%
       if pygments_html_formatter:
           pygments_html_formatter.cssclass = old_cssclass
    %>
    % else:
        ${lines[index] | syntax_highlight(language='mako')}
    % 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="nonhighlight">
    <%
       if pygments_html_formatter:
           pygments_html_formatter.linenostart = lineno
    %>
      <div class="sourceline">${line | syntax_highlight(filename)}</div>
    </div>
% endfor
</div>

% if full:
</body>
</html>
% endif
htmlentityreplace)output_encodingencoding_errors)rT   rW   r|   r*   getdefaultencoding)ri   r
   r
   r   html_error_template'  s   hr   r   )r#   r*   r2   ri   r   r   	Exceptionr   r   r   r   r   r!   r%   r&   r'   r(   r~   r   r   r   r   r
   r
   r
   r   <module>   s,    
+
