HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/lib/python3/dist-packages/twisted/test/__pycache__/test_paths.cpython-38.pyc
U


W[u"�@sjdZddlmZmZddlZddlZddlZddlZddlZddl	m
Z
ddlmZm
Z
mZddlmZmZddlmZddlmZdd	lmZmZdd
lmZe��s�dZndZGdd
�d
e�ZGdd�de�ZGdd�dej �Z!Gdd�de�Z"Gdd�d�Z#Gdd�dej �Z$Gdd�dej �Z%Gdd�de�Z&Gdd�de�Z'Gdd�de�Z(Gd d!�d!e�Z)dS)"z1
Test cases covering L{twisted.python.filepath}.
�)�division�absolute_importN)�pformat)�_PY3�long�unicode)�WindowsError�ERROR_DIRECTORY)�filepath)�platform)�SkipTest�SynchronousTestCase)�verifyObjectz"Platform does not support symlinksc@seZdZdZdd�ZdS)�
BytesTestCasezH
    Override default method implementations to support byte paths.
    cCst�|��d�S)z<
        Return a temporary path, encoded as bytes.
        �utf-8)�TestCase�mktemp�encode��self�r�9/usr/lib/python3/dist-packages/twisted/test/test_paths.pyr!szBytesTestCase.mktempN)�__name__�
__module__�__qualname__�__doc__rrrrrrsrc@s�eZdZdZdZdZdd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*S)+�AbstractFilePathTestsz1
    Tests for L{IFilePath} implementations.
    �file 1sfile 2cGs,tj�tjj|jf|���}|j�|�|S�N)�os�path�abspath�join�cmn�all�append)r�p�xrrr�_mkpath1szAbstractFilePathTests._mkpathcGst�|j|��dSr)r�mkdirr(�r�dirnamerrr�subdir7szAbstractFilePathTests.subdircGst|j|�d�S)N�wb)�openr(r*rrr�subfile;szAbstractFilePathTests.subfilec	Cs�t��|_tj�|���}|_|g|_t�|�|�	d�|�
d��}|�|j�W5QRX|�
dd��}|�|j
�W5QRX|�	d�|�
dd���|�
dd���|�
dd���t�|�|_t�d�|_dS)	N�sub1�file1�file2�sub3�
file3.ext1s
file3.ext2s
file3.ext3�/)�timeZnowrr r!rr#r$r)r,r/�write�	f1content�	f2content�closer
�FilePath�root)rr#�frrr�setUp?s



zAbstractFilePathTests.setUpcCs|�ttj|j��dS)zO
        Instances of the path type being tested provide L{IFilePath}.
        N)�
assertTruerr
Z	IFilePathr rrrr�test_verifyObjectQsz'AbstractFilePathTests.test_verifyObjectcCs2|�|j�d��d��d��|j�dddg�dS)zV
        Verify that the segments between two paths are correctly identified.
        �a�b�cN)�assertEqualr �child�segmentsFromrrrr�test_segmentsFromPositiveXs�z/AbstractFilePathTests.test_segmentsFromPositivecCs<|�t|j�d��d��d�j|j�d��d��d��dS)zW
        Verify that segmentsFrom notices when the ancestor isn't an ancestor.
        rArBrC�d�eN)�assertRaises�
ValueErrorr rErFrrrr�test_segmentsFromNegativeas
�z/AbstractFilePathTests.test_segmentsFromNegativecCs.dd�|j��D�}|�t|�t|j��dS)zi
        Verify that walking the path gives the same result as the known file
        hierarchy.
        cSsg|]
}|j�qSr�r ��.0Zfoorrr�
<listcomp>psz3AbstractFilePathTests.test_walk.<locals>.<listcomp>N)r �walkrD�setr$)rr'rrr�	test_walkkszAbstractFilePathTests.test_walkcCsxg}|j�d��d��d�}|j}|}tj�|�}||jjkrZ|�|�|}tj�|�}q2|�dd�|��D�|�dS)z{
        L{FilePath.parents()} should return an iterator of every ancestor of
        the L{FilePath} in question.
        rArBrCcSsg|]
}|j�qSrrM�rOr'rrrrP�sz6AbstractFilePathTests.test_parents.<locals>.<listcomp>N)r rErr+r<r%rD�parents)r�LZpathobj�fullpathZlastpathZthispathrrr�test_parentsts
z"AbstractFilePathTests.test_parentscCsb|j�d�}|�|��d�|�|��d�|�|��d�|�|��d�|�|�	�dg�dS)z�
        Verify that a valid subdirectory will show up as a directory, but not as a
        file, not as a symlink, and be listable.
        r0zThis directory does exist.zIt's a directory.r2N)
r rEr?�exists�isdir�assertFalse�isfile�islinkrD�listdir)rZsub1rrr�test_validSubdir�s 
�
�
�
�
�z&AbstractFilePathTests.test_validSubdircCs |j�d�}|�|��d�dS)zT
        Verify that a subdirectory that doesn't exist is reported as such.
        �sub2zThis directory does not exist.N)r rEr[rY)rZsub2rrr�test_invalidSubdir�s
�z(AbstractFilePathTests.test_invalidSubdirc	Csn|j�d�}|���}|�|��|j�W5QRX|j�d��d�}|���}|�|��|j�W5QRXdS)zF
        Make sure that we can read existent non-empty files.
        r1r0r2N)r rEr.rD�readr8r9)r�f1r=�f2rrr�test_validFiles�s

z%AbstractFilePathTests.test_validFilescCs:|j�dddg�}|j�d��d��d�}|�||�dS)z�
        C{fp.descendant([a, b, c])} returns the same L{FilePath} as is returned
        by C{fp.child(a).child(b).child(c)}.
        rArBrCN)r �
descendantrErD)rZmultipleZsinglerrr�test_multipleChildSegments�sz0AbstractFilePathTests.test_multipleChildSegmentscCs�|j�d�}|j�d�}|j�d�}i}d||<d||<|�||d�|�t|���|g�|�t|���d|�|�t|���d|�d||<|�||d�|�t|�d�dS)	zK
        Verify that path instances are usable as dictionary keys.
        r1r2��r��N)r rErD�list�keys�assertIs�assertIsNot�len)rrcZf1primerd�dictoidrrr�test_dictionaryKeys�sz)AbstractFilePathTests.test_dictionaryKeyscCs2|j�d�}|di}d||j<|�t|�d�dS)z�
        Verify that path instances are usable as dictionary keys which do not clash
        with their string counterparts.
        r1ZhelloZgoodbyerkN)r rErDrp)rrcrqrrr�test_dictionaryKeyWithString�s
z2AbstractFilePathTests.test_dictionaryKeyWithStringcCs|�tj|j�d�j�dS)zm
        Verify that children raises the appropriate exception for non-existent
        directories.
        snot realN�rJr
�UnlistableErrorr rE�childrenrrrr�test_childrenNonexistentError�s�z3AbstractFilePathTests.test_childrenNonexistentErrorcCs|�tj|j�d�j�dS)z�
        Verify that listdir raises the appropriate exception for attempting to list
        a file rather than a directory.
        r1Nrtrrrr�test_childrenNotDirectoryError�s�z4AbstractFilePathTests.test_childrenNotDirectoryErrorcCsX|j|j�d�fD]@}|�t|���t�|�t|���t�|�t|���t�qdS)z�
        Verify that all times returned from the various new time functions are ints
        (and hopefully therefore 'high precision').
        r1N)r rErD�typeZ
