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_format.cpython-310.pyc
o

�bU�@s0dZddlmZmZmZz
ddlmZeWney!dZYnwddlm	Z	ddl
mZmZm
Z
ddlmZddlmZd	d
lmZmZmZmZmZmZd	dlmZd	dlmZGd
d�dej�ZGdd�dej�ZGdd�dej�Z Gdd�dej�Z!Gdd�d�Z"Gdd�de#�Z$Gdd�dej�Z%dS)z+
Test cases for L{twisted.logger._format}.
�)�AnyStr�Optional�cast)�tzsetN)�Failure)�addTZCleanup�mktime�setTZ)�unittest)�SkipTest�)�eventAsText�formatEvent�formatEventAsClassicLogText�
formatTime�formatUnformattableEvent�formatWithCall)�LogEvent)�LogLevelc@sVeZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�Zddd�Z	ddd�Z
dS)�FormattingTestsz5
    Tests for basic event formatting functions.
    �returnNcs�dtdtdtf�fdd�}��d|d����d|d����d|d	dd
����d|dd
dd�d����d|d����d|d��|ddd�}��d|�ttd��}��d|d|ddd��dS)ac
        L{formatEvent} will format an event according to several rules:

            - A string with no formatting instructions will be passed straight
              through.

            - PEP 3101 strings will be formatted using the keys and values of
              the event as named fields.

            - PEP 3101 keys ending with C{()} will be treated as instructions
              to call that key (which ought to be a callable) before
              formatting.

        L{formatEvent} will always return L{str}, and if given bytes, will
        always treat its format string as UTF-8 encoded.
        �	logFormat�eventrcs$||d<t|�}��t|�t�|S)N�
log_format)r�assertIs�type�str)rr�result��self��A/usr/lib/python3/dist-packages/twisted/logger/test/test_format.py�format9sz0FormattingTests.test_formatEvent.<locals>.format���abcz{x})�xzno, yes.z{not_called}, {called()}.�nocS�dS)N�yesr r r r r!�<lambda>D�z2FormattingTests.test_formatEvent.<locals>.<lambda>)�
not_called�calleduSánchezsSánchez�Unable to format eventsS�nchezsS{a!s}nchez��)�az
Sb'\xe1'nchez�S�nchezsS{a!r}nchezN)r�objectr�assertEqual�assertIn�repr)rr"�maybeResult�xe1r rr!�test_formatEvent's� z FormattingTests.test_formatEventcCs$tddd�}t|�}|�d|�dS)z5
        Formatting an event with no format.
        �r)�foo�barr#N)�dictrr4�rrrr r r!�test_formatEventNoFormatNsz(FormattingTests.test_formatEventNoFormatcCs8tt�ddd�}t|�}|�d|�|�t|�|�dS)z:
        Formatting an event with a bogus format.
        r:r)rr;r<zLog format must be strN)r=r3rr5r6r>r r r!�test_formatEventWeirdFormatW�z+FormattingTests.test_formatEventWeirdFormatcCs8tddd�d�}t|�}|�d|�|�t|�|�dS)zF
        Formatting an event that's just plain out to get us.
        �{evil()}cS�ddS�Nr:rr r r r r!r*e�z?FormattingTests.test_formatUnformattableEvent.<locals>.<lambda>�r�evilr.N)r=rr5r6r>r r r!�test_formatUnformattableEventarAz-FormattingTests.test_formatUnformattableEventcCsLddddd�ttt��di}t|�}|�d|�|�d|�|�d	|�d
S)zR
        Formatting an unformattable event that has an unformattable key.
        rrBrGcSrCrDr r r r r!r*qrEzSFormattingTests.test_formatUnformattableEventWithUnformattableKey.<locals>.<lambda>�gurk�*MESSAGE LOST: unformattable object logged:�Recoverable data:�Exception during formatting:N)rr�
Unformattablerr5r>r r r!�1test_formatUnformattableEventWithUnformattableKeyks�zAFormattingTests.test_formatUnformattableEventWithUnformattableKeycCsDtddd�t�d�}t|�}|�d|�|�d|�|�d|�dS)	�T
        Formatting an unformattable event that has an unformattable value.
        rBcSrCrDr r r r r!r*rEzUFormattingTests.test_formatUnformattableEventWithUnformattableValue.<locals>.<lambda>)rrGrIrJrKrLN)r=rMrr5r>r r r!�3test_formatUnformattableEventWithUnformattableValueys�zCFormattingTests.test_formatUnformattableEventWithUnformattableValuecCsPtddd�dd�}t|ttt���}|�d|�|�td�dtd�|�d	S)
rOrBcSrCrDr r r r r!r*�rEzbFormattingTests.test_formatUnformattableEventWithUnformattableErrorOMGWillItStop.<locals>.<lambda>�okay)rrG�recoverablerJrRz = N)r=rr�
BaseExceptionrMr5r6r>r r r!�@test_formatUnformattableEventWithUnformattableErrorOMGWillItStop�s� zPFormattingTests.test_formatUnformattableEventWithUnformattableErrorOMGWillItStop�rN)�__name__�
__module__�__qualname__�__doc__r9r?r@rHrNrPrTr r r r!r"s

'
	




rc@sLeZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�Zddd�Z	dS)�TimeFormattingTestsz.
    Tests for time formatting functions.
    rNcCst|�dS)N)rrr r r!�setUp��zTimeFormattingTests.setUpcsbtdurtd��dtdtdtddf�fdd�}|d	d
