U  e0@sdZddlZddlZddlmZddlmZGdddeZGdddeZd d Z Gd d d eZ Gd ddeZ GdddeZ GdddeZ GdddeZGdddeZGdddZd#ddZddZddZdd Zed!d"ZdS)$zexception classesN)compat)utilc@s eZdZdS) MakoExceptionN__name__ __module__ __qualname__r r =/opt/hc_python/lib/python3.8/site-packages/mako/exceptions.pyrsrc@s eZdZdS)RuntimeExceptionNrr r r r r sr cCs&|dkrd||fSd|||fSdS)Nz at line: %d char: %dz" in file '%s' at line: %d char: %dr )linenoposfilenamer r r _format_fileposs rc@seZdZddZdS)CompileExceptioncCs4t||t|||||_||_||_||_dSNr__init__rr r rsourceselfmessagerr r rr r r r szCompileException.__init__Nrrrrr r r r rsrc@seZdZddZdS)SyntaxExceptioncCs4t||t|||||_||_||_||_dSrrrr r r r+szSyntaxException.__init__Nrr r r r r*src@seZdZdZdS)UnsupportedErrorz&raised when a retired feature is used.Nrrr__doc__r r r r r5src@seZdZdZdS)NameConflictErrorz3raised when a reserved word is used inappropriatelyNrr r r r r:src@s eZdZdS)TemplateLookupExceptionNrr r r r r?src@s eZdZdS)TopLevelLookupExceptionNrr r r r rCsrc@sbeZdZdZdddZeddZddZd d Zed d Z ed dZ eddZ ddZ dS) RichTracebackzPull the current exception from the ``sys`` traceback and extracts Mako-specific template information. See the usage examples in :ref:`handling_exceptions`. NcCsd\|_|_|dks|dkr*t\}}}|dkr:|p8|}|dkrF|}||_|||_t|jtt fr|jj|_|jj|_d|_ | dS)N)rT) rr sysexc_infoerror_initrecords isinstancerrZ _has_source _init_message)rr$ tracebacktvalueZtbackr r r rPs    zRichTraceback.__init__cCs t|jSr)rexception_namer$rr r r errornamefszRichTraceback.errornamec Cszzt|j|_WnHtk rXzt|j|_Wn"tk rR|jjd|_YnXYnXt|jtsvt|jdd|_dS)z+Find a unicode representation of self.errorrasciireplaceN)strr$r UnicodeErrorUnicodeEncodeErrorargsr'r-r r r r(js zRichTraceback._init_messageccsL|D]B}|ddk r4|d|d|d|dfVqt|ddVqdS)Nr)tuple)rr&Zrecr r r _get_reformatted_recordsxs  z&RichTraceback._get_reformatted_recordscCst||jS)zReturn a list of 4-tuple traceback records (i.e. normal python format) with template-corresponding lines remapped to the originating template. )listr:r&r-r r r r)szRichTraceback.tracebackcCs t|jSr)reversedr&r-r r r reverse_recordsszRichTraceback.reverse_recordscCst||jS)z;Return the same data as traceback, except in reverse order.)r;r:r=r-r r r reverse_tracebackszRichTraceback.reverse_tracebackcCs4ddl}i}t|}g}|D]*\}}}} | s4d} z||\} } } Wntk rz,|j|} | j}| j}| jp| j p|} Wn4tk r| |||| ddddfYYqYnXd}|jj }|j |dd}|d} dd | d D} | | | f||<YnX| |d}|t| kr,| |d}nd}| |||| | |||fq|js0tt|ddd D]6}||d rh||d |_||d |_q0qh|r0z^t|d dd.}t|}|sd}|d||_W5QRX|r|j||_Wntk r d|_YnX|d d|_|S)aformat 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.rNr!T) full_line_mapr@cSsg|]}|qSr r ).0Zline_r r r sz'RichTraceback._init.. r7rbzutf-8) mako.templater) extract_tbKeyErrortemplate_get_module_infocodertemplate_filenameZ template_uriappend ModuleInfoZget_module_source_metadatasplitlenranger openrZparse_encodingseekreaddecodeIOError)rZtrcbackmakomodsZ rawrecordsZ new_trcbackrr functionlineZline_mapZtemplate_linesrMinfoZ module_sourceZtemplate_sourceZ template_lnZmtmZ source_mapZ template_linelfpencodingr r r r%s         zRichTraceback._init)NN) rrrrrpropertyr.r(r:r)r=r>r%r r r r r Gs     r cCsddl}|jdS)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. rNa <%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} )rGrJTemplate)lookuprXr r r text_error_templatesrccCsddlmaddlmadS)Nr)syntax_highlight)pygments_html_formatter)Zmako.ext.pygmentpluginrdrer r r r _install_pygments s rfcs"ddlmdadfdd adS)Nr html_escaper!csSrr )rlanguagergr r rdsrd)r!N)Z mako.filtersrhrerdr r rgr _install_fallbacks rjcCs*z tWntk r$tYnXdSr)rf ImportErrorrjr r r r _install_highlightings rlcCsddl}|jjdtddS)aProvides 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. rNa <%! from mako.exceptions import RichTraceback, syntax_highlight,\ pygments_html_formatter %> <%page args="full=True, css=True, error=None, traceback=None"/> % if full: Mako Runtime Error % endif % if css: % endif % if full: % endif

Error !

<% tback = RichTraceback(error=error, traceback=traceback) src = tback.source line = tback.lineno if src: lines = src.split('\n') else: lines = None %>

${tback.errorname}: ${tback.message|h}

% if lines:
% 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
% endif
% for (filename, lineno, function, line) in tback.reverse_traceback:
${filename}, line ${lineno}:
<% if pygments_html_formatter: pygments_html_formatter.linenostart = lineno %>
${line | syntax_highlight(filename)}
% endfor
% if full: % endif Zhtmlentityreplace)Zoutput_encodingZencoding_errors)rGrJrar"getdefaultencoding)rXr r r html_error_template's hrn)N)rr"r)rXrr Exceptionrr rrrrrrrr rcrfrjrlrnr r r r s*    +