getAccessTime�floatZgetModificationTimeZgetStatusChangeTime�rr&rrr�test_newTimesAreFloats�sz,AbstractFilePathTests.test_newTimesAreFloatscCsX|j|j�d�fD]@}|�t|���t�|�t|���t�|�t|���t�qdS)zy
        Verify that all times returned from the various time functions are
        integers, for compatibility.
        r1N)r rErDry�getatime�int�getmtime�getctimer{rrr�test_oldTimesAreInts�sz*AbstractFilePathTests.test_oldTimesAreIntsN)rrrrr8r9r(r,r/r>r@rGrLrSrXr_rarergrrrsrwrxr|r�rrrrr)s,	
	
	rc@seZdZdZdd�ZdS)�FakeWindowsPathzV
    A test version of FilePath which overrides listdir to raise L{WindowsError}.
    cCs$trtdd|jt��n
ttd��dS)z.
        @raise WindowsError: always.
        Nz0A directory's validness was called into question)rrr r	rrrrr^s
��zFakeWindowsPath.listdirN)rrrrr^rrrrr��sr�c@s6eZdZdZdd�Ze��s"de_dd�Zdd�Z	d	S)
�ListingCompatibilityTestszU
    These tests verify compatibility with legacy behavior of directory listing.
    cCs.t|���}|�tj|j�|�t|j�dS)zn
        Verify that when a WindowsError is raised from listdir, catching
        WindowsError works.
        N)r�rrJr
rurvr)rZfwprrr�test_windowsErrorExceptsz1ListingCompatibilityTests.test_windowsErrorExceptzOnly relevant on on Windows.cCs t�|���}|�t|j�dS)zr
        Verify that in the normal case where a directory does not exist, we will
        get an OSError.
        N)r
r;rrJ�OSErrorrv�r�fprrr�test_alwaysCatchOSError,sz1ListingCompatibilityTests.test_alwaysCatchOSErrorcCsdt�|���}|�t|j�}t|j���}|�	d�t|j
j���}|��|��|�||�dS)z�
        Verify that the Unlistable exception raised will preserve the attributes of
        the previously-raised exception.
        �originalExceptionN)
r
r;rrJr�rvrl�__dict__rm�remover��sortrD)rr�ZoseZd1Zd2rrr�test_keepOriginalAttributes5s
z5ListingCompatibilityTests.test_keepOriginalAttributesN)
rrrrr�r�	isWindows�skipr�r�rrrrr�s		r�c@s>eZdZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�
ExplodingFilez�
    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}.
    FrcCs
t��dS�z0
        @raise IOError: Always raised.
        N��IOError)r�nrrrrbOszExplodingFile.readcCs
t��dSr�r�)r�whatrrrr7VszExplodingFile.writecCs
d|_dS)z6
        Mark the file as having been closed.
        TN)�closedrrrrr:]szExplodingFile.closecCs|Srrrrrr�	__enter__dszExplodingFile.__enter__cCs|��dSr)r:)r�exc_type�	exc_value�	tracebackrrr�__exit__hszExplodingFile.__exit__N)r)
rrrrr�rbr7r:r�r�rrrrr�Es
r�c@s2eZdZdZddd�Zdd�Zdd	�Zd
d�ZdS)
�TrackingFilePathac
    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}
    FNcCs,tj�|||�|dkrg}||_g|_dSr)r
r;�__init__�trackingList�openedFiles)rr ZalwaysCreater�rrrr�s
zTrackingFilePath.__init__cOs$tjj|f|�|�}|j�|�|S)zI
        Override 'open' to track all files opened by this path.
        )r
r;r.r�r%)r�a�kr=rrrr.�szTrackingFilePath.opencCsdd�|jD�S)z�
        Return a list of all L{TrackingFilePath}s associated with this
        L{TrackingFilePath} that have had their C{open()} method called.
        cSsg|]}|jr|�qSr)r�)rOr rrrrP�sz0TrackingFilePath.openedPaths.<locals>.<listcomp>�r�rrrr�openedPaths�szTrackingFilePath.openedPathscCst||jd�}|j�|�|S)z}
        Override L{filepath.FilePath.clonePath} to give the new path a reference
        to the same tracking list.
        r�)r�r�r%)r�nameZclonerrr�	clonePath�szTrackingFilePath.clonePath)FN)rrrrr�r.r�r�rrrrr�ms

	r�c@s,eZdZdZd	dd�Zd
dd�Zdd�ZdS)�ExplodingFilePathz�
    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.
    NcCs$tj�||�|dkr|}||_dS)aY
        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
r;r��_originalExploder)rZpathNameZoriginalExploderrrrr��szExplodingFilePath.__init__cCst�}|j_|S)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�moder=rrrr.�szExplodingFilePath.opencCst||j�Sr)r�r�)rr�rrrr��szExplodingFilePath.clonePath)N)N)rrrrr�r.r�rrrrr��s

r�c@sJeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�PermissionsTestsz*
    Test Permissions and RWX classes
    NcCsH||krD|dkrd}t|�dkr(|d7}|�d|t|�t|�f��|S)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
        N�r�
zD%snot not unequal (__ne__ not implemented correctly):
a = %s
b = %s
)rpZfailureExceptionr)r�first�second�msgrrr�assertNotUnequal�s��z!PermissionsTests.assertNotUnequalcCs�dD]P}dD]F}dD]<}t�|||�}|�|j|�|�|j|�|�|j|�qqqt�ddd�}|�|jox|jox|j�dS)z>
        L{RWX}'s constructor takes a set of booleans
        �TFTN)r
�RWXrDrbr7�executer?)r�r�wr'�rwxrrr�test_rwxFromBools�sz"PermissionsTests.test_rwxFromBoolscCs�dD]X}dD]N}dD]D}|�t�|||�t�|||��|�t�|||�t�|||��qqq|�t�ddd�t�ddd��|�dt�ddd��dS)z�
        L{RWX}'s created with the same booleans are equivalent.  If booleans
        are different, they are not equal.
        r�TFrhN)rDr
r�r��assertNotEqual)rr�r�r'rrr�test_rwxEqNe�s��
�zPermissionsTests.test_rwxEqNec
Cs|dd�}dD]P}dD]F}dD]<}t�|||�}|�|��||d�||d�||d��qqq|�t�ddd���d	�d
S)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 '-'.
        cSs|r|SdS)N�-r)�valZletterrrr�getCharsz3PermissionsTests.test_rwxShorthand.<locals>.getCharr�r�r�r'TFzr-xN)r
r�rD�	shorthand)rr�r�r�r'r�rrr�test_rwxShorthands
���
z"PermissionsTests.test_rwxShorthandc

Cs�dd�}tdd�D]�}tdd�D]�}tdd�D]�}d|||f}t|d�}t�|�}|�|j||d�d||jf�|�|j||d�d	||jf�|�|j||d
�d||jf�q.q qt�d�}d
D]$}dD]}	|�t	t	||�|	��q�q�dS)z�
        L{Permissions}'s constructor takes a valid permissions bitmask and
        parsaes it to produce the correct set of boolean permissions.
        cs&�fdd��tj��fdd�dD��S)Ncs�ttd||f�@dkS)NzS_I%s%sr)�getattr�stat)r��who)�statModeIntrr�getPermissionBit$s
