+
    Dfjq                       R t ^ RIHt ^ RIt^ RIt^ RIt^ RIt^ RIt^ RI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HtHtHtHt ^ RIHt ^ R	IHtHt ^ R
IHt ^ RI H!t!  ! R R]"4      t# ! R R]!PH                  4      t% ! R R]!PH                  4      t& ! R R]]',          4      t(]
PR                  ! ](4        ! R R4      t* ! R R4      t+ ! R R]*]+4      t, ! R R]4      t- ! R R4      t. ! R R].]!PH                  4      t/ ! R  R!].]!PH                  4      t0 ! R" R#]!PH                  4      t1 ! R$ R%]!PH                  4      t2 ! R& R']!PH                  4      t3 ! R( R)]!PH                  4      t4R# )*z"
Tests for L{twisted.python.log}.
)annotationsN)IOBaseStringIO)CallableList)implementer)Protocol)ILogObserverLogBeginnerLoggingFileLogLevelLogPublisher)handlerAndBytesIO)failurelog)r   )unittestc                      ] tR t^#tRtRtR# )FakeWarningzs
A unique L{Warning} subclass used by tests for interactions of
L{twisted.python.log} with the L{warnings} module.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       7/usr/lib/python3/dist-packages/twisted/test/test_log.pyr   r   #   s    r   r   c                  b    ] tR t^*tRtR R ltR R ltR R ltR R	 ltR
 R lt	R R lt
RtR# )TextFromEventDictTestsz!
Tests for L{textFromEventDict}.
c                   V ^8  d   QhRR/#    returnNoner   )formats   "r   __annotate__#TextFromEventDictTests.__annotate__/   s     ( (d (r   c                n    \        RR7      p\        P                  ! V4      pV P                  VR4       R# )zR
The C{"message"} value, when specified, is concatenated to generate the
message.
)messageza b cN)abcdictr   textFromEventDictassertEqualself	eventDicttexts   &  r   test_message#TextFromEventDictTests.test_message/   s.    
 1	$$Y/w'r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r&   8   s     / /T /r   c                t    \        R^ RRR7      p\        P                  ! V4      pV P                  VR4       R# )zG
