
    giD)                     `   d dl 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 d dlmZ d dlZd dlmc mZ d dlmZmZmZ d%dZdad Zd	 Zd
ZdZdZdZg dZdZ d Z!d Z"d Z#d Z$d Z%d Z&d Z'd Z( G d d      Z) G d d      Z* G d d      Z+ G d d      Z, G d  d!      Z- G d" d#      Z.d$ Z/y)&    N)rmtree)NamedTemporaryFilemkdtempmkstemp)URLError)urlparse)assert_assert_equalassert_raisesc                 N    | t               k(  rt        d      }|S t        d      )z$Stub to replace urlopen for testing.urltmp_)prefixzName or service not known)valid_httpurlr   r   )urldatatmpfiles      X/var/www/html/audio_env/lib/python3.12/site-packages/numpy/lib/tests/test__datasource.pyurlopen_stubr      s'    
mo$I6233    c                  B    t         j                  at        t         _        y N)urllib_requesturlopenold_urlopenr    r   r   setup_moduler      s     !((K)Nr   c                  "    t         t        _        y r   )r   r   r   r   r   r   teardown_moduler   "   s
    (Nr   zhttp://www.google.com/z
index.htmlzhttp://fake.abc.web/site/zfake.txt)z/etc/shadowz../../shadowz..\system.datzc:\windows\system.dats   three is the magic numberc                 T    t        dd| d      \  }}t        j                  |       |S )N.txtdstmp_T)suffixr   dirtext)r   osclosefiledirfdpaths      r   valid_textfiler+   4   s&    fX7NHBHHRLKr   c                 |    t        dd|       \  }}t        j                  |       t        j                  |       |S )Nr    r!   )r"   r   r#   )r   r%   r&   remover'   s      r   invalid_textfiler.   ;   s/    fX7CHBHHRLIIdOKr   c                      t         t        z   S r   )	http_path	http_filer   r   r   r   r   C   s    y  r   c                      t         t        z   S r   )http_fakepathhttp_fakefiler   r   r   invalid_httpurlr5   G   s    =((r   c                      t         S r   )r0   r   r   r   valid_baseurlr7   K       r   c                      t         S r   )r3   r   r   r   invalid_baseurlr:   O       r   c                      t         S r   )r1   r   r   r   valid_httpfiler=   S   r8   r   c                      t         S r   )r4   r   r   r   invalid_httpfiler?   W   r;   r   c                   6    e Zd Zd Zd Zd Zd Zd Zd Zd Z	y)	TestDataSourceOpenc                     t        j                  |      }|j                  t                     }t	        |       |j                          y r   )
datasource
DataSourceopenr   r	   r&   )selftmp_pathdsfhs       r   test_ValidHTTPz!TestDataSourceOpen.test_ValidHTTP\   s2    ""8,WW]_%

r   c                     t        j                  |      }t               }t        t        |j
                  |       	 |j                  |       y # t        $ r!}t        |j                  d u        Y d }~y d }~ww xY wr   )rC   rD   r5   r   OSErrorrE   r	   errno)rF   rG   rH   r   es        r   test_InvalidHTTPz#TestDataSourceOpen.test_InvalidHTTPb   s]    ""8,grww,	%GGCL 	%AGGtO$$	%s   A 	A8A33A8c                 t    t        j                  |      }t        t        |j                  t                      y r   )rC   rD   r   r   _cacher5   rF   rG   rH   s      r   test_InvalidHTTPCacheURLErrorz0TestDataSourceOpen.test_InvalidHTTPCacheURLErrorl   s%    ""8,h		?+<=r   c                     t        j                  |      }t        |      }|j                  |      }t	        |       |j                          y r   )rC   rD   r+   rE   r	   r&   )rF   rG   rH   
local_filerI   s        r   test_ValidFilez!TestDataSourceOpen.test_ValidFilep   s:    ""8,#H-
WWZ 

r   c                 z    t        j                  |      }t        |      }t        t        |j
                  |       y r   )rC   rD   r.   r   rL   rE   )rF   rG   rH   invalid_files       r   test_InvalidFilez#TestDataSourceOpen.test_InvalidFilew   s,    ""8,'1grww5r   c                    	 dd l }t	        j
                  |      }t        j                  j                  |d      }j                  |d      }|j                  t               |j                          |j                  |      }|j                         }|j                          t        t        |       y # t        $ r t        j                          Y w xY w)Nr   zfoobar.txt.gzw)gzipImportErrorpytestskiprC   rD   r%   r*   joinrE   write
magic_liner&   readliner
   )rF   rG   r\   rH   filepathfpresults          r   test_ValidGzipFilez%TestDataSourceOpen.test_ValidGzipFile|   s    	
 ""8,77<</:YYx%


WWX

Z(  	KKM	   B4 4CCc                    	 dd l }t	        j
                  |      }t        j                  j                  |d      }j                  |d      }|j                  t               |j                          |j                  |      }|j                         }|j                          t        t        |       y # t        $ r t        j                          Y w xY w)Nr   zfoobar.txt.bz2r[   )bz2r]   r^   r_   rC   rD   r%   r*   r`   BZ2Filera   rb   r&   rE   rc   r
   )rF   rG   rj   rH   rd   re   rf   s          r   test_ValidBz2Filez$TestDataSourceOpen.test_ValidBz2File   s    	
 ""8,77<<*:;[[3'


WWX

Z(  	KKM	rh   N)
__name__
__module____qualname__rJ   rO   rS   rV   rY   rg   rl   r   r   r   rA   rA   [   s%    %>6
)")r   rA   c                   $    e Zd Zd Zd Zd Zd Zy)TestDataSourceExistsc                 r    t        j                  |      }t        |j                  t	                            y r   )rC   rD   r	   existsr   rR   s      r   rJ   z#TestDataSourceExists.test_ValidHTTP   s%    ""8,		-/*+r   c                 t    t        j                  |      }t        |j                  t	                     d       y NF)rC   rD   r
   rs   r5   rR   s      r   rO   z%TestDataSourceExists.test_InvalidHTTP   s(    ""8,RYY0159r   c                     t        j                  |      }t        |      }t        |j	                  |             t               }t        |      }t        |j	                  |             t        |       y r   )rC   rD   r+   r	   rs   r   r   )rF   rG   rH   r   localdirs        r   rV   z#TestDataSourceExists.test_ValidFile   sW    ""8, *		'"#9 *		'"#xr   c                 z    t        j                  |      }t        |      }t        |j	                  |      d       y ru   )rC   rD   r.   r
   rs   )rF   rG   rH   r   s       r   rY   z%TestDataSourceExists.test_InvalidFile   s/    ""8,"8,RYYw'/r   N)rm   rn   ro   rJ   rO   rV   rY   r   r   r   rq   rq      s    ,:	0r   rq   c                   0    e Zd Zd Zd Zd Zd Zd Zd Zy)TestDataSourceAbspathc                 B   t        j                  |      }t        t                     \  }}}}}}t        j
                  j                  |||j                  t        j                        j                  d            }t        ||j                  t                            y N/)rC   rD   r   r   r%   r*   r`   stripsepr
   abspath)rF   rG   rH   _netlocupath
local_paths          r   rJ   z$TestDataSourceAbspath.test_ValidHTTP   sr    ""8,$,]_$=!65!QWW\\(F"'++bff"5";";C"@B
ZMO!<=r   c                     t        j                  |      }t        |      }t        j                  j                  |      d   }t        ||j                  |             t        ||j                  |             y N)rC   rD   r+   r%   r*   splitr
   r   )rF   rG   rH   r   tmpfilenames        r   rV   z$TestDataSourceAbspath.test_ValidFile   sY    ""8, *ggmmG,R0Wbjj56Wbjj12r   c                 F   t        j                  |      }t        t                     \  }}}}}}t        j
                  j                  |||j                  t        j                        j                  d            }t        ||j                  t                     k7         y r|   )rC   rD   r   r5   r%   r*   r`   r~   r   r	   r   r   )rF   rG   rH   r   r   r   invalidhttps          r   rO   z&TestDataSourceAbspath.test_InvalidHTTP   sv    ""8,$,_->$?!65!Qggll8V#(;;rvv#6#<#<S#ACrzz-/::;r   c                    t        j                  |      }t        |      }t        |      }t        j                  j                  |      d   }t        ||j                  |      k7         t        ||j                  |      k7         y r   )rC   rD   r+   r%   r*   r   r	   r   )rF   rG   rH   invalidfiler   r   s         r   rY   z&TestDataSourceAbspath.test_InvalidFile   si    ""8,$X. *ggmmG,R0rzz+667rzz'223r   c                    t        j                  |      t        |      }t        j                  j                  |      d   }fd}t         |t                     j                  t        |                   t         |t                     j                  t        |                   t         ||      j                  t        |                   t         ||      j                  t        |                   t        D ][  }t         |t        |z         j                  t        |                   t         ||      j                  t        |                   ] y )Nr   c                 `    t         j                  j                  j                  |             S r   r%   r*   r   )xrH   s    r   <lambda>z7TestDataSourceAbspath.test_sandboxing.<locals>.<lambda>   s    A7 r   )rC   rD   r+   r%   r*   r   r	   r   
