ó
    Ö›‘hß1  ã                   ó  • S r SSKrSSKJrJrJrJrJrJrJ	r	J
r
  SSKJr  SSKJr  SSKJr  SSKJrJr  SS	KJrJr  SS
KJr  SSKJr  SSKJr  SSKJr  S\R>                  S\\   S\\   SS4S jr  " S S\R>                  5      r!g)z+
Test cases for L{twisted.logger._global}.
é    N)ÚIOÚAnyÚListÚOptionalÚTextIOÚTupleÚTypeÚcast)ÚFailure)Úunittesté   )ÚtextFileLogObserver)ÚMORE_THAN_ONCE_WARNINGÚLogBeginner)ÚILogObserverÚLogEvent)ÚLogLevel)ÚLogger)ÚLogPublisher)ÚnextLineÚtestÚactualEventsÚexpectedEventsÚreturnc                 ó8  ^• [        U5      [        U5      :w  a  U R                  X5        [        5       mU H  nT[        UR                  5       5      -  mM!     S[        S[        4U4S jjnU Vs/ s H
  o4" U5      PM     nnU R                  XR5        gs  snf )a  
Compare two sequences of log events, examining only the the keys which are
present in both.

@param test: a test case doing the comparison
@param actualEvents: A list of log events that were emitted by a logger.
@param expectedEvents: A list of log events that were expected by a test.
Úeventr   c                 óˆ   >• U R                  5       nU R                  5        H  nUT;  d  M  UR                  U5        M     U$ ©N)ÚcopyÚkeysÚpop)r   r   ÚkeyÚallMergedKeyss      €ÚcC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/logger/test/test_global.pyÚsimplifyÚcompareEvents.<locals>.simplify*   s8   ø€ Ø�z‰z‹|ˆØ—:‘:–<ˆCØ˜-Õ'Ø—‘˜–ñ  ð ˆó    N)ÚlenÚassertEqualÚsetr    r   )r   r   r   r   r%   ÚsimplifiedActualr#   s         @r$   ÚcompareEventsr,      s�   ø€ ô ˆ<ÓœC Ó/Ó/Ø×Ñ˜Ô6Ü“E€MãˆØœ˜UŸZ™Z›\Ó*Ñ*Šñ  ðœð ¤X÷ ñ 6BÓB²\¨E˜ ž±\ÐÐBØ×ÑÐ%Õ6ùò Cs   Á2Bc                   ó°   • \ rS rSrSrSS jrSS jrSS jrS\S	\	SS4S
 jr
SS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSS jrSrg)ÚLogBeginnerTestsé5   z
Tests for L{LogBeginner}.
r   Nc                 ó$  • [        5       U l        [        R                  " 5       U l         " S S5      n " S S5      nU" 5       U l        U" 5       U l        [        U R                  U R                  U R
                  U R                  5      U l        g )Nc                   ó0   • \ rS rSr\" 5       r\" 5       rSrg)Ú&LogBeginnerTests.setUp.<locals>.NotSysé>   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__ÚobjectÚstdoutÚstderrÚ__static_attributes__r4   r'   r$   ÚNotSysr2   >   s   † Ù“XˆFÙ“X‹Fr'   r=   c                   ód   • \ rS rSrSS jr  SS\S\\   S\S\S	\	\
\      S
\	\   SS4S jjrSrg)Ú+LogBeginnerTests.setUp.<locals>.NotWarningséB   r   Nc                 ó   • / U l         g r   ©Úwarnings)Úselfs    r$   Ú__init__Ú4LogBeginnerTests.setUp.<locals>.NotWarnings.__init__C   s   € ð
 ð	 •r'   ÚmessageÚcategoryÚfilenameÚlinenoÚfileÚlinec                 ó@   • U R                   R                  XX4XV45        g)a%  
Emulate warnings.showwarning.

@param message: A warning message to emit.
@param category: A warning category to associate with
    C{message}.
@param filename: A file name for the source code file issuing
    the warning.
@param lineno: A line number in the source file where the
    warning was issued.
@param file: A file to write the warning message to.  If
    L{None}, write to L{sys.stderr}.
@param line: A line of source code to include with the warning
    message. If L{None}, attempt to read the line from
    C{filename} and C{lineno}.
N)rC   Úappend)rD   rG   rH   rI   rJ   rK   rL   s          r$   ÚshowwarningÚ7LogBeginnerTests.setUp.<locals>.NotWarnings.showwarningJ   s   € ð2 —‘×$Ñ$ g¸È4Ð%VÕWr'   rB   ©r   N)NN)r5   r6   r7   r8   rE   Ústrr	   ÚWarningÚintr   r   r   rO   r<   r4   r'   r$   ÚNotWarningsr?   B   sw   † ôð +/Ø&*ñXàðXð ˜w™-ðXð ð	Xð
 ðXð ˜r #™wÑ'ðXð ˜s‘mðXð ÷Xð Xr'   rU   )	r   Ú	publisherÚioÚStringIOÚerrorStreamÚ	sysModuleÚwarningsModuler   Úbeginner)rD   r=   rU   s      r$   ÚsetUpÚLogBeginnerTests.setUp:   sn   € Ü%›ˆŒÜŸ;š;›=ˆÔ÷	ñ 	÷!	Xñ !	XñF  ›ˆŒÙ)›mˆÔÜ#Ø�N‰N˜D×,Ñ,¨d¯n©n¸d×>QÑ>Qó
