
    h&                      S r SSKJr  SSKrSSKrSSKrSSKrSSKrSSKrSSK	r	SSK
Jr  SSKJrJrJrJrJrJrJrJrJr  SSKJr  SSKJr  SSKJr  SS	KJr  SS
KJrJ r   SSK!J"r"  SSK#J$r$  SSK%J&r'  \"RP                  " 5       (       + r) " S S\'5      r* " S S\*5      r+ " S S\RX                  \   5      r-\RD                  S:w  a
   " S S5      r. " S S\*5      r/ " S S5      r0 " S S\RX                  \   5      r1 " S S\RX                  \   5      r2\" S5      r3 " S  S!\*5      r4 " S" S#\+5      r5 " S$ S%\*5      r6 " S& S'\'5      r7g)(z1
Test cases covering L{twisted.python.filepath}.
    )annotationsN)pformat)	IOAnyStrCallableDictListOptionalTupleTypeVarUnion)skipIf)verifyObject)NoReturn)filepath)FileModeOtherAnyStr)platform)ERROR_DIRECTORY)SynchronousTestCasec                  "    \ rS rSrSrSS jrSrg)BytesTestCase"   z@
Override default method implementations to support byte paths.
c                L    [         R                  " U 5      R                  S5      $ )z,
Return a temporary path, encoded as bytes.
utf-8)TestCasemktempencodeselfs    ^/root/1688_scrapy/alibaba-scraper/venv/lib/python3.13/site-packages/twisted/test/test_paths.pyr   BytesTestCase.mktemp'   s     t$++G44     N)returnbytes)__name__
__module____qualname____firstlineno____doc__r   __static_attributes__r$   r#   r!   r   r   "   s    5r#   r   c                      \ rS rSrSrSrSrSS jrSS jrSS jr	SS jr
SS	 jrSS
 jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)AbstractFilePathTests.   z)
Tests for L{IFilePath} implementations.
   file 1s   file 2c                    [         R                  R                  [         R                  R                  " U R                  /UQ76 5      nU R
                  R                  U5        U$ N)ospathabspathjoincmnallappend)r    pxs      r!   _mkpathAbstractFilePathTests._mkpath6   s?    GGOOBGGLL6A67r#   c                J    [         R                  " U R                  " U6 5        g r2   )r3   mkdirr<   r    dirnames     r!   subdirAbstractFilePathTests.subdir;   s    
w'(r#   c                4    [        U R                  " U6 S5      $ )Nwb)openr<   r@   s     r!   subfileAbstractFilePathTests.subfile>   s    DLL'*D11r#   c                d   [         R                   " 5       U l        [        R                  R	                  U R                  5       5      =ol        U/U l        [        R                  " U5        U R                  S5        U R                  S5       nUR                  U R                  5        S S S 5        U R                  SS5       nUR                  U R                  5        S S S 5        U R                  S5        U R                  SS5      R                  5         U R                  SS5      R                  5         U R                  SS5      R                  5         [        R                   " U5      U l        [        R                   " S5      U l        g ! , (       d  f       N= f! , (       d  f       N= f)	N   sub1   file1   file2   sub3
   file3.ext1s
   file3.ext2s
   file3.ext3   /)timenowr3   r4   r5   r   r7   r8   r?   rB   rG   write	f1content	f2contentcloser   FilePathroot)r    r7   fs      r!   setUpAbstractFilePathTests.setUpA   s   99;77h5
G\\(#qGGDNN# $\\'8,GGDNN# -GWm,224Wm,224Wm,224%%c*	%%d+	 $#,,s   FF!
F!
F/c                j    U R                  [        [        R                  U R                  5      5        g)z?
Instances of the path type being tested provide L{IFilePath}.
N)
assertTruer   r   	IFilePathr4   r   s    r!   test_verifyObject'AbstractFilePathTests.test_verifyObjectR   s!     	X%7%7CDr#   c                    U R                  U R                  R                  S5      R                  S5      R                  S5      R                  U R                  5      / SQ5        g)zF
Verify that the segments between two paths are correctly identified.
   a   b   cra   rb   rc   N)assertEqualr4   childsegmentsFromr   s    r!   test_segmentsFromPositive/AbstractFilePathTests.test_segmentsFromPositiveX   sJ     	IIOOD!''-33D9FFtyyQ	
r#   c                "   U R                  [        U R                  R                  S5      R                  S5      R                  S5      R                  U R                  R                  S5      R                  S5      R                  S5      5        g)zG
Verify that segmentsFrom notices when the ancestor isn't an ancestor.
ra   rb   rc      d   eN)assertRaises
ValueErrorr4   rf   rg   r   s    r!   test_segmentsFromNegative/AbstractFilePathTests.test_segmentsFromNegativea   sg     	IIOOD!''-33D9FFIIOOD!''-33D9	
r#   c                    U R                   R                  5        Vs/ s H  oR                   PM     nnU R                  [        U5      [        U R                  5      5        gs  snf )zQ
Verify that walking the path gives the same result as the known file
hierarchy.
N)r4   walkre   setr8   )r    foor;   s      r!   	test_walkAbstractFilePathTests.test_walkk   sH    
 "&!12!1#XX!12QTXX/ 3s   A#c                   / nU R                   R                  S5      R                  S5      R                  S5      nUR                   nUn[        R                   R                  U5      nX@R                  R                   :w  aM  UR                  U5        Un[        R                   R                  U5      nX@R                  R                   :w  a  MM  U R                  UR                  5        Vs/ s H  ofR                   PM     snU5        gs  snf )zc
L{FilePath.parents()} should return an iterator of every ancestor of
the L{FilePath} in question.
ra   rb   rc   N)r4   rf   r3   rA   rW   r9   re   parents)r    Lpathobjfullpathlastpaththispathr;   s          r!   test_parents"AbstractFilePathTests.test_parentss   s    
 ))//$'--d399$?<<77??8,))..(HHXHwwx0H ))..( 	'//*;<*;Q&&*;<a@<s   ,D
c                |   U R                   R                  S5      nU R                  UR                  5       S5        U R                  UR	                  5       S5        U R                  UR                  5       S5        U R                  UR                  5       S5        U R                  UR                  5       S/5        g)zu
Verify that a valid subdirectory will show up as a directory, but not as a
file, not as a symlink, and be listable.
rJ   zThis directory does exist.zIt's a directory.rL   N)
r4   rf   r\   existsisdirassertFalseisfileislinkre   listdir)r    sub1s     r!   test_validSubdir&AbstractFilePathTests.test_validSubdir   s    
 yyw''CD

&9:(;<(;<(4r#   c                z    U R                   R                  S5      nU R                  UR                  5       S5        g)zD
Verify that a subdirectory that doesn't exist is reported as such.
   sub2zThis directory does not exist.N)r4   rf   r   r   )r    sub2s     r!   test_invalidSubdir(AbstractFilePathTests.test_invalidSubdir   s-     yyw'(HIr#   c                   U R                   R                  S5      nUR                  5        nU R                  UR	                  5       U R
                  5        SSS5        U R                   R                  S5      R                  S5      nUR                  5        nU R                  UR	                  5       U R                  5        SSS5        g! , (       d  f       N|= f! , (       d  f       g= f)z6
Make sure that we can read existent non-empty files.
rK   NrJ   rL   )r4   rf   rF   re   readrS   rT   )r    f1rX   f2s       r!   test_validFiles%AbstractFilePathTests.test_validFiles   s     YY__X&WWY!QVVXt~~6 YY__W%++H5WWY!QVVXt~~6 Y Y Ys   +C+C
C
C,c                    U R                   R                  / SQ5      nU R                   R                  S5      R                  S5      R                  S5      nU R                  X5        g)zn
C{fp.descendant([a, b, c])} returns the same L{FilePath} as is returned
by C{fp.child(a).child(b).child(c)}.
rd   ra   rb   rc   N)r4   
descendantrf   re   )r    multiplesingles      r!   test_multipleChildSegments0AbstractFilePathTests.test_multipleChildSegments   sO    
 99''(:;&,,T288>*r#   c                L   U R                   R                  S5      nU R                   R                  S5      nU R                   R                  S5      n0 nSXA'   SXB'   U R                  XA   S5        U R                  [        UR	                  5       5      U/5        U R                  [        UR	                  5       5      S   U5        U R                  [        UR	                  5       5      S   U5        SXC'   U R                  XC   S5        U R                  [        U5      S5        g)	z;
Verify that path instances are usable as dictionary keys.
rK   rL         r         N)r4   rf   re   listkeysassertIsassertIsNotlen)r    r   f1primer   dictoids        r!   test_dictionaryKeys)AbstractFilePathTests.test_dictionaryKeys   s     YY__X&))//(+YY__X&a(glln-t4d7<<>*1-r2glln-a0':a(Wq)r#   c                    U R                   R                  S5      nUS0nSX!R                   '   U R                  [        U5      S5        g)zm
Verify that path instances are usable as dictionary keys which do not clash
with their string counterparts.
rK   hellogoodbyer   N)r4   rf   re   r   )r    r   r   s      r!   test_dictionaryKeyWithString2AbstractFilePathTests.test_dictionaryKeyWithString   s?    
 YY__X&FH']$Wq)r#   c                    U R                  [        R                  U R                  R	                  S5      R
                  5        g)zU
Verify that children raises the appropriate exception for non-existent
directories.
s   not realNrm   r   UnlistableErrorr4   rf   childrenr   s    r!   test_childrenNonexistentError3AbstractFilePathTests.test_childrenNonexistentError   s0    
 	$$diiook&B&K&K	
r#   c                    U R                  [        R                  U R                  R	                  S5      R
                  5        g)zm
