o
    ®©Zh¬  ã                   @   s€   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d	„Zd
Z	G dd„ de
ƒZG dd„ deƒZdededefdd„ZdS )é    N)ÚPath)ÚOptional)Ú	BaseModelÚpathÚrootÚreturnc                 C   s:   t jdkr
|  |¡S z|  |¡ W dS  ty   Y dS w )z"Check if path is relative to root.)é   é	   TF)ÚsysÚversion_infoÚis_relative_toÚrelative_toÚ
ValueError)r   r   © r   úf/var/www/html/lang_env/lib/python3.10/site-packages/langchain_community/tools/file_management/utils.pyr      s   


ÿr   zlError: Access denied to {arg_name}: {value}. Permission granted exclusively to the current working directoryc                   @   s   e Zd ZdZdS )ÚFileValidationErrorz+Error for paths outside the root directory.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r      s    r   c                   @   s6   e Zd ZU dZdZee ed< 	 dedefdd„Z	dS )ÚBaseFileToolMixinzMixin for file system tools.NÚroot_dirÚ	file_pathr   c                 C   s"   | j du r	t|ƒS tt| j ƒ|ƒS )z9Get the relative path, returning an error if unsupported.N)r   r   Úget_validated_relative_path)Úselfr   r   r   r   Úget_relative_path$   s   
z#BaseFileToolMixin.get_relative_path)
r   r   r   r   r   r   ÚstrÚ__annotations__r   r   r   r   r   r   r      s
   
 r   Ú	user_pathc                 C   s6   |   ¡ } | |   ¡ }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_pathr   r   r   r   +   s   
ÿr   )r
   Úpathlibr   Útypingr   Zpydanticr   Úboolr   ZINVALID_PATH_TEMPLATEr   r   r   r   r   r   r   r   r   Ú<module>   s    ÿ