3
h}                 @   sN  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 d6k sdd7ejdd   ko^d8k 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m Z  ddl!m"Z" ddl#m$Z$m%Z%m&Z&m'Z' dd Z(dj)e$e(e&e%e(e'Z*ej+dj)e*Z*ej,j-ej,j.ej,j/ej,j/e0dZ1G dd de2Z3dd Z4dd Z5d9ddZ6G d d! d!e2Z7G d"d# d#e2Z8G d$d% d%e9Z:d:d&d'Z;d(d) Z<d;d*d+Z+ej=d<d.d/Z>ej=d0d1 Z?d2d3 Z@d=d4d5ZAdS )>    )absolute_importprint_functionN         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   sF   g }x6t dt| dD ]"}|jdj| | | |d   qW dj|S )Nr   r   z{0}-{1}r    )rangelenappendformatjoin)Zchrsouti r#   f/var/www/html/CrowdFlow/Picklecon/ble_analysis_env/lib/python3.6/site-packages/Cython/Compiler/Main.py_make_range_re'   s    "r%   z[{0}{1}][{0}{2}{1}{3}]*z{0}(\.{0})*$Z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dAddZdBdd Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. ZdCd/d0Zd1d2 Zd3d4 Zd5d6 Zd7d8 Z d9d: Z!dS )DContextNFc             C   s   ddl m}m} d|ji| _|j| | _| j| jd< || _t | _	|| _
|| _|| _i | _i | _|d k	rr| j| | j
jdd| _d | _d S )Nr   )BuiltinCythonScope__builtin__Zcythonlegacy_implicit_noexceptF)r   r'   r(   Zbuiltin_scopemodulesZcreate_cython_scopecython_scopeinclude_directoriessetfuture_directivescompiler_directivescppoptionspxds	_internedset_language_levelgetr*   Zgdb_debug_outputwriter)selfr-   r0   r1   language_levelr2   r'   r(   r#   r#   r$   __init__H   s    
zContext.__init__c             C   s   | |j |j|j|j|dS )N)r2   )Zinclude_pathr0   cplusr8   )clsr2   r#   r#   r$   from_optionsb   s    
zContext.from_optionsc             C   s   ddl m}m}m}m}m} t }|dkr0d}nt|}|dkrJ|j| |dkrd|j	||||g || _
|| _|dkr| jd | jd< d S )Nr   )r   unicode_literalsr   divisiongenerator_stopZ3strr   r)   builtins)Futurer   r=   r   r>   r?   r.   intaddupdater8   r/   r+   )r7   levelr   r=   r   r>   r?   r/   r#   r#   r$   r5   g   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
   r4   KeyErrorencoding)r7   valuerG   keyr#   r#   r$   intern_ustringw   s    


zContext.intern_ustringc       	      C   st   ddl m} t|trV|jdkrVt||tj }t|| j	}|j
| |}|j||}n|j| ||}|j||}|S )Nr   )PipelineZpyx)r   rK   
isinstancer   Z
_file_typeCompilationSourceosgetcwdcreate_default_resultobjr2   Zcreate_pyx_as_pxd_pipelinerun_pipelineZcreate_pxd_pipeline)	r7   source_descscopemodule_namerK   sourceZresult_sinkpipelineresultr#   r#   r$   process_pxd   s    zContext.process_pxdc             C   s
   t j|S )N)r	   Zreport_error)r7   excr#   r#   r$   nonfatal_error   s    zContext.nonfatal_errorc             C   sr   |j d}|j }dd |D }|dkrnd}x2d	D ]*}| j||d d | d}|r2| j|}P q2W |j||f |S )
