o
    ÒtBhE  ã                   @   s€   d dl mZ ddlZe ej¡jd ZdaG dd„ dƒadd„ Z	G dd	„ d	e
ƒZdd
d„Zdd„ Zdd„ Zddd„Zdd„ ZdS )é   )Ú_ccallback_cé    Nc                   @   s   e Zd ZdS )ÚCDataN)Ú__name__Ú
__module__Ú__qualname__© r   r   úl/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/scipy/_lib/_ccallback.pyr   	   s    r   c                  C   sB   t d urd S zdd l} |  ¡ a t jaW d S  ty    da Y d S w )Nr   F)ÚffiÚcffiÚFFIr   ÚImportError)r   r   r   r	   Ú_import_cffi   s   
ÿr   c                   @   sn   e Zd ZdZdZddd„Zdd„ Zedd	„ ƒZed
d„ ƒZ	edd„ ƒZ
dd„ Zeddd„ƒZeddd„ƒZdS )ÚLowLevelCallablea¤  
    Low-level callback function.

    Parameters
    ----------
    function : {PyCapsule, ctypes function pointer, cffi function pointer}
        Low-level callback function.
    user_data : {PyCapsule, ctypes void pointer, cffi void pointer}
        User data to pass on to the callback function.
    signature : str, optional
        Signature of the function. If omitted, determined from *function*,
        if possible.

    Attributes
    ----------
    function
        Callback function given.
    user_data
        User data given.
    signature
        Signature of the function.

    Methods
    -------
    from_cython
        Class method for constructing callables from Cython C-exported
        functions.

    Notes
    -----
    The argument ``function`` can be one of:

    - PyCapsule, whose name contains the C function signature
    - ctypes function pointer
    - cffi function pointer

    The signature of the low-level callback must match one of those expected
    by the routine it is passed to.

    If constructing low-level functions from a PyCapsule, the name of the
    capsule must be the corresponding signature, in the format::

        return_type (arg1_type, arg2_type, ...)

    For example::

        "void (double)"
        "double (double, int *, void *)"

    The context of a PyCapsule passed in as ``function`` is used as ``user_data``,
    if an explicit value for ``user_data`` was not given.

    r   Nc                 C   s    |   |||¡}t | |||f¡S ©N)Ú_parse_callbackÚtupleÚ__new__)ÚclsÚfunctionÚ	user_dataÚ	signatureÚitemr   r   r	   r   T   s   zLowLevelCallable.__new__c                 C   s   d  | j| j¡S )NzLowLevelCallable({!r}, {!r}))Úformatr   r   ©Úselfr   r   r	   Ú__repr__Z   s   zLowLevelCallable.__repr__c                 C   ó   t  | d¡S )Nr   ©r   Ú__getitem__r   r   r   r	   r   ]   ó   zLowLevelCallable.functionc                 C   r   )Né   r   r   r   r   r	   r   a   r    zLowLevelCallable.user_datac                 C   s   t  t | d¡¡S )Nr   )r   Úget_capsule_signaturer   r   r   r   r   r	   r   e   s   zLowLevelCallable.signaturec                 C   s   t ƒ ‚r   )Ú
ValueError)r   Úidxr   r   r	   r   i   s   zLowLevelCallable.__getitem__c              
   C   sd   z|j | }W n$ ty } ztdƒ|‚d}~w ty+ } ztd |¡ƒ|‚d}~ww | |||ƒS )a  
        Create a low-level callback function from an exported Cython function.

        Parameters
        ----------
        module : module
            Cython module where the exported function resides
        name : str
            Name of the exported function
        user_data : {PyCapsule, ctypes void pointer, cffi void pointer}, optional
            User data to pass on to the callback function.
        signature : str, optional
            Signature of the function. If omitted, determined from *function*.

        z?Given module is not a Cython module with __pyx_capi__ attributeNz4No function {!r} found in __pyx_capi__ of the module)Ú__pyx_capi__ÚAttributeErrorr#   ÚKeyErrorr   )r   ÚmoduleÚnamer   r   r   Úer   r   r	   Úfrom_cythonl   s   
€€ÿzLowLevelCallable.from_cythonc                 C   sÈ   t ƒ  t|tƒrt |d¡}n&t|tƒrt||ƒ\}}nt|tƒr)t||ƒ\}}nt	 
|¡r1|}ntdƒ‚t|tjƒr@t|ƒ}nt|tƒrJt|ƒ}n|d u rQd}nt	 
|¡rY|}ntdƒ‚t	 |||¡S )Nr   zMGiven input is not a callable or a low-level callable (pycapsule/ctypes/cffi)zNGiven user data is not a valid low-level void* pointer (pycapsule/ctypes/cffi))r   Ú
isinstancer   r   r   Ú
PyCFuncPtrÚ_get_ctypes_funcr   Ú_get_cffi_funcr   Úcheck_capsuler#   ÚctypesÚc_void_pÚ_get_ctypes_dataÚ_get_cffi_dataÚget_raw_capsule)r   Úobjr   r   ÚfuncÚcontextr   r   r	   r   …   s(   







z LowLevelCallable._parse_callback)NN)r   r   r   Ú__doc__Ú	__slots__r   r   Úpropertyr   r   r   r   Úclassmethodr+   r   r   r   r   r	   r      s     7



r   c                 C   sp   t  | t j¡j}|d u r4t| jƒd }t| jƒD ]\}}|dkr'|t|ƒ7 }q|dt|ƒ 7 }q|d7 }||fS )Nz (r   z, ú))r1   Úcastr2   ÚvalueÚ_typename_from_ctypesÚrestypeÚ	enumerateÚargtypes)r7   r   Úfunc_ptrÚjÚargr   r   r	   r.   ¦   s   r.   c                 C   s~   | d u rdS | t ju rdS | j}d}| d¡r&|d7 }|dd … }| d¡s| d¡r1|dd … }|dkr=|d	d
|  7 }|S )NÚvoidzvoid *r   ÚLP_r   é   Úc_r!   ú Ú*)r1   r2   r   Ú
startswith)r   r)   Úpointer_levelr   r   r	   r@   ·   s   


þ
r@   c                 C   s   t  | t j¡jS r   )r1   r>   r2   r?   ©Údatar   r   r	   r3   Í   s   r3   c                 C   s4   t  d| ¡}|d u rt  t  | ¡¡ dd¡}||fS )NÚ	uintptr_tz(*)rK   )r
   r>   ÚgetctypeÚtypeofÚreplace)r7   r   rD   r   r   r	   r/   Ö   s   r/   c                 C   s   t  d| ¡S )NrQ   )r
   r>   rO   r   r   r	   r4   á   r    r4   r   )Ú r   r1   Ú	CFUNCTYPEr2   Ú	__bases__r-   r
   r   r   r   r   r.   r@   r3   r/   r4   r   r   r   r	   Ú<module>   s     

	