HEX
Server: Apache
System: Linux zacp120.webway.host 4.18.0-553.50.1.lve.el8.x86_64 #1 SMP Thu Apr 17 19:10:24 UTC 2025 x86_64
User: govancoz (1003)
PHP: 8.3.26
Disabled: exec,system,passthru,shell_exec,proc_close,proc_open,dl,popen,show_source,posix_kill,posix_mkfifo,posix_getpwuid,posix_setpgid,posix_setsid,posix_setuid,posix_setgid,posix_seteuid,posix_setegid,posix_uname
Upload Files
File: //proc/thread-self/root/usr/local/lib/python3.7/test/__pycache__/test_logging.cpython-37.pyc
B

��gԚ�@sdZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZddlZddlZddlZddlZddlZddlZddl Z ddl!m"Z"m#Z#ddl$Z$ddl%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+m,Z,yddl-Z-ddl.Z.ddl/Z/Wn"e0k
�rvdZ-Z.Z/YnXyddl1Z1Wne0k
�r�YnXGdd	�d	ej2�Z3Gd
d�de3�Z4Gdd
�d
e3�Z5dZ6dZ7dZ8dZ9dZ:dZ;dZ<dZ=dZ>dZ?e@e?e6d�ZAe6de7de8de9de:de;de<de=d e>d!e?d"i
ZBGd#d$�d$ejC�ZDGd%d&�d&ejC�ZEGd'd(�d(e3�ZFGd)d*�d*e3�ZGGd+d,�d,eH�ZIGd-d.�d.ejJ�ZKGd/d0�d0eH�ZLGd1d2�d2e3�ZMGd3d4�d4e$jN�ZOGd5d6�d6eH�ZPGd7d8�d8ePe"�ZQGd9d:�d:ePe+�ZRGd;d<�d<ePe)�ZSeTed=��r:Gd>d?�d?eR�ZUGd@dA�dAeS�ZVGdBdC�dCe3�ZWGdDdE�dEe3�ZXGdFdG�dGejY�ZZGdHdI�dIe3�Z[GdJdK�dKe3�Z\dLdM�Z]e�^eTed=�dN�GdOdP�dPe\��Z_GdQdR�dRe3�Z`e�^eTed=�dN�GdSdT�dTe`��ZaGdUdV�dVe3�Zbe�^eTed=�dN�GdWdX�dXeb��Zce�^ejddY�GdZd[�d[eb��ZeGd\d]�d]e3�ZfGd^d_�d_e3�ZgGd`da�dae3�ZhGdbdc�dce3�Zid�ddde�Zjdfdg�ZkGdhdi�diejJ�ZlGdjdk�dke3�ZmGdldm�dme3�ZnGdndo�doe3�ZoGdpdq�dqejp�ZqGdrds�dse3�ZrGdtdu�due3�ZseTejtdv��r0ddluZuddwlvmwZwGdxdy�dye3�Zxe�yd�ZzGdzd{�d{ej{�Z|e|�Z}Gd|d}�d}ej2�Z~Gd~d�dej�Z�Gd�d��d�ej2�Z�Gd�d��d�e3�Z�Gd�d��d�e3�Z�Gd�d��d��Z�Gd�d��d�ej��Z�Gd�d��d�e3�Z�Gd�d��d�e3�Z�Gd�d��d�e3�Z�Gd�d��d�ej2�Z�Gd�d��d�ej2�Z�Gd�d��d�e3�Z�Gd�d��d�e3�Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�d�d��Z�xHd�d�d�d�d�d�e�d�d�d��ffD](\Z�Z�e�e�fd�d��Z�e�e�d�e�e���q�We�^e-d��Gd�d��d�e3��Z�Gd�d��d�ej2�Z�e��d�d��d�d���Z�e�d�k�re��dS)�zoTest harness for the logging module. Run all tests.

Copyright (C) 2001-2017 Vinay Sajip. All Rights Reserved.
�N)�assert_python_ok�assert_python_failure)�support)�
HTTPServer�BaseHTTPRequestHandler)�urlparse�parse_qs)�ThreadingUDPServer�DatagramRequestHandler�ThreadingTCPServer�StreamRequestHandlerc@s>eZdZdZdZdZdZdd�Zdd�Zdd
d�Z	dd
�Z
d	S)�BaseTestzBase class for logging tests.z&%(name)s -> %(levelname)s: %(message)sz^([\w.]+) -> (\w+): (\d+)$rcCs�t��|_t��jj}t��zrtj�	�|_
tjdd�|_|�	�|_
}tj�	�|_tj�	�|_i|_}x |D]}t||dd�||<qrWWdt��Xt�d�|_t�d�|_t�d�|_|j��|_t��|_|j�tj�t�|j�|_ t�!|j"�|_#|j �$|j#�|j�%��r6|jj&|jj&}t'd|��|j�%��r^|jj&|jj&}t'd|��|j�(|j �|�)|j�%��|�)|j�%��dS)zxSetup the default logging stream to an internal StringIO instance,
        so that we can examine log output as we want.N�disabledu«×»uĿÖG�zUnexpected handlers: %s)*rZthreading_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)�selfZlogger_dictrr �nameZhlist�r:�-/usr/local/lib/python3.7/test/test_logging.py�setUpMs@




zBaseTest.setUpcCs8|j��|j�|j�x,|jjrD|jjd}|j�|�|��qW|j�|j�t�	�z�tj
��tj
�|j
�tj��tj�|j�tj��tj�|j�|jtjdd�<t��j}d|_|j}|��|�|j�|j}x*|jD] }||dk	r�|||j|_q�WWdt��X|��tj|j�dS)zJRemove our logging stream, and restore the original logging
        level.rN) r*�closer%�
removeHandlerr.r4r+r'rrr�clear�updaterrrrrrrrr�disablerrr rr"Z
doCleanupsrZthreading_cleanupr)r8�hrrr r9r:r:r;�tearDownws8






zBaseTest.tearDownNc	Cs�|p|j}t�|p|j�}|����}|�t|�t|��xFt||�D]8\}}|�	|�}|sj|�
d|�|�t|���|�qFW|�
�}|r�|�
d|�dS)z�Match 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)r*�re�compile�expected_log_pat�getvalue�
splitlines�assertEqual�len�zip�search�fail�tuple�groups�read)	r8Zexpected_valuesr*�patZactual_lines�actual�expected�match�sr:r:r;�assert_log_lines�s

zBaseTest.assert_log_linescCs|jd7_d|jS)zMGenerate a message consisting solely of an auto-incrementing
        integer.�z%d)�message_num)r8r:r:r;�next_message�szBaseTest.next_message)NN)�__name__�
__module__�__qualname__�__doc__r0rFrXr<rCrVrYr:r:r:r;r
Es*"
r
c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd
�Z	dS)�BuiltinLevelsTestz*Test builtin levels and their inheritance.c
Cs4|j}t�d�}|�tj�t�t�d�i�}|�tj�t�d�}|�tj�|�tj	|��|�
|��|�tj	|��|�
|��|�|��|�|��|�tj	|��|�
|��|�|��|�|��|�
|��|�|��|�|��|�
|��|�
|��|�dddddd	d
ddd
dg�dS)N�ERR�INF�DEB)r_�CRITICAL�1)r_�ERROR�2)r`rb�3)r`rd�4)r`�WARNING�5)r`�INFO�6)rarb�7)rard�8)rarh�9)rarj�10)rar,�11)rYrrr+rd�
LoggerAdapterrjr,�logrb�error�warning�info�debugrV)r8�mr_r`rar:r:r;�	test_flat�sD

zBuiltinLevelsTest.test_flatcCs�|j}t�d�}|�tj�t�d�}|�tj�|�tj|��|�|��|�	|��|�
|��|�|��|�ddg�dS)Nr`zINF.ERR)zINF.ERRrbrc)zINF.ERRrdre)
rYrrr+rjrdrrrbrsrtrurvrV)r8rwr`�INF_ERRr:r:r;�test_nested_explicit�s

z&BuiltinLevelsTest.test_nested_explicitcCs�|j}t�d�}|�tj�t�d�}|�tj�t�d�}t�d�}t�d�}|�tj|��|�|��|�	|��|�
|��|�tj|��|�|��|�|��|�	|��|�
|��|�|��|�dddd	d
dg�dS)Nr`zINF.ERRz	INF.UNDEFz
INF.ERR.UNDEF�UNDEF)z	INF.UNDEFrbrc)z	INF.UNDEFrdre)z	INF.UNDEFrhrf)z	INF.UNDEFrjrg)z
INF.ERR.UNDEFrbri)z
INF.ERR.UNDEFrdrk)
rYrrr+rjrdrrrbrsrtrurvrV)r8rwr`ryZ	INF_UNDEFZ
INF_ERR_UNDEFr{r:r:r;�test_nested_inherited�s2




z'BuiltinLevelsTest.test_nested_inheritedcCs�|j}t�d�}t�d�}t�d�}|�tj�|�tj|��|�|��|�tj|��|�|��|�|��|�|��|�	ddddg�dS)Nr`zINF.BADPARENT.UNDEFz
INF.BADPARENT)zINF.BADPARENT.UNDEFrbrc)zINF.BADPARENT.UNDEFrjre)z
INF.BADPARENTrbrf)z
INF.BADPARENTrjrg)
rYrrr+rjrr�FATALrurvrV)r8rwr`Z
GRANDCHILDZCHILDr:r:r;�test_nested_with_virtual_parents 


z1BuiltinLevelsTest.test_nested_with_virtual_parentcCs,|�t�d�tj�|�t�tj�d�dS)z&See issue #22386 for more information.rjN)rIr�getLevelNamerj)r8r:r:r;�test_regression_223868sz'BuiltinLevelsTest.test_regression_22386cCs8t�tjd�|�tjtjd�|�t�tj�d�dS)z&See issue #29220 for more information.rrjN)r�addLevelNamerj�
addCleanuprIr)r8r:r:r;�test_regression_29220=sz'BuiltinLevelsTest.test_regression_29220cCst�d�}|�|tj�dS)Nr})rrrIr})r8Zfatalr:r:r;�test_issue27935Cs
z!BuiltinLevelsTest.test_issue27935cCs`t�tjd�|�tjtjd�|�t�tj�d�|�t�tj�d�|�t�d�tj�dS)z&See issue #29220 for more information.rrj�NOTSETN)rr�rjr�rIrr�)r8r:r:r;r�Gs
N)rZr[r\r]rxrzr|r~r�r�r�r:r:r:r;r^�s/#r^c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BasicFilterTestzTest the bundled Filter class.c	Cs�t�d�}|jjd}z||�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�ddg�Wd|�	|�XdS)Nz	spam.eggsr�spamzspam.eggs.fishzspam.bakedbeans)z	spam.eggsrjre)zspam.eggs.fishrjrf)
r�Filterr%r4�	addFilterrrurYrV�removeFilter)r8Zfilter_�handlerr��	spam_eggs�spam_eggs_fish�spam_bakedbeansr:r:r;�test_filterSs 





zBasicFilterTest.test_filterc	Cs�dd�}|jjd}z||�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�dd	g�Wd|�|�XdS)
NcSs&|j�d�}d�|dd��}|dkS)N�.�z	spam.eggs)r9�split�join)�record�parts�prefixr:r:r;�
filterfuncosz8BasicFilterTest.test_callable_filter.<locals>.filterfuncrr�z	spam.eggszspam.eggs.fishzspam.bakedbeans)z	spam.eggsrjre)zspam.eggs.fishrjrf)	r%r4r�rrrurYrVr�)r8r�r�r�r�r�r�r:r:r;�test_callable_filterks 




z$BasicFilterTest.test_callable_filtercCs*t��}t�ddi�}|�|�|��dS)Nr9z	spam.eggs)rr��
makeLogRecordr7�filter)r8�f�rr:r:r;�test_empty_filter�sz!BasicFilterTest.test_empty_filterN)rZr[r\r]r�r�r�r:r:r:r;r�Osr��x�w�v�u�t�s�r�q�p�orW�Silent�Taciturn�Terse�Effusive�Sociable�Verbose�	TalkativeZ	Garrulous�
Chatterbox�Boringc@seZdZdZdd�ZdS)�GarrulousFilterz)A filter which blocks garrulous messages.cCs
|jtkS)N)�levelno�	GARRULOUS)r8r�r:r:r;r��szGarrulousFilter.filterN)rZr[r\r]r�r:r:r:r;r��sr�c@seZdZdZdd�ZdS)�VerySpecificFilterz5A filter which blocks sociable and taciturn messages.cCs|jttgkS)N)r��SOCIABLE�TACITURN)r8r�r:r:r;r��szVerySpecificFilter.filterN)rZr[r\r]r�r:r:r:r;r��sr�c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�CustomLevelsAndFiltersTestz@Test various filtering possibilities with custom logging levels.z^[\w.]+ -> (\w+): (\d+)$cCs0t�|�x t��D]\}}t�||�qWdS)N)r
r<�my_logging_levels�itemsrr�)r8�k�vr:r:r;r<�s
z CustomLevelsAndFiltersTest.setUpcCs"xtD]}|�||���qWdS)N)�LEVEL_RANGErrrY)r8�loggerZlvlr:r:r;�log_at_all_levels�s
z,CustomLevelsAndFiltersTest.log_at_all_levelscCs2|j�t�|�|j�|�ddddddg�dS)N)r�ri)r�rk)r�rl)r�rm)r�rn)r�ro)r%r+�VERBOSEr�rV)r8r:r:r;�test_logger_filter�sz-CustomLevelsAndFiltersTest.test_logger_filterc	CsR|jjd�t�z$|�|j�|�dddddg�Wd|jjd�tj�XdS)Nr)r�rk)r�rl)r�rm)r�rn)r�ro)r%r4r+r�r�rVrr�)r8r:r:r;�test_handler_filter�sz.CustomLevelsAndFiltersTest.test_handler_filterc
Cs�|jjd}d}t�}|�|�zj|�|j�dddddddd	d
g	}|�|�t�}|j�|�|�|j�|�|ddd
ddddg�Wd|r�|j�|�|�|�XdS)Nr)r�rc)r�re)r�rg)r�ri)r�rk)r�rl)r�rm)r�rn)r�ro)r�rp)r�Z12)r�Z14)r�Z15)r�Z17)r�Z18)r�Z20)r%r4r�r�r�rVr�r�)r8r�Zspecific_filterZgarrZfirst_linesr:r:r;�test_specific_filters�s<

