
    <e#                    b   d 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
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ZddlZddlmZmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dd	l m!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)m*Z* ddl+m,Z,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2  ej3        d          Z4 ej3        d          Z5	 ddl6Z6ddl7Z7ddl8Z8n# e9$ r	 dxZ6xZ7Z8Y nw xY w	 ddl:Z:n# e9$ r Y nw xY w G d de%j;                  Z< G d de<          Z= G d de<          Z>dZ?dZ@dZAdZBdZCdZDdZEdZFdZGdZH eIeHe?dz             ZJe?d e@d!eAd"eBd#eCd$eDd%eEd&eFd'eGd(eHd)i
ZK G d* d+ejL                  ZM G d, d-ejL                  ZN G d. d/e<          ZO G d0 d1e<          ZP G d2 d3eQ          ZR G d4 d5ejS                  ZT G d6 d7eQ          ZU G d8 d9e<          ZV G d: d;e5jW                  ZX G d< d=eQ          ZY G d> d?eYe)          ZZ G d@ dAeYe1          Z[ G dB dCeYe/          Z\ e]edD          r G dE dFe[          Z^ G dG dHe\          Z_ ej`                     eja                     G dI dJe<                                  Zb G dK dLe<          Zc G dM dNejd                  Ze G dO dPe<          Zf ej`                     eja                     G dQ dRe<                                  ZgdS Zh e%ji         e]edD          dT           G dU dVeg                      Zj ej`                     eja                     G dW dXe<                                  Zk e%ji         e]edD          dT           G dY dZek                      Zl ej`                     eja                     G d[ d\e<                                  Zm e%ji         e]edD          dT           G d] d^em                      Zn e%ji        ejo        d_           G d` daem                      Zp ej`                     eja                     G db dce<                                  Zq G dd dee<          Zr G df dge<          Zs G dh die<          ZtddjZu G dk dl          Zvdm Zw G dn doejS                  Zx G dp dqe<          Zy G dr dse<          Zz G dt due<          Z{ G dv dwej|                  Z} G dx dye<          Z~ eja                     G dz d{e<                      Z e]ej        d|          r-ddlZdd}lmZ  eja                     G d~ de<                      Z ej        d          Z G d dej                  Z e            Z G d d          Z G d de%j;        e          Z G d dej                  Z G d de%j;                  Z G d de<          Z G d de<          Z G d d          Z G d dej                  Z G d de<          Z G d de<          Z G d de<          Z G d de%j;                  Z G d de%j;                  Z G d de<e          Z G d de<          Z G d de          Z G d de          Z G d de          Zd Zdddddd edd          ffD ]\  ZZeefdZ eedez  e            e%ji        e6d           G d de<                      Z G d de%j;                  Zd Zedk    r e%j                     dS dS )zoTest harness for the logging module. Run all tests.

Copyright (C) 2001-2022 Vinay Sajip. All Rights Reserved.
    N)assert_python_okassert_python_failure)support)	os_helper)socket_helper)threading_helper)warnings_helper)TestHandler)
HTTPServerBaseHTTPRequestHandler)urlparseparse_qs)ThreadingUDPServerDatagramRequestHandlerThreadingTCPServerStreamRequestHandlerasyncoresmtpdc                   8    e Zd ZdZdZdZdZd Zd Zd
dZ	d	 Z
dS )BaseTestzBase class for logging tests.z&%(name)s -> %(levelname)s: %(message)sz^([\w.]+) -> (\w+): (\d+)$r   c                 z   t          j                    | _        t          j                    j        j        }t          j                     	 t          j        	                                | _
        t          j        dd         | _        |	                                x| _        }t          j        	                                | _        t          j        	                                | _        i x| _        }|D ]}t'          ||         dd          ||<   	 t          j                     n# t          j                     w xY wt          j        d          | _        t          j        d          | _        t          j        d          | _        | j                                        | _        t5          j                    | _        | j                            t          j                   t          j        | j                  | _         t          j!        | j"                  | _#        | j         $                    | j#                   | j        %                                r+| j        j&        | j        j&        z   }tO          d|z            | j        %                                r+| j        j&        | j        j&        z   }tO          d|z            | j        (                    | j                    | )                    | j        %                                           | )                    | j        %                                           dS )zxSetup the default logging stream to an internal StringIO instance,
        so that we can examine log output as we want.Ndisabledu   «×»u   ĿÖG zUnexpected handlers: %s)*r   threading_setup_threading_keylogging	getLoggermanager
loggerDict_acquireLock	_handlerscopysaved_handlers_handlerListsaved_handler_listsaved_loggers_nameToLevelsaved_name_to_level_levelToNamesaved_level_to_namelogger_statesgetattr_releaseLocklogger1logger2root_loggergetEffectiveLeveloriginal_logging_levelioStringIOstreamsetLevelDEBUGStreamHandler	root_hdlr	Formatter
log_formatroot_formattersetFormatterhasHandlershandlersAssertionError
addHandler
assertTrue)selflogger_dictr&   r+   namehlists         (/usr/lib/python3.11/test/test_logging.pysetUpzBaseTest.setUpW   s    />@@'))1<	#")"3"8"8":":D&-&:111&=D#1<1A1A1C1CCD'.';'@'@'B'BD$'.';'@'@'B'BD$133D% @ @&-mD.A.8$'@ '@d##@  """"G """" (88()=>>",R00&*&6&H&H&J&J#kmm!!'-000 .t{;;%/@@##D$7888<##%% 	DL)D,<,EEE !:U!BCCC<##%% 	DL)D,<,EEE !:U!BCCC##DN3330022333002233333s   
CD$ $D9c                    | j                                          | j                            | j                   | j        j        rL| j        j        d         }| j                            |           |                                 | j        j        L| j                            | j                   t          j	                     	 t          j
                                         t          j
                            | j                   t          j                                         t          j                            | j                   t          j                                         t          j                            | j                   | j        t          j        dd<   t          j                    j        }d|_        |j        }|                                 |                    | j                   | j        }| j        D ]"}||         ||         | j        |         _        #	 t          j                     n# t          j                     w xY w|                                  t;          j        | j          dS )zJRemove our logging stream, and restore the original logging
        level.r   N) r5   closer0   removeHandlerr9   r?   r6   r2   r   r    r)   clearupdater*   r'   r(   r!   r#   r%   r$   r   r   disabler   r&   r+   r   r-   
doCleanupsr   threading_cleanupr   )rC   hr   r   r+   rE   s         rG   tearDownzBaseTest.tearDown   s0    	&&t~666' 	 )!,A**1---GGIII ' 	 	!!$"=>>>	# &&((( ''(@AAA &&((( ''(@AAA##%%%$$T%8999&*&=G #'))1GGO +Jd0111 .M* L L &28Ed8KD&t,5L  """"G """"*D,?@@@@s   E!H: :INc                 N   |p| j         }t          j        |p| j                  }|                                                                }|                     t          |          t          |                     t          ||          D ]i\  }}|	                    |          }|s| 
                    d|z              |                     t          |                                          |           j|                                }|r| 
                    d|z              dS dS )zMatch the collected log lines against the regular expression
        self.expected_log_pat, and compare the extracted group values to
        the expected_values list of tuples.z*Log line does not match expected pattern:
z'Remaining output at end of log stream:
N)r5   recompileexpected_log_patgetvalue
splitlinesassertEquallenzipsearchfailtuplegroupsread)	rC   expected_valuesr5   patactual_linesactualexpectedmatchss	            rG   assert_log_lineszBaseTest.assert_log_lines   s)    &4;j5 566((3355\**C,@,@AAA #L/ B B 	> 	>FHJJv&&E $		G"# $ $ $U5<<>>22H====KKMM 	FII@1DEEEEE	F 	F    c                 6    | xj         dz  c_         d| j         z  S )zMGenerate a message consisting solely of an auto-incrementing
        integer.   z%d)message_numrC   s    rG   next_messagezBaseTest.next_message   s&     	Ad&&&ri   NN)__name__
__module____qualname____doc__r;   rV   rl   rH   rR   rh   rn    ri   rG   r   r   O   st        ''9J4K(4 (4 (4T A  A  ADF F F F$' ' ' ' 'ri   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
BuiltinLevelsTestz*Test builtin levels and their inheritance.c                 B   | j         }t          j        d          }|                    t          j                   t          j        t          j        d          i           }|                    t          j                   t          j        d          }|                    t          j                   |                    t          j	         |                       |
                     |                       |                    t          j	         |                       |
                     |                       |                     |                       |                     |                       |                    t          j	         |                       |
                     |                       |                     |                       |                     |                       |                     |                       |                     |                       |                     |                       |                     |                       |                     |                       |                     g d           d S )NERRINFDEB))rx   CRITICAL1)rx   ERROR2)ry   r{   3)ry   r}   4)ry   WARNING5)ry   INFO6)rz   r{   7)rz   r}   8)rz   r   9)rz   r   10)rz   r7   11)rn   r   r   r6   r}   LoggerAdapterr   r7   logr{   errorwarninginfodebugrh   )rC   mrx   ry   rz   s        rG   	test_flatzBuiltinLevelsTest.test_flat   s   &&W]####G$5e$<$<bAAW\"""&&W]### 	 !!##&&&		!!## !!##&&&		!!##AACC !!##&&&		!!##AACC		!!## 	AACC		!!##		!!## 
 
 
 	 	 	 	 	ri   c                 F   | j         }t          j        d          }|                    t          j                   t          j        d          }|                    t          j                   |                    t          j         |                       |                     |                       |	                     |                       |
                     |                       |                     |                       |                     ddg           d S )Nry   INF.ERR)r   r{   r|   )r   r}   r~   rn   r   r   r6   r   r}   r   r{   r   r   r   r   rh   )rC   r   ry   INF_ERRs       rG   test_nested_explicitz&BuiltinLevelsTest.test_nested_explicit   s   &&W\"""$Y//''' 	G$aacc***aacc 	QQSSaacc(%
 	 	 	 	 	ri   c                    | j         }t          j        d          }|                    t          j                   t          j        d          }|                    t          j                   t          j        d          }t          j        d          }t          j        d          }|                    t          j         |                       |                     |                       |	                     |                       |
                     |                       |                    t          j         |                       |                     |                       |                     |                       |	                     |                       |
                     |                       |                     |                       |                     g d           d S )Nry   r   	INF.UNDEFINF.ERR.UNDEFUNDEF))r   r{   r|   )r   r}   r~   )r   r   r   )r   r   r   )r   r{   r   )r   r}   r   r   )rC   r   ry   r   	INF_UNDEFINF_ERR_UNDEFr   s          rG   test_nested_inheritedz'BuiltinLevelsTest.test_nested_inherited  s   &&W\"""$Y//'''%k22	)/::!'** 	g&,,,!!##qqss'*AACC000AACC    	aacc"""1133AACC    
 
 
 	 	 	 	 	ri   c                    | j         }t          j        d          }t          j        d          }t          j        d          }|                    t          j                   |                    t          j         |                       |                     |                       |                    t          j         |                       |                     |                       |                     |                       |                     |                       | 	                    g d           d S )Nry   INF.BADPARENT.UNDEFINF.BADPARENT))r   r{   r|   )r   r   r~   )r   r{   r   )r   r   r   )
rn   r   r   r6   r   r   FATALr   r   rh   )rC   r   ry   
GRANDCHILDCHILDs        rG   test_nested_with_virtual_parentz1BuiltinLevelsTest.test_nested_with_virtual_parent(  s   &&&'<==
!/22W\""" 	w}aacc***		'-%%%

1133 	AACC 
 
 
 	 	 	 	 	ri   c                     |                      t          j        d          t          j                   |                      t          j        t          j                  d           dS )z&See issue #22386 for more information.r   N)rY   r   getLevelNamer   rm   s    rG   test_regression_22386z'BuiltinLevelsTest.test_regression_22386B  sN    -f55w|DDD-gl;;VDDDDDri   c                 n    t          j        d          }|                     |t           j                   d S )Nr   )r   r   rY   r   )rC   fatals     rG   test_issue27935z!BuiltinLevelsTest.test_issue27935G  s0    $W--.....ri   c                    t          j        t           j        d           |                     t           j        t           j        d           |                     t          j        t           j                  d           |                     t          j        t           j                  d           |                     t          j        d          t           j                   dS )z&See issue #29220 for more information.r   r   NOTSETN)r   addLevelNamer   
addCleanuprY   r   r   rm   s    rG   test_regression_29220z'BuiltinLevelsTest.test_regression_29220K  s    W\2...,glFCCC-gl;;R@@@-gn==xHHH-h77HHHHHri   N)rp   rq   rr   rs   r   r   r   r   r   r   r   rt   ri   rG   rv   rv      s        44- - -^  .! ! !F  4E E E
/ / /I I I I Iri   rv   c                   $    e Zd ZdZd Zd Zd ZdS )BasicFilterTestzTest the bundled Filter class.c                    t          j        d          }| j        j        d         }	 |                    |           t          j        d          }t          j        d          }t          j        d          }t          j        d          }|                    |                                            |                    |                                            |                    |                                            |                    |                                            |                     ddg           |	                    |           d S # |	                    |           w xY w)N	spam.eggsr   spamspam.eggs.fishspam.bakedbeansr   r   r~   r   r   r   )
r   Filterr0   r?   	addFilterr   r   rn   rh   removeFilter)rC   filter_handlerr   	spam_eggsspam_eggs_fishspam_bakedbeanss          rG   test_filterzBasicFilterTest.test_filterW  sS    .--"+A.	*g&&&$V,,D)+66I$./?@@N%/0ABBOIId''))***NN4,,../// 1 1 3 3444  !2!2!4!4555!!*/#   
   )))))G  ))))s   DE E.c                    d }| j         j        d         }	 |                    |           t          j        d          }t          j        d          }t          j        d          }t          j        d          }|                    |                                            |                    |                                            |                    |                                            |                    |                                            |                     ddg           |                    |           d S # |                    |           w xY w)	Nc                 |    | j                             d          }d                    |d d                   }|dk    S )N.   r   )rE   splitjoin)recordpartsprefixs      rG   
filterfuncz8BasicFilterTest.test_callable_filter.<locals>.filterfuncs  s;    K%%c**EXXeBQBi((F[((ri   r   r   r   r   r   r   r   )	r0   r?   r   r   r   r   rn   rh   r   )rC   r   r   r   r   r   r   s          rG   test_callable_filterz$BasicFilterTest.test_callable_filtero  sS   	) 	) 	)
 "+A.	-j)))$V,,D)+66I$./?@@N%/0ABBOIId''))***NN4,,../// 1 1 3 3444  !2!2!4!4555!!*/#   
   ,,,,,G  ,,,,s   DE Ec                     t          j                    }t          j        ddi          }|                     |                    |                     d S )NrE   r   )r   r   makeLogRecordrB   filter)rC   frs      rG   test_empty_filterz!BasicFilterTest.test_empty_filter  sF    N!6;"788$$$$$ri   N)rp   rq   rr   rs   r   r   r   rt   ri   rG   r   r   S  sG        ((* * *0- - -:% % % % %ri   r   x   w   v   u   t   s   r   q   p   o   rk   SilentTaciturnTerseEffusiveSociableVerbose	Talkative	Garrulous
ChatterboxBoringc                       e Zd ZdZd ZdS )GarrulousFilterz)A filter which blocks garrulous messages.c                 "    |j         t          k    S N)levelno	GARRULOUSrC   r   s     rG   r   zGarrulousFilter.filter  s    ~**ri   Nrp   rq   rr   rs   r   rt   ri   rG   r   r     s)        33+ + + + +ri   r   c                       e Zd ZdZd ZdS )VerySpecificFilterz5A filter which blocks sociable and taciturn messages.c                 ,    |j         t          t          fvS r   )r   SOCIABLETACITURNr   s     rG   r   zVerySpecificFilter.filter  s    ~h%999ri   Nr   rt   ri   rG   r   r     s)        ??: : : : :ri   r   c                   4    e Zd ZdZdZd Zd Zd Zd Zd Z	dS )	CustomLevelsAndFiltersTestz@Test various filtering possibilities with custom logging levels.^[\w.]+ -> (\w+): (\d+)$c                     t                               |            t                                          D ]\  }}t	          j        ||           d S r   )r   rH   my_logging_levelsitemsr   r   )rC   kvs      rG   rH   z CustomLevelsAndFiltersTest.setUp  sS    t%++-- 	' 	'DAq A&&&&	' 	'ri   c                 j    t           D ]*}|                    ||                                            +d S r   )LEVEL_RANGEr   rn   )rC   loggerlvls      rG   log_at_all_levelsz,CustomLevelsAndFiltersTest.log_at_all_levels  s>     	1 	1CJJsD--//0000	1 	1ri   c                     | j                             t                     |                     | j                    |                     g d           d S )N)r   r   r   r   r   r   r   r   r   r   r   r   )r0   r6   VERBOSEr   rh   rm   s    rG   test_logger_filterz-CustomLevelsAndFiltersTest.test_logger_filter  sa    !!'***t/000 
 
 
 	 	 	 	 	ri   c                    | j         j        d                             t                     	 |                     | j                    |                     g d           | j         j        d                             t          j                   d S # | j         j        d                             t          j                   w xY w)Nr   )r  r  r  r  r  )r0   r?   r6   r   r   rh   r   r   rm   s    rG   test_handler_filterz.CustomLevelsAndFiltersTest.test_handler_filter  s    !!$--h777	B""4#3444!! # # #    %a(11'.AAAAAD%a(11'.AAAAs   1B 1B?c                 b   | j         j        d         }d }t                      }|                    |           	 |                     | j                    g d}|                     |           t                      }| j                             |           |                     | j                    |                     |g dz              |r| j                             |           |                    |           d S # |r| j                             |           |                    |           w xY w)Nr   )	)r   r|   )r   r~   )r   r   r  r  r  r  r  r  ))r   r   )r   12)r   14)r   15)r   17)r   18)r   20)r0   r?   r   r   r   rh   r   r   )rC   r   specific_filtergarrfirst_liness        rG   test_specific_filtersz0CustomLevelsAndFiltersTest.test_specific_filters  sY    "+A.  $!	'""4#3444  K !!+...022O&&777""4#3444!!+ 
1
 
1
 
1
 
#
 
 
 
  ? --o>>>  &&&&&  ? --o>>>  &&&&s   BC; ;3D.N)
rp   rq   rr   rs   rV   rH   r   r	  r  r  rt   ri   rG   r   r     sp        JJ 3' ' '
1 1 1  B B B (' (' (' (' ('ri   r   c                   "   e Zd Zd Zd Zd Z ej        ej	        dk    d           ej        e
j        d           ej                    d                                     Z e
j                     ej                    d                         Zd	S )
HandlerTestc                     t          j                    }d|_        |                     |j        d           d|_        |                     |j        d           |                     t
          |j        d            d S )Ngenericanothergeneric)r   HandlerrE   rY   assertRaisesNotImplementedErroremitrC   rQ   s     rG   	test_namezHandlerTest.test_name   so    O+++!!1222-qvt<<<<<ri   c                 8   t           j        dv rRdD ]}t          j                    \  }}t	          j        |           |st	          j        |           t          j        	                    |dd          }|r|j
        |j        }}|                     |d           |                     |d           t          j        ddi          }|                    |           t	          j        |           |                     t          j                            |                     |                    |           |                     t          j                            |                     n6|                     |j
        d           |                     |j        d           |                                 |rt	          j        |           t           j        d	k    rd
}nd}	 t          j                            |          }|                     |j        |j                   |                     |j                   |                                 n# t.          $ r Y nw xY wdD ]k}	|	dk    r.|                     t2          t          j        j        dd|	           6t          j                            dd|	          }|                                 lt          j                            d          }t          j        i           }|                     |                    |                     |                                 t          j                            d          }|                     |                    |                     |                                 d S )Nlinuxdarwin)TFutf-8TencodingdelaymsgTestr%  z/var/run/syslogz/dev/log)GETPOSTPUTr/  	localhostz/logr   rk   )sysplatformtempfilemkstemposrJ   unlinkr   r?   WatchedFileHandlerdevinorY   r   handleassertFalsepathexistsrB   SysLogHandlerfacilityLOG_USER
unixsocketOSErrorr  
ValueErrorHTTPHandlerBufferingHandlershouldFlush)
rC   existingfdfnrQ   r8  r9  r   socknamemethods
             rG   test_builtin_handlersz!HandlerTest.test_builtin_handlers(  s%    <...) " "!)++B "IbMMM$77WTX7YY 0 uaeC$$S"---$$S"----ufo>>AHHQKKKIbMMM$$RW^^B%7%7888HHQKKKOOBGNN2$6$67777$$QUB///$$QUB///			 "IbMMM|x'',%$228<<  QZ888---				   , 	 	F!!*g.>.J"-vv? ? ? ? $00ffMM				--a00!"%%a(()))				--a00q))***						s   $A-I 
IIc                 >   t          j                    \  }}t          j        |           t          j        |           t          j        |          }t          j        |dfft          j	        j
        |dfft          j	        j        |dfff}t          j        dv r|t          j	        j        |dfffz  }|D ]g\  }} ||ddi}|                     t          j                            |                     |                                 t          j        |           hdS )zs
        Test that Path objects are accepted as filename arguments to handlers.

        See Issue #27493.
        warQ   r#  r(  r&  N)r3  r4  r5  rJ   r6  pathlibPathr   FileHandlerr?   RotatingFileHandlerTimedRotatingFileHandlerr1  r2  r7  rB   r<  r=  )rC   rH  rI  pfncasesclsargsrQ   s           rG   test_path_objectszHandlerTest.test_path_objects^  s    !##B

	"l2(3*5%9C:F%>c
K
 <...w':S#JGIIE 	 	ICT,G,,AOOBGNN2..///GGIIIIbMMMM		 	ri   ntz/WatchedFileHandler not appropriate for Windows.z'Emscripten cannot fstat unlinked files.c           	      D     fd}d}d}d  _         d  _        dD ]}t          j        dd          \  }}t	          j        |           t          j        |||f          }d|_        |	                                 t          j                            |d|	          }t          j        d
          }	|                    |	           	 t          |          D ]}
t!          j        d           t          j        ddi          }	 t!          j                     _         |                    |           [# t(          $ r! t+          d j        d j                     w xY w	 |                                 |                                 t          j                            |          rt	          j        |           # |                                 |                                 t          j                            |          rt	          j        |           w w xY wd S )Nc                     t          |          D ]j}	 t          j        |            t          j                    _        n# t
          $ r Y nw xY wt          j        dt          j        dd          z             kd S )NgMbp?r      )	ranger5  r6  timedeletion_timerB  sleeprandomrandint)fnametries_rC   s      rG   remove_loopz*HandlerTest.test_race.<locals>.remove_loop|  s    5\\ 9 9Ie$$$)-D&&   D
56>!Q#7#7788889 9s   ,A
AAi  FT.logztest_logging-3-targetrX  Tr&  r'  z'%(asctime)s: %(levelname)s: %(message)s{Gzt?r+  testingzDeleted at z, opened at )handle_timer`  r3  r4  r5  rJ   	threadingThreaddaemonstartr   r?   r7  r:   r=   r^  r_  ra  r   r:  	Exceptionprintr   r<  r=  r6  )rC   rg  	del_count	log_countr)  rH  rI  removerrQ   r   rf  r   s   `           rG   	test_racezHandlerTest.test_raceu  s)   	9 	9 	9 	9 	9 		!" 	" 	"E%f.?@@FBHRLLL&kYPPPG!GNMMOOO 33BPU3VVA!"KLLANN1"y)) 
 
AJu%%%-ui.ABBA+/9;;($   040B0B0B040@0@B C C C 	
 			7>>"%% "IbMMM 			7>>"%% "IbMMMM"1	" 	"s%   	;F?-D32F?3+EF??AHc                 |    G d dt           j                  }|                     t          t           j                  d            |            |                     j        j        j                   d_	        | 
                    t          t           j                  d           | 
                    t          t           j                  d           t          j        d          }|                               |                    t           j                   t!          j                    t!          j                    fd}t!          j        |d	          }|                                                                  t+          j                    }|dk    rE	 |                    d
           t+          j        d           dS # t+          j        d           w xY w|                    d                                            |                                 t7          j        |d           dS )z>Ensure child logging locks are not held; bpo-6721 & bpo-36533.c                   $     e Zd Z fdZd Z xZS )AHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandlerc                     t                                                       t          j        t	          ddd                    | _        d S )Nz	/dev/nullwtr&  r(  r5   )super__init__r   r8   opensub_handlerrC   	__class__s    rG   r  zJHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.__init__  sN      """#*#8TGDDD$F $F $F   ri   c                     | j                                          	 | j                             |           | j                                          d S # | j                                          w xY wr   )r  acquirer  releaser   s     rG   r  zFHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.emit  si     ((***/$))&111$,,.....D$,,....s   A A+rp   rq   rr   r  r  __classcell__r  s   @rG   _OurHandlerr{    sL        F F F F F
/ / / / / / /ri   r  r   z*because we need at least one for this testrk    test_post_fork_child_no_deadlockc                  `   t          j                     	                                  	                                                       d                                            n#                                  w xY w	 t          j                     d S # t          j                     w xY w)N      ?)r   r    r  setwaitr  r-   )+fork_happened__release_locks_and_end_threadlocks_held__ready_to_forkrefed_hs   rG   lock_holder_thread_fnzKHandlerTest.test_post_fork_child_no_deadlock.<locals>.lock_holder_thread_fn  s     """'!!!&-11333 @DDSIIIOO%%%%GOO%%%%%$&&&&&$&&&&s"   B )A) B )A??B B-z,test_post_fork_child_no_deadlock lock holder)rk  rE   z#Child process did not deadlock. \o/z&Parent process returned from fork. \o/)exitcodeN)r   r  rY   rZ   r!   r   r  r5   rJ   rE   assertGreater_at_fork_reinit_lock_weaksetr   rA   r6   r7   ro  Eventrp  rr  r  r5  forkr   _exitr  r   r   wait_process)	rC   r  test_loggerr  lock_holder_threadpidr  r  r  s	         @@@rG   r  z,HandlerTest.test_post_fork_child_no_deadlock  s.   	/ 	/ 	/ 	/ 	/'/ 	/ 	/ 	/ 	W.//333+--+28999C3w01115553wCDDaHHH'(JKKw'''W]+++$-O$5$5!6?o6G6G3	' 	' 	' 	' 	' 	' 	'2 '-,CE E E 	  """!&&(((gii!88  !GHHH FGGG7;;===##%%% q111111s   %G G&N)rp   rq   rr   r!  rL  rY  unittestskipIfr5  rE   r   is_emscriptenr   requires_working_threadingrx  requires_forkr  rt   ri   rG   r  r    s        = = =4 4 4l  . X_RW_&WXXX_H  1022*" *" 32  YX
*"` W0022H2 H2 32 H2 H2 H2ri   r  c                       e Zd Zd ZdS )	BadStreamc                      t          d          )Ndeliberate mistake)RuntimeError)rC   datas     rG   writezBadStream.write  s    /000ri   N)rp   rq   rr   r  rt   ri   rG   r  r    s#        1 1 1 1 1ri   r  c                       e Zd Zd ZdS )TestStreamHandlerc                     || _         d S r   )error_recordr   s     rG   handleErrorzTestStreamHandler.handleError  s    "ri   N)rp   rq   rr   r  rt   ri   rG   r  r    s#        # # # # #ri   r  c                        e Zd Zej        ZdZdS )StreamWithIntNamer   N)rp   rq   rr   r   r   levelrE   rt   ri   rG   r  r    s        NEDDDri   r  c                        e Zd Zd Zd Zd ZdS )StreamHandlerTestc                    t          t                                }t          j        i           }t          j        }	 |                    |           |                     |j        |           t          j        t                                }t          j
                    5 }|                    |           d}|                     ||                                           d d d            n# 1 swxY w Y   dt          _        t          j
                    5 }|                    |           |                     d|                                           d d d            n# 1 swxY w Y   |t          _        d S # |t          _        w xY w)Nz"
