+
    üÐj¯%  ã                   óÄ   € R t ^ RIt^ RIHt ^ RIHtHtHt  ^ RIH	t	 ^ RIHt ^RIHtHtHtHt ^RIHt ^RIHt  ! R	 R
]P,                  4      tR#   ]
 d    Rt	 L@i ; i)z+
Test cases for L{twisted.logger._format}.
N)Úcount)ÚAnyÚCallableÚOptional)Útzset)Úunittest)ÚKeyFlattenerÚ
aFormatterÚextractFieldÚflattenEvent)ÚformatEvent©ÚLogEventc                   ó  a € ] tR t^t o RtV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR	 ltRV 3R lR llt	V 3R lR lt
V 3R lR ltV 3R lR ltR 3V 3R lR lltV 3R lR ltV 3R lR ltV 3R lR ltV 3R lR ltRtV tR
# ) ÚFlatFormattingTestsz1
Tests for flattened event formatting functions.
c                ó   <€ V ^8„  d   QhRR/# ©é   ÚreturnN© )ÚformatÚ__classdict__s   "€ÚB/usr/lib/python3/dist-packages/twisted/logger/test/test_flatten.pyÚ__annotate__Ú FlatFormattingTests.__annotate__   s   ø€ ÷ ,
ñ ,
 dñ ,
ó    c           	     ó&  a€ \        4       o ! R R4      p\        RV3R lV! 4       ^RRR7      p\        V4       \        V4      pVR VR	 \        P                  ! \        P
                  ! V4      4      pV P                  \        V4      R
4       R# )a  
L{flattenEvent} will "flatten" an event so that, if scrubbed of all but
serializable objects, it will preserve all necessary data to be
formatted once serialized.  When presented with an event thusly
flattened, L{formatEvent} will produce the same output.
c                   ó   € ] tR t^%tRtRtR# )Ú;FlatFormattingTests.test_formatFlatEvent.<locals>.EphemeralÚvaluer   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú	attributeÚ__static_attributes__r   r   r   Ú	Ephemeralr   %   s   † ØŒIr   r&   z€callable: {callme()} attribute: {object.attribute} numrepr: {number!r} numstr: {number!s} strrepr: {string!r} unistr: {unistr!s}c                  ó   <€ \        S 4      # ©N)Únext)Úcounters   €r   Ú<lambda>Ú:FlatFormattingTests.test_formatFlatEvent.<locals>.<lambda>1   s	   ø€ œ4 œ=r   Úhelloô   Ã¶)Ú
log_formatÚcallmeÚobjectÚnumberÚstringÚunistrr0   r1   uM   callable: 0 attribute: value numrepr: 7 numstr: 7 strrepr: 'hello' unistr: Ã¶N)r   Údictr   ÚjsonÚloadsÚdumpsÚassertEqualr   )Úselfr&   Úevent1Úevent2Úevent3r*   s   &    @r   Útest_formatFlatEventÚ(FlatFormattingTests.test_formatFlatEvent   s�   ø€ ô “'ˆ÷	 ñ 	 ô ð%ô )Ù“;ØØØô
ˆô  	�VÔä�f“ˆØ�8ÐØ�8ÐÜ—’œDŸJšJ vÓ.Ó/ˆØ×ÑÜ˜Óðö
	
r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   J   s   ø€ ÷ Rñ R¨tñ Rr   c                óÜ   € \        RRR7      p\        V4       \        P                  ! \        P                  ! V4      4      pV P                  \        V4      P                  R4      4       R# )z8
If the format string is invalid, an error is produced.
zstrrepr: {string!X}r-   )r/   r3   zUnable to format eventN)r5   r   r6   r7   r8   Ú
assertTruer   Ú
startswith)r:   r;   r<   s   &  r   Útest_formatFlatEventBadFormatÚ1FlatFormattingTests.test_formatFlatEventBadFormatJ   sR   € ô Ø-Øô
ˆô
 	�VÔÜ—’œDŸJšJ vÓ.Ó/ˆà�‰œ FÓ+×6Ñ6Ð7OÓPÖQr   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   X   s   ø€ ÷ Oñ O°tñ Or   c                ó®   €  ! R R4      pV! 4       p\        RVR7      p\        V4       VP                  4        V P                  \	        V4      R4       R# )zm
