
    mBNj+                         d dl mZmZmZ d dlZd dlmZ d dlmZ ddl	m
Z
 ddlmZmZ ddlmZ dd	lmZmZ d
ZdZdZ G d d      Zy)    )ListOptionalUnionN)
DriverInfo)
RedisError   )get_package_version)Cluster_Conn
Is_Cluster)Graph)Is_SentinelSentinel_Connz	GRAPH.UDFz
GRAPH.LISTzGRAPH.CONFIGc                   0   e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZededd fd       ZdedefdZ	de
e   fd	Zd
edeeef   fdZdd
eddfdZddZddZddZdd
ededefdZddee   defdZd ZdefdZy)FalkorDBa  
    FalkorDB Class for interacting with a FalkorDB server.

    Supports both TCP and Unix socket connections.

    Usage example::
        from falkordb import FalkorDB
        # connect to the database and select the 'social' graph
        db = FalkorDB()
        graph = db.select_graph("social")

        # connect using a Unix socket
        db = FalkorDB.from_url("unix:///path/to/redis.sock")
        graph = db.select_graph("social")

        # get a single 'Person' node from the graph and print its name
        result = graph.query("MATCH (n:Person) RETURN n LIMIT 1").result_set
        person = result[0][0]
        print(person.properties['name'])
    Nc-                 Z   t        j                  d)i d|d|ddd|d|d|d|d	|d
|d|	d|
d|ddd|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d|d |d!|d"t        ||xs
 t                     d#| d$|!d%|"d&|#d'|$}-t	        |-      r@t        |-|      \  | _        | _        | j                  j                  | j                  |(      }-t        |-      rt        |-||%|&|'|(|)|*|+|,
      }-|-| _        |-j                  | _        |-j                  | _        y )*Nhostportdbr   passwordsocket_timeoutsocket_connect_timeoutsocket_keepalivesocket_keepalive_optionsconnection_poolunix_socket_pathencodingencoding_errorsdecode_responsesTretry_on_errorsslssl_keyfilessl_certfilessl_cert_reqsssl_ca_certsssl_ca_pathssl_ca_datassl_check_hostnamessl_passwordssl_validate_ocspssl_validate_ocsp_stapledssl_ocsp_contextssl_ocsp_expected_certmax_connectionssingle_connection_clienthealth_check_intervalclient_namedriver_infousernameretryredis_connect_funccredential_providerprotocol)r     )redisRedisr   r	   r   r   sentinelservice_name
master_forr   r
   
connectionflushdbexecute_command).selfr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   lib_namelib_versionr2   r3   connect_funcr5   r6   cluster_error_retry_attemptsstartup_nodesrequire_full_coveragereinitialize_stepsread_from_replicasdynamic_startup_nodesurladdress_remapconns.                                                 b/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/falkordb/falkordb.py__init__zFalkorDB.__init__(   s0   b {{ &
&
&
 &
 	&

 *&
 $:&
 .&
 &>&
 ,&
 .&
 &
 ,&
 "&
 *&
 &
  $!&
" &#&
$ (%&
& &'&
( $)&
* $+&
,  2-&
. &/&
0 01&
2 '@3&
4 .5&
6 $:7&
8 ,9&
: &>;&
< #8=&
> $?&
@ #8[-Q<O<QRA&
B C&
D E&
F  ,G&
H !4I&
J K&
P t/<T3/G,DM4,==++D,=,=3+GDd,%""%D ||#33    rJ   returnc                     |j                  d      rd|t        d      d z   }n"|j                  d      rd|t        d      d z   }d|d<   t        j                  |fi |} | |j                        S )	aN  
        Creates a new FalkorDB instance from a URL.

        Args:
            cls: The class itself.
            url (str): The URL.
            kwargs: Additional keyword arguments to pass to the
                ``DB.from_url`` function.

        Returns:
            DB: A new DB instance.

        Usage example::
        db = FalkorDB.from_url("falkor://[[username]:[password]]@localhost:6379")
        db = FalkorDB.from_url("falkors://[[username]:[password]]@localhost:6379")
        db = FalkorDB.from_url("unix://[username@]/path/to/socket.sock?db=0[&password=password]")
        z	falkor://zredis://Nz
falkors://z	rediss://Tr   )r   )
startswithlenr8   from_urlr   )clsrJ   kwargsrL   s       rM   rT   zFalkorDB.from_url   sy    * >>+&s3{#3#566C^^L)C$5$7 88C%)!"~~c,V,4#7#788rO   graph_idc                 t    t        |t              r|dk(  rt        dt        |       d      t	        | |      S )z
        Selects a graph by creating a new Graph instance.

        Args:
            graph_id (str): The identifier of the graph.

        Returns:
            Graph: A new Graph instance associated with the selected graph.
         z*Expected a string parameter, but received .)
isinstancestr	TypeErrortyper   )r@   rW   s     rM   select_graphzFalkorDB.select_graph   sA     (C(HN<T(^<LAN  T8$$rO   c                 @    | j                   j                  t              S )z
        Lists all graph names.
        See: https://docs.falkordb.com/commands/graph.list.html

        Returns:
            List: List of graph names.

        )r=   r?   LIST_CMDr@   s    rM   list_graphszFalkorDB.list_graphs   s     ..x88rO   namec                 J    | j                   j                  t        d|      d   S )aA  
        Retrieve a DB level configuration.
        For a list of available configurations see: https://docs.falkordb.com/configuration.html#falkordb-configuration-parameters

        Args:
            name (str): The name of the configuration.

        Returns:
            int or str: The configuration value.

        GETr   r=   r?   
CONFIG_CMD)r@   rd   s     rM   
config_getzFalkorDB.config_get   s"     ..z5$GJJrO   c                 F    | j                   j                  t        d||      S )aD  
        Update a DB level configuration.
        For a list of available configurations see: https://docs.falkordb.com/configuration.html#falkordb-configuration-parameters

        Args:
            name (str): The name of the configuration.
            value: The value to set.

        Returns:
            None

        SETrg   )r@   rd   values      rM   
config_setzFalkorDB.config_set   s     ..z5$NNrO   c                 X    	 | j                   j                          y# t        $ r Y yw xY w)z5
        Close the underlying connection(s).
        N)r=   closer   rb   s    rM   ro   zFalkorDB.close   s)    
	OO!!# 		s    	))c                     | S )z1Return self to support usage in a with-statement.r7   rb   s    rM   	__enter__zFalkorDB.__enter__   s	     rO   c                 $    | j                          y)z3Close the connection when exiting a with-statement.N)ro   )r@   exc_typeexc_valexc_tbs       rM   __exit__zFalkorDB.__exit__  s    

rO   scriptreplacec                 T   t         dg}|r|j                  d       |j                  ||g       t        | j                        rK| j                  j                         D ],  }| j                  j                  |      } |j                  | }. S  | j                  j                  | }|S )a:  
        Load a User Defined Function (UDF) library.

        Args:
            name (str): The name of the library to load.
            script (str): The UDF script contents.
            replace (bool, optional): If True, replace an existing
                library with the same name. Defaults to False.
        LOADREPLACE)UDF_CMDappendextendr   r=   get_primariesget_redis_connectionr?   )r@   rd   rw   rx   argsnodeclientresps           rM   udf_loadzFalkorDB.udf_load  s      KK	"T6N# doo&557==dC-v--t4 8  34??22D9DrO   lib	with_codec                     t         dg}||j                  |       |r|j                  d        | j                  j                  | S )a  
        List User Defined Function (UDF) libraries.

        Args:
            lib (str, optional): If provided, filter the list to
                this specific library.
            with_code (bool, optional): If True, include the library
                source code in the result. Defaults to False.

        Returns:
            list: A list of UDF libraries and their metadata.
        LISTWITHCODE)r|   r}   r=   r?   )r@   r   r   r   s       rM   udf_listzFalkorDB.udf_list$  sE      ?KKKK
#.t..55rO   c                    t        | j                        rR| j                  j                         D ]3  }| j                  j                  |      }|j	                  t
        d      }5 S | j                  j	                  t
        d      }|S )zK
        Flush (remove) all User Defined Function (UDF) libraries.
        FLUSHr   r=   r   r   r?   r|   )r@   r   r   r   s       rM   	udf_flushzFalkorDB.udf_flush<  sq     doo&557==dC--gw? 8  ??227GDDrO   c                    t        | j                        rS| j                  j                         D ]4  }| j                  j                  |      }|j	                  t
        d|      }6 S | j                  j	                  t
        d|      }|S )z
        Delete a User Defined Function (UDF) library.

        Args:
            lib (str): The name of the library to delete.
        DELETEr   )r@   r   r   r   r   s        rM   
udf_deletezFalkorDB.udf_deleteM  su     doo&557==dC--gxE 8  ??227HcJDrO   ),	localhosti  NNNNNNNzutf-8strictNFNNrequiredNNNFNFFNNNFr   Nr   z1.0.0NNNN      NF   FTNN)N)rP   N)rP   r   )F)NF)__name__
__module____qualname____doc__rN   classmethodr\   rT   r   r_   r   rc   r   intri   rm   ro   rq   rv   boolr   r   r   r   r   r7   rO   rM   r   r      s_   . #!%   "'#!& %&# "]m4^ 93 9Z 9 9<%S %U %"
9T#Y 
9Ks KuS#X KOs O4 O 	

S #  :6HSM 6T 60"c rO   r   )typingr   r   r   r8   redis.driver_infor   redis.exceptionsr   _versionr	   clusterr
   r   graphr   r:   r   r   r|   ra   rh   r   r7   rO   rM   <module>r      s=    ( (  ( ' ) -  0 
L LrO   