
    Xj#                     .   d dl Z d dlZd dlZd dlZddlmZ ddlmZ  G d d          Z	 G d d          Z
 G d	 d
          Z G d de	eej        ej                  Z G d de
eej        ej                  Z G d de	eej        ej                  ZdS )    N   )util)warnings_helperc                       e Zd ZdZdZdS )StringAnchorMixindata01data02N)__name__
__module____qualname__anchor01anchor02     f/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/importlib_resources/tests/test_functional.pyr   r      s        HHHHr   r   c                   :    e Zd Zed             Zed             ZdS )ModuleAnchorMixinc                 *    t          j        d          S )Nr   	importlibimport_moduleselfs    r   r   zModuleAnchorMixin.anchor01       &x000r   c                 *    t          j        d          S Nr	   r   r   s    r   r   zModuleAnchorMixin.anchor02   r   r   N)r
   r   r   propertyr   r   r   r   r   r   r      sH        1 1 X1 1 1 X1 1 1r   r   c                        e Zd Z fdZd Zed             Zd Zd Zd Z	d Z
d Zd	 Zd
 Z ej        e          d             Zd Z xZS )FunctionalAPIBasec                 r    t                                                       |                     d           d S r   )supersetUpload_fixture)r   	__class__s    r   r"   zFunctionalAPIBase.setUp   s.    (#####r   c              #   x   K   dD ]4}|                      |          5  |V  ddd           n# 1 swxY w Y   5dS )zAYield various names of a text file in anchor02, each in a subTest))subdirectory	subsubdirresource.txt)z#subdirectory/subsubdir/resource.txt)zsubdirectory/subsubdirr(   )
path_partsN)subTestr   r)   s     r   _gen_resourcetxt_path_partsz-FunctionalAPIBase._gen_resourcetxt_path_parts   s      
 	! 	!J
 44 ! !    ! ! ! ! ! ! ! ! ! ! ! ! ! ! !	! 	!s   .2	2	c                 l    dD ]0}|                      |          r| t          |          d         c S 1| S )a&  Remove an architecture-specific UTF-16 BOM prefix when present.

        Some platforms surface UTF-16 BOM bytes as escaped text when the
        fixture is intentionally decoded as UTF-8 with ``errors='backslashreplace'``.
        Strip that prefix so assertions validate content consistently.)z\xff\xfez\xfe\xffu   ﻿N)
startswithlen)stringboms     r   remove_utf16_bomz"FunctionalAPIBase.remove_utf16_bom)   sN     : 	* 	*C  %% *c#hhjj))))*r   c                    t          j        | j        d          dk    sJ t          j        | j        dddd          dk    sJ |                                 D ]"}t          j        | j        g|R d	didk    sJ #|                     t                    5  t          j        | j                   d d d            n# 1 swxY w Y   |                     t          t           j        j        f          5  t          j        | j        d
           d d d            n# 1 swxY w Y   |                     t                    5  t          j        | j        d           d d d            n# 1 swxY w Y   t          j        | j        dd          dk    sJ | 
                    t          j        | j        dd                    d                    d                              d          k    sJ d S )N
