+
    Dfj)                         R t ^ RIHtHtHtHt ^ RIHt ^ RIH	t	 ^ RI
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 R]4      t ! R R4      t ! R R]P8                  4      tR# )z+
Test cases for L{twisted.logger._logger}.
)ListOptionalTypecast)implementer)NamedConstant)Failure)unittest)formatEvent)globalLogPublisher)ILogObserverLogEvent)InvalidLogLevelErrorLogLevelLoggerc                   :   a  ] tR t^t o RtRV 3R lR lltRtV tR# )
TestLoggerzR
L{Logger} with an overridden C{emit} method that keeps track of received
events.
Nc                @   < V ^8  d   QhRS[ RS[S[,          RS[RR/# )   levelformatkwargsreturnN)r   r   strobject)r   __classdict__s   "A/usr/lib/python3/dist-packages/twisted/logger/test/test_logger.py__annotate__TestLogger.__annotate__   s1     
 
"
,4SM
LR
	
    c                  a  \        \        4      R  V 3R ll4       p\        P                  ! V4        \        P
                  ! S W3/ VB  \        P                  ! V4       RVRVRV/S n        R#   \        P                  ! T4       i ; i)c                (    V ^8  d   QhR\         RR/# r   eventr   Nr   )r   s   "r   r   %TestLogger.emit.<locals>.__annotate__!   s     	 	H 	 	r    c                    < V Sn         R # N)r$   r$   selfs   &r   observer!TestLogger.emit.<locals>.observer    s
    DJr    r   r   r   N)r   r   r   addObserverr   emitremoveObserveremitted)r*   r   r   r   r+   s   f&&, r   r.   TestLogger.emit   s~     
\	"	 
#	 	&&x0	8KKe6v6--h7 Uff
 --h7s   A1 1B	)r0   r$   r(   )__name__
__module____qualname____firstlineno____doc__r.   __static_attributes____classdictcell__r   s   @r   r   r      s     

 
 
r    r   c                   Z   a  ] tR t^1t o Rt]! 4       tRV 3R lR lltV 3R lR ltRt	V t
R# )	LogComposedObjectz+
A regular object, with a logger attached.
Nc                4   < V ^8  d   QhRS[ S[,          RR/# )r   stater   N)r   r   )r   r   s   "r   r   LogComposedObject.__annotate__8   s      hsm t r    c                    Wn         R # r(   r=   )r*   r=   s   &&r   __init__LogComposedObject.__init__8   s    
r    c                    < V ^8  d   QhRS[ /# r   r   r   )r   r   s   "r   r   r>   ;   s     3 3 3r    c                "    R V P                    R2# )z<LogComposedObject >r@   )r*   s   &r   __str__LogComposedObject.__str__;   s    $TZZL22r    r@   r(   )r2   r3   r4   r5   r6   r   logrA   rH   r7   r8   r9   s   @r   r;   r;   1   s'      ,C 3 3r    r;   c                   D  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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## )$LoggerTestsz
Tests for L{Logger}.
c                   < V ^8  d   QhRR/# r   r   N )r   r   s   "r   r   LoggerTests.__annotate__D   s     C C4 Cr    c                p    Rp\        V4      pV P                  \        V4      R\        V4       R24       R# )z
repr() on Logger
blearghz<Logger rG   N)r   assertEqualrepr)r*   	namespacerJ   s   &  r   	test_reprLoggerTests.test_reprD   s5     	YchtI.?q$ABr    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP   L   s     2 2t 2r    c                Z    \        4       pV P                  VP                  \        4       R# )z#
Default namespace is module name.
N)r   rS   rU   r2   r*   rJ   s   & r   test_namespaceDefault!LoggerTests.test_namespaceDefaultL   s     h1r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP   S   s     ; ;T ;r    c                    . p\        R\        \        R7      \        4       4       V P	                  V^ ,          P
                  R4       R# )z
Default namespace is C{"<unknown>"} when a logger is created from a
context in which is can't be determined automatically and no namespace
was specified.
zresult.append(Logger())r   z	<unknown>N)execdictr   localsrS   rU   )r*   results   & r   test_namespaceOMGItsTooHard'LoggerTests.test_namespaceOMGItsTooHardS   s=      "%H	

 	,,k:r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP   a   s     + + +r    c                   \        4       pRP                  VP                  VP                  P                  4      pV P                  \        \        VP                  4      P                  V4       V P                  \        \        \        ,          \         P                  4      P                  V4       V P                  \        \        \        ,          \         P                  4      P                  \         4       V P                  \        \        VP                  4      P                  V4       V P                  \        4       P                  4       R# )zk
