U
    †µ“e¶	  ã                   @   sÖ   d dl mZ d dlZd dlZd dlZzd dlmZ dZW nh ek
r    dZzd dl	m
Z W n> ek
rš   zd dl	mZ W n ek
r”   dZY nX Y nX Y nX dd	lmZ dd
lmZ dd„ ZG dd„ deƒZdS )é    )Úabsolute_importN)ÚetreeTF)ÚcElementTree)ÚElementTreeé   )ÚErrors)ÚEncodedStringc                 C   s,   t | tƒr(|  d¡r(| dd…  ¡ r(dS dS )zÈ
    Names like '.0' are used internally for arguments
    to functions creating generator expressions,
    however they are not identifiers.

    See https://github.com/cython/cython/issues/5552
    Ú.é   NFT)Ú
isinstancer   Ú
startswithÚ	isdecimal)Úname© r   ú?/tmp/pip-unpacked-wheel-7k3cqui1/Cython/Debugger/DebugWriter.pyÚis_valid_tag   s    
r   c                   @   s:   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ Zdd„ ZdS )ÚCythonDebugWriterz¥
    Class to output debugging information for cygdb

    It writes debug information to cython_debug/cython_debug_info_<modulename>
    in the build directory.
    c                 C   sN   t d krt ¡ ‚tj |ptjd¡| _t  ¡ | _	d | _
| jdtddd d S )NÚcython_debugz1.0)Úversion)Úattrs)r   r   ZNoElementTreeInstalledExceptionÚosÚpathÚjoinÚcurdirÚ
output_dirÚTreeBuilderÚtbÚmodule_nameÚstartÚdict)Úselfr   r   r   r   Ú__init__.   s    
zCythonDebugWriter.__init__Nc                 C   s   t |ƒr| j ||pi ¡ d S ©N)r   r   r   ©r    r   r   r   r   r   r   8   s    zCythonDebugWriter.startc                 C   s   t |ƒr| j |¡ d S r"   )r   r   Úend)r    r   r   r   r   r$   <   s    zCythonDebugWriter.endc                 K   s&   t |ƒr"| j ||¡ | j |¡ d S r"   )r   r   r   r$   r#   r   r   r   Ú	add_entry@   s    zCythonDebugWriter.add_entryc              
   C   sà   | j  d¡ | j  d¡ | j  ¡ }zt | j¡ W n0 tk
rb } z|jtjkrR‚ W 5 d }~X Y nX t	 
|¡}i }tr~d|d< d| j }|jtj | j|¡fddi|—Ž tj | jd¡}t|d	ƒ}| tj¡ W 5 Q R X d S )
NÚModuler   TZpretty_printZcython_debug_info_ÚencodingzUTF-8ÚinterpreterÚw)r   r$   Úcloser   Úmakedirsr   ÚOSErrorÚerrnoÚEEXISTr   r   Ú	have_lxmlr   Úwriter   r   ÚopenÚsysÚ
executable)r    Zxml_root_elementÚeÚetÚkwÚfnZinterpreter_pathÚfr   r   r   Ú	serializeE   s"    


"zCythonDebugWriter.serialize)N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r!   r   r$   r%   r9   r   r   r   r   r   &   s   

r   )Ú
__future__r   r   r2   r-   Úlxmlr   r/   ÚImportErrorZ	xml.etreer   r   ZCompilerr   ZCompiler.StringEncodingr   r   Úobjectr   r   r   r   r   Ú<module>   s&   