o
    Ni#                     @   s  e efZd dlZd dlmZ zd dlmZ W n e	y&   G dd dZY nw e Z
ddlmZ dd	lmZ dd
lmZ G dd deZG dd deZG dd deZdd Zdd 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dEd$d%Zd&d' ZdEd(d)Zd*d+ Z dZ!d,d- Z"d.d/ Z#dFd0d1Z$dGd2d3Z%dGd4d5Z&d6d7 Z'dHd9d:Z(d;d< Z)edHd=d>Z*d?d@ Z+dAdB Z,dCdD Z-dS )I    N)contextmanager)localc                   @      e Zd ZdS )_threadlocalN__name__
__module____qualname__ r
   r
   J/home/ubuntu/.local/lib/python3.10/site-packages/Cython/Compiler/Errors.pyr      s    r      )open_new_file   )
DebugFlags)Optionsc                   @   r   )
PyrexErrorNr   r
   r
   r
   r   r          r   c                   @   r   )PyrexWarningNr   r
   r
   r
   r   r      r   r   c                   @   r   )CannotSpecializeNr   r
   r
   r
   r   r      r   r   c                 C   s   | d }t |trJ d| z| }W n ty    d}Y nw d|td| d d | d  }d|d| d	  f }d
}| d| d| d}|S )Nr   zOPlease replace filename strings with Scanning.FileSourceDescriptor instances %rz[unprintable code]
r      z
...
%s
%s^ r   z<------------------------------------------------------------)
isinstanceany_string_type	get_linesUnicodeDecodeErrorjoinmax)positionsourceFshbarr
   r
   r   context    s   $r#   c                 C   s&   | rd| d   | d | d f S dS )Nz
%s:%d:%d: r   r   r    )get_error_description)r   r
   r
   r   format_position1   s
   r&   c                 C   s*   |rt |}t|}d||| pdf } | S )Nz$
Error compiling Cython file:
%s%s%sr$   )r&   r#   )messager   pos_strcontr
   r
   r   format_error7   s
   r*   c                   @   s   e Zd ZdddZdd ZdS )CompileErrorNr$   c                 C   s:   || _ || _t||| _d| _t| | j ||f| _d S )NF)r   message_onlyr*   formatted_messagereported	Exception__init__argsselfr   r'   r
   r
   r   r0   @   s   zCompileError.__init__c                 C   s   | j S N)r-   )r3   r
   r
   r   __str__J      zCompileError.__str__Nr$   )r   r   r	   r0   r5   r
   r
   r
   r   r+   >   s    

r+   c                   @   s   e Zd ZdddZdS )CompileWarningNr$   c                 C   s   || _ t| t||  d S r4   )r   r/   r0   r&   r2   r
   r
   r   r0   O   s   zCompileWarning.__init__r7   r   r   r	   r0   r
   r
   r
   r   r8   M       r8   c                   @      e Zd Zdd ZdS )InternalErrorc                 C      || _ t| d|  d S )NzInternal compiler error: %sr,   r/   r0   r3   r'   r
   r
   r   r0   V   s   
zInternalError.__init__Nr9   r
   r
   r
   r   r<   S       r<   c                   @   r;   )
AbortErrorc                 C   r=   )NzAbort error: %sr>   r?   r
   r
   r   r0   ^   s   zAbortError.__init__Nr9   r
   r
   r
   r   rA   [   r@   rA   c                   @   s   e Zd ZdddZdS )CompilerCrashNc                 C   s   |rd| }nd}|| _ |rd||f }|r&dd l}|dd|| 7 }|r8|s.|d7 }|d|jj|f 7 }t| || |||||f| _d S )Nr   zCompiler crash in %s%sr   z/

Compiler crash traceback from this point on:
r$   z%s: %s)	r,   	tracebackr   	format_tb	__class__r   r+   r0   r1   )r3   posr#   r'   cause
stacktracerC   r
   r
   r   r0   d   s&   
zCompilerCrash.__init__r4   r9   r
   r
   r
   r   rB   b   r:   rB   c                   @   s   e Zd ZdZdS )NoElementTreeInstalledExceptionzcraised when the user enabled options.gdb_debug but no ElementTree
    implementation was found
    N)r   r   r	   __doc__r
   r
   r
   r   rI   z   s    rI   Tc                 C   s8   | d ur
