HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //usr/lib/python3/dist-packages/twisted/logger/test/__pycache__/test_format.cpython-38.pyc
U

�`�[#X�@s$dZddlmZmZmZzddlmZeWnek
rDdZYnXddlm	Z	ddl
mZddlm
Z
mZdd	lmZdd
lmZmZmZmZmZmZddlmZGdd
�d
e	j�ZGdd�de	j�ZGdd�de	j�ZGdd�de	j�ZGdd�de�Z Gdd�de!�Z"Gdd�de	j�Z#dS)z+
Test cases for L{twisted.logger._format}.
�)�mktime�addTZCleanup�setTZ)�tzsetN)�unittest)�SkipTest)�_PY3�unicode�)�LogLevel)�formatEvent�formatUnformattableEvent�
formatTime�formatEventAsClassicLogText�formatWithCall�eventAsText)�Failurec@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�FormattingTestsz5
    Tests for basic event formatting functions.
    cs��fdd�}��d|d����d|d����d|ddd����d|d	d
dd�d
����d|d��|d�}��d|�|ddd�}ts���d|�n��d|�ttd��}��d|d|ddd��dS)ag
        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{unicode}, and if given bytes, will
        always treat its format string as UTF-8 encoded.
        cs$||d<t|�}��t|�t�|S)N�
log_format)r�assertIs�typer	)Z	logFormat�event�result��self��A/usr/lib/python3/dist-packages/twisted/logger/test/test_format.py�format5sz0FormattingTests.test_formatEvent.<locals>.format���abcz{x})�xzno, yes.z{not_called}, {called()}.ZnocSsdS)NZyesrrrrr�<lambda>Brz2FormattingTests.test_formatEvent.<locals>.<lambda>)Z
not_calledZcalleduSánchezsSánchezsS�nchez�Unable to format eventsS{a!s}nchez��)�az
Sb'\xe1'nchez�SZnchezsS{a!r}nchezN)�assertEqual�assertInrr	�repr)rrZ	badResultZmaybeResultZxe1rrr�test_formatEvent$s*��z FormattingTests.test_formatEventcCs$tddd�}t|�}|�d|�dS)z5
        Formatting an event with no format.
        �r
)�foo�barrN)�dictrr'�rrrrrr�test_formatEventNoFormatUsz(FormattingTests.test_formatEventNoFormatcCs8tt�ddd�}t|�}|�d|�|�t|�|�dS)z:
        Formatting an event with a bogus format.
        r+r
)rr,r-z#Log format must be unicode or bytesN)r.�objectrr(r)r/rrr�test_formatEventWeirdFormat_sz+FormattingTests.test_formatEventWeirdFormatcCs8tddd�d�}t|�}|�d|�|�t|�|�dS)zF
        Formatting an event that's just plain out to get us.
        �{evil()}cSsddS�Nr+rrrrrrr"nrz?FormattingTests.test_formatUnformattableEvent.<locals>.<lambda>�r�evilr#N)r.rr(r)r/rrr�test_formatUnformattableEventjsz-FormattingTests.test_formatUnformattableEventcCsFddddd�t�di}t|�}|�d|�|�d|�|�d	|�d
S)zR
        Formatting an unformattable event that has an unformattable key.
        rr3r6cSsddSr4rrrrrr"{rzSFormattingTests.test_formatUnformattableEventWithUnformattableKey.<locals>.<lambda>�gurk�*MESSAGE LOST: unformattable object logged:�Recoverable data:�Exception during formatting:N)�
Unformattablerr(r/rrr�1test_formatUnformattableEventWithUnformattableKeyus�zAFormattingTests.test_formatUnformattableEventWithUnformattableKeycCsDtddd�t�d�}t|�}|�d|�|�d|�|�d|�dS)	�T
        Formatting an unformattable event that has an unformattable value.
        r3cSsddSr4rrrrrr"�rzUFormattingTests.test_formatUnformattableEventWithUnformattableValue.<locals>.<lambda>)rr6r8r9r:r;N)r.r<rr(r/rrr�3test_formatUnformattableEventWithUnformattableValue�s�zCFormattingTests.test_formatUnformattableEventWithUnformattableValuecCsJtddd�dd�}t|t��}|�d|�|�td�dtd�|�d	S)
r>r3cSsddSr4rrrrrr"�rzbFormattingTests.test_formatUnformattableEventWithUnformattableErrorOMGWillItStop.<locals>.<lambda>Zokay)rr6�recoverabler9r@z = N)r.r
r<r(r)r/rrr�@test_formatUnformattableEventWithUnformattableErrorOMGWillItStop�s�zPFormattingTests.test_formatUnformattableEventWithUnformattableErrorOMGWillItStopN)�__name__�
__module__�__qualname__�__doc__r*r0r2r7r=r?rArrrrrs1
rc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�TimeFormattingTestsz.
    Tests for time formatting functions.
    cCst|�dS)N)rrrrr�setUp�szTimeFormattingTests.setUpcsPtdkrtd���fdd�}|ddd�|dd	d
�|ddd
�|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.cs<t|�td�}td�}��t|�|���t|�|�dS)N)	i���rrr��r+)	i�r+�rrrr
rMr)rrr'r)�nameZexpectedDSTZexpectedSTDZlocalDSTZlocalSTDrrr�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)rr)rrOrrr� test_formatTimeWithDefaultFormat�s2�
����z4TimeFormattingTests.test_formatTimeWithDefaultFormatcCs(|�td�d�|�tddd�d�dS)zL
        If C{when} argument is L{None}, we get the default output.
        N�-�!)�default�r'rrrrr�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��
timeFormatrRrS)r^rT�rr'r�r�trrr�test_formatTimeWithNoFormat�sz/TimeFormattingTests.test_formatTimeWithNoFormatcCs td�}|�t|dd�d�dS)z2
        Alternate time format in output.
        rWz%Y/%Wr]z2013/38Nr_r`rrr�&test_formatTimeWithAlternateTimeFormat�sz:TimeFormattingTests.test_formatTimeWithAlternateTimeFormatcCs|�tddd�d�dS)z0
        "%f" supported in time format.
        g�?x��.Az%fr]Z234560NrUrrrr�test_formatTimePercentF�sz+TimeFormattingTests.test_formatTimePercentFN)
