Your IP : 216.73.216.213


Current Path : /opt/alt/python37/lib64/python3.7/site-packages/Cython/Compiler/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/site-packages/Cython/Compiler/__pycache__/Code.cpython-37.pyc

B

Z��Z�n�@s^ddlmZddlZejeeeeeeeeeeeeeeeed�ddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZddlmZddlmZyddlZWnek
r�ddlZYnXdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlmZddlmZyddl m!Z!Wn"ek
�rZddl"m#Z!YnXej$dkZ%dddddd�Z&ddiZ'ddddd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/d0d1d2d3d4d5gZ(e)d6d7d8d9d:d;d<d=d>d?d@dAdBg
�Z*dCdDij+Z,e�-dE�j.Z/GdFdG�dGe�Z0dHdI�Z1GdJdK�dKe�Z2GdLdM�dMe2�Z3drdNdO�Z4GdPdQ�dQe3�Z5GdRdS�dSe2�Z6GdTdU�dUe�Z7GdVdW�dWe�Z8GdXdY�dYe�Z9ejeeeedZ�e�-d[�:d2�ej;�j.Z<e�-d\�=d]��j.Z>e�-d^�j?Z@e�-d_�jAZBGd`da�dae�ZCGdbdc�dce�ZDGddde�dee�ZEdfdg�ZFGdhdi�die�ZGGdjdk�dke�ZHGdldm�dme�ZIGdndo�doe�ZJGdpdq�dqe�ZKdS)s�)�absolute_importN)�os�re�operator�textwrap�Template�Naming�Options�StringEncoding�Utils�SourceDescriptor�StringIOTree�
DebugFlags�
basestring�defaultdict�closing�partial)r)r)r)r�)r)r	)r)r
)�Version�)r)r)r
)r)�str)r�)zPY_MAJOR_VERSION < 3r)zPY_MAJOR_VERSION >= 3r)zPY_MAJOR_VERSION >= 3�range)zPY_MAJOR_VERSION >= 3�input)�bytes�unicoderZxrangeZ	raw_inputZPyTypeObjectZPyHeapTypeObject�
breakpoint�
__loader__�__spec__�BlockingIOError�BrokenPipeError�ChildProcessError�ConnectionAbortedError�ConnectionError�ConnectionRefusedError�ConnectionResetError�FileExistsError�FileNotFoundError�InterruptedError�IsADirectoryError�ModuleNotFoundError�NotADirectoryError�PermissionError�ProcessLookupError�RecursionError�ResourceWarning�TimeoutError�__build_class__�ascii�
memoryviewZWindowsError�_Z	__cinit__Z__dealloc__Z__richcmp__�__next__�	__await__�	__aiter__�	__anext__Z__getreadbuffer__Z__getwritebuffer__Z__getsegcount__Z__getcharbuffer__Z
__getbuffer__Z__releasebuffer__�inlineZ
CYTHON_INLINEz *(\w+) = (\1);\s*$c@sJeZdZdZdZdZdZdZddd	�Zd
d�Z	dd
�Z
dd�Zdd�ZdS)�IncludeCodez]
    An include file and/or verbatim C code to be included in the
    generated sources.
    rrrNTFcCs�|j|_t|�jd7_i|_|rb|ddkrR|ddkrRd�|�|jd<d}nd�|�|jd<|rr||j|j<|r�|j|_n|r�|j|_n|j|_dS)	Nrr�<����>z#include {0}Fz#include "{0}")	�counter�order�type�pieces�format�INITIAL�location�LATE�EARLY)�self�includeZverbatimZlate�initial�rJ�G/opt/alt/python37/lib64/python3.7/site-packages/Cython/Compiler/Code.py�__init__�s

zIncludeCode.__init__cCs<||kr0||}t|j|j�|_|j�|j�n|||<dS)z�
        Insert `self` in dict `d` with key `key`. If that key already
        exists, update the attributes of the existing value with `self`.
        N)�minrDrA�update)rG�d�key�otherrJrJrK�dict_update�s
zIncludeCode.dict_updatecCs|jS)N)r?)rGrJrJrK�sortkey�szIncludeCode.sortkeycCs|j�d�S)z�
        Return the main piece of C code, corresponding to the include
        file. If there was no include file, return None.
        r)rA�get)rGrJrJrK�	mainpiece�szIncludeCode.mainpiececCs(x"t|j�D]}|�|j|�qWdS)N)�sortedrA�putln)rG�code�krJrJrK�write�szIncludeCode.write)NNTF)
�__name__�
__module__�__qualname__�__doc__rCrFrEr>rLrRrSrUrZrJrJrJrKr:ss
r:cCs*tj�tj�tj�t���}tj�|d�S)NZUtility)r�path�dirname�abspath�__file__�join)Z
Cython_dirrJrJrK�get_utility_dir�srdc@s�eZdZdZdZiZeddd��Zedd��Zeddd	��Z	edifd
d��Z
eddd
��Ze�
d�jfdd�Zdd�Zdd�ZdS)�UtilityCodeBasea�
    Support for loading utility code from a file.

    Code sections in the file can be specified as follows:

        ##### MyUtility.proto #####

        [proto declarations]

        ##### MyUtility.init #####

        [code run at module initialization]

        ##### MyUtility #####
        #@requires: MyOtherUtility
        #@substitute: naming

        [definitions]

    for prototypes and implementation respectively.  For non-python or
    -cython files backslashes should be used instead.  5 to 30 comment
    characters may be used on either side.

    If the @cname decorator is not used and this is a CythonUtilityCode,
    one should pass in the 'name' keyword argument to be used for name
    mangling of such entries.
    FNc
Cs$|dkrdSd�|�}|r�d|kr�|dtdg�kr�|d=yt|��tt��}Wn8ttfk
r�}ztd|||f��Wdd}~XYnXd||}|dkr�||d<n0|dkr�||d<n|d	}t	r�|�
d
�}|||<|�r |d	}x8|��D],\}	}
t	�r|	�
d
�}	|�|	t���
|
�q�WdS)N�
�
substituteZnamingz@Error parsing templated utility code of type '%s' at line %d: %s�protor�implrr�ASCII)rc�setrrg�varsr�KeyError�
ValueError�RuntimeError�KEYWORDS_MUST_BE_BYTES�encode�items�
setdefaultrN)�cls�utilityr@�lines�begin_lineno�tagsrX�eZall_tags�name�valuesrJrJrK�_add_utility�s2
 



zUtilityCodeBase._add_utilityc	Cs�|j�|�}|r|Stj�t�|�}tj�|�\}}|dkr\d}tt�	d�j
d�}tjj
}n(d}tt�	d�j
d�}tt�	d�j
d�}t�	d	d
|i�j}	t�	d�j}
ttj|dd
���}|��}WdQRXtdd��}g}
tt�}d}}d}x�t|�D]�\}}|	|�}|�r�|�d��rz|�|||
||�|d}|
dd�=|��|�d�}|
|�}|�rl|��\}}nd}||}n$||�d��|�d��|
�d�q�|
�|||���q�W|dk�r�td��|�|||
||�t|�}||j|<|S)N)z.pyxz.pyz.pxdz.pxi�#z^\s*#.*��/z^\s*//.*|/\*[^*]*\*/z	\s+(\\?)$z\1zd^%(C)s{5,30}\s*(?P<name>(?:\w|\.)+)\s*%(C)s{5,30}|^%(C)s+@(?P<tag>\w+)\s*:\s*(?P<value>(?:\w|[.:])+)�Cz,(.+)[.](proto(?:[.]\S+)?|impl|init|cleanup)$zUTF-8)�encodingcSs
ddigS)NrJrJrJrJrK�<lambda>!�z:UtilityCodeBase.load_utilities_from_file.<locals>.<lambda>rrzrri�tag�valuezEmpty utility code file)�_utility_cacherTrr_rcrd�splitextrr�compile�subr
Z_unicode�rstrip�matchrrZopen_source_file�	readlinesrrk�	enumerate�groupr|�clear�groups�add�appendrn�dict)rtr_�	utilities�filenamer4�ext�comment�strip_commentsr�Z
match_specialZ
match_type�fZ	all_linesrvrxrur@rw�lineno�line�mrzZmtyperJrJrK�load_utilities_from_files\





z(UtilityCodeBase.load_utilities_from_filecs�d|kr|�dd�\�}�s�t��|d�yt���}WnXtk
r�ddl}t}|j�t|�	����}��fdd�|�
�D�}WdQRXYnX�fdd�|D�}|s�td	|��t|�dkr�td
|��|d���
��}	|	|\}
}}|�r�|���x�|��D]�\}
}|
|k�r�q|
dk�r`��rF���fdd�t|�D�}n��fd
d�t|�D�}n&|�sld}nt|�dk�r�t|�d}|||
<�qW|
dk	�r�|
|d<|dk	�r�||d<d|k�r�||d<d|k�r��r�|d<�f|�S)a
        Load utility code from a file specified by from_file (relative to
        Cython/Utility) and name util_code_name.  If from_file is not given,
        load it from the file util_code_name.*.  There should be only one
        file matched by this pattern.
        z::r�.rNcs,g|]$}tj��|����rtj�|��qSrJ)rr_rc�
startswith�basename)�.0rz)�archive�utility_dirrJrK�
<listcomp>_sz(UtilityCodeBase.load.<locals>.<listcomp>csg|]}|���r|�qSrJ)r�)r�r�)�prefixrJrKr�bsz No match found for utility code z4More than one filename match found for utility code �requirescsg|]}�j|�f���qSrJ)�load)r��dep)rt�	from_file�orig_kwargsrJrKr�uscsg|]}��|���qSrJ)�load_cached)r�r�)rtr�rJrKr�ysrhrirz�file)�rsplitrdr�listdir�OSError�zipfilerr�r�ZipFile�namelistrn�lenr��copyrrrV�list)rt�util_code_namer��kwargsZlistingr��loader�fileobj�filesr�rhrirxrzr{rJ)r�rtr�r�r�r�rKr�Hs^





