+
    Df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&   zcallable: {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DJJv./
	
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_formatFlatEventBadFormat1FlatFormattingTests.test_formatFlatEventBadFormatJ   sR     -

 	VDJJv./F+667O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_formatFlatEventWithMutatedFields9FlatFormattingTests.test_formatFlatEventWithMutatedFieldsX   sK    	, 	,& _!AQS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     !!&) ,,,#~--iZPP * GFF5r   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18<y18< 	z2I>y18<y18< 	|4jA{3Y?{3Y?$ U#	
 $$$!!)De	
 	!!)Dg	
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    tG}--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_fieldNamesSame8FlatFormattingTests._test_formatFlatEvent_fieldNamesSame   sS     =gG. . $*E
 	UU+U3r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     4 4D 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_formatFlatEventFieldNamesSame6FlatFormattingTests.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_formatEventFlatTrailingText4FlatFormattingTests.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-     !@ !@$hZ%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 	23 	23 	2r   c                    < \        V S4      # r(   )r
   )r   	flatteneds   &r   extract6FlatFormattingTests.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4a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_extractFieldFlattenFirst1FlatFormattingTests.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_flattenEventWithoutFormat2FlatFormattingTests.test_flattenEventWithoutFormat   s3     3Q'
Z c3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_flattenEventWithInertFormat4FlatFormattingTests.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_flattenEventWithNoneFormat3FlatFormattingTests.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