Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/testfixtures/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/testfixtures/__pycache__/tempdirectory.cpython-311.pyc

�

�܋f�3����ddlZddlZddlZddlmZddlmZddlmZddl	m
Z
mZmZm
Z
mZddlmZddlmZdd	lmZe
ee
efZerddlZGd
�d��Zdeegeffd
�ZdS)�N)�Path)�compile)�mkdtemp)�Union�Sequence�
TYPE_CHECKING�Tuple�Callable)�compare)�wrap�)�rmtreec���eZdZdZe��ZdZdZ	d%dddd�dee	e
dfdee	d	ed
e	fd�Z
ed���Zd&d�Zd'd�Zed'd���Z				d(dedededefd�Zd)dedefd�Z				d*dee	dedededef
d�Zd�Zdefd�Zd%dedeee	fd
e	fd�Zd%dee	ee	fd
e	fd�ZeZd%ded
e
fd �Zd%ded
dfd!�Zd%ded
e	d
eee	ffd"�Zd#�Z d$�Z!dS)+�
TempDirectoryad
    A class representing a temporary directory on disk.

    :param ignore: A sequence of strings containing regular expression
                   patterns that match filenames that should be
                   ignored by the :class:`TempDirectory` listing and
                   checking methods.

    :param create: If `True`, the temporary directory will be created
                   as part of class instantiation.

    :param path: If passed, this should be a string containing an
                 absolute path to use as the temporary directory. When
                 passed, :class:`TempDirectory` will not create a new
                 directory to use.

    :param encoding: A default encoding to use for :meth:`read` and
                     :meth:`write` operations when the ``encoding`` parameter
                     is not passed to those methods.
    FN�)�ignore�create�encoding�pathz
py.path.localrrrc��g|_|D])}|j�t|�����*|rt|��nd|_||_t
|��|_|s|�|�|���dSdSdS�N)	r�appendr�strrr�bool�dont_remover)�selfrrrr�regexs      �k/builddir/build/BUILD/cloudlinux-venv-1.0.6/venv/lib/python3.11/site-packages/testfixtures/tempdirectory.py�__init__zTempDirectory.__init__3s�������	/�	/�E��K���w�u�~�~�.�.�.�.�!%�/�C��I�I�I�4��	� ��
���:�:����	�d�l�v�~��K�K�M�M�M�M�M�#�l�~�~�c��|jr;tjdd�d�|jD����z��dSdS)Nz6TempDirectory instances not cleaned up by shutdown:
%s�
c3�$K�|]}|jV��dSr)r)�.0�is  r�	<genexpr>z'TempDirectory.atexit.<locals>.<genexpr>Is$����!@�!@�Q�!�&�!@�!@�!@�!@�!@�!@r )�	instances�warnings�warn�join)�clss r�atexitzTempDirectory.atexitDs_���=�	��M���	�	�!@�!@�#�-�!@�!@�!@�@�@�B�
�
�
�
�
�	�	r �returnc���|jr|St��|_|j�|��|jjs%t
j|j��d|j_|S)zt
        Create a temporary directory for this instance to use if one
        has not already been created.
        T)rrr'�add�	__class__�atexit_setupr,�register�rs rrzTempDirectory.createLsb��
�9�	��K��I�I��	�����4� � � ��~�*�	/��O�D�K�(�(�(�*.�D�N�'��r c���|jrAtj�|j��r|jst	|j��|`||jvr|j�|��dSdS)z�
        Delete the temporary directory and anything in it.
        This :class:`TempDirectory` cannot be used again unless
        :meth:`create` is called.
        N)r�os�existsrrr'�remover3s r�cleanupzTempDirectory.cleanupZsu���9�	������	�2�2�	�4�;K�	��4�9�����	��4�>�!�!��N�!�!�$�'�'�'�'�'�"�!r c�\�t|j��D]}|����dS)zn
        Delete all temporary directories associated with all
        :class:`TempDirectory` objects.
        N)�tupler'r8)r+r%s  r�cleanup_allzTempDirectory.cleanup_allfs6���s�}�%�%�	�	�A�
�I�I�K�K�K�K�	�	r �	recursive�
files_only�followlinksc��|r|�|��n|j}g}|r�tj||���D]�\}}}d�|t|��dzd��tj����}|r|dz
}|D]}	|s|�||	zdz��� t|��D]}
|�||
z�����n,tj
|��D]}|�|���g}t|��D]?}d}
|jD]}|�|��rd}
n�|
r�*|�|���@|S)N)r>�/r
FT)
�_joinrr5�walkr*�len�split�sepr�sorted�listdirr�search)rrr<r=r>�result�dirpath�dirnames�	filenames�dirname�name�n�filteredrrs               r�actualzTempDirectory.actualos���$(�6�t�z�z�$����T�Y�����	!�02���k�1�1�1�
0�
0�,���9��(�(�7�3�t�9�9�Q�;�<�<�#8�#>�#>�r�v�#F�#F�G�G���#��s�N�G�'�;�;�G�%�;��
�
�g�g�o�c�&9�:�:�:��"�9�-�-�0�0�D��M�M�'�$�,�/�/�/�/�0�
0��Z��%�%�
!�
!���
�
�a� � � � ����6�N�N�	"�	"�D��F���
�
���<�<��%�%��!�F��E���
���O�O�D�!�!�!�!��r c�|�|�||��}|std��|D]}t|���dS)a�
        Print the contents of the specified directory.

        :param path: The path to list, which can be:

                     * `None`, indicating the root of the temporary
                       directory should be listed.

                     * A tuple of strings, indicating that the
                       elements of the tuple should be used as directory
                       names to traverse from the root of the
                       temporary directory to find the directory to be
                       listed.

                     * A forward-slash separated string, indicating
                       the directory or subdirectory that should be
                       traversed to from the temporary directory and
                       listed.

        :param recursive: If `True`, the directory specified will have
                          its subdirectories recursively listed too.
        zNo files or directories found.N)rQ�print)rrr<rQrOs     rrGzTempDirectory.listdir�sT��.���T�9�-�-���	4��2�3�3�3��	�	�A��!�H�H�H�H�	�	r T�expectedc��d}tt|��t|�||||����d���dS)a�
        Compare the expected contents with the actual contents of the temporary
        directory. An :class:`AssertionError` will be raised if they are not the
        same.

        :param expected: A sequence of strings containing the paths
                         expected in the directory. These paths should
                         be forward-slash separated and relative to
                         the root of the temporary directory.

        :param path: The path to use as the root for the comparison,
                     relative to the root of the temporary directory.
                     This can either be:

                     * A tuple of strings, making up the relative path.

                     * A forward-slash separated string.

                     If it is not provided, the root of the temporary
                     directory will be used.

        :param files_only: If specified, directories will be excluded from
                           the list of actual paths used in the comparison.

        :param recursive: If ``False``, only the direct contents of
                          the directory specified by ``path`` will be included
                          in the actual contents used for comparison.

        :param followlinks: If ``True``, symlinks and hard links
                            will be followed when recursively building up
                            the actual list of directory contents.
        TF)rTrQr<N)rrFr:rQ)rrTrr=r<r>�__tracebackhide__s       rrzTempDirectory.compare�sa��R!�����)�)��T�[�[��)�Z������ �		!�	!�	!�	!�	!�	!r c��t|t��r|�d��}tj�|���tj��}|�tj��r+|�|j��r|Std���tj�|j|��S)Nr@z8Attempt to read or write outside the temporary Directory)
�
isinstancerrDr5rEr*�rstrip�
startswithr�
ValueError)rrN�relatives   rrAzTempDirectory._join�s����d�C� � �	#��:�:�c�?�?�D��6�;�;�t�$�$�+�+�B�F�3�3�����r�v�&�&�	��"�"�4�9�-�-�
 ����J���
��w�|�|�D�I�x�0�0�0r rJc�X�|�|��}tj|��|S)a�
        Make an empty directory at the specified path within the
        temporary directory. Any intermediate subdirectories that do
        not exist will also be created.

        :param dirpath: The directory to create, which can be:

                        * A tuple of strings.

                        * A forward-slash separated string.

        :returns: The absolute path of the created directory.
        )rAr5�makedirs)rrJ�thepaths   r�makedirzTempDirectory.makedir�s*���*�*�W�%�%��
��G�����r �filepath�datac��t|t��r|�d��}t|��dkrP|�|dd���}t
j�|��stj|��|�|��}|p|j	}|�|�
|��}t|d��5}|�|��ddd��n#1swxYwY|S)a�
        Write the supplied data to a file at the specified path within
        the temporary directory. Any subdirectories specified that do
        not exist will also be created.

        The file will always be written in binary mode. The data supplied must
        either be bytes or an encoding must be supplied to convert the string
        into bytes.

        :param filepath: The path to the file to create, which can be:

                         * A tuple of strings.

                         * A forward-slash separated string.

        :param data:

          :class:`bytes` containing the data to be written, or a :class:`str`
          if ``encoding`` has been supplied.

        :param encoding: The encoding to be used if data is not bytes. Should
                         not be passed if data is already bytes.

        :returns: The absolute path of the file written.
        r@r
