U
    hM                     @  s   d dl mZ d dlZd dlmZ d dlmZmZmZ erHd dl	m
Z
mZ dddddd	d
ZdddddddZG dd deZdS )    )annotationsN)Enum)TYPE_CHECKINGAnyCallable)ResponseFutureSessionzCallable[..., ResponseFuture]r   )funcargskwargsreturnc                   s^   t    | ||ddd fdd}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   None)_r   c                   s     j  d S N)call_soon_threadsafeZ
set_resultresult)r   asyncio_futureloopZresponse_future K/tmp/pip-unpacked-wheel-9gdii04g/langchain_community/utilities/cassandra.pysuccess_handler   s    z0wrapped_response_future.<locals>.success_handlerBaseException)excr   c                   s     j|  d S r   )r   Zset_exception)r   )r   r   r   r   error_handler   s    z.wrapped_response_future.<locals>.error_handlerN)asyncioZget_event_loopZcreate_futureZadd_callbacks)r	   r
   r   r   r   r   r   r   wrapped_response_future   s    
r   r   str)sessionqueryr   r   c                   s   t | j|f|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   Z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__ZSYNCASYNCZOFFr   r   r   r   r!   4   s   r!   )
__future__r   r   enumr   typingr   r   r   Zcassandra.clusterr   r   r   r    r!   r   r   r   r   <module>   s   