
    daf                       d dl Z d dlZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
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mZmZmZmZmZmZmZ 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$ d dl%m&Z&m'Z' d dl#m(Z( e&dz   Z)e&dz   Z*e&d	z   Z+ejX                  j[                  d
      Z.ejX                  j[                  d      Z/ejX                  dd dk(  Z0	 d dl1Z1d dl2Z2dZ3	 d dl4Z4e jj                  jm                  d e7d            Z8d Z9d Z:d>dZ;d Z<d>dZ=d Z>d Z? e?       Z@d ZA G d d      ZB G d deBe j                        ZD G d d eBe j                        ZE G d! d"eBe j                        ZF G d# d$eBe j                        ZG G d% d&eBe j                        ZH G d' d(eBe j                        ZI G d) d*eI      ZJ G d+ d,eBe j                        ZK G d- d.e j                        ZL G d/ d0e j                        ZM G d1 d2eN      ZO e j                  e@ d3       G d4 d5eOe j                               ZQ e j                  e. d6       G d7 d8eOe j                               ZR G d9 d:e j                        ZS G d; d<e j                        ZTeUd=k(  r e j                          yy# e $ r dZY Ow xY w# e $ r dZ3Y w xY w# e $ r dZ4Y w xY w)?    N)make_archiveregister_archive_formatunregister_archive_formatget_archive_formatsErrorunpack_archiveregister_unpack_formatRegistryErrorunregister_unpack_formatget_unpack_formatsSameFileError_GiveupOnFastCopy)support)	os_helper)TESTFNFakePath)warnings_helper2_SRC_DSTdarwinsunos   aixTFzos.chdirzshouldn't call os.chdir()side_effectc                  8    t        t        t        dd      d      )NEXDEV   zInvalid cross-device link)OSErrorgetattrerrno)argskwargss     +/root/Python-3.12.4/Lib/test/test_shutil.py_fake_renamer&   ;   s    
'%"-/J
KK    c                 B     t        j                          fd       }|S )Nc                      	 t         j                  }t        t         _         | i ||t         _        S # t         _        w xY wN)osrenamer&   )r#   r$   builtin_renamefuncs      r%   wrapzmock_rename.<locals>.wrap@   s4    	'YYN$BI((&BIBIs	   &5 A)	functoolswraps)r.   r/   s   ` r%   mock_renamer2   ?   s%    __T' ' Kr'   c                     t        | t              rt        j                  j                  |  } |rdnd}|rdnd}t        | ||      5 }|j                  |       ddd       y# 1 sw Y   yxY w)zWrite *content* to a file located at *path*.

    If *path* is a tuple instead of a string, os.path.join will be used to
    make a path.  If *binary* is true, the file will be opened in binary
    mode.
    wbwNutf-8encoding)
isinstancetupler+   pathjoinopenwrite)r;   contentbinarymoder8   fps         r%   
write_filerC   J   sa     $ww||T"4sDt7H	dD8	, 
  s   A""A+c                    d }t        |d      }dj                  t        |      D cg c]3  }t        j                  t
        j                        j                         5 c}      }t        | d      5 } |||      D ]  }|j                  |        	 ddd       t        j                  j                  |       |k(  sJ yc c}w # 1 sw Y   3xY w)zBCreate a test file with an arbitrary size and random text content.c              3   P   K   | |k\  sJ | |kD  r| | |z  } | |kD  r| r|  y y wr*    )totalsteps     r%   chunkszwrite_test_file.<locals>.chunksZ   s?     }}dlJTME dl K s   &&i    r'   r4   N)minr<   rangerandomchoicestringascii_lettersencoder=   r>   r+   r;   getsize)r;   sizerI   bufsizeichunkfcsizes           r%   write_test_filerX   X   s     $oGHH$W~/ mmF$8$89@@B / 0E	dD	 QD'* 	EGGEN	 77??4 D(((/ s   8C3 CCc                     t        | t              rt        j                  j                  |  } |rdnd}|rdnd}t        | ||      5 }|j                         cddd       S # 1 sw Y   yxY w)zReturn contents from a file located at *path*.

    If *path* is a tuple instead of a string, os.path.join will be used to
    make a path.  If *binary* is true, the file will be opened in binary
    mode.
    rbrNr6   r7   )r9   r:   r+   r;   r<   r=   read)r;   r@   rA   r8   rB   s        r%   	read_filer]   j   s^     $ww||T"4sDt7H	dD8	, wwy  s   A!!A*c                    g }t        t        j                  |             D ]  }t        j                  j	                  | |      }t        j                  j                  |      r[t        j                  j                  |      s<|j                  |dz          t        |      D ]  }|j                  |dz   |z           |j                  |        |S )N/)	sortedr+   listdirr;   r<   isdirislinkappendrlistdir)r;   resnamepns        r%   re   re   x   s    
Crzz$'( GGLLt$77==BGGNN1$5JJtcz"a[ +

4#:>*+ JJt Jr'   c                  
   t        t        d      syd } d }	 t        j                  dt        j                         d      5 }|j
                  } |j                  d       d d d        t        | d      5 }t        j                  dt        j                         d      5 }|j
                  }|j                         }|j                         }	 t        j                  ||dd       	 d d d        d d d        | t        j                  |        |t        j                  |       y	y	# 1 sw Y   xY w# t        $ rB Y d d d        d d d        | t        j                  |        |t        j                  |       yyw xY w# 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY w| t        j                  |        |t        j                  |       y y # | t        j                  |        |t        j                  |       w w xY w)
NsendfileFr4   dirdeletes
   0123456789rZ   r      T)hasattrr+   tempfileNamedTemporaryFilegetcwdrg   r>   r=   filenork   r   unlinkr    )srcnamedstnamerV   srcdstinfdoutfds          r%   supports_file2file_sendfiler|      s   2z"GG&((299;uM 	#QRffGGGM"	# '4  
	 C,,Tryy{5Q 	 UX((zz|

 KKtQ2  	 
	  W%W% %	# 	#  ! 	 
	  W%W% !	  	  	 
	  
	  
	  W%W%  W%W% s   *G D%G 3+F-E?D1$E?%F-G %D.*G 1	E<:E?;FG ;E<<E??F	F	G FG 1Hc                      t         rmt        j                  dk(  rZt        j                  dt        j
                  z        } | j                  d      d   j                         d   }t        |d      dk\  S y)	Niz/usr/bin/dump -o %s
      i    T)AIXsysmaxsize
subprocess	getoutput
executablesplitint)hdrsmaxdatas     r%   
_maxdataOKr      s_    
s{{j(!!"7#.."HI

4 $**,Q/72*,,r'   c                       e Zd ZddZy)BaseTestNc                     t        j                  |t        j                               }| j	                  t
        j                  |       |S )zjCreate a temporary directory that will be cleaned up.

        Returns the path of the directory.
        )prefixrm   )rq   mkdtempr+   rs   
addCleanupr   rmtree)selfr   ds      r%   r   zBaseTest.mkdtemp   s5    
 F		<	((!,r'   r*   )__name__
__module____qualname__r   rF   r'   r%   r   r      s    r'   r   c                      e Zd Zd Zej
                  d        Zej
                  d        Zej
                  d        Z e	j                  ed      d        Z e	j                  ed      d        Z e	j                  ed      d        Zd	 Zd
 Z e	j"                  ej&                  dd dk(  d      ej(                  ej*                  d                      Zd Z e	j"                  ej&                  dd dk(  d      ej(                  ej*                  d                      Zd Z e	j"                  ej&                  dd dk(  d      ej(                  ej*                  d                      Zd Zd Z e	j                  ej<                  d      d        Z e	j                  ej<                  d      d        Z  e	j"                  ej<                  d      d        Z!d Z"ej
                  d        Z# e	j                  ed      d        Z$ e	j                   e%e&d      d        e	j"                  ej&                  d!k(  d"      d#               Z'd$ Z(y)%
TestRmTreec                 b   | j                         }t        j                  j                  |d      }t        j                  |       t        t        j                  j                  |d      d       t        j                  |      }| j                  |t               t        j                  |       y )Nkillmesomefilefoo)r   r+   r;   r<   mkdirrC   fsencodeassertIsInstancebytesshutilr   )r   tmpvictims      r%   test_rmtree_works_on_bytesz%TestRmTree.test_rmtree_works_on_bytes   sp    llnc8,
277<<
3U;V$fe,fr'   c                 >   | j                         }t        j                  j                  |d      }t        j                  |       t        j                  j                  |d      }t        j
                  ||       | j                  t        t        j                  |       | j                  t        j                  j                  |             | j                  t        j                  j                  |             g fd}t        j                  ||       | j                  t              d       | j                  d   d   t        j                  j                          | j                  d   d   |       | j#                  d   d   d   t               y )Nrm   linkc                  (    j                  |        y r*   rd   r#   errorss    r%   onerrorz@TestRmTree.test_rmtree_fails_on_symlink_onerror.<locals>.onerror       MM$r'   r   r   r   ro   r   r+   r;   r<   r   symlinkassertRaisesr    r   r   
assertTrueexistslexistsassertEquallenassertIsrc   r   r   r   dir_r   r   r   s        @r%   $test_rmtree_fails_on_symlink_onerrorz/TestRmTree.test_rmtree_fails_on_symlink_onerror   s   llnww||C'
ww||C(


4'6==$7t,--.	 dG,Va(fQilBGGNN31t,fQil1ow7r'   c                 8   | j                         }t        j                  j                  |d      }t        j                  |       t        j                  j                  |d      }t        j
                  ||       | j                  t        t        j                  |       | j                  t        j                  j                  |             | j                  t        j                  j                  |             g fd}t        j                  ||       | j                  t              d       | j                  d   d   t        j                  j                          | j                  d   d   |       | j#                  d   d   t               y )Nrm   r   c                  (    j                  |        y r*   r   r   s    r%   onexcz<TestRmTree.test_rmtree_fails_on_symlink_onexc.<locals>.onexc   r   r'   r   r   r   ro   r   r   r   r   r   r   r   s        @r%   "test_rmtree_fails_on_symlink_onexcz-TestRmTree.test_rmtree_fails_on_symlink_onexc   s   llnww||C'
ww||C(


4'6==$7t,--.	 d%(Va(fQilBGGNN31t,fQilG4r'   c                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }|||fD ]  }t        j                  |        t        j                  j                  |d      }t        |d       t        j                  j                  |d      }t        j                  ||       t        j                  j                  |d      }t        j                  ||       t        j                  j                  |d      }	t        j                  ||	       t        j                  |       | j                  t        j                  j                  |             | j                  t        j                  j                  |             | j                  t        j                  j                  |             y 	Ndir1dir2dir3file1r   link1link2link3)r   r+   r;   r<   r   rC   r   r   r   assertFalser   r   
r   r   r   r   r   r   r   r   r   r   s
             r%   test_rmtree_works_on_symlinksz(TestRmTree.test_rmtree_works_on_symlinks   sG   llnww||C(ww||D&)ww||C(tT! 	AHHQK	S'*5% T7+


4T7+


4T7+


5% d-.t,-u-.r'   zonly relevant on Windowsc                 ~   | j                         }t        j                  j                  |d      }t        j                  |       t        j                  j                  |d      }t        j                  ||       | j                  t        j                  |       | j                  t        t        j                  |       | j                  t        j                  j                  |             | j                  t        j                  j!                  |             g fd}t        j                  ||       | j#                  t%              d       | j'                  d   d   t        j                  j(                         | j#                  d   d   |       | j+                  d   d   d   t               y )Nrm   r   c                  (    j                  |        y r*   r   r   s    r%   r   zBTestRmTree.test_rmtree_fails_on_junctions_onerror.<locals>.onerror  r   r'   r   r   r   ro   r   r+   r;   r<   r   _winapiCreateJunctionr   r   ru   r   r    r   r   r   r   r   r   r   r   rc   r   r   s        @r%   &test_rmtree_fails_on_junctions_onerrorz1TestRmTree.test_rmtree_fails_on_junctions_onerror  s+   llnww||C'
ww||C(tT*	(($/'6==$7t,--.	 dG,Va(fQilBGGNN31t,fQil1ow7r'   c                 x   | j                         }t        j                  j                  |d      }t        j                  |       t        j                  j                  |d      }t        j                  ||       | j                  t        j                  |       | j                  t        t        j                  |       | j                  t        j                  j                  |             | j                  t        j                  j!                  |             g fd}t        j                  ||       | j#                  t%              d       | j'                  d   d   t        j                  j(                         | j#                  d   d   |       | j+                  d   d   t               y )Nrm   r   c                  (    j                  |        y r*   r   r   s    r%   r   z>TestRmTree.test_rmtree_fails_on_junctions_onexc.<locals>.onexc#  r   r'   r   r   r   ro   r   r   s        @r%   $test_rmtree_fails_on_junctions_onexcz/TestRmTree.test_rmtree_fails_on_junctions_onexc  s'   llnww||C'
ww||C(tT*	(($/'6==$7t,--.	 d%(Va(fQilBGGNN31t,fQilG4r'   c                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }|||fD ]  }t        j                  |        t        j                  j                  |d      }t        |d       t        j                  j                  |d      }t        j                  ||       t        j                  j                  |d      }t        j                  ||       t        j                  j                  |d      }	t        j                  ||	       t        j                  |       | j                  t        j                  j                  |             | j                  t        j                  j                  |             | j                  t        j                  j                  |             y r   )r   r+   r;   r<   r   rC   r   r   r   r   r   r   r   r   s
             r%   test_rmtree_works_on_junctionsz)TestRmTree.test_rmtree_works_on_junctions+  sM   llnww||C(ww||D&)ww||C(tT! 	AHHQK	S'*5% T7+tU+T7+tU+T7+ue,d-.t,-u-.r'   c                 n   t        j                  | j                               }| j                  t        t
        j                  |       t        j                  |d       | j                         }t        |dfd       t        j                  j                  |d      }| j                  t              5 }t        j                  |       d d d        | j                  j                  j                  |       | j                  t        j                  j!                  |             t        j                  |d       | j                  t        j                  j!                  |             g fd}t        j                  ||       | j                  t#              d       | j%                  d	   d	   t        j&                         | j                  d	   d
   |       | j)                  d	   d   d
   t               | j                  d	   d   d
   j                  |       | j%                  d
   d	   t        j*                         | j                  d
   d
   |       | j)                  d
   d   d
   t               | j                  d
   d   d
   j                  |       y # 1 sw Y   xY w)Nrm   Tignore_errorststfile c                  (    j                  |        y r*   r   r   s    r%   r   z6TestRmTree.test_rmtree_errors_onerror.<locals>.onerrorT  r   r'   r   ro   r   r   rq   mktempr   r   FileNotFoundErrorr   r   rC   r+   r;   r<   NotADirectoryErrorr   	exceptionfilenamer   r   r   r   scandirr   rmdir)r   r   tmpdircmr   r   s        @r%   test_rmtree_errors_onerrorz%TestRmTree.test_rmtree_errors_onerrorA  s   ??t||~6+V]]HEhd3 FI&+77<<	212 	$bMM(#	$..9x01hd3x01	 h0Va(fQilBJJ/1x0fQil1o/AB1a118<fQilBHH-1x0fQil1o/AB1a118<'	$ 	$s   5J**J4c                 V   t        j                  | j                               }| j                  t        t
        j                  |       t        j                  |d       | j                         }t        |dfd       t        j                  j                  |d      }| j                  t              5 }t        j                  |       d d d        | j                  j                  j                  |       | j                  t        j                  j!                  |             t        j                  |d       | j                  t        j                  j!                  |             g fd}t        j                  ||       | j                  t#              d       | j%                  d	   d	   t        j&                         | j                  d	   d
   |       | j)                  d	   d   t               | j                  d	   d   j                  |       | j%                  d
   d	   t        j*                         | j                  d
   d
   |       | j)                  d
   d   t               | j                  d
   d   j                  |       y # 1 sw Y   xY w)Nr   Tr   r   r   c                  (    j                  |        y r*   r   r   s    r%   r   z2TestRmTree.test_rmtree_errors_onexc.<locals>.onexct  r   r'   r   ro   r   r   r   )r   r   r   r   r   r   s        @r%   test_rmtree_errors_onexcz#TestRmTree.test_rmtree_errors_onexca  s   ??t||~6+V]]HEhd3 FI&+77<<	212 	$bMM(#	$..9x01hd3x01	 he,Va(fQilBJJ/1x0fQil,>?1..9fQilBHH-1x0fQil,>?1..9'	$ 	$s   5JJ(N   cygwinz2This test can't be run on Cygwin (issue #1071513).c                    d| _         t        j                  t               | j	                  t
        j                  t               t        j                  j                  t        d      | _	        t        j                  j                  t        d      | _
        t        j                  | j                         t        j                  | j                         t        j                  t              j                  }t        j                  | j                        j                  }t        j                  | j                        j                  }t        j                  t        j                   z  }t        j"                  | j                  |       t        j"                  | j                  |       t        j"                  t        |       | j	                  t        j"                  t        |       | j	                  t        j"                  | j                  |       | j	                  t        j"                  | j                  |       t        j                  t        | j$                         | j'                  | j                   dd       y )Nr   abr   r   z1Expected call to onerror function did not happen.)
errorStater+   r   r   r   r   r   r;   r<   child_file_pathchild_dir_pathr   create_empty_filestatst_modeS_IREADS_IEXECchmodcheck_args_to_onerrorr   r   old_dir_modeold_child_file_modeold_child_dir_modenew_modes        r%   test_on_errorzTestRmTree.test_on_error  s   
 
v.!ww||FC8 ggll637##D$8$89
$$%wwv.. ggd&:&:;CCWWT%8%89AA<<,
%%x0
$$h/
"&,7$"6"68KL$"5"57IJfd&@&@A!L	Nr'   c                    | j                   dk  r|t        j                  u r| j                  || j                         nq|t        j
                  u r| j                  || j                         nB| j                  |t        j                         | j                  |t        | j                  g       | j                  t        |d   t                     | xj                   dz  c_         y | j                  |t        j
                         | j                  |t               | j                  t        |d   t                     d| _         y )Nro   r   r   r   )r   r+   ru   r   r   r   r   r   ra   assertInr   r   
issubclassr    r   r.   argexcs       r%   r   z TestRmTree.check_args_to_onerror  s     ??Qryy   d&:&:;!  d&9&9:dBJJ/cFD,?,?#@AOOJs1vw78OOq OT288,S&)OOJs1vw78DOr'   c                    d| _         t        j                  t               | j	                  t
        j                  t               t        j                  j                  t        d      | _	        t        j                  j                  t        d      | _
        t        j                  | j                         t        j                  | j                         t        j                  t              j                  }t        j                  | j                        j                  }t        j                  | j                        j                  }t        j                  t        j                   z  }t        j"                  | j                  |       t        j"                  | j                  |       t        j"                  t        |       | j	                  t        j"                  t        |       | j	                  t        j"                  | j                  |       | j	                  t        j"                  | j                  |       t        j                  t        | j$                         | j'                  | j                   dd       y )Nr   r   r   r   r   z/Expected call to onexc function did not happen.)r   r+   r   r   r   r   r   r;   r<   r   r   r   r   r   r   r   r   r   check_args_to_onexcr   r   s        r%   test_on_exczTestRmTree.test_on_exc  s   
 
v.!ww||FC8 ggll637##D$8$89
$$%wwv.. ggd&:&:;CCWWT%8%89AA<<,
%%x0
$$h/
"&,7$"6"68KL$"5"57IJfD$<$<=!J	Lr'   c                    | j                   dk  r|t        j                  u r| j                  || j                         nq|t        j
                  u r| j                  || j                         nB| j                  |t        j                         | j                  |t        | j                  g       | j                  t        |t                     | xj                   dz  c_         y | j                  |t        j
                         | j                  |t               | j                  t        |t                     d| _         y )Nro   r   r   )r   r+   ru   r   r   r   r   r   ra   r  r   r   r9   r    r  s       r%   r
  zTestRmTree.check_args_to_onexc  s     ??Qryy   d&:&:;!  d&9&9:dBJJ/cFD,?,?#@AOOJsG45OOq OT288,S&)OOJsG45DOr'   c                    ddfd}fd}t        j                  t               | j                  t        j
                  t               t         j                  j                  t        d      | _        t         j                  j                  t        d      | _	        t        j                  | j                         t        j                  | j                         t        j                  t              j                  }t        j                  | j                        j                  }t        j                  | j                        j                  }t        j                  t        j                  z  }t        j                   | j                  |       t        j                   | j                  |       t        j                   t        |       | j                  t         j                   t        |       | j                  t         j                   | j                  |       | j                  t         j                   | j                  |       t	        j
                  t        ||       | j#                         | j%                         y )NFc                  
    dy NTrF   )r#   onerror_calleds    r%   r   z7TestRmTree.test_both_onerror_and_onexc.<locals>.onerror  s    !Nr'   c                  
    dy r  rF   )r#   onexc_calleds    r%   r   z5TestRmTree.test_both_onerror_and_onexc.<locals>.onexc  s    Lr'   r   r   )r   r   )r+   r   r   r   r   r   r;   r<   r   r   r   r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r  r  r  s	          @@r%   test_both_onerror_and_onexcz&TestRmTree.test_both_onerror_and_onexc  s   
 	"	  	v.!ww||FC8 ggll637##D$8$89
$$%wwv.. ggd&:&:;CCWWT%8%89AA<<,
%%x0
$$h/
"&,7$"6"68KL$"5"57IJfgU;%(r'   c                    	 t         j                  fd}|t         _        t        j                  t               t	        t        dfd       t        j                  t               t         _        y # t         _        w xY w)Nc                 :    | t         k7  r
t                |       S r*   )r   r    )fnr#   r$   
orig_lstats      r%   raiserzFTestRmTree.test_rmtree_does_not_choke_on_failing_lstat.<locals>.raiser   s    <!)O%b>)r'   r   )r+   lstatr   r   rC   r   r   )r   r  r  s     @r%   +test_rmtree_does_not_choke_on_failing_lstatz6TestRmTree.test_rmtree_does_not_choke_on_failing_lstat  sT    	"J*
 BHHHV.MM&!!BHzBHs   A$A3 3B c                    t         j                  t         j                  t         j                  t         j                  ht         j
                  k  xrB t         j                  t         j                  v xr  t         j                  t         j                  v }|r| j                  t        j                         | j                  t        j                  j                         | j                         }t         j                  j!                  |d      }t        j"                  |       	 t        j$                  } G d dt&              fd}|t        _        | j)                  t        j                  |       |t        _        y | j+                  t        j                         | j+                  t        j                  j                         y # t        _        w xY w)Nr   c                       e Zd Zy)HTestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>.CalledN)r   r   r   rF   r'   r%   Calledr  :  s    r'   r  c                      r*   rF   )r#   r$   r  s     r%   _raiserzITestRmTree.test_rmtree_uses_safe_fd_version_if_available.<locals>._raiser;  s     Lr'   )r+   r=   r   ru   r   supports_dir_fdra   supports_fdsupports_follow_symlinksr   r   _use_fd_functionsr   avoids_symlink_attacksr   r;   r<   r   _rmtree_safe_fd	Exceptionr   r   )r   r$  tmp_dirr   real_rmtreer   r  s         @r%   -test_rmtree_uses_safe_fd_version_if_availablez8TestRmTree.test_rmtree_uses_safe_fd_version_if_available-  s4    ggrww		288D//0 DZZ2>>9D  WW(C(CC 	 OOF445OOFMM@@AllnGWc*AHHQK5$44-Y-!)0&!!&&--;)4&V556V]]AAB *5&s   %AG
 
Gzrequires safe rmtreec                 *   | j                         }t        j                  j                  |d      }t        j                  |       t        j                  j                  |d      }t        j                  |       fd}dt        j                  t        d|      5 | j                  t              5  t        j                  |       d d d        d d d        | j                  t        j                  j                  |             | j                  d       dg fd}t        j                  t        d|      5 t        j                  ||       d d d        | j                  t              d       | j                  d   d   |       | j                  d   d	   |       | j                  d	   d   |       | j                  d	   d	   |       | j                  d       y # 1 sw Y   $xY w# 1 sw Y   )xY w# 1 sw Y   xY w)
Nr   r   c                 *     |        dz  t         )Nr   r    )fdclose_count
orig_closes    r%   closez4TestRmTree.test_rmtree_fails_on_close.<locals>.closeN  s    rN1KMr'   r   r1  ro   c                  (    j                  |        y r*   r   r   s    r%   r   z4TestRmTree.test_rmtree_fails_on_close.<locals>.onexc]  r   r'   r   r   )r   r+   r;   r<   r   r   	swap_attrr   r    r   r   r   rb   r   r   r   )	r   r   r   r   r1  r   r/  r   r0  s	         @@@r%   test_rmtree_fails_on_closez%TestRmTree.test_rmtree_fails_on_closeE  s    llnww||C(
ww||D&)
	 r7E2 	$j""7+ $d#$	$ 	d+,a(	 r7E2 	-jMM$e,	-Va(fQilE*1t,fQilE*1t,a(!$ $	$ 	$	- 	-s0   !G<7G/G<H	/G9	4G<<H	Hzdir_fd is not supportedc                    | j                         }d}t        j                  j                  ||      }t        j                  |t        j
                        }| j                  t        j                  |       t        j                  |       t        j                  t        j                  j                  |d             t        t        j                  j                  |dd      d       | j                  t        j                  j                  |             t        j                  ||       | j                  t        j                  j                  |             y )Nr   subdirr   r   dir_fd)r   r+   r;   r<   r=   O_RDONLYr   r1  r   rC   r   r   r   r   r   )r   r(  r   fullnamer8  s        r%   test_rmtree_with_dir_fdz"TestRmTree.test_rmtree_with_dir_fdh  s    ,,.77<<0"++.&)

h12277<<(J?Gx01fV,12r'   zdir_fd is supportedc                    | j                         }| j                  t              5  t        j                  |d       d d d        | j                  t        j                  j                  |             y # 1 sw Y   8xY w)Nr   r7  )	r   r   NotImplementedErrorr   r   r   r+   r;   r   )r   r(  s     r%   #test_rmtree_with_dir_fd_unsupportedz.TestRmTree.test_rmtree_with_dir_fd_unsupportedv  sX    ,,.23 	-MM'!,	-w/0	- 	-s   A55A>c                     t        j                  | j                               \  }}t        j                  |       | j                  t        t        j                  |       t        j                  |       y Nr   )
rq   mkstempr   r+   r1  r   r   r   r   remove)r   handler;   s      r%   test_rmtree_dont_delete_filez'TestRmTree.test_rmtree_dont_delete_file}  sJ    ''DLLN;
,fmmTB
		$r'   c                    t        j                  t               	 t         j                  j	                  t        d      }t         j                  j	                  t        d      }t        j                  |       t        j
                  ||       | j                  t        t        j                  |       t        j                  |d       t        j                  t        d       y # t        j                  t        d       w xY w)NcheeseshopTr   )
r+   r   r   r;   r<   r   r   r    r   r   r   rx   ry   s      r%   test_rmtree_on_symlinkz!TestRmTree.test_rmtree_on_symlink  s     		6'',,vx0C'',,vv.CHHSMJJsC gv}}c:MM#T2MM&5FMM&5s   B/C& &Dc                 |   t        j                  t               	 t         j                  j	                  t        d      }t         j                  j	                  t        d      }t        j                  |       t        t         j                  j	                  |d      d      j                          t        j                  ||       | j                  t        t        j                  |       t        j                  |d       t        j                  t        d       y # t        j                  t        d       w xY w)NrF  rG  spamr4   Tr   )r+   r   r   r;   r<   r=   r1  r   r   r   r    r   r   rH  s      r%   test_rmtree_on_junctionz"TestRmTree.test_rmtree_on_junction  s    
		6'',,vx0C'',,vv.CHHSMc6*D1779""3,gv}}c:MM#T2MM&5FMM&5s   C'D D;mkfiforequires os.mkfifo()vxworks%fifo requires special path on VxWorksc                    t        j                  t               	 | j                  t              5  t        j                  t               d d d        | j                  t         j                  j                  t                     t        j                  t               t        j                  t               t        j                  t         j                  j                  t        d             t        j                  t               | j                  t         j                  j                  t                     y # 1 sw Y   xY w# t        j                  t               w xY w)Nmypipe)r+   rM  r   r   r   r   r   r   r;   r   ru   r   r<   r   r   s    r%   test_rmtree_on_named_pipez$TestRmTree.test_rmtree_on_named_pipe  s     			&	""#56 &f%&OOBGGNN623IIf

		"'',,vx01f/0& & IIfs"   E D9
:E 9E>E E c                    d}|dz   }t        j                  j                  t        gdg|z   }t        j                  |       t        j                  |      5  t        j                  t               d d d        y # 1 sw Y   y xY w)N(   
   r   )	r+   r;   r<   r   makedirsr   infinite_recursionr   r   )r   recursion_limitdirectory_depthbases       r%   !test_rmtree_above_recursion_limitz,TestRmTree.test_rmtree_above_recursion_limit  sj    )B.ww||F?seo&=?
D''8 	"MM&!	" 	" 	"s   A==B))r   r   r   r   r   skip_unless_symlinkr   r   r   unittest
skipUnlessr   r   r   r   r   r   skipIfr   platformskip_if_dac_overrideskip_unless_working_chmodr  r   r  r
  r  r  r*  r   r$  r4  r;  r>  rD  rI  rL  rp   r+   rT  r]  rF   r'   r%   r   r      s    ""8 #8$ ""5 #5$ ""/ #/* X"<=8 >8& X"<=5 >5& X"<=/ >/*=@:@ X__S\\"1%1IK##((N ) $KN6 6 X__S\\"1%1IK##((L ) $KL6 6 X__S\\"1%1IK##((") ) $K")H" C0 X113IJ ) K )D X113LM3 N3 X__V--/DE1 F1 ""6 #6 X"<=6 >6 XX.0FGX__S\\Y.;=1= H1"r'   r   c                      e Zd Zd Zd Zej                  d        Zd Zd Z	d Z
ej                  j                  d      d        Zd	 Z ej                    eed
      d      ej                   ej&                  ej*                  dk(  d      d                      Zd Zej                  d        Zej                  d        Zd Zd Zy)TestCopyTreec           	      N   | j                         }t        j                  j                  | j                         d      }| j	                  t
        j                  |       | j	                  t
        j                  t        j                  j                  |             t        |dfd       t        j                  t        j                  j                  |d             t        |ddfd       t        j                  ||       | j                  t        j                  j                  t        j                  j                  |d                   | j                  t        j                  j                  t        j                  j                  |d                   | j                  t        j                  j                  t        j                  j                  |dd                   t        |df      }| j                  |d       t        |ddf      }| j                  |d       y )Ndestinationtest.txt123test_dir456)r   r+   r;   r<   r   r   r   dirnamerC   r   copytreer   isfilerb   r]   r   r   src_dirdst_diractuals       r%   test_copytree_simplez!TestCopyTree.test_copytree_simple  se   ,,.'',,t||~}=w/rwww'?@GZ(%0
gz23GZ4e<)rww||GZ'HIJbggll7J&GHIrww||GZ4>(@ A 	BGZ01'GZ<='r'   c           	         | j                         }| j                         }| j                  t        j                  |       | j                  t        j                  |       t	        |dfd       t        j                  t
        j                  j                  |d             t        j                  t
        j                  j                  |d             t	        |ddfd       t	        |ddfd       t        j                  ||d       | j                  t
        j                  j                  t
        j                  j                  |d                   | j                  t
        j                  j                  t
        j                  j                  |d                   | j                  t
        j                  j                  t
        j                  j                  |dd                   t        |df      }| j                  |d       t        |ddf      }| j                  |d       | j                  t               5  t        j                  ||d	       d d d        y # 1 sw Y   y xY w)
Nznonexisting.txtrj  existing_dirzexisting.txtzwill be replacedzhas been replacedT)dirs_exist_okF)r   r   r   r   rC   r+   r   r;   r<   rn  r   ro  rb   r]   r   r   FileExistsErrorrp  s       r%   test_copytree_dirs_exist_okz(TestCopyTree.test_copytree_dirs_exist_ok  s   ,,.,,.w/w/G./7
g~67
g~67G^^<>PQG^^<>QR=rww||G=N'OPQbggll7N&KLMrww||G^4B(D E 	FG%678'G^^DE!45/ 	COOGWEB	C 	C 	Cs   I&&I/c           	      `   | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  |       t        j                  |       t        |dfd       t        j                  j                  |d      }t        j                  j                  |d      }t        j                  t        j                  j                  |d      |       t        t        d      r5t        j                  |t        j                  t        j                  z         t        t        d	      r4t        t        d
      r$t        j                  |t        j                         t        j                  |      }t        j                   ||d       | j#                  t        j                  j%                  t        j                  j                  |dd                   t        j&                  t        j                  j                  |dd            }t        j(                  dk(  r|j+                  d      r|dd  }| j-                  |t        j                  j                  |d             t        j                  |      }	t        t        d      r&| j-                  |	j.                  |j.                         t        t        d	      r'| j-                  |	j0                  |j0                         y y )Nrx   ry   subzfile.txtr   r   zsub/linklchmodlchflags	UF_NODUMPTsymlinksntz\\?\   )r   r+   r;   r<   r   rC   r   rp   r|  r   S_IRWXUS_IRWXOr}  r~  r  r   rn  r   rc   readlinkrg   
startswithr   r   st_flags)
r   r(  rq  rr  sub_dirsrc_linkdst_linksrc_statrs  dst_stats
             r%   test_copytree_symlinksz#TestCopyTree.test_copytree_symlinks  s   ,,.'',,w.'',,w.'',,w.

GZ(%077<<077<<4


277<<4	2x IIht|| ;<2z"wt['AKK$..188H%48rww||GUF'KLMRWW\\'5&AB 77d?v00;ABZFgz!BC88H%2x X--x/?/?@2z"X..0A0AB #r'   c           
      t   t         j                  j                  }t         j                  j                  }| j	                         }	  || j	                         d      }t        |dfd       t        |dfd       t        j                   ||d             t        |ddfd       t        j                   ||d             t        |ddfd       t        j                   ||dd             t        j                   ||dd	             t        |dddfd       t        |dd	d
fd       	 t        j                  dd      }t        j                  |||       | j                   | ||d                   | j                   | ||d                   | j                   | ||d                   t        j                  |       	 t        j                  dd      }t        j                  |||       | j                   | ||d                   | j                   | ||dd	                   | j                   | ||dd                   t        j                  |       	 d }t        j                  |||       | j                   | ||dd	d
                   | j                   | ||dd                   t        j                  |       	 t        j                  |       t        j                  t         j                  j                  |             y # t        j                  |       w xY w# t        j                  |       w xY w# t        j                  |       w xY w# t        j                  |       t        j                  t         j                  j                               w xY w)Nrh  ri  rj  ztest.tmprk  rl  	test_dir2r6  subdir2ztest.pyz*.tmpignorezsubdir*c                 R   g }|D ]  }t         j                  j                  | |      }t         j                  j                  |      r(|j	                         d   dk(  r|j                  |       jt         j                  j                  |      d   dv s|j                  |        |S )Nr   r6  z.py)r+   r;   r<   rb   r   rd   splitext)rx   namesrf   rg   r;   s        r%   _filterz8TestCopyTree.test_copytree_with_exclude.<locals>._filter2  s    C % -!ww||C6GGMM$/ JJL,8JJt,WW--d3B7EBJJt,- Jr'   )r+   r;   r<   r   r   rC   r   r   ignore_patternsrn  r   r   r   rm  )r   r<   r   rq  rr  patternsr  s          r%   test_copytree_with_excludez'TestCopyTree.test_copytree_with_exclude
  s   ww||,,.:	44<<>=9G,e4,e4HHT':./Z8%@HHT';/0j95AHHT';9:HHT';	:;h
CUKiCUK'!11';GBtGZ'@ AB  Wj(A!BC  Wk(B!CDg&'!11'9EB  Wj(A!BC  Wk9(M!NO  Wk8(L!MNg&'
 A   Wk9-6)8 "9 :  Wk8(L!MN g&MM'"MM"''//'23I g& g&0 g&MM'"MM"''//'23sY   C#M. *BL  2M. B
L: M. (AM M.  L77M. :MM. M++M. .A	N7c           
      L    t         j                  j                  }t         j                  j                  } j	                         } ||d      }t        j
                   ||             t        j
                   ||d             t        j
                  t         j                  j                  |dd             t        |dddfd       g  fd} | j	                         d      }t        j                  |||        j                   | ||ddd                    | j	                         d      }t        j                  t        |      ||        j                   | ||ddd                    | j	                         d      }t        t        j                  |            d	   } j                  |t         j                         t        j                  |||        j                   | ||ddd                    j                  t!              d
       y )Nsourcerk  r6  ri  rl  c                    j                  |        j                  | t               j                  |t               j	                  t        |      t        t        |                   |D ]  }j                  |t                g S r*   )rd   r   strlistr   r   set)rx   r  rg   invokationsr   s      r%   _ignorez?TestCopyTree.test_copytree_arg_types_of_ignore.<locals>._ignoreY  sq    s#!!#s+!!%.SZSZ9 1%%dC01Ir'   rh  r  r   	   )r+   r;   r<   r   r   r   rC   r   rn  r   r   r  r   r   DirEntryr   r   )	r   r<   r   r(  rq  r  rr  src_dir_entryr  s	   `       @r%   !test_copytree_arg_types_of_ignorez.TestCopyTree.test_copytree_arg_types_of_ignoreK  s   ww||,,.w)
g
gz*+
gz8<=GZ:>F	 t||~}59tGZ$. 0 1 	2 t||~}5)77CtGZ$. 0 1 	2 t||~}5RZZ01!4mR[[9ww?tGZ$. 0 1 	2 	[)1-r'   c           	         | j                         }t        j                  j                  |d      }t        j                  |       t        j                  j                  |d      }| j                  t        j                  |       t        j                  |d       t        |dfd       t        j                  t        j                  j                  |d      d       t        |dfd       t        j                  t        j                  j                  |d      d       t        j                   |	      }| j                  t        j                  |       t        j                  |d       t        j                  ||       | j                  t        j                  |      j                  t        j                  |      j                         | j                  t        j                  t        j                  j                  |d            j                  t        j                  t        j                  j                  |d            j                         | j                  t        j                  t        j                  j                  |d            j                  t        j                  t        j                  j                  |d            j                         t        j                  j                  |t        j                  j!                  |      d
         }| j                  t        j                  |      j                  t        j                  |      j                         y )Nr  rh  i  zpermissive.txtrj  zrestrictive.txtrl  i  r   r   )r   r+   r;   r<   r   r   r   r   r   rC   rq   r   rn  r   r   r   r   )r   r(  rq  rr  restrictive_subdirrestrictive_subdir_dsts         r%   !test_copytree_retains_permissionsz.TestCopyTree.test_copytree_retains_permissionsu  s3   ,,.'',,w1
'',,w6w/
% G-.6
g'78%@G./7
g'895A%--':	((*<=
#U+))1127773C3K3KLg7G!HIQQ''"'',,w8H"IJRR	Tg7H!IJRR''"'',,w8I"JKSS	U!#g.0ggmm<N.OPQ.R"T!34<<''"89AA	Cr'   zos.chmodc                    | j                         }t        j                  j                  | j                         d      }| j	                  t
        j                  |       | j	                  t
        j                  t        j                  j                  |             t        d      |_	        | j                  t
        j                        5  t        j                  ||       d d d        y # 1 sw Y   y xY w)Nrh  zka-boom)r   r+   r;   r<   r   r   r   rm  PermissionErrorr   r   r   rn  )r   
mock_patchrq  rr  s       r%   test_copytree_winerrorz#TestCopyTree.test_copytree_winerror  s    
 ,,.'',,t||~}=w/rwww'?@!0!;
v||, 	.OOGW-	. 	. 	.s   C++C4c                      fd}g  j                         t        j                   j                               t        t        j
                  j                  d      dd      5 }|j                          d d d        t        j                  |        j                  t              d       y # 1 sw Y   =xY w)	Nc                 @   j                  d        j                  | t               j                  |t               j                  | t        j
                  j                  d             j                  |t        j
                  j                  d             y Nr   )rd   r   r  r   r+   r;   r<   )r   r   ry   flagr   rx   s     r%   custom_cpfunzETestCopyTree.test_copytree_custom_copy_function.<locals>.custom_cpfun  sm    KK!!!S)!!!S)QS% 89QS% 89r'   r   r   r5   r6   r7   copy_functionr   )r   rq   r   r=   r+   r;   r<   r1  r   rn  r   r   )r   r  rV   ry   r  rx   s   `  @@@r%   "test_copytree_custom_copy_functionz/TestCopyTree.test_copytree_custom_copy_function  s    	: llnoo$,,.1"'',,sE*C'B 	aGGI	S=TA&	 	s   /B<<CrM  rN  rO  rP  c                 |   t        j                  t               	 t         j                  j	                  t        d      }t        j                  |       t         j                  j	                  |d      }	 t        j
                  |       	 t        j                  t        t               | j                  d       t        j                   t        d	       t        j                   t        d	       y # t        $ r}| j                  d|z         Y d }~d }~ww xY w# t        j                  $ rR}|j                  d   }| j                  t        |      d       |d   \  }}}| j                  d|z  |       Y d }~d }~ww xY w# t        j                   t        d	       t        j                   t        d	       w xY w)
Nr6  rR  os.mkfifo(): %sz$shutil.Error should have been raisedr   r   z`%s` is a named pipeTr   )r+   r   r   r;   r<   rM  r  skipTestr   rn  TESTFN2failr   r#   r   r   r   )r   r6  pipeer   rx   ry   	error_msgs           r%   test_copytree_named_pipez%TestCopyTree.test_copytree_named_pipe  s?   
 		7WW\\&(3FHHV77<<1D5		$B0 		@AMM&5MM'6 # 5/!3445 << K  Va0&,Qi#S)  !7$!>	JJ	K MM&5MM'6s[   AF 5C1 D )F 1	D:DF DF F .AE;6F ;F  F 8F;c                    | j                         }t        j                  j                  | j                         d      }t	        |dfd       t        j
                  t        j                  j                  |d             t	        |ddfd       g fd}t        j                  |||       | j                  t              d       y )	Nrh  ri  rj  rk  rl  c                 ,    j                  | |f       y r*   r   )rx   ry   copieds     r%   _copyz6TestCopyTree.test_copytree_special_func.<locals>._copy  s    MM3*%r'   r  ro   )
r   r+   r;   r<   rC   r   r   rn  r   r   )r   rq  rr  r  r  s       @r%   test_copytree_special_funcz'TestCopyTree.test_copytree_special_func  s    ,,.'',,t||~}=GZ(%0
gz23GZ4e<	& 	>Va(r'   c                 V   | j                         }t        j                  j                  |d      }t	        |d       t        j                  j                  |d      }t        j
                  |       ||fD ]j  }t        j                  dt        j                  j                  |d             t        j                  |t        j                  j                  |d             l t        j                  j                  | j                         d      }| j                  t        t        j                  ||       t        j                  j                  | j                         d      }t        j                  ||d	
       t        j                  |      D ]*  \  }}}| j                  d|       | j                  d|       , t        j                  j                  | j                         d      }t        j                  ||d	       | j                  dt        j                  |             y )Nri  abcdir_a
IDONTEXISTbrokenvalidrh  destination2T)ignore_dangling_symlinksdestination3r  )r   r+   r;   r<   rC   r   r   r   r   r   rn  walkassertNotInr  ra   )	r   rq  
valid_filer  r   rr  rootdirsfiless	            r%   test_copytree_dangling_symlinksz,TestCopyTree.test_copytree_dangling_symlinks  sw   ,,.WW\\':6
:u%Wg.
% 	=AJJ|RWW\\!X%>?JJz277<<7#;<	=
 '',,t||~}=%'7C '',,t||~~>4H!#!1 	*D$Xu-MM'5)	*
 '',,t||~~>48j"**W"56r'   c           	      
   | j                         }t        j                  j                  | j                         d      }t        j                  t        j                  j                  |d             t        t        j                  j                  |dd      d      5  	 d d d        t        j                  t        j                  j                  |d      t        j                  j                  |d      d       t        j                  ||d	       | j                  t        j                  j                  t        j                  j                  |d                   | j                  dt        j                  t        j                  j                  |d                   t        j                  j                  | j                         d
      }t        j                  ||d	       | j                  t        j                  j                  t        j                  j                  |d                   | j                  dt        j                  t        j                  j                  |d                   y # 1 sw Y   xY w)Nrh  real_dirri  r4   link_to_dirTtarget_is_directoryFr  r  )r   r+   r;   r<   r   r=   r   r   rn  r   rc   r  ra   r   )r   rq  rr  s      r%   test_copytree_symlink_dirz&TestCopyTree.test_copytree_symlink_dir  s   ,,.'',,t||~}=
gz23"'',,w
J?F 		


277<<477<<7'+	- 	59Wm(LMNj"**RWW\\'=-Q"RS'',,t||~~>48rww||G]'KLMj"**RWW\\'=-Q"RS	 	s   I88Jc                 @   | j                         }|dz   }| j                  t        j                  |d       t        j
                  j                  |d      }t        |d       t        j                  ||      }| j                  dgt	        j                  |             y )NdestTr   )r   r   r   r   r+   r;   r<   rC   rn  r   ra   )r   rq  rr  rx   rvs        r%   test_copytree_return_valuez'TestCopyTree.test_copytree_return_value  ss    ,,.F"w5ggll7E*3__Wg.%"**R.1r'   c                    | j                         }| j                  t        j                  |d       t        j
                  j                  |dd      }t        j
                  j                  |dd      }t	        j                  |       t        j
                  j                  |d      }t        |d       t        j                  ||      }| j                  dgt	        j                  |             y )NTr   tpg
somevendorz1.0pol)r   r   r   r   r+   r;   r<   rX  rC   rn  r   ra   )r   base_dirrq  rr  rx   r  s         r%   test_copytree_subdirectoryz'TestCopyTree.test_copytree_subdirectory  s    <<>xtD'',,xd3'',,we<
Gggll7E*3__Wg.%"**R.1r'   N)r   r   r   rt  ry  r   r^  r  r  r  r  r_  mockpatchr  r  r`  rp   r+   ra  r   rb  r  r  r  r  r  r  rF   r'   r%   rf  rf    s   (&C2 ""C #C>?4B(.TC6 ]]$. %.'$ XX.0FG""X__S\\Y.;=7= # H7.) ""7 #74 ""T #T&2
2r'   rf  c                      e Zd Zej                  d        Z ej                   ee	d      xs e	j                  dk(  d      ej                  d               Z ej                   ee	d      d      ej                  d               Zej                  d        Z ej                   ee	d	      xr  eed
      xr	  eed      d      d        Zej"                  d        Zej                  ej"                  ej&                  d                      Zd Zd Zej                  d        Z ej                   ee	d      d      d        Zej                  d        Zej"                  d        Zd Zd Zd Zd Zej                  d        Z ej                   ee	d      d      d        Z ej                  d         Z! ej                   ee	d!      d"       ej                  e"jF                  d#k(  d$      d%               Z$d& Z%d' Z& ej                  e'xs e(xs e)d(       ej                  e*d)      d*               Z+d+ Z,y,)-TestCopyc                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t	        |d       t        j
                  ||       t        j
                  ||       t        j                  |t        j                  t        j                  z         t        j                  |t        j                         | j                  t        j                  |      j                  t        j                  |      j                         t        j                  ||       | j                  t        j                  |      j                  t        j                  |      j                         t        j                  |t        j                         t        j                  ||       | j                  t        j                  |      j                  t        j                  |      j                         t        j                  |t        j                         t        j                  ||       | j                  t        j                  |      j                  t        j                  |      j                         t        j                  |t        j                         t        j                  ||       | j                  t        j                  |      j                  t        j                  |      j                         y )Nr   barbazquux)r   r+   r;   r<   rC   r   r   r   r  S_IRWXGr  assertNotEqualr   r   copymoder   r   r(  rx   ry   r  r  s         r%   test_copymode_follow_symlinksz&TestCopy.test_copymode_follow_symlinks"  s   ,,.ggll7E*ggll7E*77<</77<<033


3!


3!
dll4<</0
dll#BGGCL00"''#,2F2FGS!--rwws|/C/CD 	dll##&--rwws|/C/CD
dll#X&--rwws|/C/CD
dll#(+--rwws|/C/CDr'   r|  r  zrequires os.lchmodc                    t         j                  dk(  rt         j                  nt         j                  }| j	                         }t         j
                  j                  |d      }t         j
                  j                  |d      }t         j
                  j                  |d      }t         j
                  j                  |d      }t        |d       t        |d       t        j                  ||       t        j                  ||       t        j                  |t        j                  t        j                  z         t        j                  |t        j                          ||t        j                  t        j                  z          ||t        j                         t        j                  |      j                  }t        j                  ||d       | j!                  t        j"                  |      j                  t        j"                  |      j                         | j!                  t        j                  |      j                  |        ||t        j                         t        j                  ||d       | j!                  t        j                  |      j                  t        j                  |      j                          ||t        j                         t        j                  ||d       | j!                  t        j                  |      j                  t        j                  |      j                         y )Nr  r   r  r  r  Ffollow_symlinks)r+   rg   r   r|  r   r;   r<   rC   r   r   r  r  r  r   r   r  r   r  )r   _lchmodr(  rx   ry   r  r  old_modes           r%    test_copymode_symlink_to_symlinkz)TestCopy.test_copymode_symlink_to_symlinkA  s     !ggo"((299,,.ggll7E*ggll7E*77<</77<<033


3!


3!
dll4<</0
dll#$,,t||34$,,'773<''(EB(+33(+33	5--x8$,,'#u=--rwws|/C/CD$,,'Xu=--rwws|/C/CDr'   z requires os.lchmod to be missingc                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t	        |d       t        j
                  ||       t        j
                  ||       t        j                  ||d       y )Nr   r  r  r  Fr  )r   r+   r;   r<   rC   r   r   r  r  s         r%   *test_copymode_symlink_to_symlink_wo_lchmodz3TestCopy.test_copymode_symlink_to_symlink_wo_lchmoda  s     ,,.ggll7E*ggll7E*77<</77<<033


3!


3!(EBr'   c                 2   | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j
                  |      }t        j                  ||j                  |j                  dz
  f       t	        |d       | j                  t        j
                  |      j                  t        j
                  |      j                         t        j                  ||       t        j                  ||       t        t        d      r%t        j                  |t
        j                         n7t        j                  dk(  r$t        j                  |t
        j                         t        t        d      r4t        t
        d	      r$t        j                   |t
        j"                         t        j$                  |      }t        t        d      st        j                  dk(  rQt'        j(                  ||d
       | j                  |j*                  t        j
                  |      j*                         t'        j(                  ||d       t        j$                  |      }t        j                  t        j,                  v r0dD ]+  }	| j/                  t1        ||	      t1        ||	      dz          - t        t        d      st        j                  dk(  r&| j3                  |j*                  |j*                         t        t        d      r2t        |d      r&| j3                  |j4                  |j4                         t'        j(                  ||d       | j7                  t9        t        j
                  |      j                  t        j
                  |      j                  z
        dk         y )Nr   r  r  quxg      E@r|  r  r}  r~  Tr  Fst_atimest_mtimer   r  g?)r   r+   r;   r<   rC   r   utimer  r  r  r   rp   r|  r  rg   r   r}  r~  r  r   copystatr   r#  assertLessEqualr!   r   r  r   abs)
r   r(  rx   ry   r  r  r  src_link_statdst_link_statattrs
             r%   test_copystat_symlinkszTestCopy.test_copystat_symlinksq  s   ,,.ggll7E*ggll7E*77<</77<</3773<
x((((4/1 	23BGGCL112773<3H3HI


3!


3!2x IIh-WW_HHXt||,2z"wt['AKK$..1*2x BGGtOOOHhE 5 5rwws|7K7KL(EB*88r222. G$$W]D%A%,]D%AA%EGG 2x BGGtO]22M4I4IJ2z"w}j'I]33]5K5KL#u=BGGCL11BGGCL4I4IIJ  	!r'   chflags
EOPNOTSUPPENOTSUPz)requires os.chflags, EOPNOTSUPP & ENOTSUPc                 v   | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t	        |d       d }t        j
                  }	 t        j                  t        j                  fD ])  } ||      t        _        t        j                  ||       +  |t        j                  t        j                  z         t        _        | j                  t        t        j                  ||       |t        _        y # |t        _        w xY w)Nr   file2xxxc                 0     t               dd fd
}|S )NTr  c                    _         r*   )r"   )r;   flagsr  errexs      r%   _chflags_raiserzlTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser.<locals>._chflags_raiser  s    r'   r-  )r  r  r  s   ` @r%   make_chflags_raiserzSTestCopy.test_copystat_handles_harmless_chflags_errors.<locals>.make_chflags_raiser  s    B@D  #"r'   )r   r+   r;   r<   rC   r  r"   r  r	  r   r   r   r    )r   r   r   r  r  old_chflagsr  s          r%   -test_copystat_handles_harmless_chflags_errorsz6TestCopy.test_copystat_handles_harmless_chflags_errors  s    
 VW-VW-5% 5% 	# jj	%''6 .05
u-. -U-=-=-MNBJgvuE$BJBJs   =B"D+ +D8c                   	
 | j                         }t        j                  j                  |d      
t	        
d       t        j                  j                  |d      }t	        |d       t        j                  
|       t        j                  
dd       t        j                  
dd       t        j                  
|       | j                  t        t        j                  
            t        t        j                  |                   | j                  t        j                  
d      t        j                  |d             t        j                  |       t	        |d       t        t        j                  d      		fd}	 t        j                  |t        _        t        j                  
|       | j!                  dt        j                  |             t        _        d	d

fd
}	 t        j                  |t        _
        t        j                  
|       t        _
        t        j                  j                  |d      
t        j                  j                  |d      }t	        

       t	        ||       t        j                  
dd       t        j                  |dd       t        j"                  |d       t        j                  j                  |d      }t        j                  j                  |d      }t	        ||       t	        ||       t        j$                  
|       t        j$                  ||       | j                  t        j                  |d      d       | j                  t        j                  |d      d       y # t        _        w xY w# t        _
        w xY w)Nr   r  user.foo   42zuser.bar   43EPERMc                 *    |dk(  r | ||fi | y )Nr  rF   )fnamer  valr$   orig_setxattros_errors       r%   _raise_on_user_fooz3TestCopy.test_copyxattr.<locals>._raise_on_user_foo  s!    z!eT39&9r'   Tr  c                V    | k(  rt        t        j                  d       | |      S )NzOperation not supportedr  )r    r"   r	  )r  r  orig_listxattrrx   s     r%   _raise_on_srcz.TestCopy.test_copyxattr.<locals>._raise_on_src  s)    |emm-FGG!%IIr'   the_originalthe_original_rozuser.the_values   fiddlyi$  the_copythe_copy_ro)r   r+   r;   r<   rC   r   
_copyxattrsetxattrr   r`   	listxattrgetxattrrB  r    r"   r  r  r   r   )r   r(  ry   r   r#  srcrodstror"  r  r  rx   s          @@@@r%   test_copyxattrzTestCopy.test_copyxattr  s   ,,.ggll7E*3ggll7E*3 	#s#
CU+
CU+#s#S 12F2<<;L4MNC,C,	. 			#35;;0	:
	(KKM,BKc3'MM*bll3&78'BK48 	J	*\\N(BLc3')BL ggll7N3W&7835% 
C)95
E+Y7
ggll7J/Wm435% S!u%S*:;YGU,<=yI9 (BK *BLs   AN! 81N1 !N.1N>c                 T   | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j
                  ||       t        j                  |dd       t        j                  |ddd       t        j                  j                  |d      }t        j                  j                  |d	      }t	        |d       t        j
                  ||       t        j                  ||d       | j                  t        j                  |dd      d       | j                  t        t        j                  |d       t        j                  ||d       | j                  t        j                  |d      d       y )
Nr   r  ztrusted.foor  r  Fr  r  r  )r   r+   r;   r<   rC   r   r)  r   r(  r   r+  r   r    )r   r(  rx   r  ry   r  s         r%   test_copyxattr_symlinksz TestCopy.test_copyxattr_symlinks  s&    ,,.ggll7E*77<</3


3!
C.
HmUEJggll7E*77<</3


3!(HeDX}eTV[\'2;;]C(C?S-8%@r'   c                     d}| j                         }t        ||fd       t        j                  j	                  ||      }| j                         } |||       t        j                  j	                  ||      }||fS )Nri  r  )r   rC   r+   r;   r<   )r   methodr  r   r   tmpdir2r  s          r%   
_copy_filezTestCopy._copy_file  sg    FE?E*VU+,,.ugWe,u~r'   c                 <   | j                  t        j                        \  }}| j                  t        j
                  j                  |             | j                  t	        j                  |      j                  t	        j                  |      j                         y r*   )
r4  r   copyr   r+   r;   r   r   r   r   )r   r   r  s      r%   	test_copyzTestCopy.test_copy  s]    v{{3uu-.//1G1GHr'   c                 f   | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j
                  ||       t        t        d      r5t        j                  |t        j                  t        j                  z         t        j                  ||d       | j                  t        j                  j                  |             | j                  t!        |      t!        |             t        j"                  |       t        j                  ||d       | j%                  t        j                  j                  |             | j                  t        j&                  |      t        j&                  |             t        t        d      rM| j                  t        j(                  |      j*                  t        j(                  |      j*                         y y )Nr   r  r  r|  Tr  F)r   r+   r;   r<   rC   r   rp   r|  r   r  r  r   r6  r   rc   r   r]   rB  r   r  r  r   )r   r(  rx   ry   r  s        r%   test_copy_symlinkszTestCopy.test_copy_symlinks%  s^   ,,.ggll7E*ggll7E*77<</3


3!2x IIht|| ;<Hc48,-338
		#Hc59s+,S)2;;x+@A2x RXXh/77XXc]224 !r'   r  zrequires os.utimec                 ,   | j                  t        j                        \  }}| j                  t        j
                  j                  |             t	        j                  |      }t	        j                  |      }| j                  |j                  |j                         dD ]+  }| j                  t        ||      t        ||      dz          - t        t        d      r4t        |d      r'| j                  t        |d      t        |d             y y y )Nr  r   r  r  )r4  r   copy2r   r+   r;   r   r   r   r   r  r!   rp   )r   r   r  
file1_stat
file2_statr  s         r%   
test_copy2zTestCopy.test_copy2>  s     v||4uu-.WWU^
WWU^
++Z-?-?@* 	@D  T!:!(T!:Q!>@	@ 2y!gj*&EWZ<$Z<> 'F!r'   c                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j
                  ||       t        t        d      r5t        j                  |t        j                  t        j                  z         t        t        d      r4t        t        d      r$t        j                  |t        j                         t        j                  |      }t        j                  |      }t        j                  ||d       | j!                  t        j                  j#                  |             | j%                  t'        |      t'        |             t        j(                  |       t        j                  ||d	       | j+                  t        j                  j#                  |             | j%                  t        j,                  |      t        j,                  |             t        j                  |      }t        j.                  t        j0                  v r0d
D ]+  }| j3                  t5        ||      t5        ||      dz          - t        t        d      rL| j%                  |j6                  |j6                         | j9                  |j6                  |j6                         t        t        d      r4t        |d      r'| j%                  |j:                  |j:                         y y y )Nr   r  r  r|  r}  r~  Tr  Fr  r   r  )r   r+   r;   r<   rC   r   rp   r|  r   r  r  r}  r~  r  r   r;  r   rc   r   r]   rB  r   r  r  r#  r  r!   r   r  r  )	r   r(  rx   ry   r  r  r  r  r  s	            r%   test_copy2_symlinkszTestCopy.test_copy2_symlinksO  s2   ,,.ggll7E*ggll7E*77<</3


3!2x IIht|| ;<2z"wt['AKK$..1773<*XsD9,-338
		#XsE:s+,S)2;;x+@A88C=88r222. B$$W]D%A%,Xt%<q%@BB 2x ]22H4D4DE 0 0(2B2BC2z"w}j'I]33X5F5FG (J"r'   c                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j
                  |dd       t        j                  ||       | j                  t        j                  |d      t        j                  |d             t        j                  |       y )Nr   r  r  r  )r   r+   r;   r<   rC   r)  r   r;  r   r+  rB  )r   r(  rx   ry   s       r%   test_copy2_xattrzTestCopy.test_copy2_xattrr  s    ,,.ggll7E*ggll7E*3
CU+S#C,C,	. 			#r'   c                    t         j                  t         j                  fD ]  }| j                         }| j                         }t        j
                  j                  |d      }t        |d        |||      }| j                  |t        j
                  j                  |d              ||t        j
                  j                  |d            }| j                  |t        j
                  j                  |d              y )Nr   r  )	r   r6  r;  r   r+   r;   r<   rC   r   )r   r  rq  rr  rx   r  s         r%   test_copy_return_valuezTestCopy.test_copy_return_value  s    ;;- 	?BllnGllnG'',,w.CsE"C!BRgu!=>Cgu56BRgu!=>	?r'   c                 B    | j                  t        j                         y r*   )_test_copy_dirr   r6  rS  s    r%   test_copy_dirzTestCopy.test_copy_dir  s    FKK(r'   c                 B    | j                  t        j                         y r*   )rF  r   r;  rS  s    r%   test_copy2_dirzTestCopy.test_copy2_dir  s    FLL)r'   c                 ~   | j                         }t        j                  j                  |d      }| j                         }t        j                  j                  |d      }t	        |d       t
        j                  dk(  rt        }nt        }| j                  ||||       | j                  ||||        |||       y Nr   does_not_exist/win32)
r   r+   r;   r<   rC   r   rb  r  IsADirectoryErrorr   )r   	copy_funcrq  src_filer   ry   r  s          r%   rF  zTestCopy._test_copy_dir  s    ,,.77<</||~ggll7$568U#<<7"!C#C#y$8 	#y$4(D!r'   c                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j
                  ||       t        j                  ||d       | j                  t        j                  j                  |             | j                  t        j                  |      t        j                  |             t        j                  ||       | j                  t        j                  j                  |             y )Nrx   ry   r  r   r   Fr  )r   r+   r;   r<   rC   r   r   copyfiler   rc   r   r  r   )r   r(  rx   ry   r  r   s         r%   test_copyfile_symlinkszTestCopy.test_copyfile_symlinks  s    ,,.ggll7E*ggll7E*77<<4ww||GV,3


3h>x01T*BKK,ABc",-r'   r   zrequires os.linkc                 8   t        j                  t               t         j                  j	                  t        d      }t         j                  j	                  t        d      }	 t        |dd      5 }|j                  d       d d d        	 t        j                  ||       | j                  t        j                  t        j                  ||       t        |dd      5 }| j                  |j                         d       d d d        t        j                   |       t        j"                  t        d	
       y # 1 sw Y   xY w# t        $ r}| j                  d|z         Y d }~d }~ww xY w# 1 sw Y   pxY w# t        j"                  t        d	
       w xY w)NrF  rG  r5   r6   r7   cheddarzos.link(): %sr[   Tr   )r+   r   r   r;   r<   r=   r>   r   r  r  r   r   r   rR  r   r\   rB  r   )r   rx   ry   rV   r  s        r%   'test_dont_copy_file_onto_link_to_itselfz0TestCopy.test_dont_copy_file_onto_link_to_itself  s'    	ggll68,ggll66*	6c31 #Q	"#3S! f22FOOS#Nc31 6Q  956IIcNMM&5# # # 3o12236 6 MM&5sf   #E< 1D:E< E ">E<  !E0E< :E?E< 	E-E(#E< (E--E< 0E95E< <Fc                    t        j                  t               t         j                  j	                  t        d      }t         j                  j	                  t        d      }	 t        |dd      5 }|j                  d       d d d        t        j                  d|       | j                  t        j                  t        j                  ||       t        |dd      5 }| j                  |j                         d       d d d        t        j                  |       t        j                  t        d	       y # 1 sw Y   xY w# 1 sw Y   FxY w# t        j                  t        d	       w xY w)
NrF  rG  r5   r6   r7   rU  r[   Tr   )r+   r   r   r;   r<   r=   r>   r   r   r   r   rR  r   r\   rB  r   )r   rx   ry   rV   s       r%   *test_dont_copy_file_onto_symlink_to_itselfz3TestCopy.test_dont_copy_file_onto_symlink_to_itself  s     	ggll68,ggll66*	6c31 #Q	"#
 JJx%f22FOOS#Nc31 6Q  956IIcNMM&5# #6 6 MM&5s=   #E 1D9AE !E E 9E>E E
E E.rM  rN  rO  rP  c                    	 t        j                  t               	 | j                  t        j                  t        j                  t        t               | j                  t        j                  t        j                  t        t               t        j                  t               y # t        $ r}| j	                  d|z         Y d }~d }~ww xY w# t        j                  t               w xY w)Nr  )r+   rM  r   r  r  r   r   SpecialFileErrorrR  r  __file__rB  )r   r  s     r%   test_copyfile_named_pipez!TestCopy.test_copyfile_named_pipe  s    	1IIf	f55 &Bf55 &6C IIf  	1MM+a/00	1 IIfs#   B& A0C &	C/CCC+c                    | j                         }| j                         }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       t        j                  ||      }| j                  t        j                  j                  |             | j                  t        |      t        |             y )Nr  r   )r   r+   r;   r<   rC   r   rR  r   r   r   r]   )r   rq  rr  dst_filerP  r  s         r%   test_copyfile_return_valuez#TestCopy.test_copyfile_return_value  s    ,,.,,.77<</77<</8U#__Xx0r*+8,i.ABr'   c                 J   | j                         }t        j                  j                  |d      }t	        |d       | j                  t        t        j                  ||       | j                  t        t        j                  ||       | j                  t        |      d       y r  )r   r+   r;   r<   rC   r   r   r   rR  r   r   r]   )r   rq  rP  s      r%   test_copyfile_same_filez TestCopy.test_copyfile_same_file  sr     ,,.77<</8U#-(HM%(HE8,e4r'   zMOn MACOS, Solaris and Windows the errors are not confusing (though different)zNot valid on AIX, see gh-92670c                    | j                         }t        j                  j                  |d      }t        j                  j                  |d      }t	        |d       | j                  t        t        j                  ||       y )Nr   rL  )	r   r+   r;   r<   rC   r   r   r   rR  )r   rq  rP  ry   s       r%   test_copyfile_nonexistent_dirz&TestCopy.test_copyfile_nonexistent_dir  s[     ,,.77<</ggll7$568U#+V__hLr'   c                    | j                         }t        j                  j                  |d      }| j                         }t        j                  j                  |d      }t	        |d       t
        j                  dk(  rt        }nt        }| j                  |t        j                  ||       | j                  |t        j                  ||       | j                  |t        j                  ||       y rK  )r   r+   r;   r<   rC   r   rb  r  rN  r   r   rR  )r   rq  rP  r   ry   r  s         r%   test_copyfile_copy_dirzTestCopy.test_copyfile_copy_dir  s     ,,.77<</||~ggll7$568U#<<7"!C#C#v=#v'B#vg>r'   N)-r   r   r   r   r^  r  r_  r`  rp   r+   rg   r  ra  r  r  r"   r  skip_unless_xattrr.  skip_unless_dac_overrider0  r4  r7  r9  r>  r@  rB  rD  rG  rI  rF  rS  rV  rX  r   rb  r\  r_  ra  MACOSSOLARISr   r   rc  re  rF   r'   r%   r  r    s    ""E #E< XX.A"''T/CWX""E # YE< X__WR*,NO""
C # P
C ""(! #(!T XY/ 3 53 	2DF%	F%6   =J !=J~ ""  ''A ( ! #A.I ""4 #40 XW-/BC> D>  "" H # HD   
 !

?)*"$ "". #.  XV,.@A6 B6& ""6 #6( XX.0FGX__S\\Y.;== H	C
5 X__U0g0  3B  C X__S:;M <	 C
M?r'   r  c                      e Zd Zd Zd)dZ ej                         d        Z ej                         d        Zd Z	 ej                          e
j                   ej                  d      d      d               Z ej                         d	        Z ej                         d
        Z ej                         d        Z ej                          e
j                   ej                  d      d      d               Z ej                          e
j                   ej                  d      d      d               Zd Z ej                         d        Z ej                          e
j                  ed      d               Zd Zd Zd Zd Z ej                         d        Zd Zd Z ej                         d        Zd Z d Z!d  Z"d! Z# ej                         d"        Z$ ejJ                         d#        Z& ejN                          e
jP                  e)xr  e*        d$      d%               Z+ ej                         d&        Z,d' Z-y()*TestArchivesc                     t        j                  |      5 }|j                         }|j                          t	        |      cd d d        S # 1 sw Y   y xY wr*   )tarfiler=   getnamessortr:   )r   r;   tarr  s       r%   _tarinfozTestArchives._tarinfo(  s@    \\$ 	 3LLNEJJL<	  	  	 s   +AAc                    | j                         }t        j                  j                  ||      }t        j                  |d       t        |dfd       t        |dfd       t        j                  t        j                  j                  |d             t        |ddfd       t        j                  t        j                  j                  |d             |rt        |d	fd       ||fS )
NT)exist_okr   r  r  r{  file3sub2outer)r   r+   r;   r<   rX  rC   r   )r   r  root_dirdists       r%   _create_fileszTestArchives._create_files.  s    <<>ww||Hh/
D4(D'?E*D'?E*
dE*+D%)51
dF+,'*E2!!r'   c                    | j                         \  }}t        j                         5  t        5  t        j
                  j                  dd      }t        |d|      }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |d      5 }| j                  |j!                         g d       d d d        d d d        d d d        t        j                         5  t        5  t        j
                  j                  dd      }t        |d||      }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |d      5 }| j                  |j!                         g d       d d d        d d d        d d d        t        j                         5  t        5  t        j
                  j                  d	d      }t        |d|t        j
                  j                  |d
            }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |d      5 }| j                  |j!                         ddg       d d d        d d d        d d d        y # 1 sw Y   wxY w# 1 sw Y   |xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y   lxY w# 1 sw Y   y xY w)Nry   archiverp  .tarr[   .z./distz
./dist/subz./dist/sub2z./dist/file1z./dist/file2z./dist/sub/file3z./outerdst2rx  dist/subz	dist/sub2
dist/file1
dist/file2dist/sub/file3dst3r{  r  r  )ry  r   temp_cwdno_chdirr+   r;   r<   r   r   abspathr   ro  rm  
is_tarfiler=   assertCountEqualrn  r   rw  r  	base_namer{  tfs         r%   test_make_tarfilezTestArchives.test_make_tarfile<  s   !//1(! 	%8 	%UI6I"9eX>GWbggooi&@6&IJOOBGGNN734OOG..w78gs+ %r%%bkkm$%%	% 	% ! 
	H8 
	HVY7I"9eXxHGWbggooi&@6&IJOOBGGNN734OOG..w78gs+ Hr%%bkkmGHH
	H 
	H ! 		88 		8VY7I"9eX#%77<<%#@BGWbggooi&@6&IJOOBGGNN734OOG..w78gs+ 8r%%bkkm#%5688		8 		8 		8)% %	% 	% 	% 	%*H H
	H 
	H 
	H 
	H(8 8		8 		8 		8 		8s   N)CN7#NN"N)OC	O#N69OO%O5,C'O)#O6O)>O5NNN&	!N))N36O ;OO	OOO&"O))O2	.O55O>c                 &   | j                         \  }}t        j                  j                  | j	                         dd      }t        j                  j                  ||      }t        j                  |      5  t        5  t        |d      }| j                  ||dz          | j                  t        j                  j                  |             | j                  t        j                  |             t        j                  |d      5 }| j!                  |j#                         g d       d d d        d d d        d d d        t        j                  |      5  t        5  t        j                  j                  dd      }t        |d|      }| j                  ||d	z          | j                  t        j                  j                  |             | j                  t        j                  |             t        j                  |d
      5 }| j!                  |j#                         g d       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   #xY w# 1 sw Y   (xY w# 1 sw Y   AxY w# 1 sw Y   ExY w# 1 sw Y   y xY w)Nry   r{  gztar.tar.gzzr:gzr}  rp  r  r|  r[   r  )ry  r+   r;   r<   r   relpathr   
change_cwdr  r   r   r   ro  rm  r  r=   r  rn  r  s         r%   !test_make_tarfile_without_rootdirz.TestArchives.test_make_tarfile_without_rootdirf  s   !//1(GGLL	B	GGOOIx8	!!(+ 		%X 		%"9g6GWi)&;<OOBGGNN734OOG..w78gv. %"%%bkkm$%%		% 		% !!(+ 		HX 		HUI6I"9ehGGWi&&89OOBGGNN734OOG..w78gs+ Hr%%bkkmGHH		H 		H 		H% %		% 		% 		% 		%$H H		H 		H 		H 		Hsz   8I"?B
I	#I,I4I"J B,I;#I//I;7JIII	I""I,/I84I;;J	 JJc                    | j                         \  }}t        j                         5  t        5  t        j
                  j                  dd      }t        |d|t        j                        }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |d      5 }| j!                  |j#                         g d       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nry   r{  rp  r|  r[   r}  )ry  r   r  r  r+   r;   r<   r   curdirr   r  r   ro  rm  r  r=   r  rn  r  s         r%   &test_make_tarfile_with_explicit_curdirz3TestArchives.test_make_tarfile_with_explicit_curdir  s   !//1(! 
	%8 
	%UI6I"9eXryyIGWbggooi&@6&IJOOBGGNN734OOG..w78gs+ %r%%bkkm$%%
	% 
	% 
	%% %
	% 
	% 
	% 
	%s;   ECE#E)E1EEEE	EE#rp  zNeed the tar command to runc                    | j                         \  }}t        j                  j                  | j	                         d      }t
        5  t        |d||      }d d d        | j                  |dz          | j                  t        j                  j                  |             t        j                  j                  |d      }ddd|g}t        j                  dk(  rGdd l}t        |j                         d   j                  d	      d         d
k\  r|j                  dd       t!        j"                  ||t         j$                         | j                  t        j                  j                  |             | j                  | j'                  |      | j'                  |             t
        5  t        |d||      }d d d        | j                  ||dz          | j                  t        j                  j                  |             t
        5  t        |d||d      }d d d        | j                  ||dz          | j                  t        j                  j                  |             y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   fxY w)Nr{  r  r  zarchive2.tarrp  z-cfr   r   r~     r   z--no-mac-metadatacwdstdoutr|  Tdry_run)ry  r+   r;   r<   r   r  r   r   r   ro  r   rb  r   mac_verr   insertr   
check_callDEVNULLrq  )r   rw  r  r  tarballtarball2tar_cmdrb  s           r%   test_tarfile_vs_tarz TestArchives.test_tarfile_vs_tar  s    "//1(GGLL;	 	K"9gxJG	K 	)i"78w/0 77<<.9%:<<8# 8##%a(..s3A672=q"56g8%/%7%7	9 	x01w/x1HI  	I"9eXxHG	I)f"45w/0  	1"9eXx+/1G	1 	)f"45w/0O	K 	K:	I 	I	1 	1s$   I),I6J)I36I?Jc                    | j                         \  }}t        j                         5  t        5  t        j
                  j                  dd      }t        |d|      }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |      5 }| j                  |j!                         g d       d d d        d d d        d d d        t        j                         5  t        5  t        j
                  j                  dd      }t        |d||      }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |      5 }| j                  |j!                         g d       d d d        d d d        d d d        t        j                         5  t        5  t        j
                  j                  dd      }t        |d|t        j
                  j                  |d	            }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |      5 }| j                  |j!                         d
dg       d d d        d d d        d d d        y # 1 sw Y   uxY w# 1 sw Y   zxY w# 1 sw Y   xY w# 1 sw Y   ~xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   hxY w# 1 sw Y   lxY w# 1 sw Y   y xY w)Nry   r{  zip.zipdist/	dist/sub/
dist/sub2/r  r  r  rv  r  r  r  r  r  r  r  r  r{  r  r  )ry  r   r  r  r+   r;   r<   r   r   r  r   ro  zipfile
is_zipfileZipFiler  namelistr   rw  r  r  r{  zfs         r%   test_make_zipfilezTestArchives.test_make_zipfile  s   !//1(! 
	#8 
	#UI6I"9eX>GWbggooi&@6&IJOOBGGNN734OOG..w78) #R%%bkkm"##
	# 
	# ! 		H8 		HVY7I"9eXxHGWbggooi&@6&IJOOBGGNN734OOG..w78) HR%%bkkmGHH		H 		H ! 		98 		9VY7I"9eX#%77<<%#@BGWbggooi&@6&IJOOBGGNN734OOG..w78) 9R%%bkkm$&6799		9 		9 		9'# #
	# 
	# 
	# 
	#&H H		H 		H 		H 		H&9 9		9 		9 		9 		9s   N&CN6#NN!N&OCO #N37O ?O#O2*C&O&#O3O&;O2NNN#	N&&N03N=8O  O
	OOO#O&&O/	+O22O;c                 H   | j                         \  }}t        j                  j                  | j	                         dd      }t        j                  j                  ||      }t        j                  |      5  t        5  t        |d      }| j                  ||dz          | j                  t        j                  j                  |             | j                  t        j                  |             t        j                  |      5 }| j!                  |j#                         g d       d d d        d d d        d d d        | j                         \  }}t        j                  |      5  t        5  t        j                  j                  dd      }t        |d|      }| j                  ||dz          | j                  t        j                  j                  |             | j                  t        j                  |             t        j                  |      5 }| j!                  |j#                         g d       d d d        d d d        d d d        y # 1 sw Y   0xY w# 1 sw Y   5xY w# 1 sw Y   :xY w# 1 sw Y   AxY w# 1 sw Y   ExY w# 1 sw Y   y xY w)Nry   r{  r  r  r  r  r  )ry  r+   r;   r<   r   r  r   r  r  r   r   r   ro  r  r  r  r  r  r  s         r%   !test_make_zipfile_without_rootdirz.TestArchives.test_make_zipfile_without_rootdir  s   !//1(GGLL	B	GGOOIx8	!!(+ 		#X 		#"9e4GWi&&89OOBGGNN734OOG..w78) #R%%bkkm"##		# 		# "//1(!!(+ 		HX 		HUI6I"9ehGGWi&&89OOBGGNN734OOG..w78) HR%%bkkmGHH		H 		H 		H# #		# 		# 		# 		#&H H		H 		H 		H 		Hsz   8I3?B	I&#I+I&3I3+J2B+J#J  JJI#I&&I0	+I33I= J	JJ	JJ!c                    | j                         \  }}t        j                         5  t        5  t        j
                  j                  dd      }t        |d|t        j                        }| j                  |t        j
                  j                  |      dz          | j                  t        j
                  j                  |             | j                  t        j                  |             t        j                  |      5 }| j!                  |j#                         g d       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nry   r{  r  r  r  )ry  r   r  r  r+   r;   r<   r   r  r   r  r   ro  r  r  r  r  r  r  s         r%   &test_make_zipfile_with_explicit_curdirz3TestArchives.test_make_zipfile_with_explicit_curdir  s    "//1(! 
	#8 
	#UI6I"9eXryyIGWbggooi&@6&IJOOBGGNN734OOG..w78) #R%%bkkm"##
	# 
	# 
	## #
	# 
	# 
	# 
	#s;   ECE#E(E0EE
EE	EE"r  zNeed the zip command to runc                    | j                         \  }}t        j                  j                  | j	                         d      }t
        5  t        |d||      }d d d        | j                  |dz          | j                  t        j                  j                  |             t        j                  j                  |d      }dddd|g}t        j                  ||t        j                         | j                  t        j                  j                  |             t        j                  |      5 }|j                         }d d d        t        j                  |      5 }|j                         }	d d d        | j                  t!              t!        	             y # 1 sw Y   IxY w# 1 sw Y   ixY w# 1 sw Y   GxY w)Nr{  r  r  zarchive2.zipz-qz-rr  )ry  r+   r;   r<   r   r  r   r   r   ro  r   r  r  r  r  r  r`   )
r   rw  r  r  r{  archive2zip_cmdr  r  names2s
             r%   test_zipfile_vs_zipz TestArchives.test_zipfile_vs_zip  s]    "//1(GGLL;	 	I"9eXxHG	I 	)f"45w/0 77<<.9$nh?g8%/%7%7	9 	x01__W% 	"KKME	"__X& 	#"[[]F	#v7'	I 	I	" 	"	# 	#s$   F2F+ F7F(+F47G unzipzNeed the unzip command to runc                    | j                         \  }}t        j                  j                  | j	                         d      }t
        5  t        |d||      }d d d        | j                  |dz          | j                  t        j                  j                  |             dd|g}t        j                  |      5  	 t        j                  |t        j                         d d d        y # 1 sw Y   xY w# t        j                  $ r^}|j                   j#                  d      }d	|v r| j%                  d
       d}| j'                  |j)                  ||             Y d }~d }~ww xY w# 1 sw Y   y xY w)Nr{  r  r  r  z-t)stderrreplace)r   zunrecognized option: tzunzip doesn't support -tz{}

**Unzip Output**
{})ry  r+   r;   r<   r   r  r   r   r   ro  r   r  r   check_outputSTDOUTCalledProcessErroroutputdecoder  r  format)	r   rw  r  r  r{  r  r  detailsmsgs	            r%   test_unzip_zipfilezTestArchives.test_unzip_zipfile2  s@    "//1(GGLL;	 	I"9eXxHG	I 	)f"45w/0 D'*!!(+ 	44''
8I8IJ	4 	4	I 	I 00 4**++9+=+w6MM"<=2		#**S'2334	4 	4s=   C,<E,>%C8,C58E)AE$E,$E))E,,E5c                     | j                         }t        j                  j                  |d      }| j	                  t
        t        |d       y )Nr{  r  )r   r+   r;   r<   r   
ValueErrorr   )r   r   r  s      r%   test_make_archivezTestArchives.test_make_archiveK  s5    GGLL3	*lIuEr'   c                    t         r1t        j                  d      d   }t        j                  d      d   }ndx}}| j                         \  }}t        j                  j                  | j                         d      }t        |d||||      }| j                  t        j                  j                  |             t        |d||      }| j                  t        j                  j                  |             t        |d||||      }| j                  t        j                  j                  |             t        |d||dd      }| j                  t        j                  j                  |             y )	Nr   r  r{  r  ownergrouprp  	kjhkjhkjgoihohoh)UID_GID_SUPPORTgrpgetgrgidpwdgetpwuidry  r+   r;   r<   r   r   r   ro  )r   r  r  rw  r  r  rf   s          r%   test_make_archive_owner_groupz*TestArchives.test_make_archive_owner_groupP  s    LLOA&ELLOA&E""EE!//1(GGLL;	9eXxu!&(s+,9eXx@s+,9eXx!&e5s+,9eXx!,I?s+,r'   Requires grp and pwd supportc           
          | j                         \  }}t        j                  j                  | j	                         d      }t        j                  d      d   }t        j                  d      d   }t        j                  |      5  t        5  t        |d|d||      }d d d        d d d        | j                  t        j                  j                               t        j                   |      }	 |j#                         D ]:  }| j%                  |j&                  d       | j%                  |j(                  d       < 	 |j+                          y # 1 sw Y   xY w# 1 sw Y   xY w# |j+                          w xY w)Nr{  r   r  rx  r  )ry  r+   r;   r<   r   r  r  r  r  r   r  r  r   r   ro  rm  r=   
getmembersr   uidgidr1  )	r   rw  r  r  r  r  archive_namer{  members	            r%   test_tarfile_root_ownerz$TestArchives.test_tarfile_root_ownerl  s6    "//1(GGLL;	Q"Q"!!(+ 	BX 	B'	7Hf.35BL	B 	B
 	|45 ,,|,	!,,. 0  Q/  Q/0 MMO	B 	B 	B 	B MMOs1   EE E4AE+ E	EE(+E=c                 z    t        j                          fd}t        d|g d       	 t        5   j	                  t
              5  t        dd       d d d        d d d         j                  t        j                                t        d       y # 1 sw Y   AxY w# 1 sw Y   ExY w# t        d       w xY w)Nc                     j                  d|       j                  | d       j                  t        j                                t	               Nrw  basename)r  r   r+   rs   RuntimeError)r  r  kwcurrent_dirr   s      r%   archiverz<TestArchives.test_make_archive_cwd_default.<locals>.archiver  sA    Z,Y
3RYY[+6. r'   r  xxx filer  )	r+   rs   r   r  r   r  r   r   r   )r   r  r  s   ` @r%   test_make_archive_cwd_defaultz*TestArchives.test_make_archive_cwd_default  s    iik	! 	 xZ@	- 4&&|4 4 U344 RYY[+6%e,	4 44 4
 &e,s:   B- B!BB!,B- B	B!!B*&B- -B:c                     t        j                          j                          fd}g fd}t        d|g d       	 t	        j
                  t         d|      5  j                  t              5  t        dd       d d d        d d d         j                  t        j                                 j                  g       t        d       y # 1 sw Y   UxY w# 1 sw Y   YxY w# t        d       w xY w)Nc                     j                  d|       j                  | t        j                  j	                  d             j                  t        j
                                t               r  )r  r   r+   r;   r<   rs   r  r  r  r  r  rw  r   s      r%   r  z4TestArchives.test_make_archive_cwd.<locals>.archiver  sP    Z,Y[*(MNRYY[(3. r'   c                 8    j                  |         |        y r*   r   )r;   r  
orig_chdirs    r%   _chdirz2TestArchives.test_make_archive_cwd.<locals>._chdir  s    KKtr'   r  r  chdirr  rw  )r+   rs   r   r   r   r3  r   r  r   r   r   )r   r  r  r  r  r  rw  s   `  @@@@r%   test_make_archive_cwdz"TestArchives.test_make_archive_cwd  s    iik<<>	!
 	 	 xZ@	-""2w7 G:&&|4 G UXFGG RYY[+6THk#:;%e,G GG G &e,s=   C4 #C(9CC(A C4 C%	!C((C1-C4 4Dc                     t        j                          j                          fd}d|_        t	        d|g d       	 t
        5   j                  t              5  t        dd       d d d        d d d         j                  t        j                                t        d       y # 1 sw Y   AxY w# 1 sw Y   ExY w# t        d       w xY w)Nc                     j                  | d       j                  |d          j                  t        j                                t               )Nr  rw  )r   r+   rs   r  r  s      r%   r  zFTestArchives.test_make_archive_cwd_supports_root_dir.<locals>.archiver  sE    Y
3R
^X6RYY[+6. r'   Tr  r  r  r  )r+   rs   r   supports_root_dirr   r  r   r  r   r   r   )r   r  r  rw  s   ` @@r%   'test_make_archive_cwd_supports_root_dirz4TestArchives.test_make_archive_cwd_supports_root_dir  s    iik<<>	!
 &*"xZ@	- G&&|4 G UXFGG RYY[+6%e,	G GG G
 &e,s<   C B<!B00B<8,C 0B9	5B<<CC Cc                 B   | j                         }t        j                  |      5  t        5  | j	                  t        dd      d       | j                  t        j                  j                  d             d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Ntestrp  ztest.tar
r   r   r  r  r   r   r   r+   r;   ro  r   rw  s     r%   test_make_tarfile_in_curdirz(TestArchives.test_make_tarfile_in_curdir  sw    <<>!!(+ 	8X 	8\&%8*EOOBGGNN:67	8 	8 	8 	8 	8 	8#   BAB	8B	B	BBc                 B   | j                         }t        j                  |      5  t        5  | j	                  t        dd      d       | j                  t        j                  j                  d             d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr  r  ztest.zipr  r  s     r%   test_make_zipfile_in_curdirz(TestArchives.test_make_zipfile_in_curdir  sy     <<>!!(+ 	8X 	8\&%8*EOOBGGNN:67	8 	8 	8 	8 	8 	8r   c                    | j                  t        t        dd       | j                  t        t        dd d       | j                  t        t        dd ddg       t        dd dgd       t               D cg c]  \  }}|	 }}}| j	                  d|       t        d       t               D cg c]  \  }}|	 }}}| j                  d|       y c c}}w c c}}w )	Nr  r   c                      t         S r*   xrF   r'   r%   <lambda>z;TestArchives.test_register_archive_format.<locals>.<lambda>      Q r'   c                      t         S r*   r  rF   r'   r%   r  z;TestArchives.test_register_archive_format.<locals>.<lambda>  r  r'   )r   ro   )r   ro   r   c                      t         S r*   r  rF   r'   r%   r  z;TestArchives.test_register_archive_format.<locals>.<lambda>  s    q r'   r  )r   	TypeErrorr   r   r  r   r  )r   rg   paramsformatss       r%   test_register_archive_formatz)TestArchives.test_register_archive_format  s    )%<eQG)%<eY	)%<eY!9-	/ 	 y6(JG,?,ABLD&4BBeW%!%(,?,ABLD&4BB( C Cs   8C1Cc           	         | j                  t        j                  t         d       dD ]  }| j	                  |      5  | j                         }t        j                  j                  |d      }| j                  t              5 }t        t        d||       d d d        | j                  j                  j                  t        j                         | j                  |j                  j                   |       | j#                  t        j                  j%                  t         d             t'        j(                  |      \  }}t        j*                  |       | j                  t,              5 }t        t        d||       d d d        | j                  |j                  j                  t        j.                         | j                  |j                  j                   |       | j#                  t        j                  j%                  t         d             d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   $xY w)Nr|  FTr  nonexistingrp  r   r   r   ru   r   subTestr   r+   r;   r<   r   r   r   r   r   r"   ENOENTr   r   r   rq   rA  r1  r   ENOTDIRr   r  r(  nonexisting_filer   tmp_fdtmp_files          r%   test_make_tarfile_rootdir_nodirz,TestArchives.test_make_tarfile_rootdir_nodir  s   	((VHD/:$ 	BGg. B,,.#%77<<#G &&'89 SR 0@'RS  !3!3U\\B  !6!68HI  6($!@A $,#3#3#@  &&'9: Kb 'JK  !3!3U]]C  !6!6A  6($!@A#B B	B
S SK KB B?    AIH+CI4H8BI+H50I8I=II	c           	         | j                  t        j                  t         d       dD ]  }| j	                  |      5  | j                         }t        j                  j                  |d      }| j                  t              5 }t        t        d||       d d d        | j                  j                  j                  t        j                         | j                  |j                  j                   |       | j#                  t        j                  j%                  t         d             t'        j(                  |      \  }}t        j*                  |       | j                  t,              5 }t        t        d||       d d d        | j                  |j                  j                  t        j.                         | j                  |j                  j                   |       | j#                  t        j                  j%                  t         d             d d d         y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   $xY w)Nr  r  r  r  r  r   r  r  s          r%   test_make_zipfile_rootdir_nodirz,TestArchives.test_make_zipfile_rootdir_nodir  s    		((VHD/:$ 	BGg. B,,.#%77<<#G &&'89 SR 0@'RS  !3!3U\\B  !6!68HI  6($!@A $,#3#3#@  &&'9: Kb 'JK  !3!3U]]C  !6!6A  6($!@A#B B	B
S SK KB Br  c                      | j                   |d fi |  | j                   |t        fi |  | j                   |t        fi | y )Nc                     | S r*   rF   r;   s    r%   r  z3TestArchives.check_unpack_archive.<locals>.<lambda>  s     r'   )#check_unpack_archive_with_converterr   )r   r  r$   s      r%   check_unpack_archivez!TestArchives.check_unpack_archive  sT    000%	1)/	1000H	( &	(000LVLr'   c                    | j                         \  }}t        |      }|j                  d       t        j                  j                  | j                         d      }t        ||||      }| j                         }	t         ||       ||	      fi | | j                  t        |	      |       | j                         }
t         ||       ||
      fd|i| | j                  t        |
      |       | j                  t        j                        5  t         |t              fi | d d d        | j                  t              5  t         |t              fddi| d d d        y # 1 sw Y   @xY w# 1 sw Y   y xY w)Nrv  r{  r  r  )ry  re   rB  r+   r;   r<   r   r   r   r   r   r   	ReadErrorr   r  )r   r  	converterr$   rw  r  expectedr  r   r3  tmpdir3s              r%   r!  z0TestArchives.check_unpack_archive_with_converter  sV   !//1(H% GGLL;		68XF ,,.y*Ig,>I&I'*H5 ,,.y*Ig,> 	!v 	!	!'*H5v//0 	89V,77	8z* 	F9V,EUEfE	F 	F	8 	8	F 	Fs   E+	E7+E47F c                     | j                  |d       | j                  |d       t        j                  dt        f      5  | j                  |       d d d        y # 1 sw Y   y xY w)Nfully_trustedfilterdatazPython 3.14)r"  r   check_warningsDeprecationWarning)r   r  s     r%   check_unpack_tarballz!TestArchives.check_unpack_tarball/  sb    !!&!A!!&!8++ 235 	.%%f-	. 	. 	.s   AA&c                 &    | j                  d       y )Nrp  r/  rS  s    r%   test_unpack_archive_tarz$TestArchives.test_unpack_archive_tar6  s    !!%(r'   c                 &    | j                  d       y )Nr  r1  rS  s    r%   test_unpack_archive_gztarz&TestArchives.test_unpack_archive_gztar9      !!'*r'   c                 &    | j                  d       y )Nbztarr1  rS  s    r%   test_unpack_archive_bztarz&TestArchives.test_unpack_archive_bztar=  r5  r'   z(AIX MAXDATA must be 0x20000000 or largerc                 &    | j                  d       y )Nxztarr1  rS  s    r%   test_unpack_archive_xztarz&TestArchives.test_unpack_archive_xztarA  s     	!!'*r'   c                     | j                  d       | j                  t              5  | j                  dd       d d d        y # 1 sw Y   y xY w)Nr  r,  r*  )r"  r   r  rS  s    r%   test_unpack_archive_zipz$TestArchives.test_unpack_archive_zipF  sF    !!%(y) 	<%%eF%;	< 	< 	<s   AAc                     t               } fd}t        dddg|dg       t        dd        j                  t        t        ddg|       t        d       t        ddg|        j                  ddgd	ft                       j                  ddgd	ft                      t        d        j                  t               |       y )
Nc                 r    j                  |d       j                  | d       j                  |d       y )Nr   	stuff.booxx)r   )r   extract_dirextrar   s      r%   _booz/TestArchives.test_unpack_registry.<locals>._booP  s3    UA&X{3[$/r'   Booz.booz.b2)rC  r   r@  rA  Boo2r   )	r   r	   r   r   r
   r   r  r  r   )r   r  rD  s   `  r%   test_unpack_registryz!TestArchives.test_unpack_registryL  s    $&	0
 	uvuotl^L{D) 	-)?!(D	* 	!'vx6vx,.@.BC%&2.0B0DE 	!(+-w7r'   N)rx  ).r   r   r   rq  ry  r   requires_zlibr  r  r  r_  r`  r   whichr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r"  r!  r/  r2  r4  requires_bz2r8  requires_lzmara  r   r   r;  r=  rG  rF   r'   r%   rk  rk  $  s    " W'8 '8R WH H8% WXe,68*18 *1X W%9 %9N WH H: W# # WXe,6888 80 WXg.8:4: 4,F
 W- -6 WX*HI J *-"-.-&8 W8 8) B. WB B2MF0.) W+ + W+ + WX__S--/YZ+ [ + W< <
8r'   rk  c                       e Zd Z ej                   eed      d      d        Z ej                  ed       ej                   ee	d      d      d               Z
y)	TestMisc
disk_usagez)disk_usage not available on this platformc                 0   t        j                  t        j                  j	                  t
                    }dD ]"  }| j                  t        ||      t               $ | j                  |j                  d       | j                  |j                  d       | j                  |j                  d       | j                  |j                  |j                         | j                  |j                  |j                         t        j                  t
               y )N)rG   usedfreer   )r   rN  r+   r;   rm  r[  r   r!   r   assertGreaterrG   rP  assertGreaterEqualrQ  )r   usager  s      r%   test_disk_usagezTestMisc.test_disk_usagei  s     !!"''//(";<- 	=D!!'%"6<	=5;;*5::q)

A.UZZ85;;

3 	(#r'   r  chownzrequires os.chownc                 ^     j                         }t        j                  |      t        d        j	                  t
              5  t        j                         d d d         j	                  t              5  t        j                  d       d d d         j	                  t              5  t        j                  d       d d d         j	                  t              5  t        j                  d       d d d         j	                  t              5  t        j                  d       d d d        t        j                         }t        j                         }d fd		}t        j                  ||        |||       t        j                  |        ||       t        j                  |        ||       t        j                  |        ||
       t        j                  |||        ||||       t        j                  ||        |||       t        j                  ||        |||       t        j                  ||        |||
       	 t        j                  |      d   }t        j                   |      d   }t        j                  ||        |||       t        j                  |||        ||||       y # 1 sw Y   xY w# 1 sw Y   YxY w# 1 sw Y   1xY w# 1 sw Y   
xY w# 1 sw Y   xY w# t"        $ r Y y w xY w)Nr   ztesting chown functionznon-existing username)userznon-existing groupname)r     spamgQ	@c                     t        j                        }|j                  ||j                         |j                  ||j                         y y r*   )r+   r   r   st_uidst_gid)r;   r  r  sr   r   s       r%   check_chownz(TestMisc.test_chown.<locals>.check_chown  sH    !A  ahh/  ahh/ r'   )r  r   )NN)r   rq   r   rC   r   r  r   rV  LookupErrorr  r+   getuidgetgidr  r  r  r  KeyError)r   rm  r  r  r^  rX  r  r   s   `      @r%   
test_chownzTestMisc.test_chownx  s    ,,.??w/856z* 	#LL"	# {+ 	ALL(?@	A {+ 	CLL)AB	C y) 	,LL7+	, y) 	)LL4(	) iikiik	0 	XsC(Hc3'Xs#Hc"XC(Hc"XS)H#&Wc3'GS#&Wc"GS!W3'GS!WC(G%
	+<<$Q'DLL%a(E
 LL4/#s+LL$.c*k	# 	#	A 	A	C 	C	, 	,	) 	)D  		sN   
K=K,2K9'LL,0L  K),K69LLL 	L,+L,N)r   r   r   r_  r`  rp   r   rU  r  r+   rc  rF   r'   r%   rM  rM  g  st    X6DF$F$ X*HIXW-/BC:+ D J:+r'   rM  c                      e Zd Zd Zd Zd Zd Zd Z ej                  e
j                  dk7  d      d        Z ej                  e
j                  dk(  d	      d
        Z ej                  e
j                  dk(  d	      d        Z ej                  e
j                  dk(  d	      d        Zej"                  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 Z ej                  e
j                  dk(  d      d        Z ej                  e
j                  dk(  d      d        Z ej                  e
j                  dk(  d      d        Z ej                  e
j                  dk(  d      d        Z ej                  e
j                  dk(  d      d        Z  ej                  e
j                  dk(  d      d        Z!y) 	TestWhichc                    | j                  d      | _        t        j                  | j                  dd      | _        t        j                  | j                  j                  t        j                         | j                  | j                  j                         t
        j                  j                  | j                  j                        \  | _        | _        | j                  | _        t
        j"                  | _        d| _        y )NTmp)r   z.Exerm   r   suffixz.EXE)r   temp_dirrq   rr   	temp_filer+   r   rg   r   S_IXUSRr   r1  r;   r   rm   fileenv_pathr  extrS  s    r%   setUpzTestWhich.setUp  s    E2 "44<A<BD 	$$dll3,,- ggmmDNN,?,?@$)iir'   c                 F    t        |t              r|j                         S |S )zM
        In this class we're testing with str, so convert s to a str
        )r9   r   r  r   r]  s     r%   to_text_typezTestWhich.to_text_type  s     a88:r'   c                     t        j                  | j                  | j                        }| j	                  || j
                  j                         y Nr   )r   rI  rm  rm   r   rk  rg   r   r  s     r%   
test_basiczTestWhich.test_basic  s4    \\$))$((3T^^001r'   c                     t        j                  | j                  j                  | j                        }| j                  || j                  j                         y ru  )r   rI  rk  rg   rj  r   rv  s     r%   test_absolute_cmdzTestWhich.test_absolute_cmd  s<     \\$..--DMMBT^^001r'   c                 &   t         j                  j                  | j                        \  }}t         j                  j	                  || j
                        }t        j                  |      5  t        j                  || j                        }| j                  ||       d d d        t        j                  | j                        5  t        j                  ||      }| j                  |       d d d        y # 1 sw Y   [xY w# 1 sw Y   y xY wru  )r+   r;   r   rm   r<   rm  r   r  r   rI  rj  r   assertIsNone)r   r  tail_dirr  r  s        r%   test_relative_cmdzTestWhich.test_relative_cmd  s      WW]]4884('',,x3!!x0 	*gDMM:BR)	* !!txx0 	"gH5Bb!	" 	"		* 	*	" 	"s   -4C;	)D;DDrM  ztest is for non win32c                 $   t         j                  j                  | j                        }t	        j
                  | j                        5  t        j                  | j                  |      }| j                  |       d d d        y # 1 sw Y   y xY wru  )
r+   r;   rm  rm   r   r  r   rI  rm  r{  r   r  r  s      r%   test_cwd_non_win32zTestWhich.test_cwd_non_win32  sc     77??488,!!txx0 	"diih7Bb!	" 	" 	"s   
3BBztest is for win32c           	         t         j                  j                  | j                        }t	        j
                  | j                        5  t        j                  j                  dd      5  t        j                  | j                  |      }| j                  |t         j                  j                  | j                  | j                               d d d        t        j                  j                  dd      5  t        j                  | j                  |      }| j                  |       d d d        d d d        y # 1 sw Y   nxY w# 1 sw Y   xY w# 1 sw Y   y xY w)Nr   shutil._win_path_needs_curdirTreturn_valueF)r+   r;   rm  rm   r   r  r_  r  r  r   rI  rm  r   r<   r  r{  r  s      r%   test_cwd_win32zTestWhich.test_cwd_win32  s    77??488,!!txx0 	&$$%DSW$X K\\$))(;  RWW\\$++tyy%IJK $$%DSX$Y &\\$))(;!!"%&	& 	&K K& &	& 	&s=   
"E,A&D?)E;3E.E?E	EE	EE c                 n   t        j                  t        j                  | j                              }|dz  }|j                          |dz  }|j                          |dz  }|j                          t        j                  |      5  t        j                  j                  dd      5  t        j                  d|      }d d d        | j                  t        j                  j!                        t        j                  j!                  |             d d d        y # 1 sw Y   ^xY w# 1 sw Y   y xY w)Nr   z	hello.exer   r  Tr  )pathlibPathr+   fsdecoderm   r   touchr   r  r_  r  r  r   rI  r   r;   r  )r   r  elsewhere_in_path_dirmatch_elsewhere_in_path
exe_in_cwdr  s         r%   *test_cwd_win32_added_before_all_other_pathz4TestWhich.test_cwd_win32_added_before_all_other_path  s     <<DHH 56 (6 1##%"7+"E%%'+
!!x0 	O$$%DSW$X K\\+4IJK RWW__R0"''//*2MN		O 	OK K	O 	Os%   "D+*DAD+D(	$D++D4c                 "   t        j                  t        j                  | j                              }|dz  }|dz  }|j                          |j                          |dz  }|dz  }|j                          |j                          t        j                  j                  t        |      t        |      g      }t        j                  j                  t        j                  d|t        j                              j                         dk(  sJ y )Nr   r   zhello.com.exez	hello.comr;   rA   )r  r  r+   r  rm   r   r  pathsepr<   r  r;   r  r   rI  F_OKlower)r   r  r   r   pathext_match
path_match	test_paths          r%   )test_pathext_match_before_path_full_matchz3TestWhich.test_pathext_match_before_path_full_match	  s     <<DHH 56& & 



.K'
JJOOSYD	$:;	wwi!
 57o& 	& &r'   c                    t        j                  | j                  j                  t        j
                         t        j                  | j                  j                  t         j                        r| j                  d       t        j                  | j                  | j                  t         j                        }| j                  |       y )Nzcan't set the file read-onlyr  )r+   r   rk  rg   r   r   accessW_OKr  r   rI  rm  rm   r{  rv  s     r%   test_non_matching_modez TestWhich.test_non_matching_mode%	  su     	$$dll399T^^(("''2MM89\\$))$((A"r'   c                 h   t         j                  j                  | j                        \  }}t	        j
                  |      5  t        j                  | j                  |      }| j                  |t         j                  j                  || j                               d d d        y # 1 sw Y   y xY wru  )r+   r;   r   rm   r   r  r   rI  rm  r   r<   )r   r  r|  r  s       r%   test_relative_pathzTestWhich.test_relative_path.	  s{    WW]]4884(!!x0 	Ddiih7BRh		!BC	D 	D 	Ds   AB((B1c                 h    t        j                  d| j                        }| j                  |       y )Nzfoo.exer   )r   rI  rm   r{  rv  s     r%   test_nonexistent_filezTestWhich.test_nonexistent_file4	  s$    \\)$((3"r'   zpathext check is Windows-onlyc                     t        j                  | j                  d d | j                        }| j	                  || j
                  j                  d d | j                  z          y )Nr   )r   rI  rm  rm   r   rk  rg   ro  rv  s     r%   test_pathext_checkingzTestWhich.test_pathext_checking9	  sL    
 \\$))CR.txx8T^^00"5@Ar'   c                     t        j                         5 }| j                  |d<   t        j                  | j
                        }| j                  || j                  j                         d d d        y # 1 sw Y   y xY wNPATH)	r   EnvironmentVarGuardrn  r   rI  rm  r   rk  rg   r   envr  s      r%   test_environ_pathzTestWhich.test_environ_pathA	  s^    **, 	6--CKdii(BR!4!45	6 	6 	6s   AA33A<c           	         t        j                         5 }d|d<   t        j                  j	                  d| j
                  d      5  t        j                  t        d| j
                        5  t        j                  | j
                        5  t        j                  | j                        }| j                  |       d d d        d d d        d d d        d d d        y # 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)Nr   r  
os.confstrTr  createdefpath)r   r  r_  r  r  rm   r   r3  r+   r  r   rI  rm  r{  r  s      r%   test_environ_path_emptyz!TestWhich.test_environ_path_emptyG	  s    **, 	&CK$$\,0 % 2 &""2y$((;& %%dhh/& \\$)),!!"%& & &	& 	&& & & & & &	& 	&sS   2D&C7- C+1C	>C+C7DC($C++C40C77D 	<DDc           	         t         j                  j                  | j                  j                        }t
        j                  dk(  rUt         j                  }t        |t              rt        j                  |      }t         j                  j                  ||      }t        j                         5 }t         j                  |d<   t        j                   j#                  d| j$                  d      5  t'        j(                  t         d| j$                        5  t+        j,                  | j.                        }| j1                  |       t        j2                  | j$                        5  t+        j,                  | j.                        }| j5                  ||       d d d        d d d        d d d        d d d        y # 1 sw Y   "xY w# 1 sw Y   &xY w# 1 sw Y   *xY w# 1 sw Y   y xY w)NrM  r  r  Tr  r  )r+   r;   r  rk  rg   r   rb  r  r9   r   r   r<   r   r  r  r_  r  r  rm   r   r3  r   rI  rm  r{  r  r   )r   expected_cwdr  r  r  s        r%   test_environ_path_cwdzTestWhich.test_environ_path_cwdR	  sg   ww''(;(;<<<7"YYF,.V,77<<=L **, 	7**CK$$\,0 % 2 	7""2y$((;	7 \\$)),!!"% ))$((3 7dii0B$$R67	7 	7	7 	77 7	7 	7 	7 	7	7 	7sV   0A G0&GAG&2F9	G G(G9G>GG
GG	GG&c                 Z   t        j                         5 }|j                  dd        t        j                  j                  dt        d      5  t        j                  t        d| j                        5  t        j                  | j                        }d d d        d d d        | j                  | j                  j                          t        j                  j                  d| j                  d      5  t        j                  t        dd      5  t        j                  | j                        }d d d        d d d        | j                  || j                  j                          d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   XxY w# 1 sw Y   \xY w# 1 sw Y   y xY w)Nr  r  T)r   r  r  r  r   )r   r  popr_  r  r  r  r   r3  r+   rm   r   rI  rm  r   rk  rg   r  s      r%   test_environ_path_missingz#TestWhich.test_environ_path_missingh	  sX   **, 	6GGFD! $$\z,0 % 2 -""2y$((;- \\$)),- - R!4!45 $$\,0 % 2 -""2y"5- \\$)),- - R!4!45	6 	6- - - -- - - -	6 	6sl   9F!&E=4 E1E=AF!6F F	2F:.F!1E:6E==F	F!	FFF	F!!F*c                    t         j                  j                  | j                        }t	        j
                  | j                        5  t	        j                         5 }| j                  |d<   t        j                  | j                  d      }| j                  |       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nr   r  r   )r+   r;   rm  rm   r   r  r  rn  r   rI  rm  r{  )r   r  r  r  s       r%   test_empty_pathzTestWhich.test_empty_pathz	  s    77??488,!!txx0 	"**,	"03--CKdiib1Bb!		" 	" 	" 	" 	" 	"s%   
B>AB2!B>2B;	7B>>Cc                     t        j                         5 }|j                  dd        t        j                  | j
                        }| j                  |       d d d        y # 1 sw Y   y xY wr  )r   r  r  r   rI  rm  r{  r  s      r%   test_empty_path_no_PATHz!TestWhich.test_empty_path_no_PATH	  sS    **, 	"GGFD!dii(Bb!	" 	" 	"s   AA!!A*ztest specific to Windowsc                    | j                  d      }t        j                  | j                  | j                  d      |      }t	        j
                  |j                  t        j                         | j                  |j                         t        j                  j                  |j                        }t        j                  j                  |      d   }t        j                         5 }t!        |t"              r|n|j%                         |d<   t'        j(                  || j                        }| j+                  ||j                         d d d        y # 1 sw Y   y xY w)N.xyzTmp2rh  r   PATHEXTr   )rs  rq   rr   rj  r+   r   rg   r   rl  r   r1  r;   r  r  r   r  r9   r  r  r   rI  r   r   ro  temp_filexyzprogramr  r  s         r%   test_pathextzTestWhich.test_pathext	  s    '22t}}:>:K:KF:S\_a
""DLL1**+ ''""<#4#45''""7+A.**, 	4$.sC$8ScjjlC	NgDMM:BR!2!23	4 	4 	4s   +A#EE c                 p   | j                  d      }t        j                  | j                  | j                  d      |      }| j	                  |j
                         t        j                  j                  |j                        }t        j                  j                  |      d   }t        j                         5 }t        |t              r|n|j                          d|d<   t!        j"                  || j                        }| j%                  ||j                         d d d        y # 1 sw Y   y xY w)Nr  r  rh  r   ;r  r   )rs  rq   rr   rj  r   r1  r+   r;   r  rg   r  r   r  r9   r  r  r   rI  r   r  s         r%   test_pathext_with_empty_strz%TestWhich.test_pathext_with_empty_str	  s    '22t}}:>:K:KF:S\_a**+ ''""<#4#45''""7+A.**, 	4'1#s';NaPC	NgDMM:BR!2!23	4 	4 	4s   =A&D,,D5c                     t        j                         5 }t        | j                  t              r| j                  n| j                  j                         |d<   d|d<   t        j                  j                  | j                  | j                  d            }t        |d      j                          t        j                  |d       | j                  t        j                  | j                  d            |       d d d        y # 1 sw Y   y xY w)Nr  .testr  ztest_program.testr5     test_programr   r  r9   rj  r  r  r+   r;   r<   rs  r=   r1  r   r   r   rI  )r   r  r  s      r%   %test_pathext_applied_on_files_in_pathz/TestWhich.test_pathext_applied_on_files_in_path	  s    **, 	Y+5dmmS+I$--t}}OcOcOeCK$C	NT]]D4E4EFY4Z[IC &&(HHY&V\\$*;*;N*KLiX	Y 	Y 	Ys   C&DDc                 v   t         j                  j                  dd      5 }| j                  t	        j
                  dt        j                               |j                  d       |j                          | j                  t	        j
                  dd             |j                          d d d        t         j                  j                  dd      5 }| j                  t	        j
                  dt        j                               |j                  d       d d d        y # 1 sw Y   xxY w# 1 sw Y   y xY w)Nz&_winapi.NeedCurrentDirectoryForExePathTr  dontcarer   F)r_  r  r  r   r   _win_path_needs_curdirr+   X_OKassert_called_once_with
