o
    fK4                  	   @   s  d dl mZ d dlZd dlZd dlZd dlZd dlZd dlmZm	Z	 d dl
mZ d dlZddlmZ ddlmZmZmZ ddl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mZ ddl m!Z! ddl"m#Z# d dl$Z%ej&dkZ'e's|dd Z(ndd Z(ej&dk rd dl)Z)dd Z*nd dl+Z,d dl-m.Z. dd Z*G dd deeZ/ed9ddZ0d9ddZ1d9d d!Z2d"d# Z3ed$d% Z4i Z5e4d&Z6d:d'd(Z7d)d* Z8e1ej9:e# d+ddd,d,dddf	d-d.Z;de;_<e=d/j>Z?d0d1 Z@e=d2ZAd3d4 ZBd5d6 ZCG d7d8 d8eDZEdS );    )absolute_importN)Distribution	Extension)	build_ext   )Context)default_optionsCompilationOptionsget_directive_defaults)CythonTransformEnvTransform)SkipDeclarations)parse_from_strings)_unicode   )strip_string_literals	cythonizecached_function)Pipeline)get_cython_cache_dir)   c                 C   s   t | tr
| dS | S )Nascii)
isinstancebytesdecode)s r   O/var/www/html/mig_web/myenv/lib/python3.10/site-packages/Cython/Build/Inline.py
to_unicode   s   

r   c                 C   s   | S Nr   xr   r   r   <lambda>%       r"   )r      c                 C   s   t | |S r   )impload_dynamic)namemodule_pathr   r   r   r&   *   s   r&   )ExtensionFileLoaderc                 C   s2   t jj| t| |d}t j|}|j| |S )N)loader)	importlibutilspec_from_file_locationr)   module_from_specr*   exec_module)r'   pathspecmoduler   r   r   r&   0   s   c                       s0   e Zd Z fddZdd Z fddZ  ZS )UnboundSymbolsc                    s   t t| jd d t | _d S )N)context)superr   __init__setunbound)self	__class__r   r   r6   8   s   zUnboundSymbols.__init__c                 C   s"   |   |js| j|j |S r   )current_envlookupr'   r8   addr9   noder   r   r   visit_NameNode;   s   zUnboundSymbols.visit_NameNodec                    s   t t| | | jS r   )r5   r3   __call__r8   r?   r:   r   r   rB   ?   s   zUnboundSymbols.__call__)__name__
__module____qualname__r6   rA   rB   __classcell__r   r   r:   r   r3   7   s    r3   c                 C   s   t | } |d u rtg t ttd}ddlm} td| }t	|dD ]}|d u r*q#||}t
||r5 nq#zdd l}W n tyI   dd l}Y nw tt |tt| S )Noptionsr   )AnalyseDeclarationsTransformz(tree fragment)pyxr   )r   r   r
   r	   r   Compiler.ParseTreeTransformsrI   r   r   create_pipeliner   builtinsImportError__builtin__tupler3   r7   dir)coder4   rI   treephaserM   r   r   r   unbound_symbolsD   s(   

rU   c                 C   s   t | }|tu r
dS t| |S )Nlong)typeint	safe_type)argr4   py_typer   r   r   unsafe_typeY   s   
r\   c                 C   s   t | }|ttttfv r|jS |tu rdS |tu rdS |tu r!dS dt	j
v r8t| t	j
d jr8d| jj| jf S |jD ]'}|jdv rE dS |j|jdd	}|rb||j}|jrbd
|j|jf   S q;dS )Nzdouble complexdoublebintnumpyz"numpy.ndarray[numpy.%s_t, ndim=%s])rO   rM   objectF)need_pxdz%s.%s)rW   listrP   dictstrrC   complexfloatboolsysmodulesr   ndarraydtyper'   ndim__mro__rD   find_moduler=   is_type)rZ   r4   r[   	base_typer2   entryr   r   r   rY   a   s*   

rY   c                  C   s,   t  } |  }| | t| }|  |S r   )r   find_config_filesparse_config_filesr   finalize_options)distconfig_filesbuild_extensionr   r   r   _get_build_extensiony   s   
rx   c                 C   s   t t| t ttdS )NrG   )r   rb   r
   r	   r   )cython_include_dirsr   r   r   _create_context   s
   rz   ).c                 C   s   |D ]H}|| vrJ|d u s|d u r%t  jjj}|d u r|j}|d u r%|j}t|ts.t|}||v r9|| | |< q||v rD|| | |< qtd|  qd S )NzCouldn't find %r)inspectcurrentframef_backf_locals	f_globalsr   rc   print)kwdsrU   localsglobalssymbolcalling_framer   r   r   _populate_unbound   s"   
r   c                 C   s.   | |t jt j|tjf}tt|d	 S )Nzutf-8)
rh   version_info
executableCython__version__hashlibsha1r   encode	hexdigest)	orig_codearg_sigslanguage_levelkeyr   r   r   _inline_key   s   r   inlineFc
           ,         sr  d u rdd |rt t|nt |rt|ni }|	d u r$d|vr$d}	|	d ur,|	|d< d }t| }|d urmt||| t }t fdd|D }t	| ||	}t| ||f}|d urmdd |D }|| S | }t
