o
    f}                  	   @   sL  d dl mZmZ d dlZd dlZd dlZd dlZejdd dk s2dejdd   kr0dk rFn nej	de
ejdd   ed zd d	lmZ W n eyY   eZY nw dd
lmZ ddlmZ ddlmZmZ ddlmZmZmZmZ ddlmZ ddlmZ ddlmZ ddlmZm Z  ddl!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' dd Z(d)e$e(e&e%e(e'Z*e+d)e*Z*ej,-ej,.ej,/ej,/e0dZ1G dd de2Z3dd Z4dd Z5d7dd Z6G d!d" d"e2Z7G d#d$ d$e2Z8G d%d& d&e9Z:d8d'd(Z;d)d* Z<d7d+d,Z+ej=d9d/d0Z>ej=d1d2 Z?d3d4 Z@d:d5d6ZAdS );    )absolute_importprint_functionN   )r      )   r   )r   r   z7Sorry, Cython requires Python 2.7 or 3.3+, found %d.%d
   )
basestring)Errors)EncodedString)PyrexScannerFileSourceDescriptor)
PyrexErrorCompileErrorerrorwarning)ModuleScope)Utils)Options)CompilationOptionsdefault_options)parse_command_line)unicode_start_ch_anyunicode_continuation_ch_anyunicode_start_ch_rangeunicode_continuation_ch_rangec              	   C   sB   g }t dt| dD ]}|d| | | |d   q
d|S )Nr   r   z{0}-{1}r    )rangelenappendformatjoin)chrsouti r$   P/var/www/html/mig_web/myenv/lib/python3.10/site-packages/Cython/Compiler/Main.py_make_range_re'   s    
r&   z[{0}{1}][{0}{2}{1}{3}]*z{0}(\.{0})*$Includesc                   @   s  e Zd ZdZdZ		d;ddZedd Zdd Zd<d	d
Z	dd Z
dd Zd=ddZedd Zedd Z		d>ddZd?ddZd?ddZd@ddZ	dAdd Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zd=d/d0Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!dS )BContextNFc                 C   s   ddl m}m} d|ji| _|| | _| j| jd< || _t | _	|| _
|| _|| _i | _i | _|d ur9| | | j
dd| _d | _d S )Nr   )BuiltinCythonScope__builtin__cythonlegacy_implicit_noexceptF)r   r)   r*   builtin_scopemodulescreate_cython_scopecython_scopeinclude_directoriessetfuture_directivescompiler_directivescppoptionspxds	_internedset_language_levelgetr-   gdb_debug_outputwriter)selfr2   r5   r6   language_levelr7   r)   r*   r$   r$   r%   __init__H   s   

zContext.__init__c                 C   s   | |j |j|j|j|dS )N)r7   )include_pathr5   cplusr>   )clsr7   r$   r$   r%   from_optionsb   s   

zContext.from_optionsc                 C   s   ddl m}m}m}m}m} t }|dkrd}nt|}|dkr%|| |dkr2|	||||g || _
|| _|dkrF| jd | jd< d S d S )Nr   )r   unicode_literalsr   divisiongenerator_stop3strr   r+   builtins)Futurer   rD   r   rE   rF   r3   intaddupdater>   r4   r/   )r=   levelr   rD   r   rE   rF   r4   r$   r$   r%   r:   g   s   
zContext.set_language_levelc                 C   sJ   t ||f}z| j| W S  ty   Y nw t |}|r||_|| j|< |S N)r
   r9   KeyErrorencoding)r=   valuerP   keyr$   r$   r%   intern_ustringw   s   

zContext.intern_ustringc           	      C   sv   ddl m} t|tr,|jdkr,t||t }t|| j	}|
| |}|||}|S || ||}|||}|S )Nr   Pipelinepyx)r   rU   
isinstancer   
_file_typeCompilationSourceosgetcwdcreate_default_resultobjr7   create_pyx_as_pxd_pipelinerun_pipelinecreate_pxd_pipeline)	r=   source_descscopemodule_namerU   sourceresult_sinkpipelineresultr$   r$   r%   process_pxd   s   zContext.process_pxdc                 C   
   t |S rN   )r	   report_error)r=   excr$   r$   r%   nonfatal_error      