The C{"format"} value, when specified, is used to format the message.
zHello, %(foo)s!dude)r(   isErrorr$   foozHello, dude!Nr   r,   r0   s   &  r   test_format"TextFromEventDictTests.test_format8   s5     Q7HfU	$$Y/~.r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r&   @   s          r   c                n    \        R^ R7      p\        P                  ! V4      pV P                  V4       R# )zJ
If C{"format"} is unspecified and C{"message"} is empty, return
L{None}.
r(   r9   Nr   )r-   r   r.   assertIsNoner0   s   &  r   test_noMessageNoFormat-TextFromEventDictTests.test_noMessageNoFormat@   s.    
 Q/	$$Y/$r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r&   I   s     6 64 6r   c                     \        4       h  \         dc    \        R^\        P                  ! 4       RR7      p\
        P                  ! T4      pTf   Q hT P                  TP                  R4      4        R# i ; i)z?
The C{"why"} value, when specified, is first part of message.
r:   )r(   r9   r   whyNzfoo
r   	RuntimeErrorBaseExceptionr-   r   Failurer   r.   
assertTrue
startswithr0   s   &  r   test_whySpecified(TextFromEventDictTests.test_whySpecifiedI   sk    	6.  	6Aw/@eI ((3D###OODOOG45	6s   
 A)A98A9c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r&   W   s     
B 
B 
Br   c                     \        4       h  \         db    \        R^\        P                  ! 4       R7      p\
        P                  ! T4      pTf   Q hT P                  TP                  R4      4        R# i ; i)zI
The C{"why"} value, when unspecified, defaults to C{"Unhandled Error"}.
r(   r9   r   NzUnhandled Error
r   rF   r0   s   &  r   test_whyDefault&TextFromEventDictTests.test_whyDefaultW   sh    	B.  	BRGOO<MNI((3D###OODOO,?@A		Bs   
 A(A87A8c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r&   c   s     > > >r   c                    \        R^\        4       R7      p\        P                  ! V4      pV P	                  RV4       R# )zS
If unable to obtain a traceback due to an exception, catch it and note
the error.
rP   z
(unable to obtain traceback)Nr   )r-   objectr   r.   assertInr0   s   &  r   test_noTracebackForYou-TextFromEventDictTests.test_noTracebackForYouc   s3     QA	$$Y/6=r   r   N)r   r   r   r   r   r4   r;   rA   rL   rQ   rW   r   r   r   r   r   r   *   s+    (/ 6
B> >r   r   c                      ] tR t^ntR R ltR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltRtR# )LogTestsc                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   LogTests.__annotate__o   s     ; ;t ;r   c                	    . V n         V P                   P                  V n        \        P                  ! V P                  4       V P                  \        P                  V P                  4       R # N)catcherappendobserverr   addObserver
addCleanupremoveObserverr1   s   &r   setUpLogTests.setUpo   sB    ,.++&**DMM:r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\   u   s     * * *r   c                	8   V P                   p\        P                  ! R RR7       VP                  4       pV P	                  VR,          ^ ,          R 4       V P                  VR,          4       V P                  RV4       V P	                  \        V4      ^ 4       R# )testT)testShouldCatchr(   rk   timeN)r_   r   msgpopr/   rJ   rV   lenr1   r_   is   &  r   testObservationLogTests.testObservationu   sp    ,,-KKM9a&1+,-fa Wq)r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\   ~   s     1 1T 1r   c           	     	   V P                   p\        P                  ! R RRRRR/\        P                  RR/\        P                  RRR	7       VP	                  4       pV P                  VR,          R4       V P                  VR ,          R4       V P                  VR,          R4       V P                  VR
,          ^ ,          R4       R# )	subsystemznot the defaultsubsubsystemr)   otherr+   r*   r:   d)rx   r(   N)r_   r   callWithContextrm   rn   r/   rp   s   &  r   testContextLogTests.testContext~   s    ,,+^S'3OS!GG	
 KKM>*C0;):;7S)9a%0r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\      s     	' 	'D 	'r   c                	6   R\        4       \         3\        P                  ! \        4       4      \        33 F_  w  r\        P
                  ! V4       V P                  P                  4       pV P                  VR,          ^4       V P                  V4       Ka  	  R# )hello worldr9   Nr   r   
KeyErrorr   rI   rG   r   errr_   rn   r/   flushLoggedErrorsr1   eigrq   s   &   r   
testErrorsLogTests.testErrors   sq    *Z"__\^,l;
EA
 GGAJ  "AQy\1-""2&
r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\      s     
' 
'4 
'r   c                	j   R\        4       \         3\        P                  ! \        4       4      \        33 Fy  w  r\        P
                  ! VR4       V P                  P                  4       pV P                  VR,          ^4       V P                  VR,          R4       V P                  V4       K{  	  R# )r   foobarr9   rE   Nr   r   r   s   &   r   testErrorsWithWhyLogTests.testErrorsWithWhy   s    *Z"__\^,l;
EA
 GGAx   "AQy\1-QuXx0""2&
r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\      s     %C %Cd %Cr   c                   . p. pR R lpVP                   W2P                   3 F9  p\        P                  ! V4       V P                  \        P                  V4       K;  	  \        ^4       F  p. VR&   . VR&   \        P                  ! R. R7       V P                  \        4      pV P                  R V P                  \        V4      ^4       V P                  \        V4      ^4       V P                  \        V4      ^4       V P                  V^ ,          R,          R4       V P                  V^ ,          R,          R4       K  	  R# )	z
Exceptions raised by log observers are logged but the observer which
raised the exception remains registered with the publisher.  These
exceptions do not prevent the event from being sent to other observers
registered with the publisher.
c                    V ^8  d   QhRRRR/# r!   eventlog.EventDictr"   r#   r   )r$   s   "r   r%   3LogTests.test_erroneousErrors.<locals>.__annotate__   s     	 	- 	D 	r   c                    ^^ ,           R#    Nr   )r   s   &r   broken-LogTests.test_erroneousErrors.<locals>.broken   s    FFr   :NNNHowdy, y'all.)	log_tracer(   N)r   )r`   r   rb   rc   rd   rangerm   r   ZeroDivisionErrorr_   r/   ro   )r1   L1L2r   ra   rq   excss   &      r   test_erroneousErrorsLogTests.test_erroneousErrors   s    #%"$	 FII6HOOH%OOC..9 7 qABqEBqE GGOr2 ))*;<DQSY* SWa(SWa( RU9-/ABRU9-/AB) r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\      s     &+ &+$ &+r   c                V   \         P                  ! 4       pVP                  V P                  4       VP	                  \        R4      \
        R^4       V P                  P                  4       pV P                  VR,          V,          R4       V P                  V P                  . 4       VP	                  \        R4      \
        R^\        4       R7       V P                  P                  4       pV P                  VR,          V,          R4       V P                  V P                  . 4       R# )za
L{twisted.python.log.showwarning} emits the warning as a message
to the Twisted logging system.
zunique warning messagewarning-filename.pyr$   zQwarning-filename.py:27: twisted.test.test_log.FakeWarning: unique warning message)lineN)
r   r   rb   ra   showwarningr   r_   rn   r/   rU   )r1   	publisherr   s   &  r   test_showwarningLogTests.test_showwarning   s   
 $$&	dmm,01!		
   "(Oe#%	

 	r*
 	01! 	 	
   "(Oe#%	

 	r*r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\      s     
 
D 
r   c           
        Rp\         pRp^p\        4       p\        P                  ! WW4VR7       V P	                  VP                  4       \        P                  ! WW44      4       Rp\        4       p\        P                  ! WW4WVR7       V P	                  VP                  4       \        P                  ! WW4V4      4       R# )z|
L{twisted.python.log.showwarning} passes warnings with an explicit file
target on to the underlying Python warning system.
zanother unique messager   filer   )r   r   N)r   r   r   r   r/   getvaluewarningsformatwarning)r1   r(   categoryfilenamelinenooutputr   s   &      r   test_warningToFileLogTests.test_warningToFile   s    
 +(8&IOO""7hG	
 8&TOO""7hM	
r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r\     s     7 7t 7r   c                v  a . oR V3R llpR R lp\         P                  ! 4       pVP                  V4       VP                  V4       VP                  R4       V P	                  \        VP                  4      W04       V P	                  \        S4      ^4       V P                  S^ ,          \        4       R# )zS
Log publisher does not use the global L{log.err} when reporting broken
observers.
c                    V ^8  d   QhRRRR/# r!   r2   r   r"   r#   r   )r$   s   "r   r%   LLogTests.test_publisherReportsBrokenObserversPrivately.<locals>.__annotate__  s     	: 	: 	:$ 	:r   c                ~   < V P                  R 4      '       d%   SP                  V R,          P                  4       R# R# r9   r   N)getr`   value)r2   errorss   &r   logErrorHLogTests.test_publisherReportsBrokenObserversPrivately.<locals>.logError  s.    }}Y''i	2889 (r   c                    V ^8  d   QhRRRR/# r   r   )r$   s   "r   r%   r     s     	M 	MM 	Md 	Mr   c                    \        R 4      h)*test_publisherLocalyReportsBrokenObservers)rG   r2   s   &r   failDLogTests.test_publisherReportsBrokenObserversPrivately.<locals>.fail  s    KLLr   Hello!N)
r   r   rb   rm   r/   set	observersro   assertIsInstancerG   )r1   r   r   r   r   s   &   @r   -test_publisherReportsBrokenObserversPrivately6LogTests.test_publisherReportsBrokenObserversPrivately  s    
 	: 	:	M $$&	h'd#hY001H3CDVa(fQi6r   r_   ra   N)r   r   r   r   rf   rr   r{   r   r   r   r   r   r   r   r   r   r   rZ   rZ   n   s7    ;*1 	'
'%CN&+P
<7 7r   rZ   c                  .    ] tR tRtR R ltR R ltRtR# )FakeFilei*  c                    V ^8  d   QhRRRR/# )r!   bytesr"   r#   r   )r$   s   "r   r%   FakeFile.__annotate__+  s      5 T r   c                	(    V P                  V4       R # r^   r`   )r1   r   s   &&r   writeFakeFile.write+  s    Er   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r   .  s      t r   c                	    R # r^   r   re   s   &r   flushFakeFile.flush.  s    r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   *  s     r   r   c                  "    ] tR tRtR R ltRtR# )EvilStri5  c                   V ^8  d   QhRR/# r!   r"   strr   )r$   s   "r   r%   EvilStr.__annotate__6  s       r   c                	&    \        ^^ ,          4      # r   r   re   s   &r   __str__EvilStr.__str__6      16{r   r   N)r   r   r   r   r   r   r   r   r   r   r   5  s     r   r   c                  .    ] tR tRtR R ltR R ltRtR# )EvilRepri:  c                   V ^8  d   QhRR/# r   r   )r$   s   "r   r%   EvilRepr.__annotate__;  s     ! ! !r   c                	    R # )zHappy Evil Reprr   re   s   &r   r   EvilRepr.__str__;  s     r   c                   V ^8  d   QhRR/# r   r   )r$   s   "r   r%   r   >  s      # r   c                	&    \        ^^ ,          4      # r   r   re   s   &r   __repr__EvilRepr.__repr__>  r   r   r   N)r   r   r   r   r   r   r   r   r   r   r   r   :  s    ! r   r   c                      ] tR tRtRtR# )EvilReprStriB  r   N)r   r   r   r   r   r   r   r   r   r   B  s    r   r   c                  .    ] tR tRt$ R]R&   R R ltRtR# )_LogPublisherTestCaseMixinBaseiF  r   outc               (    V ^8  d   QhRRRRRRRR/# )	r!   instancerU   classOrTupletyper(   r   r"   r#   r   )r$   s   "r   r%   +_LogPublisherTestCaseMixinBase.__annotate__I  s,      .2=@	r   c                	    R # r^   r   )r1   r   r   r(   s   &&&&r   r   /_LogPublisherTestCaseMixinBase.assertIsInstanceI  s     	r   r   N)r   r   r   r   __annotations__r   r   r   r   r   r   r   F  s    	M r   r   c                  .    ] tR tRtR R ltR R ltRtR# )LogPublisherTestCaseMixiniO  c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   &LogPublisherTestCaseMixin.__annotate__P  s     
+ 
+t 
+r   c                    \        4       V n        \        P                  ! 4       V n        \        P
                  ! V P                  4      V n        V P                  P                  V P                  P                  4       R# )z
