U cfs@sddlmZddlZddlZddlZddlZddlmZmZddl m Z ddl m Z m Z ddlmZmZmZmZmZmZmZmZmZmZddlmZddlmZmZmZmZm Z m!Z!dd lm"Z#dd lm$Z$dd l%m&Z&d d l'm(Z(d dl)m*Z*d dl+m,Z,d dl-m.Z.m/Z/m0Z0m1Z1m2Z2d dl3m4Z4d dl5m6Z6m7Z7d dl8m9Z9d dl:m;Z;d dlm?Z?d d l@m"Z"d dlAmBZBeCdkZDdZEdZFddddddeEeFdddddd ee.eeGeGeeHeIeIeGeGeIeeIeIeeeHe feGeeeJeJee gefd!d"d#ZKeGd$d%d%ZLeGd&d'd'ZMeGd(d)d)ZNeGd*d+d+ZOGd,d-d-e6ZPGd.d/d/ZQeRd0krd d1l-m.Z.e.Z-ddlZedd2d3d4ZSedd2d5d6ZTdd7d8d9ZUeUdS):)absolute_importN) dataclassfield)walk_tb) ModuleType TracebackType) AnyCallableDictIterableListOptionalSequenceTupleTypeUnion)guess_lexer_for_filename)CommentKeywordNameNumberOperatorString)Text)Token) ClassNotFound)pretty) loop_last)Columns)ConsoleConsoleOptionsConsoleRenderable RenderResultgroup) Constrain)RegexHighlighterReprHighlighter)Panel) render_scope)Style)Syntax)ThemeWindows PdFT) consolewidth extra_linestheme word_wrap show_localslocals_max_lengthlocals_max_stringlocals_hide_dunderlocals_hide_sunder indent_guidessuppress max_frames)r3r4r5r6r7r8r9r:r;r<r=r>r?returnc s|dkrtddn| jr(dkr(dntttttdd f dd tddfdd } zt}| |tj WSt k rtj }t_ |YSXdS) a"Install a rich traceback handler. Once installed, any tracebacks will be printed with syntax highlighting and rich formatting. Args: console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance. width (Optional[int], optional): Width (in characters) of traceback. Defaults to 100. extra_lines (int, optional): Extra lines of code. Defaults to 3. theme (Optional[str], optional): Pygments theme to use in traceback. Defaults to ``None`` which will pick a theme appropriate for the platform. word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False. show_locals (bool, optional): Enable display of local variables. Defaults to False. locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10. locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80. locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True. locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False. indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True. suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback. Returns: Callable: The previous exception handler that was replaced. NT)stderr)type_value tracebackr@cs6 tj||| tddS)N r4r5r6r7r8r9r:r;r<r=r>r?)print Tracebackfrom_exceptionbool)rBrCrD) r5r=r;r<r9r:r?r8r>r6traceback_consoler4r7r2H/opt/hc_python/lib/python3.8/site-packages/pip/_vendor/rich/traceback.py excepthookas&zinstall..excepthook)ipr@csbijttddfdd }ddtttddfdd_|_fd d _dS) N)argskwargsr@cs|||dS)zEwrap the default ip.showtraceback to store info for ip._showtracebackNr2rNrO)default_showtracebacktb_datar2rKipy_show_traceback~szCinstall..ipy_excepthook_closure..ipy_show_tracebackF) is_syntax)rNrTrOr@cst}|rdn|d}dd}d|r2dnd}t|D]}|dkrPqX|j}q@|d|d|idS)z2Internally called traceback from ip._showtracebackNrunning_compiled_codeF tb_offsetrr) _get_exc_infogetrangetb_next)rTrNrO exc_tupletbcompiledrW_)rLrMrRr2rKipy_display_tracebacks  zFinstall..ipy_excepthook_closure..ipy_display_tracebackcs|ddi|S)NrTTr2rP)r`r2rKs z9install..ipy_excepthook_closure..) showtracebackrrI_showtracebackshowsyntaxerror)rMrS)rL)rQrMr`rRrKipy_excepthook_closurezsz'install..ipy_excepthook_closure) r is_jupyterr BaseExceptionr rr get_ipythonsysrL Exception)r3r4r5r6r7r8r9r:r;r<r=r>r?rerMold_excepthookr2)rLr5r=r;r<r9r:r?r8r>r6rJr4r7rKinstall0s*)()rlc@sLeZdZUeed<eed<eed<dZeed<dZee ee j fed<dS)FramefilenamelinenonamelineNlocals) __name__ __module__ __qualname__str__annotations__intrrrsr r rNoder2r2r2rKrms  rmc@s6eZdZUeed<eed<eed<eed<eed<dS) _SyntaxErroroffsetrnrrromsgN)rtrurvryrxrwr2r2r2rKr{s r{c@sPeZdZUeed<eed<dZeeed<dZe ed<e e dZ e eed<dS) Stackexc_type exc_valueN syntax_errorFis_cause)default_factoryframes)rtrurvrwrxrr r{rrIrlistrr rmr2r2r2rKr~s  r~c@seZdZUeeed<dS)TracestacksN)rtrurvr r~rxr2r2r2rKrs rc@seZdZdgZdS)PathHighlighterz(?P.*/)(?P.+)N)rtrurv highlightsr2r2r2rKrsrc@speZdZdZddddddZd$dd dd d eed d d d dd eeee e ee e e e e e e e e e e efe d ddZedd dd d eed d d d dd eeeeeee e ee e e e e e e e e e e efe ddddZed eed d deeeeee e e e e ed ddZeeedddZeeedddZee e e ddd Zeeed!d"d#Z dS)%rGaA Console renderable that renders a traceback. Args: trace (Trace, optional): A `Trace` object produced from `extract`. Defaults to None, which uses the last exception. width (Optional[int], optional): Number of characters used to traceback. Defaults to 100. extra_lines (int, optional): Additional lines of code to render. Defaults to 3. theme (str, optional): Override pygments theme used in traceback. word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False. show_locals (bool, optional): Enable display of local variables. Defaults to False. indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True. locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10. locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80. locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True. locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False. suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback. max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100. textpythoncythonpyrex)rqz.pyz.pxdz.pyxz.pxiNr0r1FTr2rE) tracer4r5r6r7r8r9r:r;r<r=r>r?c Cs|dkrHt\}}}|dks.|dks.|dkr6td|j||||d}||_||_||_t|pdd|_ ||_ ||_ | |_ ||_ ||_| |_| |_g|_| D]Z}t|ts|jdk st|dtj|j}n|}tjtj|}|j|q| dkrtd| nd|_dS)Nz9Value for 'trace' required if not called in except: blockr8 ansi_darkz+ must be a module with '__file__' attributer)riexc_info ValueErrorextractrr4r5r+ get_themer6r7r8r=r9r:r;r<r> isinstancerw__file__AssertionErrorospathdirnamenormpathabspathappendmaxr?)selfrr4r5r6r7r8r9r:r;r<r=r>r?rrrDsuppress_entityrr2r2rK__init__sF zTraceback.__init__)rrrDr4r5r6r7r8r9r:r;r<r=r>r?r@c Cs<|j||||| | | | d}|||||||| | | | | ||d S)aeCreate a traceback from exception info Args: exc_type (Type[BaseException]): Exception type. exc_value (BaseException): Exception value. traceback (TracebackType): Python Traceback object. width (Optional[int], optional): Number of characters used to traceback. Defaults to 100. extra_lines (int, optional): Additional lines of code to render. Defaults to 3. theme (str, optional): Override pygments theme used in traceback. word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False. show_locals (bool, optional): Enable display of local variables. Defaults to False. indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True. locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10. locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80. locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True. locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False. suppress (Iterable[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback. max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100. Returns: Traceback: A Traceback instance that may be printed. r8r9r:r;r<) r4r5r6r7r8r=r9r:r;r<r>r?)r)clsrrrDr4r5r6r7r8r9r:r;r<r=r>r?rich_tracebackr2r2rKrH$s2+ zTraceback.from_exceptionr) rrrDr8r9r:r;r<r@c sg} d} ddlm} ttddd} t| |j| || d} t|trtt|j pPd|j pXd|j p`d|j phd |j d | _| | | jj}ttttfttttfd fd d }t|D]\}}|jj}|r|dstj|stj| |}|jddrqt|pd||jj|r<fdd||j Dndd}|||jddr| jdd=qt!|dd}|r|j"}|}|j#}d} q$|j$}|rt!|dds|j"}|}|j#}d} q$qq$t%| d}|S)aExtract traceback information. Args: exc_type (Type[BaseException]): Exception type. exc_value (BaseException): Exception value. traceback (TracebackType): Python Traceback object. show_locals (bool, optional): Enable display of local variables. Defaults to False. locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation. Defaults to 10. locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80. locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True. locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False. Returns: Trace: A Trace instance which you can use to construct a `Traceback`. Fr) _IMPORT_CWD)_objectr@cSs&z t|WStk r YdSXdS)z1Don't allow exceptions from __str__ to propagate.zN)rwrj)rr2r2rKsafe_strs z#Traceback.extract..safe_str)rrr?rq)r|rnrorrr}) iter_localsr@c3sRss|EdHdS|D]2\}}r2|dr2qrB|drBq||fVqdS)z-Extract locals from an iterator of key pairs.N__r_ startswith)rkeyrC)r;r<r2rK get_localss  z%Traceback.extract..get_locals<_rich_traceback_omitcs"i|]\}}|tj|dqS)) max_length max_string)rtraverse).0rrC)r9r:r2rK sz%Traceback.extract..N)rnrorprs_rich_traceback_guard __cause__T__suppress_context__)r)&pip._vendor.richrrrwr~rtr SyntaxErrorr{r|rnrorr}rrrr robjectrf_code co_filenamerrrisabsjoinf_localsrYrmco_nameitemsgetattr __class__ __traceback__ __context__r)rrrrDr8r9r:r;r<rrrrstackrr frame_summaryline_nornframecauserr2)r;r<r9r:rKrjsv         zTraceback.extract)r3optionsr@c cs|j}|}|j}t|t|t|t|tj|t |t t dd|t|tt dd|t |t j |t j |t j |tj|t|t|tj t ddddd}t}tt|jjD]$\}} | jrt|| d|ddd d } t| |j} || | VW5QRX| jdk r||.tt|| j|d dd |jd |jVW5QRXt| jd df|| jj Vn>| j!rt| jd df|| j!Vnt| jdfV|s| j"rt#dVqt#dVqdS)NT)dim)bold)r pygments.textpygments.stringpygments.functionpygments.numberz repr.indentzrepr.strz repr.bracez repr.numberzrepr.bool_truezrepr.bool_falsez repr.nonez scope.borderz scope.equalsz scope.keyzscope.key.specialF)inheritz7[traceback.title]Traceback [dim](most recent call last)ztraceback.border)rr)titlestyle border_styleexpandpaddingztraceback.border.syntax_error)rrrrr4z: ztraceback.exc_typezI [i]The above exception was the direct cause of the following exception: zH [i]During handling of the above exception, another exception occurred: )$r6get_background_styleget_style_for_tokenr, TextTokenrrrFunctionrrr*rConstant Delimiterrr'rreversedrrrr( _render_stackr%r4 use_themer_render_syntax_errorrassemblerr}rr from_markup) rr3rr6background_style token_styletraceback_theme highlighterlastrstack_renderabler2r2rK__rich_console__s       zTraceback.__rich_console__)rr@ccst}t}|jdkrVtj|jrVtjd|jdfdt|j dfdd}||V||j }d|_ t |jd t|}|d |||tjd d|d dd7}|VdS) Nz r:rrrrTrzbold underline u[traceback.offset]▲[/])r'rrnrrexistsrrrwrorrrstripno_wrapminr|lenstylizer)rrrpath_highlighterrsyntax_error_textr|r2r2rKr5s(   zTraceback._render_syntax_error)rncoder@cCstj|d}|sP|d}|dkr2|d|n|}|drPd|krPdSz|j|pht||j WSt k rYdSXdS)Nrz#!rr) rrsplitextindexrlowerLEXERSrYrrpr)rrnrextnew_line_index first_liner2r2rK _guess_lexerLs zTraceback._guess_lexer)rr@c #sXt}j}ttddd}tttdfdd }d}jdkrbtjdt|j jd}d }t |j D]\}} |r||krd }qp|r|dk st t d t|d d ddVd }|dk} | j tfddjD} tj| j r(t j|t | j dddt| jdfd| jdfdd} n$t jd| jdfdt| jdfdd} | j dsf| sfdV| V| j dr|| EdHqp| spzd|| j } | sWqp| j | }t| ||d | jj| jjf| jhjdjd d }dVWn:tk r,}zt d|dfVW5d}~XYqpX| jrLt|f|| dd n|VqpdS)!N)rnr@cSsdt|S)zRead files, and cache results on filename. Args: filename (str): Filename to read Returns: str: Contents of file rq)r linecachegetlines)rnr2r2rK read_codeas z*Traceback._render_stack..read_code)rr@c3s&|jr"t|jdjjjdVdS)Nrs)rr=rr)rsr)r=r9r:)r)rr2rK render_localslsz.Traceback._render_stack..render_localsrrUFTz ... z frames hidden ...centerztraceback.error)justifyrc3s|]}|VqdS)Nr)rr)frame_filenamer2rK sz*Traceback._render_stack..rrrrz in rrzin rrqX)r6 line_numbers line_rangehighlight_linesr7 code_widthr=dedentrr)r)rr6rwrmr r"r?rZrr enumeraterrrnanyr>rrrrrorprrr+r5r7r=rjrsr)rrrr6rrexclude_framesexcluded frame_indexrfirst suppressedrr lexer_namesyntaxerrorr2)r rrKr\s              zTraceback._render_stack)N)!rtrurv__doc__rLOCALS_MAX_LENGTHLOCALS_MAX_STRINGr rryrwrIr rrr classmethodrrrgrrHrr r!r#rr$r{rrr~rr2r2r2rKrGs  3E} NrG__main__)r )ar@cCsd}t||dS)Nr)rF)r!oner2r2rKbarsr#cCs"d}ddddhdd}t|dS)NTz Paul AtreideszVladimir Harkonnenz Thufir Hawatz Duncan Idaho)NFT) charactersZ atomic_types)r#)r!rZzedr2r2rKfoos r%)r@cCs@z"z tdWntYnXWntjddYnXdS)NrTr)r%Z slfkjsldkfjr3print_exceptionr2r2r2rKrs r)V __future__rrrplatformri dataclassesrrrDrtypesrrtypingrr r r r r rrrrpip._vendor.pygments.lexersrpip._vendor.pygments.tokenrrrrrrrrrpip._vendor.pygments.utilrrqr_looprcolumnsrr3r r!r"r#r$ constrainr%rr&r'panelr(scoper)rr*rr+rr6r,systemWINDOWSrrryrwrIrgrlrmr{r~rrrGrtr#r%rr2r2r2rKs  0