zContext.nonfatal_errorc                 C   sp   | d}| }dd |D }|dkr6d}dD ]}| j||d d | d}|r.| |} nq|||f |S )N.c                 S   s   g | ]}|d fqS )Tr$   ).0pr$   r$   r%   
<listcomp>   s    z1Context._split_qualified_name.<locals>.<listcomp>r?   F).py.pyx)suffix
source_possource_file_pathsys_path)splitpopsearch_include_directories_is_init_filer   )r=   qualified_namerelative_importqualified_name_parts	last_part
is_packagers   pathr$   r$   r%   _split_qualified_name   s   

zContext._split_qualified_namec                 C   s   | r
t j| dv S dS )N)z__init__.pyxz__init__.pyz__init__.pxdF)rZ   r   basename)r   r$   r$   r%   rz      s   zContext._is_init_filec                 C   sN   |sd S t j|}d|v r#|t j|d kr%t| d| dd d S d S d S )Nrm   r   ^Dotted filenames ('%s') are deprecated. Please use the normal Python package directory layout.r   rM   )rZ   r   r   splitextr   )pospxd_pathnamer{   pxd_filenamer$   r$   r%   _check_pxd_filename   s   
zContext._check_pxd_filenamer   Tc                 C   sf  d}|rt d||||f  d }d }	|r$|r||}
n
|j}
|}d }n|}
t|
s7t|p2|ddfd| |rd|r?t d ||}|sd| j|
|| d}	| ||	|
 |	rd| 	|	}|j
||d}|s|rlt d |rp|}
| }| j|
|dD ]\}}|j
||d}qy|rt d	|  |js1|rt d
 |	s|rt d | j|
||o| d}	| ||	|
 |rt d|	  |	s|rd|_| j|
