o
    Ni                     @   s   d dl mZ d dlT d dlmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd	 d	eZd
d Zdd ZeddZedZedZeddeegdZedZdS )   )ModuleScope)*)CythonUtilityCodeerror)StringSourceDescriptor)
MemoryView)EncodedStringc                       sj   e Zd ZdZdZdd Zdd Z fddZ fd	d
Zdd Z	dddZ
dd Zdd Zdd Z  ZS )CythonScoper   Fc                 C   s   t | dd d  d| _|   || _tttfD ]}| j|j	|d dd}d|_
qt }| jd|d dd}| |_t }| jd|d dd}| |_d S )	NcythonTz<error>)cnamepymutex__Pyx_Locks_PyMutexpythread_type_lock__Pyx_Locks_PyThreadTypeLock)r   __init__pxd_file_loadedpopulate_cython_scope_contextcy_integral_typecy_floating_typecy_numeric_typedeclare_typedefnamein_cincludeget_cy_pymutex_typedeclare_typeget_decl_utility_codeutility_code_definitionget_cy_pythread_type_lock_type)selfcontext
fused_typeentrycy_pymutex_typecy_pythread_type_lock_type r&   O/home/ubuntu/.local/lib/python3.10/site-packages/Cython/Compiler/CythonScope.pyr      s.   
zCythonScope.__init__c                 C   s   | j jS N)r!   cpp)r    r&   r&   r'   is_cpp'   s   zCythonScope.is_cppc                    s   t |}|r|S t |S r(   )parse_basic_typesuperlookup_type)r    r   type	__class__r&   r'   r-   +   s   zCythonScope.lookup_typec                    s2   t  |}|d u r| js|   t  |}|S r(   )r,   lookup_cythonscope_initializedload_cythonscope)r    r   r#   r/   r&   r'   r1   3   s
   zCythonScope.lookupc                 C   s   t d| | d S )Ncython.%s is not availabler   )r    module_nameposr&   r&   r'   find_module<   s   zCythonScope.find_modulec                 C   sR   | j |d }|s|   | j |d }|r|jr|jS ttddddfd| )Nr        r4   )entriesgetr3   	as_moduler   r   )r    r5   
as_packager#   r&   r&   r'   find_submodule?   s   
zCythonScope.find_submodulec                 C   s^   | d}| }t|dkr(||d }|r|j}|d= |d u r"d S t|dks||d S )N.r   r9   )splitlenlookup_herer<   )r    qname	name_pathscoper&   r&   r'   lookup_qualified_nameO   s   
z!CythonScope.lookup_qualified_namec              	   C   sT   | j dtd dd}d|_|j}| jdtttdtd tdt	|d gd ddd d S )	NPyTypeObject)	base_typer6   r   TPyObject_TypeCheckotr   )r6   definingr   )
r   c_void_typeis_voidr.   declare_cfunction	CFuncTypec_bint_typeCFuncTypeArgpy_object_type
c_ptr_type)r    type_objecttype_object_typer&   r&   r'   r   ]   s"   
z!CythonScope.populate_cython_scopec                 C   s   | j rdS d| _ tj| | d tj| | d td| d | _}|| d|d_d|_d|_	t
j|| d t| jjj| j| tjd}dd |j D }|D ]}d|_qOtd	}t|| dd
}|| j||dd_d|_d|_	dS )zy
        Creates some entries for testing purposes and entries for
        cython.array() and for cython.view.*.
        NT)cython_scopeview)rW   	allowlistc                 S   s   g | ]	}|j jr|j qS r&   )r.   is_extension_type).0r#   r&   r&   r'   
<listcomp>   s    z0CythonScope.load_cythonscope.<locals>.<listcomp>r   dataclassesr!   )r6   )r2   cython_testscope_utility_codedeclare_in_scope!cython_test_extclass_utility_coder   	viewscopedeclare_moduler<   is_cython_builtinr   !cythonview_testscope_utility_coder   get_view_utility_coder!   shared_utility_qualified_nameview_utility_allowlistr:   valuesis_cython_builtin_typer	   )r    rb   view_utility_scope	ext_typesext_typedc_strdataclassesscoper&   r&   r'   r3   o   s@   

zCythonScope.load_cythonscope)F)__name__
__module____qualname__rd   r2   r   r*   r-   r1   r7   r>   rF   r   r3   __classcell__r&   r&   r/   r'   r
   
   s    	
r
   c                 C   s   t | S r(   )r
   r^   r&   r&   r'   create_cython_scope   s   rt   c                 K   s   t j| dfi |S )NzTestCythonScope.pyx)r   load)cy_util_namekwargsr&   r&   r'   load_testscope_utility   s   rx   a  
    /* These methods are undecorated and have therefore no prototype */
    static PyObject *__pyx_TestClass_cdef_method(
            struct __pyx_TestClass_obj *self, int value);
    static PyObject *__pyx_TestClass_cpdef_method(
            struct __pyx_TestClass_obj *self, int value, int skip_dispatch);
    static PyObject *__pyx_TestClass_def_method(
            PyObject *self, PyObject *value);
)proto	TestScopeTestDep	TestClass)r   requireszView.TestScopeN)Symtabr   
PyrexTypesUtilityCoder   Errorsr   Scanningr   r8   r   StringEncodingr	   r
   rt   rx   undecorated_methods_protosr_   test_cython_utility_depra   re   r&   r&   r&   r'   <module>   s*     

