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 :  /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 : /lib/python3/dist-packages/twisted/logger/test/__pycache__/test_flatten.cpython-310.pyc
o

�b�%�@s�dZddlZddlmZddlmZmZmZzddlm	Z	Wne
y)dZ	YnwddlmZddl
mZmZmZmZdd	lmZdd
lmZGdd�dej�ZdS)
z+
Test cases for L{twisted.logger._format}.
�N)�count)�Any�Callable�Optional)�tzset)�unittest�)�KeyFlattener�
aFormatter�extractField�flattenEvent)�formatEvent)�LogEventc@s�eZdZdZd"dd�Zd"dd�Zd"dd	�Zd"d
d�Z	d#dee	de	fd
d�Z
d"dd�Zd"dd�Zd"dd�Z
dd�fdee	ge	fddfdd�Zd"dd�Zd"dd�Zd"dd�Zd"d d!�ZdS)$�FlatFormattingTestsz9
    Tests for flattened event formatting functions.
    �returnNcsrt��Gdd�d�}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__�	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��counterrr�<lambda>1sz:FlatFormattingTests.test_formatFlatEvent.<locals>.<lambda>��hello�ö)�
log_format�callme�object�number�string�unistrr"r#uMcallable: 0 attribute: value numrepr: 7 numstr: 7 strrepr: 'hello' unistr: öN)r�dictr�json�loads�dumps�assertEqualr
)�selfr�event1�event2�event3rrr�test_formatFlatEvents&
��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)r!r%zUnable to format eventN)r'rr(r)r*�
assertTruer
�
startswith)r,r-r.rrr�test_formatFlatEventBadFormatJs�z1FlatFormattingTests.test_formatFlatEventBadFormatcCsDGdd�d�}|�}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,eZdZdZdZd	dd�Zdefdd�ZdS)
zPFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistablez.
            Unpersitable object.
            FrNcSs
d|_dS)z0
                Self destruct.
                TN��
destructed�r,rrr�selfDestructes
z]FlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.selfDestructcSs|jrdSdS)Nzpost-serialization garbagezun-persistabler4r6rrr�__repr__kszYFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.__repr__�rN)rrr�__doc__r5r7�strr8rrrr�
Unpersistable^s

r<zunpersistable: {unpersistable})r!�
unpersistablezunpersistable: un-persistableN)r'rr7r+r
)r,r<�upr-rrr�%test_formatFlatEventWithMutatedFieldsXsz9FlatFormattingTests.test_formatFlatEventWithMutatedFieldscCsdtdtfdd�}z
|�|d�d�Wnty�w|�|d�d�|�|d	�d
�|�|d�d�|�|d
�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�|�|d�d�t�}t�d�\\}}}}|duswJ�|�|�|||�d�|�|�|||�d�dS)zh
        Test that L{KeyFlattener.flatKey} returns the expected keys for format
        fields.
        �formatrcSs>t�|�D]\}}}}|dusJ�t��|||�SJd��)NFz*Unable to derive key from format: {format})r
�parser	�flatKey)r@�literalText�	fieldName�
formatSpec�
conversionrrr�
keyFromFormats�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;r+�
ValueErrorr	r
rArB)r,rG�
sameFlattenerrCrDrErFrrr�test_keyFlatteningys<����z&FlatFormattingTests.test_keyFlattening�eventcsJ|durt��G�fdd�d�}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.
        Ncs"eZdZdZdef�fdd�ZdS)zJFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStrz&
                Hack
                rcstt���Sr)r;rr6rrr�__str__�szRFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStr.__str__N)rrrr:r;rLrrrr�CountStr�srMz{x} {x}�r!�xz0 1)rr'rr+r
)r,rKrMrrr�$_test_formatFlatEvent_fieldNamesSame�s	�z8FlatFormattingTests._test_formatFlatEvent_fieldNamesSamecCs|��dS)zR
        The same format field used twice in one event is rendered twice.
        N�rPr6rrr�"test_formatFlatEventFieldNamesSame�sz6FlatFormattingTests.test_formatFlatEventFieldNamesSamecCs|��}|�|�dS)zb
        The same event flattened twice gives the same (already rendered)
        result.
        NrQ)r,rKrrr�'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} trailingrrNztest value trailingN)r'rr
r+)r,rK�resultrrr� test_formatEventFlatTrailingText�s�z4FlatFormattingTests.test_formatEventFlatTrailingTextcCs|Srr)rOrrrr�szFlatFormattingTests.<lambda>�flattenFirstcs�Gdd�d��G�fdd�d�}td|�d�}||��dtdtf�fd	d
�}|�|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@seZdZdefdd�ZdS)z=FlatFormattingTests.test_extractField.<locals>.ObjectWithReprrcSsdS)N�reprrr6rrrr8�szFFlatFormattingTests.test_extractField.<locals>.ObjectWithRepr.__repr__N)rrrr;r8rrrr�ObjectWithRepr�srXcs$eZdZd�fdd�Zddd�ZdS)z8FlatFormattingTests.test_extractField.<locals>.SomethingrNcsd|_��|_dS)Nr)r$r#r6�rXrr�__init__�szAFlatFormattingTests.test_extractField.<locals>.Something.__init__cSstd��)Nz
Just in case.)�NotImplementedErrorr6rrr�__getstate__szEFlatFormattingTests.test_extractField.<locals>.Something.__getstate__r9)rrrrZr\rrYrr�	Something�sr]z%{something.number} {something.object})r!�	something�fieldrcs
t|��Sr)r)r_)�	flattenedrr�extract
s
z6FlatFormattingTests.test_extractField.<locals>.extractzsomething.numberrzsomething.number!s�7zsomething.object!srWN)r'r;rr+)r,rVr]rKrar)rXr`r�test_extractField�s	�z%FlatFormattingTests.test_extractFieldcCs dtdtfdd�}|�|�dS)zi
        L{extractField} behaves identically if the event is explicitly
        flattened first.
        rKrcSst|�|Sr)r)rKrrrr`szDFlatFormattingTests.test_extractFieldFlattenFirst.<locals>.flattenedN)rrc)r,r`rrr�test_extractFieldFlattenFirstsz1FlatFormattingTests.test_extractFieldFlattenFirstcCs(ddd�}t|�|�|ddd��dS)zT
        L{flattenEvent} will do nothing to an event with no format string.
        �b�)�a�cN�rr+�r,�
inputEventrrr�test_flattenEventWithoutFormat s
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.
        rerfzsimple message�rgrhr!Nrirjrrr� test_flattenEventWithInertFormat(���z4FlatFormattingTests.test_flattenEventWithInertFormatcCs,dddd�}t|�|�|dddd��dS)zb
        L{flattenEvent} will do nothing to an event with log_format set to
        None.
        rerfNrmrirjrrr�test_flattenEventWithNoneFormat8roz3FlatFormattingTests.test_flattenEventWithNoneFormatr9r)rrrr:r0r3r?rJrrrPrRrSrUrrcrdrlrnrprrrrrs2

.

!>��
�


��
�
#

r)r:r(�	itertoolsr�typingrrr�timer�ImportError�
twisted.trialr�_flattenr	r
rr�_formatr
�_interfacesr�TestCaserrrrr�<module>s�

Anon7 - 2022
AnonSec Team