d|| d}|r|tjrnt|d|
dtj  |	r1d|_z@|rt d|	  |dtjtj|	d  }|	|s|	}t|	|}| |||
\}}|r||\}}||f| j|< W |S  ty0   Y |S w |S )Nr   zPContext.find_module: module_name = %s, from_module = %s, pos = %s, need_pxd = %sz'%s' is not a valid module namez...trying relative importrv   )
as_packagez...trying absolute import)r|   z...scope = %sz...pxd not loadedz...looking for pxd filez......found %sTrq   )rs   rt   rv   z'%s.pxd' not foundrm   zContext.find_module: Parsing %sr   )printqualify_namer{   module_name_patternmatchr   lookup_submodulefind_pxd_filer   rz   find_submoduler   pxd_file_loadedry   endswithr   PACKAGE_FILESr   replacerZ   sepr   r   r   rg   r8   )r=   rb   from_moduler   need_pxdabsolute_fallbackr|   debug_find_modulera   r   r{   r   namepackage_pathnamerel_pathr`   errrf   pxd_codenodes	pxd_scoper$   r$   r%   find_module   s   	




zContext.find_modulec                 C   s6   | j |d|||d}|d u rtjr| j|||dS |S )N.pxdrs   rt   rv   ru   r   )ry   r   cimport_from_pyxfind_pyx_file)r=   r{   r   rv   ru   pxdr$   r$   r%   r     s   	
zContext.find_pxd_filec                 C   s   | j |d|||dS )Nrr   r   )ry   )r=   r{   r   rv   ru   r$   r$   r%   r     s   
zContext.find_pyx_filec                 C   s(   | j ||d|d}|st|d|  |S )NT)rt   includeru   z'%s' not found)ry   r   )r=   filenamer   ru   r   r$   r$   r%   find_include_file%  s   zContext.find_include_filec                 C   s8   | j }|r
|tj }t|tg }t|||pd|||S )Nr   )r2   sysr   tuplestandard_include_pathry   )r=   r{   rs   rt   r   rv   ru   include_dirsr$   r$   r%   ry   .  s   
z"Context.search_include_directoriesc                 C   rh   rN   )r   find_root_package_dir)r=   	file_pathr$   r$   r%   r   8  rl   zContext.find_root_package_dirc                 C   s   t |t|S rN   )r   check_package_dirr   )r=   dirpackage_namesr$   r$   r%   r   ;  s   zContext.check_package_dirc                 C   s   t j|sdS t|}t||rdS t|d}t j|r)t||r)dS | |D ](\}}|dkr>| j||d}n|dkrJ| j	||d}nq.|rVt||rV dS q.dS )Nr   r   cimport)ru   r   r   )
rZ   r   existsr   modification_timefile_newer_thanreplace_suffixread_dependency_filer   ry   )r=   source_pathoutput_pathc_timepxd_pathkindr   dep_pathr$   r$   r%   c_file_out_of_date>  s$   
zContext.c_file_out_of_datec                 C   s   dd |  |D S )Nc                 S   s   g | ]
\}}|d kr|qS )r   r$   )rn   r   r   r$   r$   r%   rp   S  s    z7Context.find_cimported_module_names.<locals>.<listcomp>)r   )r=   r   r$   r$   r%   find_cimported_module_namesR  s   z#Context.find_cimported_module_namesc                 C   rh   rN   )r   is_package_dir)r=   dir_pathr$   r$   r%   r   V  rl   zContext.is_package_dirc                 C   sd   t |d}tj|r0t|d}dd dd |D D }W d    |S 1 s)w   Y  |S dS )Nz.deprUc                 S   s    g | ]}d |v r| d dqS ) r   )rw   )rn   liner$   r$   r%   rp   ]  s
    
z0Context.read_dependency_file.<locals>.<listcomp>c                 s   s    | ]}|  V  qd S rN   )strip)rn   lr$   r$   r%   	<genexpr>^  s    z/Context.read_dependency_file.<locals>.<genexpr>r$   )r   r   rZ   r   r   open)r=   r   r   fchunksr$   r$   r%   r   Y  s   
zContext.read_dependency_filec                 C   s   | j |d S rN   )r/   r;   )r=   r   r$   r$   r%   r   d  s   zContext.lookup_submodulec                 C   s,   |  |}|st|d | |d}|| j|< |S )N)parent_modulecontextr   )r   r   r/   )r=   r   r   ra   r$   r$   r%   r   h  s   

zContext.find_submodulec              
   C   s   t |ts	td|j}| j|_t }zKt|<}ddl	m
} t|||j|| d}	||	||}
| jjrOzddlm} W n tyI   tdw || W d    n1 sYw   Y  W n tyq } z| ||d }~ww t |kr{t |
S )N$Only file sources for code supportedr   )Parsing)source_encodingra   r   r   )ConcreteSyntaxTreezLFormal grammar can only be used with compiled Cython with an available pgen.)rW   r   RuntimeErrorr   r6   r	   get_errors_countr   open_source_filer   r   r   rP   p_moduler7   formal_grammarParserr   ImportErrorUnicodeDecodeError_report_decode_errorr   )r=   r`   ra   r   full_module_namesource_filename
num_errorsr   r   streer   er$   r$   r%   parseq  s>   


zContext.parsec                 C   s   |j d }|j d }|j d }d}d }}tj|jdddd(}	t|	dD ]\}}
|t|
7 }||kr?||t|
  d } nq%W d    n1 sJw   Y  t|||fd	||f S )
