o
    e#                     @   s  d dl mZ zd dlmZ W n ey   eefZY nw d dlZd dl	m
Z
 zd dlmZ W n ey?   G dd de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'dFd0d1Z(dGd2d3Z)dGd4d5Z*d6d7 Z+dHd9d:Z,d;d< Z-e
dHd=d>Z.d?d@ Z/dAdB Z0dCdD Z1dS )I    )absolute_import)
basestringN)contextmanager)localc                   @      e Zd ZdS )_threadlocalN__name__
__module____qualname__ r   r   FD:\Projects\ConvertPro\env\Lib\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f }|S )Nr   zOPlease replace filename strings with Scanning.FileSourceDescriptor instances %rz[unprintable code]
 r      z
...
%s%s^
 r   z%s
%s%s
z<------------------------------------------------------------)
isinstanceany_string_type	get_linesUnicodeDecodeErrorjoinmax)positionsourceFsr   r   r   context%   s   $r$   c                 C   s&   | rd| d   | d | d f S dS )Nz
%s:%d:%d: r   r   r   r   )Zget_error_description)r    r   r   r   format_position4   s
   r%   c                 C   s*   |rt |}t|}d||| pdf } | S )Nz%
Error compiling Cython file:
%s
%s%sr   )r%   r$   )messager    Zpos_strcontr   r   r   format_error:   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   r.   C   s   zCompileError.__init__c                 C   s   | j S N)r+   )r1   r   r   r   __str__M      zCompileError.__str__Nr   )r	   r
   r   r.   r3   r   r   r   r   r)   A   s    

r)   c                   @   s   e Zd ZdddZdS )CompileWarningNr   c                 C   s   || _ t| t||  d S r2   )r    r-   r.   r%   r0   r   r   r   r.   R   s   zCompileWarning.__init__r5   r	   r
   r   r.   r   r   r   r   r6   P       r6   c                   @      e Zd Zdd ZdS )InternalErrorc                 C      || _ t| d|  d S )NzInternal compiler error: %sr*   r-   r.   r1   r&   r   r   r   r.   Y   s   
zInternalError.__init__Nr7   r   r   r   r   r:   V       r:   c                   @   r9   )
AbortErrorc                 C   r;   )NzAbort error: %sr<   r=   r   r   r   r.   a   s   zAbortError.__init__Nr7   r   r   r   r   r?   ^   r>   r?   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 )N
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)   r.   r/   )r1   posr$   r&   causeZ
stacktracerB   r   r   r   r.   g   s&   
zCompilerCrash.__init__r2   r7   r   r   r   r   r@   e   r8   r@   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   rG   }   s    rG   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)pathZecho_to_stderrr   r   r   open_listing_file   s   

rQ   c                   C   s   t jrt j  d t _d S d S r2   )rJ   rK   closer   r   r   r   close_listing_file   s   

rS   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    rA   ASCIIreplacer   zfatal errors)rJ   cython_errors_stackappendr,   UnicodeEncodeErrorr(   getattrrK   writeencoderN   rO   r   Z	fast_failr?   )errZ	use_stackZerror_stacklinelisting_file	echo_filer   r   r   report_error   s:   

ra   c                 C   s4   | d u rt |t| |}tjrt|t| |S r2   )r:   r)   r   Zdebug_exception_on_errorr-   ra   )r    r&   r]   r   r   r   error   s   
rb   c              	   C   s8   z|  | W d S  ty   |  |dd Y d S w )NasciirV   )r[   rY   r\   )filer^   r   r   r   _write_file_encode   s
   re   c                 C   sJ   |t k rd S t| |}d| }tj}|rt|| tj}|r#t|| |S )Nz	note: %s
)LEVELr6   rJ   rK   re   rN   r    r&   levelwarnr^   r_   r`   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 )Nwarning: %s
)	rf   r   Zwarning_errorsrb   r6   rJ   rK   re   rN   rg   r   r   r   warning   s   




rk   c                 C   sd   |t k rd S tj}||v rd S t| |}d| }tj}|r"t|| tj}|r,t|| d||< |S )Nrj   T)rf   rJ   cython_errors_warn_once_seenr6   rK   re   rN   )r    r&   rh   Zwarn_once_seenri   r^   r_   r`   r   r   r   	warn_once   s   


rm   c                  C   s   g } t j|  | S r2   )rJ   rW   rX   )errorsr   r   r   hold_errors   s   ro   Fc                 C   s(   t j }| s|D ]}t| q	d S d S r2   )rJ   rW   popra   )ignoreheld_errorsr]   r   r   r   release_errors   s   

rs   c                   C   s
   t jd S )NrT   )rJ   rW   r   r   r   r   rr     s   
rr   c              	   c   s,    t  }z|V  W t| d d S t| d w )N)rq   )ro   rs   )rq   rn   r   r   r   local_errors  s
   rt   c                   C   s$   dt _d t _d t _t t _g t _d S rI   )rJ   rO   rK   rN   setrl   rW   r   r   r   r   init_thread  s
   
rv   c                   C   s   t j  t jd d = d S r2   )rJ   rl   clearrW   r   r   r   r   reset  s   
rx   c                   C   s   t jS r2   )rJ   rO   r   r   r   r   get_errors_count  r4   ry   )T)r   )r   )F)2
__future__r   __builtin__r   r   ImportErrorbytesstrrL   
contextlibr   	threadingr   r   objectrJ   ZUtilsr   r   r   r   r-   r   r   r   r$   r%   r(   r)   r6   r:   r?   r@   rG   rQ   rS   ra   rb   rf   re   r&   rk   rm   ro   rs   rr   rt   rv   rx   ry   r   r   r   r   <module>   s\   