RuntimeError: deliberate mistake
Fr   )r  r  r   r   raiseExceptionsr:  assertIsr  r8   r   captured_stderrassertInrW   rY   )rC   rQ   r   	old_raisestderrr+  s         rG   test_error_handlingz%StreamHandlerTest.test_error_handling  s   ikk**!"%%+		0HHQKKKMM!.!,,,%ikk22A(** 6f<c6??#4#45556 6 6 6 6 6 6 6 6 6 6 6 6 6 6
 ',G#(** 8f  V__%6%67778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 '0G###iG#////sU   A#E9  A C, E9 ,C00E9 3C04"E9 >E E9  E$$E9 'E$(E9 9Fc                 f   t          j                    }t          j                    }|                    |          }|                     |t          j                   |                    |          }|                     ||           |                    |          }|                     |           dS )z3
        Test setting the handler's stream
        N)	r   r8   r3   r4   	setStreamr  r1  r  assertIsNone)rC   rQ   r5   oldrd   s        rG   test_stream_settingz%StreamHandlerTest.test_stream_setting  s     !##kk&!!c3:&&&S!!ff%%%S!!&!!!!!ri   c                     t          j        t                                }|                     t	          |          d           d S )Nz<StreamHandler 2 (NOTSET)>)r   r8   r  rY   reprr   s     rG   'test_can_represent_stream_with_int_namez9StreamHandlerTest.test_can_represent_stream_with_int_name(  s<    !"3"5"566a">?????ri   N)rp   rq   rr   r  r  r  rt   ri   rG   r  r    sF        0 0 0," " "@ @ @ @ @ri   r  c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )TestSMTPServera   
    This class implements a test SMTP server.

    :param addr: A (host, port) tuple which the server listens on.
                 You can specify a port value of zero: the server's
                 *port* attribute will hold the actual port number
                 used, which can be used in client connections.
    :param handler: A callable which will be called to process
                    incoming messages. The handler will be passed
                    the client address tuple, who the message is from,
                    a list of recipients and the message data.
    :param poll_interval: The interval, in seconds, used in the underlying
                          :func:`select` or :func:`poll` call by
                          :func:`asyncore.loop`.
    :param sockmap: A dictionary which will be used to hold
                    :class:`asyncore.dispatcher` instances used by
                    :func:`asyncore.loop`. This avoids changing the
                    :mod:`asyncore` module's global state.
    c                     t           j                            | |d |d           | j                                        d         | _        || _        d | _        d| _        || _	        d S )NT)mapdecode_datark   F)
r   
SMTPServerr  socketgetsocknameport_handler_thread_quitpoll_interval)rC   addrr   r  sockmaps        rG   r  zTestSMTPServer.__init__D  sj    !!$d.2 	" 	4 	4 	4K++--a0	
*ri   c                 6    |                      ||||           dS )aI  
        Delegates to the handler passed in to the server's constructor.

        Typically, this will be a test case method.
        :param peer: The client (host, port) tuple.
        :param mailfrom: The address of the sender.
        :param rcpttos: The addresses of the recipients.
        :param data: The message.
        N)r  )rC   peermailfromrcpttosr  s        rG   process_messagezTestSMTPServer.process_messageM  s"     	dHgt44444ri   c                     t          j        | j        | j        f          x| _        }d|_        |                                 dS )zG
        Start the server running on a separate daemon thread.
        rj  TNro  rp  serve_foreverr  r  rq  rr  rC   ts     rG   rr  zTestSMTPServer.startY  N     %+43E262D1FH H H 	Hq						ri   c                 j    | j         s+t                              || j        d           | j         )dS dS )a*  
        Run the :mod:`asyncore` loop until normal termination
        conditions arise.
        :param poll_interval: The interval, in seconds, used in the underlying
                              :func:`select` or :func:`poll` call by
                              :func:`asyncore.loop`.
        rk   )r  countN)r  r   loop_map)rC   r  s     rG   r  zTestSMTPServer.serve_foreverb  sN     * 	AMM-TYaM@@@ * 	A 	A 	A 	A 	Ari   c                     d| _         t          j        | j                   d| _        |                                  t
                              | j        d           dS )zr
        Stop the thread by closing the server instance.
        Wait for the server thread to terminate.
        TN)r  
ignore_all)r  r   join_threadr  rJ   r   	close_allr  rm   s    rG   stopzTestSMTPServer.stopm  sS    
 
$T\222

tyT:::::ri   N)	rp   rq   rr   rs   r  r  rr  r  r  rt   ri   rG   r  r  /  sl         (+ + +
5 
5 
5  	A 	A 	A	; 	; 	; 	; 	;ri   r  c                   4     e Zd ZdZd Zd Z fdZd Z xZS )ControlMixina
  
    This mixin is used to start a server on a separate thread, and
    shut it down programmatically. Request handling is simplified - instead
    of needing to derive a suitable RequestHandler subclass, you just
    provide a callable which will be passed each received request to be
    processed.

    :param handler: A handler callable which will be called with a
                    single parameter - the request - in order to
                    process the request. This handler is called on the
                    server thread, effectively meaning that requests are
                    processed serially. While not quite web scale ;-),
                    this should be fine for testing applications.
    :param poll_interval: The polling interval in seconds.
    c                 `    d | _         || _        || _        t          j                    | _        d S r   )r  r  r  ro  r  ready)rC   r   r  s      rG   r  zControlMixin.__init__  s+    *_&&


ri   c                     t          j        | j        | j        f          x| _        }d|_        |                                 dS )zI
        Create a daemon thread to run the server, and start it.
        rj  TNr  r  s     rG   rr  zControlMixin.start  r  ri   c                     | j                                          t          t          |                               |           dS )z^
        Run the server. Set the ready flag before entering the
        service loop.
        N)r  r  r  r  r  )rC   r  r  s     rG   r  zControlMixin.serve_forever  s;    
 	
lD!!//>>>>>ri   c                     |                                   | j         t          j        | j                   d| _        |                                  | j                                         dS )zK
        Tell the server thread to stop, and wait for it to do so.
        N)shutdownr  r   r  server_closer  rL   rm   s    rG   r  zControlMixin.stop  s_     	<#(666DL
ri   )	rp   rq   rr   rs   r  rr  r  r  r  r  s   @rG   r  r  y  so         ' ' '  ? ? ? ? ?	 	 	 	 	 	 	ri   r  c                   $    e Zd ZdZ	 	 ddZd ZdS )TestHTTPServera  
    An HTTP server which is controllable using :class:`ControlMixin`.

    :param addr: A tuple with the IP address and port to listen on.
    :param handler: A handler callable which will be called with a
                    single parameter - the request - in order to
                    process the request.
    :param poll_interval: The polling interval in seconds.
    :param log: Pass ``True`` to enable log messages.
    r  FNc                      G fddt                     t          j        | |           t                              | ||           || _        d S )Nc                   2     e Zd ZddZd Z fdZ xZS )=TestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandlerNc                 X    |                     d          r| j        S t          |          )Ndo_)
startswithprocess_requestAttributeError)rC   rE   defaults      rG   __getattr__zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.__getattr__  s-    ??5)) 0//$T***ri   c                 :    | j                             |            d S r   serverr  rm   s    rG   r  zMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_request      $$T*****ri   c                 H    r t          |           j        |g|R   d S d S r   )r  log_message)rC   formatrX  DelegatingHTTPRequestHandlerr  r   s      rG   r  zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_message  sW     ;,E6    +F;59; ; ; ; ; ;; ;ri   r   )rp   rq   rr   r  r  r  r  )r  r  r   s   @rG   r  r    sf        + + + +
+ + +; ; ; ; ; ; ; ; ; ; ;ri   r  )r   r   r  r  sslctx)rC   r  r   r  r   r  r  s       ` @rG   r  zTestHTTPServer.__init__  sy    	; 	; 	; 	; 	; 	; 	; 	;+A 	; 	; 	; 	D$(DEEEdG];;;ri   c                     	 | j                                         \  }}| j        r| j                            |d          }n5# t          $ r(}t
          j                            d|z              d }~ww xY w||fS )NT)server_sidezGot an error:
%s
)r  acceptr  wrap_socketrB  r1  r  r  )rC   sockr  es       rG   get_requestzTestHTTPServer.get_request  s    	++--JD${ G{..t.FF 	 	 	J2Q6777	 Tzs   ?A 
A4#A//A4)r  FN)rp   rq   rr   rs   r  r  rt   ri   rG   r  r    sI        	 	 58#'   &	 	 	 	 	ri   r  c                   2     e Zd ZdZdZ	 	 ddZ fdZ xZS )TestTCPServera  
    A TCP server which is controllable using :class:`ControlMixin`.

    :param addr: A tuple with the IP address and port to listen on.
    :param handler: A handler callable which will be called with a single
                    parameter - the request - in order to process the request.
    :param poll_interval: The polling interval in seconds.
    :bind_and_activate: If True (the default), binds the server and starts it
                        listening. If False, you need to call
                        :meth:`server_bind` and :meth:`server_activate` at
                        some later time before calling :meth:`start`, so that
                        the server will set up the socket and listen on it.
    Tr  c                      G d dt                     }t          j        | |||           t                              | ||           d S )Nc                       e Zd Zd ZdS );TestTCPServer.__init__.<locals>.DelegatingTCPRequestHandlerc                 :    | j                             |            d S r   r  rm   s    rG   r:  zBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handle  r  ri   N)rp   rq   rr   r:  rt   ri   rG   DelegatingTCPRequestHandlerr    s#        + + + + +ri   r  )r   r   r  r  )rC   r  r   r  bind_and_activater  s         rG   r  zTestTCPServer.__init__  sl    	+ 	+ 	+ 	+ 	+*> 	+ 	+ 	+ 	#D$0K$5	7 	7 	7dG];;;;;ri   c                     t          t          |                                            | j                                        d         | _        d S Nrk   )r  r  server_bindr  r  r  r  s    rG   r  zTestTCPServer.server_bind  =    mT""..000K++--a0			ri   r  T)rp   rq   rr   rs   allow_reuse_addressr  r  r  r  s   @rG   r  r    sd          47#'< < < <1 1 1 1 1 1 1 1 1ri   r  c                   8     e Zd ZdZ	 	 ddZ fdZ fdZ xZS )TestUDPServera0  
    A UDP server which is controllable using :class:`ControlMixin`.

    :param addr: A tuple with the IP address and port to listen on.
    :param handler: A handler callable which will be called with a
                    single parameter - the request - in order to
                    process the request.
    :param poll_interval: The polling interval for shutdown requests,
                          in seconds.
    :bind_and_activate: If True (the default), binds the server and
                        starts it listening. If False, you need to
                        call :meth:`server_bind` and
                        :meth:`server_activate` at some later time
                        before calling :meth:`start`, so that the server will
                        set up the socket and listen on it.
    r  Tc                      G fddt                     t          j        | ||           t                              | ||           d| _        d S )Nc                   (     e Zd Zd Z fdZ xZS );TestUDPServer.__init__.<locals>.DelegatingUDPRequestHandlerc                 :    | j                             |            d S r   r  rm   s    rG   r:  zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.handle  r  ri   c                     | j                                         }|rC	 t          |                                            d S # t          $ r | j        j        s Y d S w xY wd S r   )wfilerW   r  finishrB  r   _closed)rC   r  DelegatingUDPRequestHandlerr  s     rG   r$  zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish  s    z**,, ""94@@GGIIIII" " " "#{2 "!" " """ "s   "A AA)rp   rq   rr   r:  r$  r  )r  r&  s   @rG   r&  r     sM        + + +" " " " " " " " " "ri   r&  F)r   r   r  r  r%  )rC   r  r   r  r  r&  s        @rG   r  zTestUDPServer.__init__  s~    	" 	" 	" 	" 	" 	" 	"*@ 	" 	" 	" 	#D$$?$5	7 	7 	7 	dG];;;ri   c                     t          t          |                                            | j                                        d         | _        d S r  )r  r  r  r  r  r  r  s    rG   r  zTestUDPServer.server_bind  r  ri   c                 d    t          t          |                                            d| _        d S )NT)r  r  r  r%  r  s    rG   r  zTestUDPServer.server_close  s*    mT""//111ri   r  )rp   rq   rr   rs   r  r  r  r  r  s   @rG   r  r    sw           58#'   ,1 1 1 1 1        ri   r  AF_UNIXc                       e Zd Zej        ZdS )TestUnixStreamServerNrp   rq   rr   r  r)  address_familyrt   ri   rG   r+  r+  #          ri   r+  c                       e Zd Zej        ZdS )TestUnixDatagramServerNr,  rt   ri   rG   r0  r0  &  r.  ri   r0  c                   (    e Zd Zej        Zd Zd ZdS )SMTPHandlerTestc                    i }t          t          j        df| j        d|          }|                                 t          j        |j        f}t          j                            |ddd| j	                  }| 
                    |j        dg           g | _        t          j        ddi          }t          j                    | _        |                    |           | j                            | j	                   |                                 |                     | j                                                   | 
                    t-          | j                  d	           | j        d         \  }}}}	| 
                    |d           | 
                    |dg           |                     d
|	           |                     |	                    d                     |                                 d S )Nr   MbP?meyouLog)timeoutr+  u	   Hello ✓rk   z
Subject: Log
u   

Hello ✓)r  r   HOSTr  rr  r  r   r?   SMTPHandlerTIMEOUTrY   toaddrsmessagesr   ro  r  handledr:  r  r  rB   is_setrZ   r  endswithrJ   )
rC   r  r   r  rQ   r   r  r  r  r  s
             rG   
test_basiczSMTPHandlerTest.test_basic1  s   !3Q 79Mu ') )"FK0((tUE15 ) ? ?UG,,,!5."9:: ((	$,'''++--...T]++Q///(,a(8%h4(((5'***($///&899:::						ri   c                 l    | j                             |           | j                                         d S r   )r=  appendr>  r  )rC   rX  s     rG   r  zSMTPHandlerTest.process_messageI  s2    T"""ri   N)rp   rq   rr   r   LONG_TIMEOUTr;  rA  r  rt   ri   rG   r2  r2  +  s<         "G  0    ri   r2  c                   ^    e Zd ZdZdZd Zd Zd Zd Z e	j
                    d             ZdS )	MemoryHandlerTestzTests for the MemoryHandler.r   c                 ,   t                               |            t          j                            dt          j        | j                  | _        t          j        d          | _	        d| j	        _
        | j	                            | j                   d S )N
   memr   )r   rH   r   r?   MemoryHandlerr   r9   mem_hdlrr   
