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: //proc/self/root/usr/lib/python3/dist-packages/twisted/logger/__pycache__/_flatten.cpython-38.pyc
U


W[��@sZdZddlmZddlmZddlmZe�ZGdd�de�Z	dd�Z
d	d
�Zdd�Zd
S)z�
Code related to "flattening" events; that is, extracting a description of all
relevant fields from the format string and persisting them for later
examination.
�)�	Formatter)�defaultdict)�unicodec@s eZdZdZdd�Zdd�ZdS)�KeyFlattenerz�
    A L{KeyFlattener} computes keys for the things within curly braces in
    PEP-3101-style format strings as parsed by L{string.Formatter.parse}.
    cCstdd��|_dS)z/
        Initialize a L{KeyFlattener}.
        cSsdS)Nr�rrr�9/usr/lib/python3/dist-packages/twisted/logger/_flatten.py�<lambda>�z'KeyFlattener.__init__.<locals>.<lambda>N)r�keys)�selfrrr�__init__szKeyFlattener.__init__cCsVdj||pd|pdd�}|j|d7<|j|}|dkrR|dt|j|�7}|S)a
        Compute a string key for a given field/format/conversion.

        @param fieldName: A format field name.
        @type fieldName: L{str}

        @param formatSpec: A format spec.
        @type formatSpec: L{str}

        @param conversion: A format field conversion type.
        @type conversion: L{str}

        @return: A key specific to the given field, format and conversion, as
            well as the occurrence of that combination within this
            L{KeyFlattener}'s lifetime.
        @rtype: L{str}
        z%{fieldName}!{conversion}:{formatSpec}�)�	fieldName�
formatSpec�
conversion��/)�formatr
�str)rrrr�result�nrrr�flatKey!s��
zKeyFlattener.flatKeyN)�__name__�
__module__�__qualname__�__doc__rrrrrrrsrcCs|�dd�dkrdSd|kr&|d}ni}t�}t�|d�D]�\}}}}|dkrTq>|dkr`d}|�|||�}|�||d�}||kr�q>|�d�r�|dd�}d	}	nd
}	t�|d|�}
|
d}|dkr�t}nt}|	r�|�}||�}
|
||<|||<q>|r�||d<dS)
z�
    Flatten the given event by pre-associating format fields with specific
    objects and callable results in a L{dict} put into the C{"log_flattened"}
    key in the event.

    @param event: A logging event.
    @type event: L{dict}
    �
log_formatN�
log_flattened�r�sr
z()���TFrr)	�getr�
aFormatter�parser�endswithZ	get_field�reprr)�eventZfields�keyFlattener�literalTextrrrZflattenedKeyZ
structuredKeyZcallit�fieldZ
fieldValueZconversionFunctionZflattenedValuerrr�flattenEventCs@	
�

r*cCsLt�}t�d|d�\\}}}}|�|||�}d|kr@t|�|d|S)a�
    Extract a given format field from the given event.

    @param field: A string describing a format field or log key.  This is the
        text that would normally fall between a pair of curly braces in a
        format string: for example, C{"key[2].attribute"}.  If a conversion is
        specified (the thing after the C{"!"} character in a format field) then
        the result will always be L{unicode}.
    @type field: L{str} (native string)

    @param event: A log event.
    @type event: L{dict}

    @return: A value extracted from the field.
    @rtype: L{object}

    @raise KeyError: if the field is not found in the given event.
    �{�}r)rr"r#rr*)r)r&r'r(rrr�keyrrr�extractField�s
�r.c
Csr|d}g}t�}t�|d�}|D]B\}}}}|�|�|dk	r$|�|||pPd�}	|�t||	��q$d�|�S)z�
    Format an event which has been flattened with L{flattenEvent}.

    @param event: A logging event.
    @type event: L{dict}

    @return: A formatted string.
    @rtype: L{unicode}
    rrNrr
)rr"r#�appendrr�join)
r&ZfieldValuesrr'ZformatFieldsr(rrrr-rrr�
flatFormat�s

�r1N)
r�stringr�collectionsrZtwisted.python.compatrr"�objectrr*r.r1rrrr�<module>s/=