a
    b                     @   s  d dl mZ zd dlmZ W n ey6   eefZY n0 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   f/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/Cython/Compiler/Errors.pyr
      s   r
   c                   @   s   e Zd ZdS )PyrexWarningNr   r   r   r   r   r      s   r   c                 C   s   | d }t |trJ d| z| }W n ty@   d}Y n>0 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	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_str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 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__Nr0   r   r   r   r   r1   Q   s   r1   c                   @   s   e Zd Zdd ZdS )
AbortErrorc                 C   s   || _ t| d|  d S )NzAbort error: %sr2   r3   r   r   r   r)   \   s    zAbortError.__init__Nr0   r   r   r   r   r4   Y   s   r4   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
stacktracer7   r   r   r   r)   b   s&    
zCompilerCrash.__init__)Nr0   r   r   r   r   r5   `   s   r5   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   r<   x   s   r<   c                 C   s.   | d u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    
rD   c                   C   s   t rt   d a d S r-   )r>   closer   r   r   r   close_listing_file   s    rF   Tc              	   C   s   t r|rt d |  n| jr"d S d| _zd|  }W n0 tyd   tt| ddt| dd d }Y n0 trzt| W n$ ty   t|dd	 Y n0 t	rzt	| W n$ ty   t	|dd	 Y n0 t
d
7 a
tjrtdd S )NTz%s
r%   z[unprintable exception message]r   r6   ASCIIreplacer   zfatal errors)error_stackappendr'   UnicodeEncodeErrorr#   getattrr>   writeencoderA   rB   r	   Z	fast_failr4   )errZ	use_stackliner   r   r   report_error   s,    


rR   c                 C   s4   | d u rt |t| |}tjr(t|t| |S r-   )r1   r$   r   Zdebug_exception_on_errorr(   rR   )r   r!   rP   r   r   r   error   s    
rS   c                 C   s>   |t k rd S t| |}d| }tr,t| tr:t| |S )Nz	note: %s
)LEVELr/   r>   rN   rA   r   r!   levelwarnrQ   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 )Nwarning: %s
)rT   r	   Zwarning_errorsrS   r/   r>   rN   rA   rU   r   r   r   warning   s    




rY   c                 C   sN   |t k s|tv rd S t| |}d| }tr4t| trBt| dt|< |S )NrX   T)rT   _warn_once_seenr/   r>   rN   rA   rU   r   r   r   	warn_once   s    


r[   c                   C   s   t g  d S r-   )rJ   rK   r   r   r   r   hold_errors   s    r\   Fc                 C   s"   t  }| s|D ]}t| qd S r-   )rJ   poprR   )ignoreheld_errorsrP   r   r   r   release_errors   s    r`   c                   C   s   t d S )NrG   )rJ   r   r   r   r   r_      s    r_   c              	   c   s4   g }t | z|V  W t| d nt| d 0 d S )N)r^   )rJ   rK   r`   )r^   errorsr   r   r   local_errors   s
    
rb   c                   C   s   t   td d = d S r-   )rZ   clearrJ   r   r   r   r   reset  s    rd   )r   )T)r   )r   )r   )F)F).
__future__r   __builtin__r   r   ImportErrorbytesstrr?   
contextlibr   ZUtilsr   r   r   r	   r(   r
   r   r   r    r#   r$   r/   r1   r4   r5   r<   r>   rB   rA   rD   rF   rR   rS   rT   r!   rY   rZ   r[   rJ   r\   r`   r_   rb   rd   r   r   r   r   <module>   sN   