mem_logger	propagaterA   rm   s    rG   rH   zMemoryHandlerTest.setUpT  su    t(66r7?7;~G G!+E22$%!""4=11111ri   c                 l    | j                                          t                              |            d S r   )rK  rJ   r   rR   rm   s    rG   rR   zMemoryHandlerTest.tearDown\  0    $ri   c                    | j                             |                                            |                     g            | j                             |                                            |                     g            | j                             |                                            g d}|                     |           dD ]}t          d          D ].}| j                             |                                            /|                     |           | j                             |                                            |d t          ||dz             D             z   }|                     |           | j                             |                                            |                     |           d S )N)r7   r|   r   r~   )r   r   )r]     	   c                 0    g | ]}d t          |          fS )r7   )str).0is     rG   
<listcomp>z0MemoryHandlerTest.test_flush.<locals>.<listcomp>v  s#    III1gs1vv.IIIri   rH  )rL  r   rn   rh   r   r   r^  )rC   linesnrX  s       rG   
test_flushzMemoryHandlerTest.test_flush`  s    	d//11222b!!!T..00111b!!! 1 1 3 3444
 
 

 	e$$$ 	) 	)A1XX ; ;%%d&7&7&9&9::::!!%((( O!!$"3"3"5"5666IIaR8H8HIIIIE!!%((((d//11222e$$$$$ri   c                    | j                             |                                            |                     g            | j                             |                                            |                     g            | j                             | j                   | j                                         ddg}|                     |           t          j	        
                    dt          j        | j        d          | _        | j                             | j                   | j                             |                                            |                     |           | j                             |                                            |                     |           | j                             | j                   | j                                         |                     |           dS )zO
        Test that the flush-on-close configuration works as expected.
        rQ  rR  rH  FN)rL  r   rn   rh   r   rK   rK  rJ   r   r?   rJ  r   r9   rA   )rC   rZ  s     rG   test_flush_on_closez%MemoryHandlerTest.test_flush_on_close|  s    	d//11222b!!!T..00111b!!!%%dm444
 	e$$$(66r7?7;~7<> > 	""4=111d//11222e$$$T..00111e$$$%%dm444e$$$$$ri   c                     G d d          } || j                   }	 | j                             |           t          d          D ]J}t          j        d           | j                            d           | j                            d           K	 |j        D ]}t          j
        |           d S # |j        D ]}t          j
        |           w xY w)Nc                        e Zd Zd Zd Zd ZdS )ZMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandlerc                 "    || _         g | _        d S r   )rK  threads)rC   rK  s     rG   r  zcMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.__init__  s     (!ri   c                 :    | j                             d            d S r   )rK  	setTargetrm   s    rG   removeTargetzgMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.removeTarget  s    ''-----ri   c                     t          j        | j                  }| j                            |           |                                 d S )N)rk  )ro  rp  rf  rc  rC  rr  )rC   r+  threads      rG   r:  zaMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.handle  s?    ")1BCCC##F+++ri   N)rp   rq   rr   r  rf  r:  rt   ri   rG   MockRaceConditionHandlerra    sA        " " ". . .    ri   ri  rH  rl  znot flushedflushed)rK  re  r^  r_  ra  rL  r   r   rc  r   r  )rC   ri  rk  rf  rh  s        rG   &test_race_between_set_target_and_flushz8MemoryHandlerTest.test_race_between_set_target_and_flush  s   	 	 	 	 	 	 	 	 *)$-88		5M##F+++2YY 3 3
5!!!$$]333''	22223
 !. 5 5 ,V44445 5&. 5 5 ,V44445s   A4B4 4 CN)rp   rq   rr   rs   rV   rH   rR   r\  r^  r   r  rk  rt   ri   rG   rF  rF  M  s        && 32 2 2     % % %8% % %< 10225 5 325 5 5ri   rF  c                       e Zd ZdZd ZdS )ExceptionFormatterzA special exception formatter.c                 "    d|d         j         z  S )Nz
Got a [%s]r   )rp   )rC   eis     rG   formatExceptionz"ExceptionFormatter.formatException  s    ben,,ri   N)rp   rq   rr   rs   rp  rt   ri   rG   rm  rm    s)        ((- - - - -ri   rm  c                   >   e Zd ZdZej        ZdZdZdZdZ	e
                    dd          Ze
                    dd	          Zd
e z   dz   Ze
                    dd          ZdZdZdZdZd Zd Zd ZefdZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Z d  Z!d! Z"d" Z#d#S )$ConfigFileTestz5Reading logging config from a .ini-style config file.^(\w+) \+\+ (\w+)$aN  
    [loggers]
    keys=root

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=hand1

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    a  
    [loggers]
    keys=root,parser

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=

    [logger_parser]
    level=DEBUG
    handlers=hand1
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    a  
    [loggers]
    keys=root,parser

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=hand1

    [logger_parser]
    level=DEBUG
    handlers=
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    z
sys.stdoutz
sys.stboutzformatter=form1zformatter=misspelled_namea  
    [loggers]
    keys=root

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=NOTSET
    handlers=hand1

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [formatter_form1]
    class=zS.ExceptionFormatter
    format=%(levelname)s:%(name)s:%(message)s
    datefmt=
    zclass=StreamHandlerzclass=logging.StreamHandlerag  
    [loggers]
    keys=root,parser

    [handlers]
    keys=hand1, hand2

    [formatters]
    keys=form1, form2

    [logger_root]
    level=WARNING
    handlers=

    [logger_parser]
    level=DEBUG
    handlers=hand1
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stdout,)

    [handler_hand2]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    args=(sys.stderr,)

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=

    [formatter_form2]
    format=%(message)s
    datefmt=
    a%  
    [loggers]
    keys=root,parser,compiler

    [handlers]
    keys=hand1

    [formatters]
    keys=form1

    [logger_root]
    level=WARNING
    handlers=hand1

    [logger_compiler]
    level=DEBUG
    handlers=
    propagate=1
    qualname=compiler

    [logger_parser]
    level=DEBUG
    handlers=
    propagate=1
    qualname=compiler.parser

    [handler_hand1]
    class=StreamHandler
    level=NOTSET
    formatter=form1
    kwargs={'stream': sys.stdout,}

    [formatter_form1]
    format=%(levelname)s ++ %(message)s
    datefmt=
    a  
    [loggers]
    keys=root

    [handlers]
    keys=file

    [formatters]
    keys=

    [logger_root]
    level=DEBUG
    handlers=file

    [handler_file]
    class=FileHandler
    level=DEBUG
    args=("{tempfile}",)
    kwargs={{"encoding": "utf-8"}}
    z
    [loggers]
    keys=root

    [handlers]
    keys=screen

    [formatters]
    keys=

    [logger_root]
    level=DEBUG
    handlers=screen

    [handler_screen]
    level=DEBUG
    class=StreamHandler
    args=(sys.stdout,)
    formatter=
    c                     t          j        t          j        |                    }t	          j        j        |fddi| d S )Nr(  r&  )r3   r4   textwrapdedentr   config
fileConfig)rC   confkwargsfiles       rG   apply_configzConfigFileTest.apply_config  sA    {8?40011!$CCCFCCCCCri   c                    t          j                    5 }|                     | j                   t	          j                    }|                    |                                            |                    |                                            | 	                    dg|           | 	                    g            d d d            d S # 1 swxY w Y   d S Nr}   r~   r  
r   captured_stdoutr|  config0r   r   r   rn   r   rh   rC   outputr   s      rG   test_config0_okzConfigFileTest.test_config0_ok     $&& 	&&dl+++&((FKK))++,,,LL**,,---!!# "    !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   B)C

CCc                 ^   t          j                    5 }t          j        t	          j        | j                            }t          j                    }|	                    |           t          j                            |           t          j                    }|                    |                                            |                    |                                            |                     dg|           |                     g            d d d            d S # 1 swxY w Y   d S r~  )r   r  r3   r4   ru  rv  r  configparserConfigParser	read_filer   rw  rx  r   r   rn   r   rh   )rC   r  r{  cpr   s        rG   test_config0_using_cp_okz'ConfigFileTest.test_config0_using_cp_ok  sK   $&& 	&&;xt|<<==D*,,BLLN%%b)))&((FKK))++,,,LL**,,---!!# "    !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   DD""D&)D&c                    t          j                    5 }|                     |           t          j        d          }|                    |                                            |                    |                                            |                     ddg|           |                     g            d d d            d S # 1 swxY w Y   d S Ncompiler.parserr   r|   r  r  	r   r  r|  r   r   r   rn   r   rh   rC   rw  r  r   s       rG   test_config1_okzConfigFileTest.test_config1_ok     $&& 	&&f%%%&'899FKK))++,,,LL**,,---!!#  "   
 !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&   B&CCCc                 R    |                      t          | j        | j                   d S r   r  rs  r|  config2rm   s    rG   test_config2_failurez#ConfigFileTest.test_config2_failure  %    )T%6EEEEEri   c                 R    |                      t          | j        | j                   d S r   r  rs  r|  config3rm   s    rG   test_config3_failurez#ConfigFileTest.test_config3_failure  r  ri   c                    t          j                    5 }|                     | j                   t	          j                    }	 t                      # t          $ r t	          j        d           Y nw xY wt          j	        
                    d           |                     |                                d           |                     g            d d d            d S # 1 swxY w Y   d S Nzjust testingr   z-ERROR:root:just testing
Got a [RuntimeError]
)r   r  r|  config4r   r   r  	exceptionr1  stdoutseekrY   rW   rh   r  s      rG   test_config4_okzConfigFileTest.test_config4_ok  s+   $&& 	&&dl+++&((F2"nn$ 2 2 2!.111112JOOAV__..AC C C !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s0   .CAA2/C1A22ACC"%C"c                 <    |                      | j                   d S N)rw  r  config5rm   s    rG   test_config5_okzConfigFileTest.test_config5_ok  !    DL11111ri   c                 <    |                      | j                   d S r  )r  config6rm   s    rG   test_config6_okzConfigFileTest.test_config6_ok
  r  ri   c                    t          j                    5 }|                     | j                   t	          j        d          }t	          j        d          }|                    |                                            |                    |                                            |	                    |                                            | 
                    g d|           | 
                    g            d d d            n# 1 swxY w Y   t          j                    5 }|                     | j                   t	          j        d          }|                     |j                   |                    |                                            |                    |                                            t	          j        d          }|                    |                                            |                    |                                            |	                    |                                            | 
                    g d|           | 
                    g            d d d            d S # 1 swxY w Y   d S Nr  zcompiler-hyphenated)r  r  )r{   r   r  compiler.lexer))r   r   )r}   r   )r   r   )r}   r   )r   r  r|  config1ar   r   r   rn   r   criticalrh   config7r;  r   rC   r  r   
hyphenateds       rG   test_config7_okzConfigFileTest.test_config7_ok  s   $&& 	&&dm,,,&'899F !*+@AAJKK))++,,,LL**,,--- 1 1 3 3444!! # # # 	 "    !!"%%%'	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&( $&& 	&&dl+++&'899FV_---KK))++,,,LL**,,---&'788FKK))++,,,LL**,,--- 1 1 3 3444!! # # #
  "    !!"%%%)	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&%   C&DD
D
$EI??JJc                    d }|                                  5  t          j        dd          \  }}t          j        |           t          j        dk    r|                    dd          }| j                            |          }| 	                    |           | 	                    |           d d d            n# 1 swxY w Y   t          j        j        d         }|                     |||           d S )	Nc                 V    |                                   t          j        |           d S r   rJ   r5  removeh1rI  s     rG   cleanupz/ConfigFileTest.test_config8_ok.<locals>.cleanup:       HHJJJIbMMMMMri   ri  test_logging-X-rZ  \z\\)r3  r   )check_no_resource_warningr3  r4  r5  rJ   rE   replaceconfig8r  r|  r   rootr?   r   )rC   r  rH  rI  r  r   s         rG   test_config8_okzConfigFileTest.test_config8_ok8  s+   	 	 	 ++-- 	' 	'%f.?@@FBHRLLL w$ZZf--l))2)66Gg&&&g&&&	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' 	' ,'*"-----s   BB<<C C c                 j   |                      | j                   t          j        d          }|                     |j                   |                      | j                   |                     |j                   |                      | j        d           |                     |j                   d S )Nsome_pristine_loggerF)disable_existing_loggers)r|  disable_testr   r   r;  r   rB   rC   r   s     rG   test_logger_disablingz$ConfigFileTest.test_logger_disablingO  s    $+,,,"#9::)))$+,,,((($+eLLL)))))ri   c                     d}|                      |           |                     t          j                    j        d         j        d           d S )Naw  
            [loggers]
            keys=root

            [handlers]
            keys=hand1

            [formatters]
            keys=form1

            [logger_root]
            handlers=hand1

            [handler_hand1]
            class=StreamHandler
            formatter=form1

            [formatter_form1]
            format=%(levelname)s ++ %(message)s
            r   hand1)r|  rY   r   r   r?   rE   )rC   test_configs     rG   test_config_set_handler_namesz,ConfigFileTest.test_config_set_handler_namesX  sO    ( 	+&&&*,,5a8=wGGGGGri   c                     d}t          j        t          j        |                    }|                     t
          t          j        j        |           d S )Na  
            [loggers]
            keys=root

            [handlers]
            keys=hand1

            [formatters]
            keys=form1

            [logger_root]
            handlers=hand1

            [handler_hand1]
            class=StreamHandler
            formatter=form1

            [formatter_form1]
            format=%(levelname)s ++ %(message)s

            prince
            )	r3   r4   ru  rv  r  r  r   rw  rx  )rC   r  r{  s      rG   'test_exception_if_confg_file_is_invalidz6ConfigFileTest.test_exception_if_confg_file_is_invalidp  sG    . {8?;7788,(A4HHHHHri   c                     t          j        dd          \  }}t          j        |           |                     t
          t          j        j        |           t          j	        |           d S )Ntest_empty_.inir   suffix)
r3  r4  r5  rJ   r  r  r   rw  rx  r  )rC   rH  rI  s      rG   %test_exception_if_confg_file_is_emptyz4ConfigFileTest.test_exception_if_confg_file_is_empty  sV    !vFFFB
,(A2FFF
	"ri   c                 \    |                      t          t          j        j        d           d S )Nfilenotfound)r  FileNotFoundErrorr   rw  rx  rm   s    rG   ,test_exception_if_config_file_does_not_existz;ConfigFileTest.test_exception_if_config_file_does_not_exist  s&    +W^-FWWWWWri   c                    t          j        d                                          }t          j        dd          \  }}	 t          j        ||                    d                     t          j        |           t          j
                            |dt          ddd	d
dddi                     t          j        |           dS # t          j        |           w xY w)z.bpo-33802 defaults should not get interpolatedat  
            [formatters]
            keys=default

            [formatter_default]

            [handlers]
            keys=console

            [handler_console]
            class=logging.StreamHandler
            args=tuple()

            [loggers]
            keys=root

            [logger_root]
            formatter=default
            handlers=console
            test_logging_r  r  asciir&  rk   Fr  z5%(asctime)s [%(process)d] [%(levelname)s] %(message)sz[%Y-%m-%d %H:%M:%S %z]zlogging.Formatter)r  datefmtclass)versionr  
formatters)r(  defaultsN)ru  rv  stripr3  r4  r5  r  encoderJ   r   rw  rx  dictr6  )rC   inirH  rI  s       rG   !test_defaults_do_no_interpolationz0ConfigFileTest.test_defaults_do_no_interpolation  s    o   & ' 	( !HHHB	HRG,,---HRLLLN%% -2!&]'?%8$ $ 
 
 
 &     IbMMMMMBIbMMMMs   A4C C!N)$rp   rq   rr   rs   r	   r  rV   r  config1r  r  r  r  r  r  r  r  r  r  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rt   ri   rG   rr  rr    s       ?? / I,G4G@H@ oolL99G oo/1LMMG* +*+G6 oo35RSSG'GT#GLG*L*D D D& & && & &$ &- & & & &F F FF F F& & &2 2 22 2 2)& )& )&V. . ..* * *H H H0I I I6  X X X* * * * *ri   rr  c                   8    e Zd ZdZeZdZd Zd Zd Z	d Z
d ZdS )	SocketHandlerTestzTest for SocketHandler objects.r0  r   c                    t                               |            dx| _        x| _        | _        	 |                     | j        | j        d          x| _        }|                                 n# t          $ r}|| _        Y d}~dS d}~ww xY w|j
                                         t          j        j        }t          |j        t"                    r |d|j                  | _        n ||j        d          | _        d| _        | j                            | j        j        d                    | j                            | j                   t/          j        d          | _        dS )ztSet up a TCP server to receive log messages, and a SocketHandler
        pointing to that server's address and port.N{Gz?r0  r   r   )r   rH   r   	sock_hdlrserver_exceptionserver_classaddresshandle_socketrr  rB  r  r  r   r?   SocketHandler
isinstanceserver_addressr^   r  
log_outputr0   rK   rA   ro  	Semaphorer>  rC   r   r  hclss       rG   rH   zSocketHandlerTest.setUp  s^    	t?CCCdnt'<	#'#4#4T\595G$O $O ODK&LLNNNN  	 	 	$%D!FFFFF	 	-f+U33 	?!T+v{;;DNN!T&"7>>DN&&t'7'@'CDDD##DN333 *1--   <A. .
B
8BB
c                 8   	 | j         r8| j                            | j                    | j                                          | j        r| j                                         t                              |            dS # t                              |            w xY w)zShutdown the TCP server.N)r  r0   rK   rJ   r   r  r   rR   rm   s    rG   rR   zSocketHandlerTest.tearDown  s    	$~ ' ..t~>>>$$&&&{ #  """d#####Hd####   AA= =Bc                    |j         }	 |                    d          }t          |          dk     rd S t          j        d|          d         }|                    |          }t          |          |k     r;||                    |t          |          z
            z   }t          |          |k     ;t          j        |          }t          j        |          }| xj	        |j
        dz   z  c_	        | j                                         )NTr]  >Lr   
)
connectionrecvrZ   structunpackpickleloadsr   r   r  r+  r>  r  )rC   requestconnchunkslenobjr   s          rG   r  zSocketHandlerTest.handle_socket  s    !	#IIaLLE5zzA~~=u--a0DIIdOOEe**t##		$U*; < << e**t##,u%%C*3//FOOvzD00OOL  """	#ri   c                 ^   | j         r|                     | j                    t          j        d          }|                    d           | j                                         |                    d           | j                                         |                     | j	        d           d S )Ntcpr   eggs
spam
eggs
)
r  skipTestr   r   r   r>  r  r   rY   r  r  s     rG   test_outputzSocketHandlerTest.test_output  s      	1MM$/000"5))VV.99999ri   c                    | j         r|                     | j                    d| j        _        | j                                         	 t          d          # t          $ r | j                            d           Y nw xY w| j        	                    d           t          j
                    }|                     | j        j        |           t          j        | j        j        |z
  dz              | j        	                    d           d S )Ng      @zDeliberate mistakez
Never sentzNever sent, eitherr4  zNor this)r  r  r  
retryStartr   r  r  r0   r  r   r_  r  	retryTimera  )rC   nows     rG   test_noserverzSocketHandlerTest.test_noserver	  s     	1MM$/000 %(!	53444 	5 	5 	5&&|44444	53444ikk4>3S999
4>+c1E9:::z*****s   A $A>=A>N)rp   rq   rr   rs   r  r  r  rH   rR   r  r  r  rt   ri   rG   r  r    sq         *) LG. . .4	$ 	$ 	$# # #	: 	: 	:+ + + + +ri   r  c                      t          j        dd          \  } }t          j        |            t          j        |           |S )Nr  z.sockr  )r3  r4  r5  rJ   r  )rH  rI  s     rG   _get_temp_domain_socketr    s<    _WEEEFBHRLLL IbMMMIri   zUnix sockets requiredc                   :    e Zd ZdZ eed          reZd Zd Z	dS )UnixSocketHandlerTestz)Test for SocketHandler with unix sockets.r)  c                 `    t                      | _        t                              |            d S r   )r  r  r  rH   rm   s    rG   rH   zUnixSocketHandlerTest.setUp,  )    .00%%%%%ri   c                 l    t                               |            t          j        | j                   d S r   )r  rR   r   r6  r  rm   s    rG   rR   zUnixSocketHandlerTest.tearDown1  /    ""4(((&&&&&ri   N)
rp   rq   rr   rs   hasattrr  r+  r  rH   rR   rt   ri   rG   r  r  $  sS         43wvy!! ,+& & &
' ' ' ' 'ri   r  c                   2    e Zd ZdZeZdZd Zd Zd Z	d Z
dS )DatagramHandlerTestzTest for DatagramHandler.r  c                    t                               |            dx| _        x| _        | _        	 |                     | j        | j        d          x| _        }|                                 n# t          $ r}|| _        Y d}~dS d}~ww xY w|j
                                         t          j        j        }t          |j        t"                    r |d|j                  | _        n ||j        d          | _        d| _        | j                            | j        j        d                    | j                            | j                   t/          j                    | _        dS )zvSet up a UDP server to receive log messages, and a DatagramHandler
        pointing to that server's address and port.Nr  r0  r   r   )r   rH   r   r  r  r  r  handle_datagramrr  rB  r  r  r   r?   DatagramHandlerr  r  r^   r  r  r0   rK   rA   ro  r  r>  r  s       rG   rH   zDatagramHandlerTest.setUp>  s[    	t?CCCdnt'<	#'#4#4T\595I4$Q $Q QDK&LLNNNN  	 	 	$%D!FFFFF	 	/f+U33 	?!T+v{;;DNN!T&"7>>DN&&t'7'@'CDDD##DN333 ((r  c                 8   	 | j         r| j                                          | j        r8| j                            | j                   | j                                         t                              |            dS # t                              |            w xY w)zShutdown the UDP server.N)r   r  r  r0   rK   rJ   r   rR   rm   s    rG   rR   zDatagramHandlerTest.tearDownX  s    	${ #  """~ ' ..t~>>>$$&&&d#####Hd####r   c                    t          j        dd          }|j        t          |          d          }t	          j        |          }t          j        |          }| xj        |j	        dz   z  c_        | j
                                         d S )Nr  r   r  )r  packpacketrZ   r  r	  r   r   r  r+  r>  r  )rC   r
  r  r+  r  r   s         rG   r&  z#DatagramHandlerTest.handle_datagramc  sy    {4##D		

+l6""&s++6:,,ri   c                    | j         r|                     | j                    t          j        d          }|                    d           | j                                         | j                                         |                    d           | j                                         |                     | j	        d           d S )Nudpr   r  r  )
r  r  r   r   r   r>  r  rL   rY   r  r  s     rG   r  zDatagramHandlerTest.test_outputk  s      	1MM$/000"5))VV.99999ri   N)rp   rq   rr   rs   r  r  r  rH   rR   r&  r  rt   ri   rG   r$  r$  5  sb         $# LG) ) )4	$ 	$ 	$  
: 
: 
: 
: 
:ri   r$  c                   :    e Zd ZdZ eed          reZd Zd Z	dS )UnixDatagramHandlerTestz,Test for DatagramHandler using Unix sockets.r)  c                 `    t                      | _        t                              |            d S r   )r  r  r$  rH   rm   s    rG   rH   zUnixDatagramHandlerTest.setUp  s)    .00!!$'''''ri   c                 l    t                               |            t          j        | j                   d S r   )r$  rR   r   r6  r  rm   s    rG   rR   z UnixDatagramHandlerTest.tearDown  s/    $$T***&&&&&ri   N
rp   rq   rr   rs   r"  r  r0  r  rH   rR   rt   ri   rG   r/  r/  w  sS         76wvy!! .-( ( (
' ' ' ' 'ri   r/  c                   8    e Zd ZdZeZdZd Zd Zd Z	d Z
d ZdS )	SysLogHandlerTestz!Test for SysLogHandler using UDP.r  c                    t                               |            dx| _        x| _        | _        	 |                     | j        | j        d          x| _        }|                                 n# t          $ r}|| _        Y d}~dS d}~ww xY w|j
                                         t          j        j        }t          |j        t"                    r# ||j        d         |j        f          | _        n ||j                  | _        d| _        | j                            | j        j        d                    | j                            | j                   t/          j                    | _        dS )ztSet up a UDP server to receive log messages, and a SysLogHandler
        pointing to that server's address and port.Nr  r   ri   )r   rH   r   sl_hdlrr  r  r  r&  rr  rB  r  r  r   r?   r>  r  r  r^   r  r  r0   rK   rA   ro  r  r>  r  s       rG   rH   zSysLogHandlerTest.setUp  sd    	t=AAAdlT%:	#'#4#4T\595I4$Q $Q QDK&LLNNNN  	 	 	$%D!FFFFF	 	-f+U33 	74!6q!96; GHHDLL4 566DL&&t'7'@'CDDD##DL111 ((r  c                 8   	 | j         r| j                                          | j        r8| j                            | j                   | j                                         t                              |            dS # t                              |            w xY w)zShutdown the server.N)r   r  r6  r0   rK   rJ   r   rR   rm   s    rG   rR   zSysLogHandlerTest.tearDown  s    	${ #  """| % ..t|<<<""$$$d#####Hd####r   c                 P    |j         | _        | j                                         d S r   )r+  r  r>  r  )rC   r
  s     rG   r&  z!SysLogHandlerTest.handle_datagram  s%    !.ri   c                    | j         r|                     | j                    t          j        d          }|                    d           | j                            t          j                   | 	                    | j
        d           | j                                         d| j        _        |                    d           | j                            t          j                   | 	                    | j
        d           | j                                         d| j        _        |                    d           | j                            t          j                   | 	                    | j
        d           d S )Nslh   späm
   <11>späm Fs	   <11>spämu   häm-s   <11>häm-späm)r  r  r   r   r   r>  r  r   rD  rY   r  rL   r6  
append_nulidentr  s     rG   r  zSysLogHandlerTest.test_output  s@     	1MM$/000"5))Y'.///*@AAA"'Y'.///*<===&Y'.///*GHHHHHri   c                 :   t          j        d          }| j                                         | j                                         |                    d           | j                            t          j	                   | 
                    | j        d           d S )Nr:  r;  r<  )r   r   r6  rJ   r>  rL   r   r  r   rD  rY   r  r  s     rG   test_udp_reconnectionz'SysLogHandlerTest.test_udp_reconnection  s    "5))Y'.///*@AAAAAri   N)rp   rq   rr   rs   r  r  r  rH   rR   r&  r  r@  rt   ri   rG   r4  r4    sy         ,+ LG) ) )4	$ 	$ 	$  I I I&B B B B Bri   r4  c                   :    e Zd ZdZ eed          reZd Zd Z	dS )UnixSysLogHandlerTestz)Test for SysLogHandler with Unix sockets.r)  c                 `    t                      | _        t                              |            d S r   )r  r  r4  rH   rm   s    rG   rH   zUnixSysLogHandlerTest.setUp  r  ri   c                 l    t                               |            t          j        | j                   d S r   )r4  rR   r   r6  r  rm   s    rG   rR   zUnixSysLogHandlerTest.tearDown  r!  ri   Nr2  rt   ri   rG   rB  rB    sS         43wvy!! .-& & &
' ' ' ' 'ri   rB  z$IPv6 support required for this test.c                   4     e Zd ZdZeZdZ fdZ fdZ xZ	S )IPv6SysLogHandlerTestz&Test for SysLogHandler with IPv6 host.)z::1r   c                     t           j        | j        _        t	          t
          |                                            d S r   )r  AF_INET6r  r-  r  rF  rH   r  s    rG   rH   zIPv6SysLogHandlerTest.setUp  s3    +1?(#T**0022222ri   c                     t           j        | j        _        t	          t
          |                                            d S r   )r  AF_INETr  r-  r  rF  rR   r  s    rG   rR   zIPv6SysLogHandlerTest.tearDown  s3    +1>(#T**3355555ri   )
rp   rq   rr   rs   r  r  r  rH   rR   r  r  s   @rG   rF  rF    sc         10 LG3 3 3 3 36 6 6 6 6 6 6 6 6ri   rF  c                   $    e Zd ZdZd Zd Zd ZdS )HTTPHandlerTestzTest for HTTPHandler.c                 j    t                               |            t          j                    | _        dS )ztSet up an HTTP server to receive log messages, and a HTTPHandler
        pointing to that server's address and port.N)r   rH   ro  r  r>  rm   s    rG   rH   zHTTPHandlerTest.setUp  s)     	t ((ri   c                 |   |j         | _         t          |j                  | _        | j         dk    rI	 t	          |j        d                   }|j                            |          | _        n#  d | _        Y nxY w|	                    d           |
                                 | j                                         d S )Nr.  zContent-Length   )commandr   r<  log_dataintheadersrfiler`   	post_datasend_responseend_headersr>  r  )rC   r
  rlens      rG   handle_requestzHTTPHandlerTest.handle_request  s     ..<6!!&7?+;<==!(!3!3D!9!9&!%c"""s   9A, ,	A7c                 :   t          j        d          }| j        }|                    | j        j        d                    dD ]}d}|r	 dd l}t          j                            t                    }t          j        
                    |d          }|                    |j                  }|                    |           |                    |          }	n# t          $ r d }Y nw xY wd }d }	t!          || j        d|          x| _        }
|
                                 |
j                                         d	|
j        z  }|o|}t           j                            |d
||	d          | _        d | _        |                    | j                   dD ]1}|| j        _        | j                                         d}|                    |           | j                                         |                     | j        j        d
           |                     | j         |           |dk    rtC          | j        j"                  }n'tC          | j#        $                    d                    }|                     |d         dg           |                     |d         dg           |                     |d         |g           3| j        %                                 | j                            | j                   | j        &                                 d S )Nhttpr   rh  r  zkeycert.pem)cafiler  )r  zlocalhost:%dz/frob)foobar)securecontextcredentials)r-  r.  r;  r-  r&  rE   funcNamer  r+  )'r   r   r0   rK   r?   sslr5  r<  dirname__file__r   
SSLContextPROTOCOL_TLS_SERVERload_cert_chaincreate_default_contextImportErrorr  rY  r   rr  r  r  server_portrD  h_hdlrrQ  rA   rK  r>  rL   r   rY   rP  r   queryrU  decoder  rJ   )rC   r   r0   r_  r  rc  herelocalhost_certr  r`  r   hostsecure_clientrK  r+  ds                   rG   r  zHTTPHandlerTest.test_output  s   "6**&!!$"2";A">???# 0	  0	 F#D 
PJJJ 7??844D%'W\\$%F%FN ^^C,CDDF**>:::!888OOGG # " " "!FFF" #1$8K48$I $I $I IDK&LLNNNL!F$66D"-vM!*66tW>K?FCQ 7 S SDK !DM""4;///) 2 2%+"""$$$S!!!!!###  !3W===  v666U?? !455AA !6!6w!?!?@@A  6VH555  :@@@  5C51111K**4;777Ka0	  0	 s   CC('C(N)rp   rq   rr   rs   rH   rY  r  rt   ri   rG   rL  rL    sI          ) ) )  5  5  5  5  5 ri   rL  c                   *    e Zd ZdZd Zd Zd Zd ZdS )
MemoryTestz*Test memory persistence of logger objects.c                 H    t                               |            i | _        dS )z8Create a dict to remember potentially destroyed objects.N)r   rH   
_survivorsrm   s    rG   rH   zMemoryTest.setUpJ  s    tri   c                     |D ]<}t          |          t          |          f}t          j        |          | j        |<   =dS )zKWatch the given objects for survival, by creating weakrefs to
        them.N)idr  weakrefrefrw  )rC   rX  r  keys       rG   _watch_for_survivalzMemoryTest._watch_for_survivalO  sL      	4 	4CS''499$C#*;s#3#3DOC  	4 	4ri   c                 .   t          j                     g }| j                                        D ]'\  \  }}} |            |                    |           (|r<|                     dt          |          d                    |          fz             dS dS )z;Assert that all objects watched for survival have survived.Nz;%d objects should have survived but have been destroyed: %sz, )gccollectrw  r   rC  r]   rZ   r   )rC   deadid_repr_r{  s        rG   _assertTruesurvivalzMemoryTest._assertTruesurvivalV  s     	
!%!6!6!8!8 	# 	#LS%#suu}E""" 	NII .14TDIIdOO0LM N N N N N	N 	Nri   c                 ~   | j                             t          j                   t          j        d          }|                     |           |                    t          j                   | j                             |                                            |                    |                                            | 	                    dg           ~| 
                                 t          j        d          }|                    |                                            | 	                    ddg           d S )Nr]  )r]  r7   r~   )r]  r7   r   )r0   r6   r   r   r   r}  r7   r   rn   rh   r  )rC   r]  r^  s      rG   test_persistent_loggersz"MemoryTest.test_persistent_loggersb  s(    	!!',///&&  %%%W]###t0022333		$##%%&&&!
 	 	 	   """&&		$##%%&&&!!
 	 	 	 	 	ri   N)rp   rq   rr   rs   rH   r}  r  r  rt   ri   rG   ru  ru  F  sY        44  
4 4 4
N 
N 
N    ri   ru  c                       e Zd Zd Zd ZdS )EncodingTestc                    t          j        d          }t          j        dd          \  }}t	          j        |           d}	 t          j        |d          }|                    |           	 |                    |           |	                    |           |                                 n.# |	                    |           |                                 w xY wt          |d          }	 |                     |                                                                |           |                                 n# |                                 w xY w	 t          j                            |          rt	          j        |           d S d S # t          j                            |          rt	          j        |           w w xY w)Ntestri  ztest_logging-1-u   foor&  r~  )r   r   r3  r4  r5  rJ   rR  rA   r   rK   r  rY   r`   rstripr<  isfiler  )rC   r   rH  rI  r  r   r   s          rG   test_encoding_plain_filez%EncodingTest.test_encoding_plain_file{  s   ''!&*;<<B
	)"w???GNN7### D!!!!!'*** !!'***R'***A  !2!2D999									w~~b!! 	" rw~~b!! 	"s<   +F 0B/ *F /+CF /:D> )F >EF 6Gc                 (   t          j        d          }d}t          j        d          }d|_        t          j                    } ||d          }t          j        |          }|                    |           	 |	                    |           |
                    |           |                                 n.# |
                    |           |                                 w xY w|                                }|                     |d           d S )Nr  u   до свиданияcp1251stricts    
)r   r   codecs	getwriterr(  r3   BytesIOr8   rA   r   rK   rJ   rW   rY   )rC   r   messagewriter_classr5   writerr   rg   s           rG   test_encoding_cyrillic_unicodez+EncodingTest.test_encoding_cyrillic_unicode  s    ''Q'11 (fh//'//w	KK   g&&&MMOOOO g&&&MMOOOOOOJKKKKKs   ;B: :+C%N)rp   rq   rr   r  r  rt   ri   rG   r  r  z  s7          4L L L L Lri   r  c                       e Zd Zd Zd ZdS )WarningsTestc           	      n   t          j                    5  t          j        d           |                     t          j        d           t          j        dt                     t          j                    }t          j	        |          }t          j
        d          }|                    |           t          j        d           |                    |           |                                }|                                 |                     |                    d          d           t          j                    }t          j        d	t          d
d|d           |                                }|                                 |                     |d           d d d            d S # 1 swxY w Y   d S )NTFalways)categorypy.warningszI'm warning you...z UserWarning: I'm warning you...
r   Explicitdummy.py*   z
Dummy linez0dummy.py:42: UserWarning: Explicit
  Dummy line
)warningscatch_warningsr   captureWarningsr   filterwarningsUserWarningr3   r4   r8   r   rA   warnrK   rW   rJ   r  findshowwarningrY   )rC   r5   rQ   r   rg   a_files         rG   test_warningszWarningsTest.test_warnings  s   $&& 	F 	F#D)))OOG3U;;;#H{CCCC[]]F%f--A&}55Fa   M.///  ###!!AGGIIIqvv&IJJANNN []]F [*b!'7 7 7!!ALLNNNQDF F F)	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	F 	Fs   F	F**F.1F.c                    t          j                    5  t          j        d           |                     t          j        d           t          j        d          }|                     |j        g            t          j        dt          dd           |                     t          |j                  d           |                     |j        d         t          j                   d d d            d S # 1 swxY w Y   d S )	NTFr  r  r  r  rk   r   )r  r  r   r  r   r   rY   r?   r  r  rZ   assertIsInstanceNullHandlerr  s     rG   test_warnings_no_handlersz&WarningsTest.test_warnings_no_handlers  s2   $&& 
	K 
	K#D)))OOG3U;;; &}55FV_b111 [*bIIIS111555!!&/!"4g6IJJJ
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	K 
	Ks   CC44C8;C8N)rp   rq   rr   r  r  rt   ri   rG   r  r    s:        F F F0K K K K Kri   r  c                 ,    t          j        | |          S r   )r   r:   )r  r  s     rG   
formatFuncr    s    VW---ri   c                       e Zd ZddZdS )myCustomFormatterNc                     d S r   rt   )rC   fmtr  s      rG   r  zmyCustomFormatter.__init__  s    ri   r   )rp   rq   rr   r  rt   ri   rG   r  r    s(             ri   r  c                  (    t          j                    S r   )r   r8   rt   ri   rG   handlerFuncr    s     """ri   c                       e Zd ZdS )CustomHandlerNrp   rq   rr   rt   ri   rG   r  r            Dri   r  c            
       t   e Zd ZdZej        ZdZddddiidddd	d