z0CustomLevelsAndFiltersTest.test_specific_filtersN)
rZr[r\r]rFr<r�r�r�r�r:r:r:r;r��sr�c@sZeZdZdd�Zdd�Zdd�Ze�ej	dkd�d	d
��Z
e�eed�d�d
d��ZdS)�HandlerTestcCsDt��}d|_|�|jd�d|_|�|jd�|�t|jd�dS)N�genericZanothergeneric)r�Handlerr9rI�assertRaises�NotImplementedError�emit)r8rBr:r:r;�	test_nameszHandlerTest.test_namec
Cs�tjdk�r^x�dD]�}t��\}}t�|�|s:t�|�tjj	|dd�}|r�|j
|j}}|�|d�|�|d�t�
ddi�}|�|�t�|�|�tj�|��|�|�|�tj�|��n|�|j
d�|�|jd�|��|rt�|�qWtjdk�rd	}nd
}y4tj�|�}|�|j|j�|�|j�|��Wntk
�r\YnXxHdD]@}	|	dk�r�|�ttjjd
d|	�ntj�d
d|	�}|���qdWtj�d�}t�
i�}|�|�|��|��tj�d�}|�|�|��|��dS)N)�linux�darwin)TFT)�delay����msgZTestr�z/var/run/syslogz/dev/log)�GET�POST�PUTr��	localhostz/logrrW)�sys�platform�tempfile�mkstemp�osr=�unlinkrr4�WatchedFileHandler�dev�inorIr��handle�assertFalse�path�existsr7�
SysLogHandlerZfacilityZLOG_USERZ
unixsocket�OSErrorr��
ValueError�HTTPHandlerZBufferingHandlerZshouldFlush)
r8Zexisting�fd�fnrBr�r�r�Zsockname�methodr:r:r;�test_builtin_handlers$sZ








z!HandlerTest.test_builtin_handlerscCs�t��\}}t�|�t�|�t�|�}tj|dfftj	j
|dfftj	j|dfff}tj
dkrv|tj	j|dfff7}x<|D]4\}}||�}|�tj�|��|��t�|�q|WdS)zs
        Test that Path objects are accepted as filename arguments to handlers.

        See Issue #27493.
        �w�arB)r�r�N)r�r�r�r=r��pathlibZPathr�FileHandlerr4�RotatingFileHandler�TimedRotatingFileHandlerr�r�r�r7r�r�)r8r�r�ZpfnZcases�cls�argsrBr:r:r;�test_path_objectsZs



zHandlerTest.test_path_objects�ntz/WatchedFileHandler not appropriate for Windows.c
s2�fdd�}d}d}d�_d�_�x
dD�]}t�dd�\}}t�|�tj|||fd�}d|_|�	�t
jj||d	�}t
�
d
�}	|�|	�zrxlt|�D]`}
t�d�t
�dd
i�}yt���_|�|�Wq�tk
r�td�j�jf��Yq�Xq�WWd|��|��tj�|��r(t�|�Xq(WdS)Nc	sZxTt|�D]H}yt�|�t���_Wntk
r:YnXt�dt�dd��q
WdS)Ng����Mbp?r�)	�ranger�r��time�
deletion_timer��sleep�randomZrandint)ZfnameZtries�_)r8r:r;�remove_loopts
z*HandlerTest.test_race.<locals>.remove_loopi�)FTz.logztest_logging-3-)�targetr�T)r�z'%(asctime)s: %(levelname)s: %(message)sg{�G�zt?r�ZtestingzDeleted at %s, opened at %s)Zhandle_timer�r�r�r�r=�	threading�ThreadZdaemon�startrr4r�r/r2r�r�r�r�r��	Exception�printr�r�r�r�)r8r�Z	del_countZ	log_countr�r�r�ZremoverrBr�r�r�r:)r8r;�	test_raceqs<	




zHandlerTest.test_race�forkzTest requires os.fork().c		s�Gdd�dtj�}|�ttj�d�|��|��jjj�d�_	|�
ttj�d�|�
ttj�d�t�d�}|�
��|�tj�t���t������fdd�}tj|d	d
�}|�����t��}|dkr�z|�d�Wdt�d�Xn�|�d
����|��t��}xL|�d�t�|tj�\}}||k�r<Pt��|dk�rPPt� d��qW|�d�||k�r�t�!|t"j#�t�|d�\}}|�$d�|j|ddd�dS)z>Ensure child logging locks are not held; bpo-6721 & bpo-36533.cs$eZdZ�fdd�Zdd�Z�ZS)zAHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandlercs"t���tjtdd�d�|_dS)Nz	/dev/nullZwt)r*)�super�__init__rr-�open�sub_handler)r8)�	__class__r:r;r�s
zJHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.__init__cSs,|j��z|j�|�Wd|j��XdS)N)r�acquirer��release)r8r�r:r:r;r��s
zFHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.emit)rZr[r\rr��
__classcell__r:r:)rr;�_OurHandler�sr
rz*because we need at least one for this testrW� test_post_fork_child_no_deadlockcsFt��z.���z�����d�Wd���XWdt��XdS)Ng�?)rrr�set�waitrr"r:)�+fork_happened__release_locks_and_end_thread�locks_held__ready_to_fork�refed_hr:r;�lock_holder_thread_fn�s
zKHandlerTest.test_post_fork_child_no_deadlock.<locals>.lock_holder_thread_fnz,test_post_fork_child_no_deadlock lock holder)r�r9z#Child process did not deadlock. \o/Nz&Parent process returned from fork. \o/zWaiting for child process.�g�������?z
Done waiting.zchild process deadlocked.zchild process error)r�)%rr�rIrJrr�rr*r=r9�
assertGreaterZ_at_fork_reinit_lock_weaksetrr6r+r,r��Eventr�r�r
r�rru�_exitrr�r�Z	monotonicrv�waitpid�WNOHANGr��kill�signal�SIGKILLrM)	r8r
Ztest_loggerrZlock_holder_thread�pidZ
start_timeZ
waited_pid�statusr:)rrrr;r�sR








z,HandlerTest.test_post_fork_child_no_deadlockN)
rZr[r\r�r�r��unittestZskipIfr�r9r�hasattrrr:r:r:r;r�s
61r�c@seZdZdd�ZdS)�	BadStreamcCstd��dS)Nzdeliberate mistake)�RuntimeError)r8�datar:r:r;�write�szBadStream.writeN)rZr[r\r"r:r:r:r;r�src@seZdZdd�ZdS)�TestStreamHandlercCs
||_dS)N)�error_record)r8r�r:r:r;�handleError�szTestStreamHandler.handleErrorN)rZr[r\r%r:r:r:r;r#�sr#c@seZdZejZdZdS)�StreamWithIntNamer�N)rZr[r\rr��levelr9r:r:r:r;r&sr&c@s$eZdZdd�Zdd�Zdd�ZdS)�StreamHandlerTestc	Cs�tt��}t�i�}tj}z�|�|�|�|j|�t�t��}t	�
��$}|�|�d}|�||���WdQRXdt_t	�
�� }|�|�|�
d|���WdQRXWd|t_XdS)Nz"
RuntimeError: deliberate mistake
Fr)r#rrr��raiseExceptionsr��assertIsr$r-r�captured_stderr�assertInrGrI)r8rBr�Z	old_raise�stderrr�r:r:r;�test_error_handlings 






z%StreamHandlerTest.test_error_handlingcCsVt��}t��}|�|�}|�|tj�|�|�}|�||�|�|�}|�|�dS)z3
        Test setting the handler's stream
        N)	rr-r(r)Z	setStreamr*r�r-�assertIsNone)r8rBr*�oldrRr:r:r;�test_stream_settings


z%StreamHandlerTest.test_stream_settingcCs t�t��}|�t|�d�dS)Nz<StreamHandler 2 (NOTSET)>)rr-r&rI�repr)r8rBr:r:r;�'test_can_represent_stream_with_int_name*sz9StreamHandlerTest.test_can_represent_stream_with_int_nameN)rZr[r\r.r1r3r:r:r:r;r(sr(c@s:eZdZdZdd�Zdd�Zdd�Zdd	�Zd
dd�Zd
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.
    cCs<tjj||d|dd�|j��d|_||_d|_||_dS)NT)�mapZdecode_datarW)	�smtpd�
SMTPServerr�socket�getsockname�port�_handler�_thread�
poll_interval)r8�addrr�r=�sockmapr:r:r;rFszTestSMTPServer.__init__cCs|�||||�dS)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;)r8�peer�mailfrom�rcpttosr!r:r:r;�process_messageNs
zTestSMTPServer.process_messagecCs0tj|j|jfd�|_}|�d�|��dS)zG
        Start the server running on a separate daemon thread.
        )r�r�TN)r�r��
serve_foreverr=r<�	setDaemonr�)r8�tr:r:r;r�Zs
zTestSMTPServer.startcCstj||jd�dS)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`.
        )r5N)�asyncoreZloop�_map)r8r=r:r:r;rDcszTestSMTPServer.serve_foreverNcCs0|��t�|j|�d|_tj|jdd�dS)z�
        Stop the thread by closing the server instance.
        Wait for the server thread to terminate.

        :param timeout: How long to wait for the server thread
                        to terminate.
        NT)r5Z
ignore_all)r=r�join_threadr<rGZ	close_allrH)r8�timeoutr:r:r;�stopmszTestSMTPServer.stop)N)	rZr[r\r]rrCr�rDrKr:r:r:r;r41s	
r4cs:eZdZdZdd�Zdd�Z�fdd�Zdd	d
�Z�ZS)�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.
    cCs d|_||_||_t��|_dS)N)r<r=r;r�r�ready)r8r�r=r:r:r;r�szControlMixin.__init__cCs0tj|j|jfd�|_}|�d�|��dS)zI
        Create a daemon thread to run the server, and start it.
        )r�r�TN)r�r�rDr=r<rEr�)r8rFr:r:r;r��s
zControlMixin.startcs|j��tt|��|�dS)z^
        Run the server. Set the ready flag before entering the
        service loop.
        N)rMrrrLrD)r8r=)rr:r;rD�s
zControlMixin.serve_foreverNcCs<|��|jdk	r&t�|j|�d|_|��|j��dS)z�
        Tell the server thread to stop, and wait for it to do so.

        :param timeout: How long to wait for the server thread
                        to terminate.
        N)�shutdownr<rrI�server_closerMr?)r8rJr:r:r;rK�s
zControlMixin.stop)N)	rZr[r\r]rr�rDrKr	r:r:)rr;rL{s
	rLc@s"eZdZdZd	dd�Zdd�ZdS)
�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.
    ��?FNcs<G��fdd�dt��t�||��t�|||�||_dS)Ncs2eZdZddd�Zdd�Z���fdd�Z�ZS)	z=TestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandlerNcSs|�d�r|jSt|��dS)NZdo_)�
startswith�process_request�AttributeError)r8r9�defaultr:r:r;�__getattr__�s
zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.__getattr__cSs|j�|�dS)N)�serverr;)r8r:r:r;rS�szMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_requestcs�rt�|�j|f|��dS)N)r�log_message)r8�formatr�)�DelegatingHTTPRequestHandlerrrrr:r;rX�szITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_message)N)rZr[r\rVrSrXr	r:)rZrr)rr;rZ�s
rZ)rrrrL�sslctx)r8r>r�r=rrr[r:)rZrrr;r�s
zTestHTTPServer.__init__c
Csfy(|j��\}}|jr&|jj|dd�}Wn4tk
r\}ztj�d|��Wdd}~XYnX||fS)NT)Zserver_sidezGot an error:
%s
)r8Zacceptr[Zwrap_socketr�r�r-r")r8�sockr>�er:r:r;�get_request�szTestHTTPServer.get_request)rQFN)rZr[r\r]rr^r:r:r:r;rP�s

rPcs.eZdZdZdZddd�Z�fdd�Z�ZS)	�
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.
    T��?cCs2Gdd�dt�}t�||||�t�|||�dS)Nc@seZdZdd�ZdS)z;TestTCPServer.__init__.<locals>.DelegatingTCPRequestHandlercSs|j�|�dS)N)rWr;)r8r:r:r;r��szBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handleN)rZr[r\r�r:r:r:r;�DelegatingTCPRequestHandler�sra)rrrrL)r8r>r�r=�bind_and_activaterar:r:r;r�s
zTestTCPServer.__init__cs"tt|���|j��d|_dS)NrW)rr_�server_bindr8r9r:)r8)rr:r;rc�szTestTCPServer.server_bind)r`T)rZr[r\r]Zallow_reuse_addressrrcr	r:r:)rr;r_�s


	r_cs6eZdZdZd
dd�Z�fdd�Z�fdd	�Z�ZS)�
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.
    ��?Tcs<G�fdd�dt��t�||�|�t�|||�d|_dS)Ncs&eZdZdd�Z��fdd�Z�ZS)z;TestUDPServer.__init__.<locals>.DelegatingUDPRequestHandlercSs|j�|�dS)N)rWr;)r8r:r:r;r�
szBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.handlecsD|j��}|r@yt�|���Wntk
r>|jjs:�YnXdS)N)ZwfilerGr�finishr�rW�_closed)r8r!)�DelegatingUDPRequestHandlerrr:r;rfs
zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish)rZr[r\r�rfr	r:)rh)rr;rhsrhF)r
r	rrLrg)r8r>r�r=rbr:)rhr;r	szTestUDPServer.__init__cs"tt|���|j��d|_dS)NrW)rrdrcr8r9r:)r8)rr:r;rcszTestUDPServer.server_bindcstt|���d|_dS)NT)rrdrOrg)r8)rr:r;rO#szTestUDPServer.server_close)reT)rZr[r\r]rrcrOr	r:r:)rr;rd�s

rd�AF_UNIXc@seZdZejZdS)�TestUnixStreamServerN)rZr[r\r8ri�address_familyr:r:r:r;rj(srjc@seZdZejZdS)�TestUnixDatagramServerN)rZr[r\r8rirkr:r:r:r;rl+srlc@s eZdZdZdd�Zdd�ZdS)�SMTPHandlerTestgN@c
Cs
i}ttjdf|jd|�}|��tj|jf}tjj|ddd|j	d�}|�
|jdg�g|_t�
ddi�}t��|_|�|�|j�|j	�|��|�|j���|�
t|j�d	�|jd\}}}}	|�
|d�|�
|dg�|�d
|	�|�|	�d��|��dS)Nrg����MbP?�meZyouZLog)rJr�u	Hello ✓rWz
Subject: Log
u

