+
    Dfj	9                        R t ^ RIt^ RIHt ^ RI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 ^ 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]P>                  4      t  ! R R]P>                  4      t!R# )z+
Test cases for L{twisted.logger._legacy}.
N)time)Listcast)implementer)BrokenMethodImplementation)verifyObject)contextlog)Failure)unittest)formatEvent)ILogObserverLogEvent)LegacyLogObserverWrapperpublishToNewObserver)LogLevelc                     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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R0tV tR1# )2LegacyLogObserverWrapperTestsz(
Tests for L{LegacyLogObserverWrapper}.
c                   < V ^8  d   QhRR/#    returnN )format__classdict__s   "A/usr/lib/python3/dist-packages/twisted/logger/test/test_legacy.py__annotate__*LegacyLogObserverWrapperTests.__annotate__   s     	 	 	    c                    \        \        P                  R 4      p\        V4      p \	        \        V4       R#   \
         d   pT P                  T4        Rp?R# Rp?ii ; i)z4
L{LegacyLogObserverWrapper} is an L{ILogObserver}.
c                     R # Nr   )es   &r   <lambda>>LegacyLogObserverWrapperTests.test_interface.<locals>.<lambda>"   s    r   N)r   	legacyLogr   r   r   r   fail)selflegacyObserverobserverr"   s   &   r   test_interface,LegacyLogObserverWrapperTests.test_interface   sL     i44nE+N;	x0) 	IIaLL	s   : A!AA!c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   )   s     X X4 Xr   c                    \        \        P                  4       ! R R4      4       p\        V! 4       4      pV P	                  \        V4      R4       R# )z:
L{LegacyLogObserverWrapper} returns the expected string.
c                   D   a  ] tR t^.t o V 3R lR ltV 3R lR ltRtV tR# )?LegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserverc                    < V ^8  d   QhRS[ /# )r   r   )str)r   r   s   "r   r   LLegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserver.__annotate__0   s     + +# +r   c                    R # )z<Legacy Observer>r   r'   s   &r   __repr__HLegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserver.__repr__0   s    *r   c                8   < V ^8  d   QhRS[ P                  RR/# )r   	eventDictr   N)r%   	EventDict)r   r   s   "r   r   r2   3   s!      )*=*= $ r   c                    R # r!   r   )r'   r8   s   &&r   __call__HLegacyLogObserverWrapperTests.test_repr.<locals>.LegacyObserver.__call__3   s    r   r   N)__name__
__module____qualname____firstlineno__r5   r;   __static_attributes____classdictcell__r   s   @r   LegacyObserverr/   .   s     + + r   rD   z+LegacyLogObserverWrapper(<Legacy Observer>)N)r   r%   r   r   assertEqualrepr)r'   rD   r)   s   &  r   	test_repr'LegacyLogObserverWrapperTests.test_repr)   sJ    
 
Y++	,	 	 
-	 ,N,<=h)VWr   c                &   < V ^8  d   QhRS[ RS[ /# r   eventr   r   )r   r   s   "r   r   r   :   s      X ( r   c                   a . o\        \        P                  V3R l4      p\        V4      pV! V4       V P	                  \        S4      ^4       S^ ,          # )z
Send an event to a wrapped legacy observer and capture the event as
seen by that observer.

@param event: an event

@return: the event as observed by the legacy wrapper
c                 &   < SP                  V 4      # r!   )append)r"   eventss   &r   r#   7LegacyLogObserverWrapperTests.observe.<locals>.<lambda>E   s    a@Pr   )r   r%   r   r   rE   len)r'   rK   r(   r)   rP   s   &&  @r   observe%LegacyLogObserverWrapperTests.observe:   sL     "$i446PQ+N;Va(ayr   c                &   < V ^8  d   QhRS[ RS[ /# rJ   rL   )r   r   s   "r   r   r   L   s      h 8 r   c                &   VP                  R\        4       4       VP                  RR4       VP                  R\        P                  4       V P	                  \        V4      4      pVP                  4        F  w  r4V P                  W24       K  	  V# )z
Send an event to a wrapped legacy observer and verify that its data is
preserved.

@param event: an event

@return: the event as observed by the legacy wrapper
log_time
log_system-	log_level)
setdefaultr   r   inforS   dictitemsassertIn)r'   rK   observedkeyvalues   &&   r   forwardAndVerify.LegacyLogObserverWrapperTests.forwardAndVerifyL   su     	TV,s+hmm4 <<U,  ++-JCMM#( ( r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   c   s     2 2d 2r   c                >    V P                  \        ^^R7      4       R# )zM
Basic forwarding: event keys as observed by a legacy observer are the
same.
foobarN)rc   r]   r4   s   &r   test_forward*LegacyLogObserverWrapperTests.test_forwardc   s    
 	dqa01r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   j   s     / /4 /r   c                    \        4       pV P                  \        VR7      4      pV P                  VR,          V4       R# )zK