ˆ�r'   c                 ó  ^^• [        SSS9n/ m/ m[        [        U4S j5      n[        [        U4S j5      nU R                  R	                  X#45        U R                  U5        U R                  U/T5        U R                  U/T5        g)z/
Test that C{beginLoggingTo()} adds observers.
é   r   ©ÚfooÚbarc                 ó&   >• TR                  U 5      $ r   ©rN   ©ÚeÚevents1s    €r$   Ú<lambda>ÚBLogBeginnerTests.test_beginLoggingToAddObservers.<locals>.<lambda>t   ó   ø€ ¨'¯.©.¸Ô*;r'   c                 ó&   >• TR                  U 5      $ r   re   ©rg   Úevents2s    €r$   ri   rj   u   rk   r'   N)Údictr
   r   r\   ÚbeginLoggingTorV   r)   ©rD   r   Úo1Úo2rh   rn   s       @@r$   Útest_beginLoggingToAddObserversÚ0LogBeginnerTests.test_beginLoggingToAddObserversk   sy   ù€ ô ˜ Ñ"ˆà"$ˆØ"$ˆä”,Ô ;Ó<ˆÜ”,Ô ;Ó<ˆà�‰×$Ñ$ b XÔ.Ø�‰�uÔà×Ñ˜%˜ 'Ô*Ø×Ñ˜%˜ 'Õ*r'   c                 ó  ^^• [        SSS9n/ m/ m[        [        U4S j5      n[        [        U4S j5      nU R                  U5        U R                  R                  X#45        U R                  U/T5        U R                  U/T5        g)zD
Test that events are buffered until C{beginLoggingTo()} is
called.
r`   r   ra   c                 ó&   >• TR                  U 5      $ r   re   rf   s    €r$   ri   ÚDLogBeginnerTests.test_beginLoggingToBufferedEvents.<locals>.<lambda>‡   rk   r'   c                 ó&   >• TR                  U 5      $ r   re   rm   s    €r$   ri   rx   ˆ   rk   r'   N)ro   r
   r   rV   r\   rp   r)   rq   s       @@r$   Ú!test_beginLoggingToBufferedEventsÚ2LogBeginnerTests.test_beginLoggingToBufferedEvents}   sy   ù€ ô
 ˜ Ñ"ˆà"$ˆØ"$ˆä”,Ô ;Ó<ˆÜ”,Ô ;Ó<ˆà�‰�uÔØ�‰×$Ñ$ b XÔ.à×Ñ˜%˜ 'Ô*Ø×Ñ˜%˜ 'Õ*r'   Úlimitr\   c           	      ó&  • [        US-   5       H  nU R                  [        US95        M     / nUR                  [	        [
        UR                  5      /5        U R                  [        [        SUS-   5      5      [        S U 5       5      5        g)at  
Verify that when more than C{limit} events are logged to L{LogBeginner},
only the last C{limit} are replayed by L{LogBeginner.beginLoggingTo}.

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

@raise: C{self.failureException} if the wrong events are replayed by
    C{beginner}.
r`   )Úcountc              3   ó*   #   • U  H	  oS    v •  M     g7f)r~   Nr4   )Ú.0r   s     r$   Ú	<genexpr>Ú4LogBeginnerTests._bufferLimitTest.<locals>.<genexpr>¢   s   é € Ð4ªV E�w–ªVùs   ‚N)	ÚrangerV   ro   rp   r
   r   rN   r)   Úlist)rD   r|   r\   r~   Úeventss        r$   Ú_bufferLimitTestÚ!LogBeginnerTests._bufferLimitTest�   sx   € ô ˜5 1™9Ö%ˆEØ�N‰Nœ4 eÑ,Ö-ñ &à!#ˆØ×Ñ¤¤l°F·M±MÓ!BÐ CÔDØ×ÑÜ”�q˜% !™)Ó$Ó%ÜÑ4©VÓ4Ó4õ	
