o
    Ni                     @  s   U d dl mZ d dlZd dlZd dlZd dlmZmZ d dlm	Z	 er)d dl
mZ edZded< d&ddZd&ddZd'ddZd(ddZejddddd)d$d%ZdS )*    )annotationsN)TYPE_CHECKINGTextIO)SphinxParallelError)Sphinxz.*?mzre.Pattern[str]_ANSI_COLOUR_CODESsstrreturnc                C  s   |  dddS )z4Safely encode a string for printing to the terminal.asciibackslashreplace)encodedecoder    r   K/home/ubuntu/.local/lib/python3.10/site-packages/sphinx/_cli/util/errors.pyterminal_safe   s   r   c                C  s   t d|  S )N )r   substripr   r   r   r   strip_colors   s   r   messages
extensions	tracebackc                 C  s   dd l }dd l}dd l}dd l}dd l}dtj  d|   d|  d|  d|j d|j	 d|j	 d	|j	 d
|  d| d| dS )Nr   z'Versions
========

* Platform:         z; (z)
* Python version:    (z)
* Sphinx version:   z
* Docutils version: z
* Jinja2 version:   z
* Pygments version: z

Last Messages
=============

z'

Loaded Extensions
=================

z

Traceback
=========


)
platformdocutilsjinja2pygmentssphinxsyspython_versionpython_implementation__display_version____version__)r   r   r   r   r   r   r   r    r   r   r   
error_info   s8   	r&   appSphinx | NoneexcBaseExceptionc                 C  s   t |trd|j }nddl}| }d }}| dur5| j }ddd | jD }ddd |D }tj	d	d
dd}|
t|||d W d   |jS 1 sVw   Y  |jS )z9Save the given exception's traceback in a temporary file.z(Error in parallel process)
r   Nr   r   c                 s  s    | ]
}d t | V  qdS )* N)r   ).0r   r   r   r   	<genexpr>J   s    z!save_traceback.<locals>.<genexpr>c                 s  s0    | ]}|j d krd|j d|j  dV  qdS )builtinr+   r   )N)versionname)r,   extr   r   r   r-   K   s    
z.logzsphinx-err-F)suffixprefixdeletezutf-8)
isinstancer   r   
format_excr   valuesjoin
messagelogtempfileNamedTemporaryFilewriter&   r   r1   )r'   r)   
exc_formatr   	last_msgs	exts_listr   fr   r   r   save_traceback>   s(   



rB   F)stderruse_pdbprint_tracebackr'   	exceptionrC   r   rD   boolrE   Nonec                 s  ddl m} ddlm}m} ddlm} ddlm ddl	m
}	 ddlm}
 t| |r-d S d!fdd d! fdd}   |sC|rK|d    |r^ddlm} ||
d |  d S t| trk |
d d S t| |r~||
d  t|  d S t| |	r|| j d  t|  d S t| tr||
d  t|  d S t| tr||
d  t|      |
d  d d S |j| dd}|j d d|   }||
d  | t|| } |
d  |     |
d  |
d  d S )"Nr   )BdbQuit)TracebackException	print_exc)SystemMessage)red)SphinxError)__r8   r	   r
   rH   c                    s   t | d i d S )Nfile)printr8   )rC   r   r   	print_errn      z#handle_exception.<locals>.print_errc                    s    t |   d S )N)maprR   )rS   rM   r   r   	print_redq   rT   z#handle_exception.<locals>.print_red)rP   )post_mortemz&Exception occurred, starting debugger:zInterrupted!zreStructuredText markup error::zEncoding error:zRecursion error:zThis can happen with very large or deeply nested source files. You can carefully increase the default Python recursion limit of 1000 in conf.py with e.g.:z1
    import sys
    sys.setrecursionlimit(1_500)
)limitr   zException occurred:z%The full traceback has been saved in:zwTo report this error to the developers, please open an issue at <https://github.com/sphinx-doc/sphinx/issues/>. Thanks!ziPlease also report this if it was a user error, so that a better error message can be provided next time.)r8   r	   r
   rH   )bdbrI   r   rJ   rK   docutils.utilsrL   sphinx._cli.util.colourrM   sphinx.errorsrN   sphinx.localerO   r6   pdbrW   KeyboardInterruptr	   categoryUnicodeErrorRecursionErrorfrom_exceptionstackformatr9   format_exception_onlyrstriprB   )rF   rC   rD   rE   r'   rI   rJ   rK   rL   rN   rO   rV   rW   teformatted_tbtraceback_info_pathr   )rS   rM   rC   r   handle_exceptionY   s~   	






 
rm   )r   r	   r
   r	   )r   r	   r   r	   r   r	   r
   r	   )r'   r(   r)   r*   r
   r	   )rF   r*   rC   r   rD   rG   rE   rG   r'   r(   r
   rH   )
__future__r   rer!   r;   typingr   r   r^   r   sphinx.applicationr   compiler   __annotations__r   r   r&   rB   rC   rm   r   r   r   r   <module>   s$    



%