L{formatEvent} will prefer the stored C{str()} or C{repr()} value for
an object, in case the other version.
c                   óL   a € ] tR t^^t o RtRtV 3R lR ltV 3R lR ltRtV t	R# )	ÚPFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistablez
Unpersitable object.
Fc                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   Ú]FlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.__annotate__e   s   ø€ ÷ 'ñ ' dñ 'r   c                ó   € RV n         R# )z
Self destruct.
TN©Ú
destructed©r:   s   &r   ÚselfDestructÚ]FlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.selfDestructe   s   € ð #'�–r   c                ó    <€ V ^8„  d   QhRS[ /# ©r   r   ©Ústr)r   r   s   "€r   r   rK   k   s   ø€ ÷ ,ñ ,¡#ñ ,r   c                ó.   € V P                   '       d   R # R# )zpost-serialization garbagezun-persistablerM   rO   s   &r   Ú__repr__ÚYFlatFormattingTests.test_formatFlatEventWithMutatedFields.<locals>.Unpersistable.__repr__k   s   € Ø—?—?�?Ù7á+r   rM   N)
r    r!   r"   r#   Ú__doc__rN   rP   rW   r%   Ú__classdictcell__©r   s   @r   ÚUnpersistablerI   ^   s%   ø‡ € ñð ˆJ÷'ð '÷,ö ,r   r\   zunpersistable: {unpersistable})r/   Úunpersistablezunpersistable: un-persistableN)r5   r   rP   r9   r   )r:   r\   Úupr;   s   &   r   Ú%test_formatFlatEventWithMutatedFieldsÚ9FlatFormattingTests.test_formatFlatEventWithMutatedFieldsX   sK   € ÷	,ñ 	,ñ& ‹_ˆÜÐ!AÐQSÔTˆä�VÔØ
�‰Ôà×Ñœ VÓ,Ð.MÖNr   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   y   s   ø€ ÷ ;
ñ ;
 Dñ ;