zUtilityCodeBase.loadcCs@|||f}y||Stk
r&YnX|�||�}||<|S)z`
        Calls .load(), but using a per-type cache based on utility name and file name.
        )rmr�)rt�utility_code_namer�Z_UtilityCodeBase__cacherPrXrJrJrKr��s
zUtilityCodeBase.load_cachedcKs2|j||f|�}|j|j}}|�|�|�|�fS)zR
        Load a utility code as a string. Returns (proto, implementation)
        )r�rhri�format_code)rtr�r�r��utilrhrirJrJrK�load_as_string�szUtilityCodeBase.load_as_stringz\n\n+cCs|r|d|���d}|S)z3
        Format a code section for output.
        rfz

)�strip)rGZcode_stringZreplace_empty_linesrJrJrKr��szUtilityCodeBase.format_codecCsdt|�j|jfS)Nz<%s(%s)>)r@r[rz)rGrJrJrK�__str__�szUtilityCodeBase.__str__cKsdS)NrJ)rGr�rJrJrK�get_tree�szUtilityCodeBase.get_tree)N)N)N)r[r\r]r^Zis_cython_utilityr��classmethodr|r�r�r�r�rr�r�r�r�r�rJrJrJrKre�s!@Drec@s\eZdZdZddd�Zdd�Zdd	�Zd
d�Zddd
�Zdd�Z	dd�Z
dd�Zdd�ZdS)�UtilityCodeaF
    Stores utility code to add during code generation.

    See GlobalState.put_utility_code.

    hashes/equals by instance

    proto           C prototypes
    impl            implementation code
    init            code to call on module initialization
    requires        utility code dependencies
    proto_block     the place in the resulting file where the prototype should
                    end up
    name            name of the utility code (or None)
    file            filename of the utility code file this utility was loaded
                    from (or None)
    N�utility_code_protoc		Cs@||_||_||_||_||_i|_g|_||_||_||_	dS)N)
rhri�init�cleanupr��_cache�specialize_list�proto_blockrzr�)	rGrhrir�r�r�r�rzr�rJrJrKrL�szUtilityCode.__init__cCst|j|jf�S)N)�hashrhri)rGrJrJrK�__hash__�szUtilityCode.__hash__cCsj||krdSt|�t|�}}||k	r>t||�s>t||�s>dSt|dd�}t|dd�}||jf||jfkS)NTFrh)r@�
isinstance�getattrri)rGrQZ	self_typeZ
other_typeZ
self_protoZother_protorJrJrK�__eq__�szUtilityCode.__eq__cCs|dkrdS||S)zY
        Format a string in this utility code with context. If None, do nothing.
        NrJ)rG�s�contextrJrJrK�none_or_sub�szUtilityCode.none_or_subcs�|dk	r |���d<|���d<tt�����}y
|j|Stk
r�|jdkrZd}n�fdd�|jD�}t|�	|j
��|�	|j��|�	|j��|�	|j
��||j�}|j|<|j�|�|SXdS)Nr@Z	type_namecsg|]}|����qSrJ)�
specialize)r��r)�datarJrKr��sz*UtilityCode.specialize.<locals>.<listcomp>)Zempty_declaration_codeZspecialization_name�tuplerVrrr�rmr�r�r�rhrir�r�r�r�r�)rGZ
pyrex_typer�rPr�r�rJ)r�rKr��s&

zUtilityCode.specializecsXd|krd|krd|fSi���fdd�}t�d||�}d|krHd|ksLt�t��|fS)zHReplace 'PYIDENT("xyz")' by a constant Python identifier cname.
        zPYIDENT(z
PYUNICODE(FcsX|��}y�|}Wn>tk
rR|\}}�jt�|�|dkd�j}�|<YnX|S)NZIDENT)�
identifier)r�rm�get_py_string_constr
�
EncodedString�cname)�matchobjrPr�Zstr_typerz)�output�replacementsrJrK�externalise	s$z8UtilityCode.inject_string_constants.<locals>.externalisezPY(IDENT|UNICODE)\("([^"]+)"\))rr��AssertionError�bool)rGrir�r�rJ)r�r�rK�inject_string_constantss
z#UtilityCode.inject_string_constantscsld|krd|fSt�}�fdd�}t�d||�}d|ks<t�x"t|�D]}��t�|d��qFWt|�|fS)zVReplace 'UNBOUND_METHOD(type, "name")' by a constant Python identifier cname.
        zCALL_UNBOUND_METHOD(Fcs`|��\}}}}|r0dd�|dd��d�D�ng}t|�dksPtdt|�����||||�S)NcSsg|]}|���qSrJ)r�)r��argrJrJrKr� szKUtilityCode.inject_unbound_methods.<locals>.externalise.<locals>.<listcomp>r�,�z8CALL_UNBOUND_METHOD() does not support %d call arguments)r��splitr�r��cached_unbound_method_call_code)r��
type_cname�method_name�	obj_cname�args)r�rJrKr�s$z7UtilityCode.inject_unbound_methods.<locals>.externalisezMCALL_UNBOUND_METHOD\(([a-zA-Z_]+),\s*"([^"]+)",\s*([^),]+)((?:,\s*[^),]+)*)\)zObjectHandling.c)	rkrr�r�rV�use_utility_coder�r�r�)rGrir��utility_coder��helperrJ)r�rK�inject_unbound_methodssz"UtilityCode.inject_unbound_methodscCs2d|kr|Sdd�}t�d||�}d|ks.t�|S)z<Replace CSTRING('''xyz''') by a C compatible string
        zCSTRING(cSs*|�d��dd�}d�dd�|��D��S)Nr�"r~css:|]2}|�d�r|�d�r"d|nd|dd�VqdS)�\z\\z"%s\n"
z"%s"
Nr<)�endswith)r�r�rJrJrK�	<genexpr>:szCUtilityCode.wrap_c_strings.<locals>.split_string.<locals>.<genexpr>)r��replacerc�
splitlines)r��contentrJrJrK�split_string7sz0UtilityCode.wrap_c_strings.<locals>.split_stringz)CSTRING\(\s*"""([^"]*(?:"[^"]+)*)"""\s*\))rr�r�)rGrir�rJrJrK�wrap_c_strings1szUtilityCode.wrap_c_stringscCs�|jr x|jD]}|�|�qW|jrZ||j}|�d|j�|�|�|j�d|j�|jr�|�|�	|j��}|�
||�\}}|�||�\}}|d}|�d|j�|s�|s�|�|d|j�n
|�|�|j
�r:|d}|�d|j�t|j
t��r|�|�|j
��n|�
||j�|�|�|j��|��|j�r�tj�r�|d}|�d	|j�t|jt��r�|�|�|j�d
|j�n|�||j�dS)Nz/* %s.proto */z%s_proto�utility_code_defz/* %s */z%s_impl�init_globalsz
/* %s.init */�cleanup_globalsz/* %s.cleanup */z
%s_cleanup)r�r�rhr�rWrz�put_or_includer�rir�r�r��putr�r�r�
module_pos�error_goto_if_PyErrr�r	�generate_cleanup_code)rGr�Z
dependency�writerriZis_specialised1Zis_specialised2rJrJrK�put_codeAsB


zUtilityCode.put_code)NNNNNr�NN)N)
r[r\r]r^rLr�r�r�r�r�r�r�rrJrJrJrKr��s


r�cCsB|sdS|rd||f|d<n|r*||d<ddlm}||f|�S)z+Run tempita on string s with given context.Nz%s:%sZ__namer)r�)�Tempitar�)r�r�r�rzr�rJrJrK�sub_tempitaisrcs:eZdZd�fdd�	Zeddifdd��Zdd�Z�ZS)	�TempitaUtilityCodeNcs\|dkri}t||||�}t||||�}t||||�}tt|�j||f|||d�|��dS)N)r�rzr�)r�superrrL)rGrzrhrir�r�r�r�)�	__class__rJrKrLxs
zTempitaUtilityCode.__init__cCsn|rtt|����nd}t|�dk	s(t�||||f}y||Stk
rPYnX|j|||d�}||<|S)N)r�)r�rVrrr�r�rmr�)rtr�r�r�Z_TempitaUtilityCode__cacheZcontext_keyrPrXrJrJrKr��szTempitaUtilityCode.load_cachedcCs|dkrdSt|||j|j�S)zY
        Format a string in this utility code with context. If None, do nothing.
        N)rr�rz)rGr�r�rJrJrKr��szTempitaUtilityCode.none_or_sub)NNNNNN)r[r\r]rLr�r�r��
__classcell__rJrJ)rrKrws	rc@s(eZdZdZdZdZdd�Zdd�ZdS)�LazyUtilityCodez�
    Utility code that calls a callback with the root code writer when
    available. Useful when you only have 'env' but not 'code'.
    z<lazy>NcCs