Verify that listdir raises the appropriate exception for attempting to list
a file rather than a directory.
rK   Nr   r   s    r!   test_childrenNotDirectoryError4AbstractFilePathTests.test_childrenNotDirectoryError   s-    
 	(22DIIOOH4M4V4VWr#   c                n   U R                   U R                   R                  S5      4 H  nU R                  [        UR	                  5       5      [
        5        U R                  [        UR                  5       5      [
        5        U R                  [        UR                  5       5      [
        5        M     g)zy
Verify that all times returned from the various new time functions are ints
(and hopefully therefore 'high precision').
rK   N)r4   rf   re   typegetAccessTimefloatgetModificationTimegetStatusChangeTimer    r:   s     r!   test_newTimesAreFloats,AbstractFilePathTests.test_newTimesAreFloats   s|    
 DIIOOH55AT!//"34e<T!"7"7"9:EBT!"7"7"9:EB 6r#   c                n   U R                   U R                   R                  S5      4 H  nU R                  [        UR	                  5       5      [
        5        U R                  [        UR                  5       5      [
        5        U R                  [        UR                  5       5      [
        5        M     g)za
Verify that all times returned from the various time functions are
integers, for compatibility.
rK   N)r4   rf   re   r   getatimeintgetmtimegetctimer   s     r!   test_oldTimesAreInts*AbstractFilePathTests.test_oldTimesAreInts   su    
 DIIOOH55AT!**,/5T!**,/5T!**,/5 6r#   )r8   r7   rQ   r4   rW   N)r:   r&   r%   r&   )rA   r&   r%   None)rA   r&   r%   zio.BufferedWriterr%   r   )r'   r(   r)   r*   r+   rS   rT   r<   rB   rG   rY   r^   rh   ro   ru   r~   r   r   r   r   r   r   r   r   r   r   r,   r$   r#   r!   r.   r.   .   sw     II
)2,"E

0A 
5J	7+*$*
XC6r#   r.   c                  "    \ rS rSrSrSS jrSrg)FakeWindowsPath   zN
A test version of FilePath which overrides listdir to raise L{WindowsError}.
c                :    [        SSU R                  [        5      e)z
@raise WindowsError: always.
Nz0A directory's validness was called into question)OSErrorr4   r   r   s    r!   r   FakeWindowsPath.listdir   s!     >II	
 	
r#   r$   N)r%   zList[AnyStr])r'   r(   r)   r*   r+   r   r,   r$   r#   r!   r   r      s    
r#   r   win32c                      \ rS rSrSrg)WindowsErrori  r$   N)r'   r(   r)   r*   r,   r$   r#   r!   r   r     s    r#   r   c                  v    \ rS rSrSr\" \R                  " 5       (       + S5      S	S j5       rS	S jr	S	S jr
Srg)
ListingCompatibilityTestsi  zM
These tests verify compatibility with legacy behavior of directory listing.
zOnly relevant on on Windows.c                    [        U R                  5       5      nU R                  [        R                  UR
                  5        U R                  [        UR
                  5        g)zV
Verify that when a WindowsError is raised from listdir, catching
WindowsError works.
N)r   r   rm   r   r   r   r   )r    fwps     r!   test_windowsErrorExcept1ListingCompatibilityTests.test_windowsErrorExcept  sB     dkkm,(22CLLA,5r#   c                    [         R                  " U R                  5       5      nU R                  [        UR
                  5        g)zZ
Verify that in the normal case where a directory does not exist, we will
get an OSError.
N)r   rV   r   rm   r   r   r    fps     r!   test_alwaysCatchOSError1ListingCompatibilityTests.test_alwaysCatchOSError  s.    
 t{{}-'2;;/r#   c                   [         R                  " U R                  5       5      nU R                  [        UR
                  5      n[        UR                  R                  5       5      nUR                  S5        [        UR                  R                  R                  5       5      nUR                  5         UR                  5         U R                  X45        g)zn
Verify that the Unlistable exception raised will preserve the attributes of
the previously-raised exception.
originalExceptionN)r   rV   r   rm   r   r   r   __dict__r   remover   sortre   )r    r   osed1d2s        r!   test_keepOriginalAttributes5ListingCompatibilityTests.test_keepOriginalAttributes"  s    
 t{{}-5#,,##%&
		%&#''005578
	
	 r#   r$   Nr   )r'   r(   r)   r*   r+   r   r   	isWindowsr   r   r   r,   r$   r#   r!   r   r     s:     ""$$&DE6 F60!r#   r   c                  R    \ rS rSrSrSrSSS jjrSS jrSS jrSS jr	SS jr
S	rg
)ExplodingFilei1  z
A C{file}-alike which raises exceptions from its I/O methods and keeps track
of whether it has been closed.

@ivar closed: A C{bool} which is C{False} until C{close} is called, then it
    is C{True}.
Fc                    [        5       ez 
@raise IOError: Always raised.
r   )r    ns     r!   r   ExplodingFile.read<       ir#   c                    [        5       er   r   )r    whats     r!   rR   ExplodingFile.writeB  r   r#   c                    SU l         g)z&
Mark the file as having been closed.
TNclosedr   s    r!   rU   ExplodingFile.closeH  s     r#   c                    U $ r2   r$   r   s    r!   	__enter__ExplodingFile.__enter__N  s    r#   c                $    U R                  5         g r2   )rU   )r    exc_type	exc_value	tracebacks       r!   __exit__ExplodingFile.__exit__Q  s    

r#   r   N)r   )r   r   r%   r   )r   r&   r%   r   r   )r%   r   )r   objectr   r   r   r   r%   r   )r'   r(   r)   r*   r+   r   r   rR   rU   r   r   r,   r$   r#   r!   r   r   1  s'     Fr#   r   c                  n    \ rS rSrSr  S	       S
S jjrSSS jjr  SS jr S     SS jjrSr	g)TrackingFilePathiU  a7  
A subclass of L{filepath.FilePath} which maintains a list of all other paths
created by clonePath.

@ivar trackingList: A list of all paths created by this path via
    C{clonePath} (which also includes paths created by methods like
    C{parent}, C{sibling}, C{child}, etc (and all paths subsequently created
    by those paths, etc).

@type trackingList: C{list} of L{TrackingFilePath}

@ivar openedFiles: A list of all file objects opened by this
    L{TrackingFilePath} or any other L{TrackingFilePath} in C{trackingList}.

@type openedFiles: C{list} of C{file}
Nc                j    [         R                  R                  XU5        Uc  / nUU l        / U l        g r2   )r   rV   __init__trackingListopenedFiles)r    r4   alwaysCreater  s       r!   r  TrackingFilePath.__init__g  s<     	""4|<L  	 -/r#   c                z    [         R                  R                  X5      nU R                  R	                  U5        U$ )z9
Override 'open' to track all files opened by this path.
)r   rV   rF   r  r9   r    moderX   s      r!   rF   TrackingFilePath.openw  s3     ""4."r#   c                j    U R                    Vs/ s H  oR                  (       d  M  UPM     sn$ s  snf )z
Return a list of all L{TrackingFilePath}s associated with this
L{TrackingFilePath} that have had their C{open()} method called.
)r  r  )r    r4   s     r!   openedPathsTrackingFilePath.openedPaths  s*     "&!2!2G!26F6F!2GGGs   00c                b    [        XR                  S9nU R                  R                  U5        U$ )ze
Override L{filepath.FilePath.clonePath} to give the new path a reference
to the same tracking list.
)r  )r  r  r9   )r    r4   r  clones       r!   	clonePathTrackingFilePath.clonePath  s-     !4E4EF  'r#   )r  r  )FN)r4   r   r  boolr  zEOptional[List[Union[TrackingFilePath[str], TrackingFilePath[bytes]]]]r%   r   rr  r   r%   z	IO[bytes])r%   z;List[Union[TrackingFilePath[str], TrackingFilePath[bytes]]]F)r4   r   r  r  r%   zTrackingFilePath[OtherAnyStr])
r'   r(   r)   r*   r+   r  rF   r  r  r,   r$   r#   r!   r  r  U  sw    ( # // /
	/ 
/ H	DH 7<		/3		&	 	r#   r  c                  f    \ rS rSr% SrS\S'    S
     SS jjrSSS jjr S     SS jjrS	r	g)ExplodingFilePathi  z
A specialized L{FilePath} which always returns an instance of
L{ExplodingFile} from its C{open} method.

@ivar fp: The L{ExplodingFile} instance most recently returned from the
    C{open} method.
r   r   Nc                X    [         R                  R                  X5        Uc  U nX l        g)a!  
Initialize an L{ExplodingFilePath} with a name and a reference to the

@param pathName: The path name as passed to L{filepath.FilePath}.
@type pathName: C{str}

@param originalExploder: The L{ExplodingFilePath} to associate opened
files with.
@type originalExploder: L{ExplodingFilePath}
N)r   rV   r  _originalExploder)r    pathNameoriginalExploders      r!   r  ExplodingFilePath.__init__  s*    " 	""42##!1r#   c                :    [        5       =o R                  l        U$ )z
Create, save, and return a new C{ExplodingFile}.

@param mode: Present for signature compatibility.  Ignored.

@return: A new C{ExplodingFile}.
)r   r  r   r
  s      r!   rF   ExplodingFilePath.open  s     )67""%r#   c                ,    [        XR                  5      $ r2   )r  r  )r    namer  s      r!   r  ExplodingFilePath.clonePath  s     !'='=>>r#   )r  r2   )r  r   r  zAOptional[Union[ExplodingFilePath[str], ExplodingFilePath[bytes]]]r%   r   r  r  r  )r#  r   r  r  r%   zfilepath.FilePath[OtherAnyStr])
r'   r(   r)   r*   r+   __annotations__r  rF   r  r,   r$   r#   r!   r  r    sa     	 22
2 
2,	 7<??/3?	'? ?r#   r  Tc                  |    \ rS rSrSr S       SS jjrSS jrSS jrSS jrSS jr	SS	 jr
SS
 jrSS jrSrg)PermissionsTestsi  z"
