o
    ȳgM                     @  sp   d dl mZ d dlZd dlmZ d dlmZmZmZ er$d dl	m
Z
mZ dddZdddZG dd deZdS )    )annotationsN)Enum)TYPE_CHECKINGAnyCallable)ResponseFutureSessionfuncCallable[..., ResponseFuture]argsr   kwargsreturnc                   sX   t    | |i |d fdd}d fd	d
}||  I dH S )a;  Wrap a Cassandra response future in an asyncio future.

    Args:
        func: The Cassandra function to call.
        *args: The arguments to pass to the Cassandra function.
        **kwargs: The keyword arguments to pass to the Cassandra function.

    Returns:
        The result of the Cassandra function.
    _r   r   Nonec                   s     j  d S N)call_soon_threadsafe
set_resultresult)r   asyncio_futureloopresponse_future c/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/langchain_community/utilities/cassandra.pysuccess_handler   s   z0wrapped_response_future.<locals>.success_handlerexcBaseExceptionc                   s     j|  d S r   )r   set_exception)r   )r   r   r   r   error_handler   s   z.wrapped_response_future.<locals>.error_handlerN)r   r   r   r   )r   r   r   r   )asyncioget_event_loopcreate_futureadd_callbacks)r	   r   r   r   r   r   r   r   wrapped_response_future   s   
r#   sessionr   querystrc                   s   t | j|fi |I dH S )a  Execute a CQL query asynchronously.

    Args:
        session: The Cassandra session to use.
        query: The CQL query to execute.
        kwargs: Additional keyword arguments to pass to the session execute method.

    Returns:
        The result of the query.
    N)r#   execute_async)r$   r%   r   r   r   r   aexecute_cql&   s   r(   c                   @  s   e Zd ZdZdZdZdS )	SetupMode         N)__name__
__module____qualname__SYNCASYNCOFFr   r   r   r   r)   4   s    r)   )r	   r
   r   r   r   r   r   r   )r$   r   r%   r&   r   r   r   r   )
__future__r   r   enumr   typingr   r   r   cassandra.clusterr   r   r#   r(   r)   r   r   r   r   <module>   s    

