a
    bŠÝg¬  ã                   @   sx   d dl Z d dlmZ d dlmZ d dlmZ eeedœdd„ZdZ	G d	d
„ d
e
ƒZG dd„ deƒZeeedœ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y8   Y dS 0 dS )z"Check if path is relative to root.)é   é	   TFN)ÚsysÚversion_infoÚis_relative_toÚrelative_toÚ
ValueError)r   r   © r   ú}/var/www/html/cobodadashboardai.evdpl.com/venv/lib/python3.9/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                   @   s2   e Zd ZU dZdZee ed< eedœ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   )r   Ú	user_pathr   c                 C   s6   |   ¡ } | |   ¡ }t|| ƒs2t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   ÿ