ó
    Ö›‘h‚  ã                   óœ   • S r SSKJr  SSKJr  SSKJrJrJr  SSK	J
r
  \" 5       r " S S5      rS	\
S
S4S jrS\S	\
S
\4S jrS	\
S
\4S jrg)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                   óH   • \ rS rSrSrSS jrS\S\\   S\\   S\4S	 jrS
r	g)ÚKeyFlatteneré   z�
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                 ó&   • [        S 5      U l        g)z
Initialize a L{KeyFlattener}.
c                  ó   • g)Nr   © r   ó    Ú[C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/logger/_flatten.pyÚ<lambda>Ú'KeyFlattener.__init__.<locals>.<lambda>   s   € ¸r   N)r   Úkeys)Úselfs    r   Ú__init__ÚKeyFlattener.__init__   s   € ô %0±	Ó$:ˆ�	r   Ú	fieldNameÚ
formatSpecÚ
conversionc                 óÐ   • Uc  SnUc  SnSR                  UUUS9nU R                  U==   S-  ss'   U R                  U   nUS:w  a  US[        U R                  U   5      -   -  nU$ )aZ  
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})r   r   r   r   Ú/)Úformatr   Ústr)r   r   r   r   ÚresultÚns         r   ÚflatKeyÚKeyFlattener.flatKey    s†   € ð ÑØˆJàÑØˆJà8×?Ñ?ØØ!Ø!ð @ð 
ˆð
 	�	‰	�&Ó˜QÑÓØ�I‰I�fÑˆØ�‹6Ø�cœC §	¡	¨&Ñ 1Ó2Ñ2Ñ2ˆFØˆr   )r   )r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r    r   r#   Ú__static_attributes__r   r   r   r   r      s9   † ñô
;ðØðØ*2°3©-ðØEMÈcÁ]ðà	÷r   r   Úeventr   Nc                 ó  • U R                  SS5      c  gSU ;   a  U S   nO0 n[        5       n[        R                  U S   5       H«  u  p4pVUc  M  US:w  a  SnUR	                  XEU5      nUR	                  XES5      nXq;   a  M>  UR                  S5      (       a  USS nS	n	OS
n	[        R                  USU 5      n
U
S   nUS:X  a  [        nO[        nU	(       a  U" 5       nU" U5      nXÑU'   X±U'   M­     U(       a  XS'   gg)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   ÚflattenEventrB   @   s,  € ð ‡y�y�˜tÓ$Ñ,Øà˜%ÓØ�Ñ'‰àˆä“>€Lä:D×:JÑ:JØˆlÑö;Ñ6ˆ 
ð ÑÙà˜ÓØˆJà#×+Ñ+¨IÀ:ÓNˆØ$×,Ñ,¨YÀBÓGˆàÓ!áà×Ñ˜d×#Ñ#Ø! # 2˜ˆIØ‰FàˆFä×$Ñ$ Y°°EÓ:ˆØ˜1‘Xˆ
à˜ÓÜ!%Ñä!$ÐæÙ#›ˆJá+¨JÓ7ˆØ-ˆ|ÑØ *ˆ}ÓñG;öJ Ø!'ˆoÒð r   r>   c                 ó¶   • [        5       n[        R                  SU -   S-   5      u  u  p4pVUc   eUR                  XEU5      nSU;  a  [	        U5        US   U   $ )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.   )r   r3   r4   r#   rB   )r>   r+   r9   r:   r   r   r   Úkeys           r   ÚextractFieldrG   {   so   € ô  “>€Lä9C×9IÑ9IØˆe‰�cÑó:Ñ6Ñ5€k˜jð Ñ Ð Ð à
×
Ñ
˜y°jÓ
A€Cà˜eÓ#Ü�UÔà�Ñ! #Ñ&Ð&r   c                 ó$  • U S   n[        5       n/ n[        R                  U S   5       HS  u  pEpgUR                  U5        Uc  M  UR	                  XVU=(       d    S5      nUR                  [        X   5      5        MU     SR                  U5      $ )z~
Format an event which has been flattened with L{flattenEvent}.

@param event: A logging event.

@return: A formatted string.
r.   r-   r0   r   )r   r3   r4   Úappendr#   r    Újoin)	r+   ÚfieldValuesr9   r0   r:   r   r   r   rF   s	            r   Ú
flatFormatrL   š   s‹   € ð ˜Ñ(€KÜ“>€LØ
€Aä:D×:JÑ:JØˆlÑö;Ñ6ˆ 
ð 	
�‰�ÔàÓ Ø×&Ñ& y¸j×>OÈCÓPˆCØ�H‰H”S˜Ñ)Ó*Ö+ñ;ð �7‰7�1‹:Ðr   )r)   Úcollectionsr   Ústringr   Útypingr   r   r   Ú_interfacesr	   r3   r   rB   r    rG   rL   r   r   r   Ú<module>rQ      sn   ðñ
õ $Ý ß &Ñ &å !á‹[€
÷)ñ )ðX8(˜ð 8( Tô 8(ðv'˜ð ' Hð '°ô 'ð>�hð  3õ r   