
    BTh"                        d dl Z d dlmZ d dlmZ d dlmZ d dlZd dlZd dl	m
Z
 d dlmZ d dlmZ  G d d	      Z G d
 d      Zg dZ ej$                  d      defd       Z ej$                  d      dedefd       Zy)    N)PathLike)Path)Union)VCR)CassetteNotFoundError)Requestc                   D    e Zd ZdZededefd       Zededefd       Zy)CustomSerializera  Custom serializer for VCR cassettes using YAML and gzip.

    We're using a custom serializer to avoid the default yaml serializer
    used by VCR, which is not designed to be safe for untrusted input.

    This step is an extra precaution necessary because the cassette files
    are in compressed YAML format, which makes it more difficult to inspect
    their contents during development or debugging.
    cassette_dictreturnc                     | d   D cg c]  }|j                          c}| d<   t        j                  |       }t        j                  |j                  d            S c c}w )z)Convert cassette to YAML and compress it.requestsutf-8)_to_dictyaml	safe_dumpgzipcompressencode)r   requestymls      j/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/langchain_tests/conftest.py	serializezCustomSerializer.serialize   sY     /<J.G%
#*G%
j! nn]+}}SZZ011	%
s   Adatac                     t        j                  |       j                  d      }t        j                  |      }|d   D cg c]  }t        j                  |       c}|d<   |S c c}w )z)Decompress data and convert it from YAML.r   r   )r   
decompressdecoder   	safe_loadr   
_from_dict)r   textcassetter   s       r   deserializezCustomSerializer.deserialize!   sa     t$++G4>>$'7?
7K 
,3Gw' 
  
s   A%N)	__name__
__module____qualname____doc__staticmethoddictbytesr   r"        r   r
   r
      sK     2 2% 2 2 % D  r+   r
   c            	       z    e Zd ZdZedeeee   f   dede	e
e
f   fd       Zedeeee   f   de
deddfd       Zy)	CustomPersisterz:A custom persister for VCR that uses the CustomSerializer.cassette_path
serializerr   c                     t        |      }|j                         st        d| d      |j                  d      5 }|j	                         }ddd       |j                        }|d   |d   fS # 1 sw Y   $xY w)zLoad a cassette from a file.zCassette file z does not exist.rb)modeNr   	responses)r   is_filer   openreadr"   )clsr.   r/   fr   desers         r   load_cassettezCustomPersister.load_cassette/   s     ]+$$&' /?@  T* 	a668D	&&t,Z %"444	 	s   A11A:r   Nc                    |j                  |      }t        |       } | j                  }|j                         s|j	                  d       | j                  d      5 }|j                  |       ddd       y# 1 sw Y   yxY w)zSave a cassette to a file.T)parentswbN)r   r   parentexistsmkdirr5   write)r.   r   r/   r   cassette_folderr8   s         r   save_cassettezCustomPersister.save_cassette?   sv     ##M2]+'..%%'!!$!/% 	GGDM	 	 	s   A77B )r#   r$   r%   r&   classmethodr   strr   r
   tupler(   r:   r'   rC   r*   r+   r   r-   r-   ,   s    D5!#x}"455CS5	tTz	5 5 S(3-/0 % 
	 r+   r-   ))authorizationPLACEHOLDER)z	x-api-keyrH   )zapi-keyrH   session)scoper   c            	      d    dt         j                         g ddddt        j                  d      dS )ztConfiguration that every cassette will receive.

    (Anything permitted by vcr.VCR(**kwargs) can be put here.)
    once)methoduribodyTztests/cassettesz.yaml)record_modefilter_headersmatch_onallow_playback_repeatsdecode_compressed_responsecassette_library_dirpath_transformer)_BASE_FILTER_HEADERScopyr   ensure_suffixr*   r+   r   _base_vcr_configrZ   Z   s7     .335-"&&* 1--g6 r+   rZ   c                     | S )Nr*   )rZ   s    r   
vcr_configr\   k   s    r+   )r   osr   pathlibr   typingr   pytestr   vcrr   vcr.persisters.filesystemr   vcr.requestr   r
   r-   rW   fixturer(   rZ   r\   r*   r+   r   <module>re      s           ;  >! !N  i $  !  i  $  !r+   