Add a log observer which records log events in C{self.out}.  Also,
make sure the default string encoding is ASCII so that
L{testSingleUnicode} can test the behavior of logging unencodable
unicode messages.
N)	r   r   r   r   lpFileLogObserverflorb   emitre   s   &r   rf   LogPublisherTestCaseMixin.setUpP  sM     :""$&&txx0DHHMM*r   c                    V ^8  d   QhRRRR/# )r!   r1   r   r"   r#   r   )r$   s   "r   r%   r  \  s     M M5 M$ Mr   c                b    V P                    F  pV P                  V\        V: R24       K   	  R# )z
Verify that everything written to the fake file C{self.out} was a
C{str}.  Also, restore the default string encoding to its previous
setting, if it was modified by L{setUp}.
z was not a stringN)r   r   r   )r1   chunks   & r   tearDown"LogPublisherTestCaseMixin.tearDown\  s,     XXE!!%	9J.KL r   )r	  r  r   N)r   r   r   r   rf   r  r   r   r   r   r  r  O  s    
+M Mr   r  c                  :    ] tR tRtR R ltR R ltR R ltRtR	# )
LogPublisherTestsif  c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   LogPublisherTests.__annotate__g  s     + +$ +r   c                	    V P                   P                  R 4       V P                  \        V P                  4      ^4       R# )Hello, world.Nr  rm   r/   ro   r   re   s   &r   testSingleString"LogPublisherTests.testSingleStringg  s*    O$TXX*r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r  k  s     + +D +r   c                	    V P                   P                  R R4       V P                  \        V P                  4      ^4       R# )zHello, zworld.Nr  re   s   &r   testMultipleString$LogPublisherTests.testMultipleStringk  s.     	Ix(TXX*r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r  r  s     , ,D ,r   c                    RpV P                   P                  V4       V P                  \        V P                  4      ^4       V P                  WP                  ^ ,          4       R# )z
L{log.LogPublisher.msg} does not accept non-ASCII Unicode on Python 2,
logging an error instead.

On Python 3, where Unicode is default message type, the message is
logged normally.
   Hello, ½ world.N)r  rm   r/   ro   r   rV   )r1   r(   s   & r   test_singleUnicode$LogPublisherTests.test_singleUnicoder  sE     ?GTXX*gxx{+r   r   N)r   r   r   r   r  r  r!  r   r   r   r   r  r  f  s    ++, ,r   r  c                  >   ] tR tRtRtRtRtRtRtRt	Rt
R	tR
 R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR" R# ltR$ R% ltR& R' ltR( R) ltR* R+ ltR, R- ltR. R/ ltR0 R1 ltR2 R3 lt R4 R5 lt!R6t"R7# )8FileObserverTestsi  z 
Tests for L{log.FileObserver}.
zInvalid format stringzUNFORMATTABLE OBJECTz<Invalid format string or unformattable object in log messagezPATHOLOGICAL ERRORzUnable to format eventz[UNFORMATTABLE]z)MESSAGE LOST: unformattable object loggedc               (    V ^8  d   QhRRRRRRRR/# )r!   tznamer   daylightOffsetintstandardOffsetr"   r#   r   )r$   s   "r   r%   FileObserverTests.__annotate__  s2     D DD+.D@CD	Dr   c                   \        \        RR4      f   \        P                  ! R4      h\        P
                  P                  RR4      p V\        P
                  R&   \        P                  ! 4        Rp\        P                  ! V4      pRp \        P                  ! V4      pT P                  T P                  P                  T4      T P                  P                  T4      3Y#34       Tf   \        P
                  R MT\        P
                  R&   \        P                  ! 4        R#   \         d    Y#8X  d   Tp Lh i ; i  Tf   \        P
                  R MT\        P
                  R&   \        P                  ! 4        i ; i)a  
Verify that L{getTimezoneOffset} produces the expected offset for a
certain timezone both when daylight saving time is in effect and when
it is not.

@param tzname: The name of a timezone to exercise.
@type tzname: L{bytes}

@param daylightOffset: The number of seconds west of UTC the timezone
    should be when daylight saving time is in effect.
