3
[]              '   @   sX  d dl mZ d dlZd dlZd dlZd dlZejdd d5k s`d6ejdd   koZd7k n  rejjde	ejdd   ej
d yd dlmZ W n ek
r   eZY nX 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 ejZej dZ!d Z"ej#j$ej#j%ej#j&e'ej#j(dZ)G dd de*Z+G dd de*Z,dd Z-dd Z.d8ddZ/G dd de*Z0G dd  d e*Z1G d!d" d"e*Z2G d#d$ d$e3Z4d9d%d&Z5d'd( Z6d:d)d*Z ej7d;d,d-Z8d.d/ Z9d<d0d1Z:e3d d dd dddd d d2dd d i i d+d+d3d3dd+d+ddddddd+d4Z;dS )=    )absolute_importN         z8Sorry, Cython requires Python 2.6+ or 3.3+, found %d.%d
   )
basestring)Errors)EncodedString)PyrexScannerFileSourceDescriptor)
PyrexErrorCompileErrorerrorwarning)ModuleScope)Utils)Options)Versionz2[A-Za-z_][A-Za-z0-9_]*(\.[A-Za-z_][A-Za-z0-9_]*)*$Includesc               @   s   e Zd ZdS )CompilationDataN)__name__
__module____qualname__ r   r   d/home/psgendb/BIRCHDEV/lib-linux-x86_64/python/lib64/python3.6/site-packages/Cython/Compiler/Main.pyr   ,   s   r   c               @   s   e Zd ZdZdZd5ddZdd Zd6ddZd	d
 Zdd Z	dd Z
d7ddZd8ddZdd Zdd Zd9d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* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 ZdS ):ContextNFc             C   s|   ddl m}m} d|ji| _|j| | _| j| jd< || _t | _	|| _
|| _|| _i | _i | _|d k	rr| j| d | _d S )Nr   )BuiltinCythonScope__builtin__cython) r   r   builtin_scopemodulescreate_cython_scopecython_scopeinclude_directoriessetfuture_directivescompiler_directivescppoptionspxds	_internedset_language_levelgdb_debug_outputwriter)selfr%   r(   r)   language_levelr*   r   r   r   r   r   __init__J   s    
zContext.__init__c             C   s   ddl m}m}m}m} t }|dkr,d}nt|}|dkrF|j| |dkr^|j|||g || _	|| _
|dkr| jd | jd< d S )Nr   )print_functionunicode_literalsr   division3strr   r   builtins)Futurer2   r3   r   r4   r&   intaddupdater0   r'   r"   )r/   levelr2   r3   r   r4   r'   r   r   r   r-   b   s    
zContext.set_language_levelc             C   sJ   t ||f}y
| j| S  tk
r(   Y nX t |}|r<||_|| j|< |S )N)r	   r,   KeyErrorencoding)r/   valuer=   keyr   r   r   intern_ustringr   s    


zContext.intern_ustringc             G   s>   t ||f| }y
| j| S  tk
r.   Y nX || j|< |S )N)typer,   r<   )r/   r>   r?   r   r   r   intern_value~   s    

zContext.intern_valuec       	      C   st   ddl m} t|trV|jdkrVt||tj }t|| j	}|j
| |}|j||}n|j| ||}|j||}|S )Nr   )Pipelinepyx)r    rC   
isinstancer   
_file_typeCompilationSourceosgetcwdcreate_default_resultobjr*   create_pyx_as_pxd_pipelinerun_pipelinecreate_pxd_pipeline)	r/   source_descscopemodule_namerC   sourceresult_sinkpipelineresultr   r   r   process_pxd   s    zContext.process_pxdc             C   s
   t j|S )N)r   report_error)r/   excr   r   r   nonfatal_error   s    zContext.nonfatal_errorr   Tc             C   s2  d}|rt d||||f  d }d }|rH|r8|j|}	qL|j}	|}d }n|}	tj|	snt|pd|ddfd| |r|r~t d |j|}|s| j|	|}|r|j|}|s|rt d |r|}	| }x|	j	dD ]}