diddgddZddddiidddd	d
didddgdiddidZddddiidddd	d
didddiiddgddZ	ddddiidddd	ddidddgdiddidZ
ddddiiddddd
didddgdiddidZddddiidddd	d
didddgdiddidZddddiidddd	d
didddgdiddidZdde dz   ddidddd	d
did	dgddZdedde dz   ddedddddd	d
ddeidd	dgddZddddiide dz   dd	d
didddgdiddidZddddiide dz   dd	d
dd idddgdiddidZddddiidddd	d
did!ddgdiddidZdd"dddiidddd	d
diddgdi d#ddid$Zdd%dddiidddd	d
diddgdi d#ddid$Zddddiiddddd
didddgdidd	idZdd%dddiiddd&iid'Zdd%ddd&iiddd&iid'Zddddiid(d)diidddd	d
d(gd*iddd(gd+iddgdd,Zddddiidddd	d
did-dd.idddgdiddid/Zdddiidddd	d
did-dd.idddgdiddid0Zd1dddiidddd	d
did-dd.idddgdiddid/Zddddiidddd	d
d2d3d4d5iddgddZdd6d7d8d9iddd6d:d;d<d6d=dd>d?d@ddAgdBdCidDZ dde dz   dd"dEidddd	d
didFddgdBdCidDZ!dde dz   dd"dGidddd	d
didFddgdBdCidDZ"dde dHz   dd"dGidddd	d
didFddgdBdCidDZ#ddedd"dEidddd	d
didFddgdBdCidDZ$dI Z%dJ Z&efdKZ'dL Z(dM Z)dN Z*dO Z+dP Z,dQ Z-dR Z.dS Z/dT Z0dU Z1dV Z2dW Z3dX Z4dY Z5dZ Z6d[ Z7d\ Z8d] Z9dqd_Z: e;j<                    d`             Z= e;j<                    da             Z> e;j<                    db             Z?dc Z@dd ZAde ZBdf ZCdg ZDdh ZEdi ZFdj ZGdk ZHdl ZIdm ZJdn ZKdo ZLdp ZMd^S )rConfigDictTestz)Reading logging config from a dictionary.rs  rk   form1r  z%(levelname)s ++ %(message)sr  logging.StreamHandlerr   zext://sys.stdout)r  	formatterr  r5   r   r  r?   )r  r  r?   r  r  r7   r  )r  r  r?   loggersr  zext://sys.stdboutNTOSETWRANINGmisspelled_namez.ExceptionFormatterz"%(levelname)s:%(name)s:%(message)s)()r  z.formatFunc)r  form2form3r  )r  hand2z.CustomHandlerzinvalid parameter name)r  r  r  r5   r   r  F)compilerr  )r  r  r  r?   r  r  Tr   )r  incrementalr?   r  filt1rE   )r  r  r  r5   filtersr  r  )r  r  r  r?   r  r  zcfg://true_formatterszcfg://handler_configs[hand1])r  true_formattershandler_configsr  r?   r  r  )r  r  r  r?   r  r  r   r^  !
)r]  
terminator)r  r  r  r5   r   mySimpleFormatterz1%(asctime)s (%(name)s) %(levelname)s: %(message)s$)r  style)r  r  r  zlogging.handlers.MemoryHandler   
fileGlobal)r  capacityr  rk  r  )r  bufferGlobalmymoduler  true)r  r?   rM  )r  r  r?   r  )r  r  validatemy_test_logger_custom_formatter)r  r  r  z.myCustomFormatterc                 D    t           j                            |           d S r   )r   rw  
dictConfig)rC   ry  s     rG   r|  zConfigDictTest.apply_config  s    !!$'''''ri   c                    t          j                    5 }|                     | j                   t	          j                    }|                    |                                            |                    |                                            | 	                    dg|           | 	                    g            d d d            d S # 1 swxY w Y   d S r~  r  r  s      rG   r  zConfigDictTest.test_config0_ok  r  r  c                    t          j                    5 }|                     |           t          j        d          }|                    |                                            |                    |                                            |                     ddg|           |                     g            d d d            d S # 1 swxY w Y   d S r  r  r  s       rG   r  zConfigDictTest.test_config1_ok  r  r  c                 R    |                      t          | j        | j                   d S r   r  rm   s    rG   r  z#ConfigDictTest.test_config2_failure  r  ri   c                 R    |                      t          | j        | j                   d S r   )r  rs  r|  config2arm   s    rG   test_config2a_failurez$ConfigDictTest.test_config2a_failure  %    )T%6FFFFFri   c                 R    |                      t          | j        | j                   d S r   )r  rs  r|  config2brm   s    rG   test_config2b_failurez$ConfigDictTest.test_config2b_failure  r  ri   c                 R    |                      t          | j        | j                   d S r   r  rm   s    rG   r  z#ConfigDictTest.test_config3_failure  r  ri   c                    t          j                    5 }|                     | j                   	 t	                      # t          $ r t          j        d           Y nw xY wt          j        	                    d           | 
                    |                                d           |                     g            d d d            d S # 1 swxY w Y   d S r  )r   r  r|  r  r  r   r  r1  r  r  rY   rW   rh   rC   r  s     rG   r  zConfigDictTest.test_config4_ok  s   $&& 	&&dl+++2"nn$ 2 2 2!.111112JOOAV__..AC C C !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&-   C>ACAACCCc                    t          j                    5 }|                     | j                   	 t	                      # t          $ r t          j        d           Y nw xY wt          j        	                    d           | 
                    |                                d           |                     g            d d d            d S # 1 swxY w Y   d S r  )r   r  r|  config4ar  r   r  r1  r  r  rY   rW   rh   r  s     rG   test_config4a_okzConfigDictTest.test_config4a_ok  s   $&& 	&&dm,,,2"nn$ 2 2 2!.111112JOOAV__..AC C C !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&r  c                 <    |                      | j                   d S r  r  rm   s    rG   r  zConfigDictTest.test_config5_ok  r  ri   c                 R    |                      t          | j        | j                   d S r   )r  rs  r|  r  rm   s    rG   test_config6_failurez#ConfigDictTest.test_config6_failure  s%    )T%6EEEEEri   c                    t          j                    5 }|                     | j                   t	          j        d          }|                    |                                            |                    |                                            | 	                    ddg|           | 	                    g            d d d            n# 1 swxY w Y   t          j                    5 }|                     | j
                   t	          j        d          }|                     |j                   t	          j        d          }|                    |                                            |                    |                                            | 	                    ddg|           | 	                    g            d d d            d S # 1 swxY w Y   d S )Nr  r  r  r  r  r   r   r}   r   )r   r  r|  r  r   r   r   rn   r   rh   r  rB   r   r  s      rG   r  zConfigDictTest.test_config7_ok  sF   $&& 	&&dl+++&'899FKK))++,,,LL**,,---!!#  "   
 !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& $&& 	&&dl+++&'899FOOFO,,,&'788FKK))++,,,LL**,,---!!#  "   
 !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s%   B+CCC)CGGGc                 T   t          j                    5 }|                     | j                   t	          j        d          }|                    |                                            |                    |                                            | 	                    ddg|           | 	                    g            d d d            n# 1 swxY w Y   t          j                    5 }|                     | j
                   t	          j        d          }|                     |j                   |                    |                                            |                    |                                            t	          j        d          }|                    |                                            |                    |                                            | 	                    g d|           | 	                    g            d d d            d S # 1 swxY w Y   d S )Nr  r  r  r  r  )r  r  r   r   r}   r   )r   r  r|  r  r   r   r   rn   r   rh   r  r;  r   r  s      rG   test_config_8_okzConfigDictTest.test_config_8_ok8  s   $&& 	&&dl+++&'899FKK))++,,,LL**,,---!!#  "   
 !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& $&& 	&&dl+++&'899FV_---KK))++,,,LL**,,---&'788FKK))++,,,LL**,,---!! # # #
  "    !!"%%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s%   B+CCC)D'HH!$H!c                    t          j                    5 }|                     | j                   t	          j        d          }t	          j        d          }|                    |                                            |                    |                                            |	                    |                                            | 
                    g d|           | 
                    g            d d d            n# 1 swxY w Y   t          j                    5 }|                     | j                   t	          j        d          }|                     |j                   |                    |                                            |                    |                                            t	          j        d          }|                    |                                            |                    |                                            |	                    |                                            | 
                    g d|           | 
                    g            d d d            d S # 1 swxY w Y   d S r  )r   r  r|  r  r   r   r   rn   r   r  rh   config8ar;  r   r  s       rG   test_config_8a_okz ConfigDictTest.test_config_8a_okY  s   $&& 	&&dm,,,&'899F !*+@AAJKK))++,,,LL**,,--- 1 1 3 3444!! # # # 	 "    !!"%%%'	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&( $&& 	&&dm,,,&'899FV_---KK))++,,,LL**,,---&'788FKK))++,,,LL**,,--- 1 1 3 3444!! # # #
  "    !!"%%%)	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&r  c                    t          j                    5 }|                     | j                   t	          j        d          }|                    |                                            |                     g |           |                     | j	                   |                    |                                            |                     g |           |                     | j
                   |                    |                                            |                     dg|           d d d            d S # 1 swxY w Y   d S )Nr  r  r  )r   r  r|  config9r   r   r   rn   rh   config9aconfig9br  s      rG   test_config_9_okzConfigDictTest.test_config_9_ok  sy   $&& 	&dl+++&'899FKK))++,,,!!"V!444dm,,,KK))++,,,!!"V!444dm,,,KK))++,,,!!# "   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   DD??EEc                    t          j                    5 }|                     | j                   t	          j        d          }|                    |                                            t	          j        d          }|                    |                                            t	          j        d          }|                    |                                            t	          j        d          }|                    |                                            | 	                    ddg|           d d d            d S # 1 swxY w Y   d S Nr  r  r  zcompiler.parser.codegen)r   r|   r  r  )
r   r  r|  config10r   r   r   rn   r   rh   r  s      rG   test_config_10_okz ConfigDictTest.test_config_10_ok  sp   $&& 	&dm,,,&'899FNN4,,..///&z22FNN4,,..///&'788FNN4,,..///&'@AAFLL**,,---!! #  "   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   D EEEc                 :    |                      | j                   d S r   )r  config11rm   s    rG   test_config11_okzConfigDictTest.test_config11_ok  s    T]+++++ri   c                 R    |                      t          | j        | j                   d S r   )r  rs  r|  config12rm   s    rG   test_config12_failurez$ConfigDictTest.test_config12_failure  %    )T%6FFFFFri   c                 R    |                      t          | j        | j                   d S r   )r  rs  r|  config13rm   s    rG   test_config13_failurez$ConfigDictTest.test_config13_failure  r  ri   c                    t          j                    5 }|                     | j                   t          j        d         }|                     |j        d           |                     |j        d           t	          j	        d           | 
                    |                                                    d                     d d d            d S # 1 swxY w Y   d S )Nr  r^  r  ExclamationzExclamation!
)r   r  r|  config14r   r!   rY   r]  r  r   rB   rW   r@  )rC   r  rQ   s      rG   test_config14_okzConfigDictTest.test_config14_ok  s   $&& 	J&dm,,,!'*AQUE***Q\5111OM***OOFOO--667GHHIII	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	J 	Js   B1CCCc                    d }|                                  5  t          j        dd          \  }}t          j        |           ddd|ddid	dgid
}|                     |           |                     |           d d d            n# 1 swxY w Y   t          j        j        d         }| 	                    |||           d S )Nc                 V    |                                   t          j        |           d S r   r  r  s     rG   r  z0ConfigDictTest.test_config15_ok.<locals>.cleanup  r  ri   ri  r  rk   r{  zlogging.FileHandlerr&  )r  filenamer(  r?   r  r?   r  r   )
r  r3  r4  r5  rJ   r|  r   r  r?   r   )rC   r  rH  rI  rw  r   s         rG   test_config15_okzConfigDictTest.test_config15_ok  s/   	 	 	 ++-- 	& 	&%f.?@@FBHRLLL !6$&$+   F f%%%f%%%'	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&* ,'*"-----s   A&B

BBNc                    |                     d          }t          j                            d|          }|                                 |j                                         |j        }|j                                         	 t          j	        t          j
        t          j                  }|                    d           |                    d|f           t          j        dt!          |                    }||z   }d}t!          |          }	|	dk    r-|                    ||d                    }
||
z  }|	|
z  }	|	dk    -|                                 |j                            d           t          j                                         t)          j        |           d S # |j                            d           t          j                                         t)          j        |           w xY w)Nr&  r   g       @r0  r  )r  r   rw  listenrr  r  r  r  rL   r  rJ  SOCK_STREAM
settimeoutconnectr  r*  rZ   sendrJ   stopListeningr   r  )rC   textverifyr  r  r  r  rg   	sentsofarleftsents              rG   setup_via_listenerz!ConfigDictTest.setup_via_listener  s   {{7##N!!!V,,					v		,=1CDDDOOC   LL+t,---;tSYY//DtAIq66D((yy9:://T!	 (( JJLLLGLLN((***(+++++ GLLN((***(++++s   CF& &AG4c                    t          j                    5 }|                     t          j        | j                             t          j        d          }|                    | 	                                           t          j        d          }|                    | 	                                           t          j        d          }|                    | 	                                           t          j        d          }|
                    | 	                                           |                     ddg|           d d d            d S # 1 swxY w Y   d S r  )r   r  r%  jsondumpsr  r   r   r   rn   r   rh   r  s      rG   test_listen_config_10_okz'ConfigDictTest.test_listen_config_10_ok  sz   $&& 	&##DJt}$=$=>>>&'899FNN4,,..///&z22FNN4,,..///&'788FNN4,,..///&'@AAFLL**,,---!! #  "   	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   D2EEEc                    t          j                    5 }|                     t          j        t
          j                             t          j        d          }|	                    | 
                                           |                    | 
                                           |                     ddg|           |                     g            d d d            d S # 1 swxY w Y   d S r  )r   r  r%  ru  rv  rr  r  r   r   r   rn   r   rh   r  s      rG   test_listen_config_1_okz&ConfigDictTest.test_listen_config_1_ok	  s#   $&& 	&&##HON4J$K$KLLL&'899FKK))++,,,LL**,,---!!#  "   
 !!"%%%	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	& 	&s   CC##C'*C'c                 X   d }d }t          j        d          }t          j        t          j                  }t          j                    5 }|                     ||           |	                    | 
                                           |                    | 
                                           d d d            n# 1 swxY w Y   |                     g |           |                     ddgd           t          j                    5 }|                     |           t          j        d          }|	                    | 
                                           |                    | 
                                           d d d            n# 1 swxY w Y   |                     d	d
g|           |                     ddgd           t          j                    5 }|                     |d d d         |           t          j        d          }|	                    | 
                                           |                    | 
                                           d d d            n# 1 swxY w Y   |                     ddg|           |                     ddgd           d S )Nc                     d S r   rt   stuffs    rG   verify_failz6ConfigDictTest.test_listen_verify.<locals>.verify_fail  s    4ri   c                     | d d d         S )Nr*  rt   r.  s    rG   verify_reversez9ConfigDictTest.test_listen_verify.<locals>.verify_reverse  s    2;ri   r  r  r  r  r   )rb   r  r  r*  r  r  )r   r   ru  rv  rr  r  r   r  r%  r   rn   r   rh   )rC   r0  r2  r   to_sendr  s         rG   test_listen_verifyz!ConfigDictTest.test_listen_verify  s   	 	 		 	 	 "#455/."899 $&& 	.&##G[999KK))++,,,LL**,,---		. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	.
 	b000
 + 	 	, 	, 	, $&& 	.&##G,,,&'899FKK))++,,,LL**,,---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	
  	 	 	 	
 	
 + 	 	, 	, 	, $&& 	.&##GDDbDM>BBB&'899FKK))++,,,LL**,,---	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	. 	
  	 	 	 	
 	
 + 	 	, 	, 	, 	, 	,s9   A%B==CCA8FFFBI--I14I1c                 R    |                      t          | j        | j                   d S r   )r  rC  r|  out_of_orderrm   s    rG   test_out_of_orderz ConfigDictTest.test_out_of_orderW  s&    *d&79JKKKKKri   c                 `   t          j        | j                  }d|d         d         d<   |                     |           t	          j        d          j        d         }|                     |j        t          j	                   |                     |j
        j        t          j                   d S )Nz-${asctime} (${name}) ${levelname}: ${message}r  r  r  r  r   )r"   deepcopyr6  r|  r   r   r?   r  rk  r  r  _styleStringTemplateStylerC   rw  r   s      rG   #test_out_of_order_with_dollar_stylez2ConfigDictTest.test_out_of_order_with_dollar_styleZ  s    t011>m|01(;&!!!#J//8;gngo>>>g/6%9	; 	; 	; 	; 	;ri   c                     |                      | j                   t          j        d          j        d         }|                     |j        t                     d S Nr  r   )r|  custom_formatter_class_validater   r   r?   r  r  rm  rC   r   s     rG   )test_custom_formatter_class_with_validatez8ConfigDictTest.test_custom_formatter_class_with_validated  sS    $>???#$EFFOPQRg/1CDDDDDri   c                     |                      | j                   t          j        d          j        d         }|                     |j        t                     d S r?  )r|   custom_formatter_class_validate2r   r   r?   r  r  rm  rA  s     rG   *test_custom_formatter_class_with_validate2z9ConfigDictTest.test_custom_formatter_class_with_validate2i  sS    $?@@@#$EFFOPQRg/1CDDDDDri   c                    | j                                         }d|d         d         d<   |                     |           t          j        d          j        d         }|                     |j        t                     d S )Nr  r  r  r  r  r   )	r@  r"   r|  r   r   r?   r  r  rm  r<  s      rG   9test_custom_formatter_class_with_validate2_with_wrong_fmtzHConfigDictTest.test_custom_formatter_class_with_validate2_with_wrong_fmtn  sz    5::<<14|W%g. 	&!!!#$EFFOPQRg/1CDDDDDri   c                 R    |                      t          | j        | j                   d S r   )r  rC  r|   custom_formatter_class_validate3rm   s    rG   *test_custom_formatter_class_with_validate3z9ConfigDictTest.test_custom_formatter_class_with_validate3w  s&    *d&79^_____ri   c                 R    |                      t          | j        | j                   d S r   )r  rC  r|  custom_formatter_with_functionrm   s    rG   ,test_custom_formatter_function_with_validatez;ConfigDictTest.test_custom_formatter_function_with_validatez  s&    *d&79\]]]]]ri   c                    dg dddddddd	gd
gg dd}t           j                            |          }|                     |                    d          d           |                     |                    d          d           |                     |                    d          d           |                     |                    d          d	           |                     |                    d          d           |                     |                    d          d           |                    d          }|                     |                    d          g d           |                     t          |j        d           |                     t          |j        d           |                     t          |j        d           d S )N)rk   r      )rO  bcr  rO  )rs  r   )g)rQ   rX  jr   lr   r[  )ozcfg://alistp)atuplealistadictnest1nest2nest3zcfg://atuple[1]r   zcfg://alist[1]rP  zcfg://nest1[1][0]rQ   zcfg://nest2[1][1]zcfg://adict.dzcfg://adict[f]zcfg://nest3rk   zcfg://nosuchzcfg://!zcfg://adict[2])	r   rw  BaseConfiguratorrY   convertpopr  KeyErrorrC  )rC   rs  bcr   s       rG   test_baseconfigzConfigDictTest.test_baseconfig}  s   $__Q((+C:s+...
 
 ^,,Q//$566:::$455s;;;$788#>>>$788#>>>O44c:::$455q999JJ}%%q???333(BJ???*bj)<<<(BJ0@AAAAAri   c                    ddl m  G fddt          j                  } dddg          } |dd	g
          }dd||diddgdd}t	          j                    5 }|                     |           t          j        d           d d d            n# 1 swxY w Y   |                     |	                                d           d S )Nr   )
namedtuplec                   ,     e Zd Z fdZ fdZ xZS )1ConfigDictTest.test_namedtuple.<locals>.MyHandlerc                 H     t                      j        |i | || _        d S r   )r  r  resource)rC   rh  rX  rz  r  rd  s       rG   r  z:ConfigDictTest.test_namedtuple.<locals>.MyHandler.__init__  s*      $1&111,4ri   c                     |xj         d| j        j         z  c_         t                                          |          S N )r+  rh  typer  r  )rC   r   r  s     rG   r  z6ConfigDictTest.test_namedtuple.<locals>.MyHandler.emit  s7    

6$-"4666

ww||F+++ri   r  )r  rd  s   @rG   	MyHandlerrf    sW        5 5 5 5 5 5, , , , , , , , ,ri   rm  Resourcerl  labelsmy_typerO  )rl  ro  rk   	myhandler)r  rh  r   r  r  zsome logzsome log my_type
)
collectionsrd  r   r8   r   r  r|  r   rY   rW   )rC   rm  rn  rh  rw  r  rd  s         @rG   test_namedtuplezConfigDictTest.test_namedtuple  sb   ******	, 	, 	, 	, 	, 	, 	,- 	, 	, 	, :j68*<==8C5999 # (   &K=AA	
 	
 $&& 	%&f%%%L$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	**,@AAAAAs    *BBBc                     d }|                      dd|gdd           t          j                    j        d         |u sJ g t          j                    _        d S )Nc                     dS r  rt   )rf  s    rG   r   zAConfigDictTest.test_config_callable_filter_works.<locals>.filter_  s    1ri   rk   r7   r  r  r  r   r|  r   r   r  rC   r   s     rG   !test_config_callable_filter_worksz0ConfigDictTest.test_config_callable_filter_works  s}    	 	 	G	"J"J
 
 	 	 	  ""*1-8888&(###ri   c                     t          j        d          }|                     dd|gdd           t          j                    j        d         |u sJ g t          j                    _        d S )Nr   rk   r7   r  rv  r   )r   r   r|  r   r  rx  s     rG   test_config_filter_worksz'ConfigDictTest.test_config_filter_works  s}    .--G	"J"J
 
 	 	 	  ""*1-8888&(###ri   c                      G d d          } |            }|                      dd|gdd           t          j                    j        d         |u sJ g t          j                    _        d S )Nc                       e Zd Zd ZdS )BConfigDictTest.test_config_filter_method_works.<locals>.FakeFilterc                     dS r  rt   )rC   rf  s     rG   r   zIConfigDictTest.test_config_filter_method_works.<locals>.FakeFilter.filter  s    qri   N)rp   rq   rr   r   rt   ri   rG   
FakeFilterr~    s#            ri   r  rk   r7   r  rv  r   rw  )rC   r  r   s      rG   test_config_filter_method_worksz.ConfigDictTest.test_config_filter_method_works  s    	 	 	 	 	 	 	 	 *,,G	"J"J
 
 	 	 	  ""*1-8888&(###ri   c           	           G d d          }d d |            fD ]*}|                      t          | j        dd|gdd           +d S )Nc                       e Zd ZdS );ConfigDictTest.test_invalid_type_raises.<locals>.NotAFilterNr  rt   ri   rG   
NotAFilterr    s          ri   r  rk   r7   r  rv  )r  rC  r|  )rC   r  r   s      rG   test_invalid_type_raisesz'ConfigDictTest.test_invalid_type_raises  s{    a. 	 	G!gY'O'OPP   	 	ri   c                    ddddddidddgdid	}t          j        d          }|                     |j                   |                     |           |                     |j                   |                     d
di           |                     |j                   |d= |                     |           |                     |j                   d S )Nrk   Fconsoler7   r  )r  r  rO  r  )r  r  r?   r  r  r  )r   r   r;  r   r|  rB   )rC   rw  r   s      rG   
test_90195zConfigDictTest.test_90195  s    (-$4  $!* 
 
  "3'')))&!!!)))9a.)))(((-.&!!!)))))ri   r   )Nrp   rq   rr   rs   r	   r  rV   r  r  r  r  r  r  r  r  rm  r  r  r  r  r  r  r  r  r  r  r   r  r  r
  r  r  r6  r@  rD  rI  rL  r|  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r%  r   requires_working_socketr)  r+  r4  r7  r=  rB  rE  rG  rJ  rM  rb  rs  ry  r{  r  r  r  rt   ri   rG   r  r    s       33 / I, 9
 1%".	 
  !
 
 G. 9
 1%".	 
 !%Y! !
 i
+ G8 9
 1%".	 
 '!
  !
 
) H8 9
 1%"/	 
 !%Y! !
 i
+ G8 9
 1%".	 
 !%Y! !
 i
+ H: 9
 1%".	 
 !%Y! !
 i
+ H8 9
 1/".	 
 !%Y! !
 i
+ G8 "77? 
 1%".	 
 %Y
 
! G0  *? 
  -/? 
 "? 
 
  2%".	  {

 

 %Y
 
7 HF 9
 "%55%".	 
 !%Y! !
 i
+ G: 9
 "%55%".. 
 !%Y! !
 i
- G< 9
 1%".	 
 !%Y   
 i
+ G< %*9
 1%".	 
 "%Y  
 
 i
1 G> %)9
 1%".	 
 "%Y  
 
 i
1 H< 9
 1%#.	 
 #%Y! !
 h
+ G6 )
 &!
 H  &
 &!
 H" 9
 *
 1%".$I 
 !$I! !
  !
 
7 HF 9
 1%".	 
 /4
 !%Y! !
 i
3 HB 9
 1%".	 
 /4
 !%Y! !
 i
1 H> 9
 1%".	 
 /4
 !%Y! !
 i
3 H@ 9
 1%". "' 	 	
  !
 
' H4 M" "
 1 0  :0&  
 
  +,# 
- LB !66>! 
 0$!,	 
 . $I#0 0
#' '#8 !$99>! 
 0$!,	 
 . $I#0 0
#( ($8 !$88>! 
 0$!,	 
 . $I#0 0
#( ($8  >! 
 0$!,	 
 . $I#0 0
#& &"4( ( (& & & &- & & & &F F FG G GG G GF F F& & && & &2 2 2F F F& & &:& & &B)& )& )&V  $  &, , ,G G GG G GJ J J. . .<, , , ,8 %W$&&  '&& %W$&&& & '&& %W$&&<, <, '&<,|L L L; ; ;E E E
E E E
E E E` ` `^ ^ ^B B B,B B B>) ) )) ) )	) 	) 	)  * * * * *ri   r  c                       e Zd Zd Zd ZdS )ManagerTestc                    g  G fddt           j                  }t          j        d           }|                     t          |j        t                     |                    |           |                    d          }|                    d           t          j        d           | 	                    dg           d S )Nc                       e Zd Zd fd	ZdS )6ManagerTest.test_manager_loggerclass.<locals>.MyLoggerNc                 2                         |           d S r   rC  )rC   r  r+  rX  exc_infoextraloggeds         rG   _logz;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._log  s    c"""""ri   ro   )rp   rq   rr   r  )r  s   rG   MyLoggerr    s3        # # # # # # # #ri   r  r  zshould appear in loggedzshould not appear in logged)
r   LoggerManagerr  	TypeErrorsetLoggerClassrR  r   r   rY   )rC   r  manr   r  s       @rG   test_manager_loggerclassz$ManagerTest.test_manager_loggerclass  s    	# 	# 	# 	# 	# 	# 	#w~ 	# 	# 	# od##)S%7===8$$$v&&01115666";!<=====ri   c                     t          j        d           }t                      }|                    |           |                     |j        |           d S r   )r   r  objectsetLogRecordFactoryrY   logRecordFactory)rC   r  re   s      rG   test_set_log_record_factoryz'ManagerTest.test_set_log_record_factory  sM    od##88)))-x88888ri   N)rp   rq   rr   r  r  rt   ri   rG   r  r    s2        > > > 9 9 9 9 9ri   r  c                       e Zd Zd ZdS )ChildLoggerTestc                    t          j                    }t          j        d          }t          j        d          }|                    d          }|                    d          }|                     |t          j        d                     |                     |t          j        d                     |                    d          }|                    d          }|                    d          }|                     |t          j        d                     |                     |t          j        d                     |                     ||           d S )	Nabczdef.ghixyzzuvw.xyzdefghiabc.defzabc.def.ghi)r   r   getChildr  )rC   r   l1l2c1c2c3s          rG   test_child_loggersz"ChildLoggerTest.test_child_loggers  s   u%%y))ZZZZ	""b'+E22333b'+I66777[[[[[[##b'+I66777b'+M::;;;b"ri   N)rp   rq   rr   r  rt   ri   rG   r  r    s#            ri   r  c                       e Zd ZdS )DerivedLogRecordNr  rt   ri   rG   r  r    r  ri   r  c                        e Zd Zd Zd Zd ZdS )LogRecordFactoryTestc                     G d dt           j                  }t                              |             |t                    | _        | j                            | j                   t          j                    | _	        d S )Nc                       e Zd Zd Zd ZdS )2LogRecordFactoryTest.setUp.<locals>.CheckingFilterc                     || _         d S r   )rW  )rC   rW  s     rG   r  z;LogRecordFactoryTest.setUp.<locals>.CheckingFilter.__init__$  s    ri   c                 n    t          |          }|| j        urd|d| j        }t          |          dS )NzUnexpected LogRecord type z, expected T)rl  rW  r  )rC   r   r  r+  s       rG   r   z9LogRecordFactoryTest.setUp.<locals>.CheckingFilter.filter'  sC    LLDH$$$IJ HH&C#C..(tri   N)rp   rq   rr   r  r   rt   ri   rG   CheckingFilterr  #  s2              ri   r  )
r   r   r   rH   r  r   r0   r   getLogRecordFactoryorig_factory)rC   r  s     rG   rH   zLogRecordFactoryTest.setUp"  s    
	 
	 
	 
	 
	W^ 
	 
	 
	 	t$n%566""4;///#799ri   c                     | j                             | j                   t                              |            t          j        | j                   d S r   )r0   r   r   r   rR   r   r  r  rm   s    rG   rR   zLogRecordFactoryTest.tearDown4  sI    %%dk222$#D$566666ri   c                 ,   |                      t          | j        j        |                                            t          j        t                     | j                            |                                            | 	                    dg           d S )N)r  r}   r~   )
r  r  r0   r   rn   r   r  r  r   rh   rm   s    rG   test_logrecord_classz)LogRecordFactoryTest.test_logrecord_class9  s    )T%5%=++--	/ 	/ 	/#$4555t0022333!
 	 	 	 	 	ri   N)rp   rq   rr   rH   rR   r  rt   ri   rG   r  r     sA        : : :$7 7 7
    ri   r  c                       e Zd ZdZd Zd Zd Zd Z ej	         e
ej        d          d          d             Z ej	         e
ej        d          d          d	             Z ej	         e
ej        d          d          d
             ZdS )QueueHandlerTestr   c                    t                               |            t          j        d          | _        t          j                            | j                  | _        d| _        t	          j	        d          | _
        d| j
        _        | j
                            t          j                   | j
                            | j                   d S )Nr*  queF)r   rH   queueQueuer   r?   QueueHandlerque_hdlrrE   r   
que_loggerrM  r6   r   rA   rm   s    rG   rH   zQueueHandlerTest.setUpH  s    t[__
(55djAA	!+E22$)!  111""4=11111ri   c                 l    | j                                          t                              |            d S r   )r  rJ   r   rR   rm   s    rG   rR   zQueueHandlerTest.tearDownR  rO  ri   c                    | j                             |                                            |                     t          j        | j        j                   | j                             |                                            |                     t          j        | j        j                   |                                 }| j                             |           | j                                        }| 	                    t          |t          j                             |                     |j        | j         j                   |                     |j        |j        f|d f           d S r   )r  r   rn   r  r  Empty
get_nowaitr   r   rB   r  r   	LogRecordrY   rE   r+  rX  )rC   r+  r  s      rG   test_queue_handlerz#QueueHandlerTest.test_queue_handlerV  s   d//11222%+tz'<===T..00111%+tz'<===!!$$$z$$&&
4):;;<<<DO$8999$(DI.d<<<<<ri   c                    |                                  }t          j        t          j                  }d}|                    | j        ||          }t          j        | j                  }| j        	                    |           | j
                            |           | j                                        }|                     ||j                   |                     ||j                   d S )Nz {name} -> {levelname}: {message})rE   	levelnamer  )rn   r   r   r   r  rE   r:   r;   r  r=   r  r   r  r  rY   r+  r  )rC   r+  r  log_format_strformatted_msgr  
log_records          rG   test_formattingz QueueHandlerTest.test_formattingb  s    !!(99	;&--498A3 . P P%do66	""9---$$$Z**,,

777
(:;;;;;ri   QueueListenerz5logging.handlers.QueueListener required for this testc                 8   t          t          j                              }t          j                            | j        |          }|                                 	 | j        	                    | 
                                           | j                            | 
                                           | j                            | 
                                           |                                 n# |                                 w xY w|                     |                    t          j        d                     |                     |                    t          j        d                     |                     |                    t          j        d                     |                                 t          t          j                              }|                    t          j                   t          j                            | j        |d          }|                                 	 | j        	                    | 
                                           | j                            | 
                                           | j                            | 
                                           |                                 n# |                                 w xY w|                     |                    t          j        d                     |                     |                    t          j        d                     |                     |                    t          j        d	                     |                                 d S )
Nr|   )r   r  r~   r   T)respect_handler_levelr   r   r   )r
   r   Matcherr   r?   r  r  rr  r  r   rn   r   r  r  rB   matchesr   r}   r{   rJ   r6   r;  )rC   r   listeners      rG   test_queue_listenerz$QueueHandlerTest.test_queue_listenero  s    go//00#11$*gFF	O##D$5$5$7$7888O!!$"3"3"5"5666O$$T%6%6%8%8999MMOOOOHMMOOOOMMNNNsKKLLL0@#NNOOO go//00)***#11$*gHL 2 N N	O##D$5$5$7$7888O!!$"3"3"5"5666O$$T%6%6%8%8999MMOOOOHMMOOOO#NNOOOLLMMM0@#NNOOOs   BC4 4D
8BK K'c                    t           j                            | j        | j                  }|                                 	 ddz   nG# t          $ r:}|}| j                            | 	                                |           Y d }~nd }~ww xY w| j        
                    | 	                                d           |                                 |                     | j                                                                                            d          d           |                     | j                                                                                            d          d           d S )Nrk   r   r  T
stack_info	TracebackStack)r   r?   r  r  r9   rr  ZeroDivisionErrorr  r  rn   r   r  rY   r5   rW   r  r  )rC   r  r  excs       rG   &test_queue_listener_with_StreamHandlerz7QueueHandlerTest.test_queue_listener_with_StreamHandler  sW    #11$*dnMM	IEEE  	I 	I 	ICO%%d&7&7&9&9C%HHHHHHHH	I 	d//11dCCC--//5577==kJJANNN--//5577==gFFJJJJJs    A 
B
0BB
c                    | j                             | j                   | j                            | j                   t          j                            | j	        | j                   }|
                                 | j                            d           |                                 |                     | j                                                                        d           d S )Nr   zque -> ERROR: error)r  r=   r<   r  rA   r9   r   r?   r  r  rr  r   r  rY   r5   rW   r  )rC   r  s     rG   *test_queue_listener_with_multiple_handlersz;QueueHandlerTest.test_queue_listener_with_multiple_handlers  s     	""4#6777""4>222#11$*dmLLg&&&--//55779NOOOOOri   N)rp   rq   rr   rV   rH   rR   r  r  r  
skipUnlessr"  r   r?   r  r  r  rt   ri   rG   r  r  C  s0        32 2 2     
= 
= 
=< < < X!1?CCPR R R RB X!1?CCPR RK KR RK X!1?CCPR R	P 	PR R	P 	P 	Pri   r  r  )patchc                       e Zd ZdZdZed             Z ej        e	j
        j        d          d             Z ej        e	j
        j        d          d             Zed             Zd Zd	 Zd
S )QueueListenerTestz~
        Tests based on patch submitted for issue #27930. Ensure that
        QueueListener handles all log messages.
           c                    t          j        d|z            }|                    t           j                   t           j                            |           }|                    |           t           j                            |           }|                                 |	                    d           |	                    d           |	                    d           |	                    d           |	                    d           |
                                 |                    |           |                                 dS )z
            Creates a logger with a QueueHandler that logs to a queue read by a
            QueueListener. Starts the listener, logs five messages, and stops
            the listener.
            ztest_logger_with_id_%sonetwothreefourfiveN)r   r   r6   r7   r?   r  rA   r  rr  r   r  rK   rJ   )	log_queuer>  r   r   r  s        rG   setup_and_logzQueueListenerTest.setup_and_log  s
    &'?%'GHHFOOGM***&33I>>Gg&&&'55i@@HNNKKKKKK   KKKKMMOOO  )))MMOOOOOri   r:  c                     t          | j                  D ]B}t          j                    }|                     ||                                 d|           C|                     |j        d| j        z  d           d S Nrf  r  z&correct number of handled log messages)r^  repeatr  r  r  ry  rY   
call_countrC   mock_handlerX  r  s       rG   #test_handle_called_with_queue_queuez5QueueListenerTest.test_handle_called_with_queue_queue  s    4;'' H H!KMM	""9AA.FGGGG[3Q_EG G G G Gri   c                 r   t          j                     t          | j                  D ]j}t	          j                    }|                     ||                                 d|           |                                 |	                                 k| 
                    |j        d| j        z  d           d S r  )r   *skip_if_broken_multiprocessing_synchronizer^  r  multiprocessingr  r  ry  rJ   r  rY   r  r  s       rG    test_handle_called_with_mp_queuez2QueueListenerTest.test_handle_called_with_mp_queue  s     >@@@4;'' ( (+133	""9AA.FGGG!!!%%''''[3Q_EG G G G Gri   c              #   f   K   	 	 |                                  V  # t          j        $ r g cY S w xY wr   )r  r  r  )r  s    rG   get_all_from_queuez$QueueListenerTest.get_all_from_queue  sS      1#..000001;   			s    00c                    t          j                     t          | j                  D ]}t	          j                    }|                     ||                                 d|           t          | 	                    |                    } |j
                      |j                     g t          j        j        j        gg}|                     ||dd |D             z             dS )a  
            Five messages are logged then the QueueListener is stopped. This
            test then gets everything off the queue. Failure of this test
            indicates that messages were not registered on the queue until
            _after_ the QueueListener stopped.
            rf  z&Found unexpected messages in queue: %sc                 T    g | ]%}t          |t          j                  r|j        n|&S rt   )r  r   r  r+  )rW  r   s     rG   rY  zJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>  sC     %< %< %<01 /9G<M.N.N &,QUU*+%< %< %<ri   N)r   r  r^  r  r  r  r  ry  listr   rJ   r  r   r?   r  	_sentinelr  )rC   rX  r  r   re   s        rG   $test_no_messages_in_queue_after_stopz6QueueListenerTest.test_no_messages_in_queue_after_stop  s     >@@@4;'' > >'-//""5DGGIIIIqq*ABBBT44U;;<<!!###!1!?!I JKeXF%< %<5:%< %< %<=> > > >> >ri   c                 H   t          j                    }t          j                            |          }|                                 |                                 |                     t                    5  |	                                 d d d            d S # 1 swxY w Y   d S r   )