The new-style C{"log_time"} key is copied to the old-style C{"time"}
key.
)rW   r   Nr   rc   r]   rE   r'   stamprK   s   &  r   	test_time'LegacyLogObserverWrapperTests.test_timej   s4    
 %%dE&:;v.r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   s   s     / /T /r   c                    \        4       pV P                  \        V^,           VR7      4      pV P                  VR,          V4       R# )zZ
The new-style C{"log_time"} key does not step on a pre-existing
old-style C{"time"} key.
)rW   r   r   Nrn   ro   s   &  r   test_timeAlreadySet1LegacyLogObserverWrapperTests.test_timeAlreadySets   s:    
 %%dEAIE&JKv.r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   |   s     1 1T 1r   c                n    V P                  \        RR7      4      pV P                  VR,          R4       R# )zO
The new-style C{"log_system"} key is copied to the old-style
C{"system"} key.
rh   )rX   systemNrc   r]   rE   r'   rK   s   & r   test_system)LegacyLogObserverWrapperTests.test_system|   s-    
 %%de&<=x%0r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     1 1t 1r   c                p    V P                  \        RRR7      4      pV P                  VR,          R4       R# )z^
The new-style C{"log_system"} key does not step on a pre-existing
old-style C{"system"} key.
rh   ri   )rX   ry   ry   Nrz   r{   s   & r   test_systemAlreadySet3LegacyLogObserverWrapperTests.test_systemAlreadySet   s/    
 %%deE&JKx%0r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     2 2t 2r   c                    \        \        4       \        P                  R7      pV P	                  \        V4      4      pV P                  VR,          R4       R# )za
If the new-style C{"log_system"} key is absent, the old-style
C{"system"} key is set to C{"-"}.
)rW   rZ   ry   rY   N)r]   r   r   r\   rS   rE   )r'   rK   r`   s   &  r   test_noSystem+LegacyLogObserverWrapperTests.test_noSystem   s=     df><<U,(+S1r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     	L 	LT 	Lr   c                V   V P                  \        \        P                  ^R7      4       V P                  \        \        P                  ^R7      4       V P                  \        \        P
                  ^ R7      4       V P                  \        \        P                  ^ R7      4       R# )z
If explicitly set, the C{isError} key will be preserved when forwarding
from a new-style logging emitter to a legacy logging observer,
regardless of log level.
)rZ   isErrorN)rc   r]   r   r\   warnerrorcriticalr4   s   &r   test_levelNotChange1LegacyLogObserverWrapperTests.test_levelNotChange   sj     	dX]]AFGdX]]AFGdX^^QGHdX->->JKr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     
, 
,4 
,r   c                |    V P                  \        \        P                  R7      4      pV P	                  RV4       R# )z
The new-style C{"log_level"} key is not translated to the old-style
C{"logLevel"} key.

