+
    Dfj1                         R t ^ RIt^ RIHtHtHtHtHtHtH	t	H
t
 ^ RIHt ^ RIHt ^RIHt ^RIHtHt ^RIHtHt ^RIHt ^R	IHt ^R
IHt ^RIHt R R lt ! R R]P@                  4      t!R# )z+
Test cases for L{twisted.logger._global}.
N)IOAnyListOptionalTextIOTupleTypecast)Failure)unittest)textFileLogObserver)MORE_THAN_ONCE_WARNINGLogBeginner)ILogObserverLogEvent)LogLevel)Logger)LogPublisher)nextLinec                    V ^8  d   QhR\         P                  R\        \        ,          R\        \        ,          RR/# )   testactualEventsexpectedEventsreturnN)r   TestCaser   r   )formats   "A/usr/lib/python3/dist-packages/twisted/logger/test/test_global.py__annotate__r      s>     7 7


7x.7 N7 
	7    c                ,  a \        V4      \        V4      8w  d   V P                  W4       \        4       oV F#  pS\        VP                  4       4      ,          oK%  	  R V3R llpV Uu. uF
  q4! V4      NK  	  ppV P                  WR4       R# u upi )a  
Compare two sequences of log events, examining only the the keys which are
present in both.

@param test: a test case doing the comparison
@param actualEvents: A list of log events that were emitted by a logger.
@param expectedEvents: A list of log events that were expected by a test.
c                0    V ^8  d   QhR\         R\         /# )r   eventr   )r   )r   s   "r   r   #compareEvents.<locals>.__annotate__*   s       X r   c                    < V P                  4       pV P                  4        F  pVS9  g   K  VP                  V4       K  	  V# N)copykeyspop)r"   r&   keyallMergedKeyss   &  r   simplifycompareEvents.<locals>.simplify*   s8    zz|::<C-'   r   N)lenassertEqualsetr'   )r   r   r   r"   r+   simplifiedActualr*   s   &&&   @r   compareEventsr1      s     <C//6EMUZZ\**    6BB\E\B%6 Cs   ,Bc                      a  ] tR t^5t 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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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V 3R lR ltV 3R lR ltRtV tR# ) LogBeginnerTestsz
Tests for L{LogBeginner}.
c                   < V ^8  d   QhRR/# r   r   N )r   __classdict__s   "r   r   LogBeginnerTests.__annotate__:   s     /
 /
t /
r   c                &   \        4       V n        \        P                  ! 4       V n         ! R  R4      p ! R R4      pV! 4       V n        V! 4       V n        \        V P                  V P                  V P
                  V P                  4      V n        R# )c                   2    ] tR t^>t]! 4       t]! 4       tRtR# )&LogBeginnerTests.setUp.<locals>.NotSysr6   N)__name__