��zYPermissionsTests.test_permissionsFromStat.<locals>._rwxFromStat.<locals>.getPermissionBitcsg|]}�|���qSrr)rOr�)r�r�rrrP'szSPermissionsTests.test_permissionsFromStat.<locals>._rwxFromStat.<locals>.<listcomp>)�R�W�X)r
r�)r�r�r)r�r�r�r�_rwxFromStat#s�z?PermissionsTests.test_permissionsFromStat.<locals>._rwxFromStatr�z%d%d%dZUSRz%s: got user: %sZGRPz%s: got group: %sZOTHz%s: got other: %s�)�user�group�other)rbr7r�N)
�ranger~r
�PermissionsrDr�r�r�r?r�)
rr��u�g�oZchmodStringZchmodVal�permr�r�rrr�test_permissionsFromStats:

������

z)PermissionsTests.test_permissionsFromStatcCs^|�t�d�t�d��|�t�d�t�d��|�t�d�t�d��|�dt�d��dS)zd
        Two L{Permissions}'s that are created with the same bitmask
        are equivalent
        r��rhN)rDr
r�r�r�rrrr�test_permissionsEqBs���z#PermissionsTests.test_permissionsEqcCs�tdd�D]j}tdd�D]Z}tdd�D]J}t�td|||fd��}|�|��d�dd�|j|j|j	fD���q&qq
|�t�d���d�d	S)
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.
        rr�z0o%d%d%dr�css|]}|��VqdSr)r�rTrrr�	<genexpr>[sz=PermissionsTests.test_permissionsShorthand.<locals>.<genexpr>i�z	rwxrwx---N)
r�r
r�r~rDr�r"r�r�r�)rr�r�r�r�rrr�test_permissionsShorthandPs

��
z*PermissionsTests.test_permissionsShorthand)N)rrrrr�r�r�r�r�r�r�rrrrr��s
$r�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zer�ee_ee_ee_dd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Ze��d*kr�d+e_d,d-�Ze��d*kr�d+e_d.d/�Zd0d1�Zd2d3�Zd4d5�Z d6d7�Z!d8d9�Z"d:d;�Z#d<d=�Z$d>d?�Z%d@dA�Z&dBdC�Z'dDdE�Z(dFdG�Z)dHdI�Z*dJdK�Z+dLdM�Z,dNdO�Z-dPdQ�fdRdS�Z.dTdU�Z/dVdW�Z0dXdY�Z1dZd[�Z2d\d]�Z3d^d_�Z4d`da�Z5dbdc�Z6ddde�Z7dfdg�Z8dhdi�Z9djdk�Z:dldm�Z;dndo�Z<dpdq�Z=drds�Z>dtdu�Z?dvdw�Z@dxdy�ZAdzd{�ZBd|d}�ZCd~d�ZDd�d��ZEd�d��ZFd�d��ZGd�d��ZHd�d��ZId�d��ZJe�K��r�d�eI_d�eJ_d�eA_nd+eH_d+eF_d�S)��
FilePathTestsz�
    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
CsDdD]:}|j�d��|�|�t�t�|j�d�j�j�|�qdS)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).
        )�mr�r0N)r rE�chmodrDr��S_IMODEr�st_mode�rr�rrr�
test_chmodhs�zFilePathTests.test_chmodcCstrtt��t�||�dS)z�
        Create a symbolic link named C{name} pointing at C{target}.

        @type target: C{str}
        @type name: C{str}
        @raise SkipTest: raised if symbolic links are not supported on the
            host platform.
        N)�symlinkSkiprr�symlink)r�targetr�rrrr�us	zFilePathTests.symlinkcCsZ|j�d�}|�|j|�d��|�|�d�j|�d��|�|�d�j|�dd��dS)zI
        Create several symbolic links to files and directories.
        r0�	sub1.linkr2�
file2.linkssub1.file2.linkN)r rEr�r()rr,rrr�createLinks�s
�zFilePathTests.createLinkscCsR|��|�|j�d�j|j�d�j�|�|j�d���|j�d��d��dS)zd
        L{FilePath.realpath} returns the path of the ultimate target of a
        symlink.
        r�s	link.linkr0r2N)r�r�r rErD�realpathrrrr�test_realpathSymlink�s��z"FilePathTests.test_realpathSymlinkcCs\|�|j�d�j|j�d�j�|�|j�d�j|j�d�j�|�tj|j�d�j�dS)z�
        L{FilePath.realpath} raises L{filepath.LinkError} if the path is a
        symbolic link which is part of a cycle.
        �link1slink2N)r�r rErJr
�	LinkErrorr�rrrr�test_realpathCyclicalSymlink�s
  �z*FilePathTests.test_realpathCyclicalSymlinkcCs$|�|j�d���|j�d��dS)zj
        L{FilePath.realpath} returns the path itself if the path is not a
        symbolic link.
        r0N)rDr rEr�rrrr�test_realpathNoSymlink�s
�z$FilePathTests.test_realpathNoSymlinkcsL������j�d�j�j�d��d�j��fdd�}��tj|�dS)zT
        Verify that walking a path with a cyclical symlink raises an error
        r0�sub1.loopylinkcsdd��j��D�S)NcSsg|]
}|j�qSrrMrNrrrrP�szSFilePathTests.test_walkCyclicalSymlink.<locals>.iterateOverPath.<locals>.<listcomp>�r rQrrrr�iterateOverPath�sz?FilePathTests.test_walkCyclicalSymlink.<locals>.iterateOverPathN)r�r�r rErJr
r��rr�rrr�test_walkCyclicalSymlink�s�z&FilePathTests.test_walkCyclicalSymlinkcsT������j�d�j�j�d��d�j�dd����fdd�}��|��dS)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.
        r0r�cSs
|��Sr�r]rMrrr�
noSymLinks�szKFilePathTests.test_walkObeysDescendWithCyclicalSymlinks.<locals>.noSymLinkscsdd��jj�d�D�S)NcSsg|]
}|j�qSrrMrNrrrrP�szdFilePathTests.test_walkObeysDescendWithCyclicalSymlinks.<locals>.iterateOverPath.<locals>.<listcomp>�Zdescendr�r�r�rrrr��szPFilePathTests.test_walkObeysDescendWithCyclicalSymlinks.<locals>.iterateOverPathN)r�r�r rEr?r�rr�r�)test_walkObeysDescendWithCyclicalSymlinks�s�z7FilePathTests.test_walkObeysDescendWithCyclicalSymlinkscCsB|��dd�}dd�|jj|d�D�}|�t|�t|j��dS)z{
        Verify that when the supplied C{descend} predicate returns C{False},
        the target is not traversed.
        cSs
|��Srr�rMrrrr��sz7FilePathTests.test_walkObeysDescend.<locals>.noSymLinkscSsg|]
}|j�qSrrMrNrrrrP�sz7FilePathTests.test_walkObeysDescend.<locals>.<listcomp>r�N)r�r rQrDrRr$)rr�r'rrr�test_walkObeysDescend�sz#FilePathTests.test_walkObeysDescendcCsjd}|j�d��|�|j�d���}|�||�d}|j�d��|d�|j�d���}|�||�dS)Ns
newcontentsnewscontents.tmp)r rE�
setContent�
getContentrD)rZcontentZ
newcontentrrr�test_getAndSet�szFilePathTests.test_getAndSetcCs(td�}|�t|j�|�|jj�dS)z�
        If reading from the underlying file raises an exception,
        L{FilePath.getContent} raises that exception after closing the file.
        �N)r�rJr�r�r?r�r�r�rrr�test_getContentFileClosing�sz(FilePathTests.test_getContentFileClosingcCsd|j�d�}|j�d�}|�|j|j�|�|���|�|���|�|���|�|���dS)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.
        ssub4r3N)r rEr�r?r]r[rZ)rZs4Zs3rrr�test_symbolicLink�szFilePathTests.test_symbolicLinkcCs�|j�d�|j�d�f|j�d��d�|j�d�fg}|D]J\}}|�|�|�|��d�|�|��|���|�|��|���q:dS)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.linkr4sfile3.ext1.linkzThis is a linkN)r rE�linkTor?r]rDrZr\)rZtargetLinksr��linkrrr�test_linkTo�s