|j|
}qW |rt d|  |j
s.|rt d |s|rt d	 | j|	||d
}|r<t d|  | r|rd|_
| j|	d|}|rr|jdrrnt|d|	jdtj  |r.d|_
y|rt d|  |jdtjtjj|d  }|j|s|}t||}| j|||	\}}|r||\}}||f| j|< W n tk
r,   Y nX |S )Nr   zPContext.find_module: module_name = %s, relative_to = %s, pos = %s, need_pxd = %sz'%s' is not a valid module namez...trying relative importz...trying absolute import.z...scope = %sz...pxd not loadedz...looking for pxd file)sys_pathz......found %sTz.pyz__init__.pyz'%s.pxd' not foundzContext.find_module: Parsing %sr   )printqualify_namequalified_namemodule_name_patternmatchr   lookup_submodulefind_pxd_filefind_submodulesplitpxd_file_loadedsearch_include_directoriesendswithr   replacerH   seppathsplitextr   rU   r+   )r/   rP   relative_toposneed_pxdabsolute_fallbackdebug_find_modulerO   pxd_pathnamer]   namepackage_pathnamerel_pathrN   errrT   pxd_codenodes	pxd_scoper   r   r   find_module   s    	




zContext.find_modulec             C   s  | j |d||d}|d kr|jds,|dkrtjjtjjtjjtjjttjj	d}tjj|d}| j
j| z| j |d|}W d | j
j  X |r|}|jdrt|d	| d
 n6|dkrt|d||f d
 n|dkrt|d| d
 |d kr
tjr
| j||S |S )Nz.pxd)rZ   pythonstdlibstdiostlr   
Deprecatedz!'%s' is deprecated, use 'cpython'r   z!'%s' is deprecated, use 'libc.%s'z$'%s' is deprecated, use 'libcpp.*.*')ry   rz   r{   )ry   rz   )re   
startswithrH   ri   abspathnormpathjoindirname__file__pardirr%   appendpopr   r   cimport_from_pyxfind_pyx_file)r/   r]   rl   rZ   pxdstandard_include_pathdeprecated_include_pathrq   r   r   r   ra      s,    	
 
zContext.find_pxd_filec             C   s   | j |d|S )Nz.pyx)re   )r/   r]   rl   r   r   r   r     s    zContext.find_pyx_filec             C   s(   | j |d|dd}|s$t|d|  |S )Nr    T)includez'%s' not found)re   r   )r/   filenamerl   ri   r   r   r   find_include_file  s
    
zContext.find_include_filec             C   s2   | j }|r|tj }t|tg }t|||||S )N)r%   sysri   tupler   re   )r/   r]   suffixrl   r   rZ   include_dirsr   r   r   re      s    
z"Context.search_include_directoriesc             C   s
   t j|S )N)r   find_root_package_dir)r/   	file_pathr   r   r   r   *  s    zContext.find_root_package_dirc             C   s   t j|t|S )N)r   check_package_dirr   )r/   dirpackage_namesr   r   r   r   -  s    zContext.check_package_dirc       	      C   s   t jj|sdS tj|}tj||r*dS |g}tj|d}t jj|rXtj||rXdS xX| j|D ]J\}}|dkr| j||}n|dkrd| j	||}nqd|rdtj||rddS qdW dS )Nr   z.pxdcimportr   r   )
rH   ri   existsr   modification_timefile_newer_thanreplace_suffixread_dependency_filera   re   )	r/   source_pathoutput_pathc_timerl   pxd_pathkindrq   dep_pathr   r   r   c_file_out_of_date0  s$    
zContext.c_file_out_of_datec             C   s   dd | j |D S )Nc             S   s   g | ]\}}|d kr|qS )r   r   ).0r   rq   r   r   r   
<listcomp>F  s    z7Context.find_cimported_module_names.<locals>.<listcomp>)r   )r/   r   r   r   r   find_cimported_module_namesE  s    z#Context.find_cimported_module_namesc             C   s
   t j|S )N)r   is_package_dir)r/   dir_pathr   r   r   r   I  s    zContext.is_package_dirc             C   sH   t j|d}tjj|r@t|d}dd |j D }|j  |S f S d S )Nz.deprUc             S   s(   g | ] }d |j  kr|j  jd dqS ) r   )striprc   )r   liner   r   r   r   P  s   z0Context.read_dependency_file.<locals>.<listcomp>)r   r   rH   ri   r   open	readlinesclose)r/   r   r   fchunksr   r   r   r   L  s    