N.c             S   s   g | ]}|d fqS )Tr#   ).0pr#   r#   r$   
<listcomp>   s    z1Context._split_qualified_name.<locals>.<listcomp>r9   F.py.pyx)suffix
source_possource_file_pathsys_path)r_   r`   )splitpopsearch_include_directories_is_init_filer   )r7   qualified_namerelative_importZqualified_name_partsZ	last_part
is_packagera   pathr#   r#   r$   _split_qualified_name   s    


zContext._split_qualified_namec             C   s   | rt jj| dkS dS )N__init__.pyx__init__.py__init__.pxdF)rn   ro   rp   )rN   rl   basename)rl   r#   r#   r$   rh      s    zContext._is_init_filec             C   sF   |sd S t jj|}d|krB|t jj|d krBt| d| dd d S )Nr[   r   z^Dotted filenames ('%s') are deprecated. Please use the normal Python package directory layout.r   )rE   )rN   rl   rq   splitextr   )pospxd_pathnameri   Zpxd_filenamer#   r#   r$   _check_pxd_filename   s    zContext._check_pxd_filenamer   Tc             C   s  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|
|| d}	| j||	|
 |	r| j	|	}|j
||d}|s|rt d |r|}
| }x(| j|
|dD ]\}}|j
||d}qW |r"t d	|  |js~|r8t d
 |	s|rLt d | j|
||o^| d}	| j||	|
 |rt d|	  |	 r|rd|_| j|
d|| d}|r|jtjrnt|d|
jdtj  |	r~d|_y|rt d|	  |jdtjtjj|	d  }|	j|s(|	}t|	|}| j|||
\}}|rN||\}}||f| j|< W n tk
r|   Y nX |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)rd   )
as_packagez...trying absolute import)rj   z...scope = %sz...pxd not loadedz...looking for pxd filez......found %sTz.py)ra   rb   rd   z'%s.pxd' not foundr[   zContext.find_module: Parsing %sr   )printZqualify_nameri   module_name_patternmatchr   lookup_submodulefind_pxd_fileru   rh   find_submodulerm   Zpxd_file_loadedrg   endswithr   ZPACKAGE_FILESr   replacerN   seprl   rr   r   rX   r3   )r7   rT   Zfrom_modulers   Zneed_pxdZabsolute_fallbackrj   Zdebug_find_modulerS   rt   ri   rk   nameZpackage_pathnamerel_pathrR   errrW   Zpxd_codenodesZ	pxd_scoper#   r#   r$   find_module   s    	




zContext.find_modulec             C   s6   | j |d|||d}|d kr2tjr2| j|||dS |S )Nz.pxd)ra   rb   rd   rc   )rd   )rg   r   Zcimport_from_pyxfind_pyx_file)r7   ri   rs   rd   rc   pxdr#   r#   r$   r{     s
    	zContext.find_pxd_filec             C   s   | j |d|||dS )Nz.pyx)ra   rb   rd   rc   )rg   )r7   ri   rs   rd   rc   r#   r#   r$   r     s    zContext.find_pyx_filec             C   s(   | j ||d|d}|s$t|d|  |S )NT)rb   includerc   z'%s' not found)rg   r   )r7   filenamers   rc   rl   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   )r-   sysrl   tuplestandard_include_pathrg   )r7   ri   ra   rb   r   rd   rc   include_dirsr#   r#   r$   rg   .  s    
z"Context.search_include_directoriesc             C   s
   t j|S )N)r   find_root_package_dir)r7   	file_pathr#   r#   r$   r   8  s    zContext.find_root_package_dirc             C   s   t j|t|S )N)r   check_package_dirr   )r7   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 tj|d}t jj|rRtj||rRdS x\| j|D ]N\}}|dkr~| j||d}n|dkr^| j	||d}nq^|r^tj||r^dS q^W dS )Nr   z.pxdcimport)rc   r   r   )
rN   rl   existsr   Zmodification_timeZfile_newer_thanreplace_suffixread_dependency_filer{   rg   )r7   source_pathZoutput_pathZc_timeZpxd_pathkindr   dep_pathr#   r#   r$   c_file_out_of_date>  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#   )r\   r   r   r#   r#   r$   r^   S  s    z7Context.find_cimported_module_names.<locals>.<listcomp>)r   )r7   r   r#   r#   r$   find_cimported_module_namesR  s    z#Context.find_cimported_module_namesc             C   s
   t j|S )N)r   is_package_dir)r7   Zdir_pathr#   r#   r$   r   V  s    zContext.is_package_dirc          
   C   sR   t j|d}tjj|rJt|d}dd dd |D D }W d Q R X |S f S d S )Nz.depZrUc             S   s    g | ]}d |kr|j d dqS ) r   )re   )r\   liner#   r#   r$   r^   ]  s   z0Context.read_dependency_file.<locals>.<listcomp>c             s   s   | ]}|j  V  qd S )N)strip)r\   lr#   r#   r$   	<genexpr>^  s    z/Context.read_dependency_file.<locals>.<genexpr>)r   r   rN   rl   r   open)r7   r   r   fchunksr#   r#   r$   r   Y  s    zContext.read_dependency_filec             C   s   | j j|d S )N)r+   r6   )r7   r   r#   r#   r$   rz   d  s    zContext.lookup_submodulec             C   s,   | j |}|s(t|d | |d}|| j|< |S )N)parent_modulecontextrk   )rz   r   r+   )r7   r   rv   rS   r#   r#   r$   r|   h  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)Zsource_encodingrS   r   r   )ConcreteSyntaxTreezLFormal grammar can only be used with compiled Cython with an available pgen.)rL   r   RuntimeErrorr   r1   r	   get_errors_countr   Zopen_source_filer   r   r   rG   Zp_moduler2   Zformal_grammarParserr   ImportErrorUnicodeDecodeError_report_decode_errorr   )r7   rR   rS   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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   )rG   newlinezqDecoding error, missing or incorrect coding=<encoding-name> at top of source (cannot decode with encoding %r: %s))argsior   r   	enumerater   r   )r7   rR   rY   msgpositionrG   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 )Nr[   )rN   rl   re   rr   r   r   reverser    )
r7   rl   r2   r   r   rT   _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)rl   Zecho_to_stderr)	r	   Zinit_threadZuse_listing_filer   r   main_source_filelisting_fileZopen_listing_fileZerrors_to_stderr)r7   r2   rW   rl   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r:d}|rz|j	rzyt
j|j	tj|j W n tk
rr   Y nX d |_	d S )Nz$Only file sources for code supportedr   T)compilation_sourcerR   rL   r   r   r	   Zclose_listing_filer   r   c_filer   Zcastrate_filerN   statr   EnvironmentError)r7   r   r2   rW   rR   r#   r#   r$   teardown_errors  s    



zContext.teardown_errors)FNN)N)F)NNr   TF)NTN)NTN)NN)NNFFN)F)"__name__
__module____qualname__r,   r8   r9   classmethodr<   r5   rJ   rX   rZ   rm   staticmethodrh   ru   r   r{   r   r   rg   r   r   r   r   r   r   rz   r|   r   r   r   r   r   r#   r#   r#   r$   r&   9   s>    


	 
[




	
	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)	r:   r   r   Zoutput_filerN   rl   r    isdirrq   )r   cwdr2   Zc_suffixZsuggested_file_nameZout_pathr#   r#   r$   get_output_filename  s    r   c             C   s:   t  }| jj|_| |_| j}t|j| j||_|j|_|S )N)	CompilationResultrR   r   r   r   r   r   r   Zembedded_metadata)r   r2   rW   rR   r#   r#   r$   rP     s    
rP   c             C   s4  ddl m} tjd dkr2tj| } |r2tj|}tjj| d }|j	|dd   |d krft
j|}tj }tjj| }|p|j| |}t|}tj| |jr|jdtj| }|j|s| }n|}t||}	t|	||} t| |}
|jd krJtjj|
jd d }tjj|rJtj|ddd	}d
|jdkr@d|_W d Q R X |j dks`| rp|j|||
}n|j |||
}|j!||
 d|krdtjjtjj"|d krt#|	ddfdtjj"| dd |j$|| \}}|j%|||
 |d kr0|j&r0ddl'm(} ||j)|