Hello ✓)r4rZHOSTrCr�r:rr4ZSMTPHandler�TIMEOUTrIZtoaddrs�messagesr�r�r�handledr�r
rKr7Zis_setrJr,�endswithr=)
r8r?rWr>rBr�r@rArBr!r:r:r;�
test_basic4s,


zSMTPHandlerTest.test_basiccGs|j�|�|j��dS)N)rp�appendrqr)r8r�r:r:r;rCLszSMTPHandlerTest.process_messageN)rZr[r\rorsrCr:r:r:r;rm0srmc@s4eZdZdZdZdd�Zdd�Zdd�Zd	d
�ZdS)�MemoryHandlerTestzTests for the MemoryHandler.z^[\w.]+ -> (\w+): (\d+)$cCsFt�|�tj�dtj|j�|_t�d�|_	d|j	_
|j	�|j�dS)N�
Zmemr)r
r<rr4�
MemoryHandlerrhr.�mem_hdlrr�
mem_logger�	propagater6)r8r:r:r;r<Ws

zMemoryHandlerTest.setUpcCs|j��t�|�dS)N)rxr=r
rC)r8r:r:r;rC_s
zMemoryHandlerTest.tearDowncCs�|j�|���|�g�|j�|���|�g�|j�|���dddg}|�|�xndD]f}x td�D]}|j�|���qlW|�|�|j�|���|dd�t||d�D�}|�|�q^W|j�|���|�|�dS)	N)r,rc)rjre)rhrf)r���	cSsg|]}dt|�f�qS)r,)�str)�.0�ir:r:r;�
<listcomp>ysz0MemoryHandlerTest.test_flush.<locals>.<listcomp>rv)ryrvrYrVrurtr�)r8�lines�nrr:r:r;�
test_flushcs$




zMemoryHandlerTest.test_flushcCs�|j�|���|�g�|j�|���|�g�|j�|j�|j��ddg}|�|�tj	�
dtj|jd�|_|j�
|j�|j�|���|�|�|j�|���|�|�|j�|j�|j��|�|�dS)zO
        Test that the flush-on-close configuration works as expected.
        )r,rc)rjrervFN)ryrvrYrVrur>rxr=rr4rwrhr.r6)r8r�r:r:r;�test_flush_on_closes(






z%MemoryHandlerTest.test_flush_on_closeN)	rZr[r\r]rFr<rCr�r�r:r:r:r;ruPsruc@seZdZdZdd�ZdS)�ExceptionFormatterzA special exception formatter.cCsd|djS)Nz
Got a [%s]r)rZ)r8Zeir:r:r;�formatException�sz"ExceptionFormatter.formatExceptionN)rZr[r\r]r�r:r:r:r;r��sr�c@s�eZdZdZejZdZdZdZdZ	e�
dd�Ze�
dd	�Zd
edZ
e�
dd
�ZdZdZdZdZdd�Zdd�Zdd�Zefdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,S)-�ConfigFileTestz5Reading logging config from a .ini-style config file.z^(\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.stboutzformatter=form1zformatter=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=
    zclass=StreamHandlerzclass=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=
    z�
    [loggers]
    keys=root

    [handlers]
    keys=file

    [formatters]
    keys=

    [logger_root]
    level=DEBUG
    handlers=file

    [handler_file]
    class=FileHandler
    level=DEBUG
    args=("{tempfile}",)
    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=
    cKs$t�t�|��}tjj|f|�dS)N)r(r)�textwrap�dedentr�config�
fileConfig)r8�conf�kwargs�filer:r:r;�apply_config�szConfigFileTest.apply_configc	Csbt���P}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�WdQRXdS)N)rdre)r*)
r�captured_stdoutr��config0rrrurYrsrV)r8�outputr�r:r:r;�test_config0_ok�s
zConfigFileTest.test_config0_okc	Cs�t���t}t�t�|j��}t��}|�	|�t
j�|�t
�
�}|�|���|�|���|jdg|d�|�g�WdQRXdS)N)rdre)r*)rr�r(r)r�r�r��configparserZConfigParserZ	read_filerr�r�rrurYrsrV)r8r�r�Zcpr�r:r:r;�test_config0_using_cp_ok�s

z'ConfigFileTest.test_config0_using_cp_okc	Csdt���R}|�|�t�d�}|�|���|�|���|jddg|d�|�g�WdQRXdS)Nzcompiler.parser)rjrc)rdre)r*)	rr�r�rrrurYrsrV)r8r�r�r�r:r:r;�test_config1_ok�s


zConfigFileTest.test_config1_okcCs|�t|j|j�dS)N)r�r�r��config2)r8r:r:r;�test_config2_failure�sz#ConfigFileTest.test_config2_failurecCs|�t|j|j�dS)N)r�r�r��config3)r8r:r:r;�test_config3_failure�sz#ConfigFileTest.test_config3_failurec	Cs|t���j}|�|j�t��}y
t��Wntk
rFt�d�YnXtj	�
d�|�|��d�|�
g�WdQRXdS)Nzjust testingrz-ERROR:root:just testing
Got a [RuntimeError]
)rr�r��config4rrr �	exceptionr��stdout�seekrIrGrV)r8r�r�r:r:r;�test_config4_ok�s


zConfigFileTest.test_config4_okcCs|j|jd�dS)N)r�)r��config5)r8r:r:r;�test_config5_ok�szConfigFileTest.test_config5_okcCs|j|jd�dS)N)r�)r��config6)r8r:r:r;�test_config6_ok�szConfigFileTest.test_config6_okc	Cs&t���n}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
dddg|d�|�
g�WdQRXt����}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
dd	d
dg|d�|�
g�WdQRXdS)Nzcompiler.parserzcompiler-hyphenated)rjrc)rdre)rbrf)r*zcompiler.lexer)rjrg)rdri)rjrk)rdrl)rr�r��config1arrrurYrs�criticalrV�config7r�r)r8r�r��
hyphenatedr:r:r;�test_config7_ok�s<





zConfigFileTest.test_config7_okc	Cs�dd�}|���Xt�dd�\}}t�|�tjdkrB|�dd�}|jj|d�}|�	|�|�	|�WdQRXt
jjd	}|�
|||�dS)
NcSs|��t�|�dS)N)r=r��remove)�h1r�r:r:r;�cleanup!sz/ConfigFileTest.test_config8_ok.<locals>.cleanupz.logztest_logging-X-r��\z\\)r�r)�check_no_resource_warningr�r�r�r=r9�replace�config8rYr�r�rootr4r�)r8r�r�r�r�r�r:r:r;�test_config8_oks



zConfigFileTest.test_config8_okcCsZ|�|j�t�d�}|�|j�|�|j�|�|j�|j|jdd�|�|j�dS)NZsome_pristine_loggerF)�disable_existing_loggers)r��disable_testrrr�rr7)r8r�r:r:r;�test_logger_disabling6s
z$ConfigFileTest.test_logger_disablingc
Csxt�d���}tjddd�\}}zFt�||�d��t�|�t	j
j|tdddd	d
dd�id
�d�Wdt�
|�XdS)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_z.ini)r��suffix�asciirWFr�z5%(asctime)s [%(process)d] [%(levelname)s] %(message)sz[%Y-%m-%d %H:%M:%S %z]zlogging.Formatter)rY�datefmt�class)�versionr��
formatters)�defaultsN)r�r��stripr�r�r�r"�encoder=rr�r��dictr�)r8Zinir�r�r:r:r;�!test_defaults_do_no_interpolation?s 

z0ConfigFileTest.test_defaults_do_no_interpolationN) rZr[r\r]rr�rFr��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;r��s8  *&+	r�c@s@eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
S)�SocketHandlerTestzTest for SocketHandler objects.)r�rc
Cs�t�|�d|_|_|_y$|�|j|jd�|_}|��Wn(t	k
rh}z
||_dSd}~XYnX|j
��tj
j}t|jt�r�|d|j�|_n||jd�|_d|_|j�|jj
d�|j�|j�t�d�|_dS)ztSet up a TCP server to receive log messages, and a SocketHandler
        pointing to that server's address and port.Ng{�G�z�?r�rr)r
r<rW�	sock_hdlr�server_exception�server_class�address�
handle_socketr�r�rMr
rr4Z
SocketHandler�
isinstance�server_addressrNr:�
log_outputr%r>r6r�Z	Semaphorerq)r8rWr]�hclsr:r:r;r<rs$

zSocketHandlerTest.setUpc	CsFz4|jr |j�|j�|j��|jr2|j�d�Wdt�|�XdS)zShutdown the TCP server.g@N)r�r%r>r=rWrKr
rC)r8r:r:r;rC�s
zSocketHandlerTest.tearDowncCs�|j}x�|�d�}t|�dkr Pt�d|�d}|�|�}x&t|�|kr`||�|t|��}q<Wt�|�}t�|�}|j	|j
d7_	|j��qWdS)Nr�z>Lr�
)
Z
connectionZrecvrJ�struct�unpack�pickle�loadsrr�r�r�rqr)r8�requestZconn�chunk�slen�objr�r:r:r;r��s



zSocketHandlerTest.handle_socketcCsV|jr|�|j�t�d�}|�d�|j��|�d�|j��|�|j	d�dS)NZtcpr��eggsz
spam
eggs
)
r��skipTestrrrsrqrrvrIr�)r8r�r:r:r;�test_output�s




zSocketHandlerTest.test_outputcCs�|jr|�|j�d|j_|j�d�ytd��Wn tk
rR|j�d�YnX|j�	d�t
�
�}|�|jj|�t
�
|jj|d�|j�	d�dS)Ng@g@zDeliberate mistakez
Never sentzNever sent, eitherg����MbP?zNor this)r�r�r�Z
retryStartrWrKr r%r�rsr�rZ	retryTimer�)r8�nowr:r:r;�
test_noserver�szSocketHandlerTest.test_noserverN)rZr[r\r]r_r�r�r<rCr�r�r�r:r:r:r;r�ksr�cCs*tjddd�\}}t�|�t�|�|S)Nr�z.sock)r�r�)r�r�r�r=r�)r�r�r:r:r;�_get_temp_domain_socket�s

r�zUnix sockets requiredc@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixSocketHandlerTestz)Test for SocketHandler with unix sockets.ricCst�|_t�|�dS)N)r�r�r�r<)r8r:r:r;r<�szUnixSocketHandlerTest.setUpcCst�|�t�|j�dS)N)r�rCrr�r�)r8r:r:r;rC�s
zUnixSocketHandlerTest.tearDownN)
rZr[r\r]rr8rjr�r<rCr:r:r:r;r��s

r�c@s8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�DatagramHandlerTestzTest for DatagramHandler.)r�rc
Cs�t�|�d|_|_|_y$|�|j|jd�|_}|��Wn(t	k
rh}z
||_dSd}~XYnX|j
��tj
j}t|jt�r�|d|j�|_n||jd�|_d|_|j�|jj
d�|j�|j�t��|_dS)zvSet up a UDP server to receive log messages, and a DatagramHandler
        pointing to that server's address and port.Ng{�G�z�?r�rr)r
r<rWr�r�r�r��handle_datagramr�r�rMr
rr4ZDatagramHandlerr�r�rNr:r�r%r>r6r�rrq)r8rWr]r�r:r:r;r<�s$

zDatagramHandlerTest.setUpc	CsFz4|jr|j�d�|jr2|j�|j�|j��Wdt�|�XdS)zShutdown the UDP server.g@N)rWrKr�r%r>r=r
rC)r8r:r:r;rC�szDatagramHandlerTest.tearDowncCsTt�dd�}|jt|�d�}t�|�}t�|�}|j|j	d7_|j
��dS)Nz>Lrr�)r��pack�packetrJr�r�rr�r�r�rqr)r8r�r�r�r�r�r:r:r;r�	s

z#DatagramHandlerTest.handle_datagramcCs`|jr|�|j�t�d�}|�d�|j��|j��|�d�|j��|�|j	d�dS)NZudpr�r�z
spam
eggs
)
r�r�rrrsrqr
r?rIr�)r8r�r:r:r;r�s





zDatagramHandlerTest.test_outputN)rZr[r\r]rdr�r�r<rCr�r�r:r:r:r;r��sr�c@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixDatagramHandlerTestz,Test for DatagramHandler using Unix sockets.ricCst�|_t�|�dS)N)r�r�r�r<)r8r:r:r;r<%szUnixDatagramHandlerTest.setUpcCst�|�t�|j�dS)N)r�rCrr�r�)r8r:r:r;rC*s
z UnixDatagramHandlerTest.tearDownN)
rZr[r\r]rr8rlr�r<rCr:r:r:r;r�s

r�c@s8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�SysLogHandlerTestz!Test for SysLogHandler using UDP.)r�rc
Cs�t�|�d|_|_|_y$|�|j|jd�|_}|��Wn(t	k
rh}z
||_dSd}~XYnX|j
��tj
j}t|jt�r�||jd|jf�|_n||j�|_d|_|j�|jj
d�|j�|j�t��|_dS)ztSet up a UDP server to receive log messages, and a SysLogHandler
        pointing to that server's address and port.Ng{�G�z�?rr)r
r<rW�sl_hdlrr�r�r�r�r�r�rMr
rr4r�r�r�rNr:r�r%r>r6r�rrq)r8rWr]r�r:r:r;r<5s$

zSysLogHandlerTest.setUpc	CsFz4|jr|j�d�|jr2|j�|j�|j��Wdt�|�XdS)zShutdown the server.g@N)rWrKr�r%r>r=r
rC)r8r:r:r;rCOszSysLogHandlerTest.tearDowncCs|j|_|j��dS)N)r�r�rqr)r8r�r:r:r;r�Zsz!SysLogHandlerTest.handle_datagramcCs�|jr|�|j�t�d�}|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�dS)NZslhuspäms
<11>spämFs	<11>spämuhäm-s<11>häm-späm)
r�r�rrrsrqr
rIr�r?r�Z
append_nul�ident)r8r�r:r:r;r�^s 