Test Permissions and RWX classes
Nc           	         X:w  aH  Uc  Sn[        U5      S:  a  US-  nU R                  U< S[        U5      < S[        U5      < S35      eU$ )z
Tests that C{first} != C{second} is false.  This method tests the
__ne__ method, as opposed to L{assertEqual} (C{first} == C{second}),
which tests the __eq__ method.

Note: this should really be part of trial
 r   
z8not not unequal (__ne__ not implemented correctly):
a = z
b = )r   failureExceptionr   )r    firstsecondmsgs       r!   assertNotUnequal!PermissionsTests.assertNotUnequal  sV     ?{3x!|t''(+WU^WV_N  r#   c                   U R                  [        5       nU R                  SSS5        SSS5        U R                  S[	        WR
                  5      5        U R                  S[	        UR
                  5      5        U R                  [        5       nU R                  SS5        SSS5        U R                  S[	        WR
                  5      5        U R                  SS5        g! , (       d  f       N= f! , (       d  f       NW= f)zB
Self-test for assertNotUnequal to make sure the assertion works.
r   r   zcustom messageNz __ne__ not implemented correctly)rm   AssertionErrorr0  assertInstr	exception)r    aeae2s      r!   	test_testPermissionsTests.test_test  s     ~."!!!Q(89 /8#bll:KL&BLL(9:~.#!!!Q' /8#cmm:LMa# /. /.s   C$C5$
C25
Dc                   S H  nS Hw  nS Hn  n[         R                  " XU5      nU R                  UR                  U5        U R                  UR                  U5        U R                  UR
                  U5        Mp     My     M     [         R                  " SSS5      nU R                  UR                  =(       a    UR                  =(       a    UR
                  5        g)z.
L{RWX}'s constructor takes a set of booleans
TFTN)r   RWXre   r   rR   executer\   )r    r  wr;   rwxs        r!   test_rwxFromBools"PermissionsTests.test_rwxFromBools  s     A"&A",,qQ/C$$SXXq1$$SYY2$$S[[!4	 ' #  ll4t,>SYY>3;;?r#   c                   S H  nS H  nS H{  nU R                  [        R                  " XU5      [        R                  " XU5      5        U R                  [        R                  " XU5      [        R                  " XU5      5        M}     M     M     U R	                  [        R                  " SSS5      [        R                  " SSS5      5        U R	                  S[        R                  " SSS5      5        g)zi
L{RWX}'s created with the same booleans are equivalent.  If booleans
are different, they are not equal.
r<  TFr   N)re   r   r=  r0  assertNotEqual)r    r  r?  r;   s       r!   test_rwxEqNePermissionsTests.test_rwxEqNe  s    
 A"&A$$X\\!%:HLLq<QR))(,,qQ*?aTUAVW ' # 
 	LLtT*HLLtU,K	
 	Ax||D$=>r#   c                T   S
S jnS Hg  nS H^  nS HU  n[         R                  " X#U5      nU R                  UR                  5       U" US5      U" US5      -   U" US5      -   5        MW     M`     Mi     U R                  [         R                  " SSS5      R                  5       S5        g	)z
L{RWX}'s shorthand string should be 'rwx' if read, write, and execute
permission bits are true.  If any of those permissions bits are false,
the character is replaced by a '-'.
c                    U (       a  U$ g)N-r$   )valletters     r!   getChar3PermissionsTests.test_rwxShorthand.<locals>.getChar  s    r#   r<  r  r?  r;   TFzr-xN)rJ  r  rK  r5  r%   r5  )r   r=  re   	shorthand)r    rL  r  r?  r;   r@  s         r!   test_rwxShorthand"PermissionsTests.test_rwxShorthand  s    	
 A"&A",,qQ/C$$3'!S/9GAsOK ' #  	dE48BBDeLr#   c           
        SS jn[        SS5       H  n[        SS5       H  n[        SS5       H  nSX#U4-  n[        US5      n[        R                  " U5      nU R	                  UR
                  U" US5      U SUR
                   35        U R	                  UR                  U" US5      U SUR                   35        U R	                  UR                  U" US	5      U S
UR                   35        M     M     M     [        R                  " S5      nS H0  nS H'  n	U R                  [        [        Xx5      U	5      5        M)     M2     g)z
L{Permissions}'s constructor takes a valid permissions bitmask and
parsaes it to produce the correct set of boolean permissions.
c                T   ^ ^^ SU 4S jjm[         R                  " UU4S jS 5       6 $ )Nc                >   > [        [        SU  U 35      nTU-  S:  $ )NS_Ir   )getattrstat)r   whoconstantstatModeInts      r!   getPermissionBitYPermissionsTests.test_permissionsFromStat.<locals>._rwxFromStat.<locals>.getPermissionBit*  s*     'D6#.? @#h.!33r#   c              3  6   >#    U  H  nT" UT5      v   M     g 7fr2   r$   ).0r   rZ  rW  s     r!   	<genexpr>RPermissionsTests.test_permissionsFromStat.<locals>._rwxFromStat.<locals>.<genexpr>/  s     J/$"4--/s   )RWX)r   r5  rW  r5  r%   r  )r   r=  )rY  rW  rZ  s   ``@r!   _rwxFromStat?PermissionsTests.test_permissionsFromStat.<locals>._rwxFromStat)  s#    4 <<J/J r#   r      z%d%d%dUSRz: got user: GRPz: got group: OTHz: got other:   )usergroupother)r   rR   r>  N)rY  r   rW  r5  r%   zfilepath.RWX)
ranger   r   Permissionsre   rj  rk  rl  r\   rU  )
r    rc  ugochmodStringchmodValpermrW  r   s
             r!   test_permissionsFromStat)PermissionsTests.test_permissionsFromStat#  s8   	 q!A1a[q!A"*aAY"6K";2H#//9D$$		$Xu5&-|DII;?
 $$

$Xu5&-}TZZLA
 $$

$Xu5&-}TZZLA % ! * ##E*-C4(:D AB 5 .r#   c                   U R                  [        R                  " S5      [        R                  " S5      5        U R                  [        R                  " S5      [        R                  " S5      5        U R	                  [        R                  " S5      [        R                  " S5      5        U R	                  S[        R                  " S5      5        g)zL
Two L{Permissions}'s that are created with the same bitmask
are equivalent
ri    r   N)re   r   rn  r0  rD  r   s    r!   test_permissionsEq#PermissionsTests.test_permissionsEqL  s    
 	--e4h6J6J56QRh22598;O;OPU;VWH0079M9Me9TUAx33E:;r#   c                   [        SS5       H  n[        SS5       H  n[        SS5       H  n[        R                  " [        SXU4-  S5      5      nU R	                  UR                  5       SR                  S UR                  UR                  UR                  4 5       5      5        M     M     M     U R	                  [        R                  " S5      R                  5       S5        g)	z
L{Permissions}'s shorthand string is the RWX shorthand string for its
user permission bits, group permission bits, and other permission bits
concatenated together, without a space.
r   re  z0o%d%d%dr*  c              3  @   #    U  H  oR                  5       v   M     g 7fr2   )rN  )r]  r;   s     r!   r^  =PermissionsTests.test_permissionsShorthand.<locals>.<genexpr>b  s       3VaKKMM3Vs   i  z	rwxrwx---N)
rm  r   rn  r   re   rN  r6   rj  rk  rl  )r    ro  rp  rq  rt  s        r!   test_permissionsShorthand*PermissionsTests.test_permissionsShorthandV  s     q!A1a[q!A#//J!4JA0NOD$$(  48IItzz4::3V   % !  	--e4>>@+Nr#   r$   r2   )r-  r&  r.  r   r/  zOptional[str]r%   r&  r   )r'   r(   r)   r*   r+   r0  r9  rA  rE  rO  ru  ry  r~  r,   r$   r#   r!   r(  r(    sZ    
 >B &-:	
*$@?M,'CR<Or#   r(  c                  h   \ rS rSrSrSJS jrSJS jr\" \S5      SJS j5       r	\" \S5      SJS j5       r
SJS jr\" \S5      SJS	 j5       r\" \S5      SJS
 j5       r\" \S5      SJS j5       rSJS jrSJS jr\" \S5      SJS j5       r\" \S5      SJS j5       r\" \S5      SJS j5       rSJS jrSJS jrSJS jrSJS jrSJS jr\" \R4                  " 5       S:g  S5      SJS j5       r\" \R4                  " 5       S:g  S5      SJS j5       rSJS jrSJS jrSJS jrSJS jr SJS jr!SJS jr"\" \S5      SJS  j5       r#SJS! jr$SJS" jr%SJS# jr&SJS$ jr'\" \S5      SJS% j5       r(\" \S5      SJS& j5       r)SJS' jr*SJS( jr+SJS) jr,SJS* jr-S+ 4SKS, jjr.SJS- jr/SJS. jr0SLS/ jr1SJS0 jr2\" \S5      SJS1 j5       r3\" \S5      SJS2 j5       r4SJS3 jr5SJS4 jr6SJS5 jr7SJS6 jr8SJS7 jr9SJS8 jr:SJS9 jr;SJS: jr<SJS; jr=SJS< jr>SJS= jr?SJS> jr@\" \R                  " 5       S?5      SJS@ j5       rBSJSA jrC\" \R                  " 5       (       + SB5      SJSC j5       rDSJSD jrE\" \R                  " 5       (       + SB5      SJSE j5       rF\" \R                  " 5       S?5      SJSF j5       rG\" \R                  " 5       S?5      SJSG j5       rHSHrIgI)MFilePathTestsii  z
Test various L{FilePath} path manipulations.

In particular, note that tests defined on this class instead of on the base
class are only run against L{twisted.python.filepath}.
c           
     8   S H  nU R                   R                  S5      R                  U5        U R                  [        R
                  " [        R                  " U R                   R                  S5      R                   5      R                  5      U5        M     g)z
L{FilePath.chmod} modifies the permissions of
the passed file as expected (using C{os.stat} to check). We use some
basic modes that should work everywhere (even on Windows).
)m  ri  rJ   N)r4   rf   chmodre   rV  S_IMODEr3   st_moder    r  s     r!   
test_chmodFilePathTests.test_chmodq  sg     #DIIOOG$**40RWWTYY__W%=%B%BCKKLd #r#   c                   U R                   R                  S5      n[        R                  " UR                   U R	                  S5      5        [        R                  " UR                  S5      R                   U R	                  S5      5        [        R                  " UR                  S5      R                   U R	                  SS5      5        g)z9
Create several symbolic links to files and directories.
rJ   	   sub1.linkrL   
   file2.links   sub1.file2.linkN)r4   rf   r3   symlinkr<   )r    rB   s     r!   createLinksFilePathTests.createLinks}  s     )


6;;\ :;


6<<)..]0KL


LL"''g?Q)R	
r#   z"Platform does not support symlinksc                   U R                  5         [        R                  " U R                  R	                  S5      R                  U R                  R	                  S5      R                  5        U R                  U R                  R	                  S5      R                  5       U R                  R	                  S5      R	                  S5      5        g)zL
L{FilePath.realpath} returns the path of the ultimate target of a
symlink.
r  s	   link.linkrJ   rL   N)r  r3   r  r4   rf   re   realpathr   s    r!   test_realpathSymlink"FilePathTests.test_realpathSymlink  s     	


IIOOM*//1N1S1S	
 	IIOOL)224IIOOG$**84	
r#   c                   [         R                  " U R                  R                  S5      R                  U R                  R                  S5      R                  5        [         R                  " U R                  R                  S5      R                  U R                  R                  S5      R                  5        U R	                  [
        R                  U R                  R                  S5      R                  5        g)zl
L{FilePath.realpath} raises L{filepath.LinkError} if the path is a
symbolic link which is part of a cycle.
   link1s   link2N)r3   r  r4   rf   rm   r   	LinkErrorr  r   s    r!   test_realpathCyclicalSymlink*FilePathTests.test_realpathCyclicalSymlink  s     	

499??8,11499??83L3Q3QR


499??8,11499??83L3Q3QR(,,diiooh.G.P.PQr#   c                    U R                  U R                  R                  S5      R                  5       U R                  R                  S5      5        g)zR
L{FilePath.realpath} returns the path itself if the path is not a
symbolic link.
rJ   N)re   r4   rf   r  r   s    r!   test_realpathNoSymlink$FilePathTests.test_realpathNoSymlink  s7    
 	1::<diioog>VWr#   c                N  ^  T R                  5         [        R                  " T R                  R	                  S5      R                  T R                  R	                  S5      R	                  S5      R                  5        SU 4S jjnT R                  [        R                  U5        g)zD
Verify that walking a path with a cyclical symlink raises an error
rJ      sub1.loopylinkc                 v   > TR                   R                  5        V s/ s H  o R                   PM     sn $ s  sn f r2   r4   rr   )rt   r    s    r!   iterateOverPath?FilePathTests.test_walkCyclicalSymlink.<locals>.iterateOverPath  s*    (,		(89(8HH(8999s   6Nr%   zList[bytes])r  r3   r  r4   rf   rm   r   r  )r    r  s   ` r!   test_walkCyclicalSymlink&FilePathTests.test_walkCyclicalSymlink  sr    
 	


IIOOG$))IIOOG$**+<=BB	

	: 	(,,o>r#   c                H  ^ ^ T R                  5         [        R                  " T R                  R	                  S5      R                  T R                  R	                  S5      R	                  S5      R                  5        SS jmSUU 4S jjnT R                  U" 5       5        g)z
Verify that, after making a path with cyclical symlinks, when the
supplied C{descend} predicate returns C{False}, the target is not
traversed, as if it was a simple symlink.
rJ   r  c                ,    U R                  5       (       + $ r2   r   r4   s    r!   
noSymLinksKFilePathTests.test_walkObeysDescendWithCyclicalSymlinks.<locals>.noSymLinks      {{}$$r#   c                 t   > TR                   R                  TS9 V s/ s H  o R                   PM     sn $ s  sn f )Ndescendr  )rt   r  r    s    r!   r  PFilePathTests.test_walkObeysDescendWithCyclicalSymlinks.<locals>.iterateOverPath  s.    (,		z(JK(JHH(JKKKs   5Nr4   zfilepath.FilePath[bytes]r%   r  r  )r  r3   r  r4   rf   r\   )r    r  r  s   ` @r!   )test_walkObeysDescendWithCyclicalSymlinks7FilePathTests.test_walkObeysDescendWithCyclicalSymlinks  sw     	


IIOOG$))IIOOG$**+<=BB	

	%	L 	L 	)*r#   c                    U R                  5         SS jnU R                  R                  US9 Vs/ s H  o"R                  PM     nnU R                  [	        U5      [	        U R
                  5      5        gs  snf )zc
Verify that when the supplied C{descend} predicate returns C{False},
the target is not traversed.
c                ,    U R                  5       (       + $ r2   r  r  s    r!   r  7FilePathTests.test_walkObeysDescend.<locals>.noSymLinks  r  r#   r  Nr  )r  r4   rr   re   rs   r8   )r    r  rt   r;   s       r!   test_walkObeysDescend#FilePathTests.test_walkObeysDescend  s`     		% "&
!CD!C#XX!CDQTXX/ Es   A7c                   SnU R                   R                  S5      R                  U5        U R                   R                  S5      R                  5       nU R	                  X5        SnU R                   R                  S5      R                  US5        U R                   R                  S5      R                  5       nU R	                  X5        g )Ns
   newcontents   news   contents   .tmp)r4   rf   
setContent
getContentre   )r    content
newcontents      r!   test_getAndSetFilePathTests.test_getAndSet  s    		**73YY__V,779
-		**7G<YY__V,779
-r#   c                    [        S5      nU R                  [        UR                  5        U R	                  UR
                  R                  5        g)z