Events are forwarded from the old module from to new module and are
then seen by old-style observers.
We don't want to add unexpected keys to old-style events.
)rZ   logLevelN)rc   r]   r   r\   assertNotInr{   s   & r   test_pythonLogLevelNotSet7LegacyLogObserverWrapperTests.test_pythonLogLevelNotSet   s-     %%dX]]&CDU+r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     7 74 7r   c                n    V P                  \        RR7      4      pV P                  VR,          R4       R# )z
If a stdlib log level was provided as a string (eg. C{"WARNING"}) in
the legacy "logLevel" key, it does not get converted to a number.
The documentation suggested that numerical values should be used but
this was not a requirement.
WARNINGr   r   Nrz   r{   s   & r   test_stringPythonLogLevel7LegacyLogObserverWrapperTests.test_stringPythonLogLevel   s6     %%"

 	z*I6r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     / /d /r   c                j    V P                  \        4       4      pV P                  VR,          R4       R# )z~
The old-style C{"message"} key is added, even if no new-style
C{"log_format"} is given, as it is required, but may be empty.
messageNr   rz   r{   s   & r   test_message*LegacyLogObserverWrapperTests.test_message   s+    
 %%df-y)2.r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     ; ; ;r   c                n    V P                  \        RR7      4      pV P                  VR,          R4       R# )zF
The old-style C{"message"} key is not modified if it already exists.
)r   r   Nrg   rz   r{   s   & r   test_messageAlreadySet4LegacyLogObserverWrapperTests.test_messageAlreadySet   s.     %%d>&BCy)>:r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     N NT Nr   c                    V P                  \        RRR7      4      pV P                  \        P                  ! V4      R4       R# )z
Formatting is translated such that text is rendered correctly, even
though old-style logging doesn't use PEP 3101 formatting.
zHello, {who}!world)
log_formatwhoHello, world!Nrc   r]   rE   r%   textFromEventDictr{   s   & r   test_format)LegacyLogObserverWrapperTests.test_format   s6    
 %%do7&ST44U;_Mr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     N ND Nr   c                    V P                  \        RRR7      4      pV P                  \        P                  ! V4      R4       R# )zW
Using the message key, which is special in old-style, works for
new-style formatting.
zHello, {message}!r   )r   r   r   Nr   r{   s   & r   test_formatMessage0LegacyLogObserverWrapperTests.test_formatMessage   s<    
 %%/A
 	44U;_Mr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     G Gt Gr   c                    V P                  \        RRR7      4      pV P                  \        P                  ! V4      R4       R# )zL
Formatting is not altered if the old-style C{"format"} key already
exists.
zHello!zHowdy!)r   r   Nr   r{   s   & r   test_formatAlreadySet3LegacyLogObserverWrapperTests.test_formatAlreadySet   s6    
 %%dhx&PQ44U;XFr   c                &   < V ^8  d   QhRS[ RS[/# )r   valuesr   )objectr   )r   r   s   "r   r   r      s     
 
 
H 
r   c           	     f    \        \        R4      4      pV P                  \        RRVRR/VB 4      # )z
Create a new-style event with a captured failure.

@param values: Additional values to include in the event.

@return: the new event
znyargh!log_failurer   	oopsie...r   )r
   RuntimeErrorrc   r]   )r'   r   failures   &, r   eventWithFailure.LegacyLogObserverWrapperTests.eventWithFailure   s;     ,y12$$GWGGG
 	
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       pV P                  VR,          VR,          4       V P                  VR,          4       V P                  VR,          R4       R# )ze
Captured failures in the new style set the old-style C{"failure"},
C{"isError"}, and C{"why"} keys.
r   r   r   whyr   N)r   assertIs
assertTruerE   r{   s   & r   test_failure*LegacyLogObserverWrapperTests.test_failure   sO    
 %%'eI&m(<=i()u{3r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r      s     1 1 1r   c                    \        \        R4      4      pV P                  VR7      pV P                  VR,          V4       R# )^
Captured failures in the new style do not step on a pre-existing
old-style C{"failure"} key.
zWeak salsa!)r   r   N)r
   r   r   r   )r'   r   rK   s   &  r   test_failureAlreadySet4LegacyLogObserverWrapperTests.test_failureAlreadySet   s9    
 ,}56%%g%6eI&0r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     . . .r   c                \    V P                  ^ R7      pV P                  VR,          ^ 4       R# )z^