r'   c                 óZ   • [         R                  nU R                  XR                  5        g)zp
Up to C{LogBeginner._DEFAULT_BUFFER_SIZE} log events are buffered for
replay by L{LogBeginner.beginLoggingTo}.
N)r   Ú_DEFAULT_BUFFER_SIZEr†   r\   )rD   r|   s     r$   Útest_defaultBufferLimitÚ(LogBeginnerTests.test_defaultBufferLimit¥   s!   € ô
 ×0Ñ0ˆØ×Ñ˜e§]¡]Õ3r'   c                 ó”   • Sn[        U R                  U R                  U R                  U R                  US9nU R                  X5        g)zr
The size of the L{LogBeginner} event buffer can be overridden with the
C{initialBufferSize} initilizer argument.
é   )ÚinitialBufferSizeN)r   rV   rY   rZ   r[   r†   )rD   r|   r\   s      r$   Útest_overrideBufferLimitÚ)LogBeginnerTests.test_overrideBufferLimit­   sF   € ð
 ˆÜØ�N‰NØ×ÑØ�N‰NØ×ÑØ#ñ
ˆð 	×Ñ˜eÕ.r'   c                 ó(  • / n/ n[         R                  " 5       n[        U5      nU R                  [	        SS95        [        5       u  pVU R                  R                  [        [        UR                  5      U/5        U R                  [	        SS95        [        5       u  pxU R                  R                  [        [        UR                  5      U/5        U R                  [	        SS95        [	        [        [        R                  UUUUS9n	SU l        [        U U[	        SS9[	        SS9U	[	        SS9/5        [        XU	[	        SS9/5        UR!                  5       n
U R#                  SU SU S	3U
5        U R#                  SU SU S	3U
5        g)
zŸ
When invoked twice, L{LogBeginner.beginLoggingTo} will emit a log
message warning the user that they previously began logging, and add
the new log observers.
Ú	prebuffer)r   Ú
postbufferÚpostwarn)Ú
log_formatÚ	log_levelÚfileNowÚlineNowÚfileThenÚlineThenNÚ<Ú:Ú>)rW   rX   r   rV   ro   r   r\   rp   r
   r   rN   r   r   ÚwarnÚmaxDiffr,   ÚgetvalueÚassertIn)rD   rh   rn   Ú
fileHandleÚtextObserverÚfirstFilenameÚ	firstLineÚsecondFilenameÚ
secondLineÚwarningÚoutputs              r$   Útest_beginLoggingToTwiceÚ)LogBeginnerTests.test_beginLoggingToTwice¼   sd  € ð #%ˆØ"$ˆÜ—[’[“]ˆ
Ü*¨:Ó6ˆØ�‰”t +Ñ.Ô/Ü#+£:Ñ ˆØ�‰×$Ñ$¤d¬<¸¿¹Ó&HÈ,Ð%WÔXØ�‰”t ,Ñ/Ô0Ü%-£ZÑ"ˆØ�‰×$Ñ$¤d¬<¸¿¹Ó&HÈ,Ð%WÔXØ�‰”t *Ñ-Ô.ÜÜ-Ü—m‘mØ"ØØ"Øñ
ˆð ˆŒÜØØä˜;Ñ'Ü˜<Ñ(ØÜ˜:Ñ&ð	ô		
ô 	�d g¬t¸*Ñ/EÐ%FÔGà×$Ñ$Ó&ˆØ�‰˜˜-˜¨¨)¨°AÐ6¸Ô?Ø�‰˜˜.Ð)¨¨:¨,°aÐ8¸&ÕAr'   c                 óÀ   • [        U R                  S9nUR                  S5        UR                  SSS9  U R	                  U R
                  R                  5       S5        g)z@