||_dS)N)�callback)rGrrJrJrKrL�szLazyUtilityCode.__init__cCs|�|j�}|�|�dS)N)r�
rootwriterr�)rG�globalstaterurJrJrKr�szLazyUtilityCode.put_code)r[r\r]r^r�rLrrJrJrJrKr�s
rc@s�eZdZe�dfdd�Zd.dd�Zd/dd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd0dd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�ZdS)1�
FunctionStateNcCs�||_||_||_d|_d|_t�|_|��|_|�	�d|_
d|_g|_d|_
d|_d|_d|_d|_g|_i|_i|_d|_d|_g|_d|_d|_dS)NrFT)�names_taken�owner�scope�error_label�
label_counterrk�labels_used�	new_label�return_label�new_error_label�continue_label�break_label�yield_labelsZin_try_finallyZexc_varsZcurrent_except�	can_trace�	gil_owned�temps_allocated�
temps_free�temps_used_type�temp_counter�
closure_temps�collect_temps_stack�should_declare_error_indicator�uses_error_indicator)rGr
rrrJrJrKrL�s0
zFunctionState.__init__cCs6|j}|d|_dtj|f}|dk	r2|d|7}|S)Nrz%s%dr4)rrZlabel_prefix)rGrz�n�labelrJrJrKr�s
zFunctionState.new_label�yieldcCs0|�d|�}t|j�d|f}|j�|�|S)Nzresume_from_%sr)rr�rr�)rGZ	expr_typer#Z
num_and_labelrJrJrK�new_yield_label�szFunctionState.new_yield_labelcCs|j}|�d�|_|S)N�error)rr)rGZold_err_lblrJrJrKr�szFunctionState.new_error_labelcCs|j|jfS)N)rr)rGrJrJrK�get_loop_labels�szFunctionState.get_loop_labelscCs|\|_|_dS)N)rr)rG�labelsrJrJrK�set_loop_labels�szFunctionState.set_loop_labelscCs&|��}|�|�d�|�d�f�|S)N�continue�break)r'r)r)rG�
old_labelsrJrJrK�new_loop_labels�s
zFunctionState.new_loop_labelscCs|j|j|j|jfS)N)rrrr)rGrJrJrK�get_all_labels�szFunctionState.get_all_labelscCs|\|_|_|_|_dS)N)rrrr)rGr(rJrJrK�set_all_labelsszFunctionState.set_all_labelscCsZ|��}g}x>t|ddddg�D](\}}|r>|�|�|��q |�|�q W|�|�|S)Nr*r+�returnr&)r.�zipr�rr/)rGr,Z
new_labelsZ	old_labelrzrJrJrK�all_new_labels
s
zFunctionState.all_new_labelscCs|j�|�dS)N)rr�)rG�lblrJrJrK�	use_labelszFunctionState.use_labelcCs
||jkS)N)r)rGr3rJrJrK�
label_usedszFunctionState.label_usedFcCs�|jr|js|j}n|jr&|js&|j}|js6|js6d}|j�||f�}|dk	rr|drr|d�	�}|d�
|�nDx.|jd7_dtj
|jf}||jkrtPqtW|j�||||f�||f|j|<tjr�|j�d||f�|jr�|jd�||f�|S)a�
        Allocates a temporary (which may create a new one or get a previously
        allocated and released one of the same type). Type is simply registered
        and handed back, but will usually be a PyrexType.

        If type.is_pyobject, manage_ref comes into play. If manage_ref is set to
        True, the temp will be decref-ed on return statements and in exception
        handling clauses. Otherwise the caller has to deal with any reference
        counting of the variable.

        If not type.is_pyobject, then manage_ref will be ignored, but it
        still has to be passed. It is recommended to pass False by convention
        if it is known that type will never be a Python object.

        static=True marks the temporary declaration with "static".
        This is only used when allocating backing store for a module-level
        C array literals.

        A C string referring to the variable is returned.
        FNrrz%s%dz/* %s allocated (%s) */r<)�is_constZis_referenceZconst_base_typeZis_fake_referenceZ
ref_base_type�is_pyobject�is_memoryviewslicerrT�pop�removerr�codewriter_temp_prefixrrr�rr�debug_temp_code_commentsr
rWrr�)rGr@�
manage_ref�static�freelist�resultrJrJrK�
allocate_temps,
zFunctionState.allocate_tempcCs�|j|\}}|j�||f�}|dkr>gt�f}||j||f<||dkrVtd|��|d�|�|d�|�tjr�|j	�
d|�dS)zv
        Releases a temporary so that it can be reused by other code needing
        a temp of the same type.
        NrzTemp %s freed twice!rz/* %s released */)rrrTrkror�r�rr<r
rW)rGrzr@r=r?rJrJrK�release_tempNs
zFunctionState.release_tempcCsZg}xP|jD]F\}}}}|j�||f�}|dks<||dkr|�|||oL|jf�qW|S)zxReturn a list of (cname,type,manage_ref) tuples of temp names and their type
        that are currently in use.
        Nr)rrrTr�r7)rG�usedrzr@r=r>r?rJrJrK�temps_in_use_szFunctionState.temps_in_usecCsdd�|��D�S)z�Return a list of (cname,type) tuples of temp names and their type
        that are currently in use. This includes only temps of a
        Python object type which owns its reference.
        cSs$g|]\}}}|r|jr||f�qSrJ)r7)r�rzr@r=rJrJrKr�osz9FunctionState.temps_holding_reference.<locals>.<listcomp>)rD)rGrJrJrK�temps_holding_referencejsz%FunctionState.temps_holding_referencecCsdd�|jD�S)zRReturn a list of (cname, type) tuples of refcount-managed Python objects.
        cSs g|]\}}}}|r||f�qSrJrJ)r�r�r@r=r>rJrJrKr�vs
z3FunctionState.all_managed_temps.<locals>.<listcomp>)r)rGrJrJrK�all_managed_tempssszFunctionState.all_managed_tempscCsdd�|j��D�S)z�Return a list of (cname, type) tuples of refcount-managed Python
        objects that are not currently in use.  This is used by
        try-except and try-finally blocks to clean up temps in the
        error case.
        cSs.g|]&\\}}}|r|dD]}||f�qqS)rrJ)r�r@r=r?r�rJrJrKr��sz8FunctionState.all_free_managed_temps.<locals>.<listcomp>)rrr)rGrJrJrK�all_free_managed_tempszsz$FunctionState.all_free_managed_tempscCs|j�t��dS)zJ
        Useful to find out which temps were used in a code block
        N)rr�rk)rGrJrJrK�start_collecting_temps�sz$FunctionState.start_collecting_tempscCs
|j��S)N)rr9)rGrJrJrK�stop_collecting_temps�sz#FunctionState.stop_collecting_tempscCst|�|_dS)N)�ClosureTempAllocatorr)rGrrJrJrK�init_closure_temps�sz FunctionState.init_closure_temps)N)r$)F)r[r\r]rkrLrr%rr'r)r-r.r/r2r4r5rArBrDrErFrGrHrIrKrJrJrJrKr�s*
'


1	
rc@seZdZdZddd�ZdS)�NumConstz�Global info about a Python number constant held by GlobalState.

    cname       string
    value       string
    py_type     string     int, long, float
    value_code  string     evaluation code if different from value
    NcCs ||_||_||_|p||_dS)N)r�r��py_type�
value_code)rGr�r�rMrNrJrJrKrL�szNumConst.__init__)N)r[r\r]r^rLrJrJrJrKrL�srLc@seZdZdZdd�ZdS)�
PyObjectConstz>Global info about a generic constant held by GlobalState.
    cCs||_||_dS)N)r�r@)rGr�r@rJrJrKrL�szPyObjectConst.__init__N)r[r\r]r^rLrJrJrJrKrO�srO)�possible_unicode_identifier�possible_bytes_identifier�replace_identifier�find_alphanumss
(?![0-9])\w+$z
(?![0-9])\w+$rjz[^a-zA-Z0-9_]+z([a-zA-Z0-9]+)c@s*eZdZdZdd�Zdd�Zd
dd	�ZdS)�StringConstz?Global info about a C string constant held by GlobalState.
    cCs(||_||_t�|�|_d|_g|_dS)N)r��textr
Zescape_byte_string�
escaped_value�
py_strings�py_versions)rGr�rU�byte_stringrJrJrKrL�s
zStringConst.__init__cCs*|sddg|_n||jkr&|j�|�dS)Nrr�)rXr�)rG�versionrJrJrK�add_py_version�s
zStringConst.add_py_versionNFcCsR|j}|j}t|p|�}|dko$|}|dkr4d}n(|��}|dkrNd}d}nd�t|��}||||f}	|dk	r�y||	Stk
r�Yq�Xni|_|r�d}
n2|dkr�t|t�r�tt	|��}
q�tt
|��}
nd}
|
r�tjd}ntj
}|r�d|}nd}d||�r
d�p|�rd	�pd
||jttj�d�f}
t|
|||||
�}||j|	<|S)N)�utf8zutf-8r2Zusasciizus-asciir~TFrz_%sz	%s%s%s_%sr��u�b)rWrUr��lowerrcrSrmr�rrQrPr�interned_prefixesZpy_const_prefixr�r��const_prefix�
PyStringConst)rGr�r��is_str�py3str_cstringrWrU�
is_unicodeZencoding_keyrP�internr�Zencoding_prefixZpystring_cname�	py_stringrJrJrKr��sP


zStringConst.get_py_string_const)NFN)r[r\r]r^rLr[r�rJrJrJrKrT�s
rTc@s"eZdZdZddd�Zdd�ZdS)	rbzDGlobal info about a Python string constant held by GlobalState.
    FNcCs(||_||_||_||_||_||_dS)N)r�rdr�rcrerf)rGr�r�rercrdrfrJrJrKrLszPyStringConst.__init__cCs|j|jkS)N)r�)rGrQrJrJrK�__lt__szPyStringConst.__lt__)FNF)r[r\r]r^rLrhrJrJrJrKrbs