��
zFilePathTests.test_linkTocCsP|�t|j�d�j|j�d��d��|�t|j�d�j|j�d��d��dS)z�
        Verify C{linkTo} fails in the following case:
            - the target is in a directory that doesn't exist
            - the target already exists
        r1snosubr0r2N)rJr�r rEr�rrrr�test_linkToErrors
s��zFilePathTests.test_linkToErrorscCs�|j�d��d�}d}|�|j|��|�d�}|��|�|j|����|�|�d����|��|�|j|��dS)Nr3�file3)�.foos.barsext1sext2sext3r�*)r rEr[�siblingExtensionSearch�siblingExtension�touchrYr�)r�f3ZextsZf3errr�testMultiExts
zFilePathTests.testMultiExtcCs*t�d�}|�d�|�tj|jd�dS)N�.sfoo/bar�/mon€y)r
r;�preauthChildrJ�InsecurePathrEr�rrr�testPreauthChild*s

zFilePathTests.testPreauthChildcCs|j�d�}|��|�|��d�|�t|��t���dd�|�t|��t���dd�|�t|�	�t���dd�|�
|���|�
|���t�
|j�|�
|���|jdd�|�|���|�|���|�|���|�|���dS)Nsstattestr�F)Zreraise)r rErrD�getsize�absrr6r�r}r?rYrr��restatr[r]rZr\r{rrr�
testStatCache/s   zFilePathTests.testStatCachecCs:t�t�|j��}|�|jj|j�|�|jj|j�dSr)�pickle�loads�dumpsr rD�	__class__)r�newpathrrr�testPersistBszFilePathTests.testPersistcCs@|�tj|jjd�|�tj|jjd�|�tj|jjd�dS)Ns..s/etcs../..�rJr
r
r rErrrr�testInsecureUNIXGszFilePathTests.testInsecureUNIXcCs,|�tj|jjd�|�tj|jjd�dS)Ns..\..sC:randomfilerrrrr�testInsecureWin32LszFilePathTests.testInsecureWin32Zwin32zTest will run only on Windows.cCs@|�tj|jjd�|�tj|jjd�|�tj|jjd�dS)a

        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.
        sCONsC:CONzC:\CONNrrrrr�testInsecureWin32WhackyTsz%FilePathTests.testInsecureWin32WhackycCs|�t�d�t�d��|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�|�t�d�t�d�k�dS)NrA�z)rDr
r;r?r[rrrr�testComparisoncs<����������zFilePathTests.testComparisoncCs|�tj|jjddg�dS)zt
        If C{".."} is in the sequence passed to L{FilePath.descendant},
        L{InsecurePath} is raised.
        �mon€yz..N)rJr
r
r rfrrrr�test_descendantOnly{s
�z!FilePathTests.test_descendantOnlycCsX|j�d�}|�d�}|�|��|���|�|��d�|��|�||j���dS)Ns
sibling_startssibling_test)	r rE�siblingrDr+�basename�createDirectory�assertInrv)rr&�tsrrr�testSibling�s
zFilePathTests.testSiblingcCsX|j��}|�|��|j���|�|��|j���|��|�||j�	��
��dSr)r �temporarySiblingrDr+ZassertNotInr r^r!r"�parentrv)rr#rrr�testTemporarySibling�s

z"FilePathTests.testTemporarySiblingcCs6d}|j�|�}|�|���|�d|��|f�dS)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%s does not end with %sN)r r%r?r �endswith)rZ
testExtensionr#rrr�test_temporarySiblingExtension�s��z,FilePathTests.test_temporarySiblingExtensioncCs|j��|�|j���dS)z~
        L{FilePath.remove} on a L{FilePath} that refers to a directory will
        recursively delete its contents.
        N)r r�r[rYrrrr�test_removeDirectory�s
z"FilePathTests.test_removeDirectorycCsT|j�d�}|�|j�d�j|j�|��|�|���|�|j�d����dS)zx
        For a path which is a symbolic link, L{FilePath.remove} just deletes
        the link, not the target.
        r�r0N)r rEr�r�r[rYr?)rr�rrr�test_removeWithSymlink�s
z$FilePathTests.test_removeWithSymlinkcCslt|j���}t�|���}|j�|�|j��|�|j�t|j���}|��|��|�	||�dS)z�
        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)
rlr rQr
r;r�copyTor�r�rD�rZoldPathsr�ZnewPathsrrr�test_copyToDirectory�s
z"FilePathTests.test_copyToDirectorycCsD|j�d�}dd�|_t|���}|�t|j|�|�|j	j
�dS)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}.
        snotherecSsdS)NTrrrrr�<lambda>�r�zAFilePathTests.test_copyToMissingDestFileClosing.<locals>.<lambda>N)r rEr\r�rrJr�r,r?r�r�)rZnosuch�destinationrrr�!test_copyToMissingDestFileClosing�s

z/FilePathTests.test_copyToMissingDestFileClosingcCsDt|���}tt�}|�t|j|�|�|jj�|�|jj�dS)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__rJr�r,r?r�r�)rr0�sourcerrr�test_copyToFileClosing�s
z$FilePathTests.test_copyToFileClosingcCs"|�ttf|jj|j�d��dS)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.
        r1N)rJr�r�r r,rErrrr�test_copyToDirectoryItself�s

�z(FilePathTests.test_copyToDirectoryItselfcCs�|�|j�d�j|j�d�j�t�|���}|j�|�|�|�d����|�	dd�|�d��
�D�dd�|�d��
�D��dS)zn
        Verify that copying with followLinks=True copies symlink targets
        instead of symlinks
        r0r�cSsg|]}|���qSr�r rTrrrrP�sz8FilePathTests.test_copyToWithSymlink.<locals>.<listcomp>cSsg|]}|���qSrr6rTrrrrP�sN)r�r rEr
r;rr,r[r]rDrvr�rrr�test_copyToWithSymlink�s��z$FilePathTests.test_copyToWithSymlinkcCsv|�d|j�d�j�t�|���}|jj|dd�|�|�d����|�	t
�|j�d�j�t
�|�d�j��dS)zX
        Verify that copying with followLinks=False copies symlinks as symlinks
        r0r�F�ZfollowLinksN)r�r rEr