startswithstrr5   malicious_filesr0   )rF   rG   r   r   r*   fnrH   s         @r   test_sandboxingz%TestDataSourceAbspath.test_sandboxing   s    ""8, *ggmmG,R07]_%00X?@_&'223x=ABW((X78[!,,S];<! 	8BDR(33CMBCDH''H67	8r   c                    t         j                  }	 dt         _        | j                  |       | j                  |       | j	                  |       | j                  |       | j                  |       |t         _        y # |t         _        w xY wN\)r%   r   rJ   rV   rO   rY   r   rF   rG   orig_os_seps      r   test_windows_os_sepz)TestDataSourceAbspath.test_windows_os_sep   sl    ff	!BF))!!(+!!(+  * BF[BFs   A A> >BN)	rm   rn   ro   rJ   rV   rO   rY   r   r   r   r   r   rz   rz      s     >3<48
!r   rz   c                       e Zd Zd Zd Zd Zy)TestRepositoryAbspathc                 l   t        j                  t               |      }t        t	                     \  }}}}}}t
        j                  j                  |j                  ||j                  t
        j                        j                  d            }|j                  t                     }t        ||       y r|   )rC   
Repositoryr7   r   r   r%   r*   r`   	_destpathr~   r   r   r=   r
   )rF   rG   reposr   r   r   r   rd   s           r   rJ   z$TestRepositoryAbspath.test_ValidHTTP   s    %%mox@$,]_$=!65!QWW\\%//6"'++bff"5";";C"@B
==!12Z*r   c                 v   t        j                  t               |      fd}t         |t	                     j                  t        |                   t        D ][  }t         |t        |z         j                  t        |                   t         ||      j                  t        |                   ] y )Nc                 `    t         j                  j                  j                  |             S r   r   )r   r   s    r   r   z7TestRepositoryAbspath.test_sandboxing.<locals>.<lambda>  s    q)9: r   )	rC   r   r7   r	   r=   r   r   r   r0   )rF   rG   r*   r   r   s       @r   r   z%TestRepositoryAbspath.test_sandboxing   s    %%mox@:^%&11#h-@A! 	8BDR(33CMBCDH''H67	8r   c                     t         j                  }	 dt         _        | j                  |       | j                  |       |t         _        y # |t         _        w xY wr   )r%   r   rJ   r   r   s      r   r   z)TestRepositoryAbspath.test_windows_os_sep  sB    ff	!BF)  * BF[BFs   -A AN)rm   rn   ro   rJ   r   r   r   r   r   r   r      s    +8!r   r   c                   $    e Zd Zd Zd Zd Zd Zy)TestRepositoryExistsc                     t        j                  t               |      }t        |      }t	        |j                  |             y r   )rC   r   r7   r+   r	   rs   rF   rG   r   r   s       r   rV   z#TestRepositoryExists.test_ValidFile  s1    %%mox@ *W%&r   c                     t        j                  t               |      }t        |      }t	        |j                  |      d       y ru   )rC   r   r7   r.   r
   rs   r   s       r   rY   z%TestRepositoryExists.test_InvalidFile  s3    %%mox@"8,U\\'*E2r   c                     t        j                  t               |      }t        |j	                  t                            y r   )rC   r   r7   r	   rs   r   )rF   rG   r   s      r   test_RemoveHTTPFilez(TestRepositoryExists.test_RemoveHTTPFile  s)    %%mox@]_-.r   c                 B   t               }t        j                  t               |      }t	        |      \  }}}}}}t
        j                  j                  |j                  |      }t        j                  |d       t        |      }t        |j                  |             y )Ni  )r   rC   r   r7   r   r%   r*   r`   r   mkdirr+   r	   rs   )rF   rG   	localfiler   r   r   r   r   s           r   test_CachedHTTPFilez(TestRepositoryExists.test_CachedHTTPFile"  sw    !O	 %%mox@ ( 361aAWW\\%//6:

V$ ,W%&r   N)rm   rn   ro   rV   rY   r   r   r   r   r   r   r     s    '3
/
'r   r   c                       e Zd Zd Zy)TestOpenFuncc                     t        |      }t        j                  ||      }t        |       |j	                          t        j                  |      }t        |       |j	                          y )N)destpath)r+   rC   rE   r	   r&   )rF   rG   rU   re   s       r   test_DataSourceOpenz TestOpenFunc.test_DataSourceOpen0  sJ    #H-
__Z(;

__Z(

r   N)rm   rn   ro   r   r   r   r   r   r   /  s    	r   r   c                  P    t        j                         } | `| j                          y r   )rC   rD   
_istmpdest__del__)rH   s    r   test_del_attr_handlingr   ;  s$     
			 B 	 JJLr   r   )0r%   urllib.requestrequestr   shutilr   tempfiler   r   r   urllib.errorr   urllib.parser   r^   numpy.lib._datasourcelib_datasourcerC   numpy.testingr	   r
   r   r   r   r   r   r0   r1   r3   r4   r   rb   r+   r.   r   r5   r7   r:   r=   r?   rA   rq   rz   r   r   r   r   r   r   r   <module>r      s    	 '  9 9 ! !  * * > >4 *)
 %		+@ *
!)A) A)H0 04;! ;!|! !6' ':
 
r   