rbc@sfeZdZiZddddddddd	d
ddd
ddddddddddddgZdadd�Zdd�Zdd �Zd!d"�Zd#d$�Z	d%d&�Z
d'd(�Zdbd*d+�Zd,d-�Z
dcd/d0�Zddd1d2�Zd3d4�Zded5d6�Zd7d8�Zd9d:�Zdfd;d<�Zdgd=d>�Zd?d@�ZdAdB�ZdhdCdD�ZdEdF�ZdGdH�ZdIdJ�ZdKdL�ZdMdN�ZdOdP�ZdQdR�ZdSdT�Z dUdV�Z!dWdX�Z"dYdZ�Z#d[d\�Z$d]d^�Z%d_d`�Z&dS)i�GlobalStateZh_code�filename_tableZutility_code_proto_before_typesZnumeric_typedefsZcomplex_type_declarationsZtype_declarationsr�Zmodule_declarationsZtypeinfoZbefore_global_var�
global_var�string_decls�declsZ
late_includesZall_the_rest�pystring_table�cached_builtins�cached_constantsr�Zinit_moduler��cleanup_moduleZmain_methodr��endNcCsvi|_g|_i|_t�|_i|_d|_||_||_i|_	||_
i|_i|_i|_
i|_g|_i|_|�|�||_dS)NF)rj�
filename_list�input_file_contentsrk�
utility_codes�declared_cnamesZin_utility_code_generation�code_config�common_utility_include_dir�parts�module_node�const_cnames_used�string_const_index�pyunicode_ptr_const_index�num_const_index�py_constants�cached_cmethods�set_global_stater	)rGr�rzrwrxrJrJrKrLUs$
zGlobalState.__init__cCs8|j}x|jD]}|��|j|<qWtjs4|jd=n|jd}|��|�d�|jd}|��|�d�|�d�|��|�	d�|jd}|��|�d�|�d�tj
s�|jd	=n&|jd	}|��|�d�|�d
�|jd}|�d�|�d�|jd
}|jj�r |�
d�|�d�|�d�dS)Nroz+static int __Pyx_InitCachedBuiltins(void) {rpr~z,static int __Pyx_InitCachedConstants(void) {Z__Pyx_InitCachedConstantsr�z$static int __Pyx_InitGlobals(void) {r�z(static void __Pyx_CleanupGlobals(void) {r�z)/* --- Runtime support code (head) --- */r�z
#line 1 "cython_utility"
z"/* --- Runtime support code --- */)r	�code_layout�insertion_pointryr	�cache_builtins�enter_cfunc_scoperW�put_declare_refcount_context�put_setup_refcount_contextr�rw�
emit_linenumsrZ)rGr	�part�wrXrJrJrK�initialize_main_c_codels@




















z"GlobalState.initialize_main_c_codecCs>|��|jd}t�dd�}|�|�|j��|�d�dS)Nr�ZTypeConversionszTypeConversion.cr~)�close_global_declsryrr�r�r�rirW)rGrXr�rJrJrK�finalize_main_c_code�s

z GlobalState.finalize_main_c_codecCs
|j|S)N)ry)rGrPrJrJrK�__getitem__�szGlobalState.__getitem__cCsB|��tjrV|jd}|�d�|�|j�rD|�|j�|�d�|�d�|��|jd}|�	�|�d�|�|j�r�|�|j�|�	�|�d�|�d�|��|jd}|�d�|�|j�r�|�|j�|�d�|�d�|��tj
�r|jd}|�d�|��tj
�r>|jd}|�d�|��dS)	Nroz	return 0;z
return -1;�}rpr�r�rq)�generate_const_declarationsr	r�ryrWr5r�	put_label�exit_cfunc_scope�put_finish_refcount_contextr�)rGr�rJrJrKr��sB















zGlobalState.close_global_declscCs|d�d|j�dS)Nrkzstatic PyObject *%s;)rWr�)rG�entryrJrJrK�put_pyobject_decl�szGlobalState.put_pyobject_declcCs
|jdS)Nrp)ry)rGrJrJrK�get_cached_constants_writer�sz'GlobalState.get_cached_constants_writerFcCsD|rdp
d}y|j||f}Wn tk
r>|�||�}YnX|S)N�long�int)r~rm�
new_num_const)rG�	str_value�longnessrM�crJrJrK�
get_int_const�szGlobalState.get_int_constcCs:y|j|df}Wn"tk
r4|�|d|�}YnX|S)N�float)r~rmr�)rGr�rNr�rJrJrK�get_float_const�s
zGlobalState.get_float_constr~cCs<|�||�}|dk	r8|tjkr8|jd}|�d|j�|S)Nr�z
Py_CLEAR(%s);)�new_py_constr	r�ryrWr�)rGr@r��
cleanup_level�constZcleanup_writerrJrJrK�get_py_const�s

zGlobalState.get_py_constcCsV|jr|��}n|��}y|j|}Wn tk
rF|�||�}YnX|�|�|S)N)re�
utf8encode�
byteencoder|rm�new_string_constr[)rGrU�
py_versionrYr�rJrJrK�get_string_const�s

zGlobalState.get_string_constcCsD|js
t�y|j|}Wn&tk
r>|��}|j|<YnX|S)N)rer�r}rm�new_const_cname)rGrUr�rJrJrK�get_pyunicode_ptr_const�s
z#GlobalState.get_pyunicode_ptr_constcCs^d}|r>|dk	r>|��|��kr>|j|dd�}|j|dd�}n
|�|�}|�|j|||�}|S)Nr�)r�r)r�r�r�r�r�)rGrUr�rc�
unicode_valuerdZc_stringrgrJrJrKr�s
zGlobalState.get_py_string_constcCs|j|dd�S)NT)r�)r�)rGrUrJrJrK�get_interned_identifiersz#GlobalState.get_interned_identifiercCs$|�|�}t|||�}||j|<|S)N)�new_string_const_cnamerTr|)rGrUrYr�r�rJrJrKr�s

zGlobalState.new_string_constcCs,|�||�}t||||�}||j||f<|S)N)�new_num_const_cnamerLr~)rGr�rMrNr�r�rJrJrKr�szGlobalState.new_num_constcCs$|�|�}t||�}|j�|�|S)N)r�rOrr�)rGr@r�r�r�rJrJrKr�#s

zGlobalState.new_py_constcCs|�dd�}|j|d�S)Nrj�ignore)r�)�decoder�)rGZbytes_valuer�rJrJrKr�)sz"GlobalState.new_string_const_cnamecCsJ|dkr|d7}d}tj|}d||f}|�dd��dd��d	d�}|S)
Nr��Lr�z%s%s�+r4�-Zneg_r�)rr`r�)rGr�rMr�r�rJrJrKr�.s
zGlobalState.new_num_const_cnamecCsztd|�dd��d�}|j}|}x,||krN||d}||<d||f}q$Wd||<|rhtj|}ntj}d||fS)Nr4� rz%s_%dz%s%s)rRr�r{rr`ra)rGr�r�rCZname_suffixr>rJrJrKr�7s
zGlobalState.new_const_cnamec	CsN||f}y|j|}Wn2tk
rH|�dd||f�}|j|<YnX|S)NZumethodz%s_%s)r�rmr�)rGr�r�rPr�rJrJrK�get_cached_unbound_methodEs z%GlobalState.get_cached_unbound_methodcCsHdt|�}|�t�|d��|�||�}|g|}d||d�|�fS)NzCallUnboundCMethod%dzObjectHandling.cz__Pyx_%s(&%s, %s)z, )r�r�r�r�r�rc)rGr�r�r�Z
arg_cnamesr�Zcache_cnamer�rJrJrKr�Ns
z+GlobalState.cached_unbound_method_call_codecCs�|jr�|jr�|�|j|�r�|�|�|jd}d}|jtkrzt|j\}}|�d|�|�	|j
t�|�|j�|�d�|�	|j
t�|j�|j�|r�|�d�dS)Nroz#if %sz#elsez#endif)
�
is_builtinr6�should_declarer�r�ryrz�non_portable_builtins_maprW�put_cached_builtin_init�posr
r�)rGr�r�Z	condition�replacementrJrJrK�add_cached_builtin_declZs"



z#GlobalState.add_cached_builtin_declc	CsH|jd}|�|�j}|�t�dd��|�d||||�|�f�dS)NroZGetBuiltinNamezObjectHandling.cz*%s = __Pyx_GetBuiltinName(%s); if (!%s) %s)ryr�r�r�r�r�rW�
error_goto)rGr�rzr�r�Zinterned_cnamerJrJrKr�ms
z#GlobalState.put_cached_builtin_initcCs$|��|��|��|��dS)N)�generate_cached_methods_decls�generate_string_constants�generate_num_constants�generate_object_constant_decls)rGrJrJrKr�xsz'GlobalState.generate_const_declarationscCsPdd�|jD�}|��|jd}x(|D] \}}}|�d|j�|��q(WdS)NcSsg|]}t|j�|j|f�qSrJ)r�r�)r�r�rJrJrKr�sz>GlobalState.generate_object_constant_decls.<locals>.<listcomp>rmz
static %s;)r�sortryrWr@�declaration_code)rG�consts�decls_writerr4r�r�rJrJrKr�~s

z*GlobalState.generate_object_constant_declsc	Cs�|js
dS|jd}|jd}g}x^t|j���D]L\\}}}|�|�|�t�|��j}|�	d||f�|�	d||f�q2Wt
jr�|jd}x|D]}|�	d|�q�WdS)Nrmr�z4static __Pyx_CachedCFunction %s = {0, &%s, 0, 0, 0};z%s.type = (PyObject*)&%s;r�zPy_CLEAR(%s.method);)r�ryrVrrr�r�r
r�r�rWr	r�)	rG�declr��cnamesr�r�r�Zmethod_name_cnamer�rJrJrKr��s 