@type daylightOffset: L{int}

@param standardOffset: The number of seconds west of UTC the timezone
    should be when daylight saving time is not in effect.
@type standardOffset: L{int}
tzsetNzWPlatform cannot change timezone, cannot verify correct offsets in well-known timezones.TZ)	i  r          r/  r/  r!   r.  r/  )	i        r/  r/  r/        r   )getattrrl   r   SkipTestosenvironr   r,  mktimeOverflowErrorr/   r	  getTimezoneOffset)	r1   r&  r'  r)  originalTimezonelocalStandardTuplestandardlocalDaylightTupledaylights	   &&&&     r   _getTimezoneOffsetTest(FileObserverTests._getTimezoneOffsetTest  sL   & 4$'/##3 
 ::>>$5*	%BJJtJJL "B{{#56H "C;;'9: HH..x8HH..x8  0  'JJt$#3

4 JJL1 ! 
 "3'H
(  'JJt$#3

4 JJLs3   AE D+ $AE +E>E  EE A Fc                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     F F Fr   c                ,    V P                  RRR4       R# )z
Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
correct values for the current C{TZ} environment setting for at least
some cases.  This test method exercises a timezone that is west of UTC
(and should produce positive results).
zAmerica/New_Yorki@8  PF  Nr@  re   s   &r   test_getTimezoneOffsetWestOfUTC1FileObserverTests.test_getTimezoneOffsetWestOfUTC  s     	##$6uEr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     C C Cr   c                ,    V P                  RRR4       R# )z
Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
correct values for the current C{TZ} environment setting for at least
some cases.  This test method exercises a timezone that is east of UTC
(and should produce negative results).
zEurope/BerlinNrE  re   s   &r   test_getTimezoneOffsetEastOfUTC1FileObserverTests.test_getTimezoneOffsetEastOfUTC  s     	##OUEBr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     I I Ir   c                ,    V P                  RRR4       R# )a6  
Attempt to verify that L{FileLogObserver.getTimezoneOffset} returns
correct values for the current C{TZ} environment setting for at least
some cases.  This test method exercises a timezone that does not use
daylight saving time at all (so both summer and winter time test values
should have the same offset).
zAfrica/JohannesburgNrJ  rE  re   s   &r   /test_getTimezoneOffsetWithoutDaylightSavingTimeAFileObserverTests.test_getTimezoneOffsetWithoutDaylightSavingTime  s     	##$95%Hr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     )? )?T )?r   c                    \         P                  ! R4      pR V P                  n        V P	                  V P                  P                  V4      R4       R V P                  n        V P	                  V P                  P                  V4      R4       R V P                  n        V P	                  V P                  P                  V4      R4       R V P                  n        V P	                  V P                  P                  V4      R4       R	 V P                  n        V P	                  V P                  P                  V4      R
4       R V P                  n        V P	                  V P                  P                  V4      R4       R V P                  n        V P	                  V P                  P                  V4      R4       RV P                  n        V P	                  V P                  P                  V4      R4       R# )z]
Test the method of L{FileLogObserver} which turns a timestamp into a
human-readable string.
c                    R # )rD  r   whens   &r   <lambda>7FileObserverTests.test_timeFormatting.<locals>.<lambda>      %r   z2001-02-02 23:05:06-0500c                    R# )i  rK  r   rU  s   &r   rW  rX     rY  r   z2001-02-03 05:05:06+0100c                    R# )i  iPer   rU  s   &r   rW  rX    s    &r   z2001-02-03 15:05:06+1100c                    R # )  r   rU  s   &r   rW  rX        $r   z2001-02-03 02:35:06-0130c                    R# )r]  ir   rU  s   &r   rW  rX    rY  r   z2001-02-03 05:35:06+0130c                    R # )  r   rU  s   &r   rW  rX    r^  r   z2001-02-03 03:35:06-0030c                    R# )ra  ir   rU  s   &r   rW  rX    rY  r   z2001-02-03 04:35:06+0030z%Y %mz2001 02N)	i  r!      r2     r0        r/  )calendartimegmr	  r:  r/   
formatTime
timeFormat)r1   rV  s   & r   test_timeFormatting%FileObserverTests.test_timeFormatting  s   
 => &8",,T24NO &8",,T24NO &9",,T24NO &7",,T24NO &8",,T24NO &7",,T24NO &8",,T24NO &,,T2I>r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     B BT Br   c                ~    RV P                   n        V P                  RV P                   P                  R4      4       R# )z
L{FileLogObserver.formatTime} supports a value of C{timeFormat} which
includes C{"%f"}, a L{datetime}-only format specifier for microseconds.
z%f600000gm@N)r	  rj  r/   ri  re   s   &r   #test_microsecondTimestampFormatting5FileObserverTests.test_microsecondTimestampFormatting  s/    
 #488#6#6x#@Ar   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  '  s     G Gt Gr   c                	    V P                   P                  \        4       4       V P                  \	        V P
                  4      ^4       V P                  V P                  V P
                  ^ ,          4       R# r   )r  rm   r   r/   ro   r   assertNotInERROR_UNFORMATTABLE_OBJECTre   s   &r   %test_loggingAnObjectWithBroken__str__7FileObserverTests.test_loggingAnObjectWithBroken__str__'  sJ    GITXX*88$((1+Fr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  .  s     > >$ >r   c                	    V P                   P                  R \        4       R7       V P                  \	        V P
                  4      ^4       V P                  V P                  V P
                  ^ ,          4       R# z%(blat)sr$   blatN)r  rm   r   r/   ro   r   rV   ERROR_INVALID_FORMATre   s   &r   (test_formattingAnObjectWithBroken__str__:FileObserverTests.test_formattingAnObjectWithBroken__str__.  sL    :GI6TXX*d//!=r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  3  s     6 6$ 6r   c                	    V P                   P                  R \        4       R7       V P                  \	        V P
                  4      ^4       V P                  V P                  V P
                  ^ ,          4       R# huh)systemN)r  rm   r   r/   ro   r   rV   ERROR_FORMATre   s   &r   test_brokenSystem__str__*FileObserverTests.test_brokenSystem__str__3  sL    E'),TXX*d''!5r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  8  s     D D4 Dr   c                	    V P                   P                  R \        4       .R7       V P                  \	        V P
                  4      ^4       V P                  V P                  V P
                  ^ ,          4       R# rz  r  rm   r   r/   ro   r   rV   ru  re   s   &r   1test_formattingAnObjectWithBroken__repr__IndirectCFileObserverTests.test_formattingAnObjectWithBroken__repr__Indirect8  sN    :XZL9TXX*d55txx{Cr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  =  s     D Dt Dr   c                	    V P                   P                  R \        4       .R7       V P                  \	        V P
                  4      ^4       V P                  V P                  V P
                  ^ ,          4       R# r  r  re   s   &r   %test_systemWithBroker__repr__Indirect7FileObserverTests.test_systemWithBroker__repr__Indirect=  sN    E8:,/TXX*d55txx{Cr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  B  s     > > >r   c                	    V P                   P                  R ^R7       V P                  \        V P                  4      ^4       V P                  V P                  V P                  ^ ,          4       R# )z
