U ʗRee@sddlmZddlZddlZddlZddlmZmZddlm Z ddl m Z m Z ddl mZmZmZmZmZmZmZmZmZddlmZddlmZmZmZmZmZmZdd 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-m.Z.m/Z/m0Z0d dl1m2Z2d dl3m4Z4m5Z5d dl6m7Z7d dl8m9Z9d dl:m;Z;d dlm Z d dl?m@Z@eAdkZBdZCdZDdddddddddd ee,eeEeEeeFeGeGeGeeeFe feEeeeHeHee gefd! d"d#ZIeGd$d%d%ZJeGd&d'd'ZKeGd(d)d)ZLeGd*d+d+ZMGd,d-d-e4ZNGd.d/d/ZOePd0krd d1l+m,Z,e,Z+ddlZedd2d3d4ZQedd2d5d6ZRdd7d8d9ZSeSdS):)absolute_importN) dataclassfield)walk_tb) ModuleType TracebackType) AnyCallableDictIterableListOptionalSequenceTypeUnion)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_locals indent_guidessuppress max_frames) r2r3r4r5r6r7r8r9r:returnc s|dkrttjdn|tttttdd f dd tddfdd } zt} | | tj WSt k rtj } t_ | YSXdS) a8Install 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. 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. N)file)type_value tracebackr;cs*tj|||d dS)N)r3r4r5r6r7r8r9r:)print Tracebackfrom_exception)r=r>r?) r4r8r:r7r9r5traceback_consoler3r6r1/builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/rich/traceback.py excepthookFszinstall..excepthook)ipr;csbijttddfdd }ddtttddfdd_|_fd d _dS) N)argskwargsr;cs|||dS)zEwrap the default ip.showtraceback to store info for ip._showtracebackNr1rGrH)default_showtracebacktb_datar1rDipy_show_traceback_szCinstall..ipy_excepthook_closure..ipy_show_tracebackF) is_syntax)rGrMrHr;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)rMrGrH exc_tupletbcompiledrP_)rErFrKr1rDipy_display_tracebackes  zFinstall..ipy_excepthook_closure..ipy_display_tracebackcs|ddi|S)NrMTr1rI)rYr1rDs z9install..ipy_excepthook_closure..) showtracebackrbool_showtracebackshowsyntaxerror)rFrL)rE)rJrFrYrKrDipy_excepthook_closure[sz'install..ipy_excepthook_closure) rsysstderrr BaseExceptionr rr get_ipythonrE Exception) r2r3r4r5r6r7r8r9r:r_rFold_excepthookr1) rEr4r8r:r7r9r5rCr3r6rDinstall$s  )rfc@sLeZdZUeed<eed<eed<dZeed<dZee ee j fed<dS)FramefilenamelinenonamelineNlocals) __name__ __module__ __qualname__str__annotations__intrlrmr r rNoder1r1r1rDrgs  rgc@s6eZdZUeed<eed<eed<eed<eed<dS) _SyntaxErroroffsetrhrlrimsgN)rnrorprsrrrqr1r1r1rDrus ruc@sPeZdZUeed<eed<dZeeed<dZe ed<e e dZ e eed<dS) Stackexc_type exc_valueN syntax_errorFis_cause)default_factoryframes)rnrorprqrrr{r rur|r\rlistr~r rgr1r1r1rDrxs  rxc@seZdZUeeed<dS)TracestacksN)rnrorpr rxrrr1r1r1rDrs rc@seZdZdgZdS)PathHighlighterz(?P.*/)(?P.+)N)rnrorp highlightsr1r1r1rDrsrc@sReZdZdZddddddZddd dd d d eed df eeee e ee e e e e e e e e efe d ddZedd dd d d eed df eeeeeee e ee e e e e e e e e efe ddddZed eefeeeeee e e edddZeeedddZeeedddZee e e dddZeeedd d!Z dS)"rAaA 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. 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)rkz.pyz.pxdz.pyxz.pxiNr/r0FTr1) tracer3r4r5r6r7r8locals_max_lengthlocals_max_stringr9r: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: blockr7 ansi_darkz+ must be a module with '__file__' attributer)r`exc_info ValueErrorextractrr3r4r* get_themer5r6r7r8rrr9 isinstancerq__file__AssertionErrorospathdirnamenormpathabspathappendmaxr:)selfrr3r4r5r6r7r8rrr9r:ryrzr?suppress_entityrr1r1rD__init__sB zTraceback.__init__)ryrzr?r3r4r5r6r7r8rrr9r:r;c Cs0|j||||d}|||||||| | | | | d S)aCreate 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. 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. r) r3r4r5r6r7r8rrr9r:)r)clsryrzr?r3r4r5r6r7r8rrr9r:rich_tracebackr1r1rDrBs&&zTraceback.from_exception)ryrzr?r7rrr;csg}d}ddlm} ttddd} t| |j| ||d} t|trtt|j pPd|j pXd|j p`d|j phd |j d | _|| | jj} t|D]\} }| jj}|r|d stj|stj| |}| jd drqt|pd|| jj|rfd d| jDndd}| || jddr| jdd=qt|dd}|rb|jrb|j }|}|j}d}q$|j!}|r|jrt|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. 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 propegate.zN)rqrd)rr1r1rDsafe_strSs z#Traceback.extract..safe_str)ryrzr|?rk)rvrhrirlrw<_rich_traceback_omitcs"i|]\}}|tj|dqS)) max_length max_string)rtraverse).0keyr>rrr1rD xsz%Traceback.extract..N)rhrirjrm_rich_traceback_guard __cause__T__suppress_context__)r)#pip._vendor.richrrrqrxrnr SyntaxErrorrurvrhrirrwr{rr~rf_code co_filename startswithrrisabsjoinf_localsrRrgco_nameitemsgetattr __traceback__ __class__ __context__r)rryrzr?r7rrrr|rrstackr frame_summaryline_norhframecauserr1rrDr5sz         zTraceback.extract)r2optionsr;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)rrrrr3z: 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: )$r5get_background_styleget_style_for_tokenr+ TextTokenrrrFunctionrrr)rConstant Delimiterrr&rreversedrrr~r' _render_stackr$r3 use_themer{_render_syntax_errorrassembleryrwrzr| from_markup) rr2rr5background_style token_styletraceback_theme highlighterlastrstack_renderabler1r1rD__rich_console__s       zTraceback.__rich_console__)r{r;ccst}t}|jdkrHtjd|jdfdt|jdfdd}||V||j}d|_ t |j d t |}| d |||tjd d|d dd7}|VdS) Nz r:rrrrTrzbold underline u[traceback.offset]▲[/])r&rrhrrrqrirlrstripno_wrapminrvlenstylizer)rr{rpath_highlighterrsyntax_error_textrvr1r1rDrs&   zTraceback._render_syntax_error)rhcoder;cCstj|d}|sP|d}|dkr2|d|n|}|drPd|krPdSz|j|pht||j WSt k rYdSXdS)Nrz#!rr) rrsplitextindexrlowerLEXERSrRrrjr)rrhrextnew_line_index first_liner1r1rD _guess_lexers zTraceback._guess_lexer)rr;c #s t}j}ittdfdd }tttdfdd }d}jdkrjtjdt|j jd}d }t |j D]\}} |r||krd }qx|r|dk st t d t|d d ddVd }|dk} | j tfddjD} t j|t | j dddt| jdfd| jdfdd} | j ds8| s8dV| V| j dr\|| EdHqx| sxzZ|| j } | j | }t| ||d | jj| jjf| jhjdjd d }dVWn:tk r}zt d|dfVW5d}~XYqxX| jrt|f|| ddn|VqxdS) N)rhr;c sB|}|dkr>t|dddd}|}W5QRX||<|S)zRead files, and cache results on filename. Args: filename (str): Filename to read Returns: str: Contents of file Nrtzutf-8replace)encodingerrors)rRopenread)rhr code_file) code_cacher1rD read_codes z*Traceback._render_stack..read_code)rr;c3s&|jr"t|jdjjjdVdS)Nrm)rr8rr)rmr(r8rr)r)rr1rD render_locals,sz.Traceback._render_stack..render_localsrrNFTz ... z frames hidden ...centerztraceback.error)justifyrc3s|]}|VqdS)N)r)rr)frame_filenamer1rD Osz*Traceback._render_stack..rrrrz in rrrrkX)r5 line_numbers line_rangehighlight_linesr6 code_widthr8dedentrr)r)rr5rqrgr r!r:rSrr~ enumeraterrrhanyr9rrirjrrr*r4r6r8rdrmr)rrrr5rrexclude_framesexcluded frame_indexrfirst suppressedrr lexer_namesyntaxerrorr1)rrrrDrs           zTraceback._render_stack)!rnrorp__doc__rLOCALS_MAX_LENGTHLOCALS_MAX_STRINGr rrsrqr\r rrr classmethodrrrbrrBrrr r"rr#rurrrxrr1r1r1rDrAs  .6k NrA__main__)r)ar;cCsd}t||dS)Nr)r@)roner1r1rDbarsrcCs"d}ddddhdd}t|dS)NTz Paul AtreideszVladimir Harkonnenz Thufir Hawatz Duncan Idaho)NFT) charactersZ atomic_types)r)rrZzedr1r1rDfoos r!)r;cCs@z"z tdWntYnXWntjddYnXdS)NrTr)r!Z slfkjsldkfjr2print_exceptionr1r1r1rDrs r)T __future__rrplatformr` dataclassesrrr?rtypesrrtypingrr r r r r rrrpip._vendor.pygments.lexersrpip._vendor.pygments.tokenrrrrrrrrrpip._vendor.pygments.utilrrkr_looprcolumnsrr2rr r!r"r# constrainr$rr%r&panelr'scoper(rr)rr*rr5r+systemWINDOWSrrrsrqr\rbrfrgrurxrrrArnrr!rr1r1r1rDs  ,                 lT