
    Ng                         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dS )    N)Path)Optional)	BaseModelpathrootreturnc                     t           j        dk    r|                     |          S 	 |                     |           dS # t          $ r Y dS 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     k/var/www/html/ai-engine/env/lib/python3.11/site-packages/langchain_community/tools/file_management/utils.pyr   r      sd    
6!!""4(((t   uus   > 
AAzlError: Access denied to {arg_name}: {value}. Permission granted exclusively to the current working directoryc                       e Zd ZdZdS )FileValidationErrorz+Error for paths outside the root directory.N)__name__
__module____qualname____doc__     r   r   r      s        5555r   r   c                   @    e Zd ZU dZdZee         ed<   	 dedefdZ	dS )BaseFileToolMixinzMixin for file system tools.Nroot_dir	file_pathr   c                 r    | 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$   s0    = 	??"*4+>+>	J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 K K K K Kr   r   	user_pathc                     |                                  } | |z                                   }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   +   sf     <<>>D	!**,,I)T** 
!JIJJDJJ
 
 	
 r   )r   pathlibr   typingr   pydanticr   boolr   INVALID_PATH_TEMPLATEr   r   r   r"   r   r   r   r   <module>r-      s   



                  	 	T 	d 	 	 	 	G 6 6 6 6 6* 6 6 6
K 
K 
K 
K 
K	 
K 
K 
Kd s t      r   