Nr   r   r   rz	iso8859-1r   )rP   newlinezqDecoding error, missing or incorrect coding=<encoding-name> at top of source (cannot decode with encoding %r: %s))argsior   r   	enumerater   r   )r=   r`   rj   msgpositionrP   r   columnidxr   datar$   r$   r%   r     s&   



zContext._report_decode_errorc           
      C   s   t j|\}}t j|\}}d|v r|S |g}| |r7t j|\}}	||kr+n||	 |}| |s|  d|S )Nrm   )rZ   r   rw   r   r   r   reverser    )
r=   r   r7   r   r   rb   _namesparentpackage_namer$   r$   r%   extract_module_name  s   



zContext.extract_module_namec                 C   s<   t   |jrt|jd }|_nd }t j||jd d S )Nz.lis)r   echo_to_stderr)	r	   init_threaduse_listing_filer   r   main_source_filelisting_fileopen_listing_fileerrors_to_stderr)r=   r7   rf   r   r$   r$   r%   setup_errors  s
   zContext.setup_errorsc                 C   s   |j j}t|tstdt  t |_|jdkrd}|r>|j	r@zt
|j	t|j W n	 ty8   Y nw d |_	d S d S d S )Nr   r   T)compilation_sourcer`   rW   r   r   r	   close_listing_filer   r   c_filer   castrate_filerZ   statr   EnvironmentError)r=   r   r7   rf   r`   r$   r$   r%   teardown_errors  s   




zContext.teardown_errors)FNNrN   )F)NNr   TF)NTNNN)NNFFN)"__name__
__module____qualname__r1   r>   r?   classmethodrC   r:   rS   rg   rk   r   staticmethodrz   r   r   r   r   r   ry   r   r   r   r   r   r   r   r   r   r   r   r   r  r$   r$   r$   r%   r(   9   sL    







\





	r(   c                 C   s\   |j rd}nd}t| |}|jr,tj||j}tj|r*tj|tj|S |S |S )Nz.cppz.c)	rA   r   r   output_filerZ   r   r    isdirr   )r   cwdr7   c_suffixsuggested_file_nameout_pathr$   r$   r%   get_output_filename  s   r  c                 C   s:   t  }| jj|_| |_| j}t|j| j||_|j|_|S rN   )	CompilationResultr`   r   r   r   r  r  r   embedded_metadata)r   r7   rf   r`   r$   r$   r%   r\     s   
r\   c                 C   s8  ddl m} tjd dkrt| } |rt|}tj| d }|	|dd   |d u r3t
|}t }tj| }|pD|| |}t|}t| |jrb|dtj| }||sa| }n|}t||}	t|	||} t| |}
|jd u rtj|
jd d }tj|rtj|ddd	}d
|dv rd|_W d    n1 sw   Y  | dks|s||||
}n| |||
}|!||
 d|v rdtjtj"|d v rt#|	ddfdtj"| dd |$|| \}}|%|||
 |d u r|j&rddl'm(} ||)|
j*}t+|
j|
j*| |
S )Nr   rT   r   r   rm   z.htmlr   zUTF-8)rP   z<!-- Generated by Cythond   Trq   r   r   )create_dependency_tree),r   rU   r   version_infor   decode_filenamerZ   r   r   configure_language_defaultsr(   rC   r[   abspathr   r
   $raise_error_if_module_name_forbidden'relative_path_in_code_position_commentsr   r   r   r   rY   r\   annotater   r   r   r   readlowercreate_py_pipelinecreate_pyx_pipeliner   r   r   r^   r  depfileBuild.Dependenciesr  all_dependenciesr   write_depfile)rc   r7   r   r   rU   
source_extr  abs_pathr   r`   rf   html_filename	html_filere   r   enddatar  dependenciesr$   r$   r%   r^     sb   







$

r^   c                   @      e Zd ZdZdd ZdS )rY   zk
    Contains the data necessary to start up a compilation pipeline for
    a single compilation unit.
    c                 C   s   || _ || _|| _d S rN   )r`   r   r  )r=   r`   r   r  r$   r$   r%   r?   /  s   
zCompilationSource.__init__Nr  r  r  __doc__r?   r$   r$   r$   r%   rY   *  s    rY   c                   @   r)  )r  af  
    Results from the Cython compiler:

    c_file           string or None   The generated C source file
    h_file           string or None   The generated C header file
    i_file           string or None   The generated .pxi file
    api_file         string or None   The generated C API .h file
    listing_file     string or None   File of error messages
    object_file      string or None   Result of compiling the C file
    extension_file   string or None   Result of linking the object file
    num_errors       integer          Number of compilation errors
    compilation_source CompilationSource
    c                 C   s4   d | _ d | _d | _d | _d | _d | _d | _d | _d S rN   )r   h_filei_fileapi_filer   object_fileextension_filer   )r=   r$   r$   r%   r?   D  s   
zCompilationResult.__init__Nr*  r$   r$   r$   r%   r  5  s    r  c                   @   s   e Zd ZdZdZdd ZdS )CompilationResultSetz
    Results from compiling multiple Pyrex source files. A mapping
    from source file paths to CompilationResult instances. Also
    has the following attributes:

    num_errors   integer   Total number of compilation errors
    r   c                 C   s   || |< |  j |j 7  _ d S rN   )r   )r=   rc   rf   r$   r$   r%   rK   Z  s   zCompilationResultSet.addN)r  r  r  r+  r   rK   r$   r$   r$   r%   r1  O  s    r1  c                 C   s   t | ||S )z
    compile_single(source, options, full_module_name)

    Compile the given Pyrex implementation file and return a CompilationResult.
    Always compiles a single file; does not perform timestamp checking or
    recursion.
    )r^   )rc   r7   r   r$   r$   r%   compile_single_  s   r2  c                 C   s   t | dkr|jrtddd | D } t }t }|j}|j}d}t }| D ]?}||vrg|du r7t	