Critical messages will be written as text to the error stream.
©Úobserverzignore thisza critical {message}rG   )rG   za critical message
N)r   rV   ÚinfoÚcriticalr)   rY   r    ©rD   Úlogs     r$   Útest_criticalLoggingÚ%LogBeginnerTests.test_criticalLoggingç   sO   € ô ˜dŸn™nÑ-ˆØ�‰�ÔØ�‰Ð+°YˆÑ?Ø×Ñ˜×)Ñ)×2Ñ2Ó4Ð6LÕMr'   c                 óÖ   • [        U R                  S9nU R                  R                  S5        UR	                  S5        U R                  U R                  R                  5       S5        g)zn
Once logging has begun with C{beginLoggingTo}, critical messages are no
longer written to the output stream.
r­   r4   zanother critical messageÚ N)r   rV   r\   rp   r°   r)   rY   r    r±   s     r$   Útest_criticalLoggingStopsÚ*LogBeginnerTests.test_criticalLoggingStopsð   sP   € ô
 ˜dŸn™nÑ-ˆØ�‰×$Ñ$ RÔ(Ø�‰Ð/Ô0Ø×Ñ˜×)Ñ)×2Ñ2Ó4°bÕ9r'   c           	      ó~  • / nU R                   R                  [        [        UR                  5      /5        [        S[        [        U R                  R                  5      S9  [        X[        SSS9/5        USS2	 [        S[        [        U R                  R                  5      S9  [        X[        SSS9/5        g)zŸ
L{LogBeginner.beginLoggingTo} will re-direct the standard output and
error streams by setting the C{stdio} and C{stderr} attributes on its
sys module object.
zHello, world.©rK   r:   )Úlog_namespaceÚlog_ioNzError, world.r;   )r\   rp   r
   r   rN   Úprintr   rZ   r:   r,   ro   r;   )rD   r…   s     r$   Ú%test_beginLoggingToRedirectStandardIOÚ6LogBeginnerTests.test_beginLoggingToRedirectStandardIOú   s–   € ð "$ˆØ�‰×$Ñ$¤d¬<¸¿¹Ó&GÐ%HÔIÜˆo¤D¬°·±×1FÑ1FÓ$GÒHÜØœ4¨h¸ÑOÐPô	
