
    <e?                         d dl Z d dlZd dlZd dlZd dlZd dlmZmZmZm	Z	m
Z
  G d dej                  Ze G d dej                              Zedk    r ej                     dS dS )    N)TESTFNskip_unless_symlinkcan_symlinkcreate_empty_file
change_cwdc                   H   e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zed             Zed             Z ej        ej        dk    d          d             Zd Zd Z ej        ej        dk    d          d             Zd Zd Zd Zd Z d Z!dS )	GlobTestsNc                 t    t           j                            t          j        j        | j        g|R            S N)ospathnormpathjointempdir)selfpartss     %/usr/lib/python3.11/test/test_glob.pynormzGlobTests.norm   s.    wT\ BE B B BCCC    c                        fd|D             S )Nc                 H    g | ]}t          j        j        j        g|R  S  r   r   r   r   ).0r   r   s     r   
<listcomp>z#GlobTests.joins.<locals>.<listcomp>   s/    GGGuT\2E222GGGr   r   )r   tupless   ` r   joinszGlobTests.joins   s    GGGGGGGGr   c                      | j         | }t          j                            |          \  }}t          j                            |          st          j        |           t          |           d S r   )r   r   r   splitexistsmakedirsr   )r   r   filenamebasefiles        r   mktempzGlobTests.mktemp   sa    49e$W]]8,,
dw~~d## 	K(#####r   c                 F   t           dz   | _        |                     dd           |                     dd           |                     dd           |                     dd	           |                     dd
           |                     dd           |                     d           |                     d           |                     ddd           |                     dddd           t                      rt	          j        |                     d          |                     d                     t	          j        d|                     d                     t	          j        t          j                            dd          |                     d                     t          j	        t          j
        ht          j        k    rPt          j        t          j        v r8t	          j	        | j        t          j        t          j        z            | _        d S d | _        d S )N_diraDaabF.aaG.bbH.JaaazzzFZZZEFbcdefghabrokensym1sym2sym3)r   r   r%   r   r   symlinkr   r   r   openstatsupports_dir_fdscandirsupports_fdO_RDONLYO_DIRECTORYdir_fdr   s    r   setUpzGlobTests.setUp   s   CE3E3E3E4   E6"""EDC%%%Ct,,,== 	DJtyy**DIIf,=,=>>>Jx6!2!2333Jrw||C//61B1BCCCGRW!333
bn8T8T'$,bn0LMMDKKKDKKKr   c                 x    | j         t          j        | j                    t          j        | j                   d S r   )rD   r   closeshutilrmtreer   rE   s    r   tearDownzGlobTests.tearDown0   s4    ;"HT[!!!dl#####r   c                     t          |          dk    r	|d         }nt          j        j        | }t          j                             j        |          }t          j        |fi |}t          j        |fi |}                     t          j        |fi ||           d |D             }                     t          j        t          j        |          fi ||                                t          j        t          j        |          fi ||           t           j                  5  t          j        |fi |}|D ]5} 
                    t          j                            |          |           6|dk    s|dt          j        z   k    r|dd          }	n|}	                      fd|D             |	                                t          j        |fi ||           t          j        |          }
d |D             }                     t          j        |
fi ||                                t          j        |
fi ||           d d d            n# 1 swxY w Y                        t          j        |fd j        i||                                t          j        |fd j        i||           t          j         j                  }                     t          j        |
fd|i||                                t          j        |
fd|i||            j                             t          j        |fd j        i||                                t          j        |fd j        i||                                t          j        |
fd j        i||                                t          j        |
fd j        i||           |S )	N   r   c                 6    g | ]}t          j        |          S r   r   fsencoder   xs     r   r   z"GlobTests.glob.<locals>.<listcomp>?   s     ,,,1A,,,r   **c                 Z    g | ]'}t           j                            j        |          (S r   r   )r   rR   r   s     r   r   z"GlobTests.glob.<locals>.<listcomp>K   s+    "O"O"OQ27<<a#@#@"O"O"Or   c                 6    g | ]}t          j        |          S r   rO   rQ   s     r   r   z"GlobTests.glob.<locals>.<listcomp>O   s     222R[^^222r   root_dirrD   )lenr   r   r   r   globiglobassertCountEqualrP   r   assertFalseisabsseprD   )r   r   kwargspatternpresres2bresrR   expectedbpatternbres2btempdirs   `            r   rX   zGlobTests.glob5   s   u::??AhGGglE*GGLLw//i$$V$$z!&&v&&dj55f55s;;;,,,,,diAAA&AA4HHHdjQBB6BBDIII%% 	I 	I9W////D 6 6  q!1!115555$'TBF]":":qrr7!!"O"O"O"O$"O"O"O"*, , ,!!$*W"?"?"?"?FFF{7++H22T222E!!$)H"?"?"?"?GGG!!$*X"@"@"@"@%HHH	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I 	I  	diQQ$,Q&QQSWXXXdjRR4<R6RRTXYYY;t|,,Ih<<<V<<e	E 	E 	EJx==(=f==u	F 	F 	F ;"!!	'@@$+@@@$H H H!!
7AA4;A&AA4I I I!!	(AA4;A&AA5J J J!!
8BBDKB6BBEK K K 
s   0D%I!!I%(I%c                    t          |          }t          |          }|                     t          |          t          |                     |                     t          |          t          |                     d S r   )listassertEqualsetsorted)r   l1l2s      r   assertSequencesEqual_noorderz&GlobTests.assertSequencesEqual_noorderg   sb    "XX"XXR#b''***VBZZ00000r   c                    | j         } ||                     d          |                     d          g            ||                     dd          |                     dd          g            ||                     d          |                     d          g            ||                     d          g            t          j        d          }|                     d |D             t          h           t          j        t
          j                            t
          j        d                    }|                     d |D             t          h           t          j        d          }|                     d	 |D             t          h           t          j        t
          j                            t          j
        t
          j                  d                    }|                     d
 |D             t          h           d S )Nr(   r)   r*   zymurgy*c                 ,    h | ]}t          |          S r   typer   rs     r   	<setcomp>z.GlobTests.test_glob_literal.<locals>.<setcomp>u       ///a$q''///r   c                 ,    h | ]}t          |          S r   rt   rv   s     r   rx   z.GlobTests.test_glob_literal.<locals>.<setcomp>w   ry   r      *c                 ,    h | ]}t          |          S r   rt   rv   s     r   rx   z.GlobTests.test_glob_literal.<locals>.<setcomp>z   ry   r   c                 ,    h | ]}t          |          S r   rt   rv   s     r   rx   z.GlobTests.test_glob_literal.<locals>.<setcomp>|   ry   r   )ro   rX   r   rj   strr   r   r   curdirbytesrP   )r   eqra   s      r   test_glob_literalzGlobTests.test_glob_literalm   s   .
499S>>DIIcNN+,,,
499S#3!4!4 5666
499Udii../000
499Y$$$inn//3///#777iRY4455//3///#777ioo//3///%999iR[%;%;TBBCC//3///%99999r   c                 B   |                      t          j        d          g            |                      t          j        d          g            |                      t          j        d| j                  g            |                      t          j        dt          j        | j                            g            |                      t          j        d| j                  g            |                      t          j        d| j                  g            d S )N r   )rV   )rD   )rj   rX   r   r   rP   rD   rE   s    r   test_glob_empty_patternz!GlobTests.test_glob_empty_pattern~   s    2+++3,,,2===rBBB3T\1J1JKKKRPPP2dk:::B???3t{;;;R@@@@@r   c                    | j         } ||                     d          t          | j        g d                      ||                     d          t          | j        ddg                      ||                     d          t          | j        ddg                      ||                     d	          t          | j        dg                      ||                     d
          t          | j        ddg                      ||                     d          t          | j        ddg                      ||                     d          g            d S )Nza*)r(   r*   r1   *ar(   r1   z.*r,   r.   ?aazaa?r*   zaa[ab]z*q)ro   rX   mapr   r   r   s     r   test_glob_one_directoryz!GlobTests.test_glob_one_directory   s;   .
499T??C	+>+>+>??@@@
499T??C	C<88999
499T??C	E5>::;;;
499USUG44555
499USUEN;;<<<
499XDIu~ > >???
499T??Br   c           	         | j         }t          j                            d          dk    r8 ||                     ddd          |                     ddd          g           nM ||                     ddd          |                     ddd          |                     ddd          g            ||                     ddd          |                     ddd          g           d S )NabCDr(   r5   zE*r4   r6   z*g)ro   r   r   normcaserX   r   r   s     r   test_glob_nested_directoryz$GlobTests.test_glob_nested_directory   s    .7F##v--BtyyeT**TYYsE4-H-H,IJJJJ BtyyeT**TYYsE4-H-H-1YYsE5-I-I-K L L L
499S%&&3u)E)E(FGGGGGr   c           	         | j         } ||                     dd          |                     dd          g            ||                     dd          g             ||                     dddd          |                     dddd          g            ||                     dd	          |                     d
d          |                     dd          g           d S )Nrr   r)   r(   r   r5   r6   r7   z?a?*Fr1   r2   r*   r+   ro   rX   r   r   s     r   test_glob_directory_namesz#GlobTests.test_glob_directory_names   s    .
499S#3!4!4 5666
499S$$$$
499S#sD))IIc5%../	1 	1 	1
499UD!!DIIeV$<$<$(IIeS$9$9$; 	< 	< 	< 	< 	<r   c                    t          j         |                     d          t          j        z             }|                     |g            t          j         |                     d          t          j        z             }|                     |g            t          j         |                     d          t          j        z             }|                     t          |          d           |                     t          |          |                     d          |                     d          h|                     d          t          j        z   |                     d          t          j        z   hg           d S NzZ*Zr3   zaa*   r1   r*   )rX   r   r   r]   rj   rW   assertInrk   r   ra   s     r   'test_glob_directory_with_trailing_slashz1GlobTests.test_glob_directory_with_trailing_slash   s-   i		%((26122b!!!i		%((26122b!!! i		%((26122S1%%%c#hhyy''5)9)9:yy''"&0$))E2B2BRV2KL! 	 	 	 	 	r   c           
         t          j         t          j        |                     d          t          j        z                       }|                     |g            t          j         t          j        |                     d          t          j        z                       }|                     |g            t          j         t          j        |                     d          t          j        z                       }|                     t          |          d           |                     t          |          t          j        |                     d                    t          j        |                     d                    ht          j        |                     d          t          j        z             t          j        |                     d          t          j        z             hg           d S r   )	rX   r   rP   r   r]   rj   rW   r   rk   r   s     r   -test_glob_bytes_directory_with_trailing_slashz7GlobTests.test_glob_bytes_directory_with_trailing_slash   sy    iDIIe$4$4rv$=>>??b!!!iDIIe$4$4rv$=>>??b!!!iDIIe$4$4rv$=>>??S1%%%c#hh{499U#3#344{499U#3#3446{499U#3#3bf#<=={499U#3#3bf#<==?! 	 	 	 	 	r   c           	         | j         } ||                     d          |                     d          g            ||                     dd          |                     dd          |                     dd          g           |                     |                     dt          j        z             |                     d          g|                     d          t          j        z   gg            ||                     dd          |                     dd          |                     dd	          |                     dd          g           d S )
Nr;   rr   r4   r6   r   r1   r2   r*   r+   )ro   rX   r   r   r   r]   r   s     r   test_glob_symlinkszGlobTests.test_glob_symlinks   s@   .
499Vtyy001222
499VS!!DIIfd$;$;$(IIfe$<$<$> 	? 	? 	?dii00		&))*TYYv->->-G,HI	K 	K 	K
499S$IIeV$$IIeS!!499VT#:#:<	= 	= 	= 	= 	=r   c                    | j         } ||                     d          |                     d          |                     d          |                     d          g            ||                     d          |                     d          g            ||                     d          |                     d          g           d S )Nzsym*r9   r:   r;   r   r   s     r   test_glob_broken_symlinksz#GlobTests.test_glob_broken_symlinks   s    .
499Vtyy00$))F2C2C#yy002 	3 	3 	3
499Vtyy001222
499Vtyy00122222r   win32zWin32 specific testc                    | j         } |t          j        d          g             |t          j        d          g             |t          j        d          g             |t          j        d          g             |t          j        d          dg            |t          j        d          dg            |t          j        d          g             |t          j        d          g            d S )	Nz*:s   *:z?:s   ?:z\\?\c:\s   \\?\c:\z\\*\*\s   \\*\*\)ro   rX   r   s     r   test_glob_magic_in_drivez"GlobTests.test_glob_magic_in_drive   s    .
49T??B
49UR   
49T??B
49UR   
49]##m_555
49^$$~&6777
49\""B'''
49]##R(((((r   c                     |                      t          j        |          |           |                      t          j        t          j        |                    t          j        |                     d S r   )rj   rX   escaper   rP   )r   argrd   s      r   check_escapezGlobTests.check_escape   s\    S))8444R[%5%566H8M8MNNNNNr   c                     | j         } |dd            |dd            |dd            |dd            |dd	            |d
d           d S )Nabc[z[[]?z[?]rr   z[*]z[[_/*?*/_]]z[[][[]_/[*][?][*]/_]]z/[[_/*?*/_]]/z/[[][[]_/[*][?][*]/_]]/r   r   checks     r   test_escapezGlobTests.test_escape   s~    !eUc5c5c5m4555o899999r   c                     | j         } |dd            |dd            |dd            |dd            |d	d
            |dd           d S )Nz?:?z?:[?]z*:*z*:[*]z\\?\c:\?z
\\?\c:\[?]z\\*\*\*z	\\*\*\[*]z//?/c:/?z
//?/c:/[?]z//*/*/*z	//*/*/[*]r   r   s     r   test_escape_windowszGlobTests.test_escape_windows   s|    !eWeWk=)))j,'''j,'''i%%%%%r   c                       | j         |ddi|S )N	recursiveTrX   r   r   r^   s      r   rglobzGlobTests.rglob   s    ty%:4:6:::r   c                       | j         |ddi|S )Ninclude_hiddenTr   r   s      r   hglobzGlobTests.hglob   s    ty%?????r   c                    | j         }ddg} ||                     d           | j        |             ||                     d           | j        |            dg} ||                     dd           | j        |            d S )Nr1   r,   r   z*aar,   r-   rS   r-   )ro   r   r   )r   r   lrn   s       r   test_hidden_globzGlobTests.test_hidden_glob  s    .x 
4::ejdj!n---
4::ejdj!n---^
4::dC  *$*b/22222r   c                 	   | j         }g d}t                      r|g dz  } ||                     d           | j        dg|R              ||                     t          j        d           | j        t          j        dfgd |D             R             g d}t                      r|dd	gz  } ||                     dd           | j        dg|R              ||                     d
d          |                     dddddd                      ||                     d          |                     ddd                     ddg}t                      r|dgz  } ||                     dd           | j        |            g d}t                      r|dgz  } ||                     dd           | j        |             ||                     ddd          g             ||                     ddd          |                     dd                      ||                     d
dd          |                     d                     t          | j                  5  t          j        j	         |t          j
        dd          fd|D                         |t          j
         dd          d          fd|D                         |t          j
         dd          d          fd |D                         |t          j
         t          j        d          d           t          j        d          gfd!|D             z               |t          j
         t          j        dd          d           t          j        d          gfd"|D             z               |t          j
         t          j        dd          d          fd#|D                         |t          j
         dd$          d           d%d&          g            |t          j
        d'd          g             d
dd          dg}t                      r| d(d          gz  } |t          j
         dd          d          |           g d)} |t          j
        ddd*          fd+||z   D                        d d d            d S # 1 swxY w Y   d S ),N)r4   )r3   r(   r(   r)   r(   r5   r(   r5   r4   r(   r5   r6   r(   r5   r6   r7   r   r1   r2   r*   r*   r+   ))r9   )r:   )r;   r;   r4   )r;   r6   )r;   r6   r7   rS   )r   r   c              3   6   K   | ]}t           j        f|z   V  d S r   r   r   )r   is     r   	<genexpr>z0GlobTests.test_recursive_glob.<locals>.<genexpr>  s+      )I)Iq29,*:)I)I)I)I)I)Ir   )r(   r   )r(   r5   r   )r(   r5   r6   r   )r1   r   )r*   r   )r;   r   )r;   r6   r   r(   r   r   r   r   r   r   za**r   r   r   r   r   r4   )r   r   r   r   r   r5   rr   Tr   c                     g | ]} | S r   r   r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp>8  s    0H0H0Haq0H0H0Hr   c                     g | ]} | S r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp>:      (((aq(((r   c                     g | ]} | S r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp><  r   r   c                 6    g | ]} t           j        g|R  S r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp>>  -    (K(K(Kbi)<!)<)<)<(K(K(Kr   c                 6    g | ]} t           j        g|R  S r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp>@  r   r   c                 6    g | ]} t           j        g|R  S r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp>B  s-    333bi$!$$$333r   zzz*Fr1   r2   z**zz*Fr;   ))r.   r/   )r.   r0   r   r   )r.   )r   r   c                     g | ]} | S r   r   r   s     r   r   z1GlobTests.test_recursive_glob.<locals>.<listcomp>M  s    +++Qa+++r   )ro   r   r   r   r   r   r   r   r   r   rX   )r   r   fulldirsexpectrecr   s         @r   test_recursive_globzGlobTests.test_recursive_glob
  s6   .   == 	    D 	4::dZTZ5555666
4::bi&&DJ	2J)I)ID)I)I)IJJJ	L 	L 	L* * *== 	8\#677D
4::dBE!9D!9!9!9:::
4::c4  $**z<1C!:#< #< 	= 	= 	= 	4::edjj8DDEEE$g.== 	'~&&F
4::dD!!:4:v#6777MMM== 	'~&&F
4::dD!!:4:v#6777
4::dD"%%r***
4::dE3'' 3*5 *5 	6 	6 	6
4::c4''L)A)ABBB%% 	- 	-7<DBty...0H0H0H0H40H0H0HIIIBtydB4888((((4(((* * *BtydCD999((((4(((* * *Btybi..$???bi$$%(K(K(K(Kd(K(K(KKM M MBtybir22dCCCbi$$%(K(K(K(Kd(K(K(KKM M MBtybis33tDDD3333d3335 5 5Btyd6**d;;;eV$$%' ' 'BtyT222B777d3t,,d3F}} /44--..BtydD))T:::FCCCNNNCBtydCCC++++$s(+++- - --	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	- 	-s   (I<S11S58S5c                    d}t           j                            | j        d          }t          j        j        |gdg|z  R  }t          j        |           t          j        j        |gdg|z  R  fdt          d          D             }|D ]%}|                     t          |          |           &t           j                            |dd          fdt          d          D             }|}t          |          D ]J}t           j                            |d          }|D ]%}|                     t          |          |           &Kd S )	N   deepdrr   c                 <    g | ]}t          j        d           S Tr   rX   rY   r   jr_   s     r   r   z7GlobTests.test_glob_many_open_files.<locals>.<listcomp>U  (    IIIGt444IIIr   d   rS   c                 <    g | ]}t          j        d           S r   r   r   s     r   r   z7GlobTests.test_glob_many_open_files.<locals>.<listcomp>Y  r   r   )r   r   r   r   r!   rangerj   next)r   depthr#   r`   itersitr   r_   s          @r   test_glob_many_open_filesz#GlobTests.test_glob_many_open_filesO  sY   w||DL&11GL.#u...
A',t4uU{444IIIIeCjjIII 	* 	*BT"XXq))))',,tT3//IIIIeCjjIIIu 	. 	.AQ$$A . .  b1----.	. 	.r   )"__name__
__module____qualname__rD   r   r   r%   rF   rK   rX   ro   r   r   r   r   r   r   r   r   r   r   unittest
skipUnlesssysplatformr   r   r   r   r   r   r   r   r   r   r   r   r	   r	      s       FD D DH H H$ $ $  *$ $ $
0 0 0d1 1 1: : :"A A A     	H 	H 	H< < <     " 	= 	= 	= 3 3 3 X02GHH	) 	) IH	)O O O: : : X02GHH& & IH&; ; ;@ @ @3 3 3C- C- C-J. . . . .r   r	   c                       e Zd Zd ZdS )SymlinkLoopGlobTestsc           	      $   t           dz   }t          j        |           |                     t          j        |           t          |          5  t          j        d           t          t          j        	                    dd                     t          j
        t          j        t          j        	                    dd                     t          j        dd          }|                     t          |          t          t          |                               t          |          }d}|rt          j        j	        dgdg|z  z    }|                     ||           |                    |           |snRt          j        	                    |d          }|                     ||           |                    |           |d	z  }|t          j        t          j        	                    dd          d          }|                     t          |          t          t          |                               t          |          }d}|rQt          j        j	        dgdg|z  z   dgz    }|                     ||           |                    |           |d	z  }|Qt          j        t          j        	                    dd
          d          }|                     t          |          t          t          |                               t          |          }d}|rQt          j        j	        dgdg|z  z   d
gz    }|                     ||           |                    |           |d	z  }|Qd d d            d S # 1 swxY w Y   d S )Nr'   dirr$   linkrS   Tr   r   rM   r   )r   r   r!   
addCleanuprI   rJ   r   r   r   r   r<   r   rX   rj   rW   rk   r   remove)r   r   resultsr   r   s        r   test_selflinkz"SymlinkLoopGlobTests.test_selflinkd  so   6/
Gw///   &	 &	Kbgll5&99:::Jry"',,uf"="=>>>i555GS\\3s7||+<+<==='llGE 	w|ug50@&@BdG,,,t$$$ w||D&11dG,,,t$$$
  	 iT6 : :dKKKGS\\3s7||+<+<==='llGE w|ug50@&@F8&KMdG,,,t$$$
	   iT2 6 6$GGGGS\\3s7||+<+<==='llGE w|ug50@&@B4&GIdG,,,t$$$
	  E&	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	 &	s   L*NN	N	N)r   r   r   r  r   r   r   r   r   a  s#        * * * * *r   r   __main__)rX   r   rI   r   r   test.support.os_helperr   r   r   r   r   TestCaser	   r   r   mainr   r   r   <module>r     s    				  



 P P P P P P P P P P P P P PS. S. S. S. S.! S. S. S.l
 , , , , ,8, , , ,^ zHMOOOOO r   