utf-8.fileHello, UTF-8 world!
r&   r'   r(   utf-8encoding
a resourcer8   no-such-fileutf-16.filebinary.filelatin1 backslashreplaceerrorsHello, UTF-16 world!
	utf-16-le)	resources	read_textr   r   r,   assertRaisesOSErrorabcTraversalErrorUnicodeDecodeErrorr2   encodedecoder+   s     r   test_read_textz FunctionalAPIBase.test_read_text5   s   |<<@WWWWW         ::<< 	 	J#M   % 
            w'' 	/ 	/...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/)EFGG 	? 	?~>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	?122 	> 	>}===	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> 	> !  
 "" " " " $$)  
 
 &,,[99@@% A 
 

 
 
 
 
 
s6   B<<C C 2DD D>E%%E),E)c                     t          j        | j        d          dk    sJ |                                 D ]}t          j        | j        g|R  dk    sJ  d S Nr4   s   Hello, UTF-8 world!
s
   a resource)rD   read_binaryr   r,   r   r+   s     r   test_read_binaryz"FunctionalAPIBase.test_read_binaryf   s    !$->>'( ( ( ( ::<< 	V 	VJ(DDDDUUUUU	V 	Vr   c                 Z   t          j        | j        d          5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   |                                 D ]O}t          j        | j        g|R ddi5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   P|                     t                    5  t          j        | j                   d d d            n# 1 swxY w Y   |                     t          t           j        j	        f          5  t          j        | j        d           d d d            n# 1 swxY w Y   t          j        | j        d          5 }|                     t                    5  |                                 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        | j        dd	
          5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   t          j        | j        dd          5 }|                     |                                          d                    d                              d          k    sJ 	 d d d            d S # 1 swxY w Y   d S )Nr4   r5   r8   r6   r9   r:   r;   r<   r=   r7   r>   r?   r@   rB   rC   )rD   	open_textr   readr,   r   rF   rG   rH   rI   rJ   r2   rK   rL   r   fr)   s      r   test_open_textz FunctionalAPIBase.test_open_textn   s    == 	76688666666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7::<< 	0 	0J$   !  0 vvxx</////0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 w'' 	/ 	/...	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	/)EFGG 	? 	?~>>>	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? 	? >> 	!""#566                	 	 	 	 	 	 	 	 	 	 	 	 	 	 	  M
 
 
 	2 6688111111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2  M%
 
 
 		 ((226N6U6U7 7f)       		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		 		s   AA
A>B&&B*	-B*	C22C69C6(EEE4GF0$G0F4	4G7F4	8GGG.HHH=AJ  J$'J$c                 b   t          j        | j        d          5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   |                                 D ]L}t          j        | j        g|R  5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   Md S rO   )rD   open_binaryr   rT   r,   r   rU   s      r   test_open_binaryz"FunctionalAPIBase.test_open_binary   sB   "4=,?? 	816688777777	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8 	8::<< 	1 	1J&   1 vvxx=00000	1 1 1 1 1 1 1 1 1 1 1 1 1 1 1	1 	1s#   AA
A;B##B'	*B'	c                 4   t          j        | j        d          5 }t          t	          |          d          5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        | j                  5 }t          t          j                            |d          d          5 }|                                dk    sJ 	 d d d            n# 1 swxY w Y   d d d            d S # 1 swxY w Y   d S )Nr4   r6   r7   r5   )rD   pathr   openstrrT   osjoin)r   r\   rV   s      r   	test_pathzFunctionalAPIBase.test_path   s   ^DM<88 	;Dc$ii'222 ;avvxx#::::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; ^DM** 	;dbgll466III ;Qvvxx#::::::; ; ; ; ; ; ; ; ; ; ; ; ; ; ;	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	; 	;sj   A9A"A9"A&	&A9)A&	*A99A= A=0DC5)D5C9	9D<C9	=DDDc                    t           j        } || j        d          sJ  || j        d          rJ  || j                  rJ  || j        d          rJ |                                 D ]} || j        g|R  sJ d S )Nr4   no_such_filer&   )rD   is_resourcer   r,   r   )r   rd   r)   s      r   test_is_resourcez"FunctionalAPIBase.test_is_resource   s    +{4=,77777;t}n=====;t}-----;t}n=====::<< 	; 	;J;t}:z:::::::	; 	;r   c           	         t          j        dt          f          5  t          j        | j                  }d d d            n# 1 swxY w Y   t          |          h dk    sJ |                     t                    5  t          j        dt          f          5  t          t          j        | j        d                     d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   | 
                                D ]}|                     t          t          j        j        f          5  t          j        dt          f          5  t          t          j        | j        g|R             d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        dt          f          5  t          j        | j        d          }d d d            n# 1 swxY w Y   t          |          dhk    sJ d S )Nz.*contents.*>   r&   r4   r<   r;   r4   r&   r<   )r   check_warningsDeprecationWarningrD   contentsr   setrF   rG   listr,   rH   rI   )r   cr)   s      r   test_contentszFunctionalAPIBase.test_contents   s   +^=O,PQQ 	2 	2"4=11A	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	21vvUUUUUUUg&&	B 	B*",  	B 	B #DM<@@AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B ::<< 	E 	EJ!!7IM,H"IJJE E."&0  E E Y'C
CCCDDDE E E E E E E E E E E E E E E E E E E E E E E E E E E E E E +^=O,PQQ 	B 	B"4=.AAA	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B 	B1vv-((((((s   AA	A>C%(CC%C	C%C	C%%C),C)1F%E>2F>FFFFF	F	<G##G'*G')categoryc                    t           j        t           j        t           j        t           j        t           j        t           j        t           j        fD ]}|                     |          5  | 	                    t                    5   |d            d d d            n# 1 swxY w Y   | 	                    t          t          f          5   |d           d d d            n# 1 swxY w Y   | 	                    t                    5   |d           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   d S )Nfunci  z$missing module$)rD   rE   rP   rS   rY   r\   rd   ri   r*   rF   	TypeErrorAttributeErrorModuleNotFoundErrorr   rq   s     r   test_common_errorsz$FunctionalAPIBase.test_common_errors   s$    !!N!
 	- 	-D 4(( 	- 	-&&y11  DJJJ               &&	>'BCC  DJJJ               &&':;; - -D+,,,- - - - - - - - - - - - - - -	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-	- 	-s~   (D3BD3BD3"B#$D3CD3C##D3&C#'D3DD3D  D3#D $D33D7	:D7	c           	      "   t           j        t           j        fD ]u}|                     |          5  |                     t
                    5   || j        ddd           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   vd S )Nrp   r&   r'   r(   )rD   rE   rS   r*   rF   rr   r   ru   s     r   test_text_errorsz"FunctionalAPIBase.test_text_errors   s    
 	 	D 4((  &&y11  D&#&	                              		 	s5   BA, B,A00B3A04BB	
B	)r
   r   r   r"   r,   staticmethodr2   rM   rQ   rW   rZ   ra   re   rm   r   ignore_warningsrh   rv   rx   __classcell__)r$   s   @r   r   r      s       $ $ $ $ $! ! ! 	 	 \	/
 /
 /
bV V V" " "H1 1 1; ; ;; ; ;) ) )4 %_$.@AAA- - BA-*      r   r   c                       e Zd ZdS )#FunctionalAPITest_StringAnchor_DiskNr
   r   r   r   r   r   r}   r}               	Dr   r}   c                       e Zd ZdS )#FunctionalAPITest_ModuleAnchor_DiskNr~   r   r   r   r   r      r   r   r   c                       e Zd ZdS )%FunctionalAPITest_StringAnchor_MemoryNr~   r   r   r   r   r      r   r   r   )r   r_   unittestimportlib_resourcesrD    r   compat.py39r   r   r   r   	DiskSetupTestCaser}   r   MemorySetupr   r   r   r   <module>r      s       				  ' ' ' '       ( ( ( ( ( (       
1 1 1 1 1 1 1 1P P P P P P P Pf	 	 	 	 	N		 	 		 	 	 	 	N		 	 		 	 	 	 			 	 	 	 	r   