N����wb)
rXrrDrCrAr5rr6r^r�encode�open�write)rrarbrrJr_�fs       rrhzTempDirectory.writes!��4�h��$�$�	+��~�~�c�*�*�H��x�=�=�1����j�j��#�2�#��/�/�G��7�>�>�'�*�*�
%���G�$�$�$��*�*�X�&�&���,�t�}�����;�;�x�(�(�D�
�'�4�
 �
 �	�A�
�G�G�D�M�M�M�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��s�C5�5C9�<C9c�>�|�|jn|�|��S)ao
        Return the full path on disk that corresponds to the path
        relative to the temporary directory that is passed in.

        :param path: The path to the file to create, which can be:

                     * A tuple of strings.

                     * A forward-slash separated string.

        :returns: A string containing the absolute path.

        )rrA�rrs  r�	as_stringzTempDirectory.as_string,s ��!�L�t�y�y�d�j�j��.>�.>�>r c�X�t|�|jn|�|����S)a9
        Return the :class:`~pathlib.Path` that corresponds to the path
        relative to the temporary directory that is passed in.

        :param path: The path to the file to create, which can be:

                     * A tuple of strings.

                     * A forward-slash separated string.
        )rrrArks  r�as_pathzTempDirectory.as_pathAs(�����D�I�I�4�:�:�d�3C�3C�D�D�Dr c�\�ddlm}||�|jn|�|����S)a9
        Return the :class:`py.path.local` that corresponds to the path
        relative to the temporary directory that is passed in.

        :param path: The path to the file to create, which can be:

                     * A tuple of strings.

                     * A forward-slash separated string.
        r)�local)�py.pathrprrA)rrrps   r�as_localzTempDirectory.as_localNs<��	"�!�!�!�!�!��u�$�,�T�Y�Y�D�J�J�t�4D�4D�E�E�Er c���t|�|��d��5}|���}ddd��n#1swxYwY|p|j}|�|�|��S|S)a�
        Reads the file at the specified path within the temporary
        directory.

        The file is always read in binary mode. Bytes will be returned unless
        an encoding is supplied, in which case a unicode string of the decoded
        data will be returned.

        :param filepath: The path to the file to read, which can be:

                         * A tuple of strings.

                         * A forward-slash separated string.

        :param encoding: The encoding used to decode the data in the file.

        :returns:

          The contents of the file as a :class:`str` or :class:`bytes`, if ``encoding``
          is not specified.
        �rbN)rgrA�readr�decode)rrarrirbs     rruzTempDirectory.read\s���,�$�*�*�X�&�&��
-�
-�	���6�6�8�8�D�	�	�	�	�	�	�	�	�	�	�	����	�	�	�	��,�t�}�����;�;�x�(�(�(��s�A�A	�A	c��|Srrr3s r�	__enter__zTempDirectory.__enter__ys���r c�.�|���dSr)r8)r�type�value�	tracebacks    r�__exit__zTempDirectory.__exit__|s���������r r)r-r)r-N)NFFF)NF)NFTF)"�__name__�
__module__�__qualname__�__doc__�setr'r1rrrrrrr�classmethodr,rr8r;�PathStringsrQrGrrAr`�bytesrhrl�getpathrnrrrurxr}rr rrrs%��������*����I��L��D�7;��%'�� �
�����T�?�2�3���S�M�	�
���
����"����[������
(�
(�
(�
(������[��!%�#�$� %�&�&��&��&��	&�
�&�&�&�&�P��K��4�����@!%�$�"� %�
/!�/!��s�m�/!��/!��	/!�
�/!��
/!�/!�/!�/!�b1�1�1��{�����$&�&�k�&��u�c�z�1B�&�c�&�&�&�&�P?�?�e�C��#��$6�7�?�3�?�?�?�?�&�G�E�E�K�E�4�E�E�E�E�F�F�[�F�O�F�F�F�F���[��C��5��PS��CT�����:�������r rr-c�X�d|d<t|i|��}t|j|j��S)z�
    A decorator for making a :class:`TempDirectory` available for the
    duration of a test function.

    All arguments and parameters are passed through to the
    :class:`TempDirectory` constructor.
    Fr)rrrr8)�args�kw�ls   r�tempdirr��s3���B�x�L��t�"�r�"�"�A����!�)�$�$�$r )r,r5r(�pathlibr�rer�tempfiler�typingrrrr	r
�testfixtures.comparisonr�testfixtures.utilsrrrr�rq�pyrr�rr r�<module>r�s?��
�
�
�
�	�	�	�	�����������������������B�B�B�B�B�B�B�B�B�B�B�B�B�B�+�+�+�+�+�+�#�#�#�#�#�#��������C��s��O�$�����N�N�N�f�f�f�f�f�f�f�f�R
%�H�h�Z��%9�:�
%�
%�
%�
%�
%�
%r 

Hacked By AnonymousFox1.0, Coded By AnonymousFox