zSysLogHandlerTest.test_outputN)rZr[r\r]rdr�r�r<rCr�r�r:r:r:r;r�.sr�c@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixSysLogHandlerTestz)Test for SysLogHandler with Unix sockets.ricCst�|_t�|�dS)N)r�r�r�r<)r8r:r:r;r<yszUnixSysLogHandlerTest.setUpcCst�|�t�|j�dS)N)r�rCrr�r�)r8r:r:r;rC~s
zUnixSysLogHandlerTest.tearDownN)
rZr[r\r]rr8rlr�r<rCr:r:r:r;r�qs

r�z$IPv6 support required for this test.cs4eZdZdZeZdZ�fdd�Z�fdd�Z�Z	S)�IPv6SysLogHandlerTestz&Test for SysLogHandler with IPv6 host.)z::1rcstj|j_tt|���dS)N)r8ZAF_INET6r�rkrr�r<)r8)rr:r;r<�s
zIPv6SysLogHandlerTest.setUpcstj|j_tt|���dS)N)r8�AF_INETr�rkrr�rC)r8)rr:r;rC�s
zIPv6SysLogHandlerTest.tearDown)
rZr[r\r]rdr�r�r<rCr	r:r:)rr;r��s
r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�HTTPHandlerTestzTest for HTTPHandler.cCst�|�t��|_dS)ztSet up an HTTP server to receive log messages, and a HTTPHandler
        pointing to that server's address and port.N)r
r<r�rrq)r8r:r:r;r<�s
zHTTPHandlerTest.setUpcCsr|j|_t|j�|_|jdkrRy t|jd�}|j�|�|_Wnd|_YnX|�	d�|�
�|j��dS)Nr�zContent-Length��)
�commandrr��log_data�intZheadersZrfilerP�	post_dataZ
send_responseZend_headersrqr)r8r�Zrlenr:r:r;�handle_request�s

zHTTPHandlerTest.handle_requestc	Cs�t�d�}|j}|�|jjd��x�dD�]�}d}|r�yddl}Wntk
r\d}Yq�Xtj�	t
�}tj�|d�}|�|j
�}|�|�|j|d�}	nd}d}	t||jd|d�|_}
|
��|
j��d	|
j}|o�|}tjj|d
||	dd�|_d|_|�|j�x�d
D]�}
|
|j_|j��d}|�|�|j��|�|jjd
�|�|j |
�|
dk�rtt!|jj"�}nt!|j#�$d��}|�|ddg�|�|ddg�|�|d|g��qW|j�%d�|j�|j�|j�&�q*WdS)NZhttpr)FT)r�rzkeycert.pem)Zcafileg{�G�z�?)r[zlocalhost:%dz/frob)�foo�bar)�secure�contextZcredentials)r�r�uspämr�zutf-8r9ZfuncNamer�r�g@)'rrr%r>r4�ssl�ImportErrorr�r��dirname�__file__r�Z
SSLContextZPROTOCOL_TLS_SERVERZload_cert_chainZcreate_default_contextrPr�rWr�rMr
Zserver_portr�Zh_hdlrr�r6r�rqr?rsrIr�rZqueryr��decoderKr=)r8r�r%r�r>r�r[�hereZlocalhost_certr�rWZhostZ
secure_clientr�r��dr:r:r;r��s\











zHTTPHandlerTest.test_outputN)rZr[r\r]r<r�r�r:r:r:r;r��s
r�c@s0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
MemoryTestz*Test memory persistence of logger objects.cCst�|�i|_dS)z8Create a dict to remember potentially destroyed objects.N)r
r<�
_survivors)r8r:r:r;r<�s
zMemoryTest.setUpcGs2x,|D]$}t|�t|�f}t�|�|j|<qWdS)zKWatch the given objects for survival, by creating weakrefs to
        them.N)�idr2�weakref�refr�)r8r�r��keyr:r:r;�_watch_for_survival�s
zMemoryTest._watch_for_survivalcCs`t��g}x.|j��D] \\}}}|�dkr|�|�qW|r\|�dt|�d�|�f�dS)z;Assert that all objects watched for survival have survived.Nz;%d objects should have survived but have been destroyed: %sz, )�gcZcollectr�r�rtrMrJr�)r8ZdeadZid_�repr_r�r:r:r;�_assertTruesurvival�s
zMemoryTest._assertTruesurvivalcCs�|j�tj�t�d�}|�|�|�tj�|j�|���|�|���|�	dg�~|�
�t�d�}|�|���|�	ddg�dS)Nr�)r�r,re)r�r,rf)r%r+rrjrr�r,rvrYrVr)r8r�r�r:r:r;�test_persistent_loggers�s


z"MemoryTest.test_persistent_loggersN)rZr[r\r]r<r�rrr:r:r:r;r��s
r�c@seZdZdd�Zdd�ZdS)�EncodingTestc	Cs�t�d�}t�dd�\}}t�|�d}zptj|dd�}|�|�z|�|�Wd|�	|�|��Xt
|dd�}z|�|���
�|�Wd|��XWdtj�|�r�t�|�XdS)N�testz.logztest_logging-1-ufoo€zutf-8)�encoding)rrr�r�r�r=r�r6rtr>rrIrP�rstripr��isfiler�)r8rrr�r�r!r�r�r:r:r;�test_encoding_plain_files"




z%EncodingTest.test_encoding_plain_filec	Cs�t�d�}d}t�d�}d|_t��}||d�}t�|�}|�|�z|�	|�Wd|�
|�|��X|��}|�
|d�dS)Nruдо свидания�cp1251�stricts�� �������
)rr�codecs�	getwriterrr(�BytesIOr-r6rtr>r=rGrI)r8rr�messageZwriter_classr*�writerr�rUr:r:r;�test_encoding_cyrillic_unicode/s






z+EncodingTest.test_encoding_cyrillic_unicodeN)rZr[r\r	rr:r:r:r;rsrc@seZdZdd�Zdd�ZdS)�WarningsTestc	Cs�t����t�d�|�tjd�tjdtd�t��}t�	|�}t�
d�}|�|�t�d�|�
|�|��}|��|�|�d�d�t��}t�d	td
d|d�|��}|��|�|d
�WdQRXdS)NTF�always)�categoryzpy.warningszI'm warning you...z UserWarning: I'm warning you...
r�Explicitzdummy.py�*z
Dummy linez0dummy.py:42: UserWarning: Explicit
  Dummy line
)�warnings�catch_warningsr�captureWarningsr��filterwarnings�UserWarningr(r)r-rr6�warnr>rGr=r�find�showwarningrI)r8r*rBr�rUZa_filer:r:r;�
test_warningsGs(






zWarningsTest.test_warningsc	Cs~t���lt�d�|�tjd�t�d�}|�|jg�t�dt	dd�|�t
|j�d�|�|jdtj�WdQRXdS)	NTFzpy.warningsrzdummy.pyrrWr)
rrrrr�rrIr4rrrJ�assertIsInstance�NullHandler)r8r�r:r:r;�test_warnings_no_handlers_s


z&WarningsTest.test_warnings_no_handlersN)rZr[r\rr"r:r:r:r;rEsrcCst�||�S)N)rr/)rYr�r:r:r;�
formatFuncmsr#cCst��S)N)rr-r:r:r:r;�handlerFuncpsr$c@seZdZdS)�
CustomHandlerN)rZr[r\r:r:r:r;r%ssr%c
@s�eZdZdZejZdZddddiidddd	d
d�iddgd
�d�Zddddiidddd	d
d�idddgd
�iddid�Zddddiidddd	d
d�idddiiddgd
�d�Z	ddddiidddd	dd�idddgd
�iddid�Z
ddddiiddddd
d�idddgd
�iddid�Zddddiidddd	d
d�idddgd
�iddid�Zddddiidddd	d
d�idddgd
�iddid�Z
ddeddd�idddd	d
d�id	dgd
�d�Zdedd�eddd�edd�d�ddd	d
d�deid�d	dgd
�d�Zddddiideddd	d
d�idddgd
�iddid�Zddddiideddd	d
dd �idddgd
�iddid�Zddddiidddd	d
d�id!ddgd
�iddid�Zdd"dddiidddd	d
d�iddgd
�id#�ddid$�Zdd%dddiidddd	d
d�iddgd
�id#�ddid$�Zddddiiddddd
d�idddgd
�idd	id�Zdd%dddiiddd&iid'�Zdd%ddd&iiddd&iid'�Zddddiid(d)diidddd	d
d(gd*�iddd(gd+�iddgd
�d,�Zddddiidddd	d
d�id-dd.idddgd
�iddid/�Zdddiidddd	d
d�id-dd.idddgd
�iddid0�Zd1dddiidddd	d
d�id-dd.idddgd
�iddid/�Zddddiidddd	d
d2d3d4�d5�iddgd
�d�Zdd6d7d8d9�iddd6d:�d;d<d6d=dd>�d?�d@ddAgdBdC�idD�Z dEdF�Z!dGdH�Z"efdIdJ�Z#dKdL�Z$dMdN�Z%dOdP�Z&dQdR�Z'dSdT�Z(dUdV�Z)dWdX�Z*dYdZ�Z+d[d\�Z,d]d^�Z-d_d`�Z.dadb�Z/dcdd�Z0dedf�Z1dgdh�Z2didj�Z3dkdl�Z4dmdn�Z5d~dpdq�Z6drds�Z7dtdu�Z8dvdw�Z9dxdy�Z:dzd{�Z;d|d}�Z<doS)�ConfigDictTestz)Reading logging config from a dictionary.z^(\w+) \+\+ (\w+)$rW�form1rYz%(levelname)s ++ %(message)s�hand1zlogging.StreamHandlerr�zext://sys.stdout)r��	formatterr'r*rh)r'r4)r�r�r4r�zcompiler.parserr,r')r�r�r4�loggersr�zext://sys.stdboutZNTOSETZWRANINGZmisspelled_namez.ExceptionFormatterz"%(levelname)s:%(name)s:%(message)s)z()rYz.formatFunc)r'Zform2Zform3z())r(Zhand2z.CustomHandlerzinvalid parameter name)r�r)r'r*rnzcompiler.lexerF)�compilerzcompiler.lexer)r�r�r�r4r*r�Trj)r�Zincrementalr4r*Zfilt1r9)r�r)r'r*�filters)r'r,)r�r�r,r4r*r�zcfg://true_formatterszcfg://handler_configs[hand1])r��true_formatters�handler_configsr�r4r*r�)r-r.r�r4r*r�r�r�z!
)r��
terminator)r�r)r'r*r�ZmySimpleFormatterz1%(asctime)s (%(name)s) %(levelname)s: %(message)s�$)rY�style)r�r'r)zlogging.handlers.MemoryHandler��
fileGlobal)r�Zcapacityr)r�r')r3�bufferGlobal�mymoduler4�true)r'r4rz)r�r�r4r*cCstj�|�dS)N)rr�Z
dictConfig)r8r�r:r:r;r��
szConfigDictTest.apply_configc	Csbt���P}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�WdQRXdS)N)rdre)r*)
rr�r�r�rrrurYrsrV)r8r�r�r:r:r;r��
s
zConfigDictTest.test_config0_okc	Csdt���R}|�|�t�d�}|�|���|�|���|jddg|d�|�g�WdQRXdS)Nzcompiler.parser)rjrc)rdre)r*)	rr�r�rrrurYrsrV)r8r�r�r�r:r:r;r�s


zConfigDictTest.test_config1_okcCs|�t|j|j�dS)N)r�r�r�r�)r8r:r:r;r�sz#ConfigDictTest.test_config2_failurecCs|�t|j|j�dS)N)r�r�r��config2a)r8r:r:r;�test_config2a_failuresz$ConfigDictTest.test_config2a_failurecCs|�t|j|j�dS)N)r�r�r��config2b)r8r:r:r;�test_config2b_failuresz$ConfigDictTest.test_config2b_failurecCs|�t|j|j�dS)N)r�r�r�r�)r8r:r:r;r�sz#ConfigDictTest.test_config3_failurec	Cstt���b}|�|j�y
t��Wntk
r>t�d�YnXtj�	d�|�
|��d�|�g�WdQRXdS)Nzjust testingrz-ERROR:root:just testing
Got a [RuntimeError]
)
rr�r�r�r rr�r�r�r�rIrGrV)r8r�r:r:r;r�!s


zConfigDictTest.test_config4_okc	Cstt���b}|�|j�y
t��Wntk
r>t�d�YnXtj�	d�|�
|��d�|�g�WdQRXdS)Nzjust testingrz-ERROR:root:just testing
Got a [RuntimeError]
)
rr�r��config4ar rr�r�r�r�rIrGrV)r8r�r:r:r;�test_config4a_ok0s


zConfigDictTest.test_config4a_okcCs|j|jd�dS)N)r�)r�r�)r8r:r:r;r�?szConfigDictTest.test_config5_okcCs|�t|j|j�dS)N)r�r�r�r�)r8r:r:r;�test_config6_failureBsz#ConfigDictTest.test_config6_failurec	Cs�t���T}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�WdQRXt���j}|�|j
�t�d�}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�WdQRXdS)Nzcompiler.parser)rjrc)rdre)r*zcompiler.lexer)rjrf)rdrg)
rr�r�r�rrrurYrsrVr�r7r)r8r�r�r:r:r;r�Es,




zConfigDictTest.test_config7_okc	Cs�t���T}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�WdQRXt����}|�|j
�t�d�}|�|j�|�|���|�|���t�d�}|�|���|�|���|j	dddd	g|d�|�	g�WdQRXdS)
Nzcompiler.parser)rjrc)rdre)r*zcompiler.lexer)rjrf)rdrg)rjri)rdrk)
rr�r�r�rrrurYrsrVr�r�r)r8r�r�r:r:r;�test_config_8_okbs4




zConfigDictTest.test_config_8_okc	Cs&t���n}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
dddg|d�|�
g�WdQRXt����}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
dd	d
dg|d�|�
g�WdQRXdS)Nzcompiler.parserzcompiler-hyphenated)rjrc)rdre)rbrf)r*zcompiler.lexer)rjrg)rdri)rjrk)rdrl)rr�r�r�rrrurYrsr�rV�config8ar�r)r8r�r�r�r:r:r;�test_config_8a_ok�s<





z ConfigDictTest.test_config_8a_okc	Cs�t����}|�|j�t�d�}|�|���|jg|d�|�|j	�|�|���|jg|d�|�|j
�|�|���|jdg|d�WdQRXdS)Nzcompiler.parser)r*)rjrf)rr�r��config9rrrurYrV�config9a�config9b)r8r�r�r:r:r;�test_config_9_ok�s