rBrCrDrErGrQrVrbrcrdrrrrrF�s0	rFc@sheZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�ZdS)�ClassicLogFormattingTestsz@
    Tests for classic text log event formatting functions.
    cCsHtdkrtd��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.
        NrHrPrW�XYZZY�r�log_timez%2013-09-24T11:40:47+0000 [-#-] XYZZY
)rrrrrr.r'r)rrarrrr�test_formatTimeDefaults��z0ClassicLogFormattingTests.test_formatTimeDefaultcCs,dd�}tddd�}|�t||d�d�dS)	zc
        Time is first field.  Custom formatting function is an optional
        argument.
        cSs
d�|�S)Nz__{0}__)r)rarrrr"rzAClassicLogFormattingTests.test_formatTimeCustom.<locals>.<lambda>rfi90rg)rz__12345__ [-#-] XYZZY
N�r.r'r)rrrrrr�test_formatTimeCustoms
�z/ClassicLogFormattingTests.test_formatTimeCustomcCs tddd�}|�t|�d�dS)z:
        Namespace is first part of second field.
        rf�my.namespace)r�
log_namespacez- [my.namespace#-] XYZZY
Nrj�rrrrr�test_formatNamespace%s
�z.ClassicLogFormattingTests.test_formatNamespacecCs"tdtjd�}|�t|�d�dS)z7
        Level is second part of second field.
        rf)r�	log_levelz- [-#warn] XYZZY
N�r.r�warnr'rrnrrr�test_formatLevel0s
�z*ClassicLogFormattingTests.test_formatLevelcCs tddd�}|�t|�d�dS)z)
        System is second field.
        rf�S.Y.S.T.E.M.�r�
log_system�- [S.Y.S.T.E.M.] XYZZY
Nrjrnrrr�test_formatSystem;s
�z+ClassicLogFormattingTests.test_formatSystemcCs&tddtjdd�}|�t|�d�dS)�B
        System is not supplanted by namespace and level.
        rfrlrt)rrmrprvrwNrqrnrrr�test_formatSystemRulzFs��z/ClassicLogFormattingTests.test_formatSystemRulzcCs"tdt�d�}|�t|�d�dS)ryrfruz- [UNFORMATTABLE] XYZZY
N)r.r<r'rrnrrr�test_formatSystemUnformattableVs
�z8ClassicLogFormattingTests.test_formatSystemUnformattablecCs tddd�}|�t|�d�dS)z0
        Formatted event is last field.
        zid:{id}�123�r�idz- [-#-] id:123
Nrjrnrrr�test_formatFormatas
�z+ClassicLogFormattingTests.test_formatFormatcCstdd�}|�t|�d�dS)z#
        No format string.
        r|)r~N�r.rrrnrrr�test_formatNoFormatls

�z-ClassicLogFormattingTests.test_formatNoFormatcCs tddd�}|�t|�d�dS)z&
        Empty format string.
        rr|r}Nr�rnrrr�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"
Nrjrnrrr�test_formatFormatMultiLine�s

�z4ClassicLogFormattingTests.test_formatFormatMultiLineN)rBrCrDrErirkrorsrxrzr{rr�r�r�rrrrre�s
rec@seZdZdZdd�ZdS)�FormatFieldTestsz+
    Tests for format field functions.
    cCs>|�tdtddd�d��d�|�tdtdd�d	��d
�dS)z�
        L{formatWithCall} is an extended version of L{unicode.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()}.ZearthcSsdS)N�mayberrrrrr"�rz6FormatFieldTests.test_formatWithCall.<locals>.<lambda>)ZworldZcallmezHello, earth. maybe.zHello, {repr()!r}.cSsdS)Nr)rrrrrr"�r)r)zHello, 'repr'.N)r'rr.rrrr�test_formatWithCall�s����z$FormatFieldTests.test_formatWithCallN)rBrCrDrEr�rrrrr��sr�c@seZdZdZdd�ZdS)r<z>
    An object that raises an exception from C{__repr__}.
    cCstdd�Sr4)�strrrrr�__repr__�szUnformattable.__repr__N)rBrCrDrEr�rrrrr<�sr<c@seZdZdZdS)�
CapturedErrorz3
    A captured error for use in format tests.
    N)rBrCrDrErrrrr��sr�c@sxeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�EventAsTextTestszi
    Tests for L{eventAsText}, all of which ensure that the
    returned type is UTF-8 decoded text.
    cCsjztd��Wntk
r&t�}YnXddi}||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�rrr(r	�getTraceback�r�fr�	eventTextrrr�test_eventWithTraceback�s��z(EventAsTextTests.test_eventWithTracebackcCsjztd��Wntk
r&t�}YnXddi}||d<t|ddd�}|�t|���|�|�d|�dS)	zu
        An event with an empty C{log_format} key appends a traceback from
        the accompanying failure.
        r�rrr�TFr�Nr�r�rrr�"test_formatEmptyEventWithTraceback�s��z3EventAsTextTests.test_formatEmptyEventWithTracebackcCs|ztd��Wntk