Captured failures in the new style do not step on a pre-existing
old-style C{"isError"} key.
r   r   Nr   rE   r{   s   & r   test_isErrorAlreadySet4LegacyLogObserverWrapperTests.test_isErrorAlreadySet  s,    
 %%a%0y)1-r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     / /D /r   c                \    V P                  RR7      pV P                  VR,          R4       R# )r   blah)r   r   Nr   r{   s   & r   test_whyAlreadySet0LegacyLogObserverWrapperTests.test_whyAlreadySet  s+    
 %%&%1uv.r   r   N)r=   r>   r?   r@   __doc__r*   rG   rS   rc   rj   rq   ru   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rA   rB   rC   s   @r   r   r      s     	 	X X" $ .2 2/ // /1 11 12 2	L 	L
, 
,7 7/ /; ;N NN NG G
 
4 41 1. ./ /r   r   c                      a  ] tR tR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RtV tR# )PublishToNewObserverTestsi  z$
Tests for L{publishToNewObserver}.
c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   &PublishToNewObserverTests.__annotate__  s     ? ?t ?r   c                f    . V n         \        \        V P                   P                  4      V n        R # r!   )rP   r   r   rO   r)   r4   s   &r   setUpPublishToNewObserverTests.setUp  s!    &(\4;;+=+=>r   c                @   < V ^8  d   QhRS[ RS[RS[P                  /# )r   r   r   r   )r1   r   r%   r9   )r   r   s   "r   r   r     s(      C 6 i>Q>Q r   c                    \         P                  ! \        P                  4      ;'       g    / P	                  4       pVP                  V4       WR&   \        4       VR&   RV9  d   ^ VR&   V# )z
Return a basic old-style event as would be created by L{legacyLog.msg}.

@param message: a message event value in the legacy event format
@param values: additional event values in the legacy event format

@return: a legacy event
r   r   r   )r   getr%   ILogContextcopyupdater   )r'   r   r   rK   s   &*, r   legacyEvent%PublishToNewObserverTests.legacyEvent  s_     Y22399r??AV"ifE! E)r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   /  s     . .t .r   c                    \        V P                  V P                  4       \        P                  4       V P                  \        V P                  4      ^4       R# )z&
The observer is called exactly once.
N)r   r)   r   r%   r   rE   rR   rP   r4   s   &r   test_observed'PublishToNewObserverTests.test_observed/  sA     	MM4++-y/J/J	
 	T[[)1-r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   8  s     M M4 Mr   c                    \        V P                  V P                  4       \        P                  4       V P                  V P                  ^ ,          R,          V P                  ^ ,          R,          4       R# )zK
The old-style C{"time"} key is copied to the new-style C{"log_time"}
key.
rW   r   Nr   r)   r   r%   r   rE   rP   r4   s   &r   rq   #PublishToNewObserverTests.test_time8  sR    
 	MM4++-y/J/J	
 	Q
3T[[^F5KLr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   B  s     < <d <r   c                    R R lpV P                  RR4      pV! V4      p\        V P                  W!4       V P                  \	        V P
                  ^ ,          4      V4       R# )z
A published old-style event should format as text in the same way as
the given C{textFromEventDict} callable would format it.
c                0    V ^8  d   QhR\         R\        /# rJ   )r   r1   )r   s   "r   r   <PublishToNewObserverTests.test_message.<locals>.__annotate__H  s     	A 	AX 	A# 	Ar   c                 b    R P                  \        RP                  V R,          4      4      4      # )  r   )joinreversed)rK   s   &r   r   APublishToNewObserverTests.test_message.<locals>.textFromEventDictH  s$    778CHHU9-=$>?@@r   zHello,zworld!N)r   r   r)   rE   r   rP   )r'   r   rK   texts   &   r   r   &PublishToNewObserverTests.test_messageB  sQ    	A   84 'T]]EET[[^4d;r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   Q  s     E Ed Er   c                    \        V P                  V P                  4       \        P                  4       V P                  V P                  ^ ,          R,          \        P                  4       R# )z<
Published event should have log level of L{LogLevel.info}.
rZ   N)	r   r)   r   r%   r   rE   rP   r   r\   r4   s   &r   test_defaultLogLevel.PublishToNewObserverTests.test_defaultLogLevelQ  sI     	MM4++-y/J/J	
 	Q4hmmDr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   Z  s     I Id Ir   c                    \        V P                  V P                  ^R7      \        P                  4       V P                  V P                  ^ ,          R,          \        P                  4       R# )z{