j*}tj+|
j|
j*| |
S )Nr   )rK   r   r   r[   z.htmlr   zUTF-8)rG   z<!-- Generated by Cythond   Tz.pyz^Dotted filenames ('%s') are deprecated. Please use the normal Python package directory layout.)rE   )create_dependency_tree),r   rK   r   version_infor   Zdecode_filenamerN   rl   rr   Zconfigure_language_defaultsr&   r<   rO   abspathr   r
   Z$raise_error_if_module_name_forbiddenZ'relative_path_in_code_position_commentsr~   r   r}   r   rM   rP   Zannotater   r   r   r   readlowerZcreate_py_pipelineZcreate_pyx_pipeliner   rq   r   rQ   r   ZdepfileZBuild.Dependenciesr   Zall_dependenciesr   Zwrite_depfile)rU   r2   r   r   rK   Z
source_extr   abs_pathr   rR   rW   Zhtml_filenameZ	html_filerV   r   Zenddatar   dependenciesr#   r#   r$   rQ     sV    






(
rQ   c               @   s   e Zd ZdZdd ZdS )rM   zk
    Contains the data necessary to start up a compilation pipeline for
    a single compilation unit.
    c             C   s   || _ || _|| _d S )N)rR   r   r   )r7   rR   r   r   r#   r#   r$   r9   /  s    zCompilationSource.__init__N)r   r   r   __doc__r9   r#   r#   r#   r$   rM   *  s   rM   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   Zh_fileZi_fileZapi_filer   Zobject_fileZextension_filer   )r7   r#   r#   r$   r9   D  s    zCompilationResult.__init__N)r   r   r   r   r9   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 )N)r   )r7   rU   rW   r#   r#   r$   rC   Z  s    zCompilationResultSet.addN)r   r   r   r   r   rC   r#   r#   r#   r$   r   O  s   r   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.
    )rQ   )rU   r2   r   r#   r#   r$   compile_single_  s    r   c             C   s   t | dkr|jrtddd | D } t }t }|j}|j}d}tj }x| D ]}||krR|dkrpt	j