If reading from the underlying file raises an exception,
L{FilePath.getContent} raises that exception after closing the file.
r*  N)r  rm   IOErrorr  r\   r   r   r   s     r!   test_getContentFileClosing(FilePathTests.test_getContentFileClosing  s6    
 r"'2==1%r#   c                   U R                   R                  S5      nU R                   R                  S5      n[        R                  " UR                   UR                   5        U R	                  UR                  5       5        U R                  UR                  5       5        U R	                  UR                  5       5        U R	                  UR                  5       5        g)z
Verify the behavior of the C{isLink} method against links and
non-links. Also check that the symbolic link shares the directory
property with its target.
s   sub4rM   N)r4   rf   r3   r  r\   r   r   r   )r    s4s3s      r!   test_symbolicLinkFilePathTests.test_symbolicLink  s     YY__W%YY__W%


277BGG$		$%
#
#r#   c                *   U R                   R                  S5      U R                   R                  S5      4U R                   R                  S5      R                  S5      U R                   R                  S5      4/nU H  u  p#UR                  U5        U R                  UR	                  5       S5        U R                  UR                  5       UR                  5       5        U R                  UR                  5       UR                  5       5        M     g)z
Verify that symlink creates a valid symlink that is both a link and a
file if its target is a file, or a directory if its target is a
directory.
r   s	   sub2.linkrN   s   file3.ext1.linkzThis is a linkN)r4   rf   linkTor\   r   re   r   r   )r    targetLinkstargetlinks       r!   test_linkToFilePathTests.test_linkTo  s     YY__W%tyy|'DE		(..}=		 23
 (LFMM$OODKKM+;<V\\^TZZ\:V]]_dkkm<	 (r#   c                   U R                  [        U R                  R                  S5      R                  U R                  R                  S5      R                  S5      5        U R                  [        U R                  R                  S5      R                  U R                  R                  S5      R                  S5      5        g)z
Verify C{linkTo} fails in the following case:
    - the target is in a directory that doesn't exist
    - the target already exists
rK   s   nosubrJ   rL   N)rm   r   r4   rf   r  r   s    r!   test_linkToErrorsFilePathTests.test_linkToErrors  s     	IIOOH%,,IIOOH%++H5	

 	IIOOH%,,IIOOG$**84	
r#   c                   U R                   R                  S5      R                  S5      nSnU R                  UR                  " U6 5        UR	                  S5      nUR                  5         UR                  " U6 nUc   eU R                  UR                  5       (       + 5        UR                  S5      nUc   eU R                  UR                  5       (       + 5        UR                  5         U R                  UR                  " U6 5        g )NrM      file3)   .foos   .bars   ext1s   ext2s   ext3r     *)r4   rf   r   siblingExtensionSearchsiblingExtensiontouchr   r   )r    f3extsf3efoundglobbeds         r!   testMultiExtFilePathTests.testMultiExt$  s    YY__W%++H5:22D9:!!'*		))40   U\\^+,++D1"""W^^--.

22D9:r#   c                    [         R                  " S5      nUR                  S5        U R                  [         R                  UR                  S5        g )N   .s   foo/bar   /mon€y)r   rV   preauthChildrm   InsecurePathr   s     r!   testPreauthChildFilePathTests.testPreauthChild3  s:    t$

#(//-Pr#   c                6   U R                   R                  S5      nUR                  5         U R                  UR	                  5       S5        U R                  [        UR                  5       [        R                  " 5       -
  5      S-  S5        U R                  [        UR                  5       [        R                  " 5       -
  5      S-  S5        U R                  [        UR                  5       [        R                  " 5       -
  5      S-  S5        U R                  UR                  5       5        U R                  UR                  5       5        [        R                  " UR                   5        U R                  UR                  5       5        UR                  SS9  U R                  UR                  5       5        U R                  UR!                  5       5        U R                  UR#                  5       5        U R                  UR%                  5       5        g )Ns   stattestr      F)reraise)r4   rf   r  re   getsizeabsr   rP   r   r   r\   r   r3   r   restatr   r   r   r   r   s     r!   testStatCacheFilePathTests.testStatCache8  sX   IIOOK(		a(QZZ\DIIK78B>BQZZ\DIIK78B>BQZZ\DIIK78B>B
#
#
		!&&
#	$$#$r#   c                ,   [         R                  " [         R                  " U R                  5      5      nU R	                  U R                  R
                  UR
                  5        U R	                  U R                  R                  UR                  5        g r2   )pickleloadsdumpsr4   re   	__class__)r    newpaths     r!   testPersistFilePathTests.testPersistK  sY    ,,v||DII67,,g.?.?@6r#   c                B   U R                  [        R                  U R                  R                  S5        U R                  [        R                  U R                  R                  S5        U R                  [        R                  U R                  R                  S5        g )Ns   ..s   /etcs   ../..rm   r   r  r4   rf   r   s    r!   testInsecureUNIXFilePathTests.testInsecureUNIXP  sb    (//%H(//'J(//(Kr#   r   zTest will run only on Windows.c                    U R                  [        R                  U R                  R                  S5        U R                  [        R                  U R                  R                  S5        g )Ns   ..\..s   C:randomfiler  r   s    r!   testInsecureWin32FilePathTests.testInsecureWin32U  sB    (//)L(///Rr#   c                B   U R                  [        R                  U R                  R                  S5        U R                  [        R                  U R                  R                  S5        U R                  [        R                  U R                  R                  S5        g)z
Windows has 'special' filenames like NUL and CON and COM1 and LPR
and PRN and ... god knows what else.  They can be located anywhere in
the filesystem.  For obvious reasons, we do not wish to normally permit
access to these.
s   CONs   C:CONzC:\CONNr  r   s    r!   testInsecureWin32Whacky%FilePathTests.testInsecureWin32WhackyZ  sd     	(//&I(//(K(//)Lr#   c                   U R                  [        R                  " S5      [        R                  " S5      5        U R                  [        R                  " S5      [        R                  " S5      :  5        U R                  [        R                  " S5      [        R                  " S5      :  5        U R                  [        R                  " S5      [        R                  " S5      :  5        U R                  [        R                  " S5      [        R                  " S5      :*  5        U R                  [        R                  " S5      [        R                  " S5      :  5        U R                  [        R                  " S5      [        R                  " S5      :*  5        U R                  [        R                  " S5      [        R                  " S5      :g  5        U R                  [        R                  " S5      [        R                  " S5      :g  5        U R	                  [        R                  " S5      [        R                  " S5      :g  5        g )Nra      z)re   r   rV   r\   r   r   s    r!   testComparisonFilePathTests.testComparisonf  s   **40(2C2CD2IJ))$/(2C2CD2IIJ))$/83D3DT3JJK))$/83D3DT3JJK))$/83D3DT3JJK))$/(2C2CD2IIJ))$/83D3DT3JJK))$/83D3DT3JJK))$/83D3DT3JJK**40H4E4Ed4KKLr#   c                r    U R                  [        R                  U R                  R                  SS/5        g)z\
If C{".."} is in the sequence passed to L{FilePath.descendant},
L{InsecurePath} is raised.
   mon€yz..N)rm   r   r  r4   r   r   s    r!   test_descendantOnly!FilePathTests.test_descendantOnlys  s.    
 	!!499#7#7,9M	
r#   c                j   U R                   R                  S5      nUR                  S5      nU R                  UR	                  5       UR	                  5       5        U R                  UR                  5       S5        UR                  5         U R                  X R                   R                  5       5        g )Ns   sibling_starts   sibling_test)	r4   rf   siblingre   rA   basenamecreateDirectoryr4  r   )r    r:   tss      r!   testSiblingFilePathTests.testSibling|  sz    IIOO,-YY'qyy{38
b)),,./r#   c                   U R                   R                  5       nU R                  UR                  5       U R                   R                  5       5        U R	                  UR                  5       U R                   R                  5       5        UR                  5         U R                  XR                   R                  5       R                  5       5        g r2   )r4   temporarySiblingre   rA   assertNotInr  r   r  r4  parentr   )r    r  s     r!   testTemporarySibling"FilePathTests.testTemporarySibling  s    YY'')tyy'8'8':;		(9(9(;<
b))**,5578r#   c                    SnU R                   R                  U5      nU R                  UR                  5       R	                  U5      UR                  5       < SU< 35        g)z
If L{FilePath.temporarySibling} is given an extension argument, it will
produce path objects with that extension appended to their names.
s   .test-extensionz does not end with N)r4   r  r\   r  endswith)r    testExtensionr  s      r!   test_temporarySiblingExtension,FilePathTests.test_temporarySiblingExtension  sT    
 +YY''6KKM""=1{{}2=2CD	
r#   c                    U R                   R                  5         U R                  U R                   R                  5       5        g)zf
L{FilePath.remove} on a L{FilePath} that refers to a directory will
recursively delete its contents.
N)r4   r   r   r   r   s    r!   test_removeDirectory"FilePathTests.test_removeDirectory  s/    
 			))+,r#   c                   U R                   R                  S5      n[        R                  " U R                   R                  S5      R                   UR                   5        UR	                  5         U R                  UR                  5       5        U R                  U R                   R                  S5      R                  5       5        g)z`
For a path which is a symbolic link, L{FilePath.remove} just deletes
the link, not the target.
r  rJ   N)r4   rf   r3   r  r   r   r   r\   )r    r  s     r!   test_removeWithSymlink$FilePathTests.test_removeWithSymlink  sz     yy|,


499??7+00$))<'		0779:r#   c                   [        U R                  R                  5       5      n[        R                  " U R                  5       5      nU R                  R                  U5        U R                  R                  5         UR                  U R                  5        [        U R                  R                  5       5      nUR                  5         UR                  5         U R                  X15        g)zx
L{FilePath.copyTo} makes a copy of all the contents of the directory
named by that L{FilePath} if it is able to do so.
N)
r   r4   rr   r   rV   r   copyTor   r   re   r    oldPathsr   newPathss       r!   test_copyToDirectory"FilePathTests.test_copyToDirectory  s    
 		()t{{}-				
		$))		(),r#   c                   U R                   R                  S5      nS Ul        [        U R	                  5       5      nU R                  [        UR                  U5        U R                  UR                  R                  5        g)z
If an exception is raised while L{FilePath.copyTo} is trying to open
source file to read from, the destination file is closed and the
exception is raised to the caller of L{FilePath.copyTo}.
s   notherec                     g)NTr$   r$   r#   r!   <lambda>AFilePathTests.test_copyToMissingDestFileClosing.<locals>.<lambda>  s    r#   N)r4   rf   r   r  r   rm   r  r"  r\   r   r   )r    nosuchdestinations      r!   !test_copyToMissingDestFileClosing/FilePathTests.test_copyToMissingDestFileClosing  s]     , % (6'6==+>--.r#   c                *   [        U R                  5       5      n[        [        5      nU R                  [        UR
                  U5        U R                  UR                  R                  5        U R                  UR                  R                  5        g)z
If an exception is raised while L{FilePath.copyTo} is copying bytes
between two regular files, the source and destination files are closed
and the exception propagates to the caller of L{FilePath.copyTo}.
N)	r  r   __file__rm   r  r"  r\   r   r   )r    r-  sources      r!   test_copyToFileClosing$FilePathTests.test_copyToFileClosing  s`     (6"8,'6==+>		(()--.r#   c                    U R                  [        [        4U R                  R                  U R                  R                  S5      5        g)z
L{FilePath.copyTo} fails with an OSError or IOError (depending on
platform, as it propagates errors from open() and write()) when
attempting to copy a directory to a child of itself.
rK   N)rm   r   r  r4   r"  rf   r   s    r!   test_copyToDirectoryItself(FilePathTests.test_copyToDirectoryItself  5     	g		 0 0$))//(2K	
r#   c                   [         R                  " U R                  R                  S5      R                  U R                  R                  S5      R                  5        [        R
                  " U R                  5       5      nU R                  R                  U5        U R                  UR                  S5      R                  5       5        U R                  UR                  S5      R                  5        Vs/ s H  o"R                  5       PM     snUR                  S5      R                  5        Vs/ s H  o"R                  5       PM     sn5        gs  snf s  snf )zV
Verify that copying with followLinks=True copies symlink targets
instead of symlinks
rJ   r  N)r3   r  r4   rf   r   rV   r   r"  r   r   re   r   r  )r    r   r;   s      r!   test_copyToWithSymlink$FilePathTests.test_copyToWithSymlink  s     	

499??7+00$))//(2K2P2PQt{{}-		(+2245#%88G#4#=#=#?@#?aZZ\#?@#%88H#5#>#>#@A#@aZZ\#@A	
@As   7E3E
c                <   [         R                  " SU R                  R                  S5      R                  5        [        R
                  " U R                  5       5      nU R                  R                  USS9  U R                  UR                  S5      R                  5       5        U R                  [         R                  " U R                  R                  S5      R                  5      [         R                  " UR                  S5      R                  5      5        g)zH
Verify that copying with followLinks=False copies symlinks as symlinks
rJ   r  FfollowLinksN)r3   r  r4   rf   r   rV   r   r"  r\   r   re   readlinkr   s     r!   test_copyToWithoutSymlink'FilePathTests.test_copyToWithoutSymlink  s    
 	

7DIIOOH5::;t{{}-		/*1134KK		1667KK*//0	
r#   c                    [         R                  " U R                  5       5      nU R                  [        UR
                  S5      nU R                  UR                  [        R                  5        g)zF
If the source path is missing, L{FilePath.copyTo} raises L{OSError}.
s   some other pathN)	r   rV   r   rm   r   r"  re   errnoENOENT)r    r4   excs      r!   test_copyToMissingSource&FilePathTests.test_copyToMissingSource  sK       /6HIELL1r#   c                   [        U R                  R                  5       5      n[        R                  " U R                  5       5      nU R                  R                  U5        UR                  U R                  5        [        U R                  R                  5       5      nUR                  5         UR                  5         U R                  X15        g)z^
Verify that moving an entire directory results into another directory
with the same content.
N)	r   r4   rr   r   rV   r   moveTor   re   r#  s       r!   test_moveToFilePathTests.test_moveTo	  s    
 		()t{{}-		
		$))		(),r#   c                   [         R                  " U R                  5       5      n[         R                  " U R                  5       5      nUR                  5         U R	                  UR                  5       5        U R                  UR                  5       5        UR                  U5        U R                  UR                  5       5        U R	                  UR                  5       5        g)z
A L{FilePath} that has been moved aside with L{FilePath.moveTo} no
longer registers as existing.  Its previously non-existent target
exists, though, as it was created by the call to C{moveTo}.
N)r   rV   r   r  r\   r   r   rI  )r    r   fp2s      r!   test_moveToExistsCache$FilePathTests.test_moveToExistsCache  s     t{{}-.


 			$&
		#%

%r#   c                D    U R                  5         U R                  5         g)zX
The assertion of test_moveToExistsCache should hold in the case of a
cross-mount move.
N)setUpFaultyRenamerN  r   s    r!    test_moveToExistsCacheCrossMount.FilePathTests.test_moveToExistsCacheCrossMount+  s    
 	 ##%r#   c                     g r2   r$   r$   r#   r!   r*  FilePathTests.<lambda>3  s    dr#   c                H   [         R                  " U R                  5       5      n[         R                  " U R                  5       5      nUR                  S5        UR                  S5        U" 5         U R	                  UR                  5       S5        U R	                  UR                  5       S5        [        R                  " UR                  5        U R	                  UR                  5       S5        UR                  U5        U R	                  UR                  5       S5        g)a  
L{FilePath.moveTo} clears its destination's status cache, such that
calls to L{FilePath.getsize} after the call to C{moveTo} will report the
new size, not the old one.

This is a separate test from C{test_moveToExistsCache} because it is
intended to cover the fact that the destination's cache is dropped;
test_moveToExistsCache doesn't cover this case because (currently) a
file that doesn't exist yet does not cache the fact of its non-
existence.
s   1234s
   1234567890r   
   N)
r   rV   r   r  re   r  r3   r   r4   rI  )r    hookr   rM  s       r!   test_moveToSizeCache"FilePathTests.test_moveToSizeCache3  s     t{{}-.
g}% 	q)+ 			#((+
		#*r#   c                4   ^  SU 4S jjnT R                  US9  g)zV
The assertion of test_moveToSizeCache should hold in the case of a
cross-mount move.
c                 &   > T R                  5         g r2   )rQ  r   s   r!   rY   ;FilePathTests.test_moveToSizeCacheCrossMount.<locals>.setUpX  s    ""$r#   )rX  Nr   )rY  )r    rY   s   ` r!   test_moveToSizeCacheCrossMount,FilePathTests.test_moveToSizeCacheCrossMountR  s    	% 	!!u!-r#   c                    U R                  [        [        4U R                  R                  U R                  R                  S5      5        g)z
Verify error behavior of moveTo: it should raises one of OSError or
IOError if you want to move a path into one of its child. It's simply
the error raised by the underlying rename system call.
rK   N)rm   r   r  r4   rI  rf   r   s    r!   test_moveToErrorFilePathTests.test_moveToError]  r8  r#   c                n   ^^ / mSUU4S jjn[         R                  mU R                  [         SU5        T$ )z
Set up a C{os.rename} that will fail with L{errno.EXDEV} on first call.
This is used to simulate a cross-device rename failure.

@return: a list of pair (src, dest) of calls to C{os.rename}
@rtype: C{list} of C{tuple}
c                   > TR                  X45        [        T5      S:X  a  [        [        R                  S5      eT" X5      $ )N   z;Test-induced failure simulating cross-device rename failure)r9   r   r   rC  EXDEV)srcdestinvokedWithoriginalRenames     r!   faultyRename5FilePathTests.setUpFaultyRename.<locals>.faultyRenameq  sD    {+;1$KKT  "#,,r#   rename)rg  r5  rh  r5  r%   r   )r3   rm  patch)r    rk  ri  rj  s     @@r!   rQ  FilePathTests.setUpFaultyRenameg  s5     	- 	- 

2x.r#   c                f    U R                  5       nU R                  5         U R                  U5        g)z
C{moveTo} should be able to handle C{EXDEV} error raised by
C{os.rename} when trying to move a file on a different mounted
filesystem.
N)rQ  rJ  r\   )r    ri  s     r!   test_crossMountMoveTo#FilePathTests.test_crossMountMoveTo~  s.     ,,. 	 	$r#   c                   U R                  5       nU R                  R                  S5      nU R                  R                  S5      n[        R                  " U R                  R                  S5      R                  UR                  5        UR                  U5        U R                  UR                  5       5        U R                  UR                  5       S5        U R                  U5        g)zp
By default, when moving a symlink, it should follow the link and
actually copy the content of the linked node.
rL   r  rK   r0   N)rQ  r4   rf   r3   r  rI  r   r   re   r  r\   r    ri  r   r  s       r!    test_crossMountMoveToWithSymlink.FilePathTests.test_crossMountMoveToWithSymlink  s     ,,.YY__X&YY__X&


499??8,11277;
		"%)4$r#   c                   U R                  5       nU R                  R                  S5      nU R                  R                  S5      n[        R                  " U R                  R                  S5      R                  UR                  5        UR                  USS9  U R                  UR                  5       5        U R                  UR                  5       S5        U R                  U5        g)zS
Verify that moveTo called with followLinks=False actually create
another symlink.
rL   r  rK   Fr=  r0   N)
rQ  r4   rf   r3   r  rI  r\   r   re   r  rt  s       r!   #test_crossMountMoveToWithoutSymlink1FilePathTests.test_crossMountMoveToWithoutSymlink  s     ,,.YY__X&YY__X&


499??8,11277;
		"%	(		$)4$r#   c                   [         R                  " U R                  5       5      nUR                  5        nU R	                  SUR
                  5        UR                  S5        SSS5        [        UR                  S5       nUR                  5       nU R                  US5        SSS5        g! , (       d  f       NP= f! , (       d  f       g= f)a  
L{FilePath.create} should always open (and write to) files in binary
mode; line-feed octets should be unmodified.

(While this test should pass on all platforms, it is only really
interesting on platforms which have the concept of binary mode, i.e.
Windows platforms.)
b   
Nrb)r   rV   r   creater4  r  rR   rF   r4   r   re   )r    r4   rX   r   r   s        r!   test_createBinaryMode#FilePathTests.test_createBinaryMode  s       /[[]aMM#qvv&GGEN  $))T"b779DT5) #" ] #"s   .B-#B>-
B;>
Cc                   U R                   R                  S5      nU R                  [        UR                  5      nU R                  UR                  [        R                  5        U R                   R                  S5      nUR	                  S5       nUR                  S5        S S S 5        UR	                  5        nU R                  UR                  5       S5        S S S 5        UR	                  S5      R                  5         UR	                  5        nU R                  UR                  5       S5        S S S 5        U R                   R                  S5      nUR	                  S5       nUR                  S5        S S S 5        UR	                  S5       nUR                  S	5        S S S 5        UR	                  S
5       nU R                  UR                  5       S5        S S S 5        UR	                  S5       nU R                  UR                  5       S5        UR                  SS5        UR                  S5        S S S 5        UR	                  S
5       nU R                  UR                  5       S5        S S S 5        UR	                  S5       nU R                  UR                  5       S5        UR                  SS5        UR                  S5        S S S 5        UR	                  S5       nUR                  S5        UR                  SS5        U R                  UR                  5       S5        UR                  SS5        U R                  UR                  5       S5        S S S 5        UR                  S5        UR	                  S5      R                  5         UnAU R                  [        [        4UR                  5        g ! , (       d  f       GN(= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GNn= f! , (       d  f       GNF= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f! , (       d  f       GN= f)Ns   nonexistents   writerr?     abc
defr#   s   appenders   abcas   defr  s   abcdefzr+r   re  s   ghis	   abcdefghizw+s   123za+s   456s   123456T)r4   rf   rm   r  rF   re   rC  rD  rR   r   rU   seekrequireCreater   )r    nonexistentewriterrX   appenderexistents          r!   testOpenFilePathTests.testOpen  s   iioon5g{'7'78%,,/ +[[GGK  
 [[]aQVVX{3  	C [[]aQVVXs+ 
 99??;/]]31GGFO   ]]31GGFO   ]]31QVVXy1   ]]4 AQVVXy1 FF1aLGGFO ! ]]31QVVX|4  
 ]]4 AQVVXs+FF1aLGGFO ! ]]4 A
 GGFOFF1aLQVVXs+FF1aLQVVXy1 ! 	!!$'##%7G,hmm<I 
 ]
 ]       !   
 !  ! s{   O<!O!O))O;P?!P9AP1!QAQ-A6Q'
O
O&)
O8;
P

P
P.1
Q 
Q
Q$'
Q6c                    U R                   R                  S5      nUR                  S5      nU nUR                  S5        SSS5        U R	                  UR
                  5        g! , (       d  f       N*= f)a:  
Due to a bug in Python 2.7 on Windows including multiple 'b'
characters in the mode passed to the built-in open() will cause an
error.  FilePath.open() ensures that only a single 'b' character is
included in the mode passed to the built-in open().

See http://bugs.python.org/issue7686 for details about the bug.
s   explicit-binaryrE   r  Nr4   rf   rF   rR   r\   r   r    r  openerfiles       r!   test_openWithExplicitBinaryMode-FilePathTests.test_openWithExplicitBinaryMode
  sS     !34T"tJJ{# & V   A%%
A3c                    U R                   R                  S5      nUR                  S5      nU nUR                  S5        SSS5        U R	                  UR
                  5        g! , (       d  f       N*= f)af  
Due to a bug in Python 2.7 on Windows including multiple 'b'
characters in the mode passed to the built-in open() will cause an
error.  No matter how many 'b' modes are specified, FilePath.open()
ensures that only a single 'b' character is included in the mode
passed to the built-in open().

See http://bugs.python.org/issue7686 for details about the bug.
s   multiple-binarywbbr  Nr  r  s       r!   )test_openWithRedundantExplicitBinaryModes7FilePathTests.test_openWithRedundantExplicitBinaryModes  sS     !34U#tJJ{# & Vr  c                    [         R                  " U R                  5       5      nU R                  UR	                  5       5        UR                  5         U R                  UR	                  5       5        g)zs
Check that C{filepath.FilePath.exists} correctly restat the object if
an operation has occurred in the mean time.
N)r   rV   r   r   r   makedirsr\   r   s     r!   test_existsCacheFilePathTests.test_existsCache)  sI    
 t{{}-%
		$r#   c                f   [         R                  " [        R                  R	                  U R                  5       SSS5      5      nU R                  UR                  5       5        UR                  5         U R                  UR                  5       5        U R                  UR                  5       5        g)z
C{FilePath.makedirs} creates a directory at C{path}}, including
recursively creating all parent directories leading up to the path.
s   foos   bars   bazN)r   rV   r3   r4   r6   r   r   r   r  r\   r   r   s     r!   (test_makedirsMakesDirectoriesRecursively6FilePathTests.test_makedirsMakesDirectoriesRecursively4  sn    
 rww||DKKM666RS%
		$
#r#   c                $   [         R                  " U R                  5       5      nU R                  UR	                  5       5        UR                  SS9  U R                  UR	                  5       5        U R                  UR                  5       5        g)zx
Calling C{FilePath.makedirs} with C{ignoreExistingDirectory} set to
C{True} has no effect if directory does not exist.
TignoreExistingDirectoryN)r   rV   r   r   r   r  r\   r   r   s     r!   8test_makedirsMakesDirectoriesWithIgnoreExistingDirectoryFFilePathTests.test_makedirsMakesDirectoriesWithIgnoreExistingDirectoryA  s`    
 t{{}-%
D1		$
#r#   c                :   [         R                  " [        R                  R	                  U R                  5       5      5      nUR                  5         U R                  [        UR                  5      nU R                  UR                  [        R                  5        g)ze
C{FilePath.makedirs} throws an C{OSError} exception
when called on a directory that already exists.
N)r   rV   r3   r4   r6   r   r  rm   r   re   rC  EEXISTr    r   r6  s      r!   (test_makedirsThrowsWithExistentDirectory6FilePathTests.test_makedirsThrowsWithExistentDirectoryN  s^    
 rww||DKKM:;
%%gr{{;	%,,7r#   c                   [         R                  " U R                  5       5      nUR                  5         U R	                  UR                  5       5        UR                  SS9  U R	                  UR                  5       5        g)z
C{FilePath.makedirs} succeeds when called on a directory that already
exists and the c{ignoreExistingDirectory} argument is set to C{True}.
Tr  N)r   rV   r   r  r\   r   r   s     r!   +test_makedirsAcceptsIgnoreExistingDirectory9FilePathTests.test_makedirsAcceptsIgnoreExistingDirectoryZ  sU    
 t{{}-
		$
D1		$r#   c                <   [         R                  " U R                  5       5      nUR                  5         U R	                  UR                  5       5        U R                  [        UR                  SS9nU R                  UR                  [        R                  5        g)z
When C{FilePath.makedirs} is called with C{ignoreExistingDirectory} set
to C{True} it throws an C{OSError} exceptions if path is a file.
Tr  N)r   rV   r   r~  r\   r   rm   r   r  re   rC  r  r  s      r!   5test_makedirsIgnoreExistingDirectoryExistAlreadyAFileCFilePathTests.test_makedirsIgnoreExistingDirectoryExistAlreadyAFileg  so    
 t{{}-
				$%%R[[$ & 
	 	%,,7r#   c                   SS jnU R                  [        SU5        [        R                  " U R	                  5       5      nU R                  [        UR                  SS9nU R                  UR                  [        R                  5        g)z
When C{FilePath.makedirs} is called with C{ignoreExistingDirectory} set
to C{True} it raises an C{OSError} exception if exception errno is not
EEXIST.
c                6    [        [        R                  S5      e)NzPermission Denied)r   rC  EACCESr  s    r!   faultyMakedirs_FilePathTests.test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory.<locals>.faultyMakedirs}  s    %,,(;<<r#   r  Tr  N)r4   r5  r%   r   )rn  r3   r   rV   r   rm   r   r  re   rC  r  )r    r  r   r6  s       r!   9test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectoryGFilePathTests.test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectoryv  si    	= 	

2z>2t{{}-%%R[[$ & 
	 	%,,7r#   c                   [         R                  " U R                  5       5      nUR                  S5        U R	                  UR                  5       S5        [        UR                  S5       nUR                  S5        SSS5        U R	                  UR                  5       S5        UR                  5         U R	                  UR                  5       S5        g! , (       d  f       N_= f)z
L{FilePath.changed} indicates that the L{FilePath} has changed, but does
not re-read the status information from the filesystem until it is
queried again via another method, such as C{getsize}.
s   12345r   rE   s   12345678Nre  )
r   rV   r   r  re   r  rF   r4   rR   changed)r    r   fObjs      r!   test_changedFilePathTests.test_changed  s     t{{}-
hq) "''4 DJJ{# ! 	q)


 	q) ! s   ,C
C%zTest does not run on Windowsc                   S Hz  nU R                   R                  S5      R                  U5        U R                  U R                   R                  S5      R	                  5       [
        R                  " U5      5        M|     U R                   R                  S5      R                  S5        U R                  U R                   R                  S5      R	                  5       R                  5       S5        g)z
Getting permissions for a file returns a L{Permissions} object for
POSIX platforms (which supports separate user, group, and other
permissions bits.
)ri  rx  rJ     z	rwxrw-r--N)r4   rf   r  re   getPermissionsr   rn  rN  r  s     r!   test_getPermissions_POSIX'FilePathTests.test_getPermissions_POSIX  s     #DIIOOG$**40		(7798;O;OPT;U #
 			 &&u-IIOOG$335??A;	
r#   c                    [         R                  " U R                  5       5        U R                  U R                  /5      nU R                  U/ 5        g)zi
While accessing L{twisted.python.filepath.FilePath.statinfo} is
deprecated, the filepath itself is not.
N)r   rV   r   flushWarningstest_filePathNotDeprecatedre   )r    warningInfos     r!   r  (FilePathTests.test_filePathNotDeprecated  sA    
 	$++-((($*I*I)JKb)r#   zTest will run only on Windowsc                P   U R                  U R                  R                  S5      R                  S5        S Hz  nU R                  R                  S5      R                  U5        U R	                  U R                  R                  S5      R                  5       [        R                  " U5      5        M|     U R                  R                  S5      R                  S5        U R	                  U R                  R                  S5      R                  5       R                  5       S5        g)a  
Getting permissions for a file returns a L{Permissions} object in
Windows.  Windows requires a different test, because user permissions
= group permissions = other permissions.  Also, chmod may not be able
to set the execute bit, so we are skipping tests that set the execute
bit.
rJ   ri  )ri  r  iI  z	r-xr-xr-xN)	
addCleanupr4   rf   r  re   r  r   rn  rN  r  s     r!   test_getPermissions_Windows)FilePathTests.test_getPermissions_Windows  s     			066>"DIIOOG$**40		(7798;O;OPT;U #
 			 &&u-IIOOG$335??A;	
r#   c                    U R                  U R                  R                  5       5        U R                  U R                  R                  5       5        g)z-
Ensure that a file is not a block or socket
N)r   r4   isBlockDeviceisSocketr   s    r!   test_whetherBlockOrSocket'FilePathTests.test_whetherBlockOrSocket  s:     	0023++-.r#   c                   U R                  [        U R                  R                  5        U R                  [        U R                  R                  5        U R                  [        U R                  R
                  5        U R                  [        U R                  R                  5        U R                  [        U R                  R                  5        g)z=
Verify that certain file stats are not available on Windows
N)rm   NotImplementedErrorr4   getInodeNumber	getDevicegetNumberOfHardLinks	getUserID
getGroupIDr   s    r!   (test_statinfoBitsNotImplementedInWindows6FilePathTests.test_statinfoBitsNotImplementedInWindows  s    
 	-tyy/G/GH-tyy/B/BC-tyy/M/MN-tyy/B/BC-tyy/C/CDr#   c                   U R                   R                  S5      nU R                   U4 H  nU R                  UR                  5       [        5        U R                  UR                  5       [        5        U R                  UR                  5       [        5        U R                  UR                  5       [        5        U R                  UR                  5       [        5        M     U R                  U R                   R                  5       UR                  5       5        U R                  U R                   R                  5       UR                  5       5        g)zW
Verify that file inode/device/nlinks/uid/gid stats are numbers in
a POSIX environment
rK   N)
r4   rf   assertIsInstancer  r   r  r  r  r  re   )r    cr:   s      r!   test_statinfoBitsAreNumbers)FilePathTests.test_statinfoBitsAreNumbers  s     IIOOH%AA!!!"2"2"4c:!!!++-5!!!"8"8":C@!!!++-5!!!,,.#6  	,,.>--/@r#   c                  ^ ^  " S S5      nU" 5       mSUU 4S jjnUT R                   l        ST R                   l        T R                  T R                   R	                  5       TR
                  5        T R                  T R                   R                  5       TR                  5        T R                  T R                   R                  5       TR                  5        T R                  T R                   R                  5       TR                  5        T R                  T R                   R                  5       TR                  5        g)z
Verify that the right numbers come back from the right accessor methods
for file inode/device/nlinks/uid/gid (in a POSIX environment)
c                  (    \ rS rSrSrSrSrSrSrSr	g)	<FilePathTests.test_statinfoNumbersAreValid.<locals>.FakeStati     i,  i  r  iX  r$   N)
r'   r(   r)   r*   st_inost_devst_nlinkst_uidst_gidr,   r$   r#   r!   FakeStatr    s    FFHFFr#   r  c                 (   > TTR                   l        g r2   )r4   	_statinfo)argskwargsfaker    s     r!   
fakeRestat>FilePathTests.test_statinfoNumbersAreValid.<locals>.fakeRestat  s    "&DIIr#   N)r  r   r  r   r%   r   )r4   r  r  re   r  r  r  r  r  r  r  r  r  r  )r    r  r  r  s   `  @r!   test_statinfoNumbersAreValid*FilePathTests.test_statinfoNumbersAreValid  s    	 	 z	' 	' &		 #		113T[[A,,.<7794==I,,.<--/=r#   r$   Nr   )rX  zCallable[[], None]r%   r   )r%   zList[Tuple[str, str]])Jr'   r(   r)   r*   r+   r  r  r   symlinkSkipr  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   getTyper  r  r  r  r  r  r  r  r  r&  r.  r3  r6  r:  r@  rF  rJ  rN  rR  rY  r^  ra  rQ  rq  ru  rx  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  i  sz   
	
 K=>
 ?
 K=>R ?RX K=>? ?? K=>+ ?+* K=>0 ?0.& K=>$ ?$ K=>= ?=& K=>
 ?
";Q
%&7
L
 H')+KLS MS H')+KL	M M	MM
09

- K=>
; ?
;-/&
/
 K=>
 ?
 K=>
 ?
2-&(& ?K +>	.
.% K=>% ?% K=>% ?%*"L=\'' 	%$$
8%88&*, H "@A
 B
 * ""$$&EF
 G
,/ ""$$&EFE GE H "@AA BA H "@A> B>r#   r  c                  T    \ rS rSrSrSS jrSS jrSS jrSS jrSS jr	SS jr
S	rg
)SetContentTestsi  z#
Tests for L{FilePath.setContent}.
c                   U R                  5       n[        R                  " U5      nUR                  S5        [	        US5       nUR                  5       nSSS5        U R                  SW5        g! , (       d  f       N!= f)z`
Contents of the file referred to by a L{FilePath} can be written using
L{FilePath.setContent}.
s   hello, worldr}  N)r   r   rV   r  rF   r   re   )r    
pathStringr4   r  contentss        r!   
test_writeSetContentTests.test_write  s`    
 [[]
  ,(*d#tyy{H $(3 $#s   A00
A>c                    [        S5      nU R                  [        UR                  S5        U R	                  UR
                  R                  5        g)z}
If writing to the underlying file raises an exception,
L{FilePath.setContent} raises that exception after closing the file.
r*  s   blahN)r  rm   r  r  r\   r   r   r   s     r!   test_fileClosing SetContentTests.test_fileClosing$  s8    
 r"'2==':%r#   c                    [        U R                  5       5      nUR                  S5        UR                  S5        UR                  5       nU R	                  [        U5      S5        U R                  US   US   5        g)z
L{FilePath.setContent} will use a different temporary filename on each
invocation, so that multiple processes, threads, or reentrant
invocations will not collide with each other.
s   alphas   betar   r   re  N)r  r   r  r  re   r   rD  )r    r   openedSiblingss      r!   test_nameCollision"SetContentTests.test_nameCollision-  si     dkkm,
h
g )^,a0N1-~a/@Ar#   c                   UR                  5       nU R                  [        U5      SS5        U R                  US   R	                  5       R                  5       R                  U5      SR                  US   R                  5       U5      5        g)a  
Assert that the L{TrackingFilePath} C{fp} was used to open one sibling
with the given extension.

@param fp: A L{TrackingFilePath} which should have been used to open
    file at a sibling path.
@type fp: L{TrackingFilePath}

@param extension: The extension the sibling path is expected to have
    had.
@type extension: L{str}

@raise: C{self.failureException} is raised if the extension of the
    opened file is incorrect or if not exactly one file was opened
    using C{fp}.
re  z expected exactly one opened filer   z%{!r} does not end with {!r} extensionN)r  re   r   r\   
asTextModer  r  format)r    r   	extensionopeneds       r!   _assertOneOpened SetContentTests._assertOneOpened=  sw    " !Va)KL1I  "++-66yA3::q	""$i	
r#   c                |    [        U R                  5       5      nUR                  S5        U R                  US5        g)zu
L{FilePath.setContent} creates temporary files with the extension
I{.new} if no alternate extension value is given.
s   helloz.newNr  r   r  r  r   s     r!   test_defaultExtension%SetContentTests.test_defaultExtensionW  s0    
 dkkm,
hb&)r#   c                ~    [        U R                  5       5      nUR                  SS5        U R                  US5        g)z
L{FilePath.setContent} creates temporary files with a user-supplied
extension so that if it is somehow interrupted while writing them the
file that it leaves behind will be identifiable.
s   goodbyes   -something-elsez-something-elseNr  r   s     r!   test_customExtension$SetContentTests.test_customExtension`  s4     dkkm,
j"45b"34r#   r$   Nr   )r   zTrackingFilePath[AnyStr]r  r5  r%   r   )r'   r(   r)   r*   r+   r  r  r  r  r	  r  r,   r$   r#   r!   r  r    s&    
4&B 
4*5r#   r  c                  l   \ rS rSrSrS+S jrS+S jrS+S jrS+S jrS+S jr	S+S jr
S+S	 jrS+S
 jrS+S jrS+S jr\" \R"                  " 5       S5      S+S j5       r\" \R"                  " 5       S5      S+S j5       r\" \R"                  " 5       (       + S5      S+S j5       r\" \R"                  " 5       (       + S5      S+S j5       rS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jrS+S jr S+S jr!S+S jr"S+S  jr#S+S! jr$S+S" jr%S+S# jr&S+S$ jr'S+S% jr(S+S& jr)S+S' jr*S+S( jr+S)r,g*),UnicodeFilePathTestsik  zd
L{FilePath} instances should have the same internal representation as they
were instantiated with.
c                    [         R                  " S5      nU R                  [        UR                  5      [
        5        g)zM
L{FilePath} instantiated with a text path will return a text-mode
FilePath.
	   ./mon€yN)r   rV   re   r   r4   r5  r   s     r!   test_UnicodeInstantiation.UnicodeFilePathTests.test_UnicodeInstantiationq  s,    
 ~.bgg,r#   c                    [         R                  " S5      nUR                  SR                  5       5      nU R	                  [        UR                  5      [        5        g)zq
Calling L{FilePath.child} on a text-mode L{FilePath} with a L{bytes}
subpath will return a bytes-mode FilePath.
   ./parent-mon€y   child-mon€yNr   rV   rf   r   re   r   r4   r&   r    r   rf   s      r!   #test_UnicodeInstantiationBytesChild8UnicodeFilePathTests.test_UnicodeInstantiationBytesChildy  sF    
 45+2245ejj)51r#   c                    [         R                  " S5      nUR                  S5      nU R                  [	        UR
                  5      [        5        g)zl
Calling L{FilePath.child} on a text-mode L{FilePath} with a text
subpath will return a text-mode FilePath.
r  r  N)r   rV   rf   re   r   r4   r5  r  s      r!   %test_UnicodeInstantiationUnicodeChild:UnicodeFilePathTests.test_UnicodeInstantiationUnicodeChild  s<    
 45&ejj)3/r#   c                    [         R                  " S5      nUR                  S5      nU R                  [	        UR
                  5      [        5        g)zs
Calling L{FilePath.preauthChild} on a text-mode L{FilePath} with a text
subpath will return a text-mode FilePath.
r  r  N)r   rV   r  re   r   r4   r5  r  s      r!   ,test_UnicodeInstantiationUnicodePreauthChildAUnicodeFilePathTests.test_UnicodeInstantiationUnicodePreauthChild  s<    
 45-ejj)3/r#   c                    [         R                  " S5      nUR                  SR                  5       5      nU R	                  [        UR                  5      [        5        g)zu
Calling L{FilePath.preauthChild} on a text-mode L{FilePath} with a bytes
subpath will return a bytes-mode FilePath.
r  r  N)r   rV   r  r   re   r   r4   r&   r  s      r!   *test_UnicodeInstantiationBytesPreauthChild?UnicodeFilePathTests.test_UnicodeInstantiationBytesPreauthChild  sF    
 45 2 9 9 ;<ejj)51r#   c                    [         R                  " S5      nU R                  [        UR                  5      [
        5        g)zR
L{FilePath} instantiated with a L{bytes} path will return a bytes-mode
FilePath.
   ./N)r   rV   re   r   r4   r&   r   s     r!   test_BytesInstantiation,UnicodeFilePathTests.test_BytesInstantiation  s,    
 u%bgg.r#   c                    [         R                  " S5      nUR                  SR                  5       5      nU R	                  [        UR                  5      [        5        g)zo
Calling L{FilePath.child} on a bytes-mode L{FilePath} with a bytes
subpath will return a bytes-mode FilePath.
r%  r  Nr  r  s      r!   !test_BytesInstantiationBytesChild6UnicodeFilePathTests.test_BytesInstantiationBytesChild  sE    
 u%+2245ejj)51r#   c                    [         R                  " SR                  5       5      nUR                  S5      nU R	                  [        UR                  5      [        5        g)zm
Calling L{FilePath.child} on a bytes-mode L{FilePath} with a text
subpath will return a text-mode FilePath.
u   parent-mon€yr  N)r   rV   r   rf   re   r   r4   r5  r  s      r!   #test_BytesInstantiationUnicodeChild8UnicodeFilePathTests.test_BytesInstantiationUnicodeChild  sE    
 299;<&ejj)3/r#   c                    [         R                  " SR                  5       5      nUR                  SR                  5       5      nU R	                  [        UR                  5      [        5        g)zv
Calling L{FilePath.preauthChild} on a bytes-mode L{FilePath} with a
bytes subpath will return a bytes-mode FilePath.
r  r  N)r   rV   r   r  re   r   r4   r&   r  s      r!   (test_BytesInstantiationBytesPreauthChild=UnicodeFilePathTests.test_BytesInstantiationBytesPreauthChild  sO    
 4;;=> 2 9 9 ;<ejj)51r#   c                    [         R                  " SR                  5       5      nUR                  S5      nU R	                  [        UR                  5      [        5        g)zt
Calling L{FilePath.preauthChild} on a bytes-mode L{FilePath} with a text
subpath will return a text-mode FilePath.
r  r  N)r   rV   r   r  re   r   r4   r5  r  s      r!   *test_BytesInstantiationUnicodePreauthChild?UnicodeFilePathTests.test_BytesInstantiationUnicodePreauthChild  sE    
 4;;=>-ejj)3/r#   zTest will not work on Windowsc                j    [         R                  " S5      n[        U5      nU R                  SU5        g)C
The repr of a L{unicode} L{FilePath} shouldn't burst into flames.
r  u   FilePath('/mon€y')Nr   rV   reprre   r    r   
reprOutputs      r!   test_unicoderepr%UnicodeFilePathTests.test_unicoderepr  s.    
 }-"X
2J?r#   c                    [         R                  " SR                  5       5      n[        U5      nU R	                  SU5        g)A
The repr of a L{bytes} L{FilePath} shouldn't burst into flames.
u   /parent-mon€yz%FilePath(b'/parent-mon\xe2\x82\xacy')N)r   rV   r   r7  re   r8  s      r!   test_bytesrepr#UnicodeFilePathTests.test_bytesrepr  s8    
 3::<="X
CZPr#   zTest only works on Windowsc                j    [         R                  " S5      n[        U5      nU R                  SU5        g)r5  zC:\zFilePath('C:\\')Nr6  r8  s      r!   test_unicodereprWindows,UnicodeFilePathTests.test_unicodereprWindows  s.    
 v&"X
-z:r#   c                j    [         R                  " S5      n[        U5      nU R                  SU5        g)r=  s   C:\zFilePath(b'C:\\')Nr6  r8  s      r!   test_bytesreprWindows*UnicodeFilePathTests.test_bytesreprWindows  s.    
 w'"X
.
;r#   c                    [         R                  " S5      nUR                  S5      nU R                  US   R                  [
        5        g)zD
C{globChildren} will return the same type as the pattern argument.
/r  r   N)r   rV   globChildrenr  r4   r&   r    r   r   s      r!   test_mixedTypeGlobChildren/UnicodeFilePathTests.test_mixedTypeGlobChildren  s<     s#??4(hqk..6r#   c                    [         R                  " S5      nUR                  S5      nU R                  US   R                  [
        5        g)z(
C{globChildren} works with L{unicode}.
rG  *r   N)r   rV   rH  r  r4   r5  rI  s      r!   test_unicodeGlobChildren-UnicodeFilePathTests.test_unicodeGlobChildren  s<     s#??3'hqk..4r#   c                x    [         R                  " S5      nU R                  UR                  5       [        5        g)zA
Calling C{basename} on an text- L{FilePath} returns L{unicode}.
./N)r   rV   r  r  r5  r   s     r!   test_unicodeBasename)UnicodeFilePathTests.test_unicodeBasename  s*     t$bkkmS1r#   c                x    [         R                  " S5      nU R                  UR                  5       [        5        g)zC
Calling C{dirname} on a text-mode L{FilePath} returns L{unicode}.
rQ  N)r   rV   r  rA   r5  r   s     r!   test_unicodeDirname(UnicodeFilePathTests.test_unicodeDirname  s*     t$bjjlC0r#   c                    [         R                  " S5      nUR                  5       nU R                  UR                  [
        5        g)zS
Calling C{parent} on a text-mode L{FilePath} will return a text-mode
L{FilePath}.
rQ  N)r   rV   r  r  r4   r5  )r    r   r  s      r!   test_unicodeParent'UnicodeFilePathTests.test_unicodeParent  s3    
 t$fkk3/r#   c                    [         R                  " S5      nUR                  S5      nU R                  UR                  [
        5        g)z`
A L{bytes} extension to C{temporarySibling} will mean a L{bytes} mode
L{FilePath} is returned.
r     .txtN)r   rV   r  r  r4   r&   r    r   tempSiblings      r!   test_mixedTypeTemporarySibling3UnicodeFilePathTests.test_mixedTypeTemporarySibling  s:    
 ~.))'2k..6r#   c                    [         R                  " S5      nUR                  S5      nU R                  UR                  [
        5        g)zd
A L{unicode} extension to C{temporarySibling} will mean a L{unicode}
mode L{FilePath} is returned.
u   /tmp/mon€y.txtN)r   rV   r  r  r4   r5  r\  s      r!   test_unicodeTemporarySibling1UnicodeFilePathTests.test_unicodeTemporarySibling  s;    
 01))&1k..4r#   c                J   [         R                  " S5      n[         R                  " UR                  5       S-   5      nUR                  5         UR	                  S5      nUc   eU R                  U[         R                  5        U R                  UR                  [        5        g)z
C{siblingExtensionSearch} called with L{bytes} on a L{unicode}-mode
L{FilePath} will return a L{list} of L{bytes}-mode L{FilePath}s.
r  ra  r[  N)r   rV   _asTextPathr  r  r  r4   r&   r    r   r
  newPaths       r!   $test_mixedTypeSiblingExtensionSearch9UnicodeFilePathTests.test_mixedTypeSiblingExtensionSearch&  s    
 ~.##BNN$4v$=>++G4"""gx'8'89gllE2r#   c                J   [         R                  " S5      n[         R                  " UR                  5       S-   5      nUR                  5         UR	                  S5      nUc   eU R                  U[         R                  5        U R                  UR                  [        5        g)z
C{siblingExtensionSearch} called with L{unicode} on a L{unicode}-mode
L{FilePath} will return a L{list} of L{unicode}-mode L{FilePath}s.
r  ra  N)r   rV   re  r  r  r  r4   r5  rf  s       r!   "test_unicodeSiblingExtensionSearch7UnicodeFilePathTests.test_unicodeSiblingExtensionSearch4  s    
 ~.##BNN$4v$=>++F3"""gx'8'89gllC0r#   c                @   [         R                  " S5      n[         R                  " UR                  5       S-   5      nUR                  5         UR	                  S5      nU R                  U[         R                  5        U R                  UR                  [        5        g)zt
C{siblingExtension} called with L{bytes} on a L{unicode}-mode
L{FilePath} will return a L{bytes}-mode L{FilePath}.
r  ra  r[  N)r   rV   re  r  r  r  r4   r&   rf  s       r!   test_mixedTypeSiblingExtension3UnicodeFilePathTests.test_mixedTypeSiblingExtensionC  ss    
 ~.##BNN$4v$=>%%g.gx'8'89gllE2r#   c                @   [         R                  " S5      n[         R                  " UR                  5       S-   5      nUR                  5         UR	                  S5      nU R                  U[         R                  5        U R                  UR                  [        5        g)zx
C{siblingExtension} called with L{unicode} on a L{unicode}-mode
L{FilePath} will return a L{unicode}-mode L{FilePath}.
r  ra  N)r   rV   re  r  r  r  r4   r5  rf  s       r!   test_unicodeSiblingExtension1UnicodeFilePathTests.test_unicodeSiblingExtensionQ  ss    
 ~.##BNN$4v$=>%%f-gx'8'89gllC0r#   c                   [         R                  " U R                  5       5      nUR                  5         [         R                  " U R                  5       5      nU R	                  UR                  S5      UR                  5       5        U R	                  UR                  S5      UR                  5       5        U R	                  UR                  S5      S5        U R	                  UR                  S5      S5        g)zf
C{siblingExtension} passed an empty string should return the same path,
in the type of its argument.
r#   r*  N)r   rV   r   r  re   r  asBytesModer  )r    r   	notExistss      r!   test_selfSiblingExtensionSearch4UnicodeFilePathTests.test_selfSiblingExtensionSearch_  s    
 ""4;;=1%%dkkm4	66s;V=O=O=QR66r:F<M<M<OP99"=tD99#>Er#   c                j  ^ [         R                  " S5      mTR                  5         U R                  U4S j5        TR	                  S5      nUR                  5         TR                  S5      nUc   eU R                  U[         R                  5        U R                  UR                  [        5        g)zv
C{childSearchPreauth} called with L{bytes} on a L{unicode}-mode
L{FilePath} will return a L{bytes}-mode L{FilePath}.
r  c                 $   > T R                  5       $ r2   r   r   s   r!   r*  GUnicodeFilePathTests.test_mixedTypeChildSearchPreauth.<locals>.<lambda>s      		r#   text.txts   text.txtN)
r   rV   r  r  rf   r  childSearchPreauthr  r4   r&   r    rf   rg  r   s      @r!    test_mixedTypeChildSearchPreauth5UnicodeFilePathTests.test_mixedTypeChildSearchPreauthl  s    
 ~.
+,$''4"""gx'8'89gllE2r#   c                j  ^ [         R                  " S5      mTR                  5         U R                  U4S j5        TR	                  S5      nUR                  5         TR                  S5      nUc   eU R                  U[         R                  5        U R                  UR                  [        5        g)zz
C{childSearchPreauth} called with L{unicode} on a L{unicode}-mode
L{FilePath} will return a L{unicode}-mode L{FilePath}.
r  c                 $   > T R                  5       $ r2   rz  r{  s   r!   r*  EUnicodeFilePathTests.test_unicodeChildSearchPreauth.<locals>.<lambda>  r}  r#   r~  N)
r   rV   r  r  rf   r  r  r  r4   r5  r  s      @r!   test_unicodeChildSearchPreauth3UnicodeFilePathTests.test_unicodeChildSearchPreauth}  s    
 ~.
+,$''
3"""gx'8'89gllC0r#   c                    [         R                  " S5      nUR                  5       nU R                  X5        U R	                  UR
                  [        5        g)Z
C{asBytesMode} on a L{unicode}-mode L{FilePath} returns a new
L{bytes}-mode L{FilePath}.
./tmpN)r   rV   rt  r   r  r4   r&   r    r   newfps      r!   test_asBytesModeFromUnicode0UnicodeFilePathTests.test_asBytesModeFromUnicode  sB    
 w' #ejj%0r#   c                    [         R                  " S5      nUR                  5       nU R                  X5        U R	                  UR
                  [        5        g)r     ./tmpN)r   rV   r  r   r  r4   r5  r  s      r!   test_asTextModeFromBytes-UnicodeFilePathTests.test_asTextModeFromBytes  sA    
 x(#ejj#.r#   c                    [         R                  " S5      nUR                  5       nU R                  X5        U R	                  UR
                  [        5        g)z[
C{asBytesMode} on a L{bytes}-mode L{FilePath} returns the same
L{bytes}-mode L{FilePath}.
r  N)r   rV   rt  r   r  r4   r&   r  s      r!   test_asBytesModeFromBytes.UnicodeFilePathTests.test_asBytesModeFromBytes  s@    
 x( b ejj%0r#   c                    [         R                  " S5      nUR                  5       nU R                  X5        U R	                  UR
                  [        5        g)z^
C{asTextMode} on a L{unicode}-mode L{FilePath} returns the same
L{unicode}-mode L{FilePath}.
r  N)r   rV   r  r   r  r4   r5  r  s      r!   test_asTextModeFromUnicode/UnicodeFilePathTests.test_asTextModeFromUnicode  s?    
 w'b ejj#.r#   c                    [         R                  " S5      nUR                  SS9nU R                  SUR                  5        g)z
C{asBytesMode} with an C{encoding} argument uses that encoding when
coercing the L{unicode}-mode L{FilePath} to a L{bytes}-mode L{FilePath}.
   ☃r   encoding   ☃N)r   rV   rt  r4  r4   r  s      r!   'test_asBytesModeFromUnicodeWithEncoding<UnicodeFilePathTests.test_asBytesModeFromUnicodeWithEncoding  s6    
 x(0ouzz2r#   c                    [         R                  " S5      nUR                  SS9nU R                  SUR                  5        g)z
C{asTextMode} with an C{encoding} argument uses that encoding when
coercing the L{bytes}-mode L{FilePath} to a L{unicode}-mode L{FilePath}.
r  r   r  r  N)r   rV   r  r4  r4   r  s      r!   $test_asTextModeFromBytesWithEncoding9UnicodeFilePathTests.test_asTextModeFromBytesWithEncoding  s6    
 /w/h

+r#   c                    [         R                  " S5      nU R                  [        5         UR	                  SS9  SSS5        g! , (       d  f       g= f)zu
C{asBytesMode} with an C{encoding} argument that can't be used to encode
the unicode path raises a L{UnicodeError}.
r  asciir  N)r   rV   rm   UnicodeErrorrt  r   s     r!   /test_asBytesModeFromUnicodeWithUnusableEncodingDUnicodeFilePathTests.test_asBytesModeFromUnicodeWithUnusableEncoding  s<    
 x(|,NNGN, -,,   A
Ac                    [         R                  " S5      nU R                  [        5         UR	                  SS9  SSS5        g! , (       d  f       g= f)zt
C{asTextMode} with an C{encoding} argument that can't be used to encode
the unicode path raises a L{UnicodeError}.
s   \u2603zutf-32r  N)r   rV   rm   r  r  r   s     r!   ,test_asTextModeFromBytesWithUnusableEncodingAUnicodeFilePathTests.test_asTextModeFromBytesWithUnusableEncoding  s<    
 z*|,MM8M, -,,r  r$   Nr   )-r'   r(   r)   r*   r+   r  r  r  r  r"  r&  r)  r,  r/  r2  r   r   r   r:  r>  rA  rD  rJ  rN  rR  rU  rX  r^  rb  rh  rk  rn  rq  rv  r  r  r  r  r  r  r  r  r  r  r,   r$   r#   r!   r  r  k  sJ   
-2002/2020 H "AB@ C@ H "ABQ CQ ""$$&BC; D; ""$$&BC< D<75210753131F3"1"1/1/3,--r#   r  )8r+   
__future__r   rC  ior3   r  rV  sysrP   pprintr   typingr   r   r   r   r	   r
   r   r   r   unittestr   zope.interface.verifyr   typing_extensionsr   twisted.pythonr   twisted.python.filepathr   r   twisted.python.runtimer   twisted.python.win32r   twisted.trial.unittestr   r   _supportsSymlinksr  r   r.   rV   r   r   r   r   r  r  r&  r(  r  r  r  r$   r#   r!   <module>r     s4   #  	 	   
   T T T  . & # 9 + 0 B,,..	5H 	5z6M z6z
h''/ 
4 <<7 #! #!L! !H<x((0 <~/?))&1 /?d CL]O} ]O@g>) g>TU5m U5pm-8 m-r#   