reset_mockassert_not_calledr   )r   need_curdir_mocks     r%   test_win_path_needs_curdirz$TestWhich.test_win_path_needs_curdir	  s    ]]  !IX\ ] 	1aqOOF99*bggNO44Z@'')OOF99*aHI..0	1 ]]  !IX] ^ 	AbrV:::rwwOP44Z@	A 	A	1 	1	A 	As   B
D#AD/#D,/D8c                    t        j                         5 }t        | j                  t              r| j                  n| j                  j                         |d<   d|d<   t        j                  j                  | j                  | j                  d            }t        |d      j                          t        j                  |d       | j                  t        j                  | j                  d            |       t        j                  j                  | j                  | j                  d            }t        |d      j                          t        j                  |d       | j                  t        j                  | j                  d            |       | j                  t        j                  | j                  d      t        j                         |       d d d        y # 1 sw Y   y xY w)	Nr  r  r  test.exer5   r  ztest.exe.test)rA   )r   r  r9   rj  r  r  r+   r;   r<   rs  r=   r1  r   r   r   rI  r  )r   r  exedot_tests       r%   "test_pathext_preferred_for_executez,TestWhich.test_pathext_preferred_for_execute	  s[   **, 	]+5dmmS+I$--t}}OcOcOeCK$C	N'',,t}}d.?.?
.KLCcN  "HHS%  V\\$*;*;J*GH#Nww||DMM43D3D_3UVH3%%'HHXu% V\\$*;*;J*GH(S V\\$*;*;J*GbggVX[\)	] 	] 	]s   GG%%G.c                 Z   t        j                         5 }t        | j                  t              r| j                  n| j                  j                         |d<   d|d<   t        j                  j                  | j                  | j                  d            }t        |d      j                          t        j                  |d       t        j                  j                  | j                  | j                  d            }t        |d      j                          t        j                  |d       | j                  t        j                  | j                  d            |       | j                  t        j                  | j                  d            |       d d d        y # 1 sw Y   y xY w)	Nr  z
.exe2;.exer  r  r5   r  z	test.exe2r  r  )r   r  r  exe2s       r%   &test_pathext_given_extension_preferredz0TestWhich.test_pathext_given_extension_preferred	  s+   **, 	L+5dmmS+I$--t}}OcOcOeCK)C	N'',,t}}d.?.?
.KLCcN  "HHS% 77<<t/@/@/MNDsO!!#HHT5! V\\$*;*;J*GH#NV\\$*;*;F*CDdK	L 	L 	Ls   FF!!F*N)"r   r   r   rp  rs  rw  ry  r}  r_  r`  r   rb  r  r  r  r  r   rc  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rF   r'   r%   re  re    si   2
2" X002"2" X0,.
&.
& X0,.O.O" X0,.&.&" ## $D
 X08:B:B6	&7,6$"" X02LM4 N4" X02LM4 N4  X02LM	Y N	Y X02LM
A N
A X02LM] N]0 X02LML NLr'   re  c                       e Zd Zd Zd Zy)TestWhichBytesc                    t         j                  |        t        j                  | j                        | _        t        j                  | j
                        | _        t        j                  | j                  j                        | j                  _        t        j                  | j                        | _        t        j                  | j                        | _	        t        j                  | j                        | _
        y r*   )re  rp  r+   r   rm   rm  rk  rg   rj  r  ro  rS  s    r%   rp  zTestWhichBytes.setUp	  s    ;;txx(KK		*	 kk$..*=*=>DMM2kk$++.;;txx(r'   c                 F    t        |t              r|j                         S |S )zQ
        In this class we're testing with bytes, so convert s to a bytes
        )r9   r  rP   rr  s     r%   rs  zTestWhichBytes.to_text_type	  s     a88:r'   N)r   r   r   rp  rs  rF   r'   r%   r  r  	  s    )r'   r  c                      e Zd Zd Zd Zd Zd Zd Zd Zd Z	e
d        Ze
d	        Zd
 Ze
d        Zd Ze
d        Zd Z ej&                  ej*                  j,                  d      d        Zd Zd Zd Zd Zej:                  e
d               Zej:                  e
d               Zej:                  e
d               Z ej:                  e
d               Z!d Z"d Z#e
d        Z$e
d        Z%d Z&e
d        Z'ej:                  d        Z(ej:                  d         Z)ejT                   ej&                   e+ed!      xr  e+e,d"      xr	  e+e,d#      d$      d%               Z-y&)'TestMovec                    d}| j                         | _        | j                         | _        t        j                  j                  | j                  |      | _        t        j                  j                  | j                  |      | _        t        | j                  d      5 }|j                  d       d d d        y # 1 sw Y   y xY w)Nr   r4   rY  )
r   rq  rr  r+   r;   r<   rP  r^  r=   r>   )r   r   rV   s      r%   rp  zTestMove.setUp
  s    ||~||~T\\8<T\\8<$--& 	!GGG	 	 	s   !B<<Cc                 p   t        |d      5 }|j                         }d d d        t        j                  ||       t        |d      5 }| j	                  |j                                d d d        | j                  t        j                  j                  |             y # 1 sw Y   xY w# 1 sw Y   DxY wNrZ   )	r=   r\   r   mover   r   r+   r;   r   )r   rx   ry   real_dstrV   contentss         r%   _check_move_filezTestMove._check_move_file
  s    #t_ 	 vvxH	 C(D! 	1QXqvvx0	1,-	  	 	1 	1s   B !B, B),B5c                 $   t        t        j                  |            }t        j                  ||       | j                  |t        t        j                  |                   | j                  t        j                  j                  |             y r*   )	r`   r+   ra   r   r  r   r   r;   r   )r   rx   ry   r  r  s        r%   _check_move_dirzTestMove._check_move_dir
  s[    "**S/*C6"**X*>#?@,-r'   c                 f    | j                  | j                  | j                  | j                         y r*   )r  rP  r^  rS  s    r%   test_move_filezTestMove.test_move_file
  s     dmmT]]DMMJr'   c                 f    | j                  | j                  | j                  | j                         y r*   )r  rP  rr  r^  rS  s    r%   test_move_file_to_dirzTestMove.test_move_file_to_dir"
  s     dmmT\\4==Ir'   c                 |    t        | j                        }| j                  || j                  | j                         y r*   )r   rP  r  rr  r^  )r   rx   s     r%   "test_move_file_to_dir_pathlike_srcz+TestMove.test_move_file_to_dir_pathlike_src&
  s*    t}}%c4<<?r'   c                 |    t        | j                        }| j                  | j                  || j                         y r*   )r   rr  r  rP  r^  r   ry   s     r%   "test_move_file_to_dir_pathlike_dstz+TestMove.test_move_file_to_dir_pathlike_dst+
  s*    t||$dmmS$--@r'   c                 $    | j                          y r*   )r  rS  s    r%   test_move_file_other_fsz TestMove.test_move_file_other_fs0
  s     	r'   c                 $    | j                          y r*   )r  rS  s    r%   test_move_file_to_dir_other_fsz'TestMove.test_move_file_to_dir_other_fs5
  s     	""$r'   c                     t        j                  | j                               }	 | j                  | j                  ||       t        j                  |       y # t        j                  |       w xY wr@  )rq   r   r   r  rq  r   r   r   rr  s     r%   test_move_dirzTestMove.test_move_dir:
  sN    //dlln5	&  w@W%IW%s   A A0c                 $    | j                          y r*   )r  rS  s    r%   test_move_dir_other_fszTestMove.test_move_dir_other_fsB
  s     	r'   c           
          | j                  | j                  | j                  t        j                  j                  | j                  t        j                  j                  | j                                     y r*   )r  rq  rr  r+   r;   r<   r  rS  s    r%   test_move_dir_to_dirzTestMove.test_move_dir_to_dirG
  sF    T\\4<<GGLLrww'7'7'EF	Hr'   c                 $    | j                          y r*   )r  rS  s    r%   test_move_dir_to_dir_other_fsz&TestMove.test_move_dir_to_dir_other_fsL
  s     	!!#r'   c           
      &   | j                  | j                  t        j                  j                  z   | j
                  t        j                  j                  | j
                  t        j                  j                  | j                                     y r*   )r  rq  r+   r;   seprr  r<   r  rS  s    r%   test_move_dir_sep_to_dirz!TestMove.test_move_dir_sep_to_dirQ
  sS    T\\BGGKK7GGLLrww'7'7'EF	Hr'   zrequires os.path.altsepc           
      &   | j                  | j                  t        j                  j                  z   | j
                  t        j                  j                  | j
                  t        j                  j                  | j                                     y r*   )r  rq  r+   r;   altseprr  r<   r  rS  s    r%   test_move_dir_altsep_to_dirz$TestMove.test_move_dir_altsep_to_dirU
  sS    T\\BGGNN:DLLGGLLrww'7'7'EF	Hr'   c                     t        | j                  d      5  	 d d d        | j                  t        j                  t        j
                  | j                  | j                         y # 1 sw Y   NxY w)Nr4   )r=   r^  r   r   r   r  rP  rr  rS  s    r%   "test_existing_file_inside_dest_dirz+TestMove.test_existing_file_inside_dest_dirZ
  sL    $--& 		&,,T]]DLLQ	 	s   A&&A/c                     t         j                  j                  | j                  d      }| j	                  t
        j                  t
        j                  | j                  |       y Nr  )r+   r;   r<   rq  r   r   r   r  r  s     r%   test_dont_move_dir_in_itselfz%TestMove.test_dont_move_dir_in_itself`
  s:    ggll4<</&,,T\\3Gr'   c           	         t        j                  t               	 dD ]{  \  }}t         j                  j	                  t        |      }t         j                  j	                  t        |      }| j                  t        j                  ||      d|d|d       } 	 t        j                  t               y # t        j                  t               w xY w)N))srcdirzsrcdir/dest)_destinsrc() wrongly concluded that dst (z) is not in src ()r  )
r+   r   r   r;   r<   r   r   
_destinsrcr   r   rH  s      r%   test_destinsrc_false_negativez&TestMove.test_destinsrc_false_negativee
  s    
	%7 ISggll63/ggll63/ 1 1#s ;>A3"H   II V$IV$   B B6 6Cc           	         t        j                  t               	 dD ]{  \  }}t         j                  j	                  t        |      }t         j                  j	                  t        |      }| j                  t        j                  ||      d|d|d       } 	 t        j                  t               y # t        j                  t               w xY w)N))r  zsrc/dest)r  z
srcdir.newr  z) is in src (r  r  )
r+   r   r   r;   r<   r   r   r  r   r   rH  s      r%   test_destinsrc_false_positivez&TestMove.test_destinsrc_false_positiveq
  s    
	%N DSggll63/ggll63/  !2!23!<9<c!C ! DD V$IV$r  c                    t         j                  j                  | j                  d      }t        j                  | j
                  |       t        j                  || j                         | j                  t         j                  j                  | j                               | j                  t         j                  j                  | j
                  | j                               y r
  )r+   r;   r<   rq  r   rP  r   r  r^  r   rc   samefiler  s     r%   test_move_file_symlinkzTestMove.test_move_file_symlink}
  s     ggll4<</


4==#&C't}}56((FGr'   c                    d}t         j                  j                  | j                  |      }t        j                  | j
                  |       t        j                  || j                         t         j                  j                  | j                  |      }| j                  t         j                  j                  |             | j                  t         j                  j                  | j
                  |             y r
  )r+   r;   r<   rq  r   rP  r   r  rr  r   rc   r  )r   r   ry   
final_links       r%   test_move_file_symlink_to_dirz&TestMove.test_move_file_symlink_to_dir
  s     ggll4<<2


4==#&C&WW\\$,,9
z23((
CDr'   c                 L   t         j                  j                  | j                  d      }t         j                  j                  | j                  d      }t        j                  ||       t         j                  j                  | j
                  d      }t        j                  ||       | j                  t         j                  j                  |             | j                  t         j                  j                  |      t         j                  j                  |             y Nr  r  r  )r+   r;   r<   rq  r   rr  r   r  r   rc   r   realpathr   rx   ry   r  s       r%   test_move_dangling_symlinkz#TestMove.test_move_dangling_symlink
  s     ggll4<</ggll4<</


377<<f5C"x01))#.0@0@0JKr'   c                 <   t         j                  j                  | j                  d      }t         j                  j                  | j                  d      }t        j                  |       t        j
                  ||       t         j                  j                  | j                  d      }t        j                  ||       | j                  t         j                  j                  |             | j                  t         j                  j                  ||             y r  )r+   r;   r<   rq  r   r   rr  r   r  r   rc   r  r  s       r%   test_move_dir_symlinkzTestMove.test_move_dir_symlink
  s     ggll4<</ggll4<</



377<<f5C"x01((h78r'   c           	         t        j                  | j                  | j                        }| j	                  |t
        j                  j                  | j                  t
        j                  j                  | j                                     y r*   )	r   r  rP  rr  r   r+   r;   r<   r  rv  s     r%   test_move_return_valuezTestMove.test_move_return_value
  sT    [[5T\\277+;+;DMM+JK	Mr'   c                    t        j                  | j                  t        j                  j                  | j                  d            }| j                  |t        j                  j                  | j                  d             y r
  )r   r  rP  r+   r;   r<   rr  r   rv  s     r%    test_move_as_rename_return_valuez)TestMove.test_move_as_rename_return_value
  sL    [[T\\5(IJRWW\\$,,>?r'   c                     g fd}t        j                  | j                  | j                  |       | j	                  t              d       y )Nc                 ,    j                  | |f       y r*   r   rx   ry   moveds     r%   r  z7TestMove.test_move_file_special_function.<locals>._copy
      LL#s$r'   r  r   )r   r  rP  rr  r   r   r   r  r*  s     @r%   test_move_file_special_functionz(TestMove.test_move_file_special_function
  s9    	%DMM4<<uEUQ'r'   c                    g fd}t        j                  t        j                  j	                  | j
                  d             t        j                  t        j                  j	                  | j
                  d             t        j                  | j
                  | j                  |       | j                  t              d       y )Nc                 ,    j                  | |f       y r*   r   r)  s     r%   r  z6TestMove.test_move_dir_special_function.<locals>._copy
  r+  r'   childchild1r  r   )r   r   r+   r;   r<   rq  r   r  rr  r   r   r,  s     @r%   test_move_dir_special_functionz'TestMove.test_move_dir_special_function
  s{    	%##BGGLLw$GH##BGGLLx$HIDLL$,,eDUQ'r'   c                 Z   | j                         | _        t        j                  j	                  t        j                  j                  | j                        t        j                  j                  | j                        j                               }| j                  | j                  |       	 t        j                  | j                  |       | j                  t        j                  j                  |             t        j                  |       y # t        j                  |       w xY wr*   )r   rq  r+   r;   r<   rm  r  upperr  r   r  r   rb   r   r  s     r%   test_move_dir_caseinsensitivez&TestMove.test_move_dir_caseinsensitive
  s     ||~'',,-  .4468 	DLL'2	KKg.OOBGGMM'23HHWBHHWs   /AD D*c                    t         j                  j                  | j                  d      }t         j                  j                  | j                  d      }t        j
                  | j                  |d       t        j                  ||       | j                  t         j                  j                  |             | j                  t         j                  j                  | j                  |             | j                  t         j                  j                  |             t        j
                  | j                  |d       | j                  t        j                        5  t        j                  ||       d d d        | j                  t         j                  j                  | j                  |             | j                  t         j                  j                  |             y # 1 sw Y   qxY w)N	linktodirTr  )r+   r;   r<   rq  rr  r   r   r  r   rc   r  r   r   r   r   )r   ry   rx   r  s       r%   "_test_move_symlink_to_dir_into_dirz+TestMove._test_move_symlink_to_dir_into_dir
  s.   ggll4<<577<<k:


4<<$?Cx01((x@A,- 	

4<<$?v||, 	"KKS!	"((x@As+,	" 	"s   #G**G3c                 :    | j                  | j                         y r*   )r8  rr  rS  s    r%   !test_move_symlink_to_dir_into_dirz*TestMove.test_move_symlink_to_dir_into_dir
  s    //=r'   c                     t         j                  j                  | j                  d      }t        j                  | j
                  |d       | j                  |       y )NotherlinktodirTr  )r+   r;   r<   rq  r   rr  r8  r  s     r%   ,test_move_symlink_to_dir_into_symlink_to_dirz5TestMove.test_move_symlink_to_dir_into_symlink_to_dir
  s=    ggll4<<)9:


4<<$?//4r'   r}  SF_IMMUTABLE	UF_OPAQUEzrequires lchflagsc                     	 t        j                  t               t        j                  t        t        j
                         | j                  t        t        j                  t        t               | j                  t        t        j                         v        t        j                  t        t        j                         t        j                  t         j                   j#                  t        d             t        j                  t        t        j
                         | j                  t        t        j                  t        t               | j                  t        t        j                         v        t         j                   j%                  t              rAt        j                  t        t        j                         t        j&                  t               t         j                   j%                  t              rBt        j                  t        t        j                         t        j&                  t               y y # t         j                   j%                  t              rAt        j                  t        t        j                         t        j&                  t               t         j                   j%                  t              rBt        j                  t        t        j                         t        j&                  t               w w xY w)Nr0  )r+   r   
TESTFN_SRCr}  r   r>  r   r  r   r  
TESTFN_DSTr   ra   r?  r   r   r;   r<   r   r   rS  s    r%   test_move_dir_permission_deniedz(TestMove.test_move_dir_permission_denied
  s   	-HHZ KK
D$5$56 ov{{J
SZ2::<78 KK
DNN3''Z(IJKK
D$5$56 ov{{J
SZ2::<78ww~~j)J7  ,ww~~j)J7  , * ww~~j)J7  ,ww~~j)J7  , *s   E6I CLN).r   r   r   rp  r  r  r  r  r  r  r2   r  r  r  r  r  r   r  r_  r`  r+   r;   r  r  r  r  r  r  r   r^  r  r  r   r"  r$  r&  r-  r2  r5  r8  r:  r=  rg  rp   r   rC  rF   r'   r%   r  r  
  s7   ..KJ@
A
   % %&  H
 $ $H X)BCH DHRH

%
% ""H  #H ""E  #E ""L  #L ""9  #9M
@ ( ( ( ($ - -" ""> #> ""5 #5
 ''XZ0 8$T>:8$T;7,.-	. (
-r'   r  c                       e Zd Z G d de      Zd Z ej                  ed      d        Z	 ej                  ed      d        Z
 ej                  ed      d        Zy)	TestCopyFilec                   2    e Zd ZdZdZdZddZd Zd Zd Z	y)TestCopyFile.FauxFNc                      || _         || _        y r*   )_raise_in_exit_suppress_at_exit)r   raise_in_exitsuppress_at_exits      r%   __init__zTestCopyFile.Faux.__init__  s    "/D%5D"r'   c                      y)Nr   rF   )r   r#   s     r%   r\   zTestCopyFile.Faux.read  s    r'   c                     d| _         y r  )_enteredrS  s    r%   	__enter__zTestCopyFile.Faux.__enter__  s	     DMr'   c                 j    |||f| _         | j                  rd| _        t        d      | j                  S )NTCannot close)_exited_withrI  _raisedr    rJ  )r   exc_typeexc_valexc_tbs       r%   __exit__zTestCopyFile.Faux.__exit__!  s8     ('6 9D""#n--)))r'   r  )
r   r   r   rP  rT  rU  rM  r\   rQ  rY  rF   r'   r%   FauxrG    s%    	6		!	*r'   rZ  c                     dd}t        j                  t        d|      5  | j                  t              5  t        j
                  dd       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY w)Nc                 &    | dk(  rt        d      J )NsrcfilezCannot open "srcfile"r-  )r   rA   s     r%   _openz4TestCopyFile.test_w_source_open_fails.<locals>._open)  s    9$5661r'   r=   r]  destfiler[   )r   r3  r   r   r    rR  )r   r^  s     r%   test_w_source_open_failsz%TestCopyFile.test_w_source_open_fails(  sf    	
 vvu5 	7""7+ 7	:67	7 	77 7	7 	7s"   A*AA*A'	#A**A3zskipped on macOSc                    | j                         dfd	}t        j                  t        d|      5  t        j                  dd       d d d        | j                  j                         | j                  j                  d   t        u        | j                  j                  d   j                  d       y # 1 sw Y   rxY w)	Nc                 6    | dk(  rS | dk(  rt        d      J )Nr]  r_  Cannot open "destfile"r-  )r   rA   r]  s     r%   r^  z2TestCopyFile.test_w_dest_open_fails.<locals>._open6  s)    9$:%6771r'   r=   r]  r_  r   r   )rd  r`  )rZ  r   r3  r   rR  r   rP  rT  r    r   r#   )r   r^  r]  s     @r%   test_w_dest_open_failsz#TestCopyFile.test_w_dest_open_fails2  s    ))+	 vvu5 	3OOIz2	3((),,Q/7:;--a0554	6		3 	3s   B;;Cc                     | j                         | j                  d      d	fd	}t        j                  t        d|      5  t        j                  dd       d d d        | j                  j                         | j                  j                         | j                  j                         | j                  j                  d   t        u        | j                  j                  d   j                  d       y # 1 sw Y   xY w)
NTc                 $    | dk(  rS | dk(  rS J Nr]  r_  rF   r   rA   r_  r]  s     r%   r^  z3TestCopyFile.test_w_dest_close_fails.<locals>._openI  "    9$:%1r'   r=   r]  r_  r   r   )rS  r`  )rZ  r   r3  r   rR  r   rP  rU  rT  r    r   r#   r   r^  r_  r]  s     @@r%   test_w_dest_close_failsz$TestCopyFile.test_w_dest_close_failsD  s    ))+99T?	 vvu5 	3OOIz2	3(()))*((),,Q/7:;--a055*	,	3 	3s   DDc                 P   | j                  d      | j                         dfd	}t        j                  t        d|      5  | j	                  t
              5  t        j                  dd       d d d        d d d        | j                  j                         | j                  j                         | j                  j                         | j                  j                  d   d u        | j                  j                         y # 1 sw Y   xY w# 1 sw Y   xY w)NTc                 $    | dk(  rS | dk(  rS J rh  rF   ri  s     r%   r^  z5TestCopyFile.test_w_source_close_fails.<locals>._open_  rj  r'   r=   r]  r_  r   r`  )rZ  r   r3  r   r   r    rR  r   rP  r   rU  rT  rk  s     @@r%   test_w_source_close_failsz&TestCopyFile.test_w_source_close_failsY  s     ))D/99;	 vvu5 	7""7+ 7	:67	7 	(()))*))*,,Q/478(7 7	7 	7s$   DD3DD	DD%N)r   r   r   objectrZ  ra  r_  ra  rh  re  rl  ro  rF   r'   r%   rE  rE    sy    *v *$7 X__U./6 06" X__U./, 0,( X__U./) 0)r'   rE  c                       e Zd ZdZed        Zed        Zd Zej                  d        Z
d Zd Zd Zd	 Z ej                   ej$                  d
k7  d      d        Zy)TestCopyFileObji    c                 8    t        t        | j                         y r*   )rX   r   FILESIZEclss    r%   
setUpClasszTestCopyFileObj.setUpClasss  s    -r'   c                 h    t        j                  t               t        j                  t               y r*   )r   ru   r   r  ru  s    r%   tearDownClasszTestCopyFileObj.tearDownClassw  s     !r'   c                 6    t        j                  t               y r*   r   ru   r  rS  s    r%   tearDownzTestCopyFileObj.tearDown|      !r'   c              #      K   t        t        d      5 }t        t        d      5 }||f d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wwNrZ   r4   r=   r   r  rH  s      r%   	get_fileszTestCopyFileObj.get_files  V     &$ 	!3gt$ !Cj !	! 	!! !	! 	!/   AA<A	AA	AAAc                     t        |d      5 }t        |d      5 }| j                  |j                         |j                                d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr  )r=   r   r\   )r   rx   ry   fsrcfdsts        r%   assert_files_eqzTestCopyFileObj.assert_files_eq  sc    #t_ 	;c4 ;D  diik:;	; 	;; ;	; 	;s"   A&/A	A&A#	A&&A/c                     | j                         5 \  }}t        j                  ||       d d d        | j                  t        t
               y # 1 sw Y   $xY wr*   )r  r   copyfileobjr  r   r  rH  s      r%   test_contentzTestCopyFileObj.test_content  sG    ^^ 	)#ssC(	)VW-	) 	)s   AAc                     | j                         5 \  }}t        j                  ||       |j                  rJ |j                  rJ 	 d d d        y # 1 sw Y   y xY wr*   )r  r   r  closedrH  s      r%   test_file_not_closedz$TestCopyFileObj.test_file_not_closed  sQ    ^^ 	"#ssC(zz!>zz!>z	" 	" 	"s   6AAc                 (   | j                         5 \  }}t        j                  ||       | j                  |j	                         | j
                         | j                  |j	                         | j
                         d d d        y # 1 sw Y   y xY wr*   )r  r   r  r   tellrt  rH  s      r%   test_file_offsetz TestCopyFileObj.test_file_offset  sk    ^^ 	8#ssC(SXXZ7SXXZ7	8 	8 	8s   A.BBr  zWindows onlyc                    t         j                  j                  d      5 }t        j                  t
        t               d d d        j                  sJ | j                  |j                  d   d   d       t        j                  t        j                         d      5 }|j                  d       d d d        j                  }| j!                  t"        j$                  |       t         j                  j                  d      5 }t        j                  |t               d d d        | j                  |j                  d   d   d       t        j                  t        j                         d      5 }	 d d d        |j                  }| j!                  t"        j$                  |       t         j                  j                  d      5 }t        j                  |t               d d d        |j                  rJ | j'                  |t               y # 1 sw Y   xY w# 1 sw Y   mxY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   axY w)	Nzshutil._copyfileobj_readintor   ro   i   Frl   s   foor   )r_  r  r  r   rR  r   r  calledr   	call_argsrq   rr   r+   rs   r>   rg   r   r   ru   r  )r   mrV   r  s       r%   test_win_implzTestCopyFileObj.test_win_impl  s    ]]  !?@ 	-AOOFG,	-xxx 	Q*O< ((RYY[G 	1GGFO		((%0]]  !?@ 	,AOOE7+	,Q*A. ((RYY[G 	1		((%0]]  !?@ 	,AOOE7+	,88|UG,3	- 	-	 		, 	,
	 		, 	,s;   H HH*3H7IHH'*H47I IN)r   r   r   rt  classmethodrw  ry  r|  
