§
    Ètºf‚  ã                   ó¤   — d Z ddlmZ ddlmZ ddlmZmZmZ ddl	m
Z
  e¦   «         Z G d„ d¦  «        Zd	e
d
dfd„Zded	e
d
efd„Zd	e
d
efd„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.
é    )Údefaultdict)Ú	Formatter)ÚAnyÚDictÚOptionalé   )ÚLogEventc                   óJ   — e Zd ZdZd	d„Zdedee         dee         defd„ZdS )
Ú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                 ó0   — t          d„ ¦  «        | _        dS )z/
        Initialize a L{KeyFlattener}.
        c                  ó   — dS )Nr   © r   ó    úV/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/logger/_flatten.pyú<lambda>z'KeyFlattener.__init__.<locals>.<lambda>   s   € ¸€ r   N)r   Úkeys)Úselfs    r   Ú__init__zKeyFlattener.__init__   s   € õ %0°	°	Ñ$:Ô$:ˆŒ	ˆ	ˆ	r   Ú	fieldNameÚ
formatSpecÚ
conversionc                 óÖ   — |€d}|€d}d                      |||¬¦  «        }| j        |xx         dz  cc<   | j        |         }|dk    r |dt          | j        |         ¦  «        z   z  }|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.
        NÚ z%{fieldName}!{conversion}:{formatSpec})r   r   r   r   ú/)Úformatr   Ústr)r   r   r   r   ÚresultÚns         r   ÚflatKeyzKeyFlattener.flatKey    s–   € ð ÐØˆJàÐØˆJà8×?Ò?ØØ!Ø!ð @ñ 
ô 
ˆð
 	Œ	�&ÐÐÔ˜QÑÐÐÑØŒI�fÔˆØ�Š6ˆ6Ø�c�C ¤	¨&Ô 1Ñ2Ô2Ñ2Ñ2ˆFØˆr   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r   r   r   r   r      sn   € € € € € ðð ð
;ð ;ð ;ð ;ðØðØ*2°3¬-ðØEMÈcÄ]ðà	ðð ð ð ð ð r   r   Úeventr   Nc                 óJ  — |                       dd¦  «        €dS d| v r	| d         }ni }t          ¦   «         }t                               | d         ¦  «        D ]Ã\  }}}}|€Œ
|dk    rd}|                     |||¦  «        }|                     ||d¦  «        }||v rŒE|                     d¦  «        r|dd…         }d	}	nd
}	t                               |d| ¦  «        }
|
d         }|dk    rt          }nt          }|	r
 |¦   «         } ||¦  «        }|||<   |||<   ŒÄ|r|| d<   dS dS )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Úsr   z()éþÿÿÿTFr   r   )	Úgetr   Ú
aFormatterÚparser    ÚendswithÚ	get_fieldÚreprr   )r%   ÚfieldsÚkeyFlattenerÚliteralTextr   r   r   Ú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ÔNˆØ$×,Ò,¨Y¸
ÀBÑGÔGˆà˜6Ð!Ð!àà×Ò˜dÑ#Ô#ð 	Ø! # 2 #œˆIØˆFˆFàˆFå×$Ò$ Y°°EÑ:Ô:ˆØ˜1”Xˆ
à˜ÒÐÝ!%ÐÐå!$Ðàð 	&Ø#˜™œˆJà+Ð+¨JÑ7Ô7ˆØ-ˆˆ|ÑØ *ˆˆ}ÑÐàð (Ø!'ˆˆoÑÐÐð(ð (r   r8   c                 óä   — t          ¦   «         }t                               d| z   dz   ¦  «        \  \  }}}}|€J ‚|                     |||¦  «        }d|vr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 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.
    Ú{Ú}Nr(   )r   r-   r.   r    r<   )r8   r%   r3   r4   r   r   r   Úkeys           r   ÚextractFieldrA   {   sˆ   € õ  ‘>”>€Lå9C×9IÒ9IØˆe‰�cÑñ:ô :Ñ6Ñ5€k�9˜j¨*ð Ð Ð Ð à
×
Ò
˜y¨*°jÑ
AÔ
A€Cà˜eÐ#Ð#Ý�UÑÔÐà�Ô! #Ô&Ð&r   c                 ó\  — | d         }t          ¦   «         }g }t                               | d         ¦  «        D ]_\  }}}}|                     |¦  «         |�A|                     |||pd¦  «        }|                     t          ||         ¦  «        ¦  «         Œ`d                     |¦  «        S )zŽ
    Format an event which has been flattened with L{flattenEvent}.

    @param event: A logging event.

    @return: A formatted string.
    r(   r'   Nr*   r   )r   r-   r.   Úappendr    r   Újoin)	r%   ÚfieldValuesr3   r*   r4   r   r   r   r@   s	            r   Ú
flatFormatrF   š   s²   € ð ˜Ô(€KÝ‘>”>€LØ
€Aå:D×:JÒ:JØˆlÔñ;ô ;ð ,ð ,Ñ6ˆ�Y 
¨Jð 	
�Š�ÑÔÐàÐ Ø×&Ò& y°*¸jÐ>OÈCÑPÔPˆCØ�HŠH•S˜ SÔ)Ñ*Ô*Ñ+Ô+Ð+øà�7Š7�1‰:Œ:Ðr   )r$   Úcollectionsr   Ústringr   Útypingr   r   r   Ú_interfacesr	   r-   r   r<   r   rA   rF   r   r   r   ú<module>rK      s  ðð
ð ð $Ð #Ð #Ð #Ð #Ð #Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &Ð &à !Ð !Ð !Ð !Ð !Ð !àˆY‰[Œ[€
ð)ð )ð )ð )ð )ñ )ô )ð )ðX8(˜ð 8( Tð 8(ð 8(ð 8(ð 8(ðv'˜ð ' Hð '°ð 'ð 'ð 'ð 'ð>�hð  3ð ð ð ð ð ð r   