z)GlobalState.generate_cached_methods_declscCs�dd�|j��D�}|��g}|jd}x�|D]�\}}}d}|jrxd|jksXd|jkrxd}|�dd|jkrpd	prd
�|�d|t�|j�f�|r�|�d�|j	dk	r0x*|j	��D]}|�
|jt|j�|f�q�Wq0Wxtt
|j���D]b\}}t�|�\}	}
|	�r|�d
�|�d||
f�|	r�|�d�|�d||	f�|�d�q�W|�r�|�t�dd��|��|jd}|�d�|�dtj�x�|D]�\}}}|j�r�|j�r�|jdk�r�d}
nd|j��}
|�d|j�|j�r(|�d�|�d|j|jj|jjddd|jf�|�d�|�d|j|||
|j|j|jf�|j�r�|�d��q�W|�d�|�d�|jd}|�d tj|�|j�f�dS)!NcSsg|]}t|j�|j|f�qSrJ)r�r�)r�r�rJrJrKr��sz9GlobalState.generate_string_constants.<locals>.<listcomp>rlFrr�Tz#if PY_MAJOR_VERSION %s 3r;z>=zstatic const char %s[] = "%s";z#endifz#ifdef Py_UNICODE_WIDEz static Py_UNICODE %s[] = { %s };z#elseZInitStringsz
StringTools.crnr~z$static __Pyx_StringTabEntry %s[] = {)rj�USASCIIzUS-ASCII�UTF8zUTF-8�0z"%s"zstatic PyObject *%s;z#if PY_MAJOR_VERSION >= 3z&{&%s, %s, sizeof(%s), %s, %d, %d, %d},rrz{0, 0, 0, 0, 0, 0, 0}z};r�z"if (__Pyx_InitStrings(%s) < 0) %s;)r|r{r�ryrXrWr
Zsplit_string_literalrVrWr�r�r�rVr}rrZencode_pyunicode_stringr�r�r�rZstringtab_cnamercr�r_rdrfrer�r�)rGZc_constsrWr�r4r�r�ZconditionalrgZutf16_arrayZutf32_arrayr�Zc_cnamer�r�rJrJrKr��s�


 








z%GlobalState.generate_string_constantsc
Cs�dd�|j��D�}|��|jd}|jd}x�|D]�\}}}}}}|j}	|�d|	�|dkrhd}
n:|dkrvd	}
n,t�|�r�d
}
nt|�	d��dkr�d
}
nd}
|�d|	|
||�
|	|j�f�q6WdS)NcSs2g|]*}|j|jddkt|j�|j|j|f�qS)rr�)rMr�r�rN)r�r�rJrJrKr��sz6GlobalState.generate_num_constants.<locals>.<listcomp>rmr�zstatic PyObject *%s;r�zPyFloat_FromDouble(%s)r�z%PyLong_FromString((char *)"%s", 0, 0)z$PyInt_FromString((char *)"%s", 0, 0)r��zPyInt_FromLong(%sL)zPyInt_FromLong(%s)z%s = %s; %s)r~r{r�ryr�rWrZlong_literalr��lstrip�error_goto_if_nullr�)rGr�r�r�rMr4r�rNr�r��functionrJrJrKr��s(


z"GlobalState.generate_num_constantscCsR||jkr@|j|}t|j�t|j�ks,t�|j|jks<t�dS||j|<dSdS)NFT)rvrr@r�r�)rGr�r�rQrJrJrKr�s


zGlobalState.should_declarecCsP|��}y|j|}Wn4tk
rJt|j�}|j�|�||j|<YnX|S)N)Zget_filenametable_entryrjrmr�rsr�)rG�source_descr��indexrJrJrK�lookup_filenames
zGlobalState.lookup_filenamec	Csry
|j|Stk
rYnX|jddd�}zdd�|D�}Wdt|d�rT|��X|sd|�d�||j|<|S)Nrjr�)r�Zerror_handlingcSs(g|] }d|���dd��dd��qS)z * z*/z.*[inserted by cython to avoid comment closer]/z/*z-/[inserted by cython to avoid comment start]*)r�r�)r�r�rJrJrKr�%sz7GlobalState.commented_file_contents.<locals>.<listcomp>�closer~)rtrm�	get_lines�hasattrr�r�)rGr��source_file�FrJrJrK�commented_file_contentss




z#GlobalState.commented_file_contentscCs(|r$||jkr$|j�|�|�|�dS)a
        Adds code to the C file. utility_code should
        a) implement __eq__/__hash__ for the purpose of knowing whether the same
           code has already been included
        b) implement put_code, which takes a globalstate instance

        See UtilityCode.
        N)rur�r)rGr�rJrJrKr�6s	zGlobalState.use_utility_codecCs4|dkrdS|jr|�|j�|jr0|�|j�dS)N)r�r�Zutility_code_definition)rGr�rJrJrK�use_entry_utility_codeCsz"GlobalState.use_entry_utility_code)N)F)r~N)N)NFN)N)r~)r~r~)'r[r\r]�
directivesr�rLr�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�r�r�r�r�r�r�r�rJrJrJrKrisz
*)

	

	



	
		M

rics,t�����fdd�}�fdd�}t||�S)Ncs
�|j�S)N)�	funcstate)rG)�attribute_ofrJrKrTNsz!funccontext_property.<locals>.getcst|j�|�dS)N)�setattrr�)rGr�)rzrJrKrkPsz!funccontext_property.<locals>.set)r�
attrgetter�property)rzrTrkrJ)r�rzrK�funccontext_propertyLs
r�c@seZdZddd�ZdS)�CCodeConfigTcCs||_||_||_dS)N)�emit_code_commentsr��c_line_in_traceback)rGr�r�r�rJrJrKrLZszCCodeConfig.__init__N)TTT)r[r\r]rLrJrJrJrKr�Usr�c@steZdZdZdZZd�dd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zed�Zd�dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"d�d4d5�Z#d6d7�Z$d8d9�Z%d:d;�Z&d�d=d>�Z'd?d@�Z(dAdB�Z)d�dCdD�Z*dEdF�Z+dGdH�Z,dIdJ�Z-dKdL�Z.d�dMdN�Z/d�dPdQ�Z0dRdS�Z1dTdU�Z2dVdW�Z3dXdY�Z4dZd[�Z5d\d]�Z6d^d_�Z7d`da�Z8dbdc�Z9ddde�Z:dfdg�Z;dhdi�Z<djdk�Z=dldm�Z>dndo�Z?d�dpdq�Z@drds�ZAdtdu�ZBdvdw�ZCdxdy�ZDeEfdzd{�ZFd|d}�ZGd~d�ZHd�d��ZId�d��ZJd�d��ZKd�d��ZL�dd�d��ZM�dd�d��ZNd�d��ZOd�d��ZPd�d��ZQd�d��ZR�dd�d��ZSd�d��ZT�dd�d��ZU�dd�d��ZV�dd�d��ZW�dd�d��ZXd�d��ZYd�d��ZZd�d��Z[�dd�d��Z\d�d��Z]d�d��Z^d�d��Z_�dd�d��Z`d�d��Zad�d��Zb�d	d�d��Zc�d
d�d��Zdd�d��Ze�dd�d��Zf�dd�d��Zg�d
d�d��Zh�dd�dÄZi�dd�dńZj�dd�dDŽZk�dd�dɄZld�d˄Zmd�d̈́Zn�dd�dτZo�dd�dфZpd�dӄZqd�dՄZrd�dׄZsd�dلZtd�dۄZud�d݄Zvd�d߄Zw�dd�d�Zxd�d�Zy�dd�d�Zz�dd�d�Z{d�d�Z|�dd�d�Z}�dd�d�Z~d�d�Z�dd�d�Z�d�d�Z�d�d��Z�d�d��Z�dS(�CCodeWritera�
    Utility class to output C code.

    When creating an insertion point one must care about the state that is
    kept:
    - formatting state (level, bol) is cloned and used in insertion points
      as well
    - labels, temps, exc_vars: One must construct a scope in which these can
      exist by calling enter_cfunc_scope/exit_cfunc_scope (these are for
      sanity checking and forward compatibility). Created insertion points
      looses this scope and cannot access it.
    - marker: Not copied to insertion point
    - filename_table, filename_list, input_file_contents: All codewriters
      coming from the same root share the same instances simultaneously.
    NFcCs�|dkrt�}||_d|_d|_g|_d|_d|_d|_d|_|dk	r�|�	|j
�|j|_|rv|j|_|j|_|j|_|j|_|j|_dS)Nrr)r
�buffer�last_pos�last_marked_posZ
pyclass_stackr��levelZ
call_level�bolr�r
)rG�create_fromr��copy_formattingrJrJrKrL�s&zCCodeWriter.__init__cCst|||�}|S)N)r�)rGr�r�r�r@rJrJrK�
create_new�szCCodeWriter.create_newcCs |jdkst�||_|j|_dS)N)r
r�rw)rGZglobal_staterJrJrKr��szCCodeWriter.set_global_statecCs|j�|�dS)N)r��copyto)rGr�rJrJrKr��szCCodeWriter.copytocCs
|j��S)N)r��getvalue)rGrJrJrKr��szCCodeWriter.getvaluecCs>|jr|jdnd}|jj�|g|�d��|j�|�dS)Nrrrf)r�r��markers�extend�countrZ)rGr�Z
cython_linenorJrJrKrZ�szCCodeWriter.writecCs|j||j��dd�}|S)NT)r�r�r�)r�r�r�)rGrQrJrJrKr��szCCodeWriter.insertion_pointcCs
t|d�S)z�
        Creates a new CCodeWriter connected to the same global state, which
        can later be inserted using insert.
        )r�)r�)rGrJrJrK�
new_writer�szCCodeWriter.new_writercCs"|j|jkst�|j�|j�dS)z�
        Inserts the contents of another code writer (created with
        the same global state) in the current location.

        It is ok to write to the inserted writer also after insertion.
        N)r
r�r��insert)rGr�rJrJrKr��szCCodeWriter.insertrrrrrr�return_from_error_cleanup_labelrcCs|j�|�S)N)r�r)rGrzrJrJrKr�r�zCCodeWriter.new_labelcCs
|j��S)N)r�r)rGrJrJrKr�r�zCCodeWriter.new_error_labelcGs|jj|�S)N)r�r%)rGr�rJrJrKr%�r�zCCodeWriter.new_yield_labelcCs
|j��S)N)r�r')rGrJrJrKr'�r�zCCodeWriter.get_loop_labelscCs|j�|�S)N)r�r))rGr(rJrJrKr)�r�zCCodeWriter.set_loop_labelscCs
|j��S)N)r�r-)rGrJrJrKr-�r�zCCodeWriter.new_loop_labelscCs
|j��S)N)r�r.)rGrJrJrKr.�r�zCCodeWriter.get_all_labelscCs|j�|�S)N)r�r/)rGr(rJrJrKr/�r�zCCodeWriter.set_all_labelscCs
|j��S)N)r�r2)rGrJrJrKr2�r�zCCodeWriter.all_new_labelscCs|j�|�S)N)r�r4)rGr3rJrJrKr4�r�zCCodeWriter.use_labelcCs|j�|�S)N)r�r5)rGr3rJrJrKr5�r�zCCodeWriter.label_usedcCst||d�|_dS)N)r)rr�)rGrrJrJrKr��szCCodeWriter.enter_cfunc_scopecCs
d|_dS)N)r�)rGrJrJrKr��szCCodeWriter.exit_cfunc_scopecCs|j�||�jS)N)r
r�r�)rGr�r�rJrJrK�
get_py_int�szCCodeWriter.get_py_intcCs|j�||�jS)N)r
r�r�)rGr�rNrJrJrK�get_py_float�szCCodeWriter.get_py_floatr~cCs|j�|||�jS)N)r
r�r�)rGr@r�r�rJrJrKr��szCCodeWriter.get_py_constcCs|j�|�jS)N)r
r�r�)rGrUrJrJrKr��szCCodeWriter.get_string_constcCs|j�|�S)N)r
r�)rGrUrJrJrKr��sz#CCodeWriter.get_pyunicode_ptr_constcCs|j�||||�jS)N)r
r�r�)rGrUr�rcr�rJrJrKr��szCCodeWriter.get_py_string_constcCs|j�|�jS)N)r
r�r�)rGr@rJrJrK�get_argument_default_const�sz&CCodeWriter.get_argument_default_constcCs
|�|�S)N)r�)rGrUrJrJrKrf�szCCodeWriter.interncCs|j|dd�S)NT)r�)r�)rGrUrJrJrK�intern_identifierszCCodeWriter.intern_identifiercCs
|j��S)N)r
r�)rGrJrJrKr�sz'CCodeWriter.get_cached_constants_writercCsv|jr|jr|��|jjrD|jrD|j\}}}|�d||��f�|rb|rX|�|�n
|�	|�|�d�d|_dS)Nz
#line %s "%s"
rfr)
r�r��emit_markerrwr�r�rZ�get_escaped_description�put_safer�)rGrX�safer�r�r4rJrJrKrWs

zCCodeWriter.putlnTcCs>|dkrdS|jr0|jdd�|dd�kr0dS||f|_dS)Nr)r�r�)rGr��tracerJrJrK�mark_poss
 zCCodeWriter.mark_poscCs�|j\}}||_d|_|�d�|jjrD|��|�d|�|��|r�|jr�|jjr�|j	j
dr�|��|�d|d|jj|�|�f�dS)Nrfz	/* %s */
�	linetracez__Pyx_TraceLine(%d,%d,%s)
r)
r�r�rZrwr��indent�
_build_markerr�rr
r�rr�)rGr�r�rJrJrKr�s