zConfigDictTest.test_config_9_okc	Cs�t����}|�|j�t�d�}|�|���t�d�}|�|���t�d�}|�|���t�d�}|�|���|j	ddg|d�WdQRXdS)Nzcompiler.parserr+zcompiler.lexerzcompiler.parser.codegen)rhrc)rdrg)r*)
rr�r��config10rrrtrYrsrV)r8r�r�r:r:r;�test_config_10_ok�s




z ConfigDictTest.test_config_10_okcCs|�|j�dS)N)r��config11)r8r:r:r;�test_config11_ok�szConfigDictTest.test_config11_okcCs|�t|j|j�dS)N)r�r�r��config12)r8r:r:r;�test_config12_failure�sz$ConfigDictTest.test_config12_failurecCs|�t|j|j�dS)N)r�r�r��config13)r8r:r:r;�test_config13_failure�sz$ConfigDictTest.test_config13_failurec	Csht���V}|�|j�tjd}|�|jd�|�|jd�t�	d�|�
|���d��WdQRXdS)Nr(r�z!
ZExclamationz
Exclamation!
)
rr�r��config14rrrIr�r/rtr7rGrr)r8r�rBr:r:r;�test_config14_ok�s


zConfigDictTest.test_config14_okc	Cs�dd�}|���Pt�dd�\}}t�|�ddd|d�id	dgid
�}|�|�|�|�WdQRXtjjd}|�	|||�dS)NcSs|��t�|�dS)N)r=r�r�)r�r�r:r:r;r��sz0ConfigDictTest.test_config15_ok.<locals>.cleanupz.logztest_logging-X-rWr�zlogging.FileHandler)r��filenamer4)r�r4r�r)
r�r�r�r�r=r�rr�r4r�)r8r�r�r�r�r�r:r:r;�test_config15_ok�s


zConfigDictTest.test_config15_okNc
Cs�|�d�}tj�d|�}|��|j��|j}|j��z�t	�	t	j
t	j�}|�d�|�
d|f�t�dt|��}||}d}t|�}	x.|	dkr�|�||d��}
||
7}|	|
8}	q�W|��Wd|j�d�tj��t�|d�XdS)Nzutf-8rg@r�z>L)r�rr�Zlistenr�rMr
r:r?r8r�ZSOCK_STREAMZ
settimeoutZconnectr�r�rJ�sendr=Z
stopListeningrrI)r8�textZverifyrFr:r\r�rUZ	sentsofar�leftZsentr:r:r;�setup_via_listeners,





z!ConfigDictTest.setup_via_listenerc	Cs�t����}|�t�|j��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�
|�	��|jddg|d�WdQRXdS)Nzcompiler.parserr+zcompiler.lexerzcompiler.parser.codegen)rhrc)rdrg)r*)rr�rT�json�dumpsrErrrtrYrsrV)r8r�r�r:r:r;�test_listen_config_10_oks




z'ConfigDictTest.test_listen_config_10_okc	Cslt���Z}|�t�tj��t�d�}|�	|�
��|�|�
��|jddg|d�|�g�WdQRXdS)Nzcompiler.parser)rjrc)rdre)r*)
rr�rTr�r�r�r�rrrurYrsrV)r8r�r�r:r:r;�test_listen_config_1_ok1s

z&ConfigDictTest.test_listen_config_1_okc	Csbdd�}dd�}t�d�}t�tj�}t���.}|�||�|�	|�
��|�|�
��WdQRX|jg|d�|jddgd	d
�t���6}|�|�t�d�}|�	|�
��|�|�
��WdQRX|jddg|d�|jddgd	d
�t���B}|�|ddd
�|�t�d�}|�	|�
��|�|�
��WdQRX|jddg|d�|jddgd	d
�dS)NcSsdS)Nr:)�stuffr:r:r;�verify_failAsz6ConfigDictTest.test_listen_verify.<locals>.verify_failcSs|ddd�S)Nr�r:)rYr:r:r;�verify_reverseDsz9ConfigDictTest.test_listen_verify.<locals>.verify_reversezcompiler.parser)r*)rjrc)rdrez^[\w.]+ -> (\w+): (\d+)$)rQ)rjrf)rdrgr�)rjri)rdrk)
rrr�r�r�r�rr�rTrurYrsrV)r8rZr[r�Zto_sendr�r:r:r;�test_listen_verify?sN






z!ConfigDictTest.test_listen_verifycCsB|�|j�t�d�jd}|�|jtj�|�|jj	tj
�dS)Nr5r)r��out_of_orderrrr4r r�r�r)�_style�StringTemplateStyle)r8r�r:r:r;�test_out_of_order}s

z ConfigDictTest.test_out_of_ordercCs�ddddgddd�dd	d
dgdgd
ddgd�}tj�|�}|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�|�d�d�|�d�}|�|�d�dddg�|�t|jd�|�t|jd�|�t|jd�dS)N)rWr��r��b�cr]ra)r�r�)�g)rBr�jr��lrwr��ozcfg://alist�p)ZatupleZalistZadictZnest1Znest2Znest3zcfg://atuple[1]r�zcfg://alist[1]zcfg://nest1[1][0]rBzcfg://nest2[1][1]z
cfg://adict.dzcfg://adict[f]zcfg://nest3rWzcfg://nosuchzcfg://!zcfg://adict[2])	rr�ZBaseConfiguratorrIZconvert�popr��KeyErrorr�)r8r�Zbcr�r:r:r;�test_baseconfig�s$
zConfigDictTest.test_baseconfigc	s�ddlm�G�fdd�dtj�}�dddg�}|dd	gd
�}dd||d
�iddgd�d�}t���}|�|�t�d�WdQRX|�|�	�d�dS)Nr)�
namedtuplecs*eZdZ��fdd�Z�fdd�Z�ZS)z1ConfigDictTest.test_namedtuple.<locals>.MyHandlercst�j||�||_dS)N)rr�resource)r8rmr�r�)rrlr:r;r�sz:ConfigDictTest.test_namedtuple.<locals>.MyHandler.__init__cs$|jd|jj��7_t��|�S)N� )r�rm�typerr�)r8r�)rr:r;r��sz6ConfigDictTest.test_namedtuple.<locals>.MyHandler.emit)rZr[r\rr�r	r:)rl)rr;�	MyHandler�srp�Resourcero�labelsZmy_typer�)rorrrWZ	myhandler)z()rmrj)r'r4)r�r4r�zsome logzsome log my_type
)
�collectionsrlrr-rr+r�rurIrG)r8rprqrmr�r-r:)rlr;�test_namedtuple�s	

zConfigDictTest.test_namedtuple)N)=rZr[r\r]rr�rFr�r�r�r�r7r9r�r�r�r#r$r;r�r�r�r�r?rArBrCrErGrIrKrMr]r�r�r�r�r8r:r�r�r<r�r=r�r>r@rDrFrHrJrLrNrPrTrWrXr\r`rkrtr:r:r:r;r&vsl
















!+	
>r&c@seZdZdd�Zdd�ZdS)�ManagerTestcsng�G�fdd�dtj�}t�d�}|�t|jt�|�|�|�d�}|�d�t�d�|�	�dg�dS)NcseZdZd�fdd�	ZdS)z6ManagerTest.test_manager_loggerclass.<locals>.MyLoggerNcs��|�dS)N)rt)r8r'r�r��exc_info�extra)�loggedr:r;�_log�sz;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._log)NN)rZr[r\ryr:)rxr:r;�MyLogger�srzrzshould appear in loggedzshould not appear in logged)
r�Logger�Managerr��	TypeError�setLoggerClassr�rrtrI)r8rz�manr�r:)rxr;�test_manager_loggerclass�s




z$ManagerTest.test_manager_loggerclasscCs,t�d�}t�}|�|�|�|j|�dS)N)rr|�object�setLogRecordFactoryrIZlogRecordFactory)r8rrSr:r:r;�test_set_log_record_factory�s

z'ManagerTest.test_set_log_record_factoryN)rZr[r\r�r�r:r:r:r;ru�sruc@seZdZdd�ZdS)�ChildLoggerTestcCs�t��}t�d�}t�d�}|�d�}|�d�}|�|t�d��|�|t�d��|�d�}|�d�}|�d�}|�|t�d��|�|t�d��|�||�dS)	N�abczdef.ghiZxyzzuvw.xyz�defZghizabc.defzabc.def.ghi)rrZgetChildr*)r8r��l1�l2Zc1Zc2Zc3r:r:r;�test_child_loggers�s






z"ChildLoggerTest.test_child_loggersN)rZr[r\r�r:r:r:r;r��sr�c@seZdZdS)�DerivedLogRecordN)rZr[r\r:r:r:r;r��sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�LogRecordFactoryTestcCsBGdd�dtj�}t�|�|t�|_|j�|j�t��|_	dS)Nc@seZdZdd�Zdd�ZdS)z2LogRecordFactoryTest.setUp.<locals>.CheckingFiltercSs
||_dS)N)r�)r8r�r:r:r;r�sz;LogRecordFactoryTest.setUp.<locals>.CheckingFilter.__init__cSs,t|�}||jk	r(d||jf}t|��dS)Nz)Unexpected LogRecord type %s, expected %sT)ror�r})r8r�rFr�r:r:r;r��s

z9LogRecordFactoryTest.setUp.<locals>.CheckingFilter.filterN)rZr[r\rr�r:r:r:r;�CheckingFilter�sr�)
rr�r
r<r�r�r%r�ZgetLogRecordFactory�orig_factory)r8r�r:r:r;r<�s


zLogRecordFactoryTest.setUpcCs(|j�|j�t�|�t�|j�dS)N)r%r�r�r
rCrr�r�)r8r:r:r;rC�s
zLogRecordFactoryTest.tearDowncCs@|�t|jj|���t�t�|j�|���|�	dg�dS)N)r�rdre)
r�r}r%rtrYrr�r�rsrV)r8r:r:r;�test_logrecord_class�s

z)LogRecordFactoryTest.test_logrecord_classN)rZr[r\r<rCr�r:r:r:r;r��sr�c@s�eZdZdZdd�Zdd�Zdd�Zdd	�Ze�	e
ejd
�d�dd
��Z
e�	e
ejd
�d�dd��Ze�	e
ejd
�d�dd��ZdS)�QueueHandlerTestz^[\w.]+ -> (\w+): (\d+)$cCs`t�|�t�d�|_tj�|j�|_d|_t�	d�|_
d|j
_|j
�tj
�|j
�|j�dS)Nr�ZqueF)r
r<�queue�Queuerr4�QueueHandler�que_hdlrr9r�
que_loggerrzr+rhr6)r8r:r:r;r<
s
zQueueHandlerTest.setUpcCs|j��t�|�dS)N)r�r=r
rC)r8r:r:r;rC
s
zQueueHandlerTest.tearDowncCs�|j�|���|�tj|jj�|j�|���|�tj|jj�|��}|j�|�|j��}|�	t
|tj��|�
|j|jj�|�
|j|jf|df�dS)N)r�rvrYr�r��Empty�
get_nowaitrurtr7r�r�	LogRecordrIr9r�r�)r8r�r!r:r:r;�test_queue_handler
s
z#QueueHandlerTest.test_queue_handlercCsx|��}t�tj�}d}|j|j||d�}t�|j�}|j�	|�|j
�|�|j�
�}|�||j�|�||j�dS)Nz {name} -> {levelname}: {message})r9�	levelnamer)rYrrrhrYr9r/r0r�r2r�rtr�r�rIr�r)r8r�r�Zlog_format_strZ
formatted_msgr)Z
log_recordr:r:r;�test_formatting%
s

z QueueHandlerTest.test_formatting�
QueueListenerz5logging.handlers.QueueListener required for this testcCstt�t���}tj�|j|�}|��z4|j�	|�
��|j�|�
��|j�|�
��Wd|�
�X|�|jtjdd��|�|jtjdd��|�|jtjdd��|��t�t���}|�tj�tjj|j|dd�}|��z4|j�	|�
��|j�|�
��|j�|�
��Wd|�
�X|�|jtjdd��|�|jtjdd��|�|jtjd	d��|��dS)
Nrc)r�rrerfT)Zrespect_handler_levelrgrirk)rZTestHandlerZMatcherrr4r�r�r�r�rtrYrsr�rKr7�matchesrhrdrbr=r+r�)r8r��listenerr:r:r;�test_queue_listener2
s4

z$QueueHandlerTest.test_queue_listenerc
Cs�tj�|j|j�}|��yddWn:tk
r`}z|}|jj|�	�|d�Wdd}~XYnX|�
�|�|j�
����d�d�dS)NrWr)rvZ	Traceback)rr4r�r�r.r��ZeroDivisionErrorr�r�rYrKrIr*rGr��count)r8r�r]�excr:r:r;�&test_queue_listener_with_StreamHandlerU
s&z7QueueHandlerTest.test_queue_listener_with_StreamHandlercCsd|j�|j�|j�|j�tj�|j	|j�}|�
�|j�d�|��|�
|j����d�dS)Nrszque -> ERROR: error)r�r2r1r�r6r.rr4r�r�r�rsrKrIr*rGr�)r8r�r:r:r;�*test_queue_listener_with_multiple_handlersc
sz;QueueHandlerTest.test_queue_listener_with_multiple_handlersN)rZr[r\rFr<rCr�r�r�
skipUnlessrrr4r�r�r�r:r:r:r;r�
s

"
r�r�)�patchc@sleZdZdZdZedd��Ze�e	j
jd�dd��Ze�e	j
jd�dd	��Z
ed
d��Zdd
�Zdd�ZdS)�QueueListenerTestz~
        Tests based on patch submitted for issue #27930. Ensure that
        QueueListener handles all log messages.
        �cCs�t�d|�}|�tj�tj�|�}|�|�tj�|�}|��|�	d�|�	d�|�	d�|�	d�|�	d�|�
�|�|�|��dS)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.
            ztest_logger_with_id_%s�one�twoZthreeZfourZfiveN)
rrr+r,r4r�r6r�r�rurKr>r=)�	log_queuer�r�r�r�r:r:r;�
setup_and_log|
s