r;rr,r?r]rDr�readlinkr�rrr�test_copyToWithoutSymlinks�z'FilePathTests.test_copyToWithoutSymlinkcCs2t�|���}|�t|jd�}|�|jtj�dS)zV
        If the source path is missing, L{FilePath.copyTo} raises L{OSError}.
        ssome other pathN)	r
r;rrJr�r,rD�errno�ENOENT)rr �excrrr�test_copyToMissingSourcesz&FilePathTests.test_copyToMissingSourcecCsbt|j���}t�|���}|j�|�|�|j�t|j���}|��|��|�||�dS)zv
        Verify that moving an entire directory results into another directory
        with the same content.
        N)	rlr rQr
r;r�moveTor�rDr-rrr�test_moveToszFilePathTests.test_moveTocCsjt�|���}t�|���}|��|�|���|�|���|�|�|�|���|�|���dS)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
r;rrr?rYr[r?)rr��fp2rrr�test_moveToExistsCache$s
z$FilePathTests.test_moveToExistsCachecCs|��|��dS)zp
        The assertion of test_moveToExistsCache should hold in the case of a
        cross-mount move.
        N)�setUpFaultyRenamerBrrrr� test_moveToExistsCacheCrossMount9sz.FilePathTests.test_moveToExistsCacheCrossMountcCsdSrrrrrrr/Br�zFilePathTests.<lambda>cCs�t�|���}t�|���}|�d�|�d�|�|�|��d�|�|��d�t�|j�|�|��d�|�	|�|�|��d�dS)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.
        s1234s
1234567890ri�
N)
r
r;rr�rDr
rr�r r?)r�hookr�rArrr�test_moveToSizeCacheBs


z"FilePathTests.test_moveToSizeCachecCs|j|jd�dS)zn
        The assertion of test_moveToSizeCache should hold in the case of a
        cross-mount move.
        )rFN)rGrCrrrr�test_moveToSizeCacheCrossMountbsz,FilePathTests.test_moveToSizeCacheCrossMountcCs"|�ttf|jj|j�d��dS)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.
        r1N)rJr�r�r r?rErrrr�test_moveToErrorjszFilePathTests.test_moveToErrorcs*g���fdd�}tj�|�td|��S)a
        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}
        cs0��||f�t��dkr&ttjd���||�S)N�z;Test-induced failure simulating cross-device rename failure)r%rpr�r;ZEXDEV)�src�dest��invokedWithZoriginalRenamerr�faultyRename|sz5FilePathTests.setUpFaultyRename.<locals>.faultyRename�rename)rrP�patch)rrOrrMrrCss
zFilePathTests.setUpFaultyRenamecCs|��}|��|�|�dS)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)rCr@r?)rrNrrr�test_crossMountMoveTo�sz#FilePathTests.test_crossMountMoveTocCsn|��}|j�d�}|j�d�}|�|j�d�j|j�|�|�|�|���|�|��d�|�	|�dS)z�
        By default, when moving a symlink, it should follow the link and
        actually copy the content of the linked node.
        r2r�r1rN)
rCr rEr�r?r[r]rDr�r?�rrNrdrrrr� test_crossMountMoveToWithSymlink�s
z.FilePathTests.test_crossMountMoveToWithSymlinkcCsr|��}|j�d�}|j�d�}|�|j�d�j|j�|j|dd�|�|���|�|��d�|�|�dS)zk
        Verify that moveTo called with followLinks=False actually create
        another symlink.
        r2r�r1Fr8rN)	rCr rEr�r?r?r]rDr�rSrrr�#test_crossMountMoveToWithoutSymlink�sz1FilePathTests.test_crossMountMoveToWithoutSymlinkc	Csjt�|���}|���}|�d|j�|�d�W5QRXt|jd��}|�	�}|�
|d�W5QRXdS)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�
�rbN)r
r;r�creater"r�r7r.r rbrD)rr r=r�rbrrr�test_createBinaryMode�s	
z#FilePathTests.test_createBinaryModec	CsH|j�d�}|�t|j�}|�|jtj�|j�d�}|�d��}|�d�W5QRX|���}|�|�	�d�W5QRX|�d��
�|���}|�|�	�d�W5QRX|j�d�}|�d��}|�d�W5QRX|�d��}|�d	�W5QRX|�d
��}|�|�	�d�W5QRX|�d��,}|�|�	�d�|�d
d�|�d�W5QRX|�d
��}|�|�	�d�W5QRX|�d��,}|�|�	�d�|�d
d�|�d�W5QRX|�d��H}|�d�|�d
d�|�|�	�d�|�d
d
�|�|�	�d�W5QRX|�d�|�d��
�|}~|�t
tf|j�dS)Nsnonexistentswriterr��abc
defr�sappendersabcr�sdefr�sabcdefzr+rrJsghis	abcdefghizw+s123za+s456s123456T)r rErJr�r.rDr;r<r7rbr:�seekZ
requireCreater�)rZnonexistent�e�writerr=ZappenderZexistentrrr�testOpen�sN



zFilePathTests.testOpenc	Cs<|j�d�}|�d��}|�d�W5QRX|�|j�dS)aj
        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.
        sexplicit-binaryr-r[N�r rEr.r7r?rY�rr^�filerrr�test_openWithExplicitBinaryModes	z-FilePathTests.test_openWithExplicitBinaryModec	Cs<|j�d�}|�d��}|�d�W5QRX|�|j�dS)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.  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.
        smultiple-binaryZwbbr[Nr`rarrr�)test_openWithRedundantExplicitBinaryModes's
z7FilePathTests.test_openWithRedundantExplicitBinaryModescCs6t�|���}|�|���|��|�|���dS)z�
        Check that C{filepath.FilePath.exists} correctly restat the object if
        an operation has occurred in the mean time.
        N)r
r;rr[rY�makedirsr?r�rrr�test_existsCache7szFilePathTests.test_existsCachecCsRt�tj�|��ddd��}|�|���|��|�	|���|�	|�
��dS)z�
        C{FilePath.makedirs} creates a directory at C{path}}, including
        recursively creating all parent directories leading up to the path.
        sfoosbarsbazN)r
r;rr r"rr[rYrer?rZr�rrr�(test_makedirsMakesDirectoriesRecursivelyCs
�z6FilePathTests.test_makedirsMakesDirectoriesRecursivelycCsHt�|���}|�|���|jdd�|�|���|�|���dS)z�
        Calling C{FilePath.makedirs} with C{ignoreExistingDirectory} set to
        C{True} has no effect if directory does not exist.
        T�ZignoreExistingDirectoryN)r
r;rr[rYrer?rZr�rrr�8test_makedirsMakesDirectoriesWithIgnoreExistingDirectoryRs
zFFilePathTests.test_makedirsMakesDirectoriesWithIgnoreExistingDirectorycCs@t�tj�|����}|��|�t|j�}|�	|j
t
j�dS)z}
        C{FilePath.makedirs} throws an C{OSError} exception
        when called on a directory that already exists.
        N)r
r;rr r"rrerJr�rDr;�EEXIST�rr��	exceptionrrr�(test_makedirsThrowsWithExistentDirectory`sz6FilePathTests.test_makedirsThrowsWithExistentDirectorycCsBt�|���}|��|�|���|jdd�|�|���dS)z�
        C{FilePath.makedirs} succeeds when called on a directory that already
        exists and the c{ignoreExistingDirectory} argument is set to C{True}.
        TrhN)r