contextlibcontextmanagerr  r  r  r  r  r_  ra  r+   rg   r  rF   r'   r%   rr  rr  p  s    H. . " "" ! !
;
.
"8 X__RWW_n5- 6-r'   rr  c                       e Zd ZdZdZdZdZed        Zed        Z	d Z
ej                  d        Zd	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zy)_ZeroCopyFileTestz#Tests common to all zero-copy APIs.i   r'   r   c                     t        t        | j                         t        t        d      5 }|j	                         | _        t        | j
                        | j                  k(  sJ 	 d d d        y # 1 sw Y   y xY wr  )rX   r   rt  r=   r\   FILEDATAr   )rv  rV   s     r%   rw  z_ZeroCopyFileTest.setUpClass  sY    -&$ 	51668CLs||$444	5 	5 	5s   :A//A8c                 6    t        j                  t               y r*   )r   ru   r   ru  s    r%   ry  z_ZeroCopyFileTest.tearDownClass  s     r'   c                 6    t        j                  t               y r*   r{  rS  s    r%   r|  z_ZeroCopyFileTest.tearDown  r}  r'   c              #      K   t        t        d      5 }t        t        d      5 }||f d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wwr  r  rH  s      r%   r  z_ZeroCopyFileTest.get_files  r  r  c                     t        d      )Nzmust be implemented in subclass)r=  )r   r#   r$   s      r%   zerocopy_funz_ZeroCopyFileTest.zerocopy_fun  s    !"CDDr'   c                     | j                          | j                          | j                          | j                          y r*   )r|  ry  rw  rp  rS  s    r%   resetz_ZeroCopyFileTest.reset  s*    

r'   c                    | j                         5 \  }}| j                  ||       d d d        | j                  t        t        d      | j
                         | j                         5 \  }}t        j                  j                  d      5 }t        j                  t        t               d d d        j                  rJ 	 d d d        y # 1 sw Y   xY w# 1 sw Y   -xY w# 1 sw Y   y xY w)NTr@   zshutil.copyfileobj)r  r  r   r]   r  r  r_  r  r  r   rR  r   r  )r   rx   ry   r  s       r%   test_regular_copyz#_ZeroCopyFileTest.test_regular_copy  s    ^^ 	(#sc3'	(748$--H^^ 	 #s$$%9: 1a01xx<x	  	 		( 	(
1 1	  	 s/   C*#C$C,C$CC!	C$$C-c                 d   | j                  | j                         | j                         5 \  }}| j                  t        t
        f      5  | j                  ||       d d d        d d d        | j                  t        t        d      | j                         y # 1 sw Y   =xY w# 1 sw Y   AxY w)NTr  )r   r  r  r   r    r   r  r   r]   r   r  rH  s      r%   test_same_filez _ZeroCopyFileTest.test_same_file  s    

#^^ 	,#s""G->#?@ ,!!#s+,	, 	6$7G, ,	, 	,s#   B&BB&B#	B&&B/c                     t        j                  t        j                               }| j	                  t
              5 }t        j                  |d       d d d        | j                  j                  j                  |       y # 1 sw Y   0xY w)Nr   new)rq   r   r+   rs   r   r   r   rR  r   r   r   )r   rg   r   s      r%   test_non_existent_srcz'_ZeroCopyFileTest.test_non_existent_src  sd    299;/01 	)ROOD%(	)..5	) 	)s   BBc                    t         dz   t         dz   | j                  fd       | j                  fd       t        d      5  	 d d d        t        d      5 }t        d      5 }| j                  ||       d d d        d d d        | j	                  t        d      d	       y # 1 sw Y   cxY w# 1 sw Y   ;xY w# 1 sw Y   ?xY w)
Nrx   ry   c                  .    t        j                         S r*   r   ru   )rv   s   r%   r  z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>      	 0 0 9 r'   c                  .    t        j                         S r*   r  )rw   s   r%   r  z3_ZeroCopyFileTest.test_empty_file.<locals>.<lambda>  r  r'   r4   rZ   Tr  r'   )r   r   r=   r  r   r]   )r   rx   ry   rw   rv   s      @@r%   test_empty_filez!_ZeroCopyFileTest.test_empty_file  s    5.5.9:9:'4  		 '4  	,Cgt$ ,!!#s+,	, 	748#>	 	, ,	, 	,s0   	B-C,B9?C-B69C	>CCc                     t         j                  j                  | j                  t              5  | j                  t        t        j                  t        t               d d d        y # 1 sw Y   y xY w)Nr   )
r_  r  r  
PATCHPOINTZeroDivisionErrorr   r   rR  r   r  rS  s    r%   test_unhandled_exceptionz*_ZeroCopyFileTest.test_unhandled_exception  sY    ]]  -> ! @ 	@/$oovw@	@ 	@ 	@s   /A((A1c                 |   t         j                  j                  | j                  t	        t
        j                  d            5  | j                         5 \  }}| j                  t              5  | j                  ||       d d d        d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   y xY wNyor   )r_  r  r  r  r    r"   EINVALr  r   r   r  rH  s      r%   test_exception_on_first_callz._ZeroCopyFileTest.test_exception_on_first_call  s     ]]  -4U\\4-H ! J 	0! 0Zc3&&'89 0%%c3/00	0 	00 00 0	0 	0s<   B2B&.BB&	B2B#B&&B/	+B22B;c                 H   t         j                  j                  | j                  t	        t
        j                  d            5  | j                         5 \  }}| j                  t        | j                  ||       d d d        d d d        y # 1 sw Y   xY w# 1 sw Y   y xY wr  )
r_  r  r  r  r    r"   ENOSPCr  r   r  rH  s      r%   test_filesystem_fullz&_ZeroCopyFileTest.test_filesystem_full  s     ]]  -4U\\4-H ! J 	H! HZc3!!'4+<+<c3GH	H 	HH H	H 	Hs$   B&B;BB	BB!N)r   r   r   __doc__rt  r  r  r  rw  ry  r|  r  r  r  r  r  r  r  r  r  r  r  r  rF   r'   r%   r  r    s    - HHJ5 5 ! !" ! !
E H6?@0Hr'   r  zos.sendfile() not supportedc                   F    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zy)TestZeroCopySendfileos.sendfilec                 .    t        j                  ||      S r*   )r   _fastcopy_sendfile)r   r  r  s      r%   r  z!TestZeroCopySendfile.zerocopy_fun"  s    ((t44r'   c                    t        j                  | j                        5 }t        t        d      5 }| j                  t              5  | j                  ||       d d d        t        j                  ||       d d d        d d d        | j                  t        t        d      | j                         y # 1 sw Y   [xY w# 1 sw Y   IxY w# 1 sw Y   MxY w)Nr4   Tr  )ioBytesIOr  r=   r  r   r   r  r   r  r   r]   rH  s      r%   test_non_regular_file_srcz.TestZeroCopySendfile.test_non_regular_file_src%  s    ZZ& 	-#gt$ -&&'89 0%%c3/0""3,-	- 	748$--H	0 0- -	- 	-s:   CC B4C 8C4B=9C  C		CCc                    t        t        d      5 }t        j                         5 }| j	                  t
              5  | j                  ||       d d d        t        j                  ||       |j                  d       | j                  |j                         | j                         d d d        d d d        y # 1 sw Y   kxY w# 1 sw Y   xY w# 1 sw Y   y xY w)NrZ   r   )r=   r   r  r  r   r   r  r   r  seekr   r\   r  rH  s      r%   test_non_regular_file_dstz.TestZeroCopySendfile.test_non_regular_file_dst.  s    &$ 	<3 <&&'89 0%%c3/0""3,  T]];<	< 	<0 0< <	< 	<s:   CCB9AC(C9C>CC	
CCc                    fd}g t         j                  t        j                  j	                  dd|      5  | j                         5 \  }}| j                  t              5 }t        j                  ||       d d d        d d d        d d d        sJ | j                  j                  j                  t        j                         y # 1 sw Y   RxY w# 1 sw Y   VxY w# 1 sw Y   ZxY w)Nc                  n    sj                  d         | i |S t        t        j                  d      )Nr  )rd   r    r"   EBADF)r#   r$   r  orig_sendfiles     r%   rk   zDTestZeroCopySendfile.test_exception_on_second_call.<locals>.sendfile8  s3    D!$d5f55ekk400r'   r  T)r  r   )r+   rk   r_  r  r  r  r   r    r   r  r   r   r"   r  )r   rk   rx   ry   r   r  r  s        @@r%   test_exception_on_second_callz2TestZeroCopySendfile.test_exception_on_second_call7  s    	1 ]]  t-5 ! 7 	8! 8Zc3&&w/ 82--c3788	8
 t++U[[98 88 8	8 	8s;   C'C'C>CC'CCC$	 C''C0c                 h   t         j                  j                  dt              5 }| j	                         5 \  }}t        j                  ||       |j                  sJ 	 d d d        d d d        | j                  t        t        d      | j                         y # 1 sw Y   =xY w# 1 sw Y   AxY w)Nos.fstatr   Tr  )r_  r  r  r    r  r   r  r  r   r]   r  r  r   r  rx   ry   s       r%   test_cant_get_sizez'TestZeroCopySendfile.test_cant_get_sizeI  s     ]]   A 	 Q!  Zc3))#s3xxx 	  	748$--H   	  	 s"   B((B B(B%	!B((B1c                    t         j                  j                         }d|_        t         j                  j	                  d|      5 }| j                         5 \  }}t        j                  ||       |j                  sJ 	 d d d        d d d        | j                  t        t        d      | j                         y # 1 sw Y   =xY w# 1 sw Y   AxY w)Ni  r  r  Tr  )r_  r  Mockst_sizer  r  r   r  r  r   r]   r  r  r   r  r  rx   ry   s        r%   test_small_chunksz&TestZeroCopySendfile.test_small_chunksS  s    
 }}!!# ]]  $ ? 	 1!  Zc3))#s3xxx 	  	748$--H   	  	 s$   C	(B=C	=C	C		Cc                    t         j                  j                         }| j                  dz   |_        t         j                  j                  d|      5 }| j                         5 \  }}t        j                  ||       |j                  sJ 	 d d d        d d d        | j                  t        t        d      | j                         y # 1 sw Y   =xY w# 1 sw Y   AxY w)Ni  @r  r  Tr  )r_  r  r  rt  r  r  r  r   r  r  r   r]   r  r  r  s        r%   test_big_chunkz#TestZeroCopySendfile.test_big_chunk`  s    
 }}!!#}}(9:]]  $ ? 	 1!  Zc3))#s3xxx 	  	748$--H   	  	 s$   C%(C
C
C	CCc                    t         j                  j                  dt              5 }| j	                  t        t
        j                  t        t               |j                  d   d   }| j                  |t        j                  j                  t                     t        j                  t               t!        t        dd       | j#                  t        j                  t        dz          | j	                  t        t
        j                  t        t        dz          |j                  d   d   }| j                  |d	       d d d        y # 1 sw Y   y xY w)
Nr  r   r   r   s   helloTr  3i   )r_  r  r  r  r   r   rR  r   r  r  r   r+   r;   rQ   r   ru   rC   r   )r   r  	blocksizes      r%   test_blocksize_argz'TestZeroCopySendfile.test_blocksize_argm  s    ]]  -> ! @ 	1CD/$oovw@Aq)I Y(?@W%w6OOI,,gm</$oow#GAq)IY0	1 	1 	1s   DE

Ec                    t         j                  sJ 	 t        j                  j	                  | j
                  t        t        j                  d            5 }| j                         5 \  }}| j                  t              5  t        j                  ||       d d d        d d d        |j                  sJ 	 d d d        t         j                  rJ t        j                  j	                  | j
                        5 }t        j                  t        t                |j                  rJ 	 d d d        dt         _        y # 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   xY w# 1 sw Y   9xY w# dt         _        w xY w)Nr  r   T)r   _USE_CP_SENDFILEr_  r  r  r  r    r"   ENOTSOCKr  r   r   r  r  rR  r   r  r  s       r%   test_file2file_not_supportedz1TestZeroCopySendfile.test_file2file_not_supported  s1    &&&&	+$$OO ' = % ?  BC^^% <#s**+<= <11#s;<< xxx  ....$$T__5 $088#|8$ '+F#< << <   $ $ '+F#sm   AE, E(ED<E E7AE, :-E (E, <EEE	EEE,  E)%E, ,E9N)r   r   r   r  r  r  r  r  r  r  r  r  r  rF   r'   r%   r  r    s8    J5I<:$III1$+r'   r  z
macOS onlyc                       e Zd ZdZd Zy)TestZeroCopyMACOSzposix._fcopyfilec                 L    t        j                  ||t        j                        S r*   )r   _fastcopy_fcopyfileposix_COPYFILE_DATArH  s      r%   r  zTestZeroCopyMACOS.zerocopy_fun  s    ))#sE4H4HIIr'   N)r   r   r   r  r  rF   r'   r%   r  r    s    #JJr'   r  c                       e Zd Zd Zd Zd Z ej                   ej                  e
j                  j                               d       ej                   eed      d      d               Z ej                  ej"                  d      d	        Zy
)TestGetTerminalSizec                     t        j                         }| j                  |j                  d       | j                  |j                  d       y)zCheck if get_terminal_size() returns a meaningful value.

        There's no easy portable way to actually check the size of the
        terminal, so let's check if it returns something sensible instead.
        r   N)r   get_terminal_sizerS  columnslines)r   rR   s     r%   test_does_not_crashz'TestGetTerminalSize.test_does_not_crash  s:     '')a0

A.r'   c                    t        j                         5 }d|d<   |d= t        j                         }ddd       | j	                  j
                  d       t        j                         5 }|d= d|d<   t        j                         }ddd       | j	                  |j                  d       y# 1 sw Y   {xY w# 1 sw Y   2xY w)z.Check if environment variables have precedence777COLUMNSLINESNi	  888ix  )r   r  r   r  r   r  r  r   r  rR   s      r%   test_os_environ_firstz)TestGetTerminalSize.test_os_environ_first  s     **, 	."C	NG++-D	. 	s+**, 	.I CL++-D	. 	S)	. 	.	. 	.s   B,*B8,B58Cc                    t        j                         5 }d|d<   d|d<   t        j                         }d d d        | j	                  j
                  d       | j	                  |j                  d       y # 1 sw Y   BxY w)Nr  r  yyyr  r   )r   r  r   r  rS  r  r  r  s      r%   test_bad_environz$TestGetTerminalSize.test_bad_environ  so    **, 	."C	N CL++-D	. 	a0

A.	. 	.s   A55A>z
not on ttyr  zneed os.get_terminal_size()c                    	 t        j                  ddg      j                         j                         }t        d         t        |d         f}t        j                         5 }|d= |d= t        j                         }ddd       | j                  |       y# t        t
        t         j                  f$ r | j                  d       Y w xY w# 1 sw Y   QxY w)	zCheck if stty returns the same results ignoring env

        This test will fail if stdin and stdout are connected to
        different terminals with different sizes. Nevertheless, such
        situations should be pretty rare.
        sttyrR   zstty invocation failedr   r   r  r  N)r   r  r  r   r   r  r  r  r   r   r  r   r  r   )r   rR   r&  r  rs  s        r%   test_stty_matchz#TestGetTerminalSize.test_stty_match  s    	4**FF+;<CCEKKMD QL#d1g,/**, 	0GI--/F	0
 	6* "?--/ 	4MM23	4
	0 	0s   3B %C/CCCzWASI has no /dev/nullc                    t        j                         5 }|d= |d= t        j                  t        dd       5  t        j                  d      }d d d        | j                  j                  d       | j                  |j                  d       t        t        j                  dd	
      5 }t        j                  t        d|      5  t        j                  d      }d d d        d d d        | j                  |j                  d       | j                  |j                  d       d d d        y # 1 sw Y   xY w# 1 sw Y   ^xY w# 1 sw Y   bxY w# 1 sw Y   y xY w)Nr  r  
__stdout__)rW     )fallbackrW  r  r5   r6   r7   )   rV  r  rV  )r   r  r   r3  r   r   r  r   r  r  r=   r+   devnull)r   r  rR   rV   s       r%   test_fallbackz!TestGetTerminalSize.test_fallback  s/   **, 	-GI ""3d; C//BCT\\2.TZZ, bjj#8 CA""3a8C//BC C T\\2.TZZ,!	- 	-
C CC C C C	- 	-sT   "ED.AE*ED:E%A E.D7	3E:E?EE	EEN)r   r   r   r  r  r  r_  r`  r+   isattyr   r  rt   rp   r  ra  r   is_wasir  rF   r'   r%   r  r    s    /*/ X3>>#8#8#:;\JX%8968+8 K+* X__W__&=>- ?-r'   r  c                       e Zd ZdZd Zy)PublicAPITestsz>Ensures that the correct values are exposed in the public API.c                    | j                  t        t        d             g d}t        t        d      st        j                  dk(  r|j                  d       | j                  t        t        j                        t        |             y )N__all__)r  rR  r  r   r6  r;  rn  r  r   r   rZ  	ExecErrorr   r   r   r   r   r	   r   r   r  rV  rI  r  r   statvfsr  rN  )	r   rp   r   r+   rg   rd   r   r  r	  )r   
target_apis     r%   test_module_all_attributez(PublicAPITests.test_module_all_attribute  s]    	23<
 2y!RWW_l+V^^,c*o>r'   N)r   r   r   r  r  rF   r'   r%   r  r    s
    H?r'   r  __main__)F)Wr_  unittest.mockr   rq   r   r   r+   os.pathr"   r0   r  r   rL   rN   r  r  r   r   r   r   r   r   r	   r
   r   r   r   r   rm  warningsr  r  ImportErrorr  r   test.supportr   test.support.os_helperr   r   r   r  rA  rB  rb  r  rh  ri  r   r  r  r  r   r  r  AssertionErrorr  r&   r2   rC   rX   r]   re   r|   SUPPORTS_SENDFILEr   r   TestCaser   rf  r  rk  rM  re  r  r  rE  rr  rp  r  ra  r  r  r  r  r   mainrF   r'   r%   <module>r     s       
  	         	6 6 6 6     " 3 (
3,f_
f_
)
,,
!
!'
*	ll2A%O ==z"#>?  AL	)$
&: 01 	 	}"8,, }"@`28X.. `2DC?x** C?L@	88X.. @	8FM+x** M+`xL(++ xLv	Y &L-x** L-^Y)8$$ Y)xG-h'' G-TaH aHH &&(EFs+,h.?.? s+ Gs+l UL)J)8+<+< J *JL-(++ L-^?X&& ?$ zHMMO Ag  E$  O
  Gs6   *J3  
K +K 3J>=J>KKKK