hooj %s %sr{  Nr  rm   r/   ro   r   rV   r}  re   s   &r   test_simpleBrokenFormat)FileObserverTests.test_simpleBrokenFormatB  sJ    <a0TXX*d//!=r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  G  s     > >t >r   c                	    V P                   P                  ^*^R7       V P                  \        V P                  4      ^4       V P                  V P                  V P                  ^ ,          4       R# )*   r{  Nr  re   s   &r   test_ridiculousFormat'FileObserverTests.test_ridiculousFormatG  sJ    2A&TXX*d//!=r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  L  s     < <4 <r   c                	    V P                   P                  \        4       ^R7       V P                  \	        V P
                  4      ^4       V P                  V P                  V P
                  ^ ,          4       R# )r   r{  N)r  rm   r   r/   ro   r   rV   ERROR_PATHOLOGICALre   s   &r   !test_evilFormat__repr__And__str__3FileObserverTests.test_evilFormat__repr__And__str__L  sL    ;=q1TXX*d--txx{;r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  Q  s     + +t +r   c                    V P                   P                  RRR7       V P                  \        V P                  4      ^ 4       R# )z@
This kind of eventDict used to fail silently, so test it does.
 Fr?   Nr  re   s   &r   test_strangeEventDict'FileObserverTests.test_strangeEventDictQ  s0     	B.TXX*r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  X  s     < <d <r   c                    V P                  \        P                  P                  4       V P                  \        \
        R\
        P                  4       V P                  \        \
        R\
        P                  4       R# )zU
Cleanup after a startLogging() call that mutates the hell out of some
global state.
stdoutstderrN)rc   r   theLogPublisher_stopLoggingsetattrsysr  r  re   s   &r   _startLoggingCleanup&FileObserverTests._startLoggingCleanupX  sH    
 	++889h

;h

;r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  a  s     4 4t 4r   c                   a V P                  4        \        4       p\        P                  ! V4       R V3R llp. o\        P                  ! V4       \        R\        P                  R7       V P                  S^ ,          R,          ^4       R# )z[
startLogging()'s overridden sys.stderr should consider everything
written to it an error.
c                    V ^8  d   QhRRRR/# r   r   )r$   s   "r   r%   EFileObserverTests.test_printToStderrSetsIsError.<locals>.__annotate__j  s     	# 	#= 	#T 	#r   c                *   < SP                  V 4       R # r^   r   )r   observeds   &r   observe@FileObserverTests.test_printToStderrSetsIsError.<locals>.observej  s    OOE"r   r  r   r9   N)	r  r   r   startLoggingrb   printr  r  r/   )r1   fakeFiler  r  s   &  @r   test_printToStderrSetsIsError/FileObserverTests.test_printToStderrSetsIsErrora  sj    
 	!!#:"	# 	# )+ oCJJ/!Y/3r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*  s  s     H H4 Hr   c                v   \         P                  \         P                  r!V P                  4        \	        4       p\
        P                  ! V4      pV P                  VP                  4       \
        P                  ! R4       V P                  RVP                  4       4       V P                  \         P                  \        4       V P                  \         P                  P                  \         P"                  4       \%        VRR4      pV'       g   \         P&                  ! 4       pV P                  \         P                  P(                  P+                  4       VP+                  4       4       V P                  \         P                  \        4       V P                  \         P                  P                  \         P,                  4       \%        VRR4      pV'       g   \         P&                  ! 4       pV P                  \         P                  P(                  P+                  4       VP+                  4       4       R# )zR
startLogging() installs FileLogObserver and overrides sys.stdout and
sys.stderr.
r   encodingN)r  r  r  r  r   r   r  rc   stoprm   rV   r   r   r   r/   levelNewLogLevelinfor4  getdefaultencodingr  uppererror)r1   
origStdout
origStderrr  ra   r  s   &     r   test_startLogging#FileObserverTests.test_startLoggings  sc   
 "%SZZJ!!#:##H-&h 1 1 34cjj+6));+;+;<:z48--/H,,224hnn6FGcjj+6));+<+<=:z48--/H,,224hnn6FGr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     . . .r   c                2   V P                  4        \        4       \        n        R R lp\        P
                  ! V4       V P                  \        P                  V4       \        P                  ! \        P                  4      pV P                  VP                  4       V P                  \        P                  \        4       \        P                  p\        P                  ! \        P                  4      pV P                  \        P                  V4       R# )z