r;rrer?rYr�rrr�+test_makedirsAcceptsIgnoreExistingDirectoryms
z9FilePathTests.test_makedirsAcceptsIgnoreExistingDirectorycCsJt�|���}|��|�|���|jt|jdd�}|�	|j
t
j�dS)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.
        TrhN)r
r;rrYr?r\rJr�rerDr;rjrkrrr�5test_makedirsIgnoreExistingDirectoryExistAlreadyAFile{s�zCFilePathTests.test_makedirsIgnoreExistingDirectoryExistAlreadyAFilecCsJdd�}|�td|�t�|���}|jt|jdd�}|�|j	t	j
�dS)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.
        cSsttjd��dS)NzPermission Denied)r�r;�EACCESrMrrr�faultyMakedirs�sz_FilePathTests.test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory.<locals>.faultyMakedirsreTrhN)rQrr
r;rrJr�rerDr;rp)rrqr�rlrrr�9test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectory�s�zGFilePathTests.test_makedirsRaisesNonEexistErrorsIgnoreExistingDirectoryc	Cs�t�|���}|�d�|�|��d�t|jd��}|�d�W5QRX|�|��d�|�	�|�
|j�|�|��d�dS)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}.
        s12345rjr-s12345678r�N)r
r;rr�rDr
r.r r7Zchanged�assertIsNone�statinfo)rr��fObjrrr�test_changed�s
zFilePathTests.test_changedcCsldD]4}|j�d��|�|�|j�d���t�|��q|j�d��d�|�|j�d�����d�dS)z�
        Getting permissions for a file returns a L{Permissions} object for
        POSIX platforms (which supports separate user, group, and other
        permissions bits.
        )r�r�r0��z	rwxrw-r--N)r rEr�rD�getPermissionsr
r�r�r�rrr�test_getPermissions_POSIX�s��z'FilePathTests.test_getPermissions_POSIXcCs^t�|���}|j|�|jg�}|�t|�d�|�|ddt�|�|ddd�dS)zU
        Getting L{twisted.python.filepath.FilePath.statinfo} is deprecated.
        rJr�category�message��twisted.python.filepath.FilePath.statinfo was deprecated in Twisted 15.0.0; please use other FilePath methods such as getsize(), isdir(), getModificationTime(), etc. insteadN)	r
r;rrt�
flushWarnings�test_deprecateStatinfoGetterrDrp�DeprecationWarning�rr��warningInforrrr~�s
�z*FilePathTests.test_deprecateStatinfoGettercCs^t�|���}d|_|�|jg�}|�t|�d�|�|ddt�|�|ddd�dS)zU
        Setting L{twisted.python.filepath.FilePath.statinfo} is deprecated.
        NrJrrzr{r|)	r
r;rrtr}�test_deprecateStatinfoSetterrDrprr�rrrr��s
�z*FilePathTests.test_deprecateStatinfoSettercCs$t�|���}d|_|�|j�dS)z�
        Setting L{twisted.python.filepath.FilePath.statinfo} changes the value
        of _statinfo such that getting statinfo again returns the new value.
        N)r
r;rrtrsr�rrr� test_deprecateStatinfoSetterSets�sz.FilePathTests.test_deprecateStatinfoSetterSetscCs,t�|���|�|jg�}|�|g�dS)z�
        While accessing L{twisted.python.filepath.FilePath.statinfo} is
        deprecated, the filepath itself is not.
        N)r
r;rr}�test_filePathNotDeprecatedrD)rr�rrrr��sz(FilePathTests.test_filePathNotDeprecatedcCs�|�|j�d�jd�dD]4}|j�d��|�|�|j�d���t�|��q|j�d��d�|�|j�d�����d�dS)aJ
        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.
        r0r�)r�r�iIz	r-xr-xr-xN)	�
addCleanupr rEr�rDrxr
r�r�r�rrr�test_getPermissions_Windows�s	��z)FilePathTests.test_getPermissions_WindowscCs$|�|j���|�|j���dS)z=
        Ensure that a file is not a block or socket
        N)r[r Z
isBlockDeviceZisSocketrrrr�test_whetherBlockOrSocket
sz'FilePathTests.test_whetherBlockOrSocketcCsT|�t|jj�|�t|jj�|�t|jj�|�t|jj�|�t|jj�dS)zM
        Verify that certain file stats are not available on Windows
        N)rJ�NotImplementedErrorr �getInodeNumber�	getDevice�getNumberOfHardLinks�	getUserID�
getGroupIDrrrr�(test_statinfoBitsNotImplementedInWindowss
z6FilePathTests.test_statinfoBitsNotImplementedInWindowscCs�ttf}|j�d�}|j|fD]T}|�|��|�|�|��|�|�|��|�|�|��|�|�|�	�|�q|�
|j��|���|�
|j�	�|�	��dS)zo
        Verify that file inode/device/nlinks/uid/gid stats are numbers in
        a POSIX environment
        r1N)r~rr rE�assertIsInstancer�r�r�r�r�rD)rZnumbers�cr&rrr�test_statinfoBitsAreNumbers sz)FilePathTests.test_statinfoBitsAreNumberscs�Gdd�d�}|����fdd�}|�j_d�j_���j���j����j���j����j���j	����j�
��j����j���j
�dS)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@s eZdZdZdZdZdZdZdS)z<FilePathTests.test_statinfoNumbersAreValid.<locals>.FakeStat��i,i�rwiXN)rrr�st_ino�st_dev�st_nlink�st_uid�st_gidrrrr�FakeStat7s
r�cs��j_dSr)r �	_statinfo)�args�kwargs�Zfakerrr�
fakeRestat@sz>FilePathTests.test_statinfoNumbersAreValid.<locals>.fakeRestatN)r rr�rDr�r�r�r�r�r�r�r�r�r�)rr�r�rr�r�test_statinfoNumbersAreValid1sz*FilePathTests.test_statinfoNumbersAreValidTN)Lrrrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrZgetTyperrrr$r'r)r*r+r.r1r4r5r7r:r>r@rBrDrGrHrIrCrRrTrUrZr_rcrdrfrgrirmrnrorrrvryr~r�r�r�r�r�r�r�r�r�rrrrr�as�
	

	


		 	P



r�c@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�SetContentTestsz+
    Tests for L{FilePath.setContent}.
    c	CsJ|��}t�|�}|�d�t|d��}|��}W5QRX|�d|�dS)zx
        Contents of the file referred to by a L{FilePath} can be written using
        L{FilePath.setContent}.
        shello, worldrXN)rr
r;r�r.rbrD)rZ
pathStringr ru�contentsrrr�
test_write\s

zSetContentTests.test_writecCs*td�}|�t|jd�|�|jj�dS)z�
        If writing to the underlying file raises an exception,
        L{FilePath.setContent} raises that exception after closing the file.
        r�sblahN)r�rJr�r�r?r�r�r�rrr�test_fileClosingisz SetContentTests.test_fileClosingcCsPt|���}|�d�|�d�|��}|�t|�d�|�|d|d�dS)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.
        salphasbetarkrrJN)r�rr�r�rDrpr�)rr�ZopenedSiblingsrrr�test_nameCollisionss

