U
    {±Ëhç  ã                   @   s„   d dl Z d dlZd dlZzd dlmZ dZW n$ ek
rP   dZd dlmZ Y nX ddl	m
Z
 ddlmZ d	d
„ ZG dd„ dƒZdS )é    N)ÚetreeTF)Ú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-fhl22ezh/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   0   s    zCythonDebugWriter.startc                 C   s   t |ƒr| j |¡ d S r    )r   r   Úend)r   r   r   r   r   r"   4   s    zCythonDebugWriter.endc                 K   s&   t |ƒr"| j ||¡ | j |¡ d S r    )r   r   r   r"   r!   r   r   r   Ú	add_entry8   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   Ú	serialize=   s"    


"zCythonDebugWriter.serialize)N)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r"   r#   r7   r   r   r   r   r      s   

r   )r   r0   r+   Úlxmlr   r-   ÚImportErrorZ	xml.etreer   ZCompilerr   ZCompiler.StringEncodingr   r   r   r   r   r   r   Ú<module>   s   