There are some obscure error conditions that can occur when logging is
started twice. See http://twistedmatrix.com/trac/ticket/3289 for more
information.
c                    V ^8  d   QhRRRR/# r   r   )r$   s   "r   r%   >FileObserverTests.test_startLoggingTwice.<locals>.__annotate__  s     	J 	J 	J4 	Jr   c                    V R ,          '       d7   \         P                  P                  V R,          P                  4       4       R# R# r   )r  
__stdout__r   getTracebackr   s   &r   	showError;FileObserverTests.test_startLoggingTwice.<locals>.showError  s2    ##$$Yy%9%F%F%HI $r   N)r  r   r  r  r   rb   rc   rd   r  r  r   r   assertIs)r1   r  ra   
fakeStdouts   &   r   test_startLoggingTwice(FileObserverTests.test_startLoggingTwice  s     	!!# Z
	J 		"**I6##CJJ/&cjj+6ZZ
##CJJ/cjj*-r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     35 354 35r   c           
     t  a V P                  4        \        4       p ! R R4      p\        VV\        V\	        4       V\
        4      R7      pV P                  \        RV4       R\        n        \	        4       pRR/p. o\        \        4       ! V3R lR	4      4       pV! V4       VP                  V! 4       4       \        P                  ! VR
R7       V P                  VP                  4       V P                  S. 4       \
        P                   ! R4       VP#                  4       pV P%                  RV4       R# )zi
startLogging() overrides global C{warnings.showwarning} such that
warnings go to Twisted log observers.
c                  2    ] tR tRt]! 4       t]! 4       tRtR# )FFileObserverTests.test_startLoggingOverridesWarning.<locals>.SysModulei  r   N)r   r   r   r   rU   r  r  r   r   r   r   	SysModuler    s    XFXFr   r  )logBeginnerr  N	pre-startr   c                  *   < ] tR tRtR V 3R lltRtR# )MFileObserverTests.test_startLoggingOverridesWarning.<locals>.PreStartObserveri  c                    V ^8  d   QhRRRR/# r   r   )r$   s   "r   r%   ZFileObserverTests.test_startLoggingOverridesWarning.<locals>.PreStartObserver.__annotate__  s     / /- /D /r   c                	X   < R VP                  4       9   d   SP                  V4       R# R# )r  N)keysr`   )r1   r2   receiveds   &&r   __call__VFileObserverTests.test_startLoggingOverridesWarning.<locals>.PreStartObserver.__call__  s#    ).."22OOI. 3r   r   N)r   r   r   r   r  r   )r  s   r   PreStartObserverr    s    / /r   r  F)	setStdoutzhello!zUserWarning: hello!)r  NewLogPublisherr   r
   r   r   patchr   _oldshowwarningr   r	   rb   r  rc   r  r/   warnr   rV   )	r1   newPublisherr  tempLogPublisherr  evtr  r   r  s	   &       @r   !test_startLoggingOverridesWarning3FileObserverTests.test_startLoggingOverridesWarning  s   
 	!!#&(	 	 (#L(*iR
 	

3)+;< #: G$	\	"	/ 	/ 
#	/ 	S  !1!34U3(5562&h""$+V4r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     
 
 
r   c                  aa \        4       p\        P                  ! V4      o. oR VV3R llp\        P                  ! 4       pVP	                  V4       VP                  R4       V P                  \        S4      ^4       S^ ,          pVP                  4       pRP                  SP                  VR,          4      VR,          R7      pV P                  VP                  V4      V: RV: 24       R	# )
zS
FileLogObserver.emit() will add a timestamp and system prefix to its
file output.
c                    V ^8  d   QhRRRR/# r   r   )r$   s   "r   r%   7FileObserverTests.test_emitPrefix.<locals>.__annotate__  s     	 	M 	d 	r   c                L   < SP                  V 4       SP                  V 4       R # r^   )r`   r
  )r   eventsr	  s   &r   ra   3FileObserverTests.test_emitPrefix.<locals>.observer  s    MM% HHUOr   r   z{time} [{system}] rl   r  )rl   r  z does not start with N)r   r   r  r   rb   rm   r/   ro   r   r$   ri  rJ   rK   )	r1   r   ra   r   r   resultprefixr  r	  s	   &      @@r   test_emitPrefix!FileObserverTests.test_emitPrefix  s    
 !!&)	 	
 $$&	h'hVa(q	"%,,f.? - 

 	f%j-fZ8	
r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r*    s     
 
$ 
r   c                <   \        4       p\        P                  ! V4      p\        P                  ! 4       pVP	                  VP
                  4       VP                  R4       VP                  4       pRpV P                  VP                  V4      V: RV: 24       R# )zB
FileLogObserver.emit() will append a newline to its file output.
r   zHello!
z does not end with N)
r   r   r  r   rb   r
  rm   r   rJ   endswith)r1   r   r	  r   r  suffixs   &     r   test_emitNewline"FileObserverTests.test_emitNewline  s     !!&)$$&	chh'h"OOF#j+F:6	
r   r   N)#r   r   r   r   r   r}  ru  r  r  ERROR_NO_FORMATERROR_UNFORMATTABLE_SYSTEMERROR_MESSAGE_LOSTr@  rF  rL  rP  rk  rp  rv  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r   r   r   r   r$  r$    s     3!7QL-.O!2DDLFCI)?VBG>
6
D
D
>
>
<
+<4$H4.435j
@
 
r   r$  c                  b    ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
RtR# )PythonLoggingObserverTestsi  z-
Test the bridge with python logging module.
c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   'PythonLoggingObserverTests.__annotate__  s     + +t +r   c                	$  a aa \         P                  ! R 4      oSP                  4       oSP                  \         P                  4       S P
                  R VV3R ll4       p\        4       w  S n        S n        SP                  S P                  4       S P
                  R VV 3R ll4       p\        P                  ! 4       S n        \        P                  ! 4       S n        S P                  P                  S P                  P                   4       R# )r  c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   6PythonLoggingObserverTests.setUp.<locals>.__annotate__  s     	/ 	/d 	/r   c                 *   < SP                  S 4       R # r^   )setLevel)originalLevel
rootLoggers   r   restoreLevel6PythonLoggingObserverTests.setUp.<locals>.restoreLevel  s    .r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r  #  s     	 	d 	r   c                 r   < S P                  SP                  4       SP                  P                  4        R # r^   )removeHandlerhdlrclose)r  r1   s   r   removeLogger6PythonLoggingObserverTests.setUp.<locals>.removeLogger"  s#    $$TYY/IIOOr   N)logging	getLoggergetEffectiveLevelr  DEBUGrc   r   r  r   
addHandlerr   r   r  PythonLoggingObserverobsrb   r
  )r1   r  r  r  r  s   f  @@r   rf    PythonLoggingObserverTests.setUp  s    &&r*