r   c                óö  € R R lp V P                  V! R4      R4       T P                  T! R4      R4       T P                  T! R4      R4       T P                  T! R	4      R
4       T P                  T! R4      R4       T P                  T! R4      R4       T P                  T! R4      R4       T P                  T! R4      R4       T P                  T! R4      R4       T P                  T! R4      R4       \        4       p\        P                  ! R4      w  w  ppppTf   Q hT P                  TP                  YET4      R4       T P                  TP                  YET4      R4       R#   \         d    h i ; i)zP
Test that L{KeyFlattener.flatKey} returns the expected keys for format
fields.
c                ó0   € V ^8„  d   QhR\         R\         /# )r   r   r   rT   )r   s   "r   r   Ú<FlatFormattingTests.test_keyFlattening.<locals>.__annotate__   s   € ÷ 		Gñ 		G¤#ð 		G¬#ñ 		Gr   c                 ó”   € \         P                  ! V 4       F(  w  ppppVf   Q h\        4       P                  W#V4      u # 	  Q R4       h)Nz*Unable to derive key from format: {format})r	   Úparser   ÚflatKey)r   ÚliteralTextÚ	fieldNameÚ
formatSpecÚ
conversions   &    r   ÚkeyFromFormatÚ=FlatFormattingTests.test_keyFlattening.<locals>.keyFromFormat   sW   € ô ×!Ò! &Ö)ñØØØØà Ò,Ð,Ð,Ü#“~×-Ñ-¨iÀZÓPÒPñ *ð GÐFÓF�5r   z{}z!:z{foo}zfoo!:z{foo!s}zfoo!s:z{foo!r}zfoo!r:z{foo:%s}zfoo!:%sz{foo:!}zfoo!:!z{foo::}zfoo!::z
{foo!s:%s}zfoo!s:%sz	{foo!s:!}zfoo!s:!z	{foo!s::}zfoo!s::z{x}Nzx!:zx!:/2)r9   Ú
ValueErrorr   r	   rf   rg   )r:   rl   ÚsameFlattenerrh   ri   rj   rk   s   &      r   Útest_keyFlatteningÚ&FlatFormattingTests.test_keyFlatteningy   s{  € õ		Gð	Ø×Ñ™]¨4Ó0°$Ô7ð 	×Ñ™ wÓ/°Ô9ð 	×Ñ™ yÓ1°8Ô<Ø×Ñ™ yÓ1°8Ô<ð 	×Ñ™ zÓ2°IÔ>Ø×Ñ™ yÓ1°8Ô<Ø×Ñ™ yÓ1°8Ô<ð 	×Ñ™ |Ó4°jÔAØ×Ñ™ {Ó3°YÔ?Ø×Ñ™ {Ó3°YÔ?ä$›ˆô ×Ò˜UÓ#ñ	
ñØØØØð Ò$Ð$Ð$à×ÑØ×!Ñ! )¸ÓDÀeô	
ð 	×ÑØ×!Ñ! )¸ÓDÀgö	
øôK ô 	ð ð		ús   ˆE+ Å+E8Nc                ó6   <€ V ^8„  d   QhRS[ S[,          RS[/# ©r   Úeventr   )r   r   )r   r   s   "€r   r   r   ¶   s"   ø€ ÷ ñ Ù™hÕ'ðá	ñr   c                ó®   a€ Vf*   \        4       o ! V3R lR4      p\        RV! 4       R7      p\        V4       V P                  \	        V4      R4       V# )z¯
The same format field used twice in one event is rendered twice.

@param event: An event to flatten.  If L{None}, create a new event.
@return: C{event} or the event created.
c                   ó>   <a € ] tR t^Ât o RtV 3R lV3R lltRtV tR# )ÚJFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStrz
Hack
c                ó    <€ V ^8„  d   QhRS[ /# rS   rT   )r   r   s   "€r   r   ÚWFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStr.__annotate__Ç   s   ø€ ÷ .ñ .¡Sñ .r   c                ó,   <€ \        \        S4      4      # r(   )rU   r)   )r:   r*   s   &€r   Ú__str__ÚRFlatFormattingTests._test_formatFlatEvent_fieldNamesSame.<locals>.CountStr.__str__Ç   s   ø€ Üœt G›}Ó-Ð-r   r   N)r    r!   r"   r#   rY   r{   r%   rZ   )r   r*   s   @€r   ÚCountStrrw   Â   s   ù‡ € ñ÷.÷ .ñ .r   r}   z{x} {x}©r/   Úxz0 1)r   r5   r   r9   r   )r:   rt   r}   r*   s   && @r   Ú$_test_formatFlatEvent_fieldNamesSameÚ8FlatFormattingTests._test_formatFlatEvent_fieldNamesSame¶   sS   ø€ ð Š=Ü“gˆG÷.ô .ô Ø$Ù“*ôˆEô
 	�UÔØ×Ñœ UÓ+¨UÔ3àˆr   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   Ô   s   ø€ ÷ 4ñ 4°Dñ 4r   c                ó&   € V P                  4        R# )zB
The same format field used twice in one event is rendered twice.
N©r€   rO   s   &r   Ú"test_formatFlatEventFieldNamesSameÚ6FlatFormattingTests.test_formatFlatEventFieldNamesSameÔ   s   € ð 	×1Ñ1Ö3r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   Ú   s   ø€ ÷ 9ñ 9¸ñ 9r   c                óH   € V P                  4       pV P                  V4       R# )zJ
The same event flattened twice gives the same (already rendered)
result.
Nr„   )r:   rt   s   & r   Ú'test_formatFlatEventFieldNamesSameAgainÚ;FlatFormattingTests.test_formatFlatEventFieldNamesSameAgainÚ   s    € ð
 ×9Ñ9Ó;ˆØ×1Ñ1°%Ö8r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   â   s   ø€ ÷ 8ñ 8°$ñ 8r   c                óp   € \        RRR7      p\        V4       \        V4      pV P                  VR4       R# )z[
L{formatEvent} will handle a flattened event with tailing text after
a replacement field.
ztest {x} trailingr   r~   ztest value trailingN)r5   r   r   r9   )r:   rt   Úresults   &  r   Ú test_formatEventFlatTrailingTextÚ4FlatFormattingTests.test_formatEventFlatTrailingTextâ   s9   € ô
 Ø*Øô