zContext.read_dependency_filec             C   s   | j j|d S )N)r"   get)r/   rq   r   r   r   r`   X  s    zContext.lookup_submodulec             C   s*   | j |}|s&t|d | d}|| j|< |S )N)parent_modulecontext)r`   r   r"   )r/   rq   rO   r   r   r   rb   \  s    


zContext.find_submodulec             C   s   t |tstd|j}| j|_tj}ytj|t}ddl	m
} t|||j|| d}	|j|	||}
| jjryddlm} W n tk
r   tdY nX |j| W d Q R X W n. tk
r } z| j||W Y d d }~X nX tj|krt |
S )Nz$Only file sources for code supportedr   )Parsing)source_encodingrO   r   r   )ConcreteSyntaxTreezLFormal grammar can only be used with compiled Cython with an available pgen.)rE   r   RuntimeErrorr   r)   r   
num_errorsr   open_source_filer    r   r
   r=   p_moduler*   formal_grammarParserr   ImportErrorUnicodeDecodeError_report_decode_errorr   )r/   rN   rO   r   full_module_namesource_filenamer   r   r   streer   er   r   r   parsee  s.    



zContext.parsec             C   s   |j d	 }|j d }|j d }d}d }}tj|jddddH}	x@t|	dD ]2\}}
|t|
7 }||krL||t|
  d }P qLW W d Q R X t|||fd||f S )
Nr   r   r   rz	iso8859-1r    )r=   newlinezqDecoding error, missing or incorrect coding=<encoding-name> at top of source (cannot decode with encoding %r: %s))argsior   r   	enumeratelenr   )r/   rN   rW   msgpositionr=   r   columnidxr   datar   r   r   r     s    



zContext._report_decode_errorc       
      C   s|   t jj|\}}t jj|\}}d|kr,|S |g}x6| j|rht jj|\}}	||krXP |j|	 |}q4W |j  dj|S )NrY   )rH   ri   rc   rj   r   r   reverser   )
r/   ri   r*   r   r   rP   _namesparentpackage_namer   r   r   extract_module_name  s    
zContext.extract_module_namec             C   s<   t j  |jr$tj|jd }|_nd }t j||jd d S )Nz.lis)ri   echo_to_stderr)	r   resetuse_listing_filer   r   main_source_filelisting_fileopen_listing_fileerrors_to_stderr)r/   r*   rT   ri   r   r   r   setup_errors  s    zContext.setup_errorsc             C   s|   |j j}t|tstdtj  tj|_|jdkr8d}|rx|jrxyt	j
|jtj|j W n tk
rp   Y nX d |_d S )Nz$Only file sources for code supportedr   T)compilation_sourcerN   rE   r   r   r   close_listing_filer   c_filer   castrate_filerH   statr   EnvironmentError)r/   rt   r*   rT   rN   r   r   r   teardown_errors  s    


zContext.teardown_errors)FNN)N)NNr   T)T)FF)r   r   r   r$   r0   r1   r-   r@   rB   rU   rX   rw   ra   r   r   re   r   r   r   r   r   r   r`   rb   r   r   r   r   r   r   r   r   r   r   ;   s8    

 
X
!

			r   c             C   sb   |j rd}nd}tj| |}|jrZtjj||j}tjj|rTtjj|tjj|S |S n|S d S )Nz.cppz.c)	cplusr   r   output_filerH   ri   r   isdirbasename)r   cwdr*   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 )N)	CompilationResultrN   r   r   r   r   r   r   embedded_metadata)r   r*   rT   rN   r   r   r   rJ     s    
rJ   c             C   s|  ddl m} tjj| d }|j|dd   |d kr>|j }tj }tjj| }|p`|j	| |}t
j| |jr|jdtj| }|j|s| }n|}t||}	t|	||} t| |}
|jd krtjj|
jd d }tjj|rtj|ddd}d	|jd
krd|_W d Q R X |j dks0| r@|j|||
}n|j|||
}|j||
 |j|| \}}|j|||
 |
