AnonSec Shell
Server IP : 209.38.156.173  /  Your IP : 216.73.216.122   [ Reverse IP ]
Web Server : Apache/2.4.52 (Ubuntu)
System : Linux lakekumayuhotel 5.15.0-136-generic #147-Ubuntu SMP Sat Mar 15 15:53:30 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.1.2-1ubuntu2.22
Disable Function : NONE
Domains : 2 Domains
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /lib/python3/dist-packages/twisted/logger/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ HOME ]     [ BACKUP SHELL ]     [ JUMPING ]     [ MASS DEFACE ]     [ SCAN ROOT ]     [ SYMLINK ]     

Current File : /lib/python3/dist-packages/twisted/logger/test/__pycache__/test_global.cpython-310.pyc
o

�b�1�@s�dZddlZddlmZmZmZmZmZmZm	Z	m
Z
ddlmZddl
mZddlmZddlmZmZdd	lmZmZdd
lmZddlmZddlmZdd
lmZdejdeedeeddfdd�Z Gdd�dej�Z!dS)z+
Test cases for L{twisted.logger._global}.
�N)�IO�Any�List�Optional�TextIO�Tuple�Type�cast)�Failure)�unittest�)�textFileLogObserver)�MORE_THAN_ONCE_WARNING�LogBeginner)�ILogObserver�LogEvent)�LogLevel)�Logger)�LogPublisher)�nextLine�test�actualEvents�expectedEvents�returncstt|�t|�kr|�||�t��|D]
}�t|���O�qdtdtf�fdd���fdd�|D�}|�||�dS)a7
    Compare two sequences of log events, examining only the the keys which are
    present in both.

    @param test: a test case doing the comparison
    @param actualEvents: A list of log events that were emitted by a logger.
    @param expectedEvents: A list of log events that were expected by a test.
    �eventrcs,|��}|��D]}|�vr|�|�q|S�N)�copy�keys�pop)rr�key)�
allMergedKeys��A/usr/lib/python3/dist-packages/twisted/logger/test/test_global.py�simplify*s
�zcompareEvents.<locals>.simplifycsg|]}�|��qSr!r!��.0r)r#r!r"�
<listcomp>1sz!compareEvents.<locals>.<listcomp>N)�len�assertEqual�setrr)rrrr�simplifiedActualr!)r r#r"�
compareEventss
r+c@s�eZdZdZd"dd�Zd"dd�Zd"dd	�Zd
ededdfdd
�Z	d"dd�Z
d"dd�Zd"dd�Zd"dd�Z
d"dd�Zd"dd�Zd"dd�Zd"dd�Zd"dd�Zd"d d!�ZdS)#�LogBeginnerTestsz#
    Tests for L{LogBeginner}.
    rNcCsZt�|_t��|_Gdd�d�}Gdd�d�}|�|_|�|_t|j|j|j|j�|_dS)Nc@seZdZe�Ze�ZdS)z&LogBeginnerTests.setUp.<locals>.NotSysN)�__name__�
__module__�__qualname__�object�stdout�stderrr!r!r!r"�NotSys>s
r3c@sReZdZd
dd�Z		ddedeededed	ee	e
d
eeddfdd�ZdS)z+LogBeginnerTests.setUp.<locals>.NotWarningsrNcSs
g|_dSr)�warnings)�selfr!r!r"�__init__Cs�z4LogBeginnerTests.setUp.<locals>.NotWarnings.__init__�message�category�filename�lineno�file�linecSs|j�||||||f�dS)a
                Emulate warnings.showwarning.

                @param message: A warning message to emit.
                @param category: A warning category to associate with
                    C{message}.
                @param filename: A file name for the source code file issuing
                    the warning.
                @param lineno: A line number in the source file where the
                    warning was issued.
                @param file: A file to write the warning message to.  If
                    L{None}, write to L{sys.stderr}.
                @param line: A line of source code to include with the warning
                    message. If L{None}, attempt to read the line from
                    C{filename} and C{lineno}.
                N)r4�append)r5r7r8r9r:r;r<r!r!r"�showwarningJsz7LogBeginnerTests.setUp.<locals>.NotWarnings.showwarning�rN)NN)r-r.r/r6�strr�Warning�intrrrr>r!r!r!r"�NotWarningsBs&

