Ë
    oj‚  ã                   ó–   — 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y)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                   ó<   — e Zd ZdZd	d„Zdedee   dee   defd„Zy)
Ú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                 ó&   — t        d„ «      | _        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   � r   N)r   Úkeys)Úselfs    r   Ú__init__zKeyFlattener.__init__   s   € ô %0±	Ó$:ˆ�	r   Ú	fieldNameÚ
formatSpecÚ
conversionc                 óÐ   — |€d}|€d}dj                  |||¬«      }| j                  |xx   dz  cc<   | j                  |   }|dk7  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.
        Ú 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‰I�fÑˆØ�Š6Ø�cœC §	¡	¨&Ñ 1Ó2Ñ2Ñ2ˆFØˆr   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r    r   r   r   r   r      s9   „ ñó
;ðØðØ*2°3©-ðØEMÈcÁ]ðà	ôr   r   Úeventr   Nc                 óÜ  — | j                  dd«      €yd| v r| d   }ni }t        «       }t        j                  | d   «      D ]   \  }}}}|€Œ|dk7  rd}|j	                  |||«      }|j	                  ||d«      }||v rŒ=|j                  d«      r|dd }d	}	nd
}	t        j                  |d| «      }
|
d   }|dk(  rt        }nt        }|	r |«       } ||«      }|||<   |||<   Œ¢ |r|| d<   yy)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ˆØ$×,Ñ,¨Y¸
ÀBÓGˆà˜6Ñ!àà×Ñ˜dÔ#Ø! # 2˜ˆIØ‰FàˆFä×$Ñ$ Y°°EÓ:ˆØ˜1‘Xˆ
à˜ÒÜ!%Ñä!$ÐáÙ#›ˆJá+¨JÓ7ˆØ-ˆˆ|ÑØ *ˆˆ}ÒðG#+ñJ Ø!'ˆˆoÒð r   r8   c                 ó¶   — t        «       }t        j                  d| z   dz   «      \  \  }}}}|€J ‚|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.
    ú{ú}r(   )r   r-   r.   r    r<   )r8   r%   r3   r4   r   r   r   Úkeys           r   ÚextractFieldrA   {   su   € ô  “>€Lä9C×9IÑ9IØˆe‰�cÑó:Ñ6Ñ5€k�9˜j¨*ð Ð Ð Ð à
×
Ñ
˜y¨*°jÓ
A€Cà˜eÑ#Ü�UÔà�Ñ! #Ñ&Ð&r   c                 ó  — | d   }t        «       }g }t        j                  | d   «      D ]O  \  }}}}|j                  |«       |€Œ|j	                  |||xs d«      }|j                  t        ||   «      «       ŒQ dj                  |«      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   )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ˆ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      sn   ðñ
õ $Ý ß &Ñ &å !á‹[€
÷)ñ )ðX8(˜ð 8( Tó 8(ðv'˜ð ' Hð '°ó 'ð>�hð  3ô r   