ð ’1ˆIÜˆo¤D¬°·±×1FÑ1FÓ$GÒHÜØœ4¨h¸ÑOÐPõ	
r'   c                 ó(  • U R                   R                  nU R                   R                  nU R                  R	                  SSS9  U R                  U R                   R                  U5        U R                  U R                   R                  U5        g)zw
L{LogBeginner.beginLoggingTo} will leave the existing stdout/stderr in
place if it has been told not to replace them.
r4   F)ÚredirectStandardION)rZ   r:   r;   r\   rp   ÚassertIs)rD   ÚoldOutÚoldErrs      r$   Útest_beginLoggingToDontRedirectÚ0LogBeginnerTests.test_beginLoggingToDontRedirect  si   € ð
 —‘×&Ñ&ˆØ—‘×&Ñ&ˆØ�‰×$Ñ$ R¸EÐ$ÑBØ�‰�d—n‘n×+Ñ+¨VÔ4Ø�‰�d—n‘n×+Ñ+¨VÕ4r'   c           	      óÔ  • [         R                  " [         R                  " 5       S5      n[         R                  " [         R                  " 5       S5      nXR                  l        X R                  l        / nU R                  R                  [        [        UR                  5      /5        [        [        U R                  R                  5      n[        [        U R                  R
                  5      nU R                  UR                  S5        U R                  UR                  S5        UR                  S5        UR                  S5        [        X[!        SS9[!        SS9/5        g)	zÖ
When L{LogBeginner.beginLoggingTo} redirects stdout/stderr streams, the
replacement streams will preserve the encoding of the replaced streams,
to minimally disrupt any application relying on a specific encoding.
z	shift-JISÚbig5s   —›
s   ¼ü
u   æ�Ž)r¼   u   ç‘©N)rW   ÚTextIOWrapperÚBytesIOrZ   r:   r;   r\   rp   r
   r   rN   r   r)   ÚencodingÚwriter,   ro   )rD   ÚweirdÚweirderrr…   r:   r;   s         r$   Ú$test_beginLoggingToPreservesEncodingÚ5LogBeginnerTests.test_beginLoggingToPreservesEncoding  sò   € ô × Ò ¤§¢£¨{Ó;ˆÜ×#Ò#¤B§J¢J£L°&Ó9ˆà %�‰ÔØ (�‰Ôà!#ˆØ�‰×$Ñ$¤d¬<¸¿¹Ó&GÐ%HÔIÜ”f˜dŸn™n×3Ñ3Ó4ˆÜ”f˜dŸn™n×3Ñ3Ó4ˆØ×Ñ˜Ÿ™¨+Ô6Ø×Ñ˜Ÿ™¨&Ô1à�‰�]Ô#Ø�‰�]Ô#Ü�d¤T°Ñ%:¼DÈÑ<QÐ$RÕSr'   c                 ó€  • U R                   R                  S[        [        S5        / nU R                  R                  [        [        UR                  5      /5        U R                   R                  S[        [        S5        [        R                  " 5       nU R                   R                  S[        [        SUS9  U R                  U R                   R                  S[        [        SSS4S[        [        SUS4/5        [        U U[        S[        R                  S	-   [        R                   -   [        SS
9/5        g)zj
L{LogBeginner.beginLoggingTo} will redirect the warnings of its
warnings module into the logging system.
z	a messager`   zanother messager   zyet anotherr�   rº   NÚ.)r¨   rH   rI   rJ   )r[   rO   ÚDeprecationWarningÚ__file__r\   rp   r
   r   rN   rW   rX   r)   rC   r,   ro   r6   r5   )rD   r…   Úfs      r$   Útest_warningsModuleÚ$LogBeginnerTests.test_warningsModule/  s"  € ð
 	×Ñ×'Ñ'¨Ô5GÌÐSTÔUØ!#ˆØ�‰×$Ñ$¤d¬<¸¿¹Ó&GÐ%HÔIØ×Ñ×'Ñ'ØÔ1´8¸Qô	
ô �KŠK‹MˆØ×Ñ×'Ñ'ØÔ-¬x¸Àð 	(ñ 	
ð 	×ÑØ×Ñ×(Ñ(àÔ0´(¸A¸tÀTÐJØÔ 2´H¸aÀÀDÐIðô	
ô 	ØØäØ-ä*×5Ñ5Øñä,×5Ñ5ñ6ô &Øñ	ðõ	
r'   c                 ó  • [        [        S5      5      n[        U R                  S9nUR	                  SUS9  U R
                  R                  5       nU R                  SU5        U R                  SU5        U R                  SU5        g)zB
The string resulting from a logged failure contains a traceback.
z,this is not the behavior you are looking forr­   z	a failure)ÚfailureÚ	TracebackN)r   Ú	Exceptionr   rV   rÙ   rY   r    r¡   )rD   rÕ   r²   Úmsgs       r$   Útest_failuresAppendTracebacksÚ.LogBeginnerTests.test_failuresAppendTracebacksV  sq   € ô ”IÐLÓMÓNˆÜ˜dŸn™nÑ-ˆØ�‰�K¨ˆÑ+Ø×Ñ×'Ñ'Ó)ˆØ�‰�k 3Ô'Ø�‰ÐDÀcÔJØ�‰�k 3Õ'r'   )r\   rY   rŸ   rV   rZ   r[   rQ   )r5   r6   r7   r8   Ú__doc__r]   rt   rz   rT   r   r†   rŠ   r�   rª   r³   r·   r¾   rÅ   rÏ   rÖ   rÝ   r<   r4   r'   r$   r.   r.   5   sh   † ñô/
ôb+ô$+ð&
 cð 
°[ð 
ÀTô 
ô*4ô/ô)BôVNô:ô
ô$	5ôTô0%
÷N
(r'   r.   )"rß   rW   Útypingr   r   r   r   r   r   r	   r
   Útwisted.python.failurer   Útwisted.trialr   Ú_filer   Ú_globalr   r   Ú_interfacesr   r   Ú_levelsr   Ú_loggerr   Ú	_observerr   Útest.test_stdlibr   ÚTestCaser,   r.   r4   r'   r$   Ú<module>rë      s~   ðñó 
ß E× EÓ Eå *Ý "Ý 'ß 9ß 0Ý Ý Ý $Ý 'ð7Ø
×
Ñ
ð7à�x‘.ð7ð ˜‘Nð7ð 
ô	7ô>k(�x×(Ñ(õ k(r'   