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/logger/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/logger/test/__pycache__/test_legacy.cpython-310.pyc
o

�b	9�@s�dZddlZddlmZddlmZmZddlmZddl	m
Z
ddlmZddl
mZmZdd	lmZdd
lmZddlmZdd
lmZmZddlmZmZddlmZGdd�dej�Z Gdd�dej�Z!dS)z+
Test cases for L{twisted.logger._legacy}.
�N)�time)�List�cast)�implementer)�BrokenMethodImplementation)�verifyObject)�context�log)�Failure)�unittest�)�formatEvent)�ILogObserver�LogEvent)�LegacyLogObserverWrapper�publishToNewObserver)�LogLevelc@seZdZdZd4dd�Zd4dd�Zdedefd	d
�Zdedefdd�Zd4d
d�Z	d4dd�Z
d4dd�Zd4dd�Zd4dd�Z
d4dd�Zd4dd�Zd4dd�Zd4dd�Zd4dd �Zd4d!d"�Zd4d#d$�Zd4d%d&�Zd4d'd(�Zd)edefd*d+�Zd4d,d-�Zd4d.d/�Zd4d0d1�Zd4d2d3�ZdS)5�LegacyLogObserverWrapperTestsz0
    Tests for L{LegacyLogObserverWrapper}.
    �returnNc
CsZttjdd��}t|�}ztt|�WdSty,}z|�|�WYd}~dSd}~ww)zD
        L{LegacyLogObserverWrapper} is an L{ILogObserver}.
        cS�dS�N���err�A/usr/lib/python3/dist-packages/twisted/logger/test/test_legacy.py�<lambda>"sz>LegacyLogObserverWrapperTests.test_interface.<locals>.<lambda>N)r�	legacyLogrrrr�fail)�self�legacyObserver�observerrrrr�test_interfaces��z,LegacyLogObserverWrapperTests.test_interfacecCs6ttj�Gdd�d��}t|��}|�t|�d�dS)zJ
        L{LegacyLogObserverWrapper} returns the expected string.
        c@s.eZdZdefdd�Zdejddfdd�ZdS)z?LegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserverrcSsdS)Nz<Legacy Observer>r�rrrr�__repr__0�zHLegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserver.__repr__�	eventDictNcSrrr)rr%rrr�__call__3r$zHLegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserver.__call__)�__name__�
__module__�__qualname__�strr#r�	EventDictr&rrrr�LegacyObserver.sr,z+LegacyLogObserverWrapper(<Legacy Observer>)N)rrrr�assertEqual�repr)rr,r rrr�	test_repr)s
z'LegacyLogObserverWrapperTests.test_repr�eventcs@g�ttj�fdd��}t|�}||�|�t��d��dS)z�
        Send an event to a wrapped legacy observer and capture the event as
        seen by that observer.

        @param event: an event

        @return: the event as observed by the legacy wrapper
        cs
��|�Sr)�appendr��eventsrrrEs
z7LegacyLogObserverWrapperTests.observe.<locals>.<lambda>�r)rrrrr-�len)rr0rr rr2r�observe:s	z%LegacyLogObserverWrapperTests.observecCsX|�dt��|�dd�|�dtj�|�t|��}|��D]
\}}|�||�q|S)z�
        Send an event to a wrapped legacy observer and verify that its data is
        preserved.

        @param event: an event

        @return: the event as observed by the legacy wrapper
        �log_time�
log_system�-�	log_level)�
setdefaultrr�infor6�dict�items�assertIn)rr0�observed�key�valuerrr�forwardAndVerifyLs
z.LegacyLogObserverWrapperTests.forwardAndVerifycCs|�tddd��dS)ze
        Basic forwarding: event keys as observed by a legacy observer are the
        same.
        r4r��foo�barN)rCr=r"rrr�test_forwardcsz*LegacyLogObserverWrapperTests.test_forwardcCs*t�}|�t|d��}|�|d|�dS)zc
        The new-style C{"log_time"} key is copied to the old-style C{"time"}
        key.
        )r7rN�rrCr=r-�r�stampr0rrr�	test_timejsz'LegacyLogObserverWrapperTests.test_timecCs0t�}|�t|d|d��}|�|d|�dS)zr
        The new-style C{"log_time"} key does not step on a pre-existing
        old-style C{"time"} key.
        r4)r7rrNrHrIrrr�test_timeAlreadySetssz1LegacyLogObserverWrapperTests.test_timeAlreadySetcC�$|�tdd��}|�|dd�dS)zg
        The new-style C{"log_system"} key is copied to the old-style
        C{"system"} key.
        rE)r8�systemN�rCr=r-�rr0rrr�test_system|sz)LegacyLogObserverWrapperTests.test_systemcCs&|�tddd��}|�|dd�dS)zv
        The new-style C{"log_system"} key does not step on a pre-existing
        old-style C{"system"} key.
        rErF)r8rNrNNrOrPrrr�test_systemAlreadySet�sz3LegacyLogObserverWrapperTests.test_systemAlreadySetcCs2tt�tjd�}|�t|��}|�|dd�dS)zy
        If the new-style C{"log_system"} key is absent, the old-style
        C{"system"} key is set to C{"-"}.
        )r7r:rNr9N)r=rrr<r6r-)rr0r@rrr�
test_noSystem�sz+LegacyLogObserverWrapperTests.test_noSystemcCsT|�ttjdd��|�ttjdd��|�ttjdd��|�ttjdd��dS)z�
        If explicitly set, the C{isError} key will be preserved when forwarding
        from a new-style logging emitter to a legacy logging observer,
        regardless of log level.
        r4)r:�isErrorrN)rCr=rr<�warn�error�criticalr"rrr�test_levelNotChange�sz1LegacyLogObserverWrapperTests.test_levelNotChangecCs"|�ttjd��}|�d|�dS)a)
        The new-style C{"log_level"} key is not translated to the old-style
        C{"logLevel"} key.

        Events are forwarded from the old module from to new module and are
        then seen by old-style observers.
        We don't want to add unexpected keys to old-style events.
        )r:�logLevelN)rCr=rr<�assertNotInrPrrr�test_pythonLogLevelNotSet�s	z7LegacyLogObserverWrapperTests.test_pythonLogLevelNotSetcCrM)a
        If a stdlib log level was provided as a string (eg. C{"WARNING"}) in
        the legacy "logLevel" key, it does not get converted to a number.
        The documentation suggested that numerical values should be used but
        this was not a requirement.
        �WARNING�rYrYNrOrPrrr�test_stringPythonLogLevel�s��z7LegacyLogObserverWrapperTests.test_stringPythonLogLevelcCs |�t��}|�|dd�dS)z�
        The old-style C{"message"} key is added, even if no new-style
        C{"log_format"} is given, as it is required, but may be empty.
        �messagerNrOrPrrr�test_message��z*LegacyLogObserverWrapperTests.test_messagecCrM)zV
        The old-style C{"message"} key is not modified if it already exists.
        rD)r_r_NrOrPrrr�test_messageAlreadySet�sz4LegacyLogObserverWrapperTests.test_messageAlreadySetcC�(|�tddd��}|�t�|�d�dS)z�
        Formatting is translated such that text is rendered correctly, even
        though old-style logging doesn't use PEP 3101 formatting.
        z
Hello, {who}!�world)�
log_format�who�
Hello, world!N�rCr=r-r�textFromEventDictrPrrr�test_format��z)LegacyLogObserverWrapperTests.test_formatcCrc)zo
        Using the message key, which is special in old-style, works for
        new-style formatting.
        zHello, {message}!rd)rer_rgNrhrPrrr�test_formatMessage�s
�z0LegacyLogObserverWrapperTests.test_formatMessagecCs(|�tddd��}|�t�|�d�dS)zd
        Formatting is not altered if the old-style C{"format"} key already
        exists.
        zHello!zHowdy!)re�formatNrhrPrrr�test_formatAlreadySet�rkz3LegacyLogObserverWrapperTests.test_formatAlreadySet�valuescKs&ttd��}|�td|dd�|���S)z�
        Create a new-style event with a captured failure.

        @param values: Additional values to include in the event.

        @return: the new event
        znyargh!�	oopsie...)�log_failurereNr)r
�RuntimeErrorrCr=)rro�failurerrr�eventWithFailure�s�z.LegacyLogObserverWrapperTests.eventWithFailurecCs>|��}|�|d|d�|�|d�|�|dd�dS)z}
        Captured failures in the new style set the old-style C{"failure"},
        C{"isError"}, and C{"why"} keys.
        rsrqrT�whyrpN)rt�assertIs�
assertTruer-rPrrr�test_failure�sz*LegacyLogObserverWrapperTests.test_failurecCs,ttd��}|j|d�}|�|d|�dS)�v
        Captured failures in the new style do not step on a pre-existing
        old-style C{"failure"} key.
        zWeak salsa!)rsrsN)r
rrrtrv)rrsr0rrr�test_failureAlreadySet�sz4LegacyLogObserverWrapperTests.test_failureAlreadySetcC� |jdd�}|�|dd�dS)zv
        Captured failures in the new style do not step on a pre-existing
        old-style C{"isError"} key.
        r�rTrTN�rtr-rPrrr�test_isErrorAlreadySetraz4LegacyLogObserverWrapperTests.test_isErrorAlreadySetcCr{)ry�blah)ruruNr}rPrrr�test_whyAlreadySetraz0LegacyLogObserverWrapperTests.test_whyAlreadySet�rN)r'r(r)�__doc__r!r/rr6rCrGrKrLrQrRrSrXr[r^r`rbrjrlrn�objectrtrxrzr~r�rrrrrs2




	
	















	rc@s�eZdZdZddd�Zdededejfdd	�Z	dd