zCCodeWriter.emit_markercCsv|\}}}t|t�st�|j�|�}|td|d�|�}|dd7<||||d�7}d|��|d�|�fS)Nrr�r<z             # <<<<<<<<<<<<<<rz"%s":%d
%s
rf)r�rr�r
r��maxr�rc)rGr�r�r��col�contentsrvrJrJrKr*s
zCCodeWriter._build_markercCs|�|�d|_dS)Nr)rZr�)rGrXrJrJrKr�3s
zCCodeWriter.put_safec	Cs�|jj}|r�t|�dkr�d|t�|�d����f}tj�	||�}tj�
|�s�d|t��f}tt
�|���}|�|�WdQRXt�||�d|}|�|�dS)Niz%s_%s.hr\z%s.tmp%sz#include "%s"
)r
rxr��hashlib�md5rq�	hexdigestrr_rc�exists�getpidrr�
open_new_filerZ�shutil�mover�)rGrXrzZinclude_dirZinclude_filer_Ztmp_pathr�rJrJrKr�8szCCodeWriter.put_or_includecCs�t|�rdSd}d|kr$|�d�}nd}d|kr|||�d�8}|dkrV|j|7_n&|dkr||ddkr|d}|jd8_|jr�|��|�|�d|_|dkr�|j|7_n|r�|jd7_dS)NF�{rr�Tr)�is_self_assignmentr�r�r�r�rZ)rGrXZ
fix_indentZdlrJrJrKr�Fs*
zCCodeWriter.putcKs"ddlm}|�||f|��dS)Nr)r�)rr�rW)rGrXr�r�rJrJrK�
putln_tempita_szCCodeWriter.putln_tempitacKs"ddlm}|�||f|��dS)Nr)r�)rr�r�)rGrXr�r�rJrJrK�put_tempitacszCCodeWriter.put_tempitacCs|jd7_dS)Nr)r�)rGrJrJrK�increase_indentgszCCodeWriter.increase_indentcCs|jd8_dS)Nr)r�)rGrJrJrK�decrease_indentjszCCodeWriter.decrease_indentcCs|�d�|��dS)Nr)rWr)rGrJrJrK�begin_blockms
zCCodeWriter.begin_blockcCs|��|�d�dS)Nr�)rrW)rGrJrJrK�	end_blockqszCCodeWriter.end_blockcCs|�d|j�dS)Nz  )rZr�)rGrJrJrKr�uszCCodeWriter.indentcCsdt|�ddd�S)Nz0x%02X%02X%02X%02X)rrrrr�)r�)rGZ	pyversionrJrJrK�get_py_version_hexxszCCodeWriter.get_py_version_hexcCs||jjkr|�d|�dS)Nz%s:;)r�rrW)rGr3rJrJrKr�{szCCodeWriter.put_labelcCs|j�|�|�d|�dS)Nzgoto %s;)r�r4rW)rGr3rJrJrK�put_gotoszCCodeWriter.put_gotocCs�|jdkr|s|jsdS|jdkr,|js,dS|r>|�d|�|jsN|�d�|�|jj|j|d��|jdk	r�|�	d|j�
|j��n|jjr�|�d�|�d�dS)NZprivatez%s zCYTHON_UNUSED )�dll_linkagez = %sz = NULL�;)
Z
visibilityZdefined_in_pxdrCr�Zcf_usedr@r�r�r�r�Zliteral_coder7rW)rGr�Z
storage_classrZ
definitionrJrJrK�put_var_declaration�s



zCCodeWriter.put_var_declarationc	Cs�xx|jD]n\}}}}|�|�}|jr4|�d|�q|jr\ddlm}|�d||jf�q|�d|rjdpld|f�qW|jr�|j	j
r�d}nd}|�d	|tjf�|�d
|tj
f�|�d	|tjf�dS)Nz
%s = NULL;r)�
MemoryViewz%s = %s;z%s%s;zstatic r~zCYTHON_UNUSED z
%sint %s = 0;z%sconst char *%s = NULL;)rr�r7rWr8r~rZmemslice_entry_initr r�r!r�lineno_cname�filename_cname�
clineno_cname)	rGZfunc_contextrzr@r=r>r�rZunusedrJrJrK�put_temp_declarations�s
z!CCodeWriter.put_temp_declarationscCs|�dtj�|�d�dS)Nz/* Generated by Cython %s */r~)rWrZ	watermark)rGrJrJrK�put_generated_by�szCCodeWriter.put_generated_bycCs |�d|�|�d|�dS)Nz
#ifndef %sz
#define %s)rW)rGZguardrJrJrK�put_h_guard�szCCodeWriter.put_h_guardcCstjrd|S|SdS)Nzunlikely(%s))r	Zgcc_branch_hints)rG�condrJrJrK�unlikely�szCCodeWriter.unlikelycs$|sdSdd��fdd�|D��S)Nr~z%s � csg|]}�||��qSrJrJ)r�r�)�mapperrJrKr��sz8CCodeWriter.build_function_modifiers.<locals>.<listcomp>)rc)rG�	modifiersr#rJ)r#rK�build_function_modifiers�sz$CCodeWriter.build_function_modifierscCs2|j}|js|j��r|jjr(d|jS|jSdS)Nz(PyObject *))r@Zis_self_argZis_completeZis_extension_typer�)rGr�r@rJrJrK�entry_as_pyobject�s

