
    [4%e%                     <   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
mZ d dlmZmZmZ d dlmZ d dlmZ e j        d             Z G d dej                  Z G d	 d
e          Z G d dej                  Z G d dej                  ZdS )    N)utf8)LogFormatterdefine_logging_optionsenable_pretty_logging)OptionParser)basestring_typec               #      K   t          j                    5  t          j        dt                     d V  d d d            d S # 1 swxY w Y   d S )Nignore)category)warningscatch_warningssimplefilterBytesWarning     5lib/python3.11/site-packages/tornado/test/log_test.pyignore_bytes_warningr       s      		 	"	"  h>>>>                 s    AA
Ac                   ^    e Zd Z ej        d          Zd Zd Zd Zd Z	d Z
d Zd Zd	 Zd
S )LogFormatterTestsD   (?s)\[E [0-9]{6} [0-9]{2}:[0-9]{2}:[0-9]{2} log_test:[0-9]+\] (.*)c                     t          d          | _        t          j        di| j        _        d| j        _        t          j        d          | _        d| j        _        t          j
                    | _        t          j                            | j        d          | _        |                     | j                  | _        | j                            | j                   | j                            | j                   d S )NF)colorr   zlog.out)r   	formatterloggingERROR_colors_normalLoggerlogger	propagatetempfilemkdtemptempdirospathjoinfilenamemake_handlerhandlersetFormatter
addHandlerselfs    r   setUpzLogFormatterTest.setUp.   s    %E222
 #*-!:!)n%788 %'))T\9==((77!!$.111t|,,,,,r   c                     | j                                          t          j        | j                   t          j        | j                   d S N)r*   closer%   unlinkr(   rmdirr$   r-   s    r   tearDownzLogFormatterTest.tearDown?   s@    
	$-   
r   c                 *    t          j        |          S r1   r   FileHandlerr.   r(   s     r   r)   zLogFormatterTest.make_handlerD   s    
 "8,,,r   c                 <   t          | j        d          5 }|                                                                }t          j                            |          }|r!|                    d          cd d d            S t          d|z            # 1 swxY w Y   d S )Nrb   zoutput didn't match regex: %r)	openr(   readstripr   LINE_REmatchgroup	Exception)r.   flinems       r   
get_outputzLogFormatterTest.get_outputK   s    $-&& 	H!6688>>##D (..t44A Hwwqzz		H 	H 	H 	H 	H 	H 	H 	H   ?$ FGGG	H 	H 	H 	H 	H 	H 	H 	H 	H 	Hs   AB?BBBc                     | j                             d           |                     |                                 d           d S )Nfoos   foo)r    errorassertEqualrG   r-   s    r   test_basic_loggingz#LogFormatterTest.test_basic_loggingT   s>    %   **F33333r   c           	         t                      5  | j                            d           |                     |                                 t          t          d                               d d d            d S # 1 swxY w Y   d S )N   )r   r    rJ   rK   rG   r   reprr-   s    r   test_bytes_loggingz#LogFormatterTest.test_bytes_loggingX   s    !## 	E 	EKg&&&T__..T']]0C0CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	Es   AA99A= A=c           
         t                      5  | j                            d                    d                     d d d            n# 1 swxY w Y   t	          t
          t                    r7|                     |                                 t          d                     d S |                     |                                 t          t          t          d                                         d S )N   ér   )r   r    rJ   encode
issubclassbytesr   rK   rG   r   rO   r-   s    r   test_utf8_loggingz"LogFormatterTest.test_utf8_logging^   s   !## 	7 	7Khoof55666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7e_-- 	L T__..X?????
 T__..T$x..5I5I0J0JKKKKKs   .A		AAc                     	 t          d          # t           $ r | j                            d           Y nw xY w|                                 }|                     |d           |                     d|           d S )NrN   zcaught exceptions   Exception.*\\xe9s   \n)rC   r    	exceptionrG   assertRegexassertNotIn)r.   outputs     r   test_bytes_exception_loggingz-LogFormatterTest.test_bytes_exception_loggingk   s    	6G$$$ 	6 	6 	6K!!"455555	6 ""!5666(((((s    $88N)__name__