r  r  r   r?   r  rr  r  r  rC  	task_done)rC   r  r  s      rG   test_calls_task_done_after_stopz1QueueListenerTest.test_calls_task_done_after_stop	  s    I'55i@@HNNMMOOO"":.. & &##%%%& & & & & & & & & & & & & & & & & &s   5BBBN)rp   rq   rr   rs   r  staticmethodr  r  r  r   r?   r  r  r  r   r  r  rt   ri   rG   r  r    s        	 	
 		 	 
	. 
g&4h	?	?	G 	G 
@	?	G 
g&4h	?	?
	G 
	G 
@	?
	G 
	 	 
		> 	> 	>0	& 	& 	& 	& 	&ri   r  c                       e Zd Zd ZeZd ZdS )UTCc                     t           S r   )ZEROrC   dts     rG   	utcoffsetzUTC.utcoffset  s    ri   c                     dS )Nr  rt   r  s     rG   tznamez
UTC.tzname  s    uri   N)rp   rq   rr   r  dstr  rt   ri   rG   r  r    s9           C    ri   r  c                       e Zd Zd ZdS )AssertErrorMessagec                     	  | j         dg|R i | d S # |$ r.}|                     |t          |                     Y d }~d S d }~ww xY w)Nrt   )r  rY   rV  )rC   r  r  rX  rz  r  s         rG   assert_error_messagez'AssertErrorMessage.assert_error_message#  s}    	.Db24222622222 	. 	. 	.Wc!ff---------	.s    A#AAN)rp   rq   rr   r  rt   ri   rG   r  r  !  s#        . . . . .ri   r  c                   R    e Zd Zd ZddZd Zd Zd Zd Zd Z	d	 Z
d
 Zd Zd ZdS )FormatterTestc           	          dt           j        t          j                            ddd          dd d ddd| _        d	d	d
ii| _        d S )Nzformatter.testr<  toz	dummy.extr  zMessage with %d %s)r   placeholders)rE   r  pathnamelinenor  funcr+  rX  customi  )r   r7   r5  r<  r   commonvariantsrm   s    rG   rH   zFormatterTest.setUp*  sX    $]VT;??''	
 	
 $
ri   Nc                     t          | j                  }| |                    | j        |                    t	          j        |          S r   )r  r!  rM   r"  r   r   )rC   rE   results      rG   
get_recordzFormatterTest.get_record;  sA    dk""MM$--...$V,,,ri   c                    |                                  }t          j        d          }|                     |                    |          d           t          j        d          }|                     t          |j        |           |                     |                                           t          j        d          }| 	                    |                                           t          j        d          }| 	                    |                                           t          j        d          }| 	                    |                                           d S )Nz${%(message)s}z${Message with 2 placeholders}z
%(random)s%(asctime)sz%(asctime)-15sz%(asctime)#15s
r%  r   r:   rY   r  r  rC  r;  usesTimerB   rC   r   r   s      rG   test_percentzFormatterTest.test_percentA  s   OO.//!&FGGGl++*ah222&&&m,,

%%%.//

%%%.//

%%%%%ri   c                    |                                  }t          j        dd          }|                     |                    |          d           t          j        dd          }|                     t          |j        |           t          j        dd          }|                     |                                           t          j        dd          }| 	                    |                                           t          j        dd          }| 	                    |                                           t          j        d	d          }| 	                    |                                           d S )
Nz$%{message}%${r  $%Message with 2 placeholders%$z{random}z	{message}	{asctime}z{asctime!s:15}z{asctime:15}r(  r*  s      rG   test_braceszFormatterTest.test_bracesP  s;   OOoS999!&GHHHj444*ah222k555&&&k555

%%%.c:::

%%%nC888

%%%%%ri   c                 L   |                                  }t          j        dd          }|                     |                    |          d           t          j        dd          }|                     |                    |          d           t          j        dd          }|                     |                    |          d           t          j        dd          }|                     t          |j        |           |                     |                                           t          j        d	d          }| 	                    |                                           t          j        d
d          }| 	                    |                                           t          j        dd          }|                     |                                           t          j        dd          }| 	                    |                                           d S )N
${message}r  r.  zMessage with 2 placeholdersz$messagez$$%${message}%$$r/  z	${random}z
${asctime}z$asctimez${asctime}--r(  r*  s      rG   test_dollarszFormatterTest.test_dollars`  s   OOl#666!&CDDDj444!&CDDD0<<<!&GHHHk555*ah222&&&l#666

%%%j444

%%%l#666&&&nC888

%%%%%ri   c                 h   t          j        d          }|                     |j        d           t          j        d          }|                     |j        d           t          j        d          }|                     |j        d           t          j        d          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        d	d          }|                     |j        d	           t          j        d
d          }|                     |j        d
           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           t          j        dd          }|                     |j        d           |                     t
          t           j        d           |                     t
          t           j        d           |                     t
          t           j        d           |                     t
          t           j        d           |                     t
          t           j        d           |                     t
          t           j        d           |                     t
          t           j        d           |                     t
          t           j        d            |                     t
          t           j        d!           |                     t
          d"t           j        d#d           |                     t
          d$t           j        d%d           |                     t
          d&           |                     t
          t           j        d'd           |                     t
          d(t           j        d)d           |                     t
          d*t           j        d+d           |                     t
          t           j        d,d           |                     t
          t           j        d-d           |                     t
          t           j        d.d           |                     t
          t           j        d/d           |                     t
          d0t           j        d1d           |                     t
          d2t           j        d3d           |                     t
          t           j        d4d           |                     t
          t           j        d5d           |                     t
          t           j        d6d           |                     t
          t           j        d7d           |                     t
          t           j        d8d           |                     t
          t           j        d9d           |                     t
          t           j        d:d           |                     t
          t           j        d;d           |                     t
          t           j        d<d           |                     t
          d=t           j        d>d           |                     t
          d=t           j        d?d           |                     t
          d=t           j        d@d           |                     t
          d$t           j        dd           |                     t
          t           j        d%d           |                     t
          d$t           j        dAd           |                     t
          t           j        dBd           d S )CNzM%(levelname)-15s - %(message) 5s - %(process)03d - %(module) - %(asctime)*.3sz1%(asctime)*s - %(asctime)*.3s - %(process)-34.33oz%(process)#+027.23Xz
%(foo)#.*gz5$%{message}%$ - {asctime!a:15} - {customfield['key']}r-  r.  z{process:.2f} - {custom.f:.4f}z{customfield!s:#<30}z{message!r}z{message!s}z{message!a}z{process!r:4.2}z8{process!s:<#30,.12f}- {custom:=+#30,.1d} - {module:^30}z{process!s:{w},.{p}}z{foo:12.{p}}z{foo:{w}.6}z{foo[0].bar[1].baz}z{foo[k1].bar[k2].baz}z{12[k1].bar[k2].baz}z${asctime} - $messager  z$bar $$z	$bar $$$$z%(asctime)Zz%(asctime)bz%(asctime)*z%(asctime)*3sz%(asctime)_r0  r3  z%(foo)#12.3*fz%(foo)0*.8*fz;invalid format: invalid field name/expression: 'name-thing'z{name-thing}zinvalid format: no fieldsr'  zinvalid conversion: 'Z'z{asctime!s:#30,15f}z7invalid format: expected ':' after conversion specifierz{asctime!aa:15}z%invalid format: bad specifier: '.2ff'z{process:.2ff}z{process:.2Z}z{process!s:<##30,12g}z{process!s:<#30#,12g}z{process!s:{{w}},{{p}}}z1invalid format: expected '}' before end of stringz{processz7invalid format: Single '}' encountered in format stringzprocess}z{{foo!r:4.2}z{{foo!r:4.2}}z	{foo/bar}z{foo:{{w}}.{{p}}}}z{foo!X:{{w}}.{{p}}}z{foo!a:random}z{foo!a:ran{dom}z{foo!a:ran{d}om}z
{foo.!a:d}z$invalid format: bare '$' not allowedz$bar $$$zbar $zfoo $.r]  z	${asctime)r   r:   rY   _fmtr  rC  r  rC   r   s     rG   test_format_validatez"FormatterTest.test_format_validateu  s    mnn!pqqqQRR!TUUU344!6777l++... U]`aaa!XYYY>cJJJ!ABBB4C@@@!7888m3777///m3777///m3777////s;;;!2333X`cddd![\\\4C@@@!7888nC888000m3777///33???!67775SAAA!89994C@@@!7888 5SAAA!8999is333+++k555--- 	*g&7GGG*g&7GGG*g&7GGG*g&7III*g&7GGG*g&7EEE*g&7FFF*g&7III*g&7HHH 	!!I~S 	" 	
 	
 	
 	!!'}C 	" 	
 	
 	
 	!!%	
 	
 	
 	*g&79NVYZZZ!!E0 	" 	
 	
 	
 	!!3/s 	" 	
 	
 	

 	*g&7PSTTT*g&79PX[\\\*g&79PX[\\\*g&79RZ]^^^!!?z 	" 	
 	
 	

 	!!Ez 	" 	
 	
 	

 	*g&7sSSS*g&7PSTTT*g&7CPPP*g&79MUXYYY*g&79NVYZZZ*g&79IQTUUU*g&79JRUVVV*g&79KSVWWW*g&7SQQQ 	!!4z 	" 	
 	
 	

 	!!4wc 	" 	
 	
 	

 	!!4xs 	" 	
 	
 	
 	!!'{# 	" 	
 	
 	

 	*g&7cRRR 	!!'uC 	" 	
 	
 	

 	*g&7CPPPPPri   c                    g d}g d}t          ||          D ]<\  }}t          j        ||ddi          }|                                 }|                     |                    |          d           |                     d          }|                     |                    |          d           t          j        ||          }|                                 }|                     t          |j        |           t          j        ||d	di          }|                     d          }|                     |                    |          d           >d S )
N)z%(custom)s %(message)sz{custom} {message}z$custom $message)%r-  r  r   Default)r  r  z#Default Message with 2 placeholdersz 1234 Message with 2 placeholdersr.  zNon-existing)r[   r   r:   r%  rY   r  r  rC  )rC   fmtsstylesr  r  r   r   s          rG   test_defaults_parameterz%FormatterTest.test_defaults_parameter  sR   SSS dF++ 	N 	NJC!#Uh	=RSSSA!!AQXXa[[*OPPP))AQXXa[[*LMMM !#U333A!!Aj!(A666 !#Uni=XYYYA))AQXXa[[*LMMMM	N 	Nri   c                 V    |                      t          t          j        d d d           d S )Nx)r  rC  r   r:   rm   s    rG   test_invalid_stylez FormatterTest.test_invalid_style  s'    *g&7tSIIIIIri   c           
      H   |                                  }t          j        dddddddt                    }t          j        |                    d                                                     |_        d|_        t          j
        d          }t          j        |_        |                     |                    |          d	           |                     |                    |d
          d           |                    |           |                     |j        d	           d S )N  r]        rO  r   {   %(asctime)s %(message)sz1993-04-21 08:03:00,123z%Y:%dz1993:21)r%  datetimeutcr_  mktime