"446GMM*		/ 	/ 
	/ 01	48dii(		 	 
	 ""$,,.DHHMM*r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r	  +  s     4 44 4r   c                    V P                   P                  R4       V P                  RV P                  P	                  4       4       V P                  RV P                  P	                  4       4       R# )z,
Test simple output, and default log level.
r  s   Hello, world.s   INFONr  rm   rV   r   r   re   s   &r   test_singleString,PythonLoggingObserverTests.test_singleString+  sK     	O$&(9(9(;<gtxx0023r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r	  3  s     
 
$ 
r   c                   \         P                  ! \        R4      4      pV P                  P	                  VRR7       RpV P
                  P                  4       pV P                  VP                  V4      RV: RV: 24       R# )z
Test error output.
zThat is bad.T)r   r9   s	   CRITICAL:zDoes not start with z: N)	r   rI   
ValueErrorr  rm   r   r   rJ   rK   )r1   fr  r   s   &   r   test_errorString+PythonLoggingObserverTests.test_errorString3  sl     OOJ~67At,""$f%"6*Bvj9	
r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r	  @  s     > >4 >r   c                    V P                   P                  RRRR7       V P                  RV P                  P	                  4       4       R# )z
Test logging with a format.
z%(bar)s oo %(foo)sHelloworld)r$   barr:   s   Hello oo worldNr$  re   s   &r   test_formatString,PythonLoggingObserverTests.test_formatString@  s7     	/W'J'):):)<=r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r	  G  s     7 7$ 7r   c                n   V P                   P                  R\        P                  R7       V P	                  RV P
                  P                  4       4       V P	                  RV P
                  P                  4       4       V P
                  P                  ^ ^ 4       V P
                  P                  4        V P                   P                  R\        P                  R7       V P	                  RV P
                  P                  4       4       V P	                  RV P
                  P                  4       4       R# )	z7
Test the logLevel keyword for customizing level used.
z	Spam egg.)logLevels	   Spam egg.s   ERRORzFoo bar.s   Foo bar.s   WARNINGN)
r  rm   r  ERRORrV   r   r   seektruncateWARNINGre   s   &r   test_customLevel+PythonLoggingObserverTests.test_customLevelG  s     	K'--8lDHH$5$5$78h 1 1 34aJ9k488#4#4#67j$(("3"3"56r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r	  T  s     3 3t 3r   c                    V P                   P                  RRR7       V P                  V P                  P	                  4       R4       R# )z`
Verify that an event dictionary which is not an error and has an empty
message isn't recorded.
r  Fr?   r   N)r  rm   r/   r   r   re   s   &r   r  0PythonLoggingObserverTests.test_strangeEventDictT  s5    
 	B.**,c2r   )r  r  r   r   N)r   r   r   r   r   rf   r%  r+  r2  r;  r  r   r   r   r   r  r    s*    +*4
>73 3r   r  c                  2    ] tR tRtRtR R ltR R ltRtR# )	PythonLoggingIntegrationTestsi]  z,
Test integration of python logging bridge.
c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   *PythonLoggingIntegrationTests.__annotate__b  s     3 3 3r   c                   \         P                  p\         P                  p. p VP                  \         n        VP                  \         n        \         P
                  ! 4       pVP                  4        V P                  V^ ,          VP                  4       VP                  4        V P                  \        V4      ^ 4       V\         n        V\         n        R#   T\         n        T\         n        i ; i)zf
Test that start and stop methods of the observer actually register
and unregister to the log system.
N)r   rb   rd   r`   remover  startr/   r
  r  ro   )r1   oldAddObserveroldRemoveObserverlr   s   &    r   test_startStopObserver4PythonLoggingIntegrationTests.test_startStopObserverb  s    
 ..35
	3hhCO!"C++-CIIKQqT388,HHJSVQ',CO!2C -CO!2Cs   BC C1c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rC  v  s     5 5$ 5r   c                l    ! R R\         P                  4      pV! 4       p. p\         P                  P                  p VP                  \         P                  n        VP                  RR/4       V P	                  VRR/.4       V\         P                  n        R#   T\         P                  n        i ; i)z
Test that we can inherit L{log.PythonLoggingObserver} and use super:
that's basically a validation that L{log.PythonLoggingObserver} is
new-style class.
c                  .   a  ] tR tRtR V 3R lltRtV ;t# )BPythonLoggingIntegrationTests.test_inheritance.<locals>.MyObserveri}  c                    V ^8  d   QhRRRR/# r   r   )r$   s   "r   r%   OPythonLoggingIntegrationTests.test_inheritance.<locals>.MyObserver.__annotate__~  s     ( (m ( (r   c                	&   < \         SV `  V4       R # r^   )superr
  )r1   r2   	__class__s   &&r   r
  GPythonLoggingIntegrationTests.test_inheritance.<locals>.MyObserver.emit~  s    Y'r   r   )r   r   r   r   r
  r   __classcell__)rT  s   @r   
MyObserverrO  }  s    ( (r   rW  r:   r1  N)r   r  r
  r`   r/   )r1   rW  r   rI  oldEmits   &    r   test_inheritance.PythonLoggingIntegrationTests.test_inheritancev  s    	(22 	( l!#++00	5-.XXC%%*HHeU^$Q% 01-4C%%*WC%%*s   AB B3r   N)r   r   r   r   r   rJ  rY  r   r   r   r   rA  rA  ]  s    3(5 5r   rA  c                  2    ] tR tRtRtR R ltR R ltRtR# )	DefaultObserverTestsi  z
Test the default observer.
c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   !DefaultObserverTests.__annotate__  s     ) )D )r   c                f   . V n         V P                   P                  V n        \        P                  ! V P                  4       V P                  \        P                  V P                  4       \        P                  ! 4       p\        4       Vn	        VP                  4        V P                  VP                  4       Rp\        P                  ! \        4       V4       V P                  4       pV P                  W!P                  P!                  4       4       V P#                  \%        V4      ^4       R# )z]
The reason argument passed to log.err() appears in the report
generated by DefaultObserver.
zThe reason.N)r_   r`   ra   r   rb   rc   rd   DefaultObserverr   r  rF  r  r   	Exceptionr   rV   r   r/   ro   )r1   r   reasonr   s   &   r   test_failureLogger'DefaultObserverTests.test_failureLogger  s    
 -/++&**DMM:!!#Z
		!	V$'')fjj1134Va(r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   r^    s     P Pd Pr   c                X    ! R R4      pRV! 4       3p\        V^R7      p\        P                  ! 4       p\        4       ;_uu_ 4       pWTn        VP                  V4       V P                  VP                  4       P                  R4      4       RRR4       R#   + '       g   i     R# ; i)zt
DefaultObserver.emit() does not raise when it observes an error event
with a message that causes L{repr} to raise.
c                  "    ] tR tRtR R ltRtR# )?DefaultObserverTests.test_emitEventWithBrokenRepr.<locals>.Ouchi  c                   V ^8  d   QhRR/# r   r   )r$   s   "r   r%   LDefaultObserverTests.test_emitEventWithBrokenRepr.<locals>.Ouch.__annotate__  s     " "# "r   c                	&    \        ^^ ,          4      # r   r   re   s   &r   r   HDefaultObserverTests.test_emitEventWithBrokenRepr.<locals>.Ouch.__repr__  s    1q5z!r   r   N)r   r   r   r   r   r   r   r   r   Ouchrh    s    " "r   rm  r:   r?   zfoo <Ouch instanceN)	r-   r   r`  r   r  r
  rJ   r   rK   )r1   rm  r(   r   ra   r   s   &     r   test_emitEventWithBrokenRepr1DefaultObserverTests.test_emitEventWithBrokenRepr  sx    	" 	" $&/Wa0&&(ZZ6$OMM% OOFOO-889MNO ZZZs   ABB)	r   N)r   r   r   r   r   rc  rn  r   r   r   r   r\  r\    s    ),P Pr   r\  c                      ] tR tRtRtR R ltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltRtR# )StdioOnnaStickTestsi  z>