S )Nr   )rC   rY   r   z.htmlr   zUTF-8)r=   z<!-- Generated by Cythond   Tz.py)r    rC   rH   ri   rj   configure_language_defaultscreate_contextrI   r~   r   r   $raise_error_if_module_name_forbidden'relative_path_in_code_position_commentsrg   rh   rf   r   rG   rJ   annotater   r   r   r   readlowercreate_py_pipelinecreate_pyx_pipeliner   rL   r   )rQ   r*   r   r   rC   
source_extr   abs_pathrs   rN   rT   html_filename	html_filerS   rt   enddatar   r   r   rL     s<    



rL   c               @   s   e Zd ZdZdd ZdS )rG   zk
    Contains the data necessary to start up a compilation pipeline for
    a single compilation unit.
    c             C   s   || _ || _|| _d S )N)rN   r   r   )r/   rN   r   r   r   r   r   r1     s    zCompilationSource.__init__N)r   r   r   __doc__r1   r   r   r   r   rG     s   rG   c               @   s2   e Zd ZdZdddZdd Zdd Zd	d
 ZdS )CompilationOptionsz
    See default_options at the end of this module for a list of all possible
    options and CmdLine.usage and CmdLine.parse_command_line() for their
    meaning.
    Nc       
      K   s  g | _ |rt|tr |j}nt}t|}|j| t|tt }|jdg |r|dt	|dkrddnddj
|f }t|tj }t|d }t|t| }|rdt	|dkrdnddj
|f }t|||d< |jd	d
o|d  rdd l}	|	jd d|d< d|kr*d|kr*|d |d< n|jdsD|jd|d< d|krdd|krd|d |d< |d dkrtjj
tj d|d< | jj| d S )Ninclude_pathz3got unknown compilation option%s, please remove: %sr   r   r    z, r(   z$got unknown compiler directive%s: %s
np_pythranFr   r   z%C++ mode forced when in Pythran mode!Tr0   r   cachecompiler)r  rE   r  __dict__default_optionsdictr:   r&   difference_updater   r   
ValueErrorr   get_directive_defaultsr   warningswarnrH   ri   r   get_cython_cache_dir)
r/   defaultskwr*   unknown_optionsmessagedirective_defaults
directivesunknown_directivesr  r   r   r   r1     sH    


zCompilationOptions.__init__c             C   s&   |dkr"| j jdd kr"d| j d< d S )NpybindingT)r(   r   )r/   source_extensionr   r   r   r   N  s    z.CompilationOptions.configure_language_defaultsc             C   s   t | j| j| j| j| dS )N)r*   )r   r  r(   r   r0   )r/   r   r   r   r   S  s    
z!CompilationOptions.create_contextc                s.  i }x| j j D ]\}}|d#kr(qq|d$kr4qq|d%kr@qq|d&krLqq|d'krXqq|d(krdqq|d)krpqq|d*kr|qq|d+krqq|d,kr|||< q|d-kr|||< q|d.kr|||< q|d/k r|||< q|dgk r| jrtdq|dgkr| jrtd q|||< qW  fd!d"  |S )0zi
        Return a string that contains all the options that are relevant for cache invalidation.
        show_versionr   verbosequietr   
output_dir
timestampsr  r(   r  working_pathcreate_extension	build_dirr   generate_pxir   annotate_coverage_xmlr   evaluate_tree_assertionsr   emit_linenumsc_line_in_traceback	gdb_debugr   r   r0   compile_time_envr  capi_reexport_cincludesz=capi_reexport_cincludes is not compatible with Cython cachingcommon_utility_include_dirzDcommon_utility_include_dir is not compatible with Cython caching yetc                s,   t | tr$t fdd| j D } t| S )z
            Recursively turn item into a string, turning dicts into lists with
            deterministic ordering.
            c                s    g | ]\}}t | |fqS r   )repr)r   r?   r>   )to_fingerprintr   r   r     s    zNCompilationOptions.get_fingerprint.<locals>.to_fingerprint.<locals>.<listcomp>)rE   r
  sorteditemsr,  )item)r-  r   r   r-    s    