__module____qualname____firstlineno__objectstdoutstderr__static_attributes__r6   r   r   NotSysr;   >   s    XFXFr   rD   c                   H   a  ] tR t^Bt o V 3R lR ltRV 3R lR lltRtV tR# )+LogBeginnerTests.setUp.<locals>.NotWarningsc                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   8LogBeginnerTests.setUp.<locals>.NotWarnings.__annotate__C   s      $ r   c                    . V n         R # r%   warnings)selfs   &r   __init__4LogBeginnerTests.setUp.<locals>.NotWarnings.__init__C   s    
 	 r   Nc                   < V ^8  d   QhRS[ RS[S[,          RS[ RS[RS[S[S[,          ,          RS[S[,          RR/# )	r   messagecategoryfilenamelinenofileliner   N)strr   Warningintr   r   r   )r   r7   s   "r   r   rH   J   sk     X XX w-X 	X
 X r#w'X smX Xr   c                B    V P                   P                  WW4WV34       R# )a%  
Emulate warnings.showwarning.

@param message: A warning message to emit.
@param category: A warning category to associate with
    C{message}.
@param filename: A file name for the source code file issuing
    the warning.
@param lineno: A line number in the source file where the
    warning was issued.
@param file: A file to write the warning message to.  If
    L{None}, write to L{sys.stderr}.
@param line: A line of source code to include with the warning
    message. If L{None}, attempt to read the line from
    C{filename} and C{lineno}.
N)rK   append)rL   rP   rQ   rR   rS   rT   rU   s   &&&&&&&r   showwarning7LogBeginnerTests.setUp.<locals>.NotWarnings.showwarningJ   s    2 $$g4%VWr   rJ   )NN)r<   r=   r>   r?   rM   r[   rC   __classdictcell__r7   s   @r   NotWarningsrF   B   s!      X X Xr   r_   N)	r   	publisherioStringIOerrorStream	sysModulewarningsModuler   beginner)rL   rD   r_   s   &  r   setUpLogBeginnerTests.setUp:   sn    %;;=	 	!	X !	XF  )m#NND,,dnnd>Q>Q
r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8   k   s     + + +r   c                "  aa \        ^^R7      p. o. o\        \        V3R l4      p\        \        V3R l4      pV P                  P	                  W#34       V P                  V4       V P                  V.S4       V P                  V.S4       R# )z/
Test that C{beginLoggingTo()} adds observers.
foobarc                 &   < SP                  V 4      # r%   rZ   eevents1s   &r   <lambda>BLogBeginnerTests.test_beginLoggingToAddObservers.<locals>.<lambda>t       '..*;r   c                 &   < SP                  V 4      # r%   ro   rq   events2s   &r   rs   rt   u   ru   r   N)dictr	   r   rf   beginLoggingTor`   r.   rL   r"   o1o2rr   rx   s   &   @@r   test_beginLoggingToAddObservers0LogBeginnerTests.test_beginLoggingToAddObserversk   sy     ""$"$, ;<, ;<$$bX.u%'*%'*r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8   }   s     + +4 +r   c                "  aa \        ^^R7      p. o. o\        \        V3R l4      p\        \        V3R l4      pV P                  V4       V P                  P                  W#34       V P                  V.S4       V P                  V.S4       R# )zD
Test that events are buffered until C{beginLoggingTo()} is
called.
rk   c                 &   < SP                  V 4      # r%   ro   rp   s   &r   rs   DLogBeginnerTests.test_beginLoggingToBufferedEvents.<locals>.<lambda>   ru   r   c                 &   < SP                  V 4      # r%   ro   rw   s   &r   rs   r      ru   r   N)ry   r	   r   r`   rf   rz   r.   r{   s   &   @@r   !test_beginLoggingToBufferedEvents2LogBeginnerTests.test_beginLoggingToBufferedEvents}   sy    
 ""$"$, ;<, ;<u$$bX.%'*%'*r   c                *   < V ^8  d   QhRS[ RS[RR/# )r   limitrf   r   N)rX   r   )r   r7   s   "r   r   r8      s"     
 
c 
[ 
T 
r   c           	     >   \        V^,           4       F  pV P                  \        VR7      4       K   	  . pVP                  \	        \
        VP                  4      .4       V P                  \        \        ^V^,           4      4      \        R V 4       4      4       R# )at  
Verify that when more than C{limit} events are logged to L{LogBeginner},
only the last C{limit} are replayed by L{LogBeginner.beginLoggingTo}.

@param limit: The maximum number of events the log beginner should
    buffer.
@param beginner: The L{LogBeginner} against which to verify.

@raise: C{self.failureException} if the wrong events are replayed by
    C{beginner}.
)countc              3   2   "   T F  qR ,          x  K  	  R# 5i)r   Nr6   ).0r"   s   & r   	<genexpr>4LogBeginnerTests._bufferLimitTest.<locals>.<genexpr>   s     4VEwVs   N)	ranger`   ry   rz   r	   r   rZ   r.   list)rL   r   rf   r   eventss   &&&  r   _bufferLimitTest!LogBeginnerTests._bufferLimitTest   sx     519%ENN4e,- &!#lFMM!B CDq%!)$%4V44	
r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8      s     4 4 4r   c                \    \         P                  pV P                  WP                  4       R# )zp
Up to C{LogBeginner._DEFAULT_BUFFER_SIZE} log events are buffered for
replay by L{LogBeginner.beginLoggingTo}.
N)r   _DEFAULT_BUFFER_SIZEr   rf   )rL   r   s   & r   test_defaultBufferLimit(LogBeginnerTests.test_defaultBufferLimit   s!    
 00e]]3r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8      s     / /$ /r   c                    ^p\        V P                  V P                  V P                  V P                  VR7      pV P                  W4       R# )zr
The size of the L{LogBeginner} event buffer can be overridden with the
C{initialBufferSize} initilizer argument.
)initialBufferSizeN)r   r`   rc   rd   re   r   )rL   r   rf   s   &  r   test_overrideBufferLimit)LogBeginnerTests.test_overrideBufferLimit   sF    
 NNNN#
 	e.r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8      s     )B )B$ )Br   c                Z   . p. p\         P                  ! 4       p\        V4      pV P                  \	        RR7      4       \        4       w  rVV P                  P                  \        \        VP                  4      V.4       V P                  \	        RR7      4       \        4       w  rxV P                  P                  \        \        VP                  4      V.4       V P                  \	        RR7      4       \	        \        \        P                  VVVVR7      p	RV n        \        V V\	        RR7      \	        RR7      V	\	        RR7      .4       \        WV	\	        RR7      .4       VP!                  4       p