StdioOnnaStick should act like the normal sys.stdout object.
c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%    StdioOnnaStickTests.__annotate__  s     0 0t 0r   c                	h    . V n         \        P                  ! V P                   P                  4       R # r^   )
resultLogsr   rb   r`   re   s   &r   rf   StdioOnnaStickTests.setUp  s    /1../r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     3 3$ 3r   c                	Z    \         P                  ! V P                  P                  4       R # r^   )r   rd   ru  r`   re   s   &r   r  StdioOnnaStickTests.tearDown  s    4??112r   c                   V ^8  d   QhRR/# )r!   r"   z	list[str]r   )r$   s   "r   r%   rs    s     @ @	 @r   c                	p    V P                    Uu. uF  pR P                  VR,          4      NK  	  up# u upi )r  r(   )ru  join)r1   ry   s   & r   getLogMessages"StdioOnnaStickTests.getLogMessages  s+    /3?!)%???s   !3c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     
T 
TD 
Tr   c                    \         P                  ! 4       pVP                  R4       V P                  V P	                  4       R.4       VP                  R4       V P                  V P	                  4       RR.4       R# )z
Writing to a StdioOnnaStick instance results in Twisted log messages.

Log messages are generated every time a '\n' is encountered.
zHello there
This is a testzHello therez!
zThis is a test!N)r   StdioOnnaStickr   r/   r}  r1   stdios   & r   
test_writeStdioOnnaStickTests.test_write  se     ""$12,,.@E,,.@Q0RSr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     7 7t 7r   c                    \         P                  ! 4       pVP                  R4       V P                  V P                  ^ ,          R,          4       V P                  V P                  ^ ,          R,          4       R# )zc
The log messages written by StdioOnnaStick have printed=1 keyword, and
by default are not errors.
zhello
r9   printedN)r   r  r   assertFalseru  rJ   r  s   & r   test_metadata!StdioOnnaStickTests.test_metadata  sT    
 ""$I+I67*956r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     D D Dr   c                    \         P                  ! 4       pVP                  RR.4       V P                  V P	                  4       RR.4       R# )zD
Writing lines to a StdioOnnaStick results in Twisted log messages.
zlog 1zlog 2N)r   r  
writelinesr/   r}  r  s   & r   test_writeLines#StdioOnnaStickTests.test_writeLines  sC     ""$'7+,,,.'0BCr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     	D 	DD 	Dr   c                   \         P                  p\        P                  ! 4       \         n        V P	                  \
        \         RV4       \        RRR7       \        R4       V P                  V P                  4       R.4       R# )zG
When StdioOnnaStick is set as sys.stdout, prints become log messages.
r  This )endz	is a testzThis is a testN)	r  r  r   r  rc   r  r  r/   r}  )r1   	oldStdouts   & r   
test_printStdioOnnaStickTests.test_print  s^     JJ	'')
h	:f#k,,.1A0BCr   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     7 7D 7r   c                    \         P                  ! RR7      pVP                  R4       V P                  V P                  ^ ,          R,          4       R# )zB
StdioOnnaStick created with isError=True log messages as errors.
T)r9   zlog 1
r9   N)r   r  r   rJ   ru  r  s   & r   
test_errorStdioOnnaStickTests.test_error  s:     ""40I*956r   c                   V ^8  d   QhRR/# r    r   )r$   s   "r   r%   rs    s     
 
d 
r   c                   Rp\         P                  ! RR7      pV P                  VP                  R4       VP	                  VR,           4       VP                  RV,           .4       \        P                  pV\        n        V P                  \        \        RV4       \        V4       V P                  V P                  4       VRV,           V.4       R# )z
StdioOnnaStick converts unicode prints to byte strings on Python 2, in
order to be compatible with the normal stdout/stderr objects.

On Python 3, the prints are left unmodified.
r   zutf-8)r  
zAlso, r  N)r   r  r/   r  r   r  r  r  rc   r  r  r}  )r1   unicodeStringr  r  s   &   r   test_unicode StdioOnnaStickTests.test_unicode  s     E""G41MD()(]234JJ	
h	:m!H}4mD	
r   )ru  N)r   r   r   r   r   rf   r  r}  r  r  r  r  r  r  r   r   r   r   rq  rq    s=    03@
T7D	D7
 
r   rq  )5r   
__future__r   rg  r  r6  r  rl   r   ior   r   typingr   r   zope.interfacer   r   twisted.loggerr	   r
   r   r   r  r   r  twisted.logger.test.test_stdlibr   twisted.pythonr   r   twisted.python.logtwisted.trialr   Warningr   SynchronousTestCaser   rZ   r   r   registerr   r   r   r   r  r  r$  r  rA  r\  rq  r   r   r   <module>r     sQ   #   	 
    ! &   > ' + "' A>X99 A>Hy7x++ y7xtE{    
 	'8 	X M M.,183O3O ,4N
183O3O N
bI3!=!= I3X,5H$@$@ ,5^,P877 ,P^T
(66 T
r   