
    h                         d dl Z d dlmZ d dlmZ d dlmZ dededefdZd	Z	 G d
 de
      Z G d de      ZdededefdZy)    N)Path)Optional)	BaseModelpathrootreturnc                     t         j                  dk\  r| j                  |      S 	 | j                  |       y# t        $ r Y yw xY w)z"Check if path is relative to root.)   	   TF)sysversion_infois_relative_torelative_to
ValueError)r   r   s     m/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/langchain_community/tools/file_management/utils.pyr   r      sI    
6!""4(( s   8 	AAzlError: Access denied to {arg_name}: {value}. Permission granted exclusively to the current working directoryc                       e Zd ZdZy)FileValidationErrorz+Error for paths outside the root directory.N)__name__
__module____qualname____doc__     r   r   r      s    5r   r   c                   8    e Zd ZU dZdZee   ed<   	 dedefdZ	y)BaseFileToolMixinzMixin for file system tools.Nroot_dir	file_pathr   c                 n    | j                   t        |      S t        t        | j                         |      S )z9Get the relative path, returning an error if unsupported.)r   r   get_validated_relative_path)selfr   s     r   get_relative_pathz#BaseFileToolMixin.get_relative_path$   s,    == 	?"*4+>	JJr   )
r   r   r   r   r   r   str__annotations__r   r!   r   r   r   r   r      s,    &"Hhsm"JK3 K4 Kr   r   	user_pathc                     | j                         } | |z  j                         }t        ||       st        d| d|        |S )zKResolve a relative path, raising an error if not within the root directory.zPath z% is outside of the allowed directory )resolver   r   )r   r$   	full_paths      r   r   r   +   sR     <<>D	!**,I)T*!I;CD6J
 	
 r   )r   pathlibr   typingr   pydanticr   boolr   INVALID_PATH_TEMPLATEr   r   r   r"   r   r   r   r   <module>r-      sj    
   	 	T 	d 	G 6* 6
K	 
Kd s t r   