B
    \                 @   s  d dl mZ yd dlmZ W n ek
r8   eefZY nX d dlZd dl	m
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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dad adad:d d!Zd"d# Z d;d%d&Z!d'd( Z"dZ#d<d)d*Z$d=d+d,Z%i Z&d>d-d.Z'g Z(d/d0 Z)d?d2d3Z*d4d5 Z+e
d@d6d7Z,d8d9 Z-dS )A    )absolute_import)
basestringN)contextmanager   )open_new_file   )
DebugFlags)Optionsc               @   s   e Zd ZdS )
PyrexErrorN)__name__
__module____qualname__ r   r   5lib/python3.7/site-packages/Cython/Compiler/Errors.pyr
      s   r
   c               @   s   e Zd ZdS )PyrexWarningN)r   r   r   r   r   r   r   r      s   r   c             C   s   | d }t |trtd| y| }W n tk
rB   d}Y n>X d|td| 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AssertionError	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_position+   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_strZcontr   r   r   format_error1   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(   :   s    zCompileError.__init__c             C   s   | j S )N)r%   )r*   r   r   r   __str__F   s    zCompileError.__str__)Nr   )r   r   r   r(   r+   r   r   r   r   r#   8   s   
r#   c               @   s   e Zd ZdddZdS )CompileWarningNr   c             C   s   || _ t| t||  d S )N)r   r'   r(   r    )r*   r   r!   r   r   r   r(   K   s    zCompileWarning.__init__)Nr   )r   r   r   r(   r   r   r   r   r,   I   s   r,   c               @   s   e Zd Zdd ZdS )InternalErrorc             C   s   || _ t| d|  d S )NzInternal compiler error: %s)r$   r'   r(   )r*   r!   r   r   r   r(   T   s    zInternalError.__init__N)r   r   r   r(   r   r   r   r   r-   Q   s   r-   c               @   s   e Zd Zdd ZdS )
AbortErrorc             C   s   || _ t| d|  d S )NzAbort error: %s)r$   r'   r(   )r*   r!   r   r   r   r(   \   s    zAbortError.__init__N)r   r   r   r(   r   r   r   r   r.   Y   s   r.   c               @   s   e Zd ZdddZdS )CompilerCrashNc             C   s   |rd| }nd}|| _ |r(d||f }|rLdd l}|dd|| 7 }|rp|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)   )r*   posr   r!   causeZ
stacktracer1   r   r   r   r(   b   s"    
zCompilerCrash.__init__)N)r   r   r   r(   r   r   r   r   r/   `   s   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   r6   x   s   r6   c             C   s.   | d k	rt | and a|r"tjand adad S )Nr   )r   listing_filesysstderr	echo_file
num_errors)pathZecho_to_stderrr   r   r   open_listing_file   s    
r>   c               C   s   t rt   d a d S )N)r8   closer   r   r   r   close_listing_file   s    r@   Tc          	   C   s   t r|rt d |  n| jr"d S d| _yd|  }W n2 tk
rf   tt| ddt| dd d }Y nX tryt| W n& tk
r   t|dd	 Y nX t	ryt	| W n& tk
r   t	|dd	 Y nX t
d
7 a
tjrtdd S )NTz%s
r$   z[unprintable exception message]r   r0   ASCIIreplacer   zfatal errors)error_stackappendr&   UnicodeEncodeErrorr"   getattrr8   writeencoder;   r<   r	   Z	fast_failr.   )errZ	use_stackliner   r   r   report_error   s.        rL   c             C   s4   | d krt |t| |}tjr(t|t| |S )N)r-   r#   r   Zdebug_exception_on_errorr'   rL   )r   r!   rJ   r   r   r   error   s    
 rM   c             C   s>   |t k rd S t| |}d| }tr,t| tr:t| |S )Nz	note: %s
)LEVELr,   r8   rH   r;   )r   r!   levelwarnrK   r   r   r   r!      s    


r!   c             C   sR   |t k rd S tjr | r t| |S t| |}d| }tr@t| trNt| |S )Nzwarning: %s
)rN   r	   Zwarning_errorsrM   r,   r8   rH   r;   )r   r!   rO   rP   rK   r   r   r   warning   s    




rQ   c             C   sN   |t k s|tkrd S t| |}d| }tr4t| trBt| dt|< |S )Nzwarning: %s
T)rN   _warn_once_seenr,   r8   rH   r;   )r   r!   rO   rP   rK   r   r   r   	warn_once   s    


rS   c               C   s   t g  d S )N)rD   rE   r   r   r   r   hold_errors   s    rT   Fc             C   s&   t  }| s"x|D ]}t| qW d S )N)rD   poprL   )ignoreheld_errorsrJ   r   r   r   release_errors   s    
rX   c               C   s   t d S )NrA   )rD   r   r   r   r   rW      s    rW   c          	   c   s*   g }t | z
|V  W d t| d X d S )N)rV   )rD   rE   rX   )rV   errorsr   r   r   local_errors   s
    

rZ   c               C   s   t   td d = d S )N)rR   clearrD   r   r   r   r   reset  s    r\   )r   )T)r   )r   )r   )F)F).Z
__future__r   Z__builtin__r   r   ImportErrorbytesstrr9   
contextlibr   ZUtilsr   r   r   r	   r'   r
   r   r   r    r"   r#   r,   r-   r.   r/   r6   r8   r<   r;   r>   r@   rL   rM   rN   r!   rQ   rR   rS   rD   rT   rX   rW   rZ   r\   r   r   r   r   <module>   sN   






