
     hE                         d dl mZ ddlZ ej        ej                  j        d         Zda G d d          ad Z	 G d de
          Zdd	Zd
 Zd ZddZd ZdS )   )_ccallback_c    Nc                       e Zd ZdS )CDataN)__name__
__module____qualname__     Q/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/scipy/_lib/_ccallback.pyr   r   	   s        Dr   r   c                      t           d S 	 dd l} |                                 a t           j        ad S # t          $ r da Y d S w xY w)Nr   F)fficffiFFIr   ImportError)r   s    r   _import_cffir      sZ     hhjj	   s   $1 A Ac                       e Zd ZdZdZddZd Zed             Zed             Z	ed             Z
d	 Zedd
            Ze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                 l    |                      |||          }t                              | |||f          S N)_parse_callbacktuple__new__)clsfunction	user_data	signatureitems        r   r   zLowLevelCallable.__new__T   s6     ""8Y	BB}}S49"=>>>r   c                 B    d                     | j        | j                  S )NzLowLevelCallable({!r}, {!r}))formatr   r   selfs    r   __repr__zLowLevelCallable.__repr__Z   s    -44T]DNSSSr   c                 8    t                               | d          S )Nr   r   __getitem__r!   s    r   r   zLowLevelCallable.function]         q)))r   c                 8    t                               | d          S )N   r%   r!   s    r   r   zLowLevelCallable.user_dataa   r'   r   c                 \    t          j        t                              | d                    S )Nr   )r   get_capsule_signaturer   r&   r!   s    r   r   zLowLevelCallable.signaturee   s#    1%2C2CD!2L2LMMMr   c                     t                      r   )
ValueError)r"   idxs     r   r&   zLowLevelCallable.__getitem__i   s    llr   c                     	 |j         |         }nR# t          $ r}t          d          |d}~wt          $ r(}t          d                    |                    |d}~ww xY 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   es          r   from_cythonzLowLevelCallable.from_cythonl   s    "	i*40HH 	g 	g 	g^__eff 	i 	i 	iSZZ[_``aaghh	is8Y	222s    
A*A#AAc                    t                       t          |t                    rt                              |d          }nxt          |t
                    rt          ||          \  }}nOt          |t                    rt          ||          \  }}n&t          j
        |          r|}nt          d          t          |t          j                  rt          |          }nPt          |t                    rt          |          }n+|d}n&t          j
        |          r|}nt          d          t          j        |||          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contexts         r   r   z LowLevelCallable._parse_callback   sB   c+,, 		n$$S!,,DDZ(( 	n.sI>>OD))U## 	n,S)<<OD))',, 	nDDlmmmi11 		o&y11GG	5)) 	o$Y//GGGG'	22 	oGGmnnn+D)WEEEr   )NN)r   r   r	   __doc__	__slots__r   r#   propertyr   r   r   r&   classmethodr6   r   r
   r   r   r   r      s        4 4n I? ? ? ?T T T * * X* * * X* N N XN   3 3 3 [30 F F F [F F Fr   r   c                    t          j        | t           j                  j        }|dt	          | j                  dz   }t          | j                  D ]3\  }}|dk    r|t	          |          z  }|dt	          |          z   z  }4|dz  }||fS )Nz (r   z, ))r=   castr>   value_typename_from_ctypesrestype	enumerateargtypes)rC   r   func_ptrjargs        r   r:   r:      s    {4117H )$,77$>	.. 	? 	?FAsAvv23777		T$9#$>$>>>		S	Yr   c                    | dS | t           j        u rdS | j        }d}|                    d          r$|dz  }|dd          }|                    d          $|                    d          r
|dd          }|dk    r|d	d
|z  z   z  }|S )Nvoidzvoid *r   LP_r      c_r)    *)r=   r>   r   
startswith)r   r4   pointer_levels      r   rM   rM      s    |v		 	 x=DM
//%
 
  ABBx //%
 
   t ABBxqc-'''Kr   c                 J    t          j        | t           j                  j        S r   )r=   rK   r>   rL   datas    r   r?   r?      s    ;tV_--33r   c                     t                               d|           }|Ft                               t                               |                                         dd          }||fS )N	uintptr_tz(*)rY   )r   rK   getctypetypeofreplace)rC   r   rQ   s      r   r;   r;      sU    xxT**H LLD!1!122::5#FF	Yr   c                 8    t                               d|           S )Nra   )r   rK   r^   s    r   r@   r@      s    88K&&&r   r   ) r   r=   	CFUNCTYPEr>   	__bases__r9   r   r   r   r   r   r:   rM   r?   r;   r@   r
   r   r   <module>ri      s         Vfo..8;

	 	 	 	 	 	 	 	  EF EF EF EF EFu EF EF EFX   "  ,4 4 4   ' ' ' ' 'r   