zCCodeWriter.entry_as_pyobjectcCsddlm}m}||||�S)Nr)�py_object_type�typecast)�
PyrexTypesr'r()rGr�r@r'r(rJrJrK�as_pyobject�szCCodeWriter.as_pyobjectcCs|�d|�dS)Nz__Pyx_GOTREF(%s);)rW)rGr�rJrJrK�
put_gotref�szCCodeWriter.put_gotrefcCs|�d|�dS)Nz__Pyx_GIVEREF(%s);)rW)rGr�rJrJrK�put_giveref�szCCodeWriter.put_giverefcCs|�d|�dS)Nz__Pyx_XGIVEREF(%s);)rW)rGr�rJrJrK�put_xgiveref�szCCodeWriter.put_xgiverefcCs|�d|�dS)Nz__Pyx_XGOTREF(%s);)rW)rGr�rJrJrK�put_xgotref�szCCodeWriter.put_xgotrefcCs6|r|�d|�||��n|�d|�||��dS)Nz__Pyx_INCREF(%s);zPy_INCREF(%s);)rWr*)rGr�r@�nannyrJrJrK�
put_incref�szCCodeWriter.put_increfcCs|j|||ddd�dS)NF)�
null_checkr�)�_put_decref)rGr�r@r/rJrJrK�
put_decref�szCCodeWriter.put_decrefcCs |jjr|�d|�|��dS)Nz__Pyx_GOTREF(%s);)r@r7rWr&)rGr�rJrJrK�put_var_gotref�szCCodeWriter.put_var_gotrefcCs |jjr|�d|�|��dS)Nz__Pyx_GIVEREF(%s);)r@r7rWr&)rGr�rJrJrK�put_var_giveref�szCCodeWriter.put_var_giverefcCs |jjr|�d|�|��dS)Nz__Pyx_XGOTREF(%s);)r@r7rWr&)rGr�rJrJrK�put_var_xgotref�szCCodeWriter.put_var_xgotrefcCs |jjr|�d|�|��dS)Nz__Pyx_XGIVEREF(%s);)r@r7rWr&)rGr�rJrJrK�put_var_xgiveref�szCCodeWriter.put_var_xgiverefcCs:|jjr6|r"|�d|�|��n|�d|�|��dS)Nz__Pyx_INCREF(%s);zPy_INCREF(%s);)r@r7rWr&)rGr�r/rJrJrK�put_var_incref�szCCodeWriter.put_var_increfcCs |jjr|�d|�|��dS)Nz__Pyx_XINCREF(%s);)r@r7rWr&)rGr�rJrJrK�put_var_xincref�szCCodeWriter.put_var_xincrefcCs|j|||dd|d�dS)NFT)r1r��clear_before_decref)r2)rGr�r@r/r:rJrJrK�put_decref_clear�szCCodeWriter.put_decref_clearcCs|j|||d|dd�dS)NTF)r1�have_gilr�)r2)rGr�r@r/r<rJrJrK�put_xdecrefszCCodeWriter.put_xdecrefcCs|j|||dd|d�dS)NT)r1r�r:)r2)rGr�r@r/r:rJrJrK�put_xdecref_clearszCCodeWriter.put_xdecref_clearc
	Cs�|jr|j||d�dS|r dnd}|r,dnd}	|rv|rV|s@d}	|�d||	|f�q�|�d||	|�||�|f�n|�d||	|�||�f�dS)	N)r<Z__PyxZPy�Xr~z%s_%sCLEAR(%s);z%s_%sDECREF(%s); %s = 0;z%s_%sDECREF(%s);)r8�put_xdecref_memoryviewslicerWr*)
rGr�r@r/r1r<r�r:r�r?rJrJrKr2
szCCodeWriter._put_decrefcCs|�d||f�dS)Nz__Pyx_DECREF_SET(%s, %s);)rW)rGr��	rhs_cnamerJrJrK�put_decref_setszCCodeWriter.put_decref_setcCs|�d||f�dS)Nz__Pyx_XDECREF_SET(%s, %s);)rW)rGr�rArJrJrK�put_xdecref_set"szCCodeWriter.put_xdecref_setcCs |jjr|�d|�|��dS)Nz__Pyx_XDECREF(%s);)r@r7rWr&)rGr�rJrJrK�put_var_decref%szCCodeWriter.put_var_decrefcCs:|jjr6|r"|�d|�|��n|�d|�|��dS)Nz__Pyx_XDECREF(%s);zPy_XDECREF(%s);)r@r7rWr&)rGr�r/rJrJrK�put_var_xdecref)szCCodeWriter.put_var_xdecrefcCs|j|dd�dS)NF)r1)�_put_var_decref_clear)rGr�rJrJrK�put_var_decref_clear0sz CCodeWriter.put_var_decref_clearcCs|j|dd�dS)NT)r1)rF)rGr�rJrJrK�put_var_xdecref_clear3sz!CCodeWriter.put_var_xdecref_clearcCsT|jjrP|jr,|�d|rdpd|jf�n$|�d|r:dp<d|�|�|jf�dS)Nz__Pyx_%sCLEAR(%s);r?r~z__Pyx_%sDECREF(%s); %s = 0;)r@r7�
in_closurerWr�r&)rGr�r1rJrJrKrF6s

z!CCodeWriter._put_var_decref_clearrcCs8x2|D]*}|r|jr|jr&|�|�q|�|�qWdS)N)rCZxdecref_cleanuprErD)rG�entriesZ	used_onlyr�rJrJrK�put_var_decrefsDs


zCCodeWriter.put_var_decrefscCsx|D]}|�|�qWdS)N)rE)rGrJr�rJrJrK�put_var_xdecrefsLs
zCCodeWriter.put_var_xdecrefscCsx|D]}|�|�qWdS)N)rH)rGrJr�rJrJrK�put_var_xdecrefs_clearPs
z"CCodeWriter.put_var_xdecrefs_clearcCs4ddlm}|j�|j�|�d|t|�f�dS)Nr)rz__PYX_INC_MEMVIEW(&%s, %d);)r~rr
r��memviewslice_init_coderWr�)rG�slice_cnamer<rrJrJrK�put_incref_memoryviewsliceTsz&CCodeWriter.put_incref_memoryviewslicecCs4ddlm}|j�|j�|�d|t|�f�dS)Nr)rz__PYX_XDEC_MEMVIEW(&%s, %d);)r~rr
r�rNrWr�)rGrOr<rrJrJrKr@Ysz'CCodeWriter.put_xdecref_memoryviewslicecCs|�d|�dS)Nz
%s.memview)r-)rGrOrJrJrK�put_xgiveref_memoryviewslice^sz(CCodeWriter.put_xgiveref_memoryviewslicecCsJddlm}m}|||d�}|r4|�d||f�n|�d||f�dS)Nr)r'r(�Py_Nonez%s = %s; __Pyx_INCREF(Py_None);z%s = %s; Py_INCREF(Py_None);)r)r'r(rW)rGr�r@r/r'r(Zpy_nonerJrJrK�put_init_to_py_noneas
zCCodeWriter.put_init_to_py_none�%scCs.||j}|�||j|�|jr*|�d�dS)NrR)r�rSr@rIr,)rGr��templater/rXrJrJrK�put_init_var_to_py_noneis
z#CCodeWriter.put_init_var_to_py_nonecCs�|js|jdkr:|jtkr:|jdkr2|jjds2n|r:dSddlm}|jrT|j}nd}|j	�
�}|r�|jrv||g7}|�d|j|jd�
|�||f�dS)	N�__getattribute__�__getattr__Zfast_getattrr)�method_coexistrz!{"%s", (PyCFunction)%s, %s, %s}%s�|)Z
is_specialrz�special_py_methodsr
r�Z	TypeSlotsrY�docZ	doc_cname�	signature�method_flagsrWZ
func_cnamerc)rGr�ZtermZ
allow_skiprYZdoc_coder^rJrJrK�put_pymethoddefqs*


zCCodeWriter.put_pymethoddefcCs�|j�t�dd��|jjdr6|j�t�dd��n|j�t�dd��|�d�|sjd}|rj|�d�|�d	|�|�d
�dS)a
        Acquire the GIL. The generated code is safe even when no PyThreadState
        has been allocated for this thread (for threads not initialized by
        using the Python API). Additionally, the code generated by this method
        may be called recursively.
        �ForceInitThreadszModuleSetupCode.c�fast_gil�FastGil�	NoFastGilz#ifdef WITH_THREAD�__pyx_gilstate_savezPyGILState_STATE z%s = __Pyx_PyGILState_Ensure();z#endifN)r
r�r�r�r�rWr�)rG�declare_gilstate�variablerJrJrK�put_ensure_gil�s

zCCodeWriter.put_ensure_gilcCsd|jjdr"|j�t�dd��n|j�t�dd��|s>d}|�d�|�d|�|�d�d	S)
zD
        Releases the GIL, corresponds to `put_ensure_gil`.
        rarbzModuleSetupCode.crcrdz#ifdef WITH_THREADz__Pyx_PyGILState_Release(%s);z#endifN)r
r�r�r�r�rW)rGrfrJrJrK�put_release_ensured_gil�s
z#CCodeWriter.put_release_ensured_gilcCst|jjdr"|j�t�dd��n|j�t�dd��|�d�|�d�|r\|�d|�|�d�|�d	�d
S)z
        Acquire the GIL. The thread's thread state must have been initialized
        by a previous `put_release_gil`
        rarbzModuleSetupCode.crcz#ifdef WITH_THREADz__Pyx_FastGIL_Forget();z_save = %s;ZPy_BLOCK_THREADSz#endifN)r
r�r�r�r�rW)rGrfrJrJrK�put_acquire_gil�s


zCCodeWriter.put_acquire_gilcCs~|jjdr"|j�t�dd��n|j�t�dd��|�d�|�d�|�d�|rf|�d|�|�d	�|�d
�dS)z2Release the GIL, corresponds to `put_acquire_gil`.rarbzModuleSetupCode.crcz#ifdef WITH_THREADzPyThreadState *_save;ZPy_UNBLOCK_THREADSz%s = _save;z__Pyx_FastGIL_Remember();z#endifN)r
r�r�r�r�rW)rGrfrJrJrK�put_release_gil�s



zCCodeWriter.put_release_gilcCs"|�d�|�d�|�d�dS)Nz#ifdef WITH_THREADz%PyGILState_STATE __pyx_gilstate_save;z#endif)rW)rGrJrJrKre�s

zCCodeWriter.declare_gilstatecCs|�d||�|�f�S)Nzif (%s < 0) %s)rWr�)rGr�r�rJrJrK�put_error_if_neg�szCCodeWriter.put_error_if_negc	Cs�ddlm}|jr&d}|j�|j�n2|jjrF|rFd}|j�|j�nd}|j�|j	�|�
d|j�|j�||j
|�|�f�dS)Nr)�	ExprNodesZ__Pyx_RaiseClosureNameErrorZ&__Pyx_RaiseUnboundMemoryviewSliceNogilZ__Pyx_RaiseUnboundLocalErrorz#if (unlikely(!%s)) { %s("%s"); %s })r~rlZfrom_closurer
r�Z%raise_closure_name_error_utility_coder@r8Z+raise_unbound_memoryview_utility_code_nogilZ&raise_unbound_local_error_utility_coderWZcheck_for_null_coder�rzr�)rGr�r�Zin_nogil_contextrl�funcrJrJrK�put_error_if_unbound�s"