astimezone	timetuplecreatedmsecsr   r:   gmtime	converterrY   
formatTimer  asctime)rC   r   r  r   s       rG   	test_timezFormatterTest.test_time"  s    OOtQAq!Q<< Kd 3 3 = = ? ?@@	788ka*CDDDa119===	$=>>>>>ri   c           
          G d dt           j                  }|                                 }t          j        ddddddd	t                    }t          j        |                    d                                                     |_	         |            }t
          j
        |_        |                     |                    |          d
           d S )Nc                       e Zd ZdZdZdS )DFormatterTest.test_default_msec_format_none.<locals>.NoMsecFormatterNz%d/%m/%Y %H:%M:%S)rp   rq   rr   default_msec_formatdefault_time_formatrt   ri   rG   NoMsecFormatterrV  1  s        "&"5ri   rY  rC  r]  rD  rE  rO  r   rF  z21/04/1993 08:03:00)r   r:   r%  rH  rI  r_  rJ  rK  rL  rM  rO  rP  rY   rQ  )rC   rY  r   r  r   s        rG   test_default_msec_format_nonez+FormatterTest.test_default_msec_format_none0  s    	6 	6 	6 	6 	6g/ 	6 	6 	6 OOtQAq!S#>>Kd 3 3 = = ? ?@@	Oka*?@@@@@ri   c                    t          j        ddd          }t          d          D ]]}t          j        d           t          j        dd|d	z   z  i          }|                    |          }|                     d
|           ^d S )Nz!{asctime}.{msecs:03.0f} {message}r-  z%Y-%m-%d %H:%M:%S)r  r  r  i	  g-C6:?r+  z
Message %drk   z.1000)r   r:   r^  r_  ra  r   r  assertNotIn)rC   r   rX  r   rg   s        rG   test_issue_89047zFormatterTest.test_issue_89047<  s    "ESZmnnnt 	) 	)AJv%ula!e.D&EFFAAWa((((		) 	)ri   r   )rp   rq   rr   rH   r%  r+  r1  r4  r8  r>  rA  rS  rZ  r]  rt   ri   rG   r  r  )  s        
 
 
"- - - -& & && & & & & &*TQ TQ TQlN N N(J J J? ? ?
A 
A 
A) ) ) ) )ri   r  c                       e Zd Zd Zd ZdS )TestBufferingFormatterc                 &    dt          |          z  S )Nz[(%d)rZ   rC   recordss     rG   formatHeaderz#TestBufferingFormatter.formatHeaderF      W%%ri   c                 &    dt          |          z  S )Nz(%d)]ra  rb  s     rG   formatFooterz#TestBufferingFormatter.formatFooterI  re  ri   N)rp   rq   rr   rd  rg  rt   ri   rG   r_  r_  E  s2        & & && & & & &ri   r_  c                        e Zd Zd Zd Zd ZdS )BufferingFormatterTestc                 h    t          j        ddi          t          j        ddi          g| _        d S )Nr+  r  r  )r   r   rc  rm   s    rG   rH   zBufferingFormatterTest.setUpM  s3    !5%.11!5%.11
ri   c                     t          j                    }|                     d|                    g                      |                     d|                    | j                             d S )Nr   onetwo)r   BufferingFormatterrY   r  rc  r7  s     rG   test_defaultz#BufferingFormatterTest.test_defaultS  sZ    &((QXXb\\***188DL#9#9:::::ri   c                     t                      }|                     d|                    | j                             t	          j        d          }t          |          }|                     d|                    | j                             d S )Nz[(2)onetwo(2)]z<%(message)s>z[(2)<one><two>(2)])r_  rY   r  rc  r   r:   )rC   r   lfs      rG   test_customz"BufferingFormatterTest.test_customX  sz    "$$)188DL+A+ABBB//"2&&-qxx/E/EFFFFFri   N)rp   rq   rr   rH   rn  rq  rt   ri   rG   ri  ri  L  sF        
 
 
; ; ;
G G G G Gri   ri  c                       e Zd Zd ZdS )ExceptionTestc                    | j         }t                      }|                    |           	 t          d          #  t	          j        dd           Y nxY w|                    |           |                                 |j        d         }| 	                    |j
                            d                     | 	                    |j
                            d                     | 	                    |j                            d                     | 	                    |j                            d	                     d S )
Nr  failedTr  r   z#Traceback (most recent call last):
z!
RuntimeError: deliberate mistakeStack (most recent call last):
z,logging.exception('failed', stack_info=True))r0   RecordingHandlerrA   r  r   r  rK   rJ   rc  rB   exc_textr  r@  r  )rC   r   rQ   s      rG   r  zExceptionTest.test_formatting`  s`   	Q	93444	9h4888888					IaL
-- /> ? ? 	@ 	@ 	@
++ -A B B 	C 	C 	C// 1> ? ? 	@ 	@ 	@-- /? @ @ 	A 	A 	A 	A 	As	   ; AN)rp   rq   rr   r  rt   ri   rG   rs  rs  _  s(        A A A A Ari   rs  c                       e Zd Zd ZdS )LastResortTestc                 R   | j         }|                    | j                   t          j        }t          j        }	 t          j                    5 }|                    d           | 	                    |
                                d           |                    d           | 	                    |
                                d           d d d            n# 1 swxY w Y   d t          _        t          j                    5 }|                    d           d}| 	                    |
                                |           d d d            n# 1 swxY w Y   t          j                    5 }|                    d           | 	                    |
                                d           d d d            n# 1 swxY w Y   d|j        _        dt          _        t          j                    5 }|                    d           | 	                    |
                                d           d d d            n# 1 swxY w Y   |                    | j                   |t          _        |t          _        d S # |                    | j                   |t          _        |t          _        w xY w)NzThis should not appearr   zFinal chance!zFinal chance!
z-No handlers could be found for logger "root"
F)r0   rK   r9   r   
lastResortr  r   r  r   rY   rW   r   r   emittedNoHandlerWarningrA   )rC   r  old_lastresortold_raise_exceptionsr  r+  s         rG   test_last_resortzLastResortTest.test_last_resortv  sJ   4>*** +&6	;(** Gf

3444  !2!2B777_---  !2!24EFFF	G G G G G G G G G G G G G G G "&G(** 9f_---F  !2!2C8889 9 9 9 9 9 9 9 9 9 9 9 9 9 9 (** 8f_---  !2!2B7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8
 49DL0&+G#(** 8f_---  !2!2B7778 8 8 8 8 8 8 8 8 8 8 8 8 8 8 OODN+++!/G&:G### OODN+++!/G&:G#::::s   I2 A;C	I2 CI2 C"I2 ?A E?I2 EI2 EI2 )>F3'I2 3F77I2 :F7;.I2 )>H3'I2 3H77I2 :H7;I2 24J&N)rp   rq   rr   r  rt   ri   rG   rz  rz  u  s#        #; #; #; #; #;ri   rz  c                       e Zd Zd Zd ZdS )FakeHandlerc           
      \    dD ](}t          | ||                     |||                     )d S )N)r  flushrJ   r  )setattrrecord_call)rC   
identifiercalledrK  s       rG   r  zFakeHandler.__init__  sF    > 	P 	PFD&$"2"2:vv"N"NOOOO	P 	Pri   c                     fd}|S )Nc                  Z                          d                                         d S )Nz{} - {})rC  r  )r  r  method_names   rG   innerz&FakeHandler.record_call.<locals>.inner  s+    MM)**:{CCDDDDDri   rt   )rC   r  r  r  r  s    ``` rG   r  zFakeHandler.record_call  s4    	E 	E 	E 	E 	E 	E 	Eri   N)rp   rq   rr   r  r  rt   ri   rG   r  r    s5        P P P    ri   r  c                   $     e Zd Z fdZd Z xZS )rw  c                 V     t          t          |           j        |i | g | _        d S r   )r  rw  r  rc  )rC   rX  rz  r  s      rG   r  zRecordingHandler.__init__  s1    .%%.????ri   c                 :    | j                             |           dS )z&Keep track of all the emitted records.N)rc  rC  r   s     rG   r:  zRecordingHandler.handle  s    F#####ri   )rp   rq   rr   r  r:  r  r  s   @rG   rw  rw    sG            $ $ $ $ $ $ $ri   rw  c                   |     e Zd ZdZ fdZd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Z xZS )ShutdownTestz#Test suite for the shutdown method.c                     t          t          |                                            g | _        t          j        }|                     t          t          d|           d S )Nr  )r  r  rH   r  r   r  r   r  )rC   raise_exceptionsr  s     rG   rH   zShutdownTest.setUp  sO    lD!!'')))"2*;=MNNNNNri   c                     fd}|S )Nc                                    r   rt   )r   s   rG   r  z'ShutdownTest.raise_error.<locals>.inner  s    %''Mri   rt   )rC   r   r  s    ` rG   raise_errorzShutdownTest.raise_error  s!    	 	 	 	 	ri   c                 J   t          d| j                  }t          d| j                  }t          d| j                  }t          t          j        j        |||g          }t          j        t          |                     g d}|                     || j                   d S )Nr   rk   r   handlerList)z2 - acquirez	2 - flushz	2 - closez2 - releasez1 - acquirez	1 - flushz	1 - closez1 - releasez0 - acquirez	0 - flushz	0 - close0 - release)	r  r  r  r   rz  r{  r  r  rY   )rC   handler0handler1handler2r?   re   s         rG   test_no_failurezShutdownTest.test_no_failure  s    q$+..q$+..q$+.. w*Xx,JKKT(^^4444L L L 	4;/////ri   c                 >   t          d| j                  }t          |||                     |                     t          j                            |          g}t	          j        t          |                     | 	                    d| j        d                    d S )Nr   r  r  r*  )
r  r  r  r  r   rz  r{  r  r  rY   )rC   rK  r   r   r?   s        rG   _test_with_failure_in_methodz)ShutdownTest._test_with_failure_in_method  s    a--!1!1%!8!8999O''001T(^^4444B88888ri   c                 <    |                      dt                     d S Nr  r  rB  rm   s    rG   test_with_ioerror_in_acquirez)ShutdownTest.test_with_ioerror_in_acquire  s    )))W=====ri   c                 <    |                      dt                     d S Nr  r  rm   s    rG   test_with_ioerror_in_flushz'ShutdownTest.test_with_ioerror_in_flush      ))'7;;;;;ri   c                 <    |                      dt                     d S NrJ   r  rm   s    rG   test_with_ioerror_in_closez'ShutdownTest.test_with_ioerror_in_close  r  ri   c                 <    |                      dt                     d S r  r  rC  rm   s    rG   test_with_valueerror_in_acquirez,ShutdownTest.test_with_valueerror_in_acquire  s    )))Z@@@@@ri   c                 <    |                      dt                     d S r  r  rm   s    rG   test_with_valueerror_in_flushz*ShutdownTest.test_with_valueerror_in_flush      ))':>>>>>ri   c                 <    |                      dt                     d S r  r  rm   s    rG   test_with_valueerror_in_closez*ShutdownTest.test_with_valueerror_in_close  r  ri   c                 T    dt           _        |                     dt                     d S )NFr  r   r  r  
IndexErrorrm   s    rG   .test_with_other_error_in_acquire_without_raisez;ShutdownTest.test_with_other_error_in_acquire_without_raise  s&    "')))Z@@@@@ri   c                 T    dt           _        |                     dt                     d S )NFr  r  rm   s    rG   ,test_with_other_error_in_flush_without_raisez9ShutdownTest.test_with_other_error_in_flush_without_raise  &    "'))':>>>>>ri   c                 T    dt           _        |                     dt                     d S )NFrJ   r  rm   s    rG   ,test_with_other_error_in_close_without_raisez9ShutdownTest.test_with_other_error_in_close_without_raise  r  ri   c                 l    dt           _        |                     t          | j        dt                     d S )NTr  r   r  r  r  r  rm   s    rG   +test_with_other_error_in_acquire_with_raisez8ShutdownTest.test_with_other_error_in_acquire_with_raise  s8    "&*d&G#Z	1 	1 	1 	1 	1ri   c                 l    dt           _        |                     t          | j        dt                     d S )NTr  r  rm   s    rG   )test_with_other_error_in_flush_with_raisez6ShutdownTest.test_with_other_error_in_flush_with_raise  8    "&*d&G!:	/ 	/ 	/ 	/ 	/ri   c                 l    dt           _        |                     t          | j        dt                     d S )NTrJ   r  rm   s    rG   )test_with_other_error_in_close_with_raisez6ShutdownTest.test_with_other_error_in_close_with_raise  r  ri   )rp   rq   rr   rs   rH   r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  s   @rG   r  r    s*       --O O O O O  
0 0 0 9 9 9> > >< < << < <A A A? ? ?? ? ?A A A? ? ?? ? ?1 1 1
/ / /
/ / / / / / /ri   r  c                   h    e Zd ZdZd ZddZd Zd Zd Zd Z	d	 Z
d
 Zd Zd Zd Zd Zd Zd ZdS )ModuleLevelMiscTestz)Test suite for some module level methods.c                    t           j        j        j        }|                     |d           |                     t           j        |           t          j        d           |                     t           j        j        j        d           |                     t          t           j        d            G d d          }|                     t          t           j         |                       t          j        d           t          j                     |                     t           j        j        j        t           j	                   d S )Nr   S   doesnotexistsc                       e Zd ZdS );ModuleLevelMiscTest.test_disable.<locals>._NotAnIntOrStringNr  rt   ri   rG   _NotAnIntOrStringr            Dri   r  WARN)
r   r  r   rN   rY   r   r  rC  r  r{   )rC   old_disabler  s      rG   test_disablez ModuleLevelMiscTest.test_disable  s   l*2a(((555-5r:::*goGGG	 	 	 	 	 	 	 	 	)W_6G6G6I6IJJJ 	-5w7GHHHHHri   Nc                 ~   g t          j        | t          dfd           t                      }t          j                            |           t          t          |          }| ||d|           n |d|           |                     t          |j	                  d           |j	        d         }|                     |
                                d|z             ||n&t          t          |                                          }|                     |j        |           |                     g            d S )NbasicConfigc                  2                         | |f          S r   r  )rO  kwr  s     rG   <lambda>z/ModuleLevelMiscTest._test_log.<locals>.<lambda>(  s    v}}aW'='= ri   ztest me: %rrk   r   )r   r  r   rw  r  rA   r,   rY   rZ   rc  
getMessageupperr   )rC   rK  r  	recording
log_methodr   expected_levelr  s          @rG   	_test_logzModuleLevelMiscTest._test_log%  s:   dG]====	? 	? 	? %&&		***Wf--
JumY7777J}i000Y.//333"1%**,,mi.GHHH"'"3&,,..9Y9Y888 	$$$$$ri   c                 F    |                      dt          j                   d S Nr   )r  r   r}   rm   s    rG   test_logzModuleLevelMiscTest.test_log=  s    ugm,,,,,ri   c                 0    |                      d           d S Nr   r  rm   s    rG   
test_debugzModuleLevelMiscTest.test_debug@      wri   c                 0    |                      d           d S Nr   r  rm   s    rG   	test_infozModuleLevelMiscTest.test_infoC      vri   c                 0    |                      d           d S Nr   r  rm   s    rG   test_warningz ModuleLevelMiscTest.test_warningF      y!!!!!ri   c                 0    |                      d           d S Nr   r  rm   s    rG   
test_errorzModuleLevelMiscTest.test_errorI  r  ri   c                 0    |                      d           d S Nr  r  rm   s    rG   test_criticalz!ModuleLevelMiscTest.test_criticalL      z"""""ri   c                    |                      t          t          j        t                      G d dt          j                  }t          j        |           |                     t          j                    |           t          j        t          j                   |                     t          j                    t          j                   d S )Nc                       e Zd ZdS );ModuleLevelMiscTest.test_set_logger_class.<locals>.MyLoggerNr  rt   ri   rG   r  r  R  r  ri   r  )r  r  r   r  r  r  rY   getLoggerClass)rC   r  s     rG   test_set_logger_classz)ModuleLevelMiscTest.test_set_logger_classO  s    )W%;VDDD	 	 	 	 	w~ 	 	 	 	x(((/118<<<w~.../117>BBBBBri   c                 T   g  G fddt          j                              }t          j        |           t          j        d          }|                     dg           t          j                    }t          j        |          }|                    |           	 |	                    t           j
                   |                    d           |                     |                                                                d           |                    d           |                    d           |	                    t           j                   |                    d           |                     |                                d           |                    |           |                                 t          j        t           j                   d S # |                    |           |                                 t          j        t           j                   w xY w)Nc                   2     e Zd Zdej        f fd	Z xZS )@ModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLoggerr  c                 v    t                                          ||                               d           d S )Ninitialized)r  r  rC  )rC   rE   r  r  r  s      rG   r  zIModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLogger.__init__`  s5      u---}-----ri   )rp   rq   rr   r   r   r  r  )r  r  s   @rG   r  r  _  sJ        $.gn . . . . . . . . . . .ri   r  just_some_loggerr  hellor   r   )r   r  r  r   rY   r3   r4   r8   rA   r6   r7   r   rW   r  truncater  r   rK   rJ   r  )rC   r  r   r5   rQ   r  s        @rG   test_subclass_logger_cachez.ModuleLevelMiscTest.test_subclass_logger_cache[  s   	. 	. 	. 	. 	. 	. 	.w-// 	. 	. 	.
 	x((("#566=/222!&))!	3OOGM***LL!!!V__..4466@@@OOAKKNNNOOGL)))LL!!!V__..333  ###GGIII"7>22222   ###GGIII"7>2222s   !C4G A	H'c                     t          j        d          }t          d|          \  }}}|                                }|                     d|           |                     d|           d S )Na*  
            import logging

            class A:
                def __del__(self):
                    try:
                        raise ValueError("some error")
                    except Exception:
                        logging.exception("exception in __del__")

            a = A()
        -czexception in __del__zValueError: some error)ru  rv  r   rn  r  rC   codercouterrs        rG   test_logging_at_shutdownz,ModuleLevelMiscTest.test_logging_at_shutdownz  sl         (d33Cjjll,c222.44444ri   c                 v   t           j        }|                     t           j        |           t	          j        d|d          }t          d|           t          |d          5 }|                     |	                                
                                d           d d d            d S # 1 swxY w Y   d S )Na  
            import builtins
            import logging

            class A:
                def __del__(self):
                    logging.error("log in __del__")

            # basicConfig() opens the file, but logging.shutdown() closes
            # it at Python exit. When A.__del__() is called,
            # FileHandler._open() must be called again to re-open the file.
            logging.basicConfig(filename=z, encoding="utf-8")

            a = A()

            # Simulate the Python finalization which removes the builtin
            # open() function.
            del builtins.open
        r  r&  r~  zERROR:root:log in __del__)r   TESTFNr   r6  ru  rv  r   r  rY   r`   r  )rC   r  r  fps       rG   test_logging_at_shutdown_openz1ModuleLevelMiscTest.test_logging_at_shutdown_open  s    #	((333   +3       & 	t$$$(W--- 	NRWWYY--//1LMMM	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns   &;B..B25B2c                     t          j        d          }t          d|          \  }}}|                                }|                     d|           |                     |d           d S )Nz
            import logging

            def rec():
                logging.error("foo")
                rec()

            rec()
        r  z#Cannot recover from stack overflow.rk   )ru  rv  r   rn  r\  rY   r  s        rG   test_recursion_errorz(ModuleLevelMiscTest.test_recursion_error  so         -T488Cjjll>DDDQri   c                 *   t          j                    }|                     t           j        |           |                     t           j        |           t          j                    }|                     ||           |                     ||           d S r   )r   getLevelNamesMappingrY   r'   assertIsNot)rC   mappingnew_mappings      rG   test_get_level_names_mappingz0ModuleLevelMiscTest.test_get_level_names_mapping  s    .00-w777-w777244+...+.....ri   r   )rp   rq   rr   rs   r  r  r  r  r  r  r  r  r  r   r  r  r  r  rt   ri   rG   r  r  
  s        33I I I.% % % %0- - -       " " "     # # #
C 
C 
C3 3 3>5 5 5&N N N>      / / / / /ri   r  c                   >    e Zd Zd Zd Zedd            Zd Zd ZdS )LogRecordTestc                     t          j        i           }t          |          }|                     |                    d                     |                     |                    d                     d S )Nz<LogRecord: >)r   r   rV  rB   r  r@  )rC   r   rg   s      rG   test_str_repzLogRecordTest.test_str_rep  s]    !"%%FF^44555

3(((((ri   c                    t                      }t          j                    }|                    |           ddi}t          j        d|           |                     |j        d         j        |           |                     |j        d         j	        d           |
                    |           |                                 d S )Nlessmorezless is %(less)sr   zless is more)rw  r   r   rA   r   r  rc  rX  rY   r  rK   rJ   )rC   rQ   r   rs  s       rG   test_dict_argzLogRecordTest.test_dict_arg  s    	Qf*A...ail'+++1-~>>>							ri   Nc                    t           j        }|t           _        	 dd l}|                                j        }t          j        dd|  i          }t          j        t          j	        dd           5  t          j        dd|  i          }d d d            n# 1 swxY w Y   ||j
        |j
        d}|t           _        n# |t           _        w xY w|r|                    |           d S |S )Nr   r+  msg1_r  msg2_)processNamer1.processNamer2.processName)r   logMultiprocessingr  current_processrE   r   r   	swap_itemr1  modulesr!  r  )	r|  r$  r  prev_logMultiprocessingmprE   r1r2resultss	            rG   _extract_logrecord_process_namez-LogRecordTest._extract_logrecord_process_name  sR   ")"<%7"	A((((%%'',D&}s}}'=>>B "3;0A4HH C C*E=3==+ABBC C C C C C C C C C C C C C C )-)+)+ G
 *AG&&)@G&@@@@ 	IIgNs0   AB> 0B
B> BB> BB> >Cc                 r   t          j                     dt          j        v }	 |                     t
          j        d           d}t          j        i           }|                     |j        d           | 	                    d|          }|                     d|d                    |                     d|d                    |                     d|d                    dd l
} |j                    \  }} |j        | j	        d	||f
          }|                                 |                                }|                     d|d                    |                     |d         |d                    |                     d|d                    |                                 |rdd l
}d S d S # |rdd l
}w xY w)Nr  TMainProcessrk   r!  r"  r#  r   r   rj  )r   r  r1  r'  rY   r   r$  r   r!  r-  r  PipeProcessrr  r  assertNotEqualr   )	rC   multiprocessing_importedLOG_MULTI_PROCESSINGr   r,  r  parent_conn
child_connrV  s	            rG   test_multiprocessingz"LogRecordTest.test_multiprocessing  s   :<<<#4#C  	'W7>>>#'  %b))AQ]M:::::1>RSSG]GM,BCCC]G4D,EFFF]G4D,EFFF #"""&:o&:&<&<#K'';-z;  A GGIII!&&((Gw}/EFFFW]3W=M5NOOO]G4D,EFFFFFHHH ( '&&&&&&' '' '&&&&&&&&s   FF. .F6c                    t          j        i           }| j        } ||j                    ||j                    ||j                    ||j                   t           j        }t           j        }t           j	        }	 dt           _        dt           _        dt           _	        t          j        i           }| j
        } ||j                    ||j                    ||j                    ||j                   |t           _        |t           _        |t           _	        d S # |t           _        |t           _        |t           _	        w xY w)NF)r   r   assertIsNotNonerh  
threadNameprocessr!  
logThreadslogProcessesr$  r  )rC   r   NOT_NONElog_threadslog_processeslog_multiprocessingNONEs          rG   test_optionalzLogRecordTest.test_optional  s7   !"%%'(,%8	=!&G#(G ).G&%b))A$DDNNNDDOOOD!,G#0G )<G&&& "-G#0G )<G&<<<<s   A?D& &&Er   )	rp   rq   rr   r  r  r	  r-  r7  rC  rt   ri   rG   r  r    sq        ) ) )	 	 	    \0#' #' #'J= = = = =ri   r  c                        e Zd ZdZ fdZ fdZd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZddZd Zd Zd Zd Zd Zd Z xZS )BasicConfigTestz#Test suite for logging.basicConfig.c                 |   t          t          |                                            t          j        j        | _        t          j                                        | _        t          j	        d d          | _
        t          j        j        | _        |                     | j                   g t          j        _        d S r   )r  rE  rH   r   r  r?   r!   r"   r#   r$   r%   r  r2   r   r  r  s    rG   rH   zBasicConfigTest.setUp2  s    ot$$**,,,-%/4466")"6qqq"9&-l&8#%%% "ri   c                     t           j        j        d d          D ]5}t           j                            |           |                                 6t          t          |                                            d S r   )r   r  r?   rK   rJ   r  rE  rR   )rC   rQ   r  s     rG   rR   zBasicConfigTest.tearDown;  sg    &qqq) 	 	AL&&q)))GGIIIIot$$--/////ri   c                 >   t          t          j        d| j                   t          j                                         t          j                            | j                   | j        t          j	        d d <   t          j        
                    | j                   d S )Nr?   )r  r   r  r?   r!   rL   rM   r#   r%   r$   r6   r2   rm   s    rG   r  zBasicConfigTest.cleanupA  sz    j$-888!!!  !4555"&"9QQQd9:::::ri   c                 |   t          j                     |                     t          t           j        j                  d           t           j        j        d         }|                     |t           j                   |                     |j        t          j
                   |j        }|                     |j        j        t           j                   |                     |j                   |                     |j        t           j                   |                     t           j        j        | j                   d S )Nrk   r   )r   r  rY   rZ   r  r?   r  r8   r5   r1  r  r  r:  r6  BASIC_FORMATr  r  PercentStyler  r2   )rC   r   r  s      rG   test_no_kwargszBasicConfigTest.test_no_kwargsH  s     	W\233Q777,'*gw'<===444%	).0DEEE)+,,,i.0DEEE 	+T-HIIIIIri   c                 x   t          j                    5 }t          j        t          j        d           t          j        d           t          j                            d           |                     |	                                
                                d           d d d            d S # 1 swxY w Y   d S )Nr-  r5   r  Log an errorr   ERROR:root:Log an errorr   r  r   r  r1  r  r   r  rY   rW   r  r  s     rG   test_strformatstylez#BasicConfigTest.test_strformatstyle\      $&& 	+&sz====M.)))JOOAV__..4466)+ + +		+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+ 	+   BB//B36B3c                 x   t          j                    5 }t          j        t          j        d           t          j        d           t          j                            d           |                     |	                                
                                d           d d d            d S # 1 swxY w Y   d S )Nr  rN  rO  r   rP  rQ  r  s     rG   test_stringtemplatestylez(BasicConfigTest.test_stringtemplatestyled  rS  rT  c                    d }t          j        dd           |                     t          t           j        j                  d           t           j        j        d         }|                     |t           j                   t          j        ddd          }|                     |j        j	        |j        j	                   |                     |j        j
        |j        j
                   |                     |||d           d S )	Nc                 ~    |                                   |                                  t          j        |           d S r   r  r  h2rI  s      rG   r  z.BasicConfigTest.test_filename.<locals>.cleanupn  -    HHJJJHHJJJIbMMMMMri   test.logr&  )r  r(  rk   r   rO  r~  )r   r  rY   rZ   r  r?   r  rR  r5   moderE   r   rC   r  r   re   s       rG   test_filenamezBasicConfigTest.test_filenamel  s    	 	 	
 	Z'BBBBW\233Q777,'*gw':;;;&z3III,ho.BCCC,ho.BCCC(J?????ri   c                    d }t          j        dd           t           j        j        d         }t          j        dd          }|                     |j        j        |j        j                   |                     |||d           d S )Nc                 ~    |                                   |                                  t          j        |           d S r   r  rY  s      rG   r  z.BasicConfigTest.test_filemode.<locals>.cleanup  r[  ri   r\  wbr  filemoder   )	r   r  r  r?   rR  rY   r5   r]  r   r^  s       rG   test_filemodezBasicConfigTest.test_filemode~  s    	 	 	
 	Z$????,'*&z488,ho.BCCC(J?????ri   c                    t          j                    }|                     |j                   t	          j        |           |                     t          t          j        j	                  d           t          j        j	        d         }| 
                    |t          j                   |                     |j        |           d S )Nr  rk   r   )r3   r4   r   rJ   r   r  rY   rZ   r  r?   r  r8   r5   )rC   r5   r   s      rG   test_streamzBasicConfigTest.test_stream  s    %%%6****W\233Q777,'*gw'<===00000ri   c                     t          j        d           t           j        j        d         j        }|                     |j        j        d           d S )Nz%(asctime)s - %(message)s)r  r   )r   r  r  r?   r  rY   r:  r6  rC   r  s     rG   test_formatzBasicConfigTest.test_format  sL    #>????L)!,6	).0KLLLLLri   c                     t          j        d           t           j        j        d         j        }|                     |j        d           d S )Nr^  )r  r   )r   r  r  r?   r  rY   r  ri  s     rG   test_datefmtzBasicConfigTest.test_datefmt  sG    E****L)!,6	*E22222ri   c                     t          j        d           t           j        j        d         j        }|                     |j        t           j                   d S )Nr  r.  r   )r   r  r  r?   r  r  r:  r;  ri  s     rG   