V P#                  RV RV R	2V
4       V P#                  RV RV R	2V
4       R# )
z
When invoked twice, L{LogBeginner.beginLoggingTo} will emit a log
message warning the user that they previously began logging, and add
the new log observers.
	prebuffer)r"   
postbufferpostwarn)
log_format	log_levelfileNowlineNowfileThenlineThenN<:>)ra   rb   r   r`   ry   r   rf   rz   r	   r   rZ   r   r   warnmaxDiffr1   getvalueassertIn)rL   rr   rx   
fileHandletextObserverfirstFilename	firstLinesecondFilename
secondLinewarningoutputs   &          r   test_beginLoggingToTwice)LogBeginnerTests.test_beginLoggingToTwice   sd    #%"$[[]
*:6t+./#+: $$d<&H,%WXt,/0%-Z"$$d<&H,%WXt*-.-mm""
 ;'<(:&			
 	dgt*/E%FG$$&-)A6?.):,a8&Ar   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8      s     N Nd Nr   c                    \        V P                  R7      pVP                  R4       VP                  RRR7       V P	                  V P
                  P                  4       R4       R# )z@
Critical messages will be written as text to the error stream.
observerzignore thisza critical {message}rP   )rP   za critical message
N)r   r`   infocriticalr.   rc   r   rL   logs   & r   test_criticalLogging%LogBeginnerTests.test_criticalLogging   sO     dnn-+Y?))2246LMr   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8      s     : :4 :r   c                    \        V P                  R7      pV P                  P                  R4       VP	                  R4       V P                  V P                  P                  4       R4       R# )zn
Once logging has begun with C{beginLoggingTo}, critical messages are no
longer written to the output stream.
r   zanother critical message Nr6   )r   r`   rf   rz   r   r.   rc   r   r   s   & r   test_criticalLoggingStops*LogBeginnerTests.test_criticalLoggingStops   sP    
 dnn-$$R(/0))224b9r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8      s     
 
t 
r   c           	        . pV P                   P                  \        \        VP                  4      .4       \        R\        \        V P                  P                  4      R7       \        W\        RRR7      .4       VR \        R\        \        V P                  P                  4      R7       \        W\        RRR7      .4       R# )	z
L{LogBeginner.beginLoggingTo} will re-direct the standard output and
error streams by setting the C{stdio} and C{stderr} attributes on its
sys module object.
zHello, world.rT   rA   )log_namespacelog_io:NNNzError, world.rB   N)rf   rz   r	   r   rZ   printr   rd   rA   r1   ry   rB   )rL   r   s   & r   %test_beginLoggingToRedirectStandardIO6LogBeginnerTests.test_beginLoggingToRedirectStandardIO   s     "$$$d<&G%HIoD1F1F$GH4hOP	
 1IoD1F1F$GH4hOP	
r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8     s     	5 	5 	5r   c                0   V P                   P                  pV P                   P                  pV P                  P	                  RRR7       V P                  V P                   P                  V4       V P                  V P                   P                  V4       R# )zw
L{LogBeginner.beginLoggingTo} will leave the existing stdout/stderr in
place if it has been told not to replace them.
F)redirectStandardIONr6   )rd   rA   rB   rf   rz   assertIs)rL   oldOutoldErrs   &  r   test_beginLoggingToDontRedirect0LogBeginnerTests.test_beginLoggingToDontRedirect  si    
 &&&&$$RE$Bdnn++V4dnn++V4r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8     s     T Td Tr   c           	        \         P                  ! \         P                  ! 4       R4      p\         P                  ! \         P                  ! 4       R4      pWP                  n        W P                  n        . pV P                  P                  \        \        VP                  4      .4       \        \        V P                  P                  4      p\        \        V P                  P
                  4      pV P                  VP                  R4       V P                  VP                  R4       VP                  R4       VP                  R4       \        W\!        RR7      \!        RR7      .4       R# )	z
When L{LogBeginner.beginLoggingTo} redirects stdout/stderr streams, the
replacement streams will preserve the encoding of the replaced streams,
to minimally disrupt any application relying on a specific encoding.
z	shift-JISbig5s   
s   
u   李)r   u   瑩N)ra   TextIOWrapperBytesIOrd   rA   rB   rf   rz   r	   r   rZ   r   r.   encodingwriter1   ry   )rL   weirdweirderrr   rA   rB   s   &     r   $test_beginLoggingToPreservesEncoding5LogBeginnerTests.test_beginLoggingToPreservesEncoding  s       {;##BJJL&9 % (!#$$d<&G%HIfdnn334fdnn334+6&1]#]#dT%:D<Q$RSr   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8   /  s     %
 %
T %
r   c                   V P                   P                  R\        \        ^4       . pV P                  P                  \        \        VP                  4      .4       V P                   P                  R\        \        ^4       \        P                  ! 4       pV P                   P                  R\        \        ^VR7       V P                  V P                   P                  R\        \        ^RR3R\        \        ^VR3.4       \        V V\        R\        P                  R,           \        P                   ,           \        ^R7      .4       R# )zj
L{LogBeginner.beginLoggingTo} will redirect the warnings of its
warnings module into the logging system.
z	a messagezanother messagezyet anotherr   N.)r   rQ   rR   rS   )re   r[   DeprecationWarning__file__rf   rz   r	   r   rZ   ra   rb   r.   rK   r1   ry   r=   r<   )rL   r   fs   &  r   test_warningsModule$LogBeginnerTests.test_warningsModule/  s"   
 	''5GSTU!#$$d<&G%HI''18Q	
 KKM''-x 	( 	
 	((0(AtTJ 2HaDI	
 	-*55,556 &		
r   c                   < V ^8  d   QhRR/# r5   r6   )r   r7   s   "r   r   r8   V  s     
( 
(t 
(r   c                    \        \        R4      4      p\        V P                  R7      pVP	                  RVR7       V P
                  P                  4       pV P                  RV4       V P                  RV4       V P                  RV4       R# )zB
The string resulting from a logged failure contains a traceback.
z,this is not the behavior you are looking forr   z	a failure)failure	TracebackN)r
   	Exceptionr   r`   r   rc   r   r   )rL   r   r   msgs   &   r   test_failuresAppendTracebacks.LogBeginnerTests.test_failuresAppendTracebacksV  sq     ILMNdnn-K+'')k3'DcJk3'r   )rf   rc   r   r`   rd   re   N)r<   r=   r>   r?   __doc__rg   r~   r   r   r   r   r   r   r   r   r   r   r   r   rC   r]   r^   s   @r   r3   r3   5   s     /
 /
b+ +$+ +&
 
*4 4/ /)B )BVN N: :
 
$	5 	5T T0%
 %
N
( 
(r   r3   )"r   ra   typingr   r   r   r   r   r   r   r	   twisted.python.failurer
   twisted.trialr   _filer   _globalr   r   _interfacesr   r   _levelsr   _loggerr   	_observerr   test.test_stdlibr   r1   r   r3   r6   r   r   <module>r      sL    
 E E E * " ' 9 0   $ '7>k(x(( k(r   