| } t| \} }t| } |d u rt jjj}|d u rt jjj}zt|  t|< }t||| W n ty   |std Y nw g }t D ]\}}|tu r|d	|  |= qt}t fd
d|D }|d u rt	|||	}d| }|tjv rtj| }n)d }tjd u rt }|dt_tj |}tj!||tj }tj"|s't#| |s1tj$|sg }g }g }t%&d}|D ]1\}} |'|}!|!rn|d|!( d   |!( d dkrndd l)}"||"*  |d q>t+| \}#}$d!dd |D }%dd!||#|%|$d }&| D ]\}'}(|&,|'|(}&qtj!||d })t-|)d}*z|*.|& W |*/  n|*/  w t0||)g|pd |pd |pd d}+|d u rt }t1|+g|pdg||d|_2tj3|)|_4||_5|6  tj7dkrtj8dkrt9tj | t:||}W d    n	1 sw   Y  nt:||}|j;t|||f< fdd|D }|j;| S )Nc                 S   s   dS )Nr`   r   r    r   r   r   r"      r#   zcython_inline.<locals>.<lambda>r   3strc                    s   g | ]\}}| |fqS r   r   ).0rZ   value)ctxget_typer   r   
<listcomp>       z!cython_inline.<locals>.<listcomp>c                 S   s   g | ]}|d  qS )r   r   r   rZ   r   r   r   r          z>Could not parse code as a string (to extract unbound symbols).z
cimport cython as %sc                    s   g | ]}|  |fqS r   r   r   r   r   r   r   r   r      r   _cython_inline_ z([.\w]+)[.]z
cimport %sr   r_   )NPY_NO_DEPRECATED_APINPY_1_7_API_VERSIONz, c                 S   s   g | ]}d | qS )z%s %sr   )r   ar   r   r   r     r   zf
%(module_body)s
%(cimports)s
def __invoke(%(params)s):
%(func_body)s
    return locals()
            
)cimportsmodule_bodyparams	func_bodyz.pyxw)r'   sourcesinclude_dirsextra_compile_argsdefine_macrosr{   )include_pathcompiler_directivesquietwin32)r      c                    s   g | ]} | qS r   r   r   )r   r   r   r   /  r   )<rz   rP   _cython_inline_default_contextrc   _cython_inline_cachegetr   sorteditemsr   r   r   strip_common_indentr|   r}   r~   r   r   rU   AssertionErrorr   rb   cython_moduleappendrh   ri   cython_inlineso_extrx   get_ext_filenameosr0   abspathjoinexistsmakedirsisfilerecompilematchgroupsr_   get_includeextract_func_codereplaceopenwritecloser   r   
extensionsdirname
build_temp	build_librunplatformr   add_dll_directoryr&   __invoke),rR   r   lib_dirry   cython_compiler_directivesforcer   r   r   r   r   key_hash_unbound_symbolsargsr   invokearg_listr   literalsr   r'   rZ   	arg_namesmodule_namer2   rw   r(   cflagsr   c_include_dirs	qualifiedrW   _mr_   r   r   r   module_coder   r   pyx_filefh	extensionr   r   r   r      s   











r   z[^ ]c                 C   s   d }|   }|D ]}t|}|sq| }|| dkrq|d u s$||kr&|}qt|D ]\}}t|}|rA|rA|||d  dkrBq+||d  ||< q+d|S )N#r   r   )
splitlines_find_non_spacestart	enumerater   )rR   
min_indentlinesliner   indentixr   r   r   r   :  s$   
r   zI^((cdef +(extern|class))|cimport|(from .+ cimport)|(from .+ import +[*]))c                 C   sl   g }g }|}|  dd} | d}|D ]}|ds$t|r"|}n|}|| qd|dd| fS )N	 r   z    z
    )r   split
startswithmodule_statementr   r   r   )rR   r2   functioncurrentr   r   r   r   r   r   O  s   


r   c                 C   s>   |  d}| d d dkrd| |d d   S | |d d  S )N:r$   lambdaz	return %sr   )index)sourcer   r   r   r   get_body_  s   
r  c                   @   s   e Zd Zdd Zdd ZdS )RuntimeCompiledFunctionc                 C   s   || _ tt|| _d S r   )_fr  r|   	getsource_body)r9   fr   r   r   r6   k  s   z RuntimeCompiledFunction.__init__c                 O   s^   t j| jg|R i |}trt| jf| jj| jjd|S t| jf| jj| jjd|S )N)r   r   )r|   getcallargsr  IS_PY3r   r  __globals__func_globals)r9   r   r   allr   r   r   rB   o  s     z RuntimeCompiledFunction.__call__N)rC   rD   rE   r6   rB   r   r   r   r   r  i  s    r  r   )NN)F
__future__r   r   r|   r   r   rh   distutils.corer   r   distutils.command.build_extr   r   Compiler.Mainr   Compiler.Optionsr   r	   r
   Compiler.Visitorr   r   rK   r   Compiler.TreeFragmentr   Compiler.StringEncodingr   Dependenciesr   r   r   Compilerr   Utilsr   cythonr   r   r  r   r%   r&   importlib.utilr+   importlib.machineryr)   r3   rU   r\   rY   rx   rz   r   r   r   r   r0   r   r   r   r   searchr   r   r   r   r  r`   r  r   r   r   r   <module>   sl    









 