__module____qualname__recompiler@   r/   r5   r)   rG   rL   rP   rV   r\   r   r   r   r   r   '   s         bjW G- - -"  
- - -H H H4 4 4E E EL L L
) 
) 
) 
) 
)r   r   c                       e Zd Zd Zd ZdS )UnicodeLogFormatterTestc                 .    t          j        |d          S )Nr   )encodingr7   r9   s     r   r)   z$UnicodeLogFormatterTest.make_handlery   s     "8f====r   c                     | j                             d           |                     |                                 t	          d                     d S )NrR   )r    rJ   rK   rG   r   r-   s    r   test_unicode_loggingz,UnicodeLogFormatterTest.test_unicode_logging   sD    (###**DNN;;;;;r   N)r]   r^   r_   r)   rg   r   r   r   rc   rc   x   s2        > > >< < < < <r   rc   c                   0     e Zd Z fdZd Zd Zd Z xZS )EnablePrettyLoggingTestc                     t                                                       t                      | _        t	          | j                   t          j        d          | _        d| j        _        d S )Nz-tornado.test.log_test.EnablePrettyLoggingTestF)	superr/   r   optionsr   r   r   r    r!   )r.   	__class__s    r   r/   zEnablePrettyLoggingTest.setUp   sQ    #~~t|,,,n%TUU %r   c                 d   t          j                    }	 |dz   | j        _        t	          | j        | j                   |                     dt          | j        j                             | j        	                    d           | j        j        d         
                                 t          j        |dz             }|                     dt          |                     t          |d                   5 }|                     |                                d           d d d            n# 1 swxY w Y   | j        j        D ]*}|
                                 |                                 +t          j        |dz             D ]}t!          j        |           t!          j        |           d S # | j        j        D ]*}|
                                 |                                 +t          j        |dz             D ]}t!          j        |           t!          j        |           w xY w)N	/test_logrl   r    r<   hellor   
/test_log*^\[E [^]]*\] hello$)r"   r#   rl   log_file_prefixr   r    rK   lenhandlersrJ   flushglobr=   rY   r>   r2   r%   r3   r4   r.   tmpdir	filenamesrD   r*   r(   s         r   test_log_filez%EnablePrettyLoggingTest.test_log_file   sF   !##	+1K+?DL(!$,t{KKKKQDK$8 9 9:::Kg&&&K #))+++	&<"788IQI///il## Cq  +ABBBC C C C C C C C C C C C C C C  ;/     If|&;<< $ $	(####HV  ;/     If|&;<< $ $	(####HVs1   C$F4 9)D."F4 .D22F4 5D26F4 4A;H/c                 "   t          j                    }	 |dz   | j        _        d| j        _        t          | j        | j                   | j                            d           | j        j        d         	                                 t          j
        |dz             }|                     dt          |                     t          |d                   5 }|                     |                                d           d d d            n# 1 swxY w Y   | j        j        D ]*}|	                                 |                                 +t          j
        |dz             D ]}t#          j        |           t#          j        |           d S # | j        j        D ]*}|	                                 |                                 +t          j
        |dz             D ]}t#          j        |           t#          j        |           w xY w)	Nro   timerp   rq   r   rr   r<   rs   )r"   r#   rl   rt   log_rotate_moder   r    rJ   rv   rw   rx   rK   ru   r=   rY   r>   r2   r%   r3   r4   ry   s         r   !test_log_file_with_timed_rotatingz9EnablePrettyLoggingTest.test_log_file_with_timed_rotating   s-   !##	+1K+?DL(+1DL(!$,t{KKKKKg&&&K #))+++	&<"788IQI///il## Cq  +ABBBC C C C C C C C C C C C C C C  ;/     If|&;<< $ $	(####HV  ;/     If|&;<< $ $	(####HVs1   CF )DF DF DF A;Hc                 x   	 d| j         _        d| j         _        |                     t          t
          | j         | j                   | j        j        D ]*}|                                 |	                                 +d S # | j        j        D ]*}|                                 |	                                 +w xY w)N	some_path