If C{"isError"} is set to C{1} (true) on the legacy event, the
C{"log_level"} key should get set to L{LogLevel.critical}.
r   rZ   N)	r   r)   r   r%   r   rE   rP   r   r   r4   s   &r   test_isError&PublishToNewObserverTests.test_isErrorZ  sP    
 	MM4++A+6	8S8S	
 	Q4h6G6GHr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   d  s     E ET Er   c                    \        V P                  V P                  \        P                  R7      \
        P                  4       V P                  V P                  ^ ,          R,          \        P                  4       R# )z
If the old-style C{"logLevel"} key is set to a standard library logging
level, using a predefined (L{int}) constant, the new-style
C{"log_level"} key should get set to the corresponding log level.
r   rZ   N)r   r)   r   
py_loggingr   r%   r   rE   rP   r   r   r4   s   &r   test_stdlibLogLevel-PublishToNewObserverTests.test_stdlibLogLeveld  sV     	MMj&8&89''	

 	Q4hmmDr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   q  s     E Et Er   c                    \        V P                  V P                  RR7      \        P                  4       V P                  V P                  ^ ,          R,          \        P                  4       R# )z
If the old-style C{"logLevel"} key is set to a standard library logging
level, using a string value, the new-style C{"log_level"} key should
get set to the corresponding log level.
r   r   rZ   N)	r   r)   r   r%   r   rE   rP   r   r   r4   s   &r   test_stdlibLogLevelWithString7PublishToNewObserverTests.test_stdlibLogLevelWithStringq  sP     	MMi0''	

 	Q4hmmDr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r   ~  s     6 6 6r   c                    \        V P                  V P                  RR7      \        P                  4       V P                  RV P                  ^ ,          4       R# )z
If the old-style C{"logLevel"} key is set to a standard library logging
level, using an unknown value, the new-style C{"log_level"} key should
not get set.
zFoo!!!!!r   rZ   N)r   r)   r   r%   r   r   rP   r4   s   &r   test_stdlibLogLevelWithGarbage8PublishToNewObserverTests.test_stdlibLogLevelWithGarbage~  sG     	MMj1''	

 	dkk!n5r   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     H Ht Hr   c                    \        V P                  V P                  4       \        P                  4       V P                  V P                  ^ ,          R,          R4       R# )zs
Published event should have a namespace of C{"log_legacy"} to indicate
that it was forwarded from legacy logging.
log_namespace
log_legacyNr   r4   s   &r   test_defaultNamespace/PublishToNewObserverTests.test_defaultNamespace  sE    
 	MM4++-y/J/J	
 	Q8,Gr   c                   < V ^8  d   QhRR/# r   r   )r   r   s   "r   r   r     s     Q QT Qr   c                    \        V P                  V P                  4       \        P                  4       V P                  V P                  ^ ,          R,          V P                  ^ ,          R,          4       R# )zO
The old-style C{"system"} key is copied to the new-style
C{"log_system"} key.
rX   ry   Nr   r4   s   &r   r|   %PublishToNewObserverTests.test_system  sR    
 	MM4++-y/J/J	
 	Q5t{{1~h7OPr   )rP   r)   N)r=   r>   r?   r@   r   r   r   r   rq   r   r   r   r  r	  r  r  r|   rA   rB   rC   s   @r   r   r     s     ? ? ". .M M< <E EI IE EE E6 6H HQ Qr   r   )"r   loggingr  r   typingr   r   zope.interfacer   zope.interface.exceptionsr   zope.interface.verifyr   twisted.pythonr   r	   r%   twisted.python.failurer
   twisted.trialr   _formatr   _interfacesr   r   _legacyr   r   _levelsr   TestCaser   r   r   r   r   <module>r%     s^       & @ . 4 * " ! 0 D y/H$5$5 y/xHQ 1 1 HQr   