r&t�}YnXddd�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�r3cSsddSr4rrrrrr"�rzHEventAsTextTests.test_formatUnformattableWithTraceback.<locals>.<lambda>r5r�TFr�N)r�rr�assertIsInstancer	r(r�r�rrr�%test_formatUnformattableWithTraceback�s ��z6EventAsTextTests.test_formatUnformattableWithTracebackcCs�ztd��Wntk
r&t�}YnXddddd�t�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�rr3r6cSsddSr4rrrrrr"rzMEventAsTextTests.test_formatUnformattableErrorWithTraceback.<locals>.<lambda>r8r�TFr�zMESSAGE LOSTN)r�rr<rr�r	r(r�r�rrr�*test_formatUnformattableErrorWithTracebacks*��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.
        rrr�TFr�z'(UNABLE TO OBTAIN TRACEBACK FROM EVENT)N)r1rr�r	r(�rrr�rrr�&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)rr�r	r(r�rrr�test_formatEventNonCritical5s��z,EventAsTextTests.test_formatEventNonCriticalcCsbztd��Wntk
r&t�}YnXddi}||d<t|ddd�}|�d|�|�d|�d	S)
zU
        An exception message with multibyte characters is properly handled.
        u€rr�r�TFr��	TracebackN)r�rrr(r�rrr�test_formatTracebackMultibyteEs��z.EventAsTextTests.test_formatTracebackMultibytecCstztd��Wntk
r&t�}YnXddi}||d<t|ddd�}|�d|�tsd|�d	|�n|�d
|�dS)zj
        An error raised attempting to decode the UTF still produces a
        valid log message.
        s
��testrr�r�TFr�r�u��testz.CapturedError(b'\xff\xfet\x00e\x00s\x00t\x00')N)r�rrr(rr�rrr�,test_formatTracebackHandlesUTF8DecodeFailure[s(���z=EventAsTextTests.test_formatTracebackHandlesUTF8DecodeFailurecCsdztd��Wntk
r&t�}YnXtd�}dd|d�}||d<t|dddd	�}|�|d
�dS)zq
        If includeSystem is specified as the only option no timestamp or
        traceback are printed.
        r�rW�ABCD�fake_system�rrvrhr�FT�r�ZincludeTracebackr�z[fake_system] ABCDN�r�rrrr'�rr�rarr�rrr�test_eventAsTextSystemOnlyys(���z+EventAsTextTests.test_eventAsTextSystemOnlycCs�tdkrtd��t|�td�ztd��Wntk
rFt�}YnXtd�}dd|d�}||d	<t|d
ddd�}|�|d
�dS)zq
        If includeTimestamp is specified as the only option no system or
        traceback are printed.
        NrHrPr�rWr�r�r�r�TFr�z2013-09-24T11:40:47+0000 ABCD)	rrrrr�rrrr'r�rrr�test_eventAsTextTimestampOnly�s4����z.EventAsTextTests.test_eventAsTextTimestampOnlycCsbztd��Wntk
r&t�}YnXtd�}d|d�}||d<t|dddd�}|�|d	�d
S)z\
        If includeSystem is specified with a missing system [-#-]
        is used.
        r�rWr�rgr�FTr�z
[-#-] ABCDNr�r�rrr�test_eventAsTextSystemMissing�s&���z.EventAsTextTests.test_eventAsTextSystemMissingcCshztd��Wntk
r&t�}YnXtd�}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�rWr�Ztest)rrhrprmr�FTr�z[test#info] ABCDN�r�rrr�inforr'r�rrr�.test_eventAsTextSystemMissingNamespaceAndLevel�s*���z?EventAsTextTests.test_eventAsTextSystemMissingNamespaceAndLevelcCsfztd��Wntk
r&t�}YnXtd�}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�rWr�)rrhrpr�FTr�z
[-#info] ABCDNr�r�rrr�&test_eventAsTextSystemMissingLevelOnly�s(���z7EventAsTextTests.test_eventAsTextSystemMissingLevelOnlyN)rBrCrDrEr�r�r�r�r�r�r�r�r�r�r�r�r�rrrrr��s%r�)$rEZ!twisted.python.test.test_tzhelperrrr�timer�ImportErrorZ
twisted.trialrZtwisted.trial.unittestrZtwisted.python.compatrr	Z_levelsrZ_formatrr
rrrrZtwisted.python.failurerZTestCaserrFrer�r1r<�	Exceptionr�r�rrrr�<module>s*
 Z