ˆô 	�UÔä˜UÓ#ˆà×Ñ˜Ð!6Ö7r   c                ó   € V # r(   r   )r   s   &r   r+   ÚFlatFormattingTests.<lambda>ò   s   € Áqr   c                ó<   <€ V ^8„  d   QhRS[ S[.S[3,          RR/# )r   ÚflattenFirstr   N)r   r   )r   r   s   "€r   r   r   ñ   s-   ø€ ÷ !@ñ !@Ù$¡h Z±Ð%9Õ:ð!@à	ñ!@r   c                ó  aa€  ! R R4      o ! V3R lR4      p\        RV! 4       R7      pV! V4      oR V3R llpV P                  V! R	4      ^4       V P                  V! R
4      R4       V P                  V! R4      R4       R# )zt
L{extractField} will extract a field used in the format string.

@param flattenFirst: callable to flatten an event
c                   ó2   a € ] tR t^út o V 3R lR ltRtV tR# )Ú=FlatFormattingTests.test_extractField.<locals>.ObjectWithReprc                ó    <€ V ^8„  d   QhRS[ /# rS   rT   )r   r   s   "€r   r   ÚJFlatFormattingTests.test_extractField.<locals>.ObjectWithRepr.__annotate__û   s   ø€ ÷ ñ ¡#ñ r   c                ó   € R # )Úreprr   rO   s   &r   rW   ÚFFlatFormattingTests.test_extractField.<locals>.ObjectWithRepr.__repr__û   s   € Ùr   r   N)r    r!   r"   r#   rW   r%   rZ   r[   s   @r   ÚObjectWithReprr–   ú   s   ø‡ € ÷ö r   rœ   c                   óL   <a € ] tR t^þt o V 3R lV3R lltV 3R lR ltRtV tR# )Ú8FlatFormattingTests.test_extractField.<locals>.Somethingc                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   ÚEFlatFormattingTests.test_extractField.<locals>.Something.__annotate__ÿ   s   ø€ ÷ /ñ / $ñ /r   c                ó.   <€ ^V n         S! 4       V n        R# )é   N©r2   r1   )r:   rœ   s   &€r   Ú__init__ÚAFlatFormattingTests.test_extractField.<locals>.Something.__init__ÿ   s   ø€ Ø�”Ù,Ó.�–r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r      s   ø€ ÷ ;ñ ; dñ ;r   c                ó   € \        R 4      h)zJust in case.)ÚNotImplementedErrorrO   s   &r   Ú__getstate__ÚEFlatFormattingTests.test_extractField.<locals>.Something.__getstate__  s   € Ü)¨/Ó:Ð:r   r£   N)r    r!   r"   r#   r¤   r©   r%   rZ   )r   rœ   s   @€r   Ú	Somethingrž   þ   s   ù‡ € ÷/ó /÷;ö ;r   r«   z%{something.number} {something.object})r/   Ú	somethingc                ó0   € V ^8„  d   QhR\         R\        /# )r   Úfieldr   )rU   r   )r   s   "r   r   Ú;FlatFormattingTests.test_extractField.<locals>.__annotate__  s   € ÷ 	2ñ 	2œ3ð 	2¤3ñ 	2r   c                 ó   <€ \        V S4      # r(   )r
   )r®   Ú	flatteneds   &€r   ÚextractÚ6FlatFormattingTests.test_extractField.<locals>.extract  s   ø€ Ü  yÓ1Ð1r   zsomething.numberzsomething.number!sÚ7zsomething.object!srš   N)r5   r9   )r:   r“   r«   rt   r²   rœ   r±   s   &&   @@r   Útest_extractFieldÚ%FlatFormattingTests.test_extractFieldñ   s…   ù€ ÷	ñ 	÷	;ô 	;ô Ø>Ù“kô