z:CompilationOptions.get_fingerprint.<locals>.to_fingerprint)r  r   r  r  )r   r  )r  )r  )r(   )r  )r   )r!  )r"  )r   r#  r   r$  )r   r%  )r   r&  r'  r(  r   )r   r0   r)  r  )r  r/  r*  NotImplementedErrorr+  )r/   r   r?   r>   r   )r-  r   get_fingerprintW  sJ    






	z"CompilationOptions.get_fingerprint)N)r   r   r   r  r1   r   r   r2  r   r   r   r   r    s
   
/r  c               @   s   e Zd ZdZdd ZdS )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 )N)r   h_filei_fileapi_filer   object_fileextension_filer   )r/   r   r   r   r1     s    zCompilationResult.__init__N)r   r   r   r  r1   r   r   r   r   r     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 )N)r   )r/   rQ   rT   r   r   r   r9     s    zCompilationResultSet.addN)r   r   r   r  r   r9   r   r   r   r   r8    s   r8  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.
    )rL   )rQ   r*   r   r   r   r   compile_single  s    r9  c             C   s   dd | D } t  }t }|j}|j}d}tj }x| D ]z}||kr8|dkrT|j }t|||}	|j||	}
| sv|
r|rt	j
jd|  t|||d}|j|| d}|j| q8W |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.
    c             S   s   g | ]}t jj|qS r   )rH   ri   r~   )r   rQ   r   r   r   r     s    z$compile_multiple.<locals>.<listcomp>NzCompiling %s
)r   )r&   r8  r  r  rH   rI   r   r   r   r   stderrwriterL   r9   )sourcesr*   	processedresultsr  r  r   r   rQ   output_filenameout_of_daterT   r   r   r   compile_multiple  s*    


rA  c             K   s>   t f d|i|}t| tr0|j r0t| ||S t| |S d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.
    r  N)r  rE   r   r  r9  rA  )rQ   r*   r   kwdsr   r   r   compile  s    
rC  Fc             C   s  |rJ|d }t |tstd|r8tjj|jf|  } ntj|jf|  } |}|rZ||7 }|s|j	d}t
|dd }|d }	|	| }
d| }x| D ]x}tjj||}tjj|r|S |stj||}|dk	rtjj||
}tjj|r|S tjj||	|}tjj|r|S qW dS )	a$  
    Search the list of include directories for the given file name.

    If a source file 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   z$Only file sources for code supportedrY   Nr   r1   r   r   )rE   r   r   rH   ri   r   r   r   r   rc   r   r   r   r   )dirsr]   r   rl   r   	file_descdotted_filenamer   r   rP   module_filenamepackage_filenamer   ri   package_dirr   r   r   re     s>    



re   c               C   s
   t ddS )Nr   )command_line)mainr   r   r   r   setuptools_mainG  s    rL  c             C   s   t jdd  }d}| r0ddlm} ||\}}ntt}|}|jrRt jjdt	  |j
dkrhtj|j
 yt||}|jdkrd}W n> ttfk
r } zt jjt|d  d}W Y d d }~X nX |rt jd d S )Nr   r   )parse_command_linezCython version %s
r    
)r   argvCmdLinerM  r  r	  r  r:  r;  versionr   rH   chdirrC  r   r   r   strexit)rJ  r   any_failuresrM  r*   r<  rT   r   r   r   r   rK  K  s(    


rK  r    T)r  r   r   r   r   r   r$  r#  r*  r   r  r  r  r(   r   r%  r&  r   r'  r0   r   r(  r)  r+  r  r"  r  r!  r  )r   r   )r   r   )r   r   )NN)N)NN)F)r   )<
__future__r   rH   rer   r   version_infor:  r;  r   rT  r   r   r   rS  r    r   StringEncodingr	   Scanningr
   r   r   r   r   r   Symtabr   r   r   r   rQ  rC  r^   r  ri   r~   r   r   r   r   r   objectr   r   r   rJ   rL   rG   r  r   r
  r8  r9  rA  cached_functionre   rL  rK  r	  r   r   r   r   <module>   s   4


   
5 
$
7