z"SetContentTests.test_nameCollisioncCsH|��}|�t|�dd�|�|d���|�d|d��|f�dS)aC
        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{bytes}

        @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}.
        rJz expected exactly one opened filerz!%s does not end with %r extensionN)r�rDrpr?r r()rr��	extensionZopenedrrr�_assertOneOpened�s
��z SetContentTests._assertOneOpenedcCs&t|���}|�d�|�|d�dS)z�
        L{FilePath.setContent} creates temporary files with the extension
        I{.new} if no alternate extension value is given.
        shellos.newN�r�rr�r�r�rrr�test_defaultExtension�s
z%SetContentTests.test_defaultExtensioncCs(t|���}|�dd�|�|d�dS)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.
        sgoodbyes-something-elseNr�r�rrr�test_customExtension�sz$SetContentTests.test_customExtensionN)
rrrrr�r�r�r�r�r�rrrrr�Xs


r�c@sJeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Ze��r�de_de_nde_de_d d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Z d8d9�Z!d:d;�Z"d<d=�Z#d>d?�Z$d@dA�Z%dBdC�Z&dDdE�Z'dFdG�Z(dHdI�Z)dJS)K�UnicodeFilePathTestszp
    L{FilePath} instances should have the same internal representation as they
    were instantiated with.
    cCs t�d�}|�t|j�t�dS)ze
        L{FilePath} instantiated with a text path will return a text-mode
        FilePath.
        �	./mon€yN)r
r;rDryr rr�rrr�test_UnicodeInstantiation�s
z.UnicodeFilePathTests.test_UnicodeInstantiationcCs0t�d�}|�d�d��}|�t|j�t�dS)z�
        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€yrN�r
r;rErrDryr �bytes�rr�rErrr�#test_UnicodeInstantiationBytesChild�s
z8UnicodeFilePathTests.test_UnicodeInstantiationBytesChildcCs*t�d�}|�d�}|�t|j�t�dS)z�
        Calling L{FilePath.child} on a text-mode L{FilePath} with a text
        subpath will return a text-mode FilePath.
        r�rN)r
r;rErDryr rr�rrr�%test_UnicodeInstantiationUnicodeChild�s

z:UnicodeFilePathTests.test_UnicodeInstantiationUnicodeChildcCs*t�d�}|�d�}|�t|j�t�dS)z�
        Calling L{FilePath.preauthChild} on a text-mode L{FilePath} with a text
        subpath will return a text-mode FilePath.
        r�rN)r
r;r	rDryr rr�rrr�,test_UnicodeInstantiationUnicodePreauthChild�s

zAUnicodeFilePathTests.test_UnicodeInstantiationUnicodePreauthChildcCs0t�d�}|�d�d��}|�t|j�t�dS)z�
        Calling L{FilePath.preauthChild} on a text-mode L{FilePath} with a bytes
        subpath will return a bytes-mode FilePath.
        r�r�rN)r
r;r	rrDryr r�r�rrr�*test_UnicodeInstantiationBytesPreauthChild�s
z?UnicodeFilePathTests.test_UnicodeInstantiationBytesPreauthChildcCs t�d�}|�t|j�t�dS)zj
        L{FilePath} instantiated with a L{bytes} path will return a bytes-mode
        FilePath.
        �./N)r
r;rDryr r�r�rrr�test_BytesInstantiation�s
z,UnicodeFilePathTests.test_BytesInstantiationcCs0t�d�}|�d�d��}|�t|j�t�dS)z�
        Calling L{FilePath.child} on a bytes-mode L{FilePath} with a bytes
        subpath will return a bytes-mode FilePath.
        r�r�rNr�r�rrr�!test_BytesInstantiationBytesChild�s
z6UnicodeFilePathTests.test_BytesInstantiationBytesChildcCs0t�d�d��}|�d�}|�t|j�t�dS)z�
        Calling L{FilePath.child} on a bytes-mode L{FilePath} with a text
        subpath will return a text-mode FilePath.
        uparent-mon€yrrN)r
r;rrErDryr rr�rrr�#test_BytesInstantiationUnicodeChild�s
z8UnicodeFilePathTests.test_BytesInstantiationUnicodeChildcCs6t�d�d��}|�d�d��}|�t|j�t�dS)z�
        Calling L{FilePath.preauthChild} on a bytes-mode L{FilePath} with a
        bytes subpath will return a bytes-mode FilePath.
        r�rr�N)r
r;rr	rDryr r�r�rrr�(test_BytesInstantiationBytesPreauthChildsz=UnicodeFilePathTests.test_BytesInstantiationBytesPreauthChildcCs0t�d�d��}|�d�}|�t|j�t�dS)z�
        Calling L{FilePath.preauthChild} on a bytes-mode L{FilePath} with a text
        subpath will return a text-mode FilePath.
        r�rrN)r
r;rr	rDryr rr�rrr�*test_BytesInstantiationUnicodePreauthChilds
z?UnicodeFilePathTests.test_BytesInstantiationUnicodePreauthChildcCs4t�d�}t|�}tr$|�d|�n|�d|�dS)�S
        The repr of a L{unicode} L{FilePath} shouldn't burst into flames.
        ruFilePath('/mon€y')zFilePath(u'/mon\u20acy')N�r
r;�reprrrD�rr�Z
reprOutputrrr�test_unicodereprs

z%UnicodeFilePathTests.test_unicodereprcCs:t�d�d��}t|�}tr*|�d|�n|�d|�dS)�Q
        The repr of a L{bytes} L{FilePath} shouldn't burst into flames.
        u/parent-mon€yrz%FilePath(b'/parent-mon\xe2\x82\xacy')z$FilePath('/parent-mon\xe2\x82\xacy')N)r
r;rr�rrDr�rrr�test_bytesrepr's��z#UnicodeFilePathTests.test_bytesreprcCs4t�d�}t|�}tr$|�d|�n|�d|�dS)r�zC:\�FilePath('C:\\')zFilePath(u'C:\\')Nr�r�rrr�test_unicodereprWindows5s

z,UnicodeFilePathTests.test_unicodereprWindowscCs4t�d�}t|�}tr$|�d|�n|�d|�dS)r�sC:\zFilePath(b'C:\\')r�Nr�r�rrr�test_bytesreprWindowsAs

z*UnicodeFilePathTests.test_bytesreprWindowszTest will not work on WindowszTest only works on WindowscCs*t�d�}|�d�}|�|djt�dS)zT
        C{globChildren} will return the same type as the pattern argument.
        �/rrN)r
r;�globChildrenr�r r��rr�rvrrr�test_mixedTypeGlobChildrenUs

z/UnicodeFilePathTests.test_mixedTypeGlobChildrencCs*t�d�}|�d�}|�|djt�dS)z8
        C{globChildren} works with L{unicode}.
        r��*rN)r
r;r�r�r rr�rrr�test_unicodeGlobChildren^s

z-UnicodeFilePathTests.test_unicodeGlobChildrencCst�d�}|�|��t�dS)zQ
        Calling C{basename} on an text- L{FilePath} returns L{unicode}.
        �./N)r