|}t|||}	|j||	}
| s|
r|rtjjd|  t|||j|d}|j|| d}|j| qRW |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j|qS r#   )rN   rl   r   )r\   rU   r#   r#   r$   r^   w  s    z$compile_multiple.<locals>.<listcomp>NzCompiling %s
)r   r   )r   rT   r   r.   r   
timestampsverboserN   rO   r&   r<   r   r   r   stderrwriterQ   rC   )sourcesr2   	processedresultsr   r   r   r   rU   Zoutput_filenameZout_of_daterW   r#   r#   r$   compile_multiplej  s2    


r   c             K   s>   t f d|i|}t| tr4|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.
    defaults)r   rL   r   r   r   r   )rU   r2   r   kwdsr#   r#   r$   compile  s    

r   r   Fc             C   s2  |r*| r*|d }t |ts$td|j}|rV|rFtjj|f|  } ntj|f|  } |}|rf||7 }x*| D ]"}tjj	||}	tjj
|	rl|	S qlW |s.|jd}
t|
dd }|
d }g }xH| D ]@}tj||\}}|dk	r|r|j| qt|||}	|	r|	S qW x$|D ]}t|||}	|	r|	S qW d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   z$Only file sources for code supportedr[   Nr   r   r   )rL   r   r   r   rN   rl   dirnamer   r   r    r   re   r   r   r   search_module_in_dir)dirsri   ra   rs   r   rc   Z	file_descZdotted_filenamer   rl   r   r   rT   Znamespace_dirspackage_diris_namespacer#   r#   r$   rg     sF    








rg   c             C   s4   t j| ||}| r0|r0t jtjj| |d|}|S )Nr9   )r   Zfind_versioned_filerN   rl   r    )r   rT   ra   rl   r#   r#   r$   r     s    
r   c               C   s
   t ddS )Nr   )command_line)mainr#   r#   r#   r$   setuptools_main  s    r   c             C   s,  t jdd  }d}| ryt|\}}W q tk
r } zDdd l}|j|jkrN tdjt jd |jt j	d t j
d W Y d d }~X qX ntt}|}|jrtj  |jdkrt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 |r(t j
d d S )Nr   r   z#{}: No such file or directory: '{}')filer   
)r   argvr   IOErrorerrnoENOENTrw   r   r   r   exitr   r   Zshow_versionr   print_versionZworking_pathrN   chdirr   r   r   r   r   str)r   r   Zany_failuresr2   r   r   r   rW   r#   r#   r$   r     s4    


r   )r   r   )r   r   )r   r   )NN)N)NN)r   NFN)r   )B
__future__r   r   rN   rer   r   r   r   r   r   r   r)   r   r   r   r   r	   ZStringEncodingr
   ZScanningr   r   r   r   r   r   ZSymtabr   r   r   r   r   ZCmdLiner   ZLexiconr   r   r   r   r%   r   rx   r   rl   r   r    r   __file__r   objectr&   r   rP   rQ   rM   r   dictr   r   r   Zcached_functionrg   r   r   r   r#   r#   r#   r$   <module>   s^   4


    
F
(
: