
    3fi                     f    d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlm	Z	 d dl
mZ  G d de	      Zy)    N)IteratorSequence)Path)	ByteStore)InvalidKeyExceptionc                       e Zd ZdZdddddeez  dedz  dedz  ded	df
d
Zded	efdZ	ded	dfdZ
dee   d	eedz     fdZdeeeef      d	dfdZdee   d	dfdZddedz  d	ee   fdZy)LocalFileStorea  `BaseStore` interface that works on the local file system.

    Examples:
        Create a `LocalFileStore` instance and perform operations on it:

        ```python
        from langchain_classic.storage import LocalFileStore

        # Instantiate the LocalFileStore with the root path
        file_store = LocalFileStore("/path/to/root")

        # Set values for keys
        file_store.mset([("key1", b"value1"), ("key2", b"value2")])

        # Get values for keys
        values = file_store.mget(["key1", "key2"])  # Returns [b"value1", b"value2"]

        # Delete keys
        file_store.mdelete(["key1"])

        # Iterate over keys
        for key in file_store.yield_keys():
            print(key)  # noqa: T201
        ```
    NF)
chmod_file	chmod_dirupdate_atime	root_pathr
   r   r   returnc                j    t        |      j                         | _        || _        || _        || _        y)a  Implement the `BaseStore` interface for the local file system.

        Args:
            root_path: The root path of the file store. All keys are interpreted as
                paths relative to this root.
            chmod_file: Sets permissions for newly created files, overriding the
                current `umask` if needed.
            chmod_dir: Sets permissions for newly created dirs, overriding the
                current `umask` if needed.
            update_atime: Updates the filesystem access time (but not the modified
                time) when a file is read. This allows MRU/LRU cache policies to be
                implemented for filesystems where access time updates are disabled.
        N)r   absoluter   r
   r   r   )selfr   r
   r   r   s        c/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/storage/file_system.py__init__zLocalFileStore.__init__'   s.    * i113$"(    keyc                 P   t        j                  d|      sd| }t        |      | j                  |z  j	                         }| j                  j	                         }t
        j                  j                  ||g      }|t        |      k7  rd| d| d| d| }t        |      |S )zGet the full path for a given key relative to the root path.

        Args:
            key: The key relative to the root path.

        Returns:
            The full path for the given key.
        z^[a-zA-Z0-9_.\-/]+$zInvalid characters in key: zInvalid key: z+. Key should be relative to the full path. z vs. z and full path of )	rematchr   r   resolveospath
commonpathstr)r   r   msg	full_pathr   common_paths         r   _get_full_pathzLocalFileStore._get_full_pathA   s     xx.4/u5C%c**^^c)224	NN**,	gg(()Y)?@#i.(u$O+U;-/A)N  &c**r   dir_pathc                     |j                         sV| j                  |j                         |j                  d       | j                  |j                  | j                         yyy)a(  Makes a store directory path (including parents) with specified permissions.

        This is needed because `Path.mkdir()` is restricted by the current `umask`,
        whereas the explicit `os.chmod()` used here is not.

        Args:
            dir_path: The store directory to make.
        T)exist_okN)exists_mkdir_for_storeparentmkdirr   chmod)r   r"   s     r   r&   zLocalFileStore._mkdir_for_storeY   sR      !!(//2NNDN)~~)t~~. * !r   keysc                 ^   g }|D ]  }| j                  |      }|j                         rq|j                         }|j                  |       | j                  sRt        j                  |t        j                         |j                         j                  f       |j                  d        |S )a  Get the values associated with the given keys.

        Args:
            keys: A sequence of keys.

        Returns:
            A sequence of optional values associated with the keys.
            If a key is not found, the corresponding value will be `None`.
        N)
r!   r%   
read_bytesappendr   r   utimetimestatst_mtime)r   r*   valuesr   r   values         r   mgetzLocalFileStore.mgeth   s     &( 		$C++C0I!!,,.e$$$HHYinn6F6O6O(PQd#		$ r   key_value_pairsc                     |D ]j  \  }}| j                  |      }| j                  |j                         |j                  |       | j                  P|j                  | j                         l y)zvSet the values for the given keys.

        Args:
            key_value_pairs: A sequence of key-value pairs.
        N)r!   r&   r'   write_bytesr
   r)   )r   r5   r   r3   r   s        r   msetzLocalFileStore.mset   sc     * 	1JC++C0I!!)"2"23!!%(*0	1r   c                 v    |D ]4  }| j                  |      }|j                         s%|j                          6 y)zzDelete the given keys and their associated values.

        Args:
            keys: A sequence of keys to delete.
        N)r!   r%   unlink)r   r*   r   r   s       r   mdeletezLocalFileStore.mdelete   s;      	#C++C0I!  "	#r   prefixc              #      K   |r| j                  |      n| j                  }|j                  d      D ];  }|j                         s|j	                  | j                        }t        |       = yw)zGet an iterator over keys that match the given prefix.

        Args:
            prefix: The prefix to match.

        Yields:
            Keys that match the given prefix.
        *N)r!   r   rglobis_filerelative_tor   )r   r<   prefix_pathfilerelative_paths        r   
yield_keyszLocalFileStore.yield_keys   sb      6<d))&1%%c* 	)D||~ $ 0 0 @-((	)s   AA2+A2)N)__name__
__module____qualname____doc__r   r   intboolr   r!   r&   r   listbytesr4   tupler8   r;   r   rE    r   r   r	   r	      s    < "& $"):) $J	)
 :) ) 
)4# $ 0/ /$ /# 4+= .1HU3:->$? 1D 1	#HSM 	#d 	#)t )x} )r   r	   )r   r   r/   collections.abcr   r   pathlibr   langchain_core.storesr   $langchain_classic.storage.exceptionsr   r	   rO   r   r   <module>rT      s(    	 	  .  + DX)Y X)r   