zQueueListenerTest.setup_and_logr�cCsNx2t|j�D]$}t��}|�|d|��|f�qW|�|jd|jd�dS)Nz%s_%sr2z&correct number of handled log messages)r��repeatr�r�r�r�rI�
call_count)r8�mock_handlerr�r:r:r;�#test_handle_called_with_queue_queue�
s
z5QueueListenerTest.test_handle_called_with_queue_queuecCsht�d�xBt|j�D]4}t��}|�|d|��|f�|��|�	�qW|�
|jd|jd�dS)Nzmultiprocessing.synchronizez%s_%sr2z&correct number of handled log messages)r�
import_moduler�r��multiprocessingr�r�r�r=rIrIr�)r8r�rr�r:r:r;� test_handle_called_with_mp_queue�
s
z2QueueListenerTest.test_handle_called_with_mp_queueccs0yx|��VqWWntjk
r*gSXdS)N)r�r�r�)r�r:r:r;�get_all_from_queue�
s
z$QueueListenerTest.get_all_from_queuecCs�t�d�x|t|j�D]n}t��}|�|d|��|f�t|�	|��}|�
�|��gtj
jjgg}|�||ddd�|D��qWdS)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.
            zmultiprocessing.synchronizez%s_%sz&Found unexpected messages in queue: %scSs"g|]}t|tj�r|jn|�qSr:)r�rr�r�)r~rwr:r:r;r��
szJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>N)rr�r�r�r�r�r�r��listr�r=rIrr4r�Z	_sentinelr,)r8rr�r�rSr:r:r;�$test_no_messages_in_queue_after_stop�
s	
z6QueueListenerTest.test_no_messages_in_queue_after_stopc	CsFt��}tj�|�}|��|��|�t��|�	�WdQRXdS)N)
r�r�rr4r�r�rKr�r�Z	task_done)r8r�r�r:r:r;�test_calls_task_done_after_stop�
sz1QueueListenerTest.test_calls_task_done_after_stopN)rZr[r\r]r��staticmethodr�r�r�rr4r�r�r�r�r�r�r:r:r:r;r�t
s
r�c@s eZdZdd�ZeZdd�ZdS)�UTCcCstS)N)�ZERO)r8�dtr:r:r;�	utcoffset�
sz
UTC.utcoffsetcCsdS)Nr�r:)r8r�r:r:r;�tzname�
sz
UTC.tznameN)rZr[r\r��dstr�r:r:r:r;r��
sr�c@sFeZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�
FormatterTestc	Cs0dtjtj�ddd�dddddd�|_i|_dS)	Nzformatter.testr��toz	dummy.extrzMessage with %d %s)r�Zplaceholders)r9r'�pathname�linenorv�funcr�r�)rr,r�r�r��common�variants)r8r:r:r;r<�
s
zFormatterTest.setUpNcCs,t|j�}|dk	r"|�|j|�t�|�S)N)r�r�r@r�rr�)r8r9�resultr:r:r;�
get_record�
s
zFormatterTest.get_recordcCs�|��}t�d�}|�|�|�d�t�d�}|�t|j|�|�|���t�d�}|�	|���t�d�}|�	|���t�d�}|�|���dS)Nz${%(message)s}z${Message with 2 placeholders}z
%(random)sz%(asctime)sz%(asctime)-15s�asctime)
r�rr/rIrYr�rjr��usesTimer7)r8r�r�r:r:r;�test_percent�
s




zFormatterTest.test_percentcCs�|��}tjddd�}|�|�|�d�tjddd�}|�t|j|�|�|���tjddd�}|�	|���tjddd�}|�	|���tjddd�}|�	|���tjd	dd�}|�|���dS)
Nz
$%{message}%$�{)r1z$%Message with 2 placeholders%$z{random}z	{asctime}z{asctime!s:15}z{asctime:15}r�)
r�rr/rIrYr�rjr�r�r7)r8r�r�r:r:r;�test_bracesszFormatterTest.test_bracescCs�|��}tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�t|j|�|�|���tjddd�}|�	|���tjd	dd�}|�|���tjd
dd�}|�	|���tjddd�}|�|���dS)Nz$messager0)r1zMessage with 2 placeholdersz$$%${message}%$$z$%Message with 2 placeholders%$z	${random}z
${asctime}z	${asctimez$asctimer�)
r�rr/rIrYr�rjr�r�r7)r8r�r�r:r:r;�test_dollarss zFormatterTest.test_dollarscCs|�ttjddd�dS)N�x)r�r�rr/)r8r:r:r;�test_invalid_style)sz FormatterTest.test_invalid_stylec
Cs�|��}t�dddddddt�}t�|�d����|_d|_t	�
d�}tj|_|�
|�|�d	�|�
|�|d
�d�|�|�|�
|jd	�dS)Ni�r���rar�{z%(asctime)s %(message)sz1993-04-21 08:03:00,123z%Y:%dz1993:21)r��datetime�utcr�ZmktimeZ
astimezoneZ	timetupleZcreatedZmsecsrr/�gmtimeZ	converterrIZ
formatTimerYr�)r8r�r�r�r:r:r;�	test_time,s

zFormatterTest.test_time)N)
rZr[r\r<r�r�r�r�r�r�r:r:r:r;r��
s
r�c@seZdZdd�Zdd�ZdS)�TestBufferingFormattercCsdt|�S)Nz[(%d))rJ)r8�recordsr:r:r;�formatHeader;sz#TestBufferingFormatter.formatHeadercCsdt|�S)Nz(%d)])rJ)r8r�r:r:r;�formatFooter>sz#TestBufferingFormatter.formatFooterN)rZr[r\r�r�r:r:r:r;r�:sr�c@s$eZdZdd�Zdd�Zdd�ZdS)�BufferingFormatterTestcCs"t�ddi�t�ddi�g|_dS)Nr�r�r�)rr�r�)r8r:r:r;r<BszBufferingFormatterTest.setUpcCs2t��}|�d|�g��|�d|�|j��dS)NrZonetwo)r�BufferingFormatterrIrYr�)r8r�r:r:r;�test_defaultHsz#BufferingFormatterTest.test_defaultcCsDt�}|�d|�|j��t�d�}t|�}|�d|�|j��dS)Nz[(2)onetwo(2)]z
<%(message)s>z[(2)<one><two>(2)])r�rIrYr�rr/)r8r�Zlfr:r:r;�test_customMs

z"BufferingFormatterTest.test_customN)rZr[r\r<r�r�r:r:r:r;r�Asr�c@seZdZdd�ZdS)�
ExceptionTestcCs�|j}t�}|�|�ytd��Wntjddd�YnX|�|�|��|jd}|�	|j
�d��|�	|j
�d��|�	|j
�d��|�	|j
�d	��dS)
Nzdeliberate mistakeZfailedT)�
stack_inforz#Traceback (most recent call last):
z!
RuntimeError: deliberate mistakezStack (most recent call last):
z,logging.exception('failed', stack_info=True))r%�RecordingHandlerr6r rr�r>r=r�r7Zexc_textrRrrr�)r8r�rBr:r:r;r�Us


zExceptionTest.test_formattingN)rZr[r\r�r:r:r:r;r�Tsr�c@seZdZdd�ZdS)�LastResortTestc	Cs,|j}|�|j�tj}tj}z�t���:}|�d�|�	|�
�d�|�d�|�	|�
�d�WdQRXdt_t���$}|�d�d}|�	|�
�|�WdQRXt��� }|�d�|�	|�
�d�WdQRXd|j_
dt_t��� }|�d�|�	|�
�d�WdQRXWd|�|j�|t_|t_XdS)NzThis should not appearrz
Final chance!zFinal chance!
z-No handlers could be found for logger "root"
F)r%r>r.rZ
lastResortr)rr+rvrIrGrtrZemittedNoHandlerWarningr6)r8r�Zold_lastresortZold_raise_exceptionsr-r�r:r:r;�test_last_resortks4








zLastResortTest.test_last_resortN)rZr[r\r�r:r:r:r;r�jsr�c@seZdZdd�Zdd�ZdS)�FakeHandlerc	Cs(x"dD]}t|||�|||��qWdS)N)r�flushr=r)�setattr�record_call)r8�
identifier�calledr�r:r:r;r�s
zFakeHandler.__init__cs���fdd�}|S)Ncs��d�����dS)Nz{} - {})rtrYr:)r�r��method_namer:r;�inner�sz&FakeHandler.record_call.<locals>.innerr:)r8r�r�r�r�r:)r�r�r�r;r��szFakeHandler.record_callN)rZr[r\rr�r:r:r:r;r��sr�cs$eZdZ�fdd�Zdd�Z�ZS)r�cstt|�j||�g|_dS)N)rr�rr�)r8r�r�)rr:r;r�szRecordingHandler.__init__cCs|j�|�dS)z&Keep track of all the emitted records.N)r�rt)r8r�r:r:r;r��szRecordingHandler.handle)rZr[r\rr�r	r:r:)rr;r��sr�cs�eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Z�ZS)"�ShutdownTestz#Test suite for the shutdown method.cs.tt|���g|_tj}|�ttd|�dS)Nr))rr�r<r�rr)r�r�)r8Zraise_exceptions)rr:r;r<�szShutdownTest.setUpcs�fdd�}|S)Ncs
���dS)Nr:r:)rsr:r;r��sz'ShutdownTest.raise_error.<locals>.innerr:)r8rsr�r:)rsr;�raise_error�szShutdownTest.raise_errorcCsvtd|j�}td|j�}td|j�}ttjj|||g�}tjt|�d�ddddd	d
ddd
dddg}|�||j�dS)NrrWr�)�handlerListz2 - acquirez	2 - flushz	2 - closez2 - releasez1 - acquirez	1 - flushz	1 - closez1 - releasez0 - acquirez	0 - flushz	0 - closez0 - release)	r�r�r5rr�r�rNr�rI)r8Zhandler0Zhandler1Zhandler2r4rSr:r:r;�test_no_failure�szShutdownTest.test_no_failurecCsRtd|j�}t|||�|��tj�|�g}tjt|�d�|�	d|jd�dS)Nr)r�z0 - releaser�)
r�r�r�r�rr�r�rNr�rI)r8r�rsr�r4r:r:r;�_test_with_failure_in_method�s
z)ShutdownTest._test_with_failure_in_methodcCs|�dt�dS)Nr)r�r�)r8r:r:r;�test_with_ioerror_in_acquire�sz)ShutdownTest.test_with_ioerror_in_acquirecCs|�dt�dS)Nr�)r�r�)r8r:r:r;�test_with_ioerror_in_flush�sz'ShutdownTest.test_with_ioerror_in_flushcCs|�dt�dS)Nr=)r�r�)r8r:r:r;�test_with_ioerror_in_close�sz'ShutdownTest.test_with_ioerror_in_closecCs|�dt�dS)Nr)r�r�)r8r:r:r;�test_with_valueerror_in_acquire�sz,ShutdownTest.test_with_valueerror_in_acquirecCs|�dt�dS)Nr�)r�r�)r8r:r:r;�test_with_valueerror_in_flush�sz*ShutdownTest.test_with_valueerror_in_flushcCs|�dt�dS)Nr=)r�r�)r8r:r:r;�test_with_valueerror_in_close�sz*ShutdownTest.test_with_valueerror_in_closecCsdt_|�dt�dS)NFr)rr)r��
IndexError)r8r:r:r;�.test_with_other_error_in_acquire_without_raise�sz;ShutdownTest.test_with_other_error_in_acquire_without_raisecCsdt_|�dt�dS)NFr�)rr)r�r�)r8r:r:r;�,test_with_other_error_in_flush_without_raise�sz9ShutdownTest.test_with_other_error_in_flush_without_raisecCsdt_|�dt�dS)NFr=)rr)r�r�)r8r:r:r;�,test_with_other_error_in_close_without_raise�sz9ShutdownTest.test_with_other_error_in_close_without_raisecCsdt_|�t|jdt�dS)NTr)rr)r�r�r�)r8r:r:r;�+test_with_other_error_in_acquire_with_raise�s
z8ShutdownTest.test_with_other_error_in_acquire_with_raisecCsdt_|�t|jdt�dS)NTr�)rr)r�r�r�)r8r:r:r;�)test_with_other_error_in_flush_with_raise�s
z6ShutdownTest.test_with_other_error_in_flush_with_raisecCsdt_|�t|jdt�dS)NTr=)rr)r�r�r�)r8r:r:r;�)test_with_other_error_in_close_with_raise�s
z6ShutdownTest.test_with_other_error_in_close_with_raise)rZr[r\r]r<r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r	r:r:)rr;r��s"	r�c@sxeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
ejdd��Zdd�ZdS)�ModuleLevelMiscTestz)Test suite for some module level methods.cCs`tjjj}|�|d�|�tj|�t�d�|�tjjjd�t��|�tjjjtj�dS)Nr�S)rr�rrArIr�rb)r8�old_disabler:r:r;�test_disables

z ModuleLevelMiscTest.test_disableNcs�g�t�|td�fdd��t�}tj�|�tt|�}|dk	rN||d|�n
|d|�|�t|j	�d�|j	d}|�|�
�d|�|dk	r�|ntt|���}|�|j|�|��g�dS)N�basicConfigcs��||f�S)N)rt)r��kw)r�r:r;�<lambda>�z/ModuleLevelMiscTest._test_log.<locals>.<lambda>ztest me: %rrWr)
rr�rr�r�r6r!rIrJr�Z
getMessage�upperr�)r8r�r'�	recording�
log_methodr�Zexpected_levelr:)r�r;�	_test_logs



zModuleLevelMiscTest._test_logcCs|�dtj�dS)Nrr)rrrd)r8r:r:r;�test_log)szModuleLevelMiscTest.test_logcCs|�d�dS)Nrv)r)r8r:r:r;�
test_debug,szModuleLevelMiscTest.test_debugcCs|�d�dS)Nru)r)r8r:r:r;�	test_info/szModuleLevelMiscTest.test_infocCs|�d�dS)Nrt)r)r8r:r:r;�test_warning2sz ModuleLevelMiscTest.test_warningcCs|�d�dS)Nrs)r)r8r:r:r;�
test_error5szModuleLevelMiscTest.test_errorcCs|�d�dS)Nr�)r)r8r:r:r;�
test_critical8sz!ModuleLevelMiscTest.test_criticalcCs^|�ttjt�Gdd�dtj�}t�|�|�t��|�t�tj�|�t��tj�dS)Nc@seZdZdS)z;ModuleLevelMiscTest.test_set_logger_class.<locals>.MyLoggerN)rZr[r\r:r:r:r;rz>srz)r�r}rr~r�r{rI�getLoggerClass)r8rzr:r:r;�test_set_logger_class;s
z)ModuleLevelMiscTest.test_set_logger_classc	s�g�G�fdd�dt���}t�|�t�d�}|��dg�t��}t�|�}|�|�zh|�	tj
�|�d�|�|���
�d�|�d�|�d�|�	tj�|�d�|�|��d�Wd|�|�|��t�tj�XdS)Ncs&eZdZdejf��fdd�	Z�ZS)z@ModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLoggerrzcst��||���d�dS)N�initialized)rrrt)r8r9r')rrr:r;rLszIModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLogger.__init__)rZr[r\rr�rr	r:)r)rr;rzKsrzZjust_some_loggerrZhellorr)rrr~rrIr(r)r-r6r+r,rvrGr��truncater�rjr>r=r{)r8rzr�r*rBr:)rr;�test_subclass_logger_cacheGs(








z.ModuleLevelMiscTest.test_subclass_logger_cachecCs8d}td|�\}}}|��}|�d|�|�d|�dS)Na&if 1:
            import logging

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

            a = A()z-czexception in __del__zValueError: some error)rr�r,)r8�code�rc�out�errr:r:r;�test_logging_at_shutdownfs

z,ModuleLevelMiscTest.test_logging_at_shutdowncCs8d}td|�\}}}|��}|�d|�|�|d�dS)Nz�if 1:
            import logging

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

            rec()z-cz#Cannot recover from stack overflow.rW)rr�ZassertNotInrI)r8rrrrr:r:r;�test_recursion_errorys
	z(ModuleLevelMiscTest.test_recursion_error)N)rZr[r\r]rrr	r
rrr
rrrrZrequires_type_collectingrrr:r:r:r;r��s
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
LogRecordTestcCs6t�i�}t|�}|�|�d��|�|�d��dS)Nz<LogRecord: �>)rr�r}r7rRrr)r8r�rUr:r:r;�test_str_rep�s
zLogRecordTest.test_str_repcCsjt�}t��}|�|�ddi}t�d|�|�|jdj|�|�|jdj	d�|�
|�|��dS)NZlessZmorezless is %(less)srzless is more)r�rrr6rtr*r�r�rIrr>r=)r8rBr�r�r:r:r;�
test_dict_arg�s

zLogRecordTest.test_dict_argcCs\t�i�}|�|jd�y*ddl}t�i�}|�|j|��j�Wntk
rVYnXdS)NZMainProcessr)rr�rI�processNamer�Zcurrent_processr9r�)r8r�Zmpr:r:r;�test_multiprocessing�s

z"LogRecordTest.test_multiprocessingcCs�t�i�}|j}||j�||j�||j�||j�tj}tj}tj	}zNdt_dt_dt_	t�i�}|j
}||j�||j�||j�||j�Wd|t_|t_|t_	XdS)NF)rr��assertIsNotNoneZthreadZ
threadName�processr�
logThreads�logProcesses�logMultiprocessingr/)r8r�ZNOT_NONEZlog_threadsZ
log_processesZlog_multiprocessingZNONEr:r:r;�
test_optional�s,








zLogRecordTest.test_optionalN)rZr[r\rrrr%r:r:r:r;r�s
rcs�eZdZdZ�fdd�Z�fdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd/d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Z�ZS)0�BasicConfigTestz#Test suite for logging.basicConfig.csVtt|���tjj|_tj��|_tj	dd�|_
tjj|_|�
|j�gtj_dS)N)rr&r<rr�r4rrrrrr'r'r�r�)r8)rr:r;r<�s

zBasicConfigTest.setUpcs@x,tjjdd�D]}tj�|�|��qWtt|���dS)N)rr�r4r>r=rr&rC)r8rB)rr:r;rC�szBasicConfigTest.tearDowncCsJttjd|j�tj��tj�|j�|jtj	dd�<tj�
|j�dS)Nr4)r�rr�r4rr?r@rrrr+r')r8r:r:r;r��s

zBasicConfigTest.cleanupcCs�t��|�ttjj�d�tjjd}|�|tj�|�|jt	j
�|j}|�|jj
tj�|�|j�|�|jtj�|�tjj|j�dS)NrWr)rrrIrJr�r4r r-r*r�r-r)r^�_fmtZBASIC_FORMATr/r��PercentStyler'r')r8r�r)r:r:r;�test_no_kwargs�szBasicConfigTest.test_no_kwargsc	CsRt���@}tjtjdd�t�d�tj�d�|�|�	��
�d�WdQRXdS)Nr�)r*r1zLog an errorrzERROR:root:Log an error)rr�rrr�r�rsr�rIrGr�)r8r�r:r:r;�test_strformatstyle�s

z#BasicConfigTest.test_strformatstylec	CsRt���@}tjtjdd�t�d�tj�d�|�|�	��
�d�WdQRXdS)Nr0)r*r1zLog an errorrzERROR:root:Log an error)rr�rrr�r�rsr�rIrGr�)r8r�r:r:r;�test_stringtemplatestyle�s

z(BasicConfigTest.test_stringtemplatestylecCs�dd�}tjdd�|�ttjj�d�tjjd}|�|tj�t�dd�}|�|jj	|jj	�|�|jj
|jj
�|�|||d�dS)NcSs|��|��t�|�dS)N)r=r�r�)r��h2r�r:r:r;r��sz.BasicConfigTest.test_filename.<locals>.cleanupztest.log)rOrWrr�)rrrIrJr�r4r r�r*�moder9r�)r8r�r�rSr:r:r;�
test_filename�szBasicConfigTest.test_filenamecCsVdd�}tjddd�tjjd}t�dd�}|�|jj|jj�|�|||d�dS)NcSs|��|��t�|�dS)N)r=r�r�)r�r,r�r:r:r;r�sz.BasicConfigTest.test_filemode.<locals>.cleanupztest.log�wb)rO�filemoder)	rrr�r4r�rIr*r-r�)r8r�r�rSr:r:r;�
test_filemodeszBasicConfigTest.test_filemodecCs`t��}|�|j�tj|d�|�ttjj	�d�tjj	d}|�
|tj�|�|j|�dS)N)r*rWr)
r(r)r�r=rrrIrJr�r4r r-r*)r8r*r�r:r:r;�test_streamszBasicConfigTest.test_streamcCs.tjdd�tjjdj}|�|jjd�dS)Nr�)rYr)rrr�r4r)rIr^r')r8r)r:r:r;�test_format&szBasicConfigTest.test_formatcCs,tjdd�tjjdj}|�|jd�dS)Nr�)r�r)rrr�r4r)rIr�)r8r)r:r:r;�test_datefmt,szBasicConfigTest.test_datefmtcCs.tjdd�tjjdj}|�|jtj�dS)Nr0)r1r)rrr�r4r)r r^r_)r8r)r:r:r;�
test_style2szBasicConfigTest.test_stylecCsTtjj}|�tjj|�tjdd�|�tjjd�tjdd�|�tjjd�dS)N�9)r'�:)rr�r'r�r+rrI)r8�	old_levelr:r:r;�
test_level8szBasicConfigTest.test_levelcCsp|j}t��g}tj}|ttjd|d�|ttjd|d�|ttj||d�|ttjtjd�tjddd�dS)Nztest.log)rOr*)rOr4)r*r4)Zloglevelr�)rOr0)r�rr-r�r-r�rrj)r8r�r4r*r:r:r;�test_incompatibleBs



z!BasicConfigTest.test_incompatiblecCs�t��t�tj�t��g}t��}|d�|�tj|d�|�|dtjj	d�|�|dtjj	d�|�|dtjj	d�|�
|dj�|�
|dj�|�|dj|�|�|dj|dj�dS)Nr�)r4rrW)rr-r�r�r/r2rr*r�r4r r))r8r4r�r:r:r;�
test_handlersQs

zBasicConfigTest.test_handlersNcsfg�tj����fdd�}t��td|�tt|�}|dk	rH||d�n|d����difg�dS)Ncs<��tjj}tj�d���tjj|���||f�dS)N�d)rr�r'r+r�rt)r�rr8)r��old_basic_configr8r:r;�my_basic_configgs
z2BasicConfigTest._test_log.<locals>.my_basic_configrztest mer:)rrrr�r!rI)r8r�r'r>rr:)r�r=r8r;rbs
zBasicConfigTest._test_logcCs|�dtj�dS)Nrr)rrrh)r8r:r:r;r	yszBasicConfigTest.test_logcCs|�d�dS)Nrv)r)r8r:r:r;r
|szBasicConfigTest.test_debugcCs|�d�dS)Nru)r)r8r:r:r;rszBasicConfigTest.test_infocCs|�d�dS)Nrt)r)r8r:r:r;r�szBasicConfigTest.test_warningcCs|�d�dS)Nrs)r)r8r:r:r;r
�szBasicConfigTest.test_errorcCs|�d�dS)Nr�)r)r8r:r:r;r�szBasicConfigTest.test_critical)N)rZr[r\r]r<rCr�r)r*r+r.r1r2r3r4r5r9r:r;rr	r
rrr
rr	r:r:)rr;r&�s.	


r&csLeZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	�Z
S)�LoggerAdapterTestcs�tt|���tjdd��t�|_tj|_|j�	|j�|�
|jj|j�|�
|jj��fdd�}|�
|�|�
tj
�tj|jdd�|_dS)Ncs�tjdd�<dS)N)rrr:)�old_handler_listr:r;r��sz(LoggerAdapterTest.setUp.<locals>.cleanup)r�rw)rr?r<rrr�rr�r�r6r�r>r=rNrq�adapter)r8r�)r)r@r;r<�s
zLoggerAdapterTest.setUpc
Cs�d}d}yddWn6tk
rJ}z|}|j�||j�Wdd}~XYnX|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dS)Nztesting exception: %rrWr)r�rAr�rrIrJr�r�rrdr�r�rvr�
__traceback__)r8r�r�r]r�r:r:r;�test_exception�s"z LoggerAdapterTest.test_exceptionc
Cs�yddWn&tk
r2}z|}Wdd}~XYnX|jjd|d�|�t|jj�d�|jjd}|�|j|j||j	f�dS)NrWrz
exc_info test)rv)
r�rAr�rIrJrr�rvrrB)r8r]r�r�r:r:r;�test_exception_excinfo�sz(LoggerAdapterTest.test_exception_excinfocCshd}|j�||j�|�t|jj�d�|jjd}|�|jtj�|�|j	|�|�|j
|jf�dS)Nzcritical test! %rrWr)rAr�rrIrJr�r�rrbr�r�)r8r�r�r:r:r;r�szLoggerAdapterTest.test_criticalcCsD|jjjj}d|jjj_|�t|jjjd|�|�|j�d��dS)N�!rA� )rAr�rrAr�r�r��isEnabledFor)r8r�r:r:r;�test_is_enabled_for�s
z%LoggerAdapterTest.test_is_enabled_forcCsR|�|j���x|jjD]}|j�|�qW|�|j���|�|j���dS)N)r7rAr3r�r4r>r�)r8r�r:r:r;�test_has_handlers�s
z#LoggerAdapterTest.test_has_handlerscCsLGdd�dtj�}d}||jdd�}||dd�}d|_|�t|�t|��|�tj||j�|�t	|jj
�d�|jj
d}|�|jtj�|�|jd|���|�|j
|jf�|j}|�|j|�|�|jj|�t�}z6||_|�|j|�|�|j|�|�|jj|�Wd||_X|�|j|�|�|j|�|�|jj|�dS)	Nc@seZdZdZdd�ZdS)z.LoggerAdapterTest.test_nested.<locals>.Adapter�AdaptercSs|j�d|��|fS)Nrn)r�)r8r�r�r:r:r;r!�sz6LoggerAdapterTest.test_nested.<locals>.Adapter.processN)rZr[r\r�r!r:r:r:r;rJ�srJzAdapters can be nested, yo.)r�rwZAdapterAdapterrWrzAdapter AdapterAdapter )rrqr�r�rIr2rrrbrrJr�r�r�r�rr*r�)r8rJr�rAZadapter_adapterr�Zorig_managerZtemp_managerr:r:r;�test_nested�s2zLoggerAdapterTest.test_nested)rZr[r\r<rCrDrrHrIrKr	r:r:)rr;r?�s

	r?cs�eZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Z�ZS)�
LoggerTestcsbtt|���t�|_tjdd�|_|j�|j�|�	|jj
|j�|�	|jj�|�	tj�dS)NZblah)r9)
rrLr<r�rrr{r�r6r�r>r=rN)r8)rr:r;r<�szLoggerTest.setUpcCs|�t|jjt��dS)N)r�r}r�r+r�)r8r:r:r;�test_set_invalid_levelsz!LoggerTest.test_set_invalid_levelc
Cs�d}d}yddWn6tk
rJ}z|}|j�||j�Wdd}~XYnX|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dS)Nztesting exception: %rrWr)r�r�r�rrIrJr�r�rrdr�r�rvrrB)r8r�r�r]r�r:r:r;rCs"zLoggerTest.test_exceptionc	Cs2t�tdd��|�t|jjdd�WdQRXdS)Nr)Troztest message)r�	swap_attrrr�r}r�rr)r8r:r:r;�!test_log_invalid_level_with_raisesz,LoggerTest.test_log_invalid_level_with_raisec	Cs,t�tdd��|j�dd�WdQRXdS)Nr)Froztest message)rrNrr�rr)r8r:r:r;�test_log_invalid_level_no_raisesz*LoggerTest.test_log_invalid_level_no_raisecsPg�t�|tjd�fdd��|jjdd�|�t��d�|�d�d�dS)	N�print_stackcs��|���S)N)rtrG)r�r�)r�r:r;r"rz=LoggerTest.test_find_caller_with_stack_info.<locals>.<lambda>T)r�rWzStack (most recent call last):
r)rr�r�	tracebackr�Z
findCallerrIrJ)r8r:)r�r;� test_find_caller_with_stack_infosz+LoggerTest.test_find_caller_with_stack_infoc
Cs�d}d}d}}}}}}}	t�|||||||||	�	}
xFdt|
j���D]0}|di}|jt|jj|||||||||	d�qRWdS)Nz	my record�
)rr�z
some value)rw�sinfo)	rZ_logRecordFactoryrN�__dict__�keysr�rjr��
makeRecord)
r8r9r'r��lnor�r�rvr�rU�rvr�rwr:r:r;�%test_make_record_with_extra_overwrite)s

