
    3fi                     x    d dl mZmZmZmZ d dlmZmZ d dlm	Z	  ed      Z
 ed      Z G d de	e
ef         Zy)	    )AsyncIteratorCallableIteratorSequence)AnyTypeVar)	BaseStoreKVc            
       f   e Zd ZdZdeeef   deegef   dee	ge
f   deege	f   ddf
dZd	ee   dee	dz     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ee	f      ddfdZd	ee   ddfdZd	ee   ddfdZdddedz  dee   ee   z  fdZdddedz  dee   ee   z  fdZy)EncoderBackedStorea  Wraps a store with key and value encoders/decoders.

    Examples that uses JSON for encoding/decoding:

    ```python
    import json


    def key_encoder(key: int) -> str:
        return json.dumps(key)


    def value_serializer(value: float) -> str:
        return json.dumps(value)


    def value_deserializer(serialized_value: str) -> float:
        return json.loads(serialized_value)


    # Create an instance of the abstract store
    abstract_store = MyCustomStore()

    # Create an instance of the encoder-backed store
    store = EncoderBackedStore(
        store=abstract_store,
        key_encoder=key_encoder,
        value_serializer=value_serializer,
        value_deserializer=value_deserializer,
    )

    # Use the encoder-backed store methods
    store.mset([(1, 3.14), (2, 2.718)])
    values = store.mget([1, 2])  # Retrieves [3.14, 2.718]
    store.mdelete([1, 2])  # Deletes the keys 1 and 2
    ```
    storekey_encodervalue_serializervalue_deserializerreturnNc                 <    || _         || _        || _        || _        y)aW  Initialize an `EncodedStore`.

        Args:
            store: The underlying byte store to wrap.
            key_encoder: Function to encode keys from type `K` to strings.
            value_serializer: Function to serialize values from type `V` to bytes.
            value_deserializer: Function to deserialize bytes back to type V.
        N)r   r   r   r   )selfr   r   r   r   s        f/var/www/auto_recruiter/arenv/lib/python3.12/site-packages/langchain_classic/storage/encoder_backed.py__init__zEncoderBackedStore.__init__4   s#     
& 0"4    keysc                     |D cg c]  }| j                  |       }}| j                  j                  |      }|D cg c]  }|| j                  |      n| c}S c c}w c c}w )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`.
        )r   r   mgetr   r   r   keyencoded_keysvaluesvalues         r   r   zEncoderBackedStore.mgetH   ss     EI"IS4#3#3C#8"I"I.  
 /4.?D##E*UJ
 	
 #J
s
   AA"c                    K   |D cg c]  }| j                  |       }}| j                  j                  |       d{   }|D cg c]  }|| j                  |      n| c}S c c}w 7 ,c c}w w)a  Async 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   amgetr   r   s         r   r!   zEncoderBackedStore.amgetY   s      EI"IS4#3#3C#8"I"Izz''55  
 /4.?D##E*UJ
 	
 #J5
s,   A3A' A3A, A3A.$	A3.A3key_value_pairsc                     |D cg c]'  \  }}| j                  |      | j                  |      f) }}}| j                  j                  |       yc c}}w )zvSet the values for the given keys.

        Args:
            key_value_pairs: A sequence of key-value pairs.
        N)r   r   r   msetr   r"   r   r   encoded_pairss        r   r$   zEncoderBackedStore.msetj   sW     .
U c"D$9$9%$@A
 
 	

&	
s   ,Ac                    K   |D cg c]'  \  }}| j                  |      | j                  |      f) }}}| j                  j                  |       d{    yc c}}w 7 w)z|Async set the values for the given keys.

        Args:
            key_value_pairs: A sequence of key-value pairs.
        N)r   r   r   amsetr%   s        r   r(   zEncoderBackedStore.amsetv   sh      .
U c"D$9$9%$@A
 
 jj}---	
 	.s   A#,A!A#A!A#c                     |D cg c]  }| j                  |       }}| j                  j                  |       yc c}w )zzDelete the given keys and their associated values.

        Args:
            keys: A sequence of keys to delete.
        N)r   r   mdeleter   r   r   r   s       r   r*   zEncoderBackedStore.mdelete   s9     :>>#((->>

<( ?s   ;c                    K   |D cg c]  }| j                  |       }}| j                  j                  |       d{    yc c}w 7 
w)zAsync delete the given keys and their associated values.

        Args:
            keys: A sequence of keys to delete.
        N)r   r   amdeleter+   s       r   r-   zEncoderBackedStore.amdelete   sF      :>>#((->>jj!!,/// ?/s   AA AA
 Aprefixr/   c             #   X   K   | j                   j                  |      E d{    y7 w)zGet an iterator over keys that match the given prefix.

        Args:
            prefix: The prefix to match.

        Yields:
            Keys that match the given prefix.
        r.   N)r   
yield_keys)r   r/   s     r   r1   zEncoderBackedStore.yield_keys   s#      ::(((777s    *(*c               h   K   | j                   j                  |      2 3 d{   }| 7 
6 yw)zAsync get an iterator over keys that match the given prefix.

        Args:
            prefix: The prefix to match.

        Yields:
            Keys that match the given prefix.
        r.   N)r   ayield_keys)r   r/   r   s      r   r3   zEncoderBackedStore.ayield_keys   s7      //v/> 	 	#I	>s   20.0202)__name__
__module____qualname____doc__r	   strr   r   r
   r   bytesr   r   listr   r!   tupler$   r(   r*   r-   r   r1   r   r3    r   r   r   r      ss   $L5c"5 qc3h'5 #A3:.	5
 %cUAX.5 
5(
! 
a$h 
"
 
QX 
"
'HU1a4[$9 
'd 
'
.8E!Q$K+@ 
.T 
.)HQK )D )08A; 04 0 "8 d
8 
!x}	$	8( " d
 
q	M#.	.	r   r   N)collections.abcr   r   r   r   typingr   r   langchain_core.storesr	   r
   r   r   r<   r   r   <module>r@      s=    G G
 ,CLCLh1a4 hr   