d�|dd
d�|ddd�|ddd�dS)z�
        Default time stamp format is RFC 3339 and offset respects the timezone
        as set by the standard C{TZ} environment variable and L{tzset} API.
        N�:Platform cannot change timezone; unable to verify offsets.�name�expectedDST�expectedSTDrcs<t|�td�}td�}��t|�|���t|�|�dS)N)	i���rrr��r:)	i�r:�rrrrrer)r	rr4r)r^r_r`�localDST�localSTDrr r!�testForTimeZone�s
zMTimeFormattingTests.test_formatTimeWithDefaultFormat.<locals>.testForTimeZone�UTC+00z2006-06-30T00:00:00+0000z2007-01-31T00:00:00+0000zEST+05EDT,M4.1.0,M10.5.0z2006-06-30T00:00:00-0400z2007-01-31T00:00:00-0500zCEST-01CEDT,M4.1.0,M10.5.0z2006-06-30T00:00:00+0200z2007-01-31T00:00:00+0100zCST+06z2006-06-30T00:00:00-0600z2007-01-31T00:00:00-0600)rrr)rrhr rr!� test_formatTimeWithDefaultFormat�s.
����z4TimeFormattingTests.test_formatTimeWithDefaultFormatcCs(|�td�d�|�tddd�d�dS)zL
        If C{when} argument is L{None}, we get the default output.
        N�-�!)�default�r4rrr r r!�test_formatTimeWithNoTime�sz-TimeFormattingTests.test_formatTimeWithNoTimecCs6td�}|�t|dd�d�|�t|ddd�d�dS)zR
        If C{timeFormat} argument is L{None}, we get the default output.
        �	i��	���(�/r:ir:N��
timeFormatrkrl)rwrm�rr4r�r�tr r r!�test_formatTimeWithNoFormat�sz/TimeFormattingTests.test_formatTimeWithNoFormatcCs td�}|�t|dd�d�dS)z2
        Alternate time format in output.
        rpz%Y/%Wrvz2013/38Nrxryr r r!�&test_formatTimeWithAlternateTimeFormat�sz:TimeFormattingTests.test_formatTimeWithAlternateTimeFormatcCs|�tddd�d�dS)z0
        "%f" supported in time format.
        g�?x��.Az%frv�234560Nrnrr r r!�test_formatTimePercentF�sz+TimeFormattingTests.test_formatTimePercentFrU)
rVrWrXrYr[rjror{r|r~r r r r!rZ�s


-

rZc@s~eZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�Zddd�Z	ddd�Z
ddd�Zddd�Zddd�Z
ddd�ZdS)�ClassicLogFormattingTestsz@
    Tests for classic text log event formatting functions.
    rNcCsHtdurtd��t|�td�td�}td|d�}|�t|�d�dS)z�
        Time is first field.  Default time stamp format is RFC 3339 and offset
        respects the timezone as set by the standard C{TZ} environment variable
        and L{tzset} API.
        Nr]rirp�XYZZY�r�log_timez%2013-09-24T11:40:47+0000 [-#-] XYZZY
)rrrr	rr=r4r)rrzrr r r!�test_formatTimeDefault�s�z0ClassicLogFormattingTests.test_formatTimeDefaultcCs:dttdtfdd�}tddd�}|�t||d�d	�d
S)zc
        Time is first field.  Custom formatting function is an optional
        argument.
        rzrcSsd|�d�S)N�__r )rzr r r!rr\zCClassicLogFormattingTests.test_formatTimeCustom.<locals>.formatTimer�i90r�)rz__12345__ [-#-] XYZZY
N)r�floatrr=r4r)rrrr r r!�test_formatTimeCustoms
�z/ClassicLogFormattingTests.test_formatTimeCustomcC� tddd�}|�t|�d�dS)z:
        Namespace is first part of second field.
        r��my.namespace)r�
log_namespacez- [my.namespace#-] XYZZY
N�r=r4r�rrr r r!�test_formatNamespace�
�z.ClassicLogFormattingTests.test_formatNamespacecCs"tdtjd�}|�t|�d�dS)z7
        Level is second part of second field.
        r�)r�	log_levelz- [-#warn] XYZZY
N�r=r�warnr4rr�r r r!�test_formatLevel�
�z*ClassicLogFormattingTests.test_formatLevelcCr�)z)
        System is second field.
        r��S.Y.S.T.E.M.�r�
log_system�- [S.Y.S.T.E.M.] XYZZY
Nr�r�r r r!�test_formatSystem#r�z+ClassicLogFormattingTests.test_formatSystemcCs&tddtjdd�}|�t|�d�dS)�B
        System is not supplanted by namespace and level.
        r�r�r�)rr�r�r�r�Nr�r�r r r!�test_formatSystemRulz-s��z/ClassicLogFormattingTests.test_formatSystemRulzcCs"tdt�d�}|�t|�d�dS)r�r�r�z- [UNFORMATTABLE] XYZZY
N)r=rMr4rr�r r r!�test_formatSystemUnformattable<r�z8ClassicLogFormattingTests.test_formatSystemUnformattablecCr�)z0
        Formatted event is last field.
        zid:{id}�123�r�idz- [-#-] id:123
Nr�r�r r r!�test_formatFormatFr�z+ClassicLogFormattingTests.test_formatFormatcCstdd�}|�t|�d�dS)z#
        No format string.
        r�)r�N�r=rrr�r r r!�test_formatNoFormatPs
z-ClassicLogFormattingTests.test_formatNoFormatcCs tddd�}|�t|�d�dS)z&
        Empty format string.
        r#r�r�Nr�r�r r r!�test_formatEmptyFormatWsz0ClassicLogFormattingTests.test_formatEmptyFormatcCstdd�}|�t|�d�dS)zO
        If the formatted event has newlines, indent additional lines.
        z"XYZZY
A hollow voice says:
"Plugh")rz-- [-#-] XYZZY
	A hollow voice says:
	"Plugh"
Nr�r�r r r!�test_formatFormatMultiLine^s

�z4ClassicLogFormattingTests.test_formatFormatMultiLinerU)rVrWrXrYr�r�r�r�r�r�r�r�r�r�r�r r r r!r�s














rc@seZdZdZddd�ZdS)�FormatFieldTestsz+
    Tests for format field functions.
    rNcCs>|�tdtddd�d��d�|�tdtdd�d	��d
�dS)z�
        L{formatWithCall} is an extended version of L{str.format} that
        will interpret a set of parentheses "C{()}" at the end of a format key
        to mean that the format key ought to be I{called} rather than
        stringified.
        zHello, {world}. {callme()}.�earthcSr()N�mayber r r r r!r*xr+z6FormatFieldTests.test_formatWithCall.<locals>.<lambda>)�world�callmezHello, earth. maybe.zHello, {repr()!r}.cSr()Nr6r r r r r!r*}r+)r6zHello, 'repr'.N)r4rr=rr r r!�test_formatWithCallns���z$FormatFieldTests.test_formatWithCallrU)rVrWrXrYr�r r r r!r�isr�c@seZdZdZdefdd�ZdS)rMz>
    An object that raises an exception from C{__repr__}.
    rcCstdd�SrD)rrr r r!�__repr__�r\zUnformattable.__repr__N)rVrWrXrYrr�r r r r!rM�srMc@seZdZdZdS)�
CapturedErrorz3
    A captured error for use in format tests.
    N)rVrWrXrYr r r r!r��sr�c@s�eZdZdZddd�Zddd�Zddd	�Zdd
d�Zddd
�Zddd�Z	ddd�Z
ddd�Zddd�Zddd�Z
ddd�Zddd�Zddd�ZdS)�EventAsTextTestszi
    Tests for L{eventAsText}, all of which ensure that the
    returned type is UTF-8 decoded text.
    rNcCsdztd��tyt�}Ynwddi}||d<t|ddd�}|�t|���|�|�d|�dS)	zT
        An event with a C{log_failure} key will have a traceback appended.
        �This is a fake errorr�This is a test log message�log_failureTF��includeTimestamp�
includeSystemN�r�rr
r5r�getTraceback�r�fr�	eventTextr r r!�test_eventWithTraceback�s
�z(EventAsTextTests.test_eventWithTracebackcCsdztd��tyt�}Ynwddi}||d<t|ddd�}|�t|���|�|�d|�dS)	zu
        An event with an empty C{log_format} key appends a traceback from
        the accompanying failure.
        r�rr#r�TFr�Nr�r�r r r!�"test_formatEmptyEventWithTraceback�s
�z3EventAsTextTests.test_formatEmptyEventWithTracebackcCsvztd��tyt�}Ynwddd�d�}||d<t|ddd	�}|�|t�|�t|���|�|�d|�d
S)zw
        An event with an unformattable value in the C{log_format} key still
        has a traceback appended.
        r�rBcSrCrDr r r r r!r*�rEzHEventAsTextTests.test_formatUnformattableWithTraceback.<locals>.<lambda>rFr�TFr�N)r�rr
�assertIsInstancerr5r�r�r r r!�%test_formatUnformattableWithTraceback�s
��z6EventAsTextTests.test_formatUnformattableWithTracebackcCs�ztd��tyt�}Ynwddddd�ttt��di}||d<t|d	d
d�}|�|t�|�d|�|�t|���|�|�d|�d
S)z�
        An event with an unformattable value in the C{log_format} key, that
        throws an exception when __repr__ is invoked still has a traceback
        appended.
        r�rrBrGcSrCrDr r r r r!r*�rEzMEventAsTextTests.test_formatUnformattableErrorWithTraceback.<locals>.<lambda>rIr�TFr�zMESSAGE LOSTN)	r�rrrrMr
r�r5r�r�r r r!�*test_formatUnformattableErrorWithTraceback�s
��z;EventAsTextTests.test_formatUnformattableErrorWithTracebackcCs<ddi}t�|d<t|ddd�}|�|t�|�d|�dS)	zk
        If a traceback cannot be appended, a message indicating this is true
        is appended.
        rr#r�TFr�z'(UNABLE TO OBTAIN TRACEBACK FROM EVENT)N)r3r
r�rr5�rrr�r r r!�&test_formatEventUnformattableTraceback�s

z7EventAsTextTests.test_formatEventUnformattableTracebackcCs2ddi}t|ddd�}|�|t�|�d|�dS)zY
        An event with no C{log_failure} key will not have a traceback appended.
        rr�TFr�N)r
r�rr5r�r r r!�test_formatEventNonCritical�sz,EventAsTextTests.test_formatEventNonCriticalcCs\ztd��tyt�}Ynwddi}||d<t|ddd�}|�d|�|�d|�d	S)
zU
        An exception message with multibyte characters is properly handled.
        u€rr�r�TFr��	TracebackN�r�rr
r5r�r r r!�test_formatTracebackMultibyte�s
�z.EventAsTextTests.test_formatTracebackMultibytecCs\ztd��tyt�}Ynwddi}||d<t|ddd�}|�d|�|�d	|�d
S)zj
        An error raised attempting to decode the UTF still produces a
        valid log message.
        s
��testrr�r�TFr�r�z.CapturedError(b"\xff\xfet\x00e\x00s\x00t\x00")Nr�r�r r r!�,test_formatTracebackHandlesUTF8DecodeFailures
�z=EventAsTextTests.test_formatTracebackHandlesUTF8DecodeFailurecCs^ztd��tyt�}Ynwtd�}dd|d�}||d<t|dddd	�}|�|d
�dS)zq
        If includeSystem is specified as the only option no timestamp or
        traceback are printed.
        r�rp�ABCD�fake_system�rr�r�r�FT�r��includeTracebackr�z[fake_system] ABCDN�r�rrr
r4�rr�rzrr�r r r!�test_eventAsTextSystemOnlys*
����z+EventAsTextTests.test_eventAsTextSystemOnlycCs~tdurtd��t|�td�ztd��ty t�}Ynwtd�}dd|d�}||d	<t|d
ddd�}|�|d
�dS)zq
        If includeTimestamp is specified as the only option no system or
        traceback are printed.
        Nr]rir�rpr�r�r�r�TFr�z2013-09-24T11:40:47+0000 ABCD)	rrrr	r�rrr
r4r�r r r!�test_eventAsTextTimestampOnly0s2
����z.EventAsTextTests.test_eventAsTextTimestampOnlycCs\ztd��tyt�}Ynwtd�}d|d�}||d<t|dddd�}|�|d	�d
S)z\
        If includeSystem is specified with a missing system [-#-]
        is used.
        r�rpr�r�r�FTr�z
[-#-] ABCDNr�r�r r r!�test_eventAsTextSystemMissingRs(
����z.EventAsTextTests.test_eventAsTextSystemMissingcCsbztd��tyt�}Ynwtd�}d|tjdd�}||d<t|dddd	�}|�|d
�dS)z�
        If includeSystem is specified with a missing system but
        namespace and level are present they are used.
        r�rpr��test)rr�r�r�r�FTr�z[test#info] ABCDN�r�rrr�infor
r4r�r r r!�.test_eventAsTextSystemMissingNamespaceAndLevelms,
����z?EventAsTextTests.test_eventAsTextSystemMissingNamespaceAndLevelcCs`ztd��tyt�}Ynwtd�}d|tjd�}||d<t|dddd�}|�|d	�d
S)zv
        If includeSystem is specified with a missing system but
        level is present, level is included.
        r�rpr�)rr�r�r�FTr�z
[-#info] ABCDNr�r�r r r!�&test_eventAsTextSystemMissingLevelOnly�s*
����z7EventAsTextTests.test_eventAsTextSystemMissingLevelOnlyrU)rVrWrXrYr�r�r�r�r�r�r�r�r�r�r�r�r�r r r r!r��s






	



"
r�)&rY�typingrrr�timer�ImportError�twisted.python.failurer�!twisted.python.test.test_tzhelperrrr	�
twisted.trialr
�twisted.trial.unittestr�_formatr
rrrrr�_interfacesr�_levelsr�TestCaserrZrr�rM�	Exceptionr�r�r r r r!�<module>s.� tR	

Anon7 - 2022
AnonSec Team