|}t|||}	|||	}
|rG|
rb|rQtjd|  t|||j|d}||| d}|| q(|S )z
    compile_multiple(sources, options)

    Compiles the given sequence of Pyrex implementation files and returns
    a CompilationResultSet. Performs timestamp checking and/or recursion
    if these are specified in the options.
    r   z>Full module name can only be set for single source compilationc                 S   s   g | ]}t j|qS r$   )rZ   r   r  )rn   rc   r$   r$   r%   rp   w  s    z$compile_multiple.<locals>.<listcomp>NzCompiling %s
)r   r   )r   rb   r   r3   r1  
timestampsverboserZ   r[   r(   rC   r  r   r   stderrwriter^   rK   )sourcesr7   	processedresultsr3  r4  r   r  rc   output_filenameout_of_daterf   r$   r$   r%   compile_multiplej  s6   

r<  c                 K   s>   t dd|i|}t| tr|jst| ||S | g} t| |S )a  
    compile(source [, options], [, <option> = <value>]...)

    Compile one or more Pyrex implementation files, with optional timestamp
    checking and recursing on dependencies.  The source argument may be a string
    or a sequence of strings.  If it is a string and no recursion or timestamp
    checking is requested, a CompilationResult is returned, otherwise a
    CompilationResultSet is returned.
    defaultsNr$   )r   rW   r   r3  r2  r<  )rc   r7   r   kwdsr$   r$   r%   compile  s   


r?  r   Fc                 C   s*  |r|s|d }t |tstd|j}|r*|r"tj|f|  } nt|f|  } |}|r2||7 }| D ]}tj	||}	tj
|	rG|	  S q4|s|d}
t|
dd }|
d }g }| D ]"}t||\}}|dur|ru|| q_t|||}	|	r|	  S q_|D ]}t|||}	|	r|	  S qdS )a)  
    Search the list of include directories for the given file name.

    If a source file path or position is given, first searches the directory
    containing that file.  Returns None if not found, but does not report an error.

    The 'include' option will disable package dereferencing.
    r   r   rm   Nr   )rW   r   r   r   rZ   r   dirnamer   r   r    r   rw   r   r   r   search_module_in_dir)dirsr{   rs   r   r   ru   	file_descdotted_filenamer@  r   r   r   rb   namespace_dirspackage_diris_namespacer$   r$   r%   ry     sL   



ry   c                 C   s2   t | ||}|s|rt tj| |d|}|S )Nr?   )r   find_versioned_filerZ   r   r    )rF  rb   rs   r   r$   r$   r%   rA    s   rA  c                   C   s
   t ddS )Nr   )command_line)mainr$   r$   r$   r%   setuptools_main  rl   rK  c              
   C   s.  t jdd  }d}| rEzt|\}}W n7 tyD } z%dd l}|j|jkr& tdt jd |jt j	d t 
d W Y d }~nd }~ww tt}|}|jrRt  |jdkr]t|j zt||}|jdkrjd}W n  ttfy } zt j	t|d  d}W Y d }~nd }~ww |rt 
d d S d S )Nr   r   z#{}: No such file or directory: '{}')filer   
)r   argvr   IOErrorerrnoENOENTr   r   r   r5  exitr   r   show_versionr   print_versionworking_pathrZ   chdirr?  r   r  r   r6  str)rI  r   any_failuresr7   r7  r   rP  rf   r$   r$   r%   rJ    s@   	


rJ  r  rN   )r   NFN)r   )B
__future__r   r   rZ   rer   r   r  r5  r6  r   rR  r+   r   r   rW  r   r	   StringEncodingr
   Scanningr   r   r   r   r   r   Symtabr   r   r   r   r   CmdLiner   Lexiconr   r   r   r   r&   r   r   r?  r   r  r    r@  __file__r   objectr(   r  r\   r^   rY   r  dictr1  r2  r<  cached_functionry   rA  rK  rJ  r$   r$   r$   r%   <module>   sh   4
   
F

(:
