
    dh                         S SK r S SKJr  S SKJrJrJrJr   " S S5      r    SS\\	   S\\	   S\\	   S	\\	   S
\4
S jjr
g)    N)ceil)AnyDictListOptionalc                   P   \ rS rSrSrS\SS4S jr\S\4S j5       r\S\	\
\4   4S j5       rS\SS4S	 jrSS
\\	\
\4      SS4S jjr SS\S\	\
\\	\
\4      4   4S jjr SS\
S\\   S\S\\	\
\4      4S jjr\    SS\\
   S\\
   S\\
   S\\
   S\4
S jj5       rSrg)ArangoGraph   a  ArangoDB wrapper for graph operations.

*Security note*: Make sure that the database connection uses credentials
    that are narrowly-scoped to only include necessary permissions.
    Failure to do so may result in data corruption or loss, since the calling
    code may attempt commands that would result in deletion, mutation
    of data if appropriately prompted or reading sensitive data if such
    data is present in the database.
    The best way to guard against such negative outcomes is to (as appropriate)
    limit the permissions granted to the credentials used with this tool.

    See https://python.langchain.com/docs/security for more information.
dbreturnNc                 F    U R                  U5        U R                  5         g)z-Create a new ArangoDB graph wrapper instance.N)set_db
set_schema)selfr   s     a/var/www/html/shao/venv/lib/python3.13/site-packages/langchain_community/graphs/arangodb_graph.py__init__ArangoGraph.__init__   s    B    c                     U R                   $ N)_ArangoGraph__dbr   s    r   r   ArangoGraph.db   s    yyr   c                     U R                   $ r   )_ArangoGraph__schemar   s    r   schemaArangoGraph.schema   s    }}r   c                 v    SSK Jn  [        X5      (       d  Sn[        U5      eXl        U R                  5         g )Nr   )Databasez;**db** parameter must inherit from arango.database.Database)arango.databaser   
isinstance	TypeErrorr   r   )r   r   r   msgs       r   r   ArangoGraph.set_db"   s.    ,"''OCC.  	r   r   c                 D    Uc  U R                  5       U l        gUU l        g)zW
Set the schema of the ArangoDB Database.
Auto-generates Schema if **schema** is None.
N)generate_schemar   )r   r   s     r   r   ArangoGraph.set_schema,   s    
 39.,,.fr   sample_ratioc                    SUs=::  a  S::  d  O  [        S5      eU R                  R                  5        Vs/ sH  nUS   US   S.PM     nn/ nU R                  R                  5        H  nUS   (       a  M  US   nUS   nU R                  R	                  U5      R                  5       nUS:X  a  MJ  [        X-  5      =(       d    Sn	S	U S
U	 S3n
/ nU R                  R                  R                  U
5       HC  nUR                  5        H,  u  pUR                  U[        U5      R                  S.5        M.     ME     UR                  SUSUU S3USU 3W05        M     X4S.$ s  snf )z
Generates the schema of the ArangoDB Database and returns it
User can specify a **sample_ratio** (0 to 1) to determine the
ratio of documents/edges used (in relation to the Collection size)
to render each Collection Schema.
r      z0**sample_ratio** value must be in between 0 to 1nameedge_definitions)
graph_namer,   systemtypez
                FOR doc in `z`
                    LIMIT z,
                    RETURN doc
            )r+   r/   collection_namecollection_type_propertiesexample_)zGraph SchemazCollection Schema)
ValueErrorr   graphscollections
collectioncountr   r   aqlexecuteitemsappendr/   __name__)r   r(   ggraph_schemacollection_schemar7   col_namecol_typecol_sizelimit_amountr9   
propertiesdockeyvalues                  r   r&   ArangoGraph.generate_schema3   s    L%A%OPP
 WW^^%.
% V9!<N:OP% 	 .
 35''--/J(# 'v.H&v.H GG..x8>>@H 1}   78=AL%J ''. )C 02Jyy}},,S1"%))+JC%%sDK<P<P&QR #. 2 $$%x%xj,jxj)3	9 0J !-UU[.
s   E'querytop_kkwargsc                     SSK nU R                  R                  R                  " U40 UD6nUR	                  XR5       Vs/ sH  ofPM     sn$ s  snf )zQuery the ArangoDB database.r   N)	itertoolsr   r9   r:   islice)r   rJ   rK   rL   rN   cursorrF   s          r   rJ   ArangoGraph.queryo   sI     	&&u77(//>?>>???s   
Aurldbnameusernamepasswordc                 &    [        XX4S9nU " U5      $ )a  Convenience constructor that builds Arango DB from credentials.

Args:
    url: Arango DB url. Can be passed in as named arg or set as environment
        var ``ARANGODB_URL``. Defaults to "http://localhost:8529".
    dbname: Arango DB name. Can be passed in as named arg or set as
        environment var ``ARANGODB_DBNAME``. Defaults to "_system".
    username: Can be passed in as named arg or set as environment var
        ``ARANGODB_USERNAME``. Defaults to "root".
    password: Can be passed ni as named arg or set as environment var
        ``ARANGODB_PASSWORD``. Defaults to "".

Returns:
    An arango.database.StandardDatabase.
)rR   rS   rT   rU   )get_arangodb_client)clsrR   rS   rT   rU   r   s         r   from_db_credentialsArangoGraph.from_db_credentialsx   s    . !X
 2wr   )__db__schemar   )r   NNNN)r=   
__module____qualname____firstlineno____doc__r   r   propertyr   r   strr   r   r   r   floatr   r&   intrJ   classmethodrY   __static_attributes__ r   r   r	   r	      se   3 4 
 C   S#X    M$sCx.!9 MT M %&:V!:V	c4S#X''	(:Vz 26@@!)#@AD@	d38n	@  " $"&"&c]  3-	
 3- 
 r   r	   rR   rS   rT   rU   r   c                     SSK Jn  U =(       d     [        R                  R                  SS5      nU=(       d     [        R                  R                  SS5      nU=(       d     [        R                  R                  S	S
5      nU=(       d     [        R                  R                  SS5      n	U" U5      R                  XxU	SS9$ ! [         a  n[        S5      UeSnAff = f)aj  Get the Arango DB client from credentials.

Args:
    url: Arango DB url. Can be passed in as named arg or set as environment
        var ``ARANGODB_URL``. Defaults to "http://localhost:8529".
    dbname: Arango DB name. Can be passed in as named arg or set as
        environment var ``ARANGODB_DBNAME``. Defaults to "_system".
    username: Can be passed in as named arg or set as environment var
        ``ARANGODB_USERNAME``. Defaults to "root".
    password: Can be passed ni as named arg or set as environment var
        ``ARANGODB_PASSWORD``. Defaults to "".

Returns:
    An arango.database.StandardDatabase.
r   )ArangoClientzIUnable to import arango, please install with `pip install python-arango`.NARANGODB_URLzhttp://localhost:8529ARANGODB_DBNAME_systemARANGODB_USERNAMErootARANGODB_PASSWORD T)verify)arangorj   ImportErrorosenvirongetr   )
rR   rS   rT   rU   rj   e_url_dbname	_username	_passwords
             r   rW   rW      s    *' Nrzz~~n6MNDIRZZ^^,=yIGL0CV!LIH0CR!HI  Yt LL  W
	s   C 
CCCr]   )ru   mathr   typingr   r   r   r   r	   rc   rW   rh   r   r   <module>r      su    	  , ,L L`  ""	!M	#!MSM!M sm!M sm	!M
 	!Mr   