z CCodeWriter.put_error_if_unboundcCsZd|j_|rd|j_|jjr.dtjtjf}nd}dtjtj	|�
|d�tj|d|fS)NTz	 %s = %s;r~z%s = %s[%s]; %s = %s;%srr)r�r r!rwr�rrZline_c_macror�filetable_cnamer�r)rGr�rCZcinforJrJrK�set_error_info�szCCodeWriter.set_error_infocCs0|jj}|j�|�d|�|d�|d|fS)Nz__PYX_ERR(%s, %s, %s)rr)r�rr4r�)rGr�r3rJrJrKr�	szCCodeWriter.error_gotocCsd|�|�|�|�fS)Nz
if (%s) %s)r!r�)rGr r�rJrJrK�
error_goto_if	szCCodeWriter.error_goto_ifcCs|�d||�S)Nz!%s)rq)rGr�r�rJrJrKr�	szCCodeWriter.error_goto_if_nullcCs|�d||�S)Nz%s < 0)rq)rGr�r�rJrJrK�error_goto_if_neg	szCCodeWriter.error_goto_if_negcCs|�d|�S)NzPyErr_Occurred())rq)rGr�rJrJrKr�	szCCodeWriter.error_goto_if_PyErrcCs|j�|�S)N)r
r�)rGr�rJrJrKr�	szCCodeWriter.lookup_filenamecCs|�d�dS)NZ__Pyx_RefNannyDeclarations)rW)rGrJrJrKr�	sz(CCodeWriter.put_declare_refcount_contextcCs6|r|j�t�dd��|�d||r(dp*df�dS)Nr`zModuleSetupCode.cz%__Pyx_RefNannySetupContext("%s", %d);rr)r
r�r�r�rW)rGrzZacquire_gilrJrJrKr�	sz&CCodeWriter.put_setup_refcount_contextcCs|�d�dS)Nz__Pyx_RefNannyFinishContext();)rW)rGrJrJrKr� 	sz'CCodeWriter.put_finish_refcount_contextcCs4||rtjndtjtjf}d|j_|�d|�dS)z�
        Build a Python traceback for propagating exceptions.

        qualified_name should be the qualified name of the function.
        rTz%__Pyx_AddTraceback("%s", %s, %s, %s);N)rrrrr�r!rW)rG�qualified_nameZ
include_cline�format_tuplerJrJrK�put_add_traceback#	szCCodeWriter.put_add_tracebackcCsL|tjtjtj|jjd|f}d|j_|�d|�|j�	t
�dd��dS)z�
        Generate code to print a Python warning for an unraisable exception.

        qualified_name should be the qualified name of the function.
        �unraisable_tracebacksTz0__Pyx_WriteUnraisable("%s", %s, %s, %s, %d, %d);ZWriteUnraisableExceptionzExceptions.cN)rrrrr
r�r�r!rWr�r�r�)rGrs�nogilrtrJrJrK�put_unraisable2	s
zCCodeWriter.put_unraisablecCs|�d�dS)NZ__Pyx_TraceDeclarations)rW)rGrJrJrK�put_trace_declarationsE	sz"CCodeWriter.put_trace_declarationscCs|r|�d|�dS)Nz__Pyx_TraceFrameInit(%s))rW)rG�codeobjrJrJrK�put_trace_frame_initH	sz CCodeWriter.put_trace_frame_initcCs4|�d|tj|�|d�|d||�|�f�dS)Nz*__Pyx_TraceCall("%s", %s[%s], %s, %d, %s);rr)rWrror�r�)rGrzr�rwrJrJrK�put_trace_callL	szCCodeWriter.put_trace_callcCs|�d�dS)Nz__Pyx_TraceException();)rW)rGrJrJrK�put_trace_exceptionP	szCCodeWriter.put_trace_exceptioncCs|�d||f�dS)Nz__Pyx_TraceReturn(%s, %d);)rW)rGZretvalue_cnamerwrJrJrK�put_trace_returnS	szCCodeWriter.put_trace_returncCs"|�d�|�|�|�d�dS)Nz#ifdef _OPENMPz#endif /* _OPENMP */)rW)rG�stringrJrJrK�putln_openmpV	s

zCCodeWriter.putln_openmpcCsD|�d|�|�d�|�d�|�d�|�d�|�d�dS)zl
        Redefine the macros likely() and unlikely to no-ops, depending on
        condition 'cond'
        z#if %sz    #undef likelyz    #undef unlikelyz    #define likely(x)   (x)z    #define unlikely(x) (x)z#endifN)rW)rGr rJrJrK�undef_builtin_expect[	s



z CCodeWriter.undef_builtin_expectcCsD|�d|�|�d�|�d�|�d�|�d�|�d�dS)Nz#if %sz    #undef likelyz    #undef unlikelyz2    #define likely(x)   __builtin_expect(!!(x), 1)z2    #define unlikely(x) __builtin_expect(!!(x), 0)z#endif)rW)rGr rJrJrK�redef_builtin_expectg	s



z CCodeWriter.redef_builtin_expect)NNF)N)N)r~N)NFN)r~F)T)r~NT)T)T)T)TF)TT)TF)TFTFF)T)r)F)F)T)rTT)T)TN)N)N)N)F)F)F)T)F)N)F)F)�r[r\r]r^r
rwrLr�r�r�r�rZr�r�r�r�rrrrrrr�rrrr%r'r)r-r.r/r2r4r5r�r�r�r�r�r�r�r�r�rfr�r�rWr�r�rr�r�r�rrrrrrr�rr�rrrrrr!�modifier_output_mapperr%r&r*r+r,r-r.r0r3r4r5r6r7r8r9r;r=r>r2rBrCrDrErGrHrFrKrLrMrPr@rQrSrVr_rgrhrirjrerkrnrpr�rqr�rrr�r�r�r�r�rurxryr{r|r}r~r�r�r�rJrJrJrKr�`s







	
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�PyrexCodeWritercCst�|�|_d|_dS)Nr)rr	r�r�)rGZoutfile_namerJrJrKrLt	szPyrexCodeWriter.__init__cCs|j�dd|j|f�dS)Nz%s%s
r")r�rZr�)rGrXrJrJrKrWx	szPyrexCodeWriter.putlncCs|jd7_dS)Nr)r�)rGrJrJrKr�{	szPyrexCodeWriter.indentcCs|jd8_dS)Nr)r�)rGrJrJrK�dedent~	szPyrexCodeWriter.dedentN)r[r\r]rLrWr�r�rJrJrJrKr�p	sr�c@sjeZdZdZddd�Zddd	�Zdd
d�Zdd
�Zdd�Zddd�Z	dd�Z
ddd�Zdd�Zdd�Z
dS)�
PyxCodeWriterz�
    Can be used for writing out some Cython code. To use the indenter
    functionality, the Cython.Compiler.Importer module will have to be used
    to load the code to support python 2.4
    Nrr2cCs"|pt�|_||_||_||_dS)N)r
r�r�r�r�)rGr��indent_levelr�r�rJrJrKrL�	szPyxCodeWriter.__init__rcCs|j|7_dS)NT)r�)rG�levelsrJrJrKr��	szPyxCodeWriter.indentcCs|j|8_dS)N)r�)rGr�rJrJrKr��	szPyxCodeWriter.dedentcCs|�|�|��dS)a
        Instead of

            with pyx_code.indenter("for i in range(10):"):
                pyx_code.putln("print i")

        write

            if pyx_code.indenter("for i in range(10);"):
                pyx_code.putln("print i")
                pyx_code.dedent()
        T)rWr�)rGr�rJrJrK�indenter�	s
zPyxCodeWriter.indentercCs$|j��}t|t�r |�|j�}|S)N)r�r�r�rr�r�)rGr@rJrJrKr��	s

zPyxCodeWriter.getvaluecCs&|p|j}|rt||�}|�|�dS)N)r�r�_putln)rGr�r�rJrJrKrW�	s

zPyxCodeWriter.putlncCs|j�d|jd|f�dS)Nz%s%s
z    )r�rZr�)rGr�rJrJrKr��	szPyxCodeWriter._putlncCsB|p|j}|rt||�}t�|�}x|��D]}|�|�q,WdS)N)r�rrr�r�r�)rG�chunkr�r�rJrJrK�	put_chunk�	s


zPyxCodeWriter.put_chunkcCst|j��|j|j�S)N)r�r�r�r�r�)rGrJrJrKr��	szPyxCodeWriter.insertion_pointcCst|||���dS)N)r�r�)rGrzrJrJrK�named_insertion_point�	sz#PyxCodeWriter.named_insertion_point)NrNr2)r)r)N)N)r[r\r]r^rLr�r�r�r�rWr�r�r�r�rJrJrJrKr��	s




	r�c@s$eZdZdd�Zdd�Zdd�ZdS)rJcCs||_i|_i|_d|_dS)Nr)�klassrr�temps_count)rGr�rJrJrKrL�	szClosureTempAllocator.__init__cCs*x$|j��D]\}}t|�|j|<qWdS)N)rrrr�r)rGr@r�rJrJrK�reset�	szClosureTempAllocator.resetcCs�||jkr g|j|<g|j|<n|j|r:|j|�d�Sdtj|jf}|jjd|||dd�|j|�|�|jd7_|S)Nrz%s%dT)r�rzr�r@Zis_cdefr)	rrr9rr;r�r�Zdeclare_varr�)rGr@r�rJrJrKrA�	s


z"ClosureTempAllocator.allocate_tempN)r[r\r]rLr�rArJrJrJrKrJ�	srJ)NN)L�
__future__r�cython�declare�objectrrr
�sysrrrr�	functoolsr�
contextlibr�collectionsrr�ImportErrorrr~rr	rr
rrZScanningrr
Z__builtin__r�builtinsr�version_inforpr�Zbasicsize_builtins_mapZuncachable_builtinsrkr[rTr�r�r�r
r:rdrer�rrrrrLrOr��UrPrqrQr�rR�findallrSrTrbrir�r�r�r�r�rJrJrJrJrK�<module>s�


Lm8
l
O7	E