
    BTh[                        d dl mZ d dlmZ d dlmZ d dlmZmZmZm	Z	m
Z
 d dlmZ d dlmZ d dlmZmZ d dlmZ d d	lmZ d d
lmZ d dlmZmZmZ ddlmZ erd dlmZmZmZmZmZ  G d de      Z  G d de      Z! G d de!      Z"y)    )Enum)gettext)Path)TYPE_CHECKINGOptionalSetTypeUnioncategory)TEXT_ENCODING)SnapshotSnapshotCollection)TaintedSnapshotError)AmberDataSerializer)PyTestLocation)PropertyFilterPropertyMatcherSerializableData   )AbstractSyrupyExtension)r   r   r   SerializedDataSnapshotIndexc                        e Zd ZdZdZdefdZy)	WriteModebtreturnc                     | j                   S N)value)selfs    o/var/www/catia.catastroantioquia-mas.com/valormas/lib/python3.12/site-packages/syrupy/extensions/single_file.py__str__zWriteMode.__str__'   s    zz    N)__name__
__module____qualname__BINARYTEXTstrr$    r%   r#   r   r   #   s    FD r%   r   c                      e Zd ZeZej                  ZdZddddddde	d   de	d   d	e	d
   ddf
dZ
edddddddefd       Zdedee   ddfdZedddddefd       Zedddefd       ZdeddfdZdededede	d   fdZedeee   ee   f   fd       Zede	e   fd        Ze	 	 	 	 d$d!       Zed"edefd#       Zy)%SingleFileSnapshotExtensionrawNexcludeincludematcherdatar   r1   r   r2   r3   r   r   r   c                    | j                         }|t        u r	 t        |        ||      S # t        $ rC t        t	        d      j                  t        |      j                  |j                              d w xY w)Nz>Can't serialize '{}' to '{}'. You must convert the data first.)get_supported_dataclassbytes
memoryview	TypeErrorr   formattyper&   )r"   r4   r1   r2   r3   supported_dataclasss         r#   	serializez%SingleFileSnapshotExtension.serialize0   s     #::<%'4  #4((  XfT$Z002E2N2NO 	s
   - AA9r   )indextest_locationr   r>   r   c                N    | j                  t        j                  ||            S N)r?   r>   ),_SingleFileSnapshotExtension__clean_filenamer   get_snapshot_nameclsr?   r>   s      r#   rC   z-SingleFileSnapshotExtension.get_snapshot_nameD   s*     ###55+5
 	
r%   snapshot_locationsnapshot_namesc                6    t        |      j                          y r    )r   unlink)r"   rF   rG   s      r#   delete_snapshotsz,SingleFileSnapshotExtension.delete_snapshotsN   s     	&&(r%   c                (    | j                  ||      S rA   )rC   rD   s      r#   _get_file_basenamez.SingleFileSnapshotExtension._get_file_basenameS   s     $$=$NNr%   c                    t        j                  |      }t        t        |      j	                  |j
                              S )N)r?   )r   dirnamer+   r   joinpathbasename)rE   r?   original_dirnames      r#   rN   z#SingleFileSnapshotExtension.dirnameY   s5    2::W4()22=3I3IJKKr%   r   c                    | j                   rt        | j                         dz   nd}|d |  }t        |      j                  d   }t	        |      }|j                  t        |             |S )Nr   r   )location)name)_file_extensionlenr   partsr   addr   )r"   rF   file_ext_lenfilename_wo_extrP   snapshot_collections         r#   _read_snapshot_collectionz5SingleFileSnapshotExtension._read_snapshot_collection^   sl     9=8L8Ls4//014RS+Nl];(..r20:KLh 78""r%   snapshot_name