wrong_moderp   )
rl   rt   r   assertRaises
ValueErrorr   r    rv   rw   r2   )r.   r*   s     r   test_wrong_rotate_mode_valuez4EnablePrettyLoggingTest.test_wrong_rotate_mode_value   s    	 +6DL(+7DL(%{	      ;/       4;/     s   AB   9B9)r]   r^   r_   r/   r|   r   r   __classcell__)rm   s   @r   ri   ri      se        & & & & &  (  (             r   ri   c                   D    e Zd ZdZddZd Zd Zd Zd Zd Z	d	 Z
d
 ZdS )LoggingOptionTestz?Test the ability to enable and disable Tornado's logging hooks.Nc                 (   d}d}d                     |||g          }t          j        t          j        d|g|pg z   t          j        t          j                  }|                                \  }}|                     |j	        dd|z             d|v S )	Nz7from tornado.options import options, parse_command_linez%import logging; logging.info("hello");z-c)stdoutstderrr   zprocess failed: %rs   hello)
r'   
subprocessPopensys
executablePIPESTDOUTcommunicaterK   
returncode)	r.   	statementargsIMPORTLOG_INFOprogramprocr   r   s	            r   logs_presentzLoggingOptionTest.logs_present   s     K:((FIx899^T7+tzr:?$
 
 

 ))++!-AF-JKKK6!!r   c                 V    |                      |                     d                     d S )NpassassertFalser   r-   s    r   test_defaultzLoggingOptionTest.test_default   s*    **62233333r   c                 V    |                      |                     d                     d S )Nparse_command_line()
assertTruer   r-   s    r   test_tornado_defaultz&LoggingOptionTest.test_tornado_default   s)    ))*@AABBBBBr   c                 Z    |                      |                     ddg                     d S )Nr   z--logging=noner   r-   s    r   test_disable_command_linez+LoggingOptionTest.test_disable_command_line   1    **+ADTCUVVWWWWWr   c                 Z    |                      |                     ddg                     d S )Nr   z--logging=Noner   r-   s    r   *test_disable_command_line_case_insensitivez<LoggingOptionTest.test_disable_command_line_case_insensitive   r   r   c                 V    |                      |                     d                     d S )Nz.options.logging = "none"; parse_command_line()r   r-   s    r   test_disable_code_stringz*LoggingOptionTest.test_disable_code_string   s6    NOO	
 	
 	
 	
 	
r   c                 V    |                      |                     d                     d S )N,options.logging = None; parse_command_line()r   r-   s    r   test_disable_code_nonez(LoggingOptionTest.test_disable_code_none   s6    LMM	
 	
 	
 	
 	
r   c                 Z    |                      |                     ddg                     d S )Nr   z--logging=infor   r-   s    r   test_disable_overridez'LoggingOptionTest.test_disable_override   s>    >AQ@R 	
 	
 	
 	
 	
r   r1   )r]   r^   r_   __doc__r   r   r   r   r   r   r   r   r   r   r   r   r      s        II" " " "$4 4 4C C CX X XX X X
 
 


 
 


 
 
 
 
r   r   )
contextlibrx   r   r%   r`   r   r   r"   unittestr   tornado.escaper   tornado.logr   r   r   tornado.optionsr   tornado.utilr   contextmanagerr   TestCaser   rc   ri   r   r   r   r   <module>r      s         				 				     



          S S S S S S S S S S ( ( ( ( ( ( ( ( ( ( ( (   N) N) N) N) N)x( N) N) N)b	< 	< 	< 	< 	<. 	< 	< 	<=  =  =  =  = h/ =  =  = @1
 1
 1
 1
 1
) 1
 1
 1
 1
 1
r   