ˆñ
 ! Ó'ˆ	÷	2ð 	2ð 	×Ñ™Ð!3Ó4°aÔ8Ø×Ñ™Ð!5Ó6¸Ô<Ø×Ñ™Ð!5Ó6¸Ö?r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r     s   ø€ ÷ 
*ñ 
*¨tñ 
*r   c                ó4   € R R lpV P                  V4       R# )zQ
L{extractField} behaves identically if the event is explicitly
flattened first.
c                ó0   € V ^8„  d   QhR\         R\         /# rs   r   )r   s   "r   r   ÚGFlatFormattingTests.test_extractFieldFlattenFirst.<locals>.__annotate__  s   € ÷ 	ñ 	œXð 	¬(ñ 	r   c                 ó   € \        V 4       V # r(   )r   )rt   s   &r   r±   ÚDFlatFormattingTests.test_extractFieldFlattenFirst.<locals>.flattened  s   € Ü˜ÔØˆLr   N)rµ   )r:   r±   s   & r   Útest_extractFieldFlattenFirstÚ1FlatFormattingTests.test_extractFieldFlattenFirst  s   € õ	ð 	×Ñ˜yÖ)r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r      s   ø€ ÷ 9ñ 9°ñ 9r   c                óT   € RRR^/p\        V4       V P                  VRRR^/4       R# )zD
L{flattenEvent} will do nothing to an event with no format string.
ÚaÚbÚcN©r   r9   ©r:   Ú
inputEvents   & r   Útest_flattenEventWithoutFormatÚ2FlatFormattingTests.test_flattenEventWithoutFormat   s3   € ð ˜3  QÐ'ˆ
Ü�ZÔ Ø×Ñ˜ c¨3°°QÐ%7Ö8r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   (  s   ø€ ÷ 
ñ 
°$ñ 
r   c           	     ó\   € RRR^RR/p\        V4       V P                  VRRR^RR/4       R# )zb
L{flattenEvent} will do nothing to an event with a format string that
contains no format fields.
rÁ   rÂ   rÃ   r/   zsimple messageNrÄ   rÅ   s   & r   Ú test_flattenEventWithInertFormatÚ4FlatFormattingTests.test_flattenEventWithInertFormat(  sE   € ð
 ˜3  Q¨Ð6FÐGˆ
Ü�ZÔ Ø×ÑØà�SØ�QØÐ.ðö	
r   c                ó   <€ V ^8„  d   QhRR/# r   r   )r   r   s   "€r   r   r   8  s   ø€ ÷ 
ñ 
°ñ 
r   c           	     ó\   € RRR^RR/p\        V4       V P                  VRRR^RR/4       R# )zJ
L{flattenEvent} will do nothing to an event with log_format set to
None.
rÁ   rÂ   rÃ   r/   NrÄ   rÅ   s   & r   Útest_flattenEventWithNoneFormatÚ3FlatFormattingTests.test_flattenEventWithNoneFormat8  sC   € ð
 ˜3  Q¨°dÐ;ˆ
Ü�ZÔ Ø×ÑØà�SØ�QØ˜dðö	
r   r   r(   )r    r!   r"   r#   rY   r>   rD   r_   rp   r€   r…   r‰   rŽ   rµ   r½   rÇ   rË   rÏ   r%   rZ   r[   s   @r   r   r      sœ   ø‡ € ñ÷,
ð ,
÷\Rð R÷Oð O÷B;
ð ;
÷zò ÷<4ð 4÷9ð 9÷8ð 8ñ  >I÷!@ò !@÷F
*ð 
*÷9ð 9÷
ð 
÷ 
ö 
r   r   )rY   r6   Ú	itertoolsr   Útypingr   r   r   Útimer   ÚImportErrorÚtwisted.trialr   Ú_flattenr   r	   r
   r   Ú_formatr   Ú_interfacesr   ÚTestCaser   r   r   r   Ú<module>rÚ      s[   ðñó Ý ß *Ñ *ðÝõ #ß KÓ KÝ !Ý "ôo
˜(×+Ñ+ö o
øð ô Ø‚Eðús   ˜A Á	AÁA