session_idc                    	 t        |d| j                   | j                               5 }|j                         cd d d        S # 1 sw Y   y xY w# t        $ r Y y w xY w)Nrencoding)open_write_modeget_write_encodingreadFileNotFoundError)r"   rF   r^   r_   fs        r#   !_read_snapshot_data_from_locationz=SingleFileSnapshotExtension._read_snapshot_data_from_locationi   se    	!D$$%&002   vvx      ! 		s-   )A A	A A
A A 	AAc                 T    | j                   t        j                  k(  rt        S t        S r    )re   r   r*   r+   r7   rE   s    r#   r6   z3SingleFileSnapshotExtension.get_supported_dataclassv   s    ??inn,Jr%   c                 J    | j                   t        j                  k(  rt        S y r    )re   r   r*   r   rl   s    r#   rf   z.SingleFileSnapshotExtension.get_write_encoding|   s    ??inn,  r%   c                   |j                   t        t        |            j                  }}t	        || j                               sQt        d      }t        |j                  | j                         j                  t        |      j                              t        |d| j                   | j                               5 }|j                  |       d d d        y # 1 sw Y   y xY w)Nz7Can't write non supported data. Expected '{}', got '{}'wrb   )rT   nextiterr4   
isinstancer6   r   r9   r:   r&   r;   rd   re   rf   write)rE   r\   filepathr4   
error_textri   s         r#   _write_snapshot_collectionz6SingleFileSnapshotExtension._write_snapshot_collection   s    
  (()*+00  $ ; ; => IJ !!//1::DJ<O<O 
 #//*+c6L6L6N
 	GGDM	 	 	s   ?CC#filenamec                     dt        | j                  xs d      z
  }dddj                  fd|D              }|d | S )N    z	\/?*:|"<>)Cc              3   T   K   | ]  vrt        fd D              s   yw)c              3   8   K   | ]  }|t              v   y wr    r   ).0categcs     r#   	<genexpr>zISingleFileSnapshotExtension.__clean_filename.<locals>.<genexpr>.<genexpr>   s     H!,Hs   N)any)r~   r   exclude_categexclude_charss    @r#   r   z?SingleFileSnapshotExtension.__clean_filename.<locals>.<genexpr>   s/      #
%H-HH #
s   $()rW   rV   join)rE   rw   max_filename_lengthcleaned_filenamer   r   s       @@r#   __clean_filenamez,SingleFileSnapshotExtension.__clean_filename   sU    !C(;(;(Ar$BB$77 #
#
 
   4!455r%   r\   r   r   N)r&   r'   r(   r   _text_encodingr   r)   re   rV   r   r=   classmethodr+   rC   r   rJ   rL   rN   r]   rj   r
   r	   r7   r6   rf   rv   rB   r,   r%   r#   r.   r.   +   s   "N""KO /3.2/3) ) *+	)
 *+) +,) 
)( JK
/
8G
	
 
)$')9<S)	)
 O/O8GO	O O
 L'7 LC L L	#$'	#		#$'8;IL	$	% d3ie.D(E  
 8C=  
 %9	 * 
6 
6 
6 
6r%   r.   c                       e Zd ZdZej
                  Zddddddded   ded   d	ed
   ddf
dZde	de	de	ded   fdZ
e	 	 	 	 dd       Zy) SingleFileAmberSnapshotExtensionambrNr0   r4   r   r1   r   r2   r3   r   r   r   c                4    t        j                  ||||      S )Nr0   )r   r=   )r"   r4   r1   r2   r3   s        r#   r=   z*SingleFileAmberSnapshotExtension.serialize   s      #,,'7G
 	
r%   rF   r^   r_   c                    t        j                  |      }|r|j                  sy t        t	        |      d       }|sy |j
                  s|j
                  rt        |j                        |j                  S )N)snapshot_data)r   	read_filehas_snapshotsrp   rq   taintedr   r4   )r"   rF   r^   r_   r\   snapshots         r#   rj   zBSingleFileAmberSnapshotExtension._read_snapshot_data_from_location   sg     2;;<MN"*=*K*K0148&&(*:*:&X]]CC}}r%   c                2    t        j                  |d       y )NF)merge)r   
write_file)rE   r\   s     r#   rv   z;SingleFileAmberSnapshotExtension._write_snapshot_collection   s     	&&':%Hr%   r   )r&   r'   r(   rV   r   r*   re   r   r=   r+   rj   r   rv   r,   r%   r#   r   r      s    O..K /3.2/3

 

 *+	


 *+

 +,

 


$'8;IL	$	%  I%9I	I Ir%   r   N)#enumr   r   pathlibr   typingr   r   r   r	   r
   unicodedatar   syrupy.constantsr   syrupy.datar   r   syrupy.exceptionsr   "syrupy.extensions.amber.serializerr   syrupy.locationr   syrupy.typesr   r   r   baser   r   r   r   r.   r   r,   r%   r#   <module>r      sq        ! * 3 B * J J )  x6"9 x6v$I'B $Ir%   