test_stylezBasicConfigTest.test_style  sJ    #&&&&L)!,6	i.0KLLLLLri   c                 Z   t           j        j        }|                     t           j        j        |           t          j        d           |                     t           j        j        d           t          j        d           |                     t           j        j        d           d S )N9   )r  :   )r   r  r  r   r6   r  rY   )rC   	old_levels     rG   
test_levelzBasicConfigTest.test_level  s    L&	-y999"%%%%+R000"%%%%+R00000ri   c                    | j         }t          j                    g}t          j        } |t
          t          j        d|            |t
          t          j        d|            |t
          t          j        ||            |t
          t          j        t          j                   t          j        d d           d S )Nr\  )r  r5   )r  r?   )r5   r?   )loglevelrO  rc  )r  r   r8   r1  r  rC  r  r   )rC   r  r?   r5   s       rG   test_incompatiblez!BasicConfigTest.test_incompatible  s    ()++,Z!4z=C	E 	E 	E 	EZ!4z?G	I 	I 	I 	IZ!4V?G	I 	I 	I 	I 	Z!4w|LLLLTC888888ri   c                 R   t          j                    t          j        t          j                  t          j                    g}t          j                    }|d                             |           t          j        |           |                     |d         t           j        j	        d                    |                     |d         t           j        j	        d                    |                     |d         t           j        j	        d                    | 
                    |d         j                   | 
                    |d         j                   |                     |d         j        |           |                     |d         j        |d         j                   d S )Nr   )r?   r   rk   )r   r8   r1  r  r:   r=   r  r  r  r?   r9  r  )rC   r?   r   s      rG   test_handlerszBasicConfigTest.test_handlers  sL   !##!#*--!##

   ###X....hqk7<#8#;<<<hqk7<#8#;<<<hqk7<#8#;<<<Xa[2333Xa[2333hqk+Q///hqk+Xa[-BCCCCCri   c                    t          j                    }t          j                    }t          j        |          g}t          j        |          g}t          j        t          j        |           t          j        d           t          j        d           t          j        d           | 	                    t          t          j        j                  d           t          j        t          j        |d           t          j        d           t          j        d           t          j        d           | 	                    t          t          j        j                  d           | 	                    |                                                                d           | 	                    |                                                                d	           d S )
Nr  r  r   r   rk   T)r  r?   forcezWARNING:root:warnz WARNING:root:warn
INFO:root:info)r3   r4   r   r8   r  r   r   r   r   rY   rZ   r  r?   r   rW   r  )rC   old_string_ionew_string_ioold_handlersnew_handlerss        rG   
test_forcezBasicConfigTest.test_force  s   -m<<=-m<<='/LIIIIVgW\233Q777',"&	( 	( 	( 	(VgW\233Q777//117799,	. 	. 	.//117799<	> 	> 	> 	> 	>ri   c                    	 d}t          j        d|ddt           j                   |                     t	          t           j        j                  d           t           j        j        d         }|                     |t           j                   |                     |j	        |           t          j
        d           |                                 t          dd	          5 }|                                                                }d d d            n# 1 swxY w Y   t          j        d           |                     |d           d S # |                                 t          dd	          5 }|                                                                }d d d            n# 1 swxY w Y   t          j        d           |                     |d           w xY w)
Nr&  r\  r  %(message)sr  r(  errorsr  r  rk   r   .   The Øresund Bridge joins Copenhagen to Malmör~  r   r  r7   rY   rZ   r  r?   r  rR  r(  r   rJ   r  r`   r  r5  r  rC   r(  r   r   r  s        rG   test_encodingzBasicConfigTest.test_encoding  s:   	OHh'/'4GMK K K K S!677;;;l+A.G!!'7+>???W-x888MJKKKMMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!TMO O O O O	 MMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!TMO O O OB   B=E $'DDD&G4'F'G'F++G.F+/.Gc                    	 d}t          j        d|ddt           j                   |                     t	          t           j        j                  d           t           j        j        d         }|                     |t           j                   |                     |j	        |           t          j
        d           |                                 t          dd	
          5 }|                                                                }d d d            n# 1 swxY w Y   t          j        d           |                     |d           d S # |                                 t          dd	
          5 }|                                                                }d d d            n# 1 swxY w Y   t          j        d           |                     |d           w xY w)Nr  r\  ignorer  r  rk   r   r  r&  r~  z*The resund Bridge joins Copenhagen to Malmr  r  s        rG   test_encoding_errorsz$BasicConfigTest.test_encoding_errors  s   	QHh'/'4GMK K K K S!677;;;l+A.G!!'7+>???W-x888MJKKKMMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!T#OPPPPP	 MMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!T#OPPPPr  c                    	 d}t          j        d|dt           j                   |                     t	          t           j        j                  d           t           j        j        d         }|                     |t           j                   |                     |j	        |           |                     |j
        d           t          j        d           |                                 t          dd	
          5 }|                                                                }d d d            n# 1 swxY w Y   t!          j        d           |                     |d           d S # |                                 t          dd	
          5 }|                                                                }d d d            n# 1 swxY w Y   t!          j        d           |                     |d           w xY w)Nr  r\  r  )r  r(  r  r  rk   r   backslashreplaceu<   😂: ☃️: The Øresund Bridge joins Copenhagen to Malmör&  r~  zL\U0001f602: \u2603\ufe0f: The \xd8resund Bridge joins Copenhagen to Malm\xf6)r   r  r7   rY   rZ   r  r?   r  rR  r(  r  r   rJ   r  r`   r  r5  r  r  s        rG   test_encoding_errors_defaultz,BasicConfigTest.test_encoding_errors_default  sV   	KHh'4GMK K K K S!677;;;l+A.G!!'7+>???W-x888W^-?@@@MXYYYMMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!T $J K K K K K	 MMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!T $J K K K KsB   CE( >'D11D58D5(&G7'G5G7GG7G	.G7c                 t   	 d}t          j        d|d dt           j                   |                     t	          t           j        j                  d           t           j        j        d         }|                     |t           j                   |                     |j	        |           | 
                    |j                   g fd}||_        t          j        d           |                                |                     d	d                    |                                 t#          dd
          5 }|                                                                }d d d            n# 1 swxY w Y   t)          j        d           |                     |d           d S # |                                 t#          dd
          5 }|                                                                }d d d            n# 1 swxY w Y   t)          j        d           |                     |d           w xY w)Nr  r\  r  r  rk   r   c                 z    t          j                    \  }}}                    t          |                     d S r   )r1  r  rC  rV  )r   rf  r   r  s      rG   dummy_handle_errorzEBasicConfigTest.test_encoding_errors_none.<locals>.dummy_handle_error2  s2    ,..1as1vv&&&&&ri   r  z:'ascii' codec can't encode character '\xd8' in position 4:r&  r~  r   )r   r  r7   rY   rZ   r  r?   r  rR  r(  r  r  r  r   rB   r  rJ   r  r`   r  r5  r  )rC   r(  r   r  r   r  r  s         @rG   test_encoding_errors_nonez)BasicConfigTest.test_encoding_errors_none"  s   	(Hh'+'4GMK K K K S!677;;;l+A.G!!'7+>???W-x888gn---G' ' ' ' ' #5GMJKKKOOG$$$MM =>EajJ J J MMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!T3''''' MMOOOj7333 (qvvxx~~''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Ij!!!T3''''sB   DF( >'E11E58E5(&H7'H5H7HH7H	.H7Nc                      g t           j         fd}t          j         t           d|           t	          t           |          }| ||d           n |d                                di fg           d S )Nc                                    t           j        j        }t           j                            d                               t           j        j        |                               | |f           d S )Nd   )r   r  r  r6   r   rC  )rO  r  rr  r  old_basic_configrC   s      rG   my_basic_configz2BasicConfigTest._test_log.<locals>.my_basic_configI  sg    *IL!!#&&&OOGL19===MM1b'"""""ri   r  ztest mert   )r   r  r   r  r,   rY   )rC   rK  r  r  r  r  r  s   `    @@rG   r  zBasicConfigTest._test_logD  s    ".	# 	# 	# 	# 	# 	# 	# 	dG]ODDDWf--
Jui((((Jy!!! 	2r(,,,,,ri   c                 F    |                      dt          j                   d S r  )r  r   r   rm   s    rG   r  zBasicConfigTest.test_log[  s    ugo.....ri   c                 0    |                      d           d S r  r  rm   s    rG   r  zBasicConfigTest.test_debug^  r  ri   c                 0    |                      d           d S r  r  rm   s    rG   r  zBasicConfigTest.test_infoa  r  ri   c                 0    |                      d           d S r  r  rm   s    rG   r  zBasicConfigTest.test_warningd  r  ri   c                 0    |                      d           d S r  r  rm   s    rG   r  zBasicConfigTest.test_errorg  r  ri   c                 0    |                      d           d S r  r  rm   s    rG   r  zBasicConfigTest.test_criticalj  r  ri   r   ) rp   rq   rr   rs   rH   rR   r  rL  rR  rV  r_  re  rg  rj  rl  rn  rs  rv  rx  r  r  r  r  r  r  r  r  r  r  r  r  r  r  s   @rG   rE  rE  .  s       --# # # # #0 0 0 0 0; ; ;J J J(+ + ++ + +@ @ @$@ @ @1 1 1M M M3 3 3M M M1 1 19 9 9D D D"> > >*O O O(Q Q Q&K K K(( ( (D- - - -./ / /       " " "     # # # # # # #ri   rE  c                   B     e Zd Z fdZd Zd Zd Zd Zd Zd Z	 xZ
S )LoggerAdapterTestc                 @   t          t          |                                            t          j        d d          t                      | _        t          j        | _        | j        	                    | j                   | 
                    | j        j        | j                   | 
                    | j        j                   fd}| 
                    |           | 
                    t          j                   t          j        | j        d           | _        d S )Nc                  *     t           j        d d <   d S r   )r   r$   )old_handler_lists   rG   r  z(LoggerAdapterTest.setUp.<locals>.cleanupy  s    &6G ###ri   r   r  )r  r  rH   r   r$   rw  r  r  r   rA   r   rK   rJ   r  r   adapter)rC   r  r  r  s     @rG   rH   zLoggerAdapterTest.setUpo  s    &&,,..."/2)++lt~...14>BBB,---	7 	7 	7 	7 	7 	   ())),DKtLLLri   c                    d}d }	 ddz   n9# t           $ r,}|}| j                            || j                   Y d }~nd }~ww xY w|                     t          | j        j                  d           | j        j        d         }|                     |j        t          j	                   |                     |j
        |           |                     |j        | j        f           |                     |j        |j        ||j        f           d S Nztesting exception: %rrk   r   )r  r  r  r  rY   rZ   rc  r   r   r}   r+  rX  r  r  __traceback__rC   r+  r  r  r   s        rG   test_exceptionz LoggerAdapterTest.test_exception  s&   %	8EEE  	8 	8 	8CL""377777777	8 	T^344a888'*777S)))t~&7888-c.?@	B 	B 	B 	B 	B    
A"=Ac                 L   	 ddz   n# t           $ r}|}Y d }~nd }~ww xY w| j                            d|           |                     t	          | j        j                  d           | j        j        d         }|                     |j        |j        ||j	        f           d S )Nrk   r   zexc_info testr  )
r  r  r  rY   rZ   r  rc  r  r  r  )rC   r  r  r   s       rG   test_exception_excinfoz(LoggerAdapterTest.test_exception_excinfo  s    	EEE  	 	 	CCCCCC	 	===T^344a888'*-c.?@	B 	B 	B 	B 	Bs    
c                    d}| j                             || j                   |                     t	          | j        j                  d           | j        j        d         }|                     |j        t          j                   |                     |j	        |           |                     |j
        | j        f           d S )Nzcritical test! %rrk   r   )r  r  r  rY   rZ   rc  r   r   r{   r+  rX  )rC   r+  r   s      rG   r  zLoggerAdapterTest.test_critical  s    !c4>222T^344a888'*)9:::S)))t~&788888ri   c                    | j         j        j        j        }d| j         j        j        _        |                     t
          | j         j        j        d|           |                     | j                             d                     d S )N!   rN       )r  r   r   rN   r   r  r;  isEnabledForrC   r  s     rG   test_is_enabled_forz%LoggerAdapterTest.test_is_enabled_for  ss    l)19.0#+!4!<i#	% 	% 	%2226677777ri   c                 `   |                      | j                                                   | j        j        D ]}| j                            |           |                     | j                                                   |                     | j                                                   d S r   )rB   r  r>   r   r?   rK   r;  rA  s     rG   test_has_handlersz#LoggerAdapterTest.test_has_handlers  s    0022333{+ 	/ 	/GK%%g....0022333113344444ri   c                     G d dt           j                  }d} || j        d           } ||d           }d|_        |                     t          |          t          |                     |                    t           j        || j                   |                     t          | j        j
                  d           | j        j
        d         }|                     |j        t           j                   |                     |j        d|            |                     |j        | j        f           |j        }|                     |j        |           |                     | j        j        |           t!                      }	 ||_        |                     |j        |           |                     |j        |           |                     | j        j        |           ||_        n# ||_        w xY w|                     |j        |           |                     |j        |           |                     | j        j        |           d S )	Nc                       e Zd ZdZd ZdS ).LoggerAdapterTest.test_nested.<locals>.AdapterAdapterc                     | j          d| |fS rj  r   )rC   r+  rz  s      rG   r;  z6LoggerAdapterTest.test_nested.<locals>.Adapter.process  s    +----v55ri   N)rp   rq   rr   r   r;  rt   ri   rG   r  r    s(        F6 6 6 6 6ri   r  zAdapters can be nested, yo.r  AdapterAdapterrk   r   zAdapter AdapterAdapter )r   r   r   r   rY   r  r   r{   r  rZ   rc  r   r+  rX  r   r  r  )rC   r  r+  r  adapter_adapterr   orig_managertemp_managers           rG   test_nestedzLoggerAdapterTest.test_nested  s2   	6 	6 	6 	6 	6g+ 	6 	6 	6 ,'D999!'===!1g_(=(=>>>G,c4>BBBT^344a888'*)9:::%Ds%D%DEEEt~&7888&.go|444dk)<888xx	3&2O#MM/1<@@@MM'/<888MM$+-|<<<&2O##lO#2222o-|<<<go|444dk)<88888s   AG0 0	G9)rp   rq   rr   rH   r  r  r  r  r  r  r  r  s   @rG   r  r  n  s        M M M M M"B B B"B B B9 9 98 8 85 5 59 9 9 9 9 9 9ri   r  c                   ~     e Zd Z fdZd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd Zd Zd Zd Zd Z xZS )
LoggerTestc                    t          t          |                                            t                      | _        t          j        d          | _        | j                            | j                   | 	                    | j        j
        | j                   | 	                    | j        j                   | 	                    t
          j                   d S )NblahrE   )r  r  rH   rw  r  r   r  r   rA   r   rK   rJ   r  r  s    rG   rH   zLoggerTest.setUp  s    j$%%''')++n&111t~...14>BBB,---()))))ri   c                     |                      t          d| j        j        d            |                      t          d| j        j        d           d S )Nz,Level not an integer or a valid string: Nonez.Level not an integer or a valid string: (0, 0))r   r   )r  r  r   r6   rm   s    rG   test_set_invalid_levelz!LoggerTest.test_set_invalid_level  s^    !!EK $	( 	( 	( 	!!GK &	* 	* 	* 	* 	*ri   c                    d}d }	 ddz   n9# t           $ r,}|}| j                            || j                   Y d }~nd }~ww xY w|                     t          | j        j                  d           | j        j        d         }|                     |j        t          j	                   |                     |j
        |           |                     |j        | j        f           |                     |j        |j        ||j        f           d S r  )r  r   r  r  rY   rZ   rc  r   r   r}   r+  rX  r  r  r  r  s        rG   r  zLoggerTest.test_exception  s&   %	7EEE  	7 	7 	7CK!!#t~66666666	7 	T^344a888'*777S)))t~&7888-c.?@	B 	B 	B 	B 	Br  c                     t          j        t          dd          5  |                     t          | j        j        dd           d d d            d S # 1 swxY w Y   d S )Nr  Tr   test message)r   	swap_attrr   r  r  r   r   rm   s    rG   !test_log_invalid_level_with_raisez,LoggerTest.test_log_invalid_level_with_raise  s    w(94@@ 	P 	Pi$OOO	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	P 	Ps   (AAAc                     t          j        t          dd          5  | j                            dd           d d d            d S # 1 swxY w Y   d S )Nr  Fr   r  )r   r  r   r   r   rm   s    rG   test_log_invalid_level_no_raisez*LoggerTest.test_log_invalid_level_no_raise  s    w(95AA 	2 	2KOOD.111	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2 	2s   AA	A	c                    g t          j        | t          j        dfd           | j                            d           |                     t                    d           |                     dd                    d S )Nprint_stackc                 R                         |                                          S r   )rC  rW   )r   r{  r  s     rG   r  z=LoggerTest.test_find_caller_with_stack_info.<locals>.<lambda>	  s    fmmDMMOO&D&D ri   Tr  rk   rv  r   )r   r  r   	tracebackr   
findCallerrY   rZ   )rC   r  s    @rG    test_find_caller_with_stack_infoz+LoggerTest.test_find_caller_with_stack_info  s    dG-}DDDD	F 	F 	F 	$///Va(((;VAYGGGGGri   c                     d| j         j        fdfdfd}| j        j        } |             |                     |d         j        d           |d         j        }dz   |             |                     |d         j        d           |                     |d         j        |           |d         j        }dz   |             |                     |d         j        d           |                     |d         j        |           |d         j        }t          j	                    }|
                    | j                   t          j         |             |                     |d         j        d           |                    | j                   | j         j        dz   |             |                     |d         j        d	           |                     |d         j        |           d S )
Nrk   c                  "     d            d S )Nr  )
stacklevelrt   )	the_leveltriggers   rG   	innermostz>LoggerTest.test_find_caller_with_stacklevel.<locals>.innermost  s    GFy111111ri   c                                     d S r   rt   )r  s   rG   r  z:LoggerTest.test_find_caller_with_stacklevel.<locals>.inner  s    IKKKKKri   c                                     d S r   rt   )r  s   rG   outerz:LoggerTest.test_find_caller_with_stacklevel.<locals>.outer  s    EGGGGGri   r*  r  r  r   test_find_caller_with_stacklevel)r   r   r  rc  rY   rb  r  r  r   r   rA   rK   )	rC   r  rc  r  r0   r  r  r  r  s	        @@@@rG   r  z+LoggerTest.test_find_caller_with_stacklevel  s!   	+%	2 	2 	2 	2 	2 	2	 	 	 	 		 	 	 	 	 .(-{;;;#Q	-w77772;-v666#Q	-w77772;-v666#'))t~.../-w777!!$.111+%Q	-/QRRR72;-v66666ri   c                     d}d}d x}x}x}x}x}x}}	t          j        |||||||||		  	        }
dt          |
j                                                  z   D ]5}|di}|                     t          | j        j        |||||||||	           6d S )N	my record   )r  rR  
some valuer  sinfo)	r   _logRecordFactoryr^   __dict__keysr  r`  r   
makeRecord)rC   rE   r  rI  lnor+  rX  r  r  r  rvr|  r  s                rG   %test_make_record_with_extra_overwritez0LoggerTest.test_make_record_with_extra_overwrite7  s    :>>>S>3>>>4%&tUBS$'/u> > *E"+2B2B2D2D,E,EE 	8 	8C,'Eh(>e #sD($)  8 8 8 8	8 	8ri   c                     d}d}d x}x}x}x}x}x}}	ddi}
| j                             ||||||||
|		  	        }|                     d|j                   d S )Nr  r  	valid_keyr  r  )r   r  r  r  )rC   rE   r  rI  r  r+  rX  r  r  r  r  r$  s               rG   (test_make_record_with_extra_no_overwritez3LoggerTest.test_make_record_with_extra_no_overwriteD  s    :>>>S>3>>>4%l+''eRc4(0U ( L Lk6?33333ri   c                    |                      | j                                                   | j        j        D ]}| j                            |           |                     | j                                                   d S r   )rB   r   r>   r?   rK   r;  rA  s     rG   r  zLoggerTest.test_has_handlersM  sw    //11222{+ 	/ 	/GK%%g....002233333ri   c                     t          j        d          }d|_        |                     |                                           d S )Nz
blah.childF)r   r   rM  r;  r>   )rC   child_loggers     rG   test_has_handlers_no_propagatez)LoggerTest.test_has_handlers_no_propagateT  s@    (66!&113344444ri   c                     | j         j        j        }d| j         j        _        |                     t          | j         j        d|           |                     | j                             d                     d S )N   rN      )r   r   rN   r   r  r;  r  r  s     rG   r  zLoggerTest.test_is_enabled_forY  sc    k)1&(#!4iMMM11"5566666ri   c                 f   | j         j        }| j         j        j        }d| j         _        d| j         j        _        |                     t
          | j         d|           |                     t
          | j         j        d|           |                     | j                             d                     d S )NTrD  r   rN   r  )r   r   r   rN   r   r  r;  r  )rC   old_disabledr  s      rG   #test_is_enabled_for_disabled_loggerz.LoggerTest.test_is_enabled_for_disabled_logger_  s    {+k)1#&(#j,GGG!4iMMM11"5566666ri   c                    t          j                    }|                     |t           j                   |                     |t          j        d                      |                     |t          j        d                     |                     |t          j        d                     |                     |t          j        d          j                   |                     |t          j        d          j                   |                     |t          j        d          j                   |                     |t          j        d                     |                     |t          j        d          j                   d S )Nr   r  r]  foo.bar )r   r   r  r  parentr  )rC   r  s     rG   test_root_logger_aliasesz#LoggerTest.test_root_logger_aliasesk  s4    ""dGL)))dG-d33444dG-b11222dG-f55666dG-e449:::dG-i88=>>>dG-e44;<<<w066777w0;;BCCCCCri   c                     |                      t          t          j        t                     |                      t          t          j        d           d S )Ns   foo)r  r  r   r   anyrm   s    rG   test_invalid_nameszLoggerTest.test_invalid_namesx  s>    )W%6<<<)W%6?????ri   c                     t          t          j        dz             D ]Z}dD ]U}t          j        |          }t          j        ||          }t          j        |          }|                     ||           V[d S )Nrk   )r   r  r]  r  zbaz.bar)r^  r  HIGHEST_PROTOCOLr   r   r(  r	  r  )rC   protorE   r   rg   	unpickleds         rG   test_picklingzLoggerTest.test_pickling|  s    62Q677 	1 	1EA 1 1 *400L//"LOO	i0000	1	1 	1ri   c                 
   | j         }t          j        d          }t          j        d          }|                    t          j                   |                     |                                t          j                   |                     |j        i            |                     |	                    t          j                             | 
                    |	                    t          j                             |                     |j        t          j        dt          j        di           |                     |j        i            |                     |	                    t          j                             |                     |j        i            |                     |	                    t          j                             |                     |j        t          j        di           |                    t          j                   |                     |                                t          j                   |                     |j        i            | 
                    |	                    t          j                             |                    t          j                   |                     |                                t          j                   |                     |j        i            |                     |j        i            |                     |j        i            | 
                    |	                    t          j                             |                     |	                    t          j                             | 
                    |	                    t          j                             |                     |	                    t          j                             |                     |	                    t          j                             t          j                     |                     |                                t          j                   |                     |j        i            |                     |j        i            |                     |j        i            | 
                    |	                    t          j                             | 
                    |	                    t          j                             | 
                    |	                    t          j                             d S )Nr  r  TF)r0   r   r   r6   r}   rY   r1   _cacherB   r  r;  r7   r{   r   rN   )rC   r  r.   r/   s       rG   test_cachingzLoggerTest.test_caching  s%   #E**#I.. 	gm$$$2244gmDDD,,, 	,,W];;<<<--gm<<==='-w}e)TUUUb))),,W];;<<< 	b)))))'-88999w}d&;<<< 	)***2244g6FGGG,,, 	--gm<<=== 	(((2244g6FGGG,,,,,,b))) 	--gm<<===,,W-=>>???--gm<<===,,W-=>>???))'-88999 	2244g6FGGG,,,,,,b))) 	--g.>??@@@--g.>??@@@**7+;<<=====ri   )rp   rq   rr   rH   r  r  r  r  r  r  r  r  r  r  r  r  r  r   r  r  r  r  s   @rG   r  r    s8       * * * * ** * *B B B"P P P2 2 2H H H%7 %7 %7N8 8 84 4 44 4 45 5 5
7 7 7
7 
7 
7D D D@ @ @1 1 16> 6> 6> 6> 6> 6> 6>ri   r  c                   *    e Zd ZdZd Zd Zd Zd ZdS )BaseFileTestz1Base class for handler tests that write log filesc                     t                               |            t          j        dd          \  }| _        t          j        |           g | _        d S )Nri  ztest_logging-2-)r   rH   r3  r4  rI  r5  rJ   rmfiles)rC   rH  s     rG   rH   zBaseFileTest.setUp  sE    t&v/@AADG
ri   c                     | j         D ]}t          j        |           t          j                            | j                  rt          j        | j                   t                              |            d S r   )r  r5  r6  r<  r=  rI  r   rR   )rC   rI  s     rG   rR   zBaseFileTest.tearDown  sf    , 	 	BIbMMMM7>>$'"" 	Idg$ri   c                     |                      t          j                            |          d|z             | j                            |           dS )z7Assert a log file is there and register it for deletionzLog file %r does not existr+  N)rB   r5  r<  r=  r  rC  )rC   r  s     rG   assertLogFilezBaseFileTest.assertLogFile  sT    x0088C 	 	E 	E 	EH%%%%%ri   c           
      p    t          j        dt           j        dd|                                 d d d           S )Nr[  rV  rk   )r   r  r7   rn   rm   s    rG   next_reczBaseFileTest.next_rec  s9     gmS!!%!2!2!4!4dD$H H 	Hri   N)rp   rq   rr   rs   rH   rR   r  r  rt   ri   rG   r
  r
    s[        77       & & &H H H H Hri   r
  c                       e Zd Zd Zd ZdS )FileHandlerTestc                 *   t          j        | j                   t          j        | j        dd          }|                     |j                   |                     t           j        	                    | j                             |
                    t          j        i                      |                     |j                   |                     t           j        	                    | j                             |                                 d S )Nr&  Tr'  )r5  r6  rI  r   rR  r  r5   r;  r<  r=  r:  r   r9  rB   rJ   )rC   fhs     rG   
test_delayzFileHandlerTest.test_delay  s    
	$' 7$GGG")$$$00111
		''++,,,RY'''tw//000