z0LoggerTest.test_make_record_with_extra_overwritecCs\d}d}d}}}}}}}	ddi}
|jj||||||||
|	d�	}|�d|j�dS)Nz	my recordrTZ	valid_keyz
some value)rwrU)r�rXr,rV)r8r9r'r�rYr�r�rvr�rUrwr�r:r:r;�(test_make_record_with_extra_no_overwrite6sz3LoggerTest.test_make_record_with_extra_no_overwritecCsB|�|j���x|jjD]}|j�|�qW|�|j���dS)N)r7r�r3r4r>r�)r8r�r:r:r;rI?szLoggerTest.test_has_handlerscCs"t�d�}d|_|�|���dS)Nz
blah.childF)rrrzr�r3)r8Zchild_loggerr:r:r;�test_has_handlers_no_propagateFs
z)LoggerTest.test_has_handlers_no_propagatecCs>|jjj}d|jj_|�t|jjd|�|�|j�d��dS)N�rA�)r�rrAr�r�r�rG)r8r�r:r:r;rHKs

zLoggerTest.test_is_enabled_forcCs�t��}|�|tj�|�|t�d��|�|t�d��|�|t�d�j�|�|t�d�j�|�|t�d�j�|�|t�d��|�|t�d�j�dS)Nrr�zfoo.bar�)rrr*r��parentZassertIsNot)r8r�r:r:r;�test_root_logger_aliasesQsz#LoggerTest.test_root_logger_aliasescCs$|�ttjt�|�ttjd�dS)Nsfoo)r�r}rr�any)r8r:r:r;�test_invalid_names]szLoggerTest.test_invalid_namescCsVxPttjd�D]>}x8dD]0}t�|�}t�||�}t�|�}|�||�qWqWdS)NrW)rr�r�zfoo.barzbaz.bar)r�r�ZHIGHEST_PROTOCOLrrrVr�r*)r8�protor9r�rUZ	unpickledr:r:r;�
test_picklingas


zLoggerTest.test_picklingcCs6|j}t�d�}t�d�}|�tj�|�|��tj�|�|ji�|�|�	tj��|�
|�	tj��|�|jtjdtjdi�|�|ji�|�|�	tj��|�|ji�|�|�	tj��|�|jtjdi�|�tj�|�|��tj�|�|ji�|�
|�	tj��|�tj
�|�|��tj�|�|ji�|�|ji�|�|ji�|�
|�	tj��|�|�	tj��|�
|�	tj��|�|�	tj��|�|�	tj��t��|�|��tj�|�|ji�|�|ji�|�|ji�|�
|�	tj��|�
|�	tj��|�
|�	tj��dS)Nr�zabc.defTF)r%rrr+rdrIr&�_cacher7rGr�r,rbr�rA)r8r�r#r$r:r:r;�test_cachingisH

zLoggerTest.test_caching)rZr[r\r<rMrCrOrPrSr[r\rIr]rHrbrdrfrhr	r:r:)rr;rL�s	

	rLc@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BaseFileTestz1Base class for handler tests that write log filescCs0t�|�t�dd�\}|_t�|�g|_dS)Nz.logztest_logging-2-)r
r<r�r�r�r�r=�rmfiles)r8r�r:r:r;r<�s

zBaseFileTest.setUpcCsBx|jD]}t�|�qWtj�|j�r4t�|j�t�|�dS)N)rjr�r�r�r�r�r
rC)r8r�r:r:r;rC�s
zBaseFileTest.tearDowncCs*|jtj�|�d|d�|j�|�dS)z7Assert a log file is there and register it for deletionzLog file %r does not exist)r�N)r7r�r�r�rjrt)r8rOr:r:r;�
assertLogFile�szBaseFileTest.assertLogFileN)rZr[r\r]r<rCrkr:r:r:r;ri�sric@seZdZdd�ZdS)�FileHandlerTestcCsxt�|j�tj|jdd�}|�|j�|�tj�	|j��|�
t�i��|�|j�|�
tj�	|j��|��dS)NT)r�)r�r�r�rr�r/r*r�r�r�r�r�r r7r=)r8�fhr:r:r;�
test_delay�szFileHandlerTest.test_delayN)rZr[r\rnr:r:r:r;rl�srlc@sBeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zej	dd��Z
d
S)�RotatingFileHandlerTestc
Cst�dtjdd|��ddd�S)Nr�rhrW)rr�r,rY)r8r:r:r;�next_rec�sz RotatingFileHandlerTest.next_reccCs.tjj|jdd�}|�|�d��|��dS)Nr)�maxBytes)rr4r�r�r��shouldRolloverr=)r8�rhr:r:r;�test_should_not_rollover�sz0RotatingFileHandlerTest.test_should_not_rollovercCs2tjj|jdd�}|�|�|����|��dS)NrW)rq)rr4r�r�r7rrrpr=)r8rsr:r:r;�test_should_rollover�sz,RotatingFileHandlerTest.test_should_rollovercCs4tj�|j�}|�|���|�|j�|��dS)N)rr4r�r�r�rprkr=)r8rsr:r:r;�test_file_created�sz)RotatingFileHandlerTest.test_file_createdcCs�dd�}tjj|jddd�}||_|�|���|�|j�|�|���|�||jd��|�|���|�||jd��|�t	j
�||jd���|��dS)	NcSs|dS)Nz.testr:)r9r:r:r;�namer�sz>RotatingFileHandlerTest.test_rollover_filenames.<locals>.namerr�rW)�backupCountrqz.1z.2z.3)
rr4r�r�rwr�rprkr�r�r�r�r=)r8rwrsr:r:r;�test_rollover_filenames�sz/RotatingFileHandlerTest.test_rollover_filenamesc	Cs�dd�}dd�}tjj|jddd�}||_||_|��}|�|�|�|j�|��}|�|�||jd�}|�|�t	j
}t|d	��0}|��}	t
�|	�}
|�|
�d
�|j|�WdQRX|�|���||jd�}|�|�t|d	��0}|��}	t
�|	�}
|�|
�d
�|j|�WdQRX|�|���||jd�}t|d	��0}|��}	t
�|	�}
|�|
�d
�|j|�WdQRX|�t	j�||jd���|��dS)
NcSs|dS)Nz.gzr:)r9r:r:r;rw�sz3RotatingFileHandlerTest.test_rotator.<locals>.namerc
SsXt|d��:}|��}t�|d�}t|d��}|�|�WdQRXWdQRXt�|�dS)N�rbr|r/)rrP�zlib�compressr"r�r�)�source�destZsfr!�
compressedZdfr:r:r;�rotator�sz5RotatingFileHandlerTest.test_rotator.<locals>.rotatorr�rW)rxrqz.1rzr�z.2z.3)rr4r�r�r�rwrpr�rkr��lineseprrPr{Z
decompressrIr�r�r�r�r�r=)r8rwr�rsZm1Zm2r��newliner�rr!r:r:r;�test_rotator�sB



"

"
"z$RotatingFileHandlerTest.test_rotatorN)rZr[r\rprtrurvryrZ
requires_zlibr�r:r:r:r;ro�sroc@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�TimedRotatingFileHandlerTestc
s�tjj|jddd�}t�d�}|�|�t�ddi�}|�|�|�|j�t	�
d�t�ddi�}|�|�|��d	}tj�
�}d
}xNt|�D]B}|tj|d�}	|j|	�d��tj���}|r�|j���Pq�Wd
|}
|�s�tj�|j�\}��fdd�t�|�D�}td|�d�tjd�td|tjd�xJ|D]B}
td|
�tj�||
�}t|d��}t|���WdQRX�q@W|j||
d�dS)N�SrW)rxz%(asctime)s %(message)sr�ztesting - initialg�������?ztesting - after delayFi,)�secondsz.%Y-%m-%d_%H-%M-%Sz,No rotated files found, went back %d secondscsg|]}|���r|�qSr:)rR)r~r�)r�r:r;r�:sz>TimedRotatingFileHandlerTest.test_rollover.<locals>.<listcomp>z
Test time: %sz%Y-%m-%d %H-%M-%S)r�zThe only matching files are: %szContents of %s:r�)r�)rr4r�r�r/r2r�r�rkr�r�r=r�r�r��	timedeltaZstrftimer�r�r�rjrtr��listdirr�r�r-r�rrPr7)r8rmZfmtZr1Zr2�foundr��GO_BACK�secs�prevr�Zdn�filesr�r�Ztfr:)r�r;�
test_rolloversB






z*TimedRotatingFileHandlerTest.test_rollovercCsR|j}|ttjj|jddd�|ttjj|jddd�|ttjj|jddd�dS)N�XT)r��WZW7)r�r�rr4r�r�)r8r�r:r:r;�test_invalidDs


z)TimedRotatingFileHandlerTest.test_invalidcCsxd}t�ddd�}tjj|jdddd|d�}z<|�|�}|�||d�|�|d�}|�||d	�Wd|��XdS)
Nr��MIDNIGHTrWT)�when�intervalrxr��atTimei��iжi@�)	r�r�rr4r�r��computeRolloverrIr=)r8�currentTimer�rsrRr:r:r;�"test_compute_rollover_daily_attimeMs
z?TimedRotatingFileHandlerTest.test_compute_rollover_daily_attimec		Cs6tt���}||d}t�ddd�}t�|�j}x�td�D]�}tjj|j	d|ddd|d�}z�||krvd||}n||}|d9}|d	7}||7}|�
|�}||kr�td
tj�tdt
��|�||�||kr�|d7}|�
|d
�}||k�rtd
tj�tdt
��|�||�Wd|��Xq<WdS)Ni�Qr�rrzW%drWT)r�r�rxr�r�i��zfailed in timezone: %dzlocal vars: %si�:	iж)r�r�r�r�Ztm_wdayr�rr4r�r�r�r�Ztimezone�localsrIr=)	r8r�Ztodayr�ZwdayZdayrsrSrRr:r:r;�#test_compute_rollover_weekly_attime]s8

z@TimedRotatingFileHandlerTest.test_compute_rollover_weekly_attimeN)rZr[r\r�r�r�r�r:r:r:r;r�s*	r�cKstjf|�tjdd�S)NrW)r�)r�r�)rr:r:r;r��sr�)r�rW)�M�<)�Hi)�Di�Q)r�i�QZW0r��)ZdaysZhourscCsRtjj|j|dddd�}d}|�|�}||k�r:|dk�r:y�|jrNt�|�}n
t�|�}|d}|d}|d	}	tjj	|d
|d
|	}
||
}t
d||jftjd�t
d
|tjd�t
d|tjd�t
d|	tjd�t
d|
tjd�t
d|tjd�Wn0t
k
�r8t
dt��dtjd�YnX|�||�|��dS)NrWrT)r�r�rxr�gr�rar�r2r�z
t: %s (%s))r�zcurrentHour: %szcurrentMinute: %szcurrentSecond: %szr: %sz
result: %sz exception in diagnostic code: %s)rr4r�r�r�r�r�r�Z	localtimeZ	_MIDNIGHTr�r�r-r�rvrIr=)r8r��exprsr�rRrFZcurrentHourZ
currentMinuteZ
currentSecondr�r�r:r:r;�test_compute_rollover�s6



 r�ztest_compute_rollover_%sz>win32evtlog/win32evtlogutil/pywintypes required for this test.c@seZdZdd�ZdS)�NTEventLogHandlerTestc
Cs
d}t�d|�}t�|�}ytj�d�}Wn:tjk
rd}z|jdkrRt	�
d���Wdd}~XYnXt�ddi�}|�|�|�
�|�|t�|��tjtjB}d}d}	t�|||	�}
x4|
D],}|jdkr�q�t�||�}|d	kr�q�d
}Pq�Wd|	}|j||d�dS)
NZApplicationZtest_loggingr2z#Insufficient privileges to run testr�zTest Log MessageFr<zTest Log Message
Tz3Record not found in event log, went back %d records)r�)�win32evtlogZOpenEventLogZGetNumberOfEventLogRecordsrr4ZNTEventLogHandler�
pywintypesrsZwinerrorrZSkipTestr�r�r=Z
assertLessZEVENTLOG_BACKWARDS_READZEVENTLOG_SEQUENTIAL_READZReadEventLogZ
SourceName�win32evtlogutilZSafeFormatMessager7)r8ZlogtypeZelhZnum_recsrBr]r��flagsr�r�Zeventsr�r:r:r;rs�s8





z NTEventLogHandlerTest.test_basicN)rZr[r\rsr:r:r:r;r��sr�c@seZdZdd�ZdS)�MiscTestCasec
Cs2ddddddddd	d
ddd
h
}tj|t|d�dS)Nr"r$r#Zcurrentframer(ZStrFormatStyler_ZFiltererZPlaceHolderr|Z
RootLoggerr�r�)�	blacklist)rZcheck__all__r)r8r�r:r:r;�test__all__�szMiscTestCase.test__all__N)rZr[r\r�r:r:r:r;r��sr��LC_ALLrc'Csvtttttttttt	t
ttt
ttttttttttttttttttt t!t"t#t$t%t&g'}t't(j)d�rh|�*t+�t,j-|�dS)Nr�).r^r�r�r�rur�r�r�r�rrr&rur�r�r(r�r�r�r�r�r&r?rLrmrlror�rr�r�r�r�r�r�r�r�r�r�rrr4rtr�rZrun_unittest)Ztestsr:r:r;�	test_main�s
r��__main__)N)�r]rZlogging.handlersZlogging.configrr�r�r�r�r(rrUr�r�r�rDrr8r�r�r�Ztest.support.script_helperrrrrr�r�r�rrr�rGZhttp.serverrrr6Zurllib.parserrZsocketserverr	r
rrr�r�r�r�r{ZTestCaser
r^r�ZSILENTr�ZTERSEZEFFUSIVEr�r�Z	TALKATIVEr�Z
CHATTERBOXZBORINGr�r�r�r�r�r�r�r�r�rr-r#r&r(r7r4rLrPr_rdrrjrlrmrur/r�r�r�r�r�r�r�r�r�r�ZIPV6_ENABLEDr�r�r�rrr#r$r%r&rur�r�r�r�r�r4r�Z
unittest.mockr�r�r�r�Ztzinfor�r�r�r�r�r�r�r�r�r!r�r�r�rr&r?rLrirlror�r�r�r�r�r�r�r�Zrun_with_localer�rZr:r:r:r;�<module>sLmFY_,J5)/ NJY@CM41(
K#i`
	Y'W5Ol+Tn!#