r;r�r rr�rrr�test_unicodeBasenamegs
z)UnicodeFilePathTests.test_unicodeBasenamecCst�d�}|�|��t�dS)zS
        Calling C{dirname} on a text-mode L{FilePath} returns L{unicode}.
        r�N)r
r;r�r+rr�rrr�test_unicodeDirnameos
z(UnicodeFilePathTests.test_unicodeDirnamecCs$t�d�}|��}|�|jt�dS)zk
        Calling C{parent} on a text-mode L{FilePath} will return a text-mode
        L{FilePath}.
        r�N)r
r;r&r�r r)rr�r&rrr�test_unicodeParentws
z'UnicodeFilePathTests.test_unicodeParentcCs&t�d�}|�d�}|�|jt�dS)zx
        A L{bytes} extension to C{temporarySibling} will mean a L{bytes} mode
        L{FilePath} is returned.
        r��.txtN)r
r;r%r�r r��rr�ZtempSiblingrrr�test_mixedTypeTemporarySibling�s

z3UnicodeFilePathTests.test_mixedTypeTemporarySiblingcCs&t�d�}|�d�}|�|jt�dS)z|
        A L{unicode} extension to C{temporarySibling} will mean a L{unicode}
        mode L{FilePath} is returned.
        u/tmp/mon€y�.txtN)r
r;r%r�r rr�rrr�test_unicodeTemporarySibling�s

z1UnicodeFilePathTests.test_unicodeTemporarySiblingcCsNt�d�}t�|��d�}|��|�d�}|�|tj�|�|jt�dS)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�r�r�N)r
r;�_asTextPathrrr�r r��rr�r�newPathrrr�$test_mixedTypeSiblingExtensionSearch�s

z9UnicodeFilePathTests.test_mixedTypeSiblingExtensionSearchcCsNt�d�}t�|��d�}|��|�d�}|�|tj�|�|jt�dS)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�r�N)r
r;r�rrr�r rr�rrr�"test_unicodeSiblingExtensionSearch�s

z7UnicodeFilePathTests.test_unicodeSiblingExtensionSearchcCsNt�d�}t�|��d�}|��|�d�}|�|tj�|�|jt�dS)z�
        C{siblingExtension} called with L{bytes} on a L{unicode}-mode
        L{FilePath} will return a L{bytes}-mode L{FilePath}.
        r�r�r�N)r
r;r�rrr�r r�r�rrr�test_mixedTypeSiblingExtension�s

z3UnicodeFilePathTests.test_mixedTypeSiblingExtensioncCsNt�d�}t�|��d�}|��|�d�}|�|tj�|�|jt�dS)z�
        C{siblingExtension} called with L{unicode} on a L{unicode}-mode
        L{FilePath} will return a L{unicode}-mode L{FilePath}.
        r�r�N)r
r;r�rrr�r rr�rrr�test_unicodeSiblingExtension�s

z1UnicodeFilePathTests.test_unicodeSiblingExtensioncs`t�d�����|��fdd����d�}|����d�}|�|tj�|�|jt	�dS)z�
        C{childSearchPreauth} called with L{bytes} on a L{unicode}-mode
        L{FilePath} will return a L{bytes}-mode L{FilePath}.
        r�cs���Sr�r�r�r�rrr/�r�zGUnicodeFilePathTests.test_mixedTypeChildSearchPreauth.<locals>.<lambda>�text.txtstext.txtN)
r
r;r!r�rEr�childSearchPreauthr�r r��rrEr�rr�r� test_mixedTypeChildSearchPreauth�s


z5UnicodeFilePathTests.test_mixedTypeChildSearchPreauthcs`t�d�����|��fdd����d�}|����d�}|�|tj�|�|jt	�dS)z�
        C{childSearchPreauth} called with L{unicode} on a L{unicode}-mode
        L{FilePath} will return a L{unicode}-mode L{FilePath}.
        r�cs���Srr�rr�rrr/�r�zEUnicodeFilePathTests.test_unicodeChildSearchPreauth.<locals>.<lambda>r�N)
r
r;r!r�rErr�r�r rr�rr�r�test_unicodeChildSearchPreauth�s


z3UnicodeFilePathTests.test_unicodeChildSearchPreauthcCs0t�d�}|��}|�||�|�|jt�dS)�r
        C{asBytesMode} on a L{unicode}-mode L{FilePath} returns a new
        L{bytes}-mode L{FilePath}.
        �./tmpN)r
r;�asBytesModeror�r r��rr�Znewfprrr�test_asBytesModeFromUnicode�s
z0UnicodeFilePathTests.test_asBytesModeFromUnicodecCs0t�d�}|��}|�||�|�|jt�dS)r��./tmpN)r
r;�
asTextModeror�r rr�rrr�test_asTextModeFromBytes�s
z-UnicodeFilePathTests.test_asTextModeFromBytescCs0t�d�}|��}|�||�|�|jt�dS)zs
        C{asBytesMode} on a L{bytes}-mode L{FilePath} returns the same
        L{bytes}-mode L{FilePath}.
        r�N)r
r;r�rnr�r r�r�rrr�test_asBytesModeFromBytess
z.UnicodeFilePathTests.test_asBytesModeFromBytescCs0t�d�}|��}|�||�|�|jt�dS)zv
        C{asTextMode} on a L{unicode}-mode L{FilePath} returns the same
        L{unicode}-mode L{FilePath}.
        r�N)r
r;r�rnr�r rr�rrr�test_asTextModeFromUnicodes
z/UnicodeFilePathTests.test_asTextModeFromUnicodecCs(t�d�}|jdd�}|�d|j�dS)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
r;r�r"r r�rrr�'test_asBytesModeFromUnicodeWithEncodings
z<UnicodeFilePathTests.test_asBytesModeFromUnicodeWithEncodingcCs(t�d�}|jdd�}|�d|j�dS)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�rr�r�N)r
r;r�r"r r�rrr�$test_asTextModeFromBytesWithEncoding(s
z9UnicodeFilePathTests.test_asTextModeFromBytesWithEncodingc	Cs0t�d�}|�t��|jdd�W5QRXdS)z�
        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
r;rJ�UnicodeErrorr�r�rrr�/test_asBytesModeFromUnicodeWithUnusableEncoding2s
zDUnicodeFilePathTests.test_asBytesModeFromUnicodeWithUnusableEncodingc	Cs0t�d�}|�t��|jdd�W5QRXdS)z�
        C{asTextMode} with an C{encoding} argument that can't be used to encode
        the unicode path raises a L{UnicodeError}.
        s\u2603zutf-32r�N)r
r;rJr�r�r�rrr�,test_asTextModeFromBytesWithUnusableEncoding<s
zAUnicodeFilePathTests.test_asTextModeFromBytesWithUnusableEncodingN)*rrrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��sR	



	



		





r�)*rZ
__future__rrrr6rr;r�ZpprintrZtwisted.python.compatrrrZtwisted.python.win32rr	Ztwisted.pythonr
Ztwisted.python.runtimerZtwisted.trial.unittestrr
rZzope.interface.verifyrZ_supportsSymlinksr�rrr;r�r�r�r�r�r�r�r�r�rrrr�<module>s@(S+(6+~[