t | t_nd t_|rtjt_nd t_dt_d S Nr   )r   threadlocalcython_errors_listing_filesysstderrcython_errors_echo_filecython_errors_count)pathecho_to_stderrr
   r
   r   open_listing_file   s   

rT   c                   C   s   t jrt j  d t _d S d S r4   )rL   rM   closer
   r
   r
   r   close_listing_file   s   

rV   c              	   C   s
  t j}|r|r|d |  d S | jrd S d| _zd|  }W n ty6   tt| ddt| dd d }Y nw t j}|rVz|| W n tyU   ||	dd	 Y nw t j
}|ruz|| W n tyt   ||	dd	 Y nw t  jd
7  _tjrtdd S )NTz%s
r,   z[unprintable exception message]r   r   ASCIIreplacer   zfatal errors)rL   cython_errors_stackappendr.   UnicodeEncodeErrorr*   getattrrM   writeencoderP   rQ   r   	fast_failrA   )err	use_stackerror_stacklinelisting_file	echo_filer
   r
   r   report_error   s:   

rg   c                 C   s4   | d u rt |t| |}tjrt|t| |S r4   )r<   r+   r   debug_exception_on_errorr/   rg   )r   r'   ra   r
   r
   r   error   s   
ri   c              	   C   s8   z|  | W d S  ty   |  |dd Y d S w )NasciirY   )r^   r\   r_   )filerd   r
   r
   r   _write_file_encode   s
   rl   c                 C   sL   |j d sd S t| |}d| }tj}|rt|| tj}|r$t|| |S )Nshow_performance_hintszperformance hint: %s
)
directivesr8   rL   rM   rl   rP   )r   r'   envwarnrd   re   rf   r
   r
   r   performance_hint   s   



rq   c                 C   sJ   |t k rd S t| |}d| }tj}|rt|| tj}|r#t|| |S )Nz	note: %s
)LEVELr8   rL   rM   rl   rP   r   r'   levelrp   rd   re   rf   r
   r
   r   r'      s   


r'   c                 C   s^   |t k rd S tjr| rt| |S t| |}d| }tj}|r#t|| tj}|r-t|| |S Nzwarning: %s
)	rr   r   warning_errorsri   r8   rL   rM   rl   rP   rs   r
   r
   r   warning   s   




rw   c                 C   sf   |t k rd S tj}||v rd S t| |}d| }tj}|r"t|| tj}|r,t|| || |S ru   )rr   rL   cython_errors_warn_once_seenr8   rM   rl   rP   add)r   r'   rt   warn_once_seenrp   rd   re   rf   r
   r
   r   	warn_once   s   



r{   c                  C   s   g } t j|  | S r4   )rL   rZ   r[   )errorsr
   r
   r   hold_errors   s   r}   Fc                 C   s(   t j }| s|D ]}t| q	d S d S r4   )rL   rZ   poprg   )ignoreheld_errorsra   r
   r
   r   release_errors  s   

r   c                   C   s
   t jd S )NrW   )rL   rZ   r
   r
   r
   r   r     s   
r   c              	   c   s,    t  }z|V  W t| d d S t| d w )N)r   )r}   r   )r   r|   r
   r
   r   local_errors  s
   r   c                   C   s$   dt _d t _d t _t t _g t _d S rK   )rL   rQ   rM   rP   setrx   rZ   r
   r
   r
   r   init_thread  s
   
r   c                   C   s   t j  t jd d = d S r4   )rL   rx   clearrZ   r
   r
   r
   r   reset$  s   
r   c                   C   s   t jS r4   )rL   rQ   r
   r
   r
   r   get_errors_count(  r6   r   )T)r   )r   )F).bytesstrr   rN   
contextlibr   	threadingr   r   ImportErrorrL   Utilsr   r$   r   r   r/   r   r   r   r#   r&   r*   r+   r8   r<   rA   rB   rI   rT   rV   rg   ri   rr   rl   rq   r'   rw   r{   r}   r   r   r   r   r   r   r
   r
   r
   r   <module>   sT   







