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_flatten.cpython-38.pyc
U


W[�#�@s�dZddlmZddlZzddlmZeWnek
rDdZYnXddlmZddl	m
Z
ddlmZm
Z
mZmZGd	d
�d
ej�ZdS)z+
Test cases for L{twisted.logger._format}.
�)�countN)�tzset)�unittest�)�formatEvent)�flattenEvent�extractField�KeyFlattener�
aFormatterc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zddd�Zd
d�Z	dd�Z
dd�Zdd�fdd�Zdd�Z
dd�Zdd�Zdd�Zd
S) �FlatFormattingTestsz9
    Tests for flattened event formatting functions.
    cstt��Gdd�dt�}td�fdd�|�dddd	�}t|�t|�}|d
=|d=t�t�|��}|�t|�d�d
S)a)
        L{flattenEvent} will "flatten" an event so that, if scrubbed of all but
        serializable objects, it will preserve all necessary data to be
        formatted once serialized.  When presented with an event thusly
        flattened, L{formatEvent} will produce the same output.
        c@seZdZdZdS)z;FlatFormattingTests.test_formatFlatEvent.<locals>.Ephemeral�valueN)�__name__�
__module__�__qualname__Z	attribute�rr�B/usr/lib/python3/dist-packages/twisted/logger/test/test_flatten.py�	Ephemeral*srz�callable: {callme()} attribute: {object.attribute} numrepr: {number!r} numstr: {number!s} strrepr: {string!r} unistr: {unistr!s}cst��S�N)�nextr�Zcounterrr�<lambda>6�z:FlatFormattingTests.test_formatFlatEvent.<locals>.<lambda>��hello�ö)�
log_format�callme�object�number�stringZunistrrruMcallable: 0 attribute: value numrepr: 7 numstr: 7 strrepr: 'hello' unistr: öN)	rr�dictr�json�loads�dumps�assertEqualr)�selfr�event1�event2Zevent3rrr�test_formatFlatEvent!s&
�
�z(FlatFormattingTests.test_formatFlatEventcCs<tddd�}t|�t�t�|��}|�t|��d��dS)zH
        If the format string is invalid, an error is produced.
        zstrrepr: {string!X}r)rrzUnable to format eventN)r rr!r"r#Z
assertTruer�
startswith)r%r&r'rrr�test_formatFlatEventBadFormatMs��z1FlatFormattingTests.test_formatFlatEventBadFormatcCsFGdd�dt�}|�}td|d�}t|�|��|�t|�d�dS)z�
        L{formatEvent} will prefer the stored C{str()} or C{repr()} value for
        an object, in case the other version.
        c@s$eZdZdZdZdd�Zdd�ZdS)zPFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistablez.
            Unpersitable object.
            FcSs
d|_dS)z0
                Self destruct.
                TN��
destructed�r%rrr�selfDestructksz]FlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.selfDestructcSs|jr
dSdSdS)Nzpost-serialization garbagezun-persistabler+r-rrr�__repr__qszYFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.__repr__N)r
rr�__doc__r,r.r/rrrr�
Unpersistableesr1zunpersistable: {unpersistable})rZ
unpersistablezunpersistable: un-persistableN)rr rr.r$r)r%r1Zupr&rrr�%test_formatFlatEventWithMutatedFields`s�z9FlatFormattingTests.test_formatFlatEventWithMutatedFieldscCs
dd�}z|�|d�d�Wntk
r2�YnX|�|d�d�|�|d�d�|�|d	�d
�|�|d�d�|�|d
�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�t�d�\}|dd�}t�}|�|j|�d�|�|j|�d�dS)zh
        Test that L{KeyFlattener.flatKey} returns the expected keys for format
        fields.
        cSs.t�|�D]\}}}}t��|||�SdSr)r
�parser	�flatKey)�formatZliteralTextZ	fieldNameZ
formatSpecZ
conversionrrr�
keyFromFormat�s��z=FlatFormattingTests.test_keyFlattening.<locals>.keyFromFormatz{}z!:z{foo}zfoo!:z{foo!s}zfoo!s:z{foo!r}zfoo!r:z{foo:%s}zfoo!:%sz{foo:!}zfoo!:!z{foo::}zfoo!::z
{foo!s:%s}zfoo!s:%sz	{foo!s:!}zfoo!s:!z	{foo!s::}zfoo!s::z{x}�Nzx!:zx!:/2)r$�
ValueErrorr
r3r	r4)r%r6ZkeyPlusLiteral�keyZ
sameFlattenerrrr�test_keyFlattening�s&z&FlatFormattingTests.test_keyFlatteningNcsL|dkr0t��G�fdd�dt�}td|�d�}t|�|�t|�d�|S)z�
        The same format field used twice in one event is rendered twice.

        @param event: An event to flatten.  If L{None}, create a new event.
        @return: C{event} or the event created.
        NcseZdZdZ�fdd�ZdS)zJFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStrz&
                Hack
                cstt���Sr)�strrr-rrr�__str__�szRFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStr.__str__N)r
rrr0r<rrrr�CountStr�sr=z{x} {x}�r�xz0 1)rrr rr$r)r%�eventr=rrr�$_test_formatFlatEvent_fieldNamesSame�s�z8FlatFormattingTests._test_formatFlatEvent_fieldNamesSamecCs|��dS)zR
        The same format field used twice in one event is rendered twice.
        N�rAr-rrr�"test_formatFlatEventFieldNamesSame�sz6FlatFormattingTests.test_formatFlatEventFieldNamesSamecCs|��}|�|�dS)zb
        The same event flattened twice gives the same (already rendered)
        result.
        NrB)r%r@rrr�'test_formatFlatEventFieldNamesSameAgain�sz;FlatFormattingTests.test_formatFlatEventFieldNamesSameAgaincCs,tddd�}t|�t|�}|�|d�dS)zs
        L{formatEvent} will handle a flattened event with tailing text after
        a replacement field.
        ztest {x} trailingrr>ztest value trailingN)r rrr$)r%r@�resultrrr� test_formatEventFlatTrailingText�s�z4FlatFormattingTests.test_formatEventFlatTrailingTextcCs|Srr)r?rrrr�rzFlatFormattingTests.<lambda>cszGdd�dt��G�fdd�dt�}td|�d�}||���fdd�}|�|d	�d
�|�|d�d�|�|d
�d�dS)z�
        L{extractField} will extract a field used in the format string.

        @param flattenFirst: callable to flatten an event
        c@seZdZdd�ZdS)z=FlatFormattingTests.test_extractField.<locals>.ObjectWithReprcSsdS)N�reprrr-rrrr/�szFFlatFormattingTests.test_extractField.<locals>.ObjectWithRepr.__repr__N)r
rrr/rrrr�ObjectWithRepr�srHcs eZdZ�fdd�Zdd�ZdS)z8FlatFormattingTests.test_extractField.<locals>.Somethingcsd|_��|_dS)Nr)rrr-�rHrr�__init__�szAFlatFormattingTests.test_extractField.<locals>.Something.__init__cSstd��dS)Nz
Just in case.)�NotImplementedErrorr-rrr�__getstate__�szEFlatFormattingTests.test_extractField.<locals>.Something.__getstate__N)r
rrrJrLrrIrr�	Something�srMz%{something.number} {something.object})rZ	somethingcs
t|��Sr)r)Zfield)�	flattenedrr�extractsz6FlatFormattingTests.test_extractField.<locals>.extractzsomething.numberrzsomething.number!s�7zsomething.object!srGN)rr r$)r%ZflattenFirstrMr@rOr)rHrNr�test_extractField�s�z%FlatFormattingTests.test_extractFieldcCsdd�}|�|�dS)zi
        L{extractField} behaves identically if the event is explicitly
        flattened first.
        cSst|�|Sr)r)ZevtrrrrNszDFlatFormattingTests.test_extractFieldFlattenFirst.<locals>.flattenedN)rQ)r%rNrrr�test_extractFieldFlattenFirstsz1FlatFormattingTests.test_extractFieldFlattenFirstcCs(ddd�}t|�|�|ddd��dS)zT
        L{flattenEvent} will do nothing to an event with no format string.
        �br7)�a�cN�rr$�r%Z
inputEventrrr�test_flattenEventWithoutFormats
z2FlatFormattingTests.test_flattenEventWithoutFormatcCs,dddd�}t|�|�|dddd��dS)zz
        L{flattenEvent} will do nothing to an event with a format string that
        contains no format fields.
        rSr7zsimple message�rTrUrNrVrWrrr� test_flattenEventWithInertFormat$s��z4FlatFormattingTests.test_flattenEventWithInertFormatcCs,dddd�}t|�|�|dddd��dS)zb
        L{flattenEvent} will do nothing to an event with log_format set to
        None.
        rSr7NrYrVrWrrr�test_flattenEventWithNoneFormat5s��z3FlatFormattingTests.test_flattenEventWithNoneFormat)N)r
rrr0r(r*r2r:rArCrDrFrQrRrXrZr[rrrrrs,"1
	!	r)r0�	itertoolsrr!�timer�ImportErrorZ
twisted.trialrZ_formatrZ_flattenrrr	r
ZTestCaserrrrr�<module>s