ri   c                 P   t          j        | j                   t          j        | j        dd          }|                    t          j        d                     |                    |                                            |	                                 |                    |                                            t          | j                  5 }|                     |                                                                d           d d d            d S # 1 swxY w Y   d S )Nr&  rN  )r(  r]  r  r|   )r5  r6  rI  r   rR  r=   r:   r  r  rJ   r  rY   r`   r  )rC   r  r  s      rG   %test_emit_after_closing_in_write_modez5FileHandlerTest.test_emit_after_closing_in_write_mode  s"   
	$' 7EEE
)-88999
   




   $']] 	5bRWWYY__..444	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5 	5s   ;DD"DN)rp   rq   rr   r  r  rt   ri   rG   r  r    s2          	5 	5 	5 	5 	5ri   r  c                       e Zd Z ej        ej        d          d             Zd Zd Z	d Z
d Z ej                    d             ZdS )	RotatingFileHandlerTestWASI does not have /dev/null.c                    t           j                            | j        dd          }|                     |                    d                      |                                 t           j                            t          j        dd          }|                     |                    | 	                                                     |                                 d S )Nr&  r   r(  maxBytesrk   )
r   r?   rS  rI  r;  shouldRolloverrJ   r5  devnullr  rC   rhs     rG   test_should_not_rolloverz0RotatingFileHandlerTest.test_should_not_rollover  s     11'A 2 7 7**400111



 11
Wq 2 : :**4==??;;<<<





ri   c                     t           j                            | j        dd          }|                     |                    |                                                      |                                 d S )Nr&  rk   r  )r   r?   rS  rI  rB   r   r  rJ   r"  s     rG   test_should_rolloverz,RotatingFileHandlerTest.test_should_rollover  s[    11$'GVW1XX))$--//::;;;





ri   c                     t           j                            | j        d          }|                    |                                            |                     | j                   |                                 d S )Nr&  r~  )r   r?   rS  rI  r  r  r  rJ   r"  s     rG   test_file_createdz)RotatingFileHandlerTest.test_file_created  sb     11$'G1LL
   47###





ri   c                    d }t           j                            | j        ddd          }||_        |                    |                                            |                     | j                   |                    |                                            |                      || j        dz                        |                    |                                            |                      || j        dz                        |                     t          j
                             || j        dz                                  |                                 d S )	Nc                     | dz   S N.testrt   r  s    rG   namerz>RotatingFileHandlerTest.test_rollover_filenames.<locals>.namer  s    '>!ri   r&  r   rk   r(  backupCountr  .1.2.3)r   r?   rS  rI  r-  r  r  r  r;  r5  r<  r=  rJ   )rC   r-  r#  s      rG   test_rollover_filenamesz/RotatingFileHandlerTest.test_rollover_filenames
  s1   	" 	" 	"11Gg1q 2 B B
   47###
   55400111
   55400111dgn(=(=>>???





ri   c                     G d dt           j        j                  } || j        ddd          }|                     |                    | j                  | j        dz              |                    |                                            |                     | j                   |                    |                                            |                     |                    | j        dz             d	z              | 	                    t          j                            |                    | j        dz                                  |                                 d S )
Nc                       e Zd Zd Zd ZdS )ZRotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotatorc                     |dz   S r+  rt   )rC   rE   s     rG   r-  z`RotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotator.namer  s    g~%ri   c                 x    t           j                            |          rt          j        ||dz              d S d S )N.rotated)r5  r<  r=  r  )rC   sourcedests      rG   rotatorzbRotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotator.rotator  s?    7>>&)) :Jvtj'899999: :ri   N)rp   rq   rr   r-  r<  rt   ri   rG   HandlerWithNamerAndRotatorr6    s2        & & &: : : : :ri   r=  r&  r   rk   r.  r,  r0  r9  )r   r?   rS  rI  rY   r-  r  r  r  r;  r5  r<  r=  rJ   )rC   r=  r#  s      rG   test_namer_rotator_inheritancez6RotatingFileHandlerTest.test_namer_rotator_inheritance  s>   	: 	: 	: 	: 	:)9)M 	: 	: 	: ('Gg1qB B B$'**DGg,=>>>
   47###
   288DGdN33j@AAA4(@(@AABBB





ri   c                    d }d }t           j                            | j        ddd          }||_        ||_        |                                 }|                    |           |                     | j                   |                                 }|                    |            || j        dz             }|                     |           t          j
        }t          |d          5 }|                                }	t          j        |	          }
|                     |
                    d	          |j        |z              d d d            n# 1 swxY w Y   |                    |                                             || j        d
z             }|                     |           t          |d          5 }|                                }	t          j        |	          }
|                     |
                    d	          |j        |z              d d d            n# 1 swxY w Y   |                    |                                             || j        d
z             }t          |d          5 }|                                }	t          j        |	          }
|                     |
                    d	          |j        |z              d d d            n# 1 swxY w Y   |                     t          j                             || j        dz                                  |                                 d S )Nc                     | dz   S )Nz.gzrt   r  s    rG   r-  z3RotatingFileHandlerTest.test_rotator.<locals>.namer.  s    %<ri   c                 J   t          | d          5 }|                                }t          j        |d          }t          |d          5 }|                    |           d d d            n# 1 swxY w Y   d d d            n# 1 swxY w Y   t          j        |            d S )NrbrT  rb  )r  r`   zlibcompressr  r5  r  )r:  r;  sfr  
compresseddfs         rG   r<  z5RotatingFileHandlerTest.test_rotator.<locals>.rotator1  s   fd## )rwwyy!]433
$%% )HHZ((() ) ) ) ) ) ) ) ) ) ) ) ) ) )) ) ) ) ) ) ) ) ) ) ) ) ) ) )
 Ifs5   :BA-!B-A1	1B4A1	5BBBr&  r   rk   r.  r0  rB  r  r1  r2  )r   r?   rS  rI  r<  r-  r  r  r  r5  linesepr  r`   rC  
decompressrY   rn  r+  r;  r<  r=  rJ   )rC   r-  r<  r#  m1m2rI  newliner   rF  r  s              rG   test_rotatorz$RotatingFileHandlerTest.test_rotator,  s   	  	  	 	 	 	 11Gg1q 2 B B
]]__
47###]]__
U47T>""2*"d^^ 	EqJ?:..DT[[1126G3CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	   U47T>""2"d^^ 	EqJ?:..DT[[1126G3CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	   U47T>"""d^^ 	EqJ?:..DT[[1126G3CDDD	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	E 	dgn(=(=>>???





s9   -AEEE=AH##H'*H'8AKK"%K"N)rp   rq   rr   r  r  r   is_wasir$  r&  r(  r3  r>  requires_zlibrM  rt   ri   rG   r  r    s        X_W_&EFF  GF  
      & W* * * * *ri   r  c                   j    e Zd Z ej        ej        d          d             Zd Zd Z	d Z
d Zd ZdS )	TimedRotatingFileHandlerTestr  c                 ,   t           j                            t          j        ddd          }t          j        d           t          j        ddi          }|                     |	                    |                     |
                                 d S )NSr&  rk   r(  r/  皙?r+  ztesting - device file)r   r?   rT  r5  r!  r_  ra  r   r;  r   rJ   )rC   r  r   s      rG   r$  z5TimedRotatingFileHandlerTest.test_should_not_rolloverZ  s     66
C'q 7 B B
3!5*A"BCC**1--...





ri   c                    t           j                            | j        ddd          }t          j        d          }|                    |           t          j        ddi          }|                    |           |                     | j                   t          j
        d           t          j        dd	i          }|                    |           |                                 d
}t          j                                        }d}t          |          D ]t}|t          j        |          z
  }	| j        |	                    d          z   t"          j                                      }|r| j                                        nud|z  }
|st"          j                            | j                  \  }fdt#          j        |          D             }t1          d|                    d          z  t2          j                   t1          d|z  t2          j                   |D ]}}t1          d|z             t"          j                            ||          }t9          |d          5 }t1          |                                           d d d            n# 1 swxY w Y   ~|                     ||
           d S )NrS  r&  rk   rT  rG  r+  ztesting - initialrU  ztesting - after delayFi,  secondsz.%Y-%m-%d_%H-%M-%Sz,No rotated files found, went back %d secondsc                 >    g | ]}|                               |S rt   )r  )rW  r   rI  s     rG   rY  z>TimedRotatingFileHandlerTest.test_rollover.<locals>.<listcomp>  s*    CCC1!,,r2B2BCQCCCri   zTest time: %sz%Y-%m-%d %H-%M-%Sr{  zThe only matching files are: %szContents of %s:r   r  )r   r?   rT  rI  r:   r=   r   r  r  r_  ra  rJ   rH  r  r^  	timedeltastrftimer5  r<  r=  r  rC  r   listdirrt  r1  r  r   r  r`   rB   )rC   r  r  r*  r+  foundr  GO_BACKsecsprevr+  dnfilesr   r<  tfrI  s                   @rG   test_rolloverz*TimedRotatingFileHandlerTest.test_rollovere  s   66wA 7 ? ? 9::
"E+>#?@@
47###
3"E+B#CDD




 ##%%'NN 	 	D+D9999D4==)=>>>BGNN2&&E ##B''' =wF 
	%W]]47++FBCCCC
2CCCE/CLL1D$E$EECJWWWW3e;#*MMMM % %'!+,,,w||B**$__ %"''))$$$% % % % % % % % % % % % % % %3'''''s   5"J##J'	*J'	c                    | j         } |t          t          j        j        | j        ddd            |t          t          j        j        | j        ddd            |t          t          j        j        | j        ddd           d S )NXr&  Tr'  WW7)r  rC  r   r?   rT  rI  )rC   r  s     rG   test_invalidz)TimedRotatingFileHandlerTest.test_invalid  s    (Z!1!JWcG4	A 	A 	A 	AZ!1!JWcG4	A 	A 	A 	AZ!1!JWdWD	B 	B 	B 	B 	B 	Bri   c           	         d}t          j        ddd          }t          j                            | j        ddddd|          }	 |                    |          }|                     ||dz              |                    |d	z             }|                     ||d
z              |                                 d S # |                                 w xY w)Nr      r&  MIDNIGHTrk   Tr(  whenintervalr/  rI  atTime  ж  i@ )	rH  r_  r   r?   rT  rI  computeRolloverrY   rJ   )rC   currentTimerq  r#  rd   s        rG   "test_compute_rollover_daily_attimez?TimedRotatingFileHandlerTest.test_compute_rollover_daily_attime  s    r1a((66GgJPQV 7 % %	''44FV[<%?@@@''l(BCCFV[<%?@@@HHJJJJJBHHJJJJs   AB: :Cc           
         t          t          j                              }||dz  z
  }t          j        ddd          }t          j        |          j        }t          d          D ]f}t          j                            | j	        dd|z  ddd|	          }	 ||k    r	d|z
  |z   }n||z
  }|dz  }|d
z  }||z  }|
                    |          }||k    r:t          dt          j        z             t          dt                      z             |                     ||           ||k    r|dz  }|
                    |dz             }||k    r:t          dt          j        z             t          dt                      z             |                     ||           |                                 O# |                                 w xY wd S )NQ rl  r      r&  zW%drk   Trn  rr  zfailed in timezone: %dzlocal vars: %si:	 rs  )rR  r_  rH  rO  tm_wdayr^  r   r?   rT  rI  rt  rt  timezonelocalsrY   rJ   )	rC   ru  todayrq  wdaydayr#  re   rd   s	            rG   #test_compute_rollover_weekly_attimez@TimedRotatingFileHandlerTest.test_compute_rollover_weekly_attime  s   $)++&&kE11r1a(({5!!)88 	 	C!::'aUV ; ) )B#:: !"D3HH #d
HL(L(E!++E22X%%2T]BCCC*VXX5666  222$;; 00H++EL,@AAX%%2T]BCCC*VXX5666  222







?	 	s   DF66Gc                 @   t          j        d          }|                     t          j        |           g }t
          j                                        }t          d          D ]B}|                    |	                    d                     |t          j
        d          z  }Cd}g }g }|D ]}t          j                            |d|z            }	t          j                            |	d	dd
d          }
|                    |
           |                    d          r |D ]}|                    |d|           d |
_        |D ]}|                    |d|d           |D ]K}t          j                            ||          }	t'          |	d          5 }	 d d d            n# 1 swxY w Y   Lt)          |          D ]S\  }}||         }
|
                                }|                     t/          |          d           |                    d          rUd|z  }	|D ]L}t          j                            |          \  }}|                     |                    |	                     M|D ]}t          j                            |          \  }}|                     |                    d                     |                     |                    |dz             o)|t/          |          dz                                                       Ud S )Nr  r  rH  z%Y-%m-%d_%H-%M-%Sr  rW  )a.bza.b.czd.ezd.e.fz%s.logrg   ry  T)ro  rp  r/  r)  r  z.log.c                 4    |                      dd          dz   S )Nri  r   )r  r  s    rG   r  zKTimedRotatingFileHandlerTest.test_compute_files_to_delete.<locals>.<lambda>  s    T\\&"-E-E-N ri   r   ri  rb  rO  z%s.log.r   )r3  mkdtempr   shutilrmtreerH  r  r^  rC  r\  r[  r5  r<  r   r   r?   rT  r  r-  r  	enumerategetFilesToDeleterY   rZ   r   rB   r@  isdigit)rC   wdtimesr  rX  prefixesrc  rotatorsr   rV  r<  r  rI  r   
candidatesrQ  rs  s                    rG   test_compute_files_to_deletez9TimedRotatingFileHandlerTest.test_compute_files_to_delete  s   _555r***""$$r 	0 	0ALL%899:::($Q////BB3 	< 	<FRF!233A&??IJLMFJ @ L LG OOG$$$  '' < < <ALL!:;;;;< !O N < <ALL!:;;;;<  	 	BR$$Aa !               #8,, 	C 	CIAvqkG 1133JS__a000  '' 
C&# 6 6AGMM!,,EArOOBMM!$4$455556 $ C CAGMM!,,EArOOBKK$7$7888OOBMM&3,$?$? %B$&s6{{Q$7$?$?$A$AC C C CC	C 	Cs    F..F2	5F2	N)rp   rq   rr   r  r  r   rN  r$  re  rj  rv  r  r  rt   ri   rG   rQ  rQ  Y  s        X_W_&EFF  GF(( (( ((TB B B   & & &P.C .C .C .C .Cri   rQ  c                  P    t          j        di | t          j        d          z  S )Nrk   rW  rt   )rH  r[  )r  s    rG   r`  r`    s,    ####x'9!'D'D'DDDri   )rS  rk   )M<   )Hi  )Drx  )rm  rx  W0r]     )dayshoursc                    t           j                            | j        d|ddd          }d}|                    |          }||k    rh|dk    ra	 |j        rt          j        |          }nt          j        |          }|d         }|d	         }|d
         }	t           j        j	        |dz  |z   dz  |	z   z
  }
||
z   }t          d|d|j        dt          j                   t          d|z  t          j                   t          d|z  t          j                   t          d|	z  t          j                   t          d|
z  t          j                   t          d|z  t          j                   n5# t          $ r(}t          d|z  t          j                   Y d }~nd }~ww xY w|                     ||           |                                 d S )Nr&  rk   r   T)r(  ro  rp  r/  rI  g        rm  rO  r]  r  r  zt: z ()rZ  zcurrentHour: %szcurrentMinute: %szcurrentSecond: %szr: %sz
result: %sz exception in diagnostic code: %s)r   r?   rT  rI  rt  rI  r_  rO  	localtime	_MIDNIGHTrt  r1  r  rs  rY   rJ   )rC   ro  expr#  ru  rd   r  currentHourcurrentMinutecurrentSecondr   r$  r  s                rG   test_compute_rolloverr    s   66GgD1!QU 7 W W##K00&== z!!Sv 8 K44 N;77"#A$K$%aDM$%aDM(2{R7G7D8EHJ7K)7* +A )1_FE!!!RVVV43:FFFF+k9
KKKK-=CJOOOO-=CJOOOO'A+CJ7777,/cjAAAAA  S S S<q@szRRRRRRRRRSf%%%





s   D*E< <
F.F))F.ztest_compute_rollover_%sz>win32evtlog/win32evtlogutil/pywintypes required for this test.c                       e Zd Zd ZdS )NTEventLogHandlerTestc                    d}t          j        d |          }t          j        |          }	 t          j                            d          }n7# t          j        $ r%}|j        dk    rt          j
        d           d }~ww xY wt          j        ddi          }|                    |           |                                 |                     |t          j        |                     t           j        t           j        z  }d}d}	t          j        |||	          }
|
D ],}|j        dk    rt'          j        ||          }|d	k    r*d
} d|	z  }|                     ||           d S )NApplicationtest_loggingr  z#Insufficient privileges to run testr+  zTest Log MessageFr  zTest Log Message
Tz3Record not found in event log, went back %d recordsr  )win32evtlogOpenEventLogGetNumberOfEventLogRecordsr   r?   NTEventLogHandler
pywintypesr   winerrorr  SkipTestr   r:  rJ   
assertLessEVENTLOG_BACKWARDS_READEVENTLOG_SEQUENTIAL_READReadEventLog
SourceNamewin32evtlogutilSafeFormatMessagerB   )rC   logtypeelhnum_recsrQ   r  r   flagsr^  r_  eventsr+  s               rG   rA  z NTEventLogHandlerTest.test_basic2  sz   &tW559#>>	 22>BBAA 	 	 	zQ'(MNNN	
 !5*<"=>>					+"H"M"MNNN345)#ug>> 	 	A|~--!3Aw??C,,,ECgM3'''''s   A B A<<BN)rp   rq   rr   rA  rt   ri   rG   r  r  0  s#        ( ( ( ( (ri   r  c                       e Zd Zd ZdS )MiscTestCasec                 F    h d}t          j        | t          |           d S )N>   r  r  Filtererro  
RootLoggerr<  PlaceHolderrK  currentframer=  StrFormatStyler$  r;  )not_exported)r   check__all__r   )rC   r  s     rG   test__all__zMiscTestCase.test__all__U  s3      
 	T7FFFFFFri   N)rp   rq   rr   r  rt   ri   rG   r  r  T  s(        G G G G Gri   r  c                  T    t          j        t          j        dd                     d S )NLC_ALLr   )r  enterModuleContextr   run_with_localert   ri   rG   setUpModuler  a  s&     7" E EFFFFFri   __main__r   )rs   r   logging.handlerslogging.configr  r  r"   rH  rP  r  r3   r  r'  r5  r  rb  rT   r  r  r  r1  r3  test.support.script_helperr   r   r  r   test.supportr   r   r   r	   test.support.logging_helperr
   ru  ro  r_  r  r  rz  http.serverr   r   urllib.parser   r   socketserverr   r   r   r   import_deprecatedr   r   r  r  r  rj  rC  TestCaser   rv   r   SILENTr   TERSEEFFUSIVEr   r  	TALKATIVEr   
CHATTERBOXBORINGr^  r   r   r   r   r   r   r  r  r  r8   r  r  r  r  r  r  r  r  r  r"  r+  r0  r  r  r2  rF  r:   rm  rr  r  r  r  r  r$  r/  r4  rB  IPV6_ENABLEDrF  rL  ru  r  r  r  r  r  r  r  r  r  r  r  r  r  r?   r  unittest.mockr  r  r[  r  tzinfor  rI  r  r  rm  r_  ri  rs  rz  r  r  rw  r  r  r  rE  r  r  r
  r  r  rQ  r`  ro  r  r  r  r  r  r  rp   mainrt   ri   rG   <module>r     s?  " 
                   				 				  				   				    



  N N N N N N N N       " " " " " " & & & & & & ) ) ) ) ) ) ( ( ( ( ( ( 3 3 3 3 3 3          : : : : : : : : + + + + + + + +D D D D D D D D D D D D -?,Z88))'2263333333333333 6 6 6155K5/JJJ6	KKKK 	 	 	D	j' j' j' j' j'x  j' j' j'ZUI UI UI UI UI UI UI UIn<% <% <% <% <%h <% <% <%L 		
eFFQJ'' (*	'**)++,
( + + + + +gn + + +: : : : : : : :V' V' V' V' V' V' V' V'rU2 U2 U2 U2 U2( U2 U2 U2p1 1 1 1 1 1 1 1# # # # #- # # #       '@ '@ '@ '@ '@ '@ '@ '@XG; G; G; G; G;U% G; G; G;T0 0 0 0 06 0 0 0d' ' ' ' '\: ' ' 'R1 1 1 1 1L"4 1 1 1>- - - - -L"4 - - -^ 769 (( ( ( ( (} ( ( (( ( ( ( ( ( ( (
 ! "",,..    h   /. #"@f5 f5 f5 f5 f5 f5 f5 f5R- - - - -* - - -B B B B BX B B BJ ! "",,..W+ W+ W+ W+ W+ W+ W+ /. #"W+r   WWVY//1HII' ' ' ' '- ' ' JI'  ! "",,..>: >: >: >: >:( >: >: /. #">:@ WWVY//1HII' ' ' ' '1 ' ' JI'  ! "",,..IB IB IB IB IB IB IB /. #"IBV WWVY//1HII' ' ' ' '- ' ' JI'  ]/;= =6 6 6 6 6- 6 6= =6 ! "",,..K  K  K  K  K h K  K  /. #"K Z1 1 1 1 1 1 1 1h.L .L .L .L .L8 .L .L .Lb%K %K %K %K %K8 %K %K %KP. . . .       # # #	 	 	 	 	G) 	 	 	S* S* S* S* S*X S* S* S*j(9 9 9 9 9( 9 9 9.    h   "	 	 	 	 	w( 	 	 	         8      F -,..iP iP iP iP iPx iP iP /.iPV 77_-- b&######0022]& ]& ]& ]& ]&H ]& ]& 32]&@ x!    (/    
cee. . . . . . . .Y) Y) Y) Y) Y)H%'9 Y) Y) Y)x& & & & &W7 & & &G G G G GX. G G G&A A A A AH A A A,$; $; $; $; $;X $; $; $;N	 	 	 	 	 	 	 	$ $ $ $ $w* $ $ $T/ T/ T/ T/ T/8 T/ T/ T/nx/ x/ x/ x/ x/( x/ x/ x/vg= g= g= g= g=H g= g= g=R}# }# }# }# }#h' }# }# }#@
i9 i9 i9 i9 i9) i9 i9 i9X`> `> `> `> `>- `> `> `>FH H H H H8 H H H45 5 5 5 5l 5 5 5,j j j j jl j j jXeC eC eC eC eC< eC eC eCPE E E  %,1B///0 )d )dID# *.3        B G(*Dt*KMbcccc ["bcc (  (  (  (  (H  (  ( dc (FG G G G G8$ G G GG G G zHMOOOOO s$   C% %C32C37C< <DD