�����
���rC)	r�	publisher�io�StringIO�errorStream�	sysModule�warningsModuler�beginner)r5r3rCr!r!r"�setUp:s
#
�zLogBeginnerTests.setUpcsrtddd�}g�g�tt�fdd��}tt�fdd��}|j�||f�|�|�|�|g��|�|g��dS)z?
        Test that C{beginLoggingTo()} adds observers.
        �r��foo�barc�
��|�Sr�r=��e��events1r!r"�<lambda>t�
zBLogBeginnerTests.test_beginLoggingToAddObservers.<locals>.<lambda>crPrrQrR��events2r!r"rVurWN)�dictr	rrJ�beginLoggingTorDr(�r5r�o1�o2r!�rUrYr"�test_beginLoggingToAddObserversks
z0LogBeginnerTests.test_beginLoggingToAddObserverscsrtddd�}g�g�tt�fdd��}tt�fdd��}|�|�|j�||f�|�|g��|�|g��dS)z\
        Test that events are buffered until C{beginLoggingTo()} is
        called.
        rLrrMcrPrrQrRrTr!r"rV�rWzDLogBeginnerTests.test_beginLoggingToBufferedEvents.<locals>.<lambda>crPrrQrRrXr!r"rV�rWN)rZr	rrDrJr[r(r\r!r_r"�!test_beginLoggingToBufferedEvents}s
z2LogBeginnerTests.test_beginLoggingToBufferedEvents�limitrJcCsft|d�D]
}|�t|d��qg}|�tt|j�g�|�ttd|d��tdd�|D���dS)a�
        Verify that when more than C{limit} events are logged to L{LogBeginner},
        only the last C{limit} are replayed by L{LogBeginner.beginLoggingTo}.

        @param limit: The maximum number of events the log beginner should
            buffer.
        @param beginner: The L{LogBeginner} against which to verify.

        @raise: C{self.failureException} if the wrong events are replayed by
            C{beginner}.
        rL)�countcss�|]}|dVqdS)rcNr!r$r!r!r"�	<genexpr>�s�z4LogBeginnerTests._bufferLimitTest.<locals>.<genexpr>N)	�rangerDrZr[r	rr=r(�list)r5rbrJrc�eventsr!r!r"�_bufferLimitTest�s�z!LogBeginnerTests._bufferLimitTestcCstj}|�||j�dS)z�
        Up to C{LogBeginner._DEFAULT_BUFFER_SIZE} log events are buffered for
        replay by L{LogBeginner.beginLoggingTo}.
        N)r�_DEFAULT_BUFFER_SIZErhrJ)r5rbr!r!r"�test_defaultBufferLimit�sz(LogBeginnerTests.test_defaultBufferLimitcCs.d}t|j|j|j|j|d�}|�||�dS)z�
        The size of the L{LogBeginner} event buffer can be overridden with the
        C{initialBufferSize} initilizer argument.
        �)�initialBufferSizeN)rrDrGrHrIrh)r5rbrJr!r!r"�test_overrideBufferLimit�s�z)LogBeginnerTests.test_overrideBufferLimitc	Cs$g}g}t��}t|�}|�tdd��t�\}}|j�tt	|j
�|g�|�tdd��t�\}}|j�tt	|j
�|g�|�tdd��tttj
||||d�}	d|_t||tdd�tdd�|	tdd�g�t|||	tdd�g�|��}
|�d|�d|�d	�|
�|�d|�d|�d	�|
�dS)
z�
        When invoked twice, L{LogBeginner.beginLoggingTo} will emit a log
        message warning the user that they previously began logging, and add
        the new log observers.
        �	prebuffer)r�
postbuffer�postwarn)�
log_format�	log_level�fileNow�lineNow�fileThen�lineThenN�<�:�>)rErFr
rDrZrrJr[r	rr=rr�warn�maxDiffr+�getvalue�assertIn)r5rUrY�
fileHandle�textObserver�
firstFilename�	firstLine�secondFilename�
secondLine�warning�outputr!r!r"�test_beginLoggingToTwice�sB

�	��
z)LogBeginnerTests.test_beginLoggingToTwicecCs:t|jd�}|�d�|jddd�|�|j��d�dS)zP
        Critical messages will be written as text to the error stream.
        ��observerzignore thisza critical {message}r7)r7za critical message
N)rrD�info�criticalr(rGr|�r5�logr!r!r"�test_criticalLogging�s
z%LogBeginnerTests.test_criticalLoggingcCs8t|jd�}|j�d�|�d�|�|j��d�dS)z�
        Once logging has begun with C{beginLoggingTo}, critical messages are no
        longer written to the output stream.
        r�r!zanother critical message�N)rrDrJr[r�r(rGr|r�r!r!r"�test_criticalLoggingStops�s
z*LogBeginnerTests.test_criticalLoggingStopscCs�g}|j�tt|j�g�tdtt|jj�d�t	||t
ddd�g�|dd�=tdtt|jj�d�t	||t
ddd�g�dS)z�
        L{LogBeginner.beginLoggingTo} will re-direct the standard output and
        error streams by setting the C{stdio} and C{stderr} attributes on its
        sys module object.
        z
Hello, world.�r;r1)�
log_namespace�log_ioNz
Error, world.r2)rJr[r	rr=�printrrHr1r+rZr2)r5rgr!r!r"�%test_beginLoggingToRedirectStandardIO�s�
�z6LogBeginnerTests.test_beginLoggingToRedirectStandardIOcCsD|jj}|jj}|jjddd�|�|jj|�|�|jj|�dS)z�
        L{LogBeginner.beginLoggingTo} will leave the existing stdout/stderr in
        place if it has been told not to replace them.
        r!F)�redirectStandardION)rHr1r2rJr[�assertIs)r5�oldOut�oldErrr!r!r"�test_beginLoggingToDontRedirects
z0LogBeginnerTests.test_beginLoggingToDontRedirectcCs�t�t��d�}t�t��d�}||j_||j_g}|j�tt	|j
�g�tt|jj�}tt|jj�}|�|j
d�|�|j
d�|�d�|�d�t||tdd�tdd�g�dS)	z�
        When L{LogBeginner.beginLoggingTo} redirects stdout/stderr streams, the
        replacement streams will preserve the encoding of the replaced streams,
        to minimally disrupt any application relying on a specific encoding.
        z	shift-JIS�big5s��
s��
u李)r�u瑩N)rE�
TextIOWrapper�BytesIOrHr1r2rJr[r	rr=rr(�encoding�writer+rZ)r5�weird�weirderrrgr1r2r!r!r"�$test_beginLoggingToPreservesEncodings

 z5LogBeginnerTests.test_beginLoggingToPreservesEncodingc
Cs�|j�dttd�g}|j�tt|j�g�|j�dttd�t	�
�}|jjdttd|d�|�|jjdttdddfdttd|dfg�t
||tdtjd	tjtdd
�g�dS)z�
        L{LogBeginner.beginLoggingTo} will redirect the warnings of its
        warnings module into the logging system.
        z	a messagerLzanother messagerzyet anotherrkr�N�.)r�r8r9r:)rIr>�DeprecationWarning�__file__rJr[r	rr=rErFr(r4r+rZr.r-)r5rg�fr!r!r"�test_warningsModule/s>�
��������z$LogBeginnerTests.test_warningsModulecCsXttd��}t|jd�}|jd|d�|j��}|�d|�|�d|�|�d|�dS)zR
        The string resulting from a logged failure contains a traceback.
        z,this is not the behavior you are looking forr�z	a failure)�failure�	TracebackN)r
�	ExceptionrrDr�rGr|r})r5r�r��msgr!r!r"�test_failuresAppendTracebacksVs
z.LogBeginnerTests.test_failuresAppendTracebacksr?)r-r.r/�__doc__rKr`rarBrrhrjrmr�r�r�r�r�r�r�r�r!r!r!r"r,5s 

1




+
	




'r,)"r�rE�typingrrrrrrrr	�twisted.python.failurer
�
twisted.trialr�_filer
�_globalrr�_interfacesrr�_levelsr�_loggerr�	_observerr�test.test_stdlibr�TestCaser+r,r!r!r!r"�<module>s,(���
�

Anon7 - 2022
AnonSec Team