Default namespace for classes using L{Logger} as a descriptor is the
class name they were retrieved from.
z{}.{}N)r;   r   r3   	__class__r2   rS   r   r   rJ   rU   r   assertIssourceassertIsNoner   )r*   objexpectedNamespaces   &  r   test_namespaceAttribute#LoggerTests.test_namespaceAttributea   s    
  !#NNNNMM""

 	j#''2<<>OPj!#4#8#89CCEV	
 	j!#4#8#89@@BS	
 	d:sww/66<&(//*r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP   w   s     = = =r    c                   a . o ! V3R lR4      pVP                   P                  R4       V P                  \        S4      ^4       V P                  S^ ,          R,          R4       R# )z8
When used as a descriptor, the observer is propagated.
c                   N   < ] tR t^}t]! ]! ] Z P                  4      R7      tRt	R# )5LoggerTests.test_descriptorObserver.<locals>.MyObjectr+   rO   N)
r2   r3   r4   r5   r   r   r   appendrJ   r7   )observeds   r   MyObjectrr   }   s    $|X__"EFCr    rv   hello
log_formatN)rJ   inforS   len)r*   rv   ru   s   & @r   test_descriptorObserver#LoggerTests.test_descriptorObserverw   sW     $&	G 	G 	'"X*!\2G<r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     B B4 Br    c                >   \        R4      p\        \        VP                  4      pVP	                  R4       V P                  RVP                  4       V P                  VP                  R,          V4       \        VP                  4      pV P                  RV4       R# )zk
On instances that have a L{Logger} class attribute, the C{log_source}
key is available to format strings.
rw   zHello, {log_source}.
log_sourcez!Hello, <LogComposedObject hello>.N)	r;   r   r   rJ   errorassertInr$   rS   r
   )r*   rk   rJ   stuffs   &   r   !test_sourceAvailableForFormatting-LoggerTests.test_sourceAvailableForFormatting   ss    
  (:sww'		()lCII.<0#6CII&95Ar    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     > >$ >r    c                   \        4       p\        P                  ! 4        EF  pRpVP                  VP                  R7      p\        WP                  4      pV! W4VP                  R7       V P                  VP                  R,          V4       V P                  VP                  R,          V4       V P                  VP                  R,          R,          V4       V P                  \        VR4      R	4       V P                  VP                  R
,          V4       V P                  VP                  R,          V4       V P                  VP                  R,          \        4       V P                  VP                  R,          4       V P                  VP                  R,          V4       V P                  \        VP                  4      V4       EK  	  R# )zE
Test that log levels and messages are emitted correctly for
Logger.
zThis is a {level_name} message)
level_name)junkr   r   r   r   r   r$   zNo event observed.rx   	log_levellog_namespacer   N)r   r   iterconstantsr   namegetattrrS   r0   
assertTruehasattrr$   r2   rj   r
   )r*   rJ   r   r   message	logMethods   &     r   test_basicLoggerLoggerTests.test_basicLogger   sO   
 l++-E5Fmmuzzm:GZZ0IfuzzB S[[159S[[2F;S[[26:GDOOGC13GHSYY|4f=SYY{3U;SYY7Bcii56SYYv.8[3W=) .r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     , ,D ,r    c                   a aa \        \        4      R VV 3R ll4       o ! V3R lR4      o\        \        SP                  4      P                  4        R# )z.
C{log_source} event key refers to the class.
c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   4LoggerTests.test_sourceOnClass.<locals>.__annotate__        	: 	:H 	: 	:r    c                 :   < SP                  V R ,          S4       R# r   NrS   )r$   Thingor*   s   &r   r+   0LoggerTests.test_sourceOnClass.<locals>.observer       U<0&9r    c                   ,   < ] tR t^t]!  Z R7      tRtR# ).LoggerTests.test_sourceOnClass.<locals>.Thingors   rO   Nr2   r3   r4   r5   r   rJ   r7   rs   s   r   r   r          h/Cr    r   Nr   r   r   r   rJ   ry   )r*   r   r+   s   f@@r   test_sourceOnClassLoggerTests.test_sourceOnClass   sD    
 
\	"	: 	: 
#	:	0 	0 	Z$))+r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     , ,t ,r    c                   a aa \        \        4      R V V3R ll4       o ! V3R lR4      pV! 4       o\        \        SP                  4      P                  4        R# )z1
C{log_source} event key refers to the instance.
c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   7LoggerTests.test_sourceOnInstance.<locals>.__annotate__   r   r    c                 :   < SP                  V R ,          S4       R# r   r   )r$   r*   thingos   &r   r+   3LoggerTests.test_sourceOnInstance.<locals>.observer   r   r    c                   ,   < ] tR t^t]!  Z R7      tRtR# )1LoggerTests.test_sourceOnInstance.<locals>.Thingors   rO   Nr   rs   s   r   r   r      r   r    r   Nr   )r*   r   r+   r   s   f @@r   test_sourceOnInstance!LoggerTests.test_sourceOnInstance   sK    
 
\	"	: 	: 
#	:	0 	0 Z$))+r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     
 
D 
r    c                v   a  \        \        4      R V 3R ll4       p\        VR7      pVP                  4        R# )z%
C{log_source} event key is L{None}.
c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   4LoggerTests.test_sourceUnbound.<locals>.__annotate__   s     	3 	3H 	3 	3r    c                 8   < SP                  V R ,          4       R# r   )rj   r)   s   &r   r+   0LoggerTests.test_sourceUnbound.<locals>.observer   s    eL12r    rs   Nr   r   r   ry   )r*   r+   rJ   s   f  r   test_sourceUnboundLoggerTests.test_sourceUnbound   s1    
 
\	"	3 
#	3 (+
r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     : :T :r    c                ~   \        4       p \        R4      h  \         d    TP                  R4        Mi ; iT P                  \        4      pT P	                  \        T4      ^4       T P	                  TP                  R,          \        P                  4       T P	                  TP                  R,          R4       R# )z/
Test that log.failure() emits the right data.
zbaloney!Whoopsr   r   N)	r   RuntimeErrorfailureflushLoggedErrorsrS   rz   r0   r   criticalr*   rJ   errorss   &  r   test_defaultFailureLoggerTests.test_defaultFailure   s     l	"z** 	"KK!	" ''5Va(W-x/@/@AX.9s    66c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     3 3 3r    c                   \        4       pVP                  RR\        P                  RRR7       V P	                  VP
                  R,          R4       V P	                  VP
                  R,          \        P                  4       V P	                  VP
                  R,          VP                  4       V P                  VP
                  R	,          4       R
# )zA
Make sure that kwargs conflicting with args don't pass through.
*#z*namespace*z*source*)rx   r   r   r   rx   r   r   r   N)r   warnr   r   rS   r$   rU   rj   rZ   s   & r   test_conflictingKwargs"LoggerTests.test_conflictingKwargs   s     lnn'! 	 	
 	<0#6;/??3S]]C#))L12r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP      s     	) 	) 	)r    c                    \        4       pVP                  R4       V P                  \        4      pV P	                  \        V4      ^4       R# )z1
Test passing in a bogus log level to C{emit()}.
z*bogus*N)r   r.   r   r   rS   rz   r   s   &  r   test_logInvalidLogLevel#LoggerTests.test_logInvalidLogLevel   s<     l''(<=Va(r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP     s     ) )D )r    c                   a aaa \        \        4      R V3R ll4       o\        \        4      R VVV 3R ll4       o\        SR7      oSP                  R. R7       R# )	z5
Tracing keeps track of forwarding to the publisher.
c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   ,LoggerTests.test_trace.<locals>.__annotate__  s     	 	X 	$ 	r    c                    < S! V 4       R # r(   rO   )r$   r+   s   &r   	publisher)LoggerTests.test_trace.<locals>.publisher  s
    UOr    c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   r     s     	E 	EH 	E 	Er    c                 @   < SP                  V R ,          SS3.4       R# )	log_traceNr   )r$   rJ   r   r*   s   &r   r+   (LoggerTests.test_trace.<locals>.observer  s     U;/3	2B1CDr    rs   zHello.)r   Nr   )r*   rJ   r+   r   s   f@@@r   
test_traceLoggerTests.test_trace  sY    
 
\	"	 
#	 
\	"	E 	E 
#	E ),R(r    c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP     s     ), ),d ),r    c                
  aa . o\        \        4      R V3R ll4       p\        VR7      p^ o ! V3R lR4      pVP                  RV! 4       R7      ;_uu_ 4       p^^ ,           RRR4       V P	                  XP
                  R	4       V P	                  VP                  R
4       V P	                  \        S4      ^4       Sw  p. SR&   VR,          pV P	                  S^ 4       V P	                  \        V4      R4       V P	                  S^4       V P	                  VP                  \        4       VP                  RV! 4       R7      ;_uu_ 4       pV P	                  VP
                  R	4       V P	                  VP                  R	4       RRR4       V P	                  S^4       V P	                  XP
                  R
4       V P	                  VP                  R	4       R#   + '       g   i     EL; i  + '       g   i     Lp; i)zv
The L{Logger.failuresHandled} context manager catches any
L{BaseException} and converts it into a logged L{Failure}.
c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   6LoggerTests.test_failuresHandled.<locals>.__annotate__       	! 	!( 	!t 	!r    c                 *   < SP                  V 4       R # r(   rt   r$   eventss   &r   logged0LoggerTests.test_failuresHandled.<locals>.logged      MM% r    rs   c                   :   <a  ] tR tRt o V 3R lV3R lltRtV tR# )2LoggerTests.test_failuresHandled.<locals>.Reprablei%  c                    < V ^8  d   QhRS[ /# rD   rE   )r   r   s   "r   r   ?LoggerTests.test_failuresHandled.<locals>.Reprable.__annotate__&  s     ) )# )r    c                "   < S^,          oRS R2# )   z<repr rG   rO   )r*   reprds   &r   __repr__;LoggerTests.test_failuresHandled.<locals>.Reprable.__repr__&  s    
wa((r    rO   N)r2   r3   r4   r5   r   r7   r8   )r   r   s   @r   Reprabler   %  s     ) ) )r    r   z*while testing failure handling for {value})valueNFT:NNNlog_failurez+while testing failure handling for <repr 1>zsucceeding for {value})r   r   r   failuresHandledrS   	succeededfailedrz   r
   typeZeroDivisionError)	r*   r   rJ   r   	operationfop2r   r   s	   &      @@r   test_failuresHandled LoggerTests.test_failuresHandled  s   
 	\	"	! 
#	! &)	) 	)   8
 ! 
 
E
 	,,e4))40Va(q	M*"!N	
 	"!23  !9 LLPSS]]E2SZZ/ M 	"-U++
 
 
  MLs   
G9G2G/	2H	c                   < V ^8  d   QhRR/# rN   rO   )r   r   s   "r   r   rP   B  s      4  4T  4r    c                6  a . o\        \        4      R V3R ll4       p\        VR7      pVP                  R4      pRpV;_uu_ 4       pRpRRR4       V P	                  XR4       V P                  VR4       V P                  S. 4       RpR R	 lpV;_uu_ 4       pV! 4        RRR4       V P                  \        S4      ^4       Sw  pVR
,          pV P                  VP                  \        4       R#   + '       g   i     L; i  + '       g   i     Lm; i)z
The L{Logger.failureHandler} context manager can safely be shared
amongst multiple invocations and converts L{BaseException} into logged
L{Failure}s.
c                (    V ^8  d   QhR\         RR/# r#   r%   )r   s   "r   r   5LoggerTests.test_failureHandler.<locals>.__annotate__K  r   r    c                 *   < SP                  V 4       R # r(   r   r   s   &r   r   /LoggerTests.test_failureHandler.<locals>.loggedJ  r   r    rs   rw   FTNc                    V ^8  d   QhRR/# rN   rO   )r   s   "r   r   r  Y  s     	& 	&4 	&r    c                      \        4       hr(   )KeyboardInterruptrO   r    r   	raisebase2LoggerTests.test_failureHandler.<locals>.raisebaseY  s    #%%r    r   )	r   r   r   failureHandlerrh   rS   rz   r   r  )	r*   r   rJ   r
  successfhr  r   r   s	   &       @r   test_failureHandlerLoggerTests.test_failureHandlerB  s     	\	"	! 
#	! &)++G4^rG b$$'$	& ^rK  	Va(=!!23! ^ ^s   C5D5D	D	rO   N)r2   r3   r4   r5   r6   rV   r[   rc   rm   r{   r   r   r   r   r   r   r   r   r   r   r  r7   r8   r9   s   @r   rL   rL   ?   s     C C2 2; ;+ +,= =B B> >:, ,, ,
 
: : 3 3&	) 	)) ) ), ),V 4  4r    rL   N)r6   typingr   r   r   r   zope.interfacer   
constantlyr   twisted.python.failurer   twisted.trialr	   _formatr
   _globalr   _interfacesr   r   _levelsr   r   _loggerr   r   r;   TestCaserL   rO   r    r   <module>r     sW    . - & $ * " ! ( 0 4 
 
43 3c4(## c4r    