d�Z
ddd
�Zddd�Zddd�Z
ddd�Zddd�Zddd�Zddd�Zddd�Zddd�ZdS)�PublishToNewObserverTestsz,
    Tests for L{publishToNewObserver}.
    rNcCsg|_tt|jj�|_dSr)r3rrr1r r"rrr�setUpszPublishToNewObserverTests.setUpr_rocOsDt�tj�pi��}|�|�||d<t�|d<d|vr d|d<|S)a
        Return a basic old-style event as would be created by L{legacyLog.msg}.

        @param message: a message event value in the legacy event format
        @param values: additional event values in the legacy event format

        @return: a legacy event
        r_rrTr)r�getr�ILogContext�copy�updater)rr_ror0rrr�legacyEvents	

z%PublishToNewObserverTests.legacyEventcCs*t|j|��tj�|�t|j�d�dS)z6
        The observer is called exactly once.
        r4N)rr r�rrir-r5r3r"rrr�
test_observed/s�z'PublishToNewObserverTests.test_observedcC�8t|j|��tj�|�|jdd|jdd�dS)zc
        The old-style C{"time"} key is copied to the new-style C{"log_time"}
        key.
        rr7rN�rr r�rrir-r3r"rrrrK8��$z#PublishToNewObserverTests.test_timecCsNdtdtfdd�}|�dd�}||�}t|j||�|�t|jd�|�dS)	z�
        A published old-style event should format as text in the same way as
        the given C{textFromEventDict} callable would format it.
        r0rcSsd�td�|d���S)N�� r_)�join�reversed)r0rrrriHszAPublishToNewObserverTests.test_message.<locals>.textFromEventDictzHello,zworld!rN)rr*r�rr r-r
r3)rrir0�textrrrr`Bs
z&PublishToNewObserverTests.test_messagecCs0t|j|��tj�|�|jddtj�dS)zL
        Published event should have log level of L{LogLevel.info}.
        rr:N)	rr r�rrir-r3rr<r"rrr�test_defaultLogLevelQs�z.PublishToNewObserverTests.test_defaultLogLevelcC�4t|j|jdd�tj�|�|jddtj�dS)z�
        If C{"isError"} is set to C{1} (true) on the legacy event, the
        C{"log_level"} key should get set to L{LogLevel.critical}.
        r4r|rr:N)	rr r�rrir-r3rrWr"rrr�test_isErrorZs�z&PublishToNewObserverTests.test_isErrorcCs6t|j|jtjd�tj�|�|jddt	j
�dS)z�
        If the old-style C{"logLevel"} key is set to a standard library logging
        level, using a predefined (L{int}) constant, the new-style
        C{"log_level"} key should get set to the corresponding log level.
        r]rr:N)rr r��
py_loggingr\rrir-r3rrUr"rrr�test_stdlibLogLevelds�z-PublishToNewObserverTests.test_stdlibLogLevelcCr�)z�
        If the old-style C{"logLevel"} key is set to a standard library logging
        level, using a string value, the new-style C{"log_level"} key should
        get set to the corresponding log level.
        r\r]rr:N)	rr r�rrir-r3rrUr"rrr�test_stdlibLogLevelWithStringqs
�z7PublishToNewObserverTests.test_stdlibLogLevelWithStringcCs.t|j|jdd�tj�|�d|jd�dS)z�
        If the old-style C{"logLevel"} key is set to a standard library logging
        level, using an unknown value, the new-style C{"log_level"} key should
        not get set.
        zFoo!!!!!r]r:rN)rr r�rrirZr3r"rrr�test_stdlibLogLevelWithGarbage~s
�z8PublishToNewObserverTests.test_stdlibLogLevelWithGarbagecCs.t|j|��tj�|�|jddd�dS)z�
        Published event should have a namespace of C{"log_legacy"} to indicate
        that it was forwarded from legacy logging.
        r�
log_namespace�
log_legacyNr�r"rrr�test_defaultNamespace�s�z/PublishToNewObserverTests.test_defaultNamespacecCr�)zg
        The old-style C{"system"} key is copied to the new-style
        C{"log_system"} key.
        rr8rNNr�r"rrrrQ�r�z%PublishToNewObserverTests.test_systemr�)r'r(r)r�r�r*r�rr+r�r�rKr`r�r�r�r�r�r�rQrrrrr�s


	



	






r�)"r��loggingr�r�typingrr�zope.interfacer�zope.interface.exceptionsr�zope.interface.verifyr�twisted.pythonrr	r�twisted.python.failurer
�
twisted.trialr�_formatr
�_interfacesrr�_legacyrr�_levelsr�TestCaserr�rrrr�<module>s"}

Anon7 - 2022
AnonSec Team