Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_logging.cpython-310.pyc
o

�9jQ�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZddlmZddlmZddlmZddlmZdd	l m!Z!ddl"Z"ddl#Z#ddl$Z$ddl%Z%ddl&Z&ddl'Z'dd
l(m)Z)m*Z*ddl+m,Z,m-Z-ddl.m/Z/m0Z0m1Z1m2Z2e&�3��e&�4d
e5�ddl6Z6ddl7Z7Wd�n1s�wYzddl8Z8ddl9Z9ddl:Z:Wne;y�dZ8Z9Z:Ynwzddl<Z<Wn
e;�yYnwGdd�de%j=�Z>Gdd�de>�Z?Gdd�de>�Z@dZAdZBdZCdZDdZEdZFdZGdZHdZIdZJeKeJeAd�ZLeAdeBd eCd!eDd"eEd#eFd$eGd%eHd&eId'eJd(i
ZMGd)d*�d*ejN�ZOGd+d,�d,ejN�ZPGd-d.�d.e>�ZQGd/d0�d0e>�ZRGd1d2�d2eS�ZTGd3d4�d4ejU�ZVGd5d6�d6eS�ZWGd7d8�d8e>�ZXGd9d:�d:e7jY�ZZGd;d<�d<eS�Z[Gd=d>�d>e[e)�Z\Gd?d@�d@e[e1�Z]GdAdB�dBe[e/�Z^e_edC��r�GdDdE�dEe]�Z`GdFdG�dGe^�ZaGdHdI�dIe>�ZbGdJdK�dKe>�ZcGdLdM�dMejd�ZeGdNdO�dOe>�ZfGdPdQ�dQe>�ZgdRdS�Zhe%�ie_edC�dT�GdUdV�dVeg��ZjGdWdX�dXe>�Zke%�ie_edC�dT�GdYdZ�dZek��ZlGd[d\�d\e>�Zme%�ie_edC�dT�Gd]d^�d^em��Zne%�iejod_�Gd`da�daem��ZpGdbdc�dce>�ZqGddde�dee>�ZrGdfdg�dge>�ZsGdhdi�die>�Ztd�djdk�ZuGdldm�dm�Zvdndo�ZwGdpdq�dqejU�ZxGdrds�dse>�ZyGdtdu�due>�ZzGdvdw�dwe>�Z{Gdxdy�dyej|�Z}Gdzd{�d{e>�Z~Gd|d}�d}e>�Ze_ej�d~��r�ddl�Z�ddl�m�Z�Gd�d��d�e>�Z�e��d�Z�Gd�d��d�ej��Z�e��Z�Gd�d��d��Z�Gd�d��d�e%j=e��Z�Gd�d��d�ej��Z�Gd�d��d�e%j=�Z�Gd�d��d�e>�Z�Gd�d��d�e>�Z�Gd�d��d��Z�Gd�d��d�ej��Z�Gd�d��d�e>�Z�Gd�d��d�e>�Z�Gd�d��d�e>�Z�Gd�d��d�e%j=�Z�Gd�d��d�e%j=�Z�Gd�d��d�e>e��Z�Gd�d��d�e>�Z�Gd�d��d�e��Z�Gd�d��d�e��Z�Gd�d��d�e��Z�d�d��Z�d�d�d�d�d�d�e�d�d�d��ffD]\Z�Z�e�e�fd�d��Z�e�e�d�e�e���q�e%�ie8d��Gd�d��d�e>��Z�Gd�d��d�e%j=�Z�d�d��Z�e�d�k�r�e%���dSdS)�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�ignorec@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��z;tj�	�|_
tjdd�|_|�	�|_
}tj�	�|_tj�	�|_i|_}|D]}t||dd�||<q8Wt��nt��wt�d�|_t�d�|_t�d�|_|j��|_t��|_|j�tj�t�|j�|_ t�!|j"�|_#|j �$|j#�|j�%�r�|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)*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�hlist�rC�(/usr/lib/python3.10/test/test_logging.py�setUpVsD


��


zBaseTest.setUpcCs>|j��|j�|j�|jjr$|jjd}|j�|�|��|jjs|j�|j�t�	�z^tj
��tj
�|j
�tj��tj�|j�tj��tj�|j�|jtjdd�<t��j}d|_|j}|��|�|j�|j}|jD]}||dur�|||j|_qwWt��nt��w|��tj|j�dS)zJRemove our logging stream, and restore the original logging
        level.rN) r1�closer,�
removeHandlerr5r;r2r.rrr%�clear�updater&r#r$rrr!r rr�disablerr"r'rr)�
doCleanupsr�threading_cleanupr)r?�hrrr'rArCrCrD�tearDown�s>
�




��zBaseTest.tearDownNc	Cs�|p|j}t�|p|j�}|����}|�t|�t|��t||�D]\}}|�	|�}|s4|�
d|�|�t|���|�q"|�
�}|rN|�
d|�dSdS)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)r1�re�compile�expected_log_pat�getvalue�
splitlines�assertEqual�len�zip�search�fail�tuple�groups�read)	r?�expected_valuesr1�pat�actual_lines�actual�expected�match�srCrCrD�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�r?rCrCrD�next_message�s
zBaseTest.next_message�NN)�__name__�
__module__�__qualname__�__doc__r7rQrerErNrcrgrCrCrCrDrNs*
"rc@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dS)�BuiltinLevelsTestz*Test builtin levels and their inheritance.cCs"|j}t�d�}|�tj�t�t�d�i�}|�tj�t�d�}|�tj�|�tj	|��|�
|��|�tj	|��|�
|��|�|��|�|��|�tj	|��|�
|��|�|��|�|��|�
|��|�|��|�|��|�
|��|�
|��|�gd��dS)N�ERR�INF�DEB))rn�CRITICAL�1)rn�ERROR�2)rorq�3)rors�4)ro�WARNING�5)ro�INFO�6)rprq�7)rprs�8)rprw�9)rpry�10)rpr3�11)rgrrr2rs�
LoggerAdapterryr3�logrq�error�warning�info�debugrc)r?�mrnrorprCrCrD�	test_flat�s.

zBuiltinLevelsTest.test_flatcCs�|j}t�d�}|�tj�t�d�}|�tj�|�tj|��|�|��|�	|��|�
|��|�|��|�ddg�dS)Nro�INF.ERR)r�rqrr)r�rsrt�
rgrrr2ryrsr�rqr�r�r�r�rc)r?r�ro�INF_ERRrCrCrD�test_nested_explicit�s


�z&BuiltinLevelsTest.test_nested_explicitcCs�|j}t�d�}|�tj�t�d�}|�tj�t�d�}t�d�}t�d�}|�tj|��|�|��|�	|��|�
|��|�tj|��|�|��|�|��|�	|��|�
|��|�|��|�gd��dS)Nror��	INF.UNDEF�
INF.ERR.UNDEF�UNDEF))r�rqrr)r�rsrt)r�rwru)r�ryrv)r�rqrx)r�rsrzr�)r?r�ror��	INF_UNDEF�
INF_ERR_UNDEFr�rCrCrD�test_nested_inheriteds&




z'BuiltinLevelsTest.test_nested_inheritedcCs�|j}t�d�}t�d�}t�d�}|�tj�|�tj|��|�|��|�tj|��|�|��|�|��|�|��|�	gd��dS)Nro�INF.BADPARENT.UNDEF�
INF.BADPARENT))r�rqrr)r�ryrt)r�rqru)r�ryrv)
rgrrr2ryr��FATALr�r�rc)r?r�ro�
GRANDCHILD�CHILDrCrCrD�test_nested_with_virtual_parent's


z1BuiltinLevelsTest.test_nested_with_virtual_parentcCs,|�t�d�tj�|�t�tj�d�dS)z&See issue #22386 for more information.ryN)rTr�getLevelNameryrfrCrCrD�test_regression_22386Asz'BuiltinLevelsTest.test_regression_22386cCst�d�}|�|tj�dS)Nr�)rr�rTr�)r?�fatalrCrCrD�test_issue27935F�
z!BuiltinLevelsTest.test_issue27935cCs`t�tjd�|�tjtjd�|�t�tj�d�|�t�tj�d�|�t�d�tj�dS)z&See issue #29220 for more information.rry�NOTSETN)r�addLevelNamery�
addCleanuprTr�r�rfrCrCrD�test_regression_29220Js
z'BuiltinLevelsTest.test_regression_29220N)rirjrkrlr�r�r�r�r�r�r�rCrCrCrDrm�s/#rmc@�(eZdZdZdd�Zdd�Zdd�ZdS)	�BasicFilterTestzTest the bundled Filter class.c	Cs�t�d�}|jjd}zD|�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�ddg�W|�	|�dS|�	|�w)N�	spam.eggsr�spam�spam.eggs.fish�spam.bakedbeans�r�ryrt�r�ryru)
r�Filterr,r;�	addFilterrr�rgrc�removeFilter)r?�filter_�handlerr��	spam_eggs�spam_eggs_fish�spam_bakedbeansrCrCrD�test_filterVs"





�zBasicFilterTest.test_filterc	Cs�dd�}|jjd}zD|�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�dd	g�W|�|�dS|�|�w)
NcSs&|j�d�}d�|dd��}|dkS)N�.�r�)rA�split�join)�record�parts�prefixrCrCrD�
filterfuncrsz8BasicFilterTest.test_callable_filter.<locals>.filterfuncrr�r�r�r�r�r�)	r,r;r�rrr�rgrcr�)r?r�r�r�r�r�r�rCrCrD�test_callable_filterns"




�z$BasicFilterTest.test_callable_filtercCs*t��}t�ddi�}|�|�|��dS)NrAr�)rr��
makeLogRecordr>�filter)r?�f�rrCrCrD�test_empty_filter�sz!BasicFilterTest.test_empty_filterN)rirjrkrlr�r�r�rCrCrCrDr�Rs
r��x�w�v�u�t�s�r�q�p�ord�Silent�Taciturn�Terse�Effusive�Sociable�Verbose�	Talkative�	Garrulous�
Chatterbox�Boringc@�eZdZdZdd�ZdS)�GarrulousFilterz)A filter which blocks garrulous messages.cCs
|jtkS�N)�levelno�	GARRULOUS�r?r�rCrCrDr���
zGarrulousFilter.filterN�rirjrkrlr�rCrCrCrDr���r�c@r�)�VerySpecificFilterz5A filter which blocks sociable and taciturn messages.cCs|jttfvSr�)r��SOCIABLE�TACITURNr�rCrCrDr���zVerySpecificFilter.filterNr�rCrCrCrDr��r�r�c@�<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�CustomLevelsAndFiltersTestz@Test various filtering possibilities with custom logging levels.�^[\w.]+ -> (\w+): (\d+)$cCs,t�|�t��D]
\}}t�||�q	dSr�)rrE�my_logging_levels�itemsrr�)r?�k�vrCrCrDrE�s
�z CustomLevelsAndFiltersTest.setUpcCstD]
}|�||���qdSr�)�LEVEL_RANGEr�rg)r?�logger�lvlrCrCrD�log_at_all_levels�s�z,CustomLevelsAndFiltersTest.log_at_all_levelscCs*|j�t�|�|j�|�gd��dS)N)�r�rx�r�rz�r�r{�r�r|�r�r}�r�r~)r,r2�VERBOSEr�rcrfrCrCrD�test_logger_filter�sz-CustomLevelsAndFiltersTest.test_logger_filterc	Cs^|jjd�t�z|�|j�|�gd��W|jjd�tj�dS|jjd�tj�w)Nr)r�r�r�r�r�)r,r;r2r�r�rcrr�rfrCrCrD�test_handler_filter�s
.z.CustomLevelsAndFiltersTest.test_handler_filterc	Cs�|jjd}d}t�}|�|�z7|�|j�gd�}|�|�t�}|j�|�|�|j�|�|gd��W|rA|j�|�|�|�dS|rP|j�|�|�|�w)Nr)	)r�rr)r�rt)r�rvr�r�r�r�r�r�))r�r)r��12)r��14)r��15)r��17)r��18)r��20)r,r;r�r�r�rcr�r�)r?r��specific_filter�garr�first_linesrCrCrD�test_specific_filters�s$

�z0CustomLevelsAndFiltersTest.test_specific_filtersN)
rirjrkrlrQrEr�r�r�r�rCrCrCrDr��sr�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�generic�anothergeneric)r�HandlerrArT�assertRaises�NotImplementedError�emit�r?rMrCrCrD�	test_nameszHandlerTest.test_namec
Cs�tjdvr�dD]t}t��\}}t�|�|st�|�tjj	|ddd�}|rb|j
|j}}|�|d�|�|d�t�
ddi�}|�|�t�|�|�tj�|��|�|�|�tj�|��n|�|j
d�|�|jd�|��|r{t�|�qtjd	kr�d
}nd}ztj�|�}|�|j|j�|�|j�|��Wn	ty�YnwdD]}	|	d
kr�|�ttjjdd|	�q�tj�dd|	�}|��q�tj�d�}t�
i�}|�|�|��|��tj�d�}|�|�|��|��dS)N��linux�darwin)TF�utf-8T��encoding�delay����msg�Testr
z/var/run/syslogz/dev/log)�GET�POST�PUTr�	localhostz/logrrd)�sys�platform�tempfile�mkstemp�osrF�unlinkrr;�WatchedFileHandler�dev�inorTr��handle�assertFalse�path�existsr>�
SysLogHandler�facility�LOG_USER�
unixsocket�OSErrorr�
ValueError�HTTPHandler�BufferingHandler�shouldFlush)
r?�existing�fd�fnrMrrr��sockname�methodrCrCrD�test_builtin_handlers's`






�
��

z!HandlerTest.test_builtin_handlerscCs�t��\}}t�|�t�|�t�|�}tj|dfftj	j
|dfftj	j|dfff}tj
dvr;|tj	j|dfff7}|D]\}}||ddi�}|�tj�|��|��t�|�q=dS)zs
        Test that Path objects are accepted as filename arguments to handlers.

        See Issue #27493.
        �w�arMrr
rN)rrrrFr�pathlib�Pathr�FileHandlerr;�RotatingFileHandler�TimedRotatingFileHandlerrrrr>r!r")r?r-r.�pfn�cases�cls�argsrMrCrCrD�test_path_objects]s 


�
�zHandlerTest.test_path_objects�ntz/WatchedFileHandler not appropriate for Windows.c
sD�fdd�}d}d}d�_d�_dD]�}t�dd�\}}t�|�tj|||fd�}d|_|�	�t
jj|d	|d
�}t
�
d�}	|�|	�zFt|�D],}
t�d�t
�d
di�}zt���_|�|�WqItyutd�j�jf��wW|��|��tj�|�r�t�|�q|��|��tj�|�r�t�|�wwdS)Nc	sTt|�D]#}zt�|�t���_Wn	tyYnwt�dt�dd��qdS)Ng����Mbp?r�)	�rangerr�time�
deletion_timer'�sleep�random�randint)�fname�tries�_rfrCrD�remove_loopws
��z*HandlerTest.test_race.<locals>.remove_loopi��FT�.logztest_logging-3-��targetr<Trrz'%(asctime)s: %(levelname)s: %(message)s�{�G�zt?r�testingzDeleted at %s, opened at %s)�handle_timerBrrrrF�	threading�Thread�daemon�startrr;rr6r9r@rArCr�r�	Exception�printr�r!r"r)r?rI�	del_count�	log_countrr-r.�removerrMr�rHr�rCrfrD�	test_racetsR	




����
����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�Wt�d�dSt�d�w|�d����|��tj|dd
�dS)z>Ensure child logging locks are not held; bpo-6721 & bpo-36533.c�$eZdZ�fdd�Zdd�Z�ZS)zAHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandlercs&t���tjtdddd�d�|_dS)Nz	/dev/null�wtr�r
�r1)�super�__init__rr4�open�sub_handlerrf��	__class__rCrDra�s
�zJHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.__init__cSs4|j��z|j�|�W|j��dS|j��wr�)rc�acquirer�releaser�rCrCrDr�s
zFHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.emit�rirjrkrar�
__classcell__rCrCrdrD�_OurHandler�srjrz*because we need at least one for this testrd� test_post_fork_child_no_deadlockcsTt��z ���z�����d�W���n���wWt��dSt��w)N��?)rrrf�set�waitrgr)rC��+fork_happened__release_locks_and_end_thread�locks_held__ready_to_fork�refed_hrCrD�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)rMrAz#Child process did not deadlock. \o/z&Parent process returned from fork. \o/)�exitcodeN)rrrTrUrr�rcr1rFrA�
assertGreater�_at_fork_reinit_lock_weaksetrr=r2r3rQ�EventrRrTrnrr[r��_exitrmr�r�wait_process)r?rj�test_loggerrs�lock_holder_thread�pidrCrorDrk�s8


�
z,HandlerTest.test_post_fork_child_no_deadlockN)
rirjrkrr1r=�unittest�skipIfrrArZ�hasattrrkrCrCrCrDr�s6
0r�c@�eZdZdd�ZdS)�	BadStreamcCstd��)N�deliberate mistake)�RuntimeError�r?�datarCrCrD�write��zBadStream.writeN)rirjrkr�rCrCrCrDr���r�c@r�)�TestStreamHandlercC�
||_dSr�)�error_recordr�rCrCrD�handleError�r�zTestStreamHandler.handleErrorN)rirjrkr�rCrCrCrDr��r�r�c@seZdZejZdZdS)�StreamWithIntNamer�N)rirjrkrr��levelrArCrCrCrDr��sr�c@�$eZdZdd�Zdd�Zdd�ZdS)�StreamHandlerTestcCs�tt��}t�i�}tj}ze|�|�|�|j|�t�t��}t	�
��}|�|�d}|�||���Wd�n1s>wYdt_t	�
��}|�|�|�
d|���Wd�n1sbwYW|t_dSW|t_dS|t_w)Nz"
RuntimeError: deliberate mistake
Fr)r�r�rr��raiseExceptionsr�assertIsr�r4r�captured_stderr�assertInrRrT)r?rMr��	old_raise�stderrrrCrCrD�test_error_handling�s(




�

�
�z%StreamHandlerTest.test_error_handlingcCsVt��}t��}|�|�}|�|tj�|�|�}|�||�|�|�}|�|�dS)z3
        Test setting the handler's stream
        N)	rr4r/r0�	setStreamr�rr��assertIsNone)r?rMr1�oldr_rCrCrD�test_stream_settings


z%StreamHandlerTest.test_stream_settingcCs t�t��}|�t|�d�dS)Nz<StreamHandler 2 (NOTSET)>)rr4r�rT�reprrrCrCrD�'test_can_represent_stream_with_int_name"sz9StreamHandlerTest.test_can_represent_stream_with_int_nameN)rirjrkr�r�r�rCrCrCrDr��sr�c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�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.
    cCsBtjj||d|dd�|j��d|_||_d|_d|_||_	dS)NT)�map�decode_datardF)
�smtpd�
SMTPServerra�socket�getsockname�port�_handler�_thread�_quit�
poll_interval)r?�addrr�r��sockmaprCrCrDra>s�
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�)r?�peer�mailfrom�rcpttosr�rCrCrD�process_messageGs
zTestSMTPServer.process_messagecC�,tj|j|jfd�|_}d|_|��dS)zG
        Start the server running on a separate daemon thread.
        rLTN�rQrR�
serve_foreverr�r�rSrT�r?�trCrCrDrTS�
�zTestSMTPServer.startcCs&|jstj||jdd�|jrdSdS)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`.
        rd)r��countN)r��asyncore�loop�_map�r?r�rCrCrDr�\s�zTestSMTPServer.serve_forevercCs4d|_t�|j�d|_|��tj|jdd�dS)zr
        Stop the thread by closing the server instance.
        Wait for the server thread to terminate.
        TN)r��
ignore_all)r�r�join_threadr�rFr��	close_allr�rfrCrCrD�stopgs
zTestSMTPServer.stopN)	rirjrkrlrar�rTr�r�rCrCrCrDr�)s		r�cs8eZdZdZdd�Zdd�Z�fdd�Zdd	�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��|_dSr�)r�r�r�rQrw�ready)r?r�r�rCrCrDra�szControlMixin.__init__cCr�)zI
        Create a daemon thread to run the server, and start it.
        rLTNr�r�rCrCrDrT�r�zControlMixin.startcs|j��tt|��|�dS)z^
        Run the server. Set the ready flag before entering the
        service loop.
        N)r�rmr`r�r�r�rdrCrDr��s
zControlMixin.serve_forevercCs:|��|jdurt�|j�d|_|��|j��dS)zK
        Tell the server thread to stop, and wait for it to do so.
        N)�shutdownr�rr��server_closer�rHrfrCrCrDr��s
zControlMixin.stop)	rirjrkrlrarTr�r�rirCrCrdrDr�ss	r�c@s&eZdZdZ		d	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.
    rlFNcs<G��fdd�dt��t�||��t�|||�||_dS)Ncs2eZdZddd�Zdd�Z���fdd�Z�ZS)	z=TestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandlerNcSs|�d�r|jSt|��)N�do_)�
startswith�process_request�AttributeError)r?rA�defaultrCrCrD�__getattr__�s
zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.__getattr__cS�|j�|�dSr���serverr�rfrCrCrDr���zMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_requestcs$�rt�|�j|g|�R�dSdSr�)r`�log_message)r?�formatr<)�DelegatingHTTPRequestHandlerrer�rCrDr��s����zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_messager�)rirjrkr�r�r�rirC�r�r�rdrDr��s
r�)rr
rar��sslctx)r?r�r�r�r�r�rCr�rDra�s

zTestHTTPServer.__init__c
Csdz|j��\}}|jr|jj|dd�}W||fSW||fSty1}z	tj�d|��d}~ww)NT)�server_sidezGot an error:
%s
)r��acceptr��wrap_socketr'rr�r�)r?�sockr��erCrCrD�get_request�s����zTestHTTPServer.get_request)rlFN)rirjrkrlrar�rCrCrCrDr��s

�r�cs2eZdZdZdZ		ddd�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.
    TrlcCs2Gdd�dt�}t�||||�t�|||�dS)Nc@r�)z;TestTCPServer.__init__.<locals>.DelegatingTCPRequestHandlercSr�r�r�rfrCrCrDr�r�zBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handleN)rirjrkrrCrCrCrD�DelegatingTCPRequestHandler��r�)rrrar�)r?r�r�r��bind_and_activater�rCrCrDra�s

�zTestTCPServer.__init__c�"tt|���|j��d|_dS�Nrd)r`r��server_bindr�r�r�rfrdrCrDr���zTestTCPServer.server_bind�rlT)rirjrkrl�allow_reuse_addressrar�rirCrCrdrDr��s
�
r�cs:eZdZdZ		d
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.
    rlTcs<G�fdd�dt��t�||�|�t�|||�d|_dS)Ncs&eZdZdd�Z��fdd�Z�ZS)z;TestUDPServer.__init__.<locals>.DelegatingUDPRequestHandlercSr�r�r�rfrCrCrDrr�zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.handlecsF|j��}|r!z
t�|���WdSty |jjs�YdSwdSr�)�wfilerRr`�finishr'r��_closedr�)�DelegatingUDPRequestHandlerrerCrDr�s
���zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish)rirjrkrr�rirC�r�rdrDr�sr�F)rrrar�r�)r?r�r�r�r�rCr�rDra�s�
zTestUDPServer.__init__cr�r�)r`r�r�r�r�r�rfrdrCrDr�r�zTestUDPServer.server_bindcstt|���d|_dS)NT)r`r�r�r�rfrdrCrDr�s
zTestUDPServer.server_closer�)rirjrkrlrar�r�rirCrCrdrDr��s
�r��AF_UNIXc@�eZdZejZdS)�TestUnixStreamServerN�rirjrkr�r��address_familyrCrCrCrDr��
r�c@r�)�TestUnixDatagramServerNr�rCrCrCrDr� r�r�c@s"eZdZejZdd�Zdd�ZdS)�SMTPHandlerTestc
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)Nr���MbP?�me�you�Log)�timeoutru	Hello ✓rdz
Subject: Log
u

Hello ✓)r�r�HOSTr�rTr�rr;�SMTPHandler�TIMEOUTrT�toaddrs�messagesr�rQrw�handledrrnr�r>�is_setrUr��endswithrF)
r?r�r�r�rMr�r�r�r�r�rCrCrD�
test_basic)s0��

zSMTPHandlerTest.test_basiccGs|j�|�|j��dSr�)r��appendr�rm)r?r<rCrCrDr�AszSMTPHandlerTest.process_messageN)rirjrkr�LONG_TIMEOUTr�r�r�rCrCrCrDr�%sr�c@r�)�MemoryHandlerTestzTests for the MemoryHandler.r�cCsFt�|�tj�dtj|j�|_t�d�|_	d|j	_
|j	�|j�dS)N�
�memr)rrErr;�
MemoryHandlerrwr5�mem_hdlrr�
mem_logger�	propagater=rfrCrCrDrELs
�zMemoryHandlerTest.setUpcC�|j��t�|�dSr�)rrFrrNrfrCrCrDrNT�
zMemoryHandlerTest.tearDowncCs�|j�|���|�g�|j�|���|�g�|j�|���gd�}|�|�dD]1}td�D]
}|j�|���q3|�|�|j�|���|dd�t||d�D�}|�|�q-|j�|���|�|�dS)N)�r3rr�ryrt)rwru)r?��	cSsg|]}dt|�f�qS)r3)�str)�.0�irCrCrD�
<listcomp>nsz0MemoryHandlerTest.test_flush.<locals>.<listcomp>r)rr�rgrcr�r�r@)r?�lines�nrrCrCrD�
test_flushXs 



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
rrFN)rr�rgrcr�rGrrFrr;rrwr5r=)r?rrCrCrD�test_flush_on_closets,


�
�


z%MemoryHandlerTest.test_flush_on_closec
Cs�Gdd�d�}||j�}z,|j�|�td�D]}t�d�|j�d�|j�d�qW|jD]}t	�
|�q/dS|jD]}t	�
|�q<w)Nc@r�)zZMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandlercSs||_g|_dSr�)r�threads)r?rrCrCrDra�s
zcMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.__init__cSs|j�d�dSr�)r�	setTargetrfrCrCrD�removeTarget�r�zgMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.removeTargetcSs&tj|jd�}|j�|�|��dS)N)rM)rQrRrrr�rT)r?r�threadrCrCrDr�szaMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.handleN)rirjrkrarrrCrCrCrD�MockRaceConditionHandler�srrrNznot flushed�flushed)rrr@rArCrr�r�rrr�)r?rrMrHrrCrCrD�&test_race_between_set_target_and_flush�s


�
��z8MemoryHandlerTest.test_race_between_set_target_and_flushN)
rirjrkrlrQrErNrrrrCrCrCrDrEsrc@r�)�ExceptionFormatterzA special exception formatter.cCsd|djS)Nz
Got a [%s]r)ri)r?�eirCrCrD�formatException�r�z"ExceptionFormatter.formatExceptionN)rirjrkrlrrCrCrCrDr�src@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,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.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=
    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=
    cKs,t�t�|��}tjj|fddi|��dS)Nr
r)r/r0�textwrap�dedentr�config�
fileConfig)r?�conf�kwargs�filerCrCrD�apply_config�szConfigFileTest.apply_configcC�xt���.}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�Wd�dS1s5wYdS�N�rsrtr_�
r�captured_stdoutr)�config0rrr�rgr�rc�r?�outputr�rCrCrD�test_config0_ok��
��"�zConfigFileTest.test_config0_okcCs�t���@}t�t�|j��}t��}|�	|�t
j�|�t
�
�}|�|���|�|���|jdg|d�|�g�Wd�dS1sGwYdSr+)rr.r/r0r"r#r/�configparser�ConfigParser�	read_filerr$r%rr�rgr�rc)r?r1r(�cpr�rCrCrD�test_config0_using_cp_ok�s

��"�z'ConfigFileTest.test_config0_using_cp_okcC�zt���/}|�|�t�d�}|�|���|�|���|jddg|d�|�g�Wd�dS1s6wYdS�N�compiler.parser�ryrrr,r_�	rr.r)rrr�rgr�rc�r?r$r1r�rCrCrD�test_config1_ok��


��"�zConfigFileTest.test_config1_okcC�|�t|j|j�dSr��rrUr)�config2rfrCrCrD�test_config2_failure��z#ConfigFileTest.test_config2_failurecCrAr��rrUr)�config3rfrCrCrD�test_config3_failure�rEz#ConfigFileTest.test_config3_failurec	Cs�t���8}|�|j�t��}zt��ty t�d�Ynwtj	�
d�|�|��d�|�
g�Wd�dS1s?wYdS�Nzjust testingrz-ERROR:root:just testing
Got a [RuntimeError]
)rr.r)�config4rrr��	exceptionr�stdout�seekrTrRrcr0rCrCrD�test_config4_ok�s
�
�"�zConfigFileTest.test_config4_okcC�|j|jd�dS�N)r$�r?�config5rfrCrCrD�test_config5_ok��zConfigFileTest.test_config5_okcCrOrP)r?�config6rfrCrCrD�test_config6_okrTzConfigFileTest.test_config6_okcC�Jt���;}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
gd�|d�|�
g�Wd�n1sBwYt���P}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
gd�|d�|�
g�Wd�dS1s�wYdS�Nr;zcompiler-hyphenated)r<r,)rqrur_�compiler.lexer))ryrv)rsrx)ryrz)rsr{)rr.r)�config1arrr�rgr��criticalrc�config7r r�r?r1r��
hyphenatedrCrCrD�test_config7_ok�6



��



�"�zConfigFileTest.test_config7_okcCs�dd�}|���1t�dd�\}}t�|�tjdkr!|�dd�}|jj|d�}|�	|�|�	|�Wd�n1s<wYt
jjd	}|�
|||�dS)
NcS�|��t�|�dSr��rFr�remove��h1r.rCrCrD�cleanup1�z/ConfigFileTest.test_config8_ok.<locals>.cleanuprK�test_logging-X-r>�\z\\)rr)�check_no_resource_warningrrrrFrA�replace�config8r�r)r�rootr;r�)r?rfr-r.rlr�rCrCrD�test_config8_ok/s



�zConfigFileTest.test_config8_okcCsZ|�|j�t�d�}|�|j�|�|j�|�|j�|j|jdd�|�|j�dS)N�some_pristine_loggerF)�disable_existing_loggers)r)�disable_testrrr rr>�r?r�rCrCrD�test_logger_disablingFs
z$ConfigFileTest.test_logger_disablingcCs*d}|�|�|�t��jdjd�dS)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)rTrrr;rA)r?�test_configrCrCrD�test_config_set_handler_namesOs
z,ConfigFileTest.test_config_set_handler_namescCs�t�d���}tjddd�\}}z*t�||�d��t�|�t	j
j|dtddd	d
ddd
�id�d�Wt�
|�dSt�
|�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_z.ini�r��suffix�asciirrdFrz5%(asctime)s [%(process)d] [%(levelname)s] %(message)sz[%Y-%m-%d %H:%M:%S %z]zlogging.Formatter)r��datefmt�class)�versionrp�
formatters)r
�defaultsN)r"r#�striprrrr��encoderFrr$r%�dictr)r?�inir-r.rCrCrD�!test_defaults_do_no_interpolationgs,�
����z0ConfigFileTest.test_defaults_do_no_interpolationN)!rirjrkrlrrjrQr/�config1rZrkrCrGrJrRrUr\rlrqr)r2r8r?rDrHrNrSrVr_rnrsrvr�rCrCrCrDr �sB  ��*&+	r c@s@eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
S)�SocketHandlerTestzTest for SocketHandler objects.�rrc
Cs�t�|�d|_|_|_z|�|j|jd�|_}|��Wnt	y6}z
||_WYd}~dSd}~ww|j
��tj
j}t|jt�rN|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.N�{�G�z�?rrr)rrEr��	sock_hdlr�server_exception�server_class�address�
handle_socketrTr'r�rnrr;�
SocketHandler�
isinstance�server_addressrYr��
log_outputr,rGr=rQ�	Semaphorer��r?r�r��hclsrCrCrDrE�s*

���
zSocketHandlerTest.setUpc	Cs\z'|jr|j�|j�|j��|jr |j��Wt�|�dSWt�|�dSt�|�w)zShutdown the TCP server.N)r�r,rGrFr�r�rrNrfrCrCrDrN�s
�zSocketHandlerTest.tearDowncCs�|j}	|�d�}t|�dkrdSt�d|�d}|�|�}t|�|kr5||�|t|��}t|�|ks$t�|�}t�|�}|j	|j
d7_	|j��q)NTr?�>Lr�
)
�
connection�recvrU�struct�unpack�pickle�loadsrr�r�rr�rg)r?�request�conn�chunk�slen�objr�rCrCrDr��s

�


�zSocketHandlerTest.handle_socketcCsV|jr	|�|j�t�d�}|�d�|j��|�d�|j��|�|j	d�dS)N�tcpr��eggs�
spam
eggs
)
r��skipTestrrr�r�rfr�rTr�rrrCrCrD�test_output�s




zSocketHandlerTest.test_outputcCs�|jr	|�|j�d|j_|j��ztd��ty%|j�d�Ynw|j�	d�t
�
�}|�|jj|�t
�
|jj|d�|j�	d�dS)Ng@zDeliberate mistakez
Never sentzNever sent, eitherr�zNor this)r�r�r��
retryStartr�r�r�r,rKr�rAru�	retryTimerC)r?�nowrCrCrD�
test_noserver�s
�zSocketHandlerTest.test_noserverN)rirjrkrlr�r�r�rErNr�r�r�rCrCrCrDr��sr�cCs*tjddd�\}}t�|�t�|�|S)Nrwz.sockrx)rrrrFrc)r-r.rCrCrD�_get_temp_domain_socket�s

r�zUnix sockets requiredc@�.eZdZdZeed�r
eZdd�Zdd�Z	dS)�UnixSocketHandlerTestz)Test for SocketHandler with unix sockets.r�cC�t�|_t�|�dSr�)r�r�r�rErfrCrCrDrE��zUnixSocketHandlerTest.setUpcC�t�|�t�|j�dSr�)r�rNrrr�rfrCrCrDrN�
zUnixSocketHandlerTest.tearDownN)
rirjrkrlrr�r�r�rErNrCrCrCrDr���
r�c@�8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�DatagramHandlerTestzTest for DatagramHandler.r�c
Cs�t�|�d|_|_|_z|�|j|jd�|_}|��Wnt	y6}z
||_WYd}~dSd}~ww|j
��tj
j}t|jt�rN|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.Nr�rrr)rrEr�r�r�r�r��handle_datagramrTr'r�rnrr;�DatagramHandlerr�r�rYr�r�r,rGr=rQrwr�r�rCrCrDrE
s*

���
zDatagramHandlerTest.setUpc	C�\z'|jr	|j��|jr |j�|j�|j��Wt�|�dSWt�|�dSt�|�w)zShutdown the UDP server.N)r�r�r�r,rGrFrrNrfrCrCrDrN'�
�zDatagramHandlerTest.tearDowncCsTt�dd�}|jt|�d�}t�|�}t�|�}|j|j	d7_|j
��dS)Nr�rr�)r��pack�packetrUr�r�rr�r�rr�rm)r?r�r�r�r�r�rCrCrDr�2s

z#DatagramHandlerTest.handle_datagramcCs`|jr	|�|j�t�d�}|�d�|j��|j��|�d�|j��|�|j	d�dS)N�udpr�r�r�)
r�r�rrr�r�rnrHrTr�rrrCrCrDr�:s





zDatagramHandlerTest.test_outputN�rirjrkrlr�r�r�rErNr�r�rCrCrCrDr�sr�c@r�)�UnixDatagramHandlerTestz,Test for DatagramHandler using Unix sockets.r�cCr�r�)r�r�r�rErfrCrCrDrENr�zUnixDatagramHandlerTest.setUpcCr�r�)r�rNrrr�rfrCrCrDrNSr�z UnixDatagramHandlerTest.tearDownN�
rirjrkrlrr�r�r�rErNrCrCrCrDr�Fr�r�c@r�)�SysLogHandlerTestz!Test for SysLogHandler using UDP.r�c
Cs�t�|�d|_|_|_z|�|j|jd�|_}|��Wnt	y6}z
||_WYd}~dSd}~ww|j
��tj
j}t|jt�rR||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.Nr�r�)rrEr��sl_hdlrr�r�r�r�rTr'r�rnrr;r#r�r�rYr�r�r,rGr=rQrwr�r�rCrCrDrE^s*

���
zSysLogHandlerTest.setUpc	Cr�)zShutdown the server.N)r�r�r�r,rGrFrrNrfrCrCrDrNxr�zSysLogHandlerTest.tearDowncCs|j|_|j��dSr�)r�r�r�rm)r?r�rCrCrDr��rgz!SysLogHandlerTest.handle_datagramcCs�|jr	|�|j�t�d�}|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�dS)N�slh�späms
<11>spämFs	<11>spämuhäm-s<11>häm-späm)
r�r�rrr�r�rnrTr�rHr��
append_nul�identrrrCrCrDr��s 








zSysLogHandlerTest.test_outputNr�rCrCrCrDr�Wsr�c@r�)�UnixSysLogHandlerTestz)Test for SysLogHandler with Unix sockets.r�cCr�r�)r�r�r�rErfrCrCrDrE�r�zUnixSysLogHandlerTest.setUpcCr�r�)r�rNrrr�rfrCrCrDrN�r�zUnixSysLogHandlerTest.tearDownNr�rCrCrCrDr��r�r�z$IPv6 support required for this test.cs4eZdZdZeZdZ�fdd�Z�fdd�Z�Z	S)�IPv6SysLogHandlerTestz&Test for SysLogHandler with IPv6 host.)z::1rc�tj|j_tt|���dSr�)r��AF_INET6r�r�r`r�rErfrdrCrDrE�r�zIPv6SysLogHandlerTest.setUpcr�r�)r��AF_INETr�r�r`r�rNrfrdrCrDrN�r�zIPv6SysLogHandlerTest.tearDown)
rirjrkrlr�r�r�rErNrirCrCrdrDr��sr�c@r�)	�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)rrErQrwr�rfrCrCrDrE�s
zHTTPHandlerTest.setUpcCsn|j|_t|j�|_|jdkr'zt|jd�}|j�|�|_Wnd|_Y|�	d�|�
�|j��dS)NrzContent-Length��)
�commandrr!�log_data�int�headers�rfiler[�	post_data�
send_response�end_headersr�rm)r?r��rlenrCrCrD�handle_request�s

zHTTPHandlerTest.handle_requestc	Cs�t�d�}|j}|�|jjd�dD]�}d}|rJzddl}Wnty*d}Yn$wtj�	t
�}tj�|d�}|�|j
�}|�|�|j|d�}	nd}d}	t||jd|d�|_}
|
��|
j��d	|
j}|ok|}tjj|d
||	dd�|_d|_|�|j�d
D]T}
|
|j_|j��d}|�|�|j��|�|jjd
�|�|j |
�|
dkr�t!|jj"�}nt!|j#�$d��}|�|ddg�|�|ddg�|�|d|g�q�|j�%�|j�|j�|j�&�qdS)N�httprrJr�zkeycert.pem)�cafiler�)r�zlocalhost:%dz/frob)�foo�bar)�secure�context�credentials)rrr�rrrA�funcNamer�r)'rrr,rGr;�ssl�ImportErrorrr!�dirname�__file__r��
SSLContext�PROTOCOL_TLS_SERVER�load_cert_chain�create_default_contextr�r�r�rTr�rn�server_portr)�h_hdlrr�r=r0r�rHr�rTr�r
�queryr��decoder�rF)r?r�r,r�r�r�r��here�localhost_certr�r��host�
secure_clientr0r�drCrCrDr��sd
�
�


�



�zHTTPHandlerTest.test_outputN)rirjrkrlrEr�r�rCrCrCrDr��s

r�c@�0eZdZdZdd�Zdd�Zdd�Zdd	�Zd
S)�
MemoryTestz*Test memory persistence of logger objects.cCst�|�i|_dS)z8Create a dict to remember potentially destroyed objects.N)rrE�
_survivorsrfrCrCrDrE
s

zMemoryTest.setUpcGs.|D]}t|�t|�f}t�|�|j|<qdS)zKWatch the given objects for survival, by creating weakrefs to
        them.N)�idr��weakref�refr�)r?r<r��keyrCrCrD�_watch_for_survivals�zMemoryTest._watch_for_survivalcCs`t��g}|j��D]\\}}}|�dur|�|�q|r.|�dt|�d�|�f�dSdS)z;Assert that all objects watched for survival have survived.Nz;%d objects should have survived but have been destroyed: %sz, )�gc�collectr�r�r�rXrUr�)r?�dead�id_�repr_r�rCrCrD�_assertTruesurvivals

�
��zMemoryTest._assertTruesurvivalcCs�|j�tj�t�d�}|�|�|�tj�|j�|���|�|���|�	dg�~|�
�t�d�}|�|���|�	ddg�dS)Nr�)r�r3rt)r�r3ru)r,r2rryrr�r3r�rgrcr�)r?r�r�rCrCrD�test_persistent_loggers%s"

�

�z"MemoryTest.test_persistent_loggersN)rirjrkrlrEr�r�r�rCrCrCrDr�	sr�c@�eZdZdd�Zdd�ZdS)�EncodingTestc	Cs�t�d�}t�dd�\}}t�|�d}zStj|dd�}|�|�z|�|�W|�	|�|��n
|�	|�|��wt
|dd�}z|�|���
�|�W|��n|��wWtj�|�rft�|�dSdStj�|�rtt�|�ww)N�testrKztest_logging-1-ufoo€rr^)rrrrrrFr6r=r�rGrbrTr[�rstripr!�isfilerc)r?r�r-r.r�r�r�rCrCrD�test_encoding_plain_file>s,





�
��z%EncodingTest.test_encoding_plain_filec	Cs�t�d�}d}t�d�}d|_t��}||d�}t�|�}|�|�z|�	|�W|�
|�|��n
|�
|�|��w|��}|�
|d�dS)Nruдо свидания�cp1251�stricts�� �������
)rr�codecs�	getwriterr
r/�BytesIOr4r=r�rGrFrRrT)r?r��message�writer_classr1�writerr�rbrCrCrD�test_encoding_cyrillic_unicodeXs 







�
z+EncodingTest.test_encoding_cyrillic_unicodeN)rirjrkrr
rCrCrCrDr=src@r�)�WarningsTestc	Cs�t���ft�d�|�tjd�tjdtd�t��}t�	|�}t�
d�}|�|�t�d�|�
|�|��}|��|�|�d�d�t��}t�d	td
d|d�|��}|��|�|d
�Wd�dS1smwYdS)NTF�always)�category�py.warningszI'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�UserWarningr/r0r4rr=�warnrGrRrFru�find�showwarningrT)r?r1rMr�rb�a_filerCrCrD�
test_warningsps.






��"�zWarningsTest.test_warningscCs�t���<t�d�|�tjd�t�d�}|�|jg�t�dt	dd�|�t
|j�d�|�|jdtj�Wd�dS1sCwYdS)	NTFrrrrrdr)
rrrrr�rrTr;rrrU�assertIsInstance�NullHandlerrrrCrCrD�test_warnings_no_handlers�s


"�z&WarningsTest.test_warnings_no_handlersN)rirjrkrr!rCrCrCrDrnsrcCst�||�Sr�)rr6)r�r{rCrCrD�
formatFunc��r"c@seZdZddd�ZdS)�myCustomFormatterNcC�dSr�rC)r?�fmtr{rCrCrDra��zmyCustomFormatter.__init__r�)rirjrkrarCrCrCrDr$�sr$cCst��Sr�)rr4rCrCrCrD�handlerFunc�r�r(c@�eZdZdS)�
CustomHandlerN�rirjrkrCrCrCrDr*��r*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 ddeddd"dE�idddd	d
d�idFddgdBdC�idD�Z!ddeddd"dG�idddd	d
d�idFddgdBdC�idD�Z"ddedHdd"dG�idddd	d
d�idFddgdBdC�idD�Z#ddedd"dE�idddd	d
d�idFddgdBdC�idD�Z$dIdJ�Z%dKdL�Z&efdMdN�Z'dOdP�Z(dQdR�Z)dSdT�Z*dUdV�Z+dWdX�Z,dYdZ�Z-d[d\�Z.d]d^�Z/d_d`�Z0dadb�Z1dcdd�Z2dedf�Z3dgdh�Z4didj�Z5dkdl�Z6dmdn�Z7dodp�Z8dqdr�Z9d�dtdu�Z:dvdw�Z;dxdy�Z<dzd{�Z=d|d}�Z>d~d�Z?d�d��Z@d�d��ZAd�d��ZBd�d��ZCd�d��ZDd�d��ZEd�d��ZFd�d��ZGdsS)��ConfigDictTestz)Reading logging config from a dictionary.r!rd�form1r�z%(levelname)s ++ %(message)srt�logging.StreamHandlerr�zext://sys.stdout)r|�	formatterr�r1rw�r�r;)r}r~r;rmr;r3r�)r}r~r;�loggersrmzext://sys.stdbout�NTOSET�WRANING�misspelled_namez.ExceptionFormatterz"%(levelname)s:%(name)s:%(message)s)�()r�z.formatFunc)r.�form2�form3r6)rt�hand2z.CustomHandlerzinvalid parameter name)r|r0r�r1r}rYF)�compilerrY)r}rpr~r;r2rmTry)r}�incrementalr;r2�filt1rA)r|r0r�r1�filters)r�r=)r}r~r=r;r2rmzcfg://true_formatterszcfg://handler_configs[hand1])r}�true_formatters�handler_configsr~r;r2rm)r>r?r~r;r2rmr�r��!
)r��
terminator)r|r0r�r1r��mySimpleFormatterz1%(asctime)s (%(name)s) %(levelname)s: %(message)s�$)r��style)r|r�r0zlogging.handlers.MemoryHandler��
fileGlobal)r|�capacityr0rMr�)rF�bufferGlobal�mymodulerH�true)r�r;r)r}r~r;r2)r6r��validate�my_test_logger_custom_formatter)r|r�rKz.myCustomFormattercCstj�|�dSr�)rr$�
dictConfig)r?r&rCrCrDr)�r�zConfigDictTest.apply_configcCr*r+r-r0rCrCrDr2�r3zConfigDictTest.test_config0_okcCr9r:r=r>rCrCrDr?�r@zConfigDictTest.test_config1_okcCrAr�rBrfrCrCrDrD�rEz#ConfigDictTest.test_config2_failurecCrAr�)rrUr)�config2arfrCrCrD�test_config2a_failure�rEz$ConfigDictTest.test_config2a_failurecCrAr�)rrUr)�config2brfrCrCrD�test_config2b_failure�rEz$ConfigDictTest.test_config2b_failurecCrAr�rFrfrCrCrDrH�rEz#ConfigDictTest.test_config3_failurec	C�t���4}|�|j�zt��tyt�d�Ynwtj�	d�|�
|��d�|�g�Wd�dS1s;wYdSrI)
rr.r)rJr�rrKrrLrMrTrRrc�r?r1rCrCrDrN��
�
�"�zConfigDictTest.test_config4_okc	CrRrI)
rr.r)�config4ar�rrKrrLrMrTrRrcrSrCrCrD�test_config4a_ok�rTzConfigDictTest.test_config4a_okcCrOrPrQrfrCrCrDrS�rTzConfigDictTest.test_config5_okcCrAr�)rrUr)rUrfrCrCrD�test_config6_failure��z#ConfigDictTest.test_config6_failurecCst���/}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�Wd�n1s6wYt���;}|�|j
�t�d�}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�Wd�dS1s}wYdS)Nr;r<r,r_rY�ryru�rsrv)
rr.r)r�rrr�rgr�rcr\r>rr0rCrCrDr_�s8

���


��"�zConfigDictTest.test_config7_okcCs$t���/}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�Wd�n1s6wYt���I}|�|j
�t�d�}|�|j�|�|���|�|���t�d�}|�|���|�|���|j	gd�|d�|�	g�Wd�dS1s�wYdS)Nr;r<r,r_rY)rYrZ�ryrx�rsrz)
rr.r)r�rrr�rgr�rcrlr rr0rCrCrD�test_config_8_ok�s6

���



�"�zConfigDictTest.test_config_8_okcCrWrX)rr.r)rZrrr�rgr�r[rc�config8ar rr]rCrCrD�test_config_8a_okr`z ConfigDictTest.test_config_8a_okcCs�t���K}|�|j�t�d�}|�|���|jg|d�|�|j	�|�|���|jg|d�|�|j
�|�|���|jdg|d�Wd�dS1sRwYdS)Nr;r_rY)rr.r)�config9rrr�rgrc�config9a�config9br0rCrCrD�test_config_9_okGs 

��"�zConfigDictTest.test_config_9_okcCs�t���H}|�|j�t�d�}|�|���t�d�}|�|���t�d�}|�|���t�d�}|�|���|j	ddg|d�Wd�dS1sOwYdS�Nr;r:rYzcompiler.parser.codegen)rwrrrZr_)
rr.r)�config10rrr�rgr�rcr0rCrCrD�test_config_10_okYs"




��"�z ConfigDictTest.test_config_10_okcCs|�|j�dSr�)r?�config11rfrCrCrD�test_config11_oklr�zConfigDictTest.test_config11_okcCrAr�)rrUr)�config12rfrCrCrD�test_config12_failureorXz$ConfigDictTest.test_config12_failurecCrAr�)rrUr)�config13rfrCrCrD�test_config13_failurerrXz$ConfigDictTest.test_config13_failurecCs~t���1}|�|j�tjd}|�|jd�|�|jd�t�	d�|�
|���d��Wd�dS1s8wYdS)Nrtr�r@�Exclamationz
Exclamation!
)
rr.r)�config14rrrTr�rAr�r>rRr�)r?r1rMrCrCrD�test_config14_okus


"�zConfigDictTest.test_config14_okcCs�dd�}|���.t�dd�\}}t�|�ddd|dd	�id
dgid�}|�|�|�|�Wd�n1s9wYtjjd}|�	|||�dS)
NcSrar�rbrdrCrCrDrf�rgz0ConfigDictTest.test_config15_ok.<locals>.cleanuprKrhrdr(zlogging.FileHandlerr)r|�filenamer
r;�r}r;rmr)
rjrrrrFr)rrmr;r�)r?rfr-r.r$r�rCrCrD�test_config15_ok~s&

����
�zConfigDictTest.test_config15_okNc	Cs
|�d�}tj�d|�}|��|j��|j}|j��zVt	�	t	j
t	j�}|�d�|�
d|f�t�dt|��}||}d}t|�}	|	dkr]|�||d��}
||
7}|	|
8}	|	dksH|��W|j�d�tj��t�|�dS|j�d�tj��t�|�w)Nrrg@rr�)r�rr$�listenrTr�rnr�rHr�r��SOCK_STREAM�
settimeout�connectr�r�rU�sendrF�
stopListeningrr�)r?�text�verifyr�r�r�r�rb�	sentsofar�left�sentrCrCrD�setup_via_listener�s4



�

�
z!ConfigDictTest.setup_via_listenercCs�t���K}|�t�|j��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�
|�	��|jddg|d�Wd�dS1sRwYdSrd)rr.r~�json�dumpsrerrr�rgr�rcr0rCrCrD�test_listen_config_10_ok�s"




��"�z'ConfigDictTest.test_listen_config_10_okcCs�t���3}|�t�tj��t�d�}|�	|�
��|�|�
��|jddg|d�|�g�Wd�dS1s:wYdSr:)
rr.r~r"r#r r�rrr�rgr�rcr0rCrCrD�test_listen_config_1_ok�s

��"�z&ConfigDictTest.test_listen_config_1_okcCs�dd�}dd�}t�d�}t�tj�}t���}|�||�|�	|�
��|�|�
��Wd�n1s6wY|jg|d�|jddgd	d
�t��� }|�|�t�d�}|�	|�
��|�|�
��Wd�n1srwY|jddg|d�|jddgd	d
�t���&}|�|ddd
�|�t�d�}|�	|�
��|�|�
��Wd�n1s�wY|jddg|d�|jddgd	d
�dS)NcSr%r�rC��stuffrCrCrD�verify_fail�r'z6ConfigDictTest.test_listen_verify.<locals>.verify_failcSs|ddd�S)NrrCr�rCrCrD�verify_reverse�r�z9ConfigDictTest.test_listen_verify.<locals>.verify_reverser;r_r<r,r�)r]rYrZrr[r\)
rrr"r#r r�rr.r~r�rgr�rc)r?r�r�r��to_sendr1rCrCrD�test_listen_verify�sh

���


�����

����
�z!ConfigDictTest.test_listen_verifycCrAr�)rr(r)�out_of_orderrfrCrCrD�test_out_of_order
rXz ConfigDictTest.test_out_of_ordercCs\t�|j�}d|ddd<|�|�t�d�jd}|�|jtj	�|�|j
jtj�dS)Nz-${asctime} (${name}) ${levelname}: ${message}r~rBr�rIr)
r�deepcopyr�r)rrr;rrMrr0�_style�StringTemplateStyle�r?r$r�rCrCrD�#test_out_of_order_with_dollar_style
s

�z2ConfigDictTest.test_out_of_order_with_dollar_stylecC�.|�|j�t�d�jd}|�|jt�dS�NrLr)r)�custom_formatter_class_validaterrr;rr0r�r?r�rCrCrD�)test_custom_formatter_class_with_validate$
�z8ConfigDictTest.test_custom_formatter_class_with_validatecCr�r�)r)� custom_formatter_class_validate2rrr;rr0rr�rCrCrD�*test_custom_formatter_class_with_validate2)
r�z9ConfigDictTest.test_custom_formatter_class_with_validate2cCsF|j��}d|ddd<|�|�t�d�jd}|�|jt�dS)NrCr~r.rDrLr)	r�rr)rrr;rr0rr�rCrCrD�9test_custom_formatter_class_with_validate2_with_wrong_fmt.
s


zHConfigDictTest.test_custom_formatter_class_with_validate2_with_wrong_fmtcCrAr�)rr(r)� custom_formatter_class_validate3rfrCrCrD�*test_custom_formatter_class_with_validate37
rXz9ConfigDictTest.test_custom_formatter_class_with_validate3cCrAr�)rr(r)�custom_formatter_with_functionrfrCrCrD�,test_custom_formatter_function_with_validate:
rXz;ConfigDictTest.test_custom_formatter_function_with_validatecCs�dgd�ddd�dddd	gd
ggd�d�}tj�|�}|�|�d
�d�|�|�d�d�|�|�d�d�|�|�d�d	�|�|�d�d�|�|�d�d�|�d�}|�|�d�gd��|�t|jd�|�t|jd�|�t|jd�dS)N)rdr��)r3�b�cr�r�)r�r�)�g)rMr�jr��lr�r)�ozcfg://alist�p)�atuple�alist�adict�nest1�nest2�nest3zcfg://atuple[1]r�zcfg://alist[1]r�zcfg://nest1[1][0]rMzcfg://nest2[1][1]z
cfg://adict.dzcfg://adict[f]zcfg://nest3rdzcfg://nosuchzcfg://!zcfg://adict[2])	rr$�BaseConfiguratorrT�convert�popr�KeyErrorr()r?r��bcr�rCrCrD�test_baseconfig=
s&�
zConfigDictTest.test_baseconfigcs�ddlm�G�fdd�dtj�}�dddg�}|dd	gd
�}dd||d
�iddgd�d�}t���}|�|�t�d�Wd�n1sGwY|�|�	�d�dS)Nr��
namedtuplecs*eZdZ��fdd�Z�fdd�Z�ZS)z1ConfigDictTest.test_namedtuple.<locals>.MyHandlercst�j|i|��||_dSr�)r`ra�resource)r?r�r<r')rer�rCrDraX
s
z:ConfigDictTest.test_namedtuple.<locals>.MyHandler.__init__cs$|jd|jj��7_t��|�S�N� )rr��typer`rr�rdrCrDr\
sz6ConfigDictTest.test_namedtuple.<locals>.MyHandler.emitrhrCr�rdrD�	MyHandlerW
sr��Resourcer��labels�my_typer3)r�r�rd�	myhandler)r6r�ryr1rqzsome logzsome log my_type
)
�collectionsr�rr4rr�r)r�rTrR)r?r�r�r�r$r�rCr�rD�test_namedtupleS
s"	��
�


�zConfigDictTest.test_namedtuplecCs�dddddd�idddgd�id	�}t�d�}|�|j�|�|�|�|j�|�d
di�|�|j�|d=|�|�|�|j�dS)NrdF�consoler3r/)r�r|r3r1)r}rpr;r2r}rp)rrr rr)r>)r?r$r�rCrCrD�
test_90195r
s,�����


zConfigDictTest.test_90195r�)HrirjrkrlrrjrQr/r�rZrCrNrPrGrJrr"r(rUrRrUr\rlr^r`rarbrergrirkrnr�r�r�r�r�r)r2r?rDrOrQrHrNrVrSrWr_r]r_rcrfrhrjrlrorrr~r�r�r�r�r�r�r�r�r�r�r�r�r�rCrCrCrDr-�s�����	������	��������	��������	��������	��������	��������	��������	�����������#����	��������
��������	��������
��	������
��	������	��������������������
����#���������!������������������ �����
����������!����	�������	�������	�������	���!+	
>
	r-c@r�)�ManagerTestcsng�G�fdd�dtj�}t�d�}|�t|jt�|�|�|�d�}|�d�t�d�|�	�dg�dS)NcseZdZd�fdd�	ZdS)z6ManagerTest.test_manager_loggerclass.<locals>.MyLoggerNcs��|�dSr��r�)r?r�rr<�exc_info�extra��loggedrCrD�_log�
r�z;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._logrh)rirjrkr�rCr�rCrD�MyLogger�
sr�rzshould appear in loggedzshould not appear in logged)
r�Logger�Managerr�	TypeError�setLoggerClassr�rr�rT)r?r��manr�rCr�rD�test_manager_loggerclass�
s




z$ManagerTest.test_manager_loggerclasscCs,t�d�}t�}|�|�|�|j|�dSr�)rr��object�setLogRecordFactoryrT�logRecordFactory)r?r�r`rCrCrD�test_set_log_record_factory�
s

z'ManagerTest.test_set_log_record_factoryN)rirjrkr�r�rCrCrCrDr��
sr�c@r�)�ChildLoggerTestcCs�t��}t�d�}t�d�}|�d�}|�d�}|�|t�d��|�|t�d��|�d�}|�d�}|�d�}|�|t�d��|�|t�d��|�||�dS)	N�abczdef.ghi�xyzzuvw.xyz�def�ghi�abc.defzabc.def.ghi)rr�getChildr�)r?r��l1�l2�c1�c2�c3rCrCrD�test_child_loggers�
s






z"ChildLoggerTest.test_child_loggersN)rirjrkr�rCrCrCrDr��
r�r�c@r))�DerivedLogRecordNr+rCrCrCrDr��
r,r�c@r�)�LogRecordFactoryTestcCsBGdd�dtj�}t�|�|t�|_|j�|j�t��|_	dS)Nc@r�)z2LogRecordFactoryTest.setUp.<locals>.CheckingFiltercSr�r�)r;)r?r;rCrCrDra�
r�z;LogRecordFactoryTest.setUp.<locals>.CheckingFilter.__init__cSs,t|�}||jurd||jf}t|��dS)Nz)Unexpected LogRecord type %s, expected %sT)r�r;r�)r?r�r�rrCrCrDr��
s
�z9LogRecordFactoryTest.setUp.<locals>.CheckingFilter.filterN)rirjrkrar�rCrCrCrD�CheckingFilter�
�r�)
rr�rrEr�r�r,r��getLogRecordFactory�orig_factory)r?r�rCrCrDrE�
s


zLogRecordFactoryTest.setUpcCs(|j�|j�t�|�t�|j�dSr�)r,r�r�rrNrr�r�rfrCrCrDrN�
s
zLogRecordFactoryTest.tearDowncCs@|�t|jj|���t�t�|j�|���|�	dg�dS)N)rmrsrt)
rr�r,r�rgrr�r�r�rcrfrCrCrD�test_logrecord_class�
s�

�z)LogRecordFactoryTest.test_logrecord_classN)rirjrkrErNr�rCrCrCrDr��
sr�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)�QueueHandlerTestr�cCs`t�|�t�d�|_tj�|j�|_d|_t�	d�|_
d|j
_|j
�tj
�|j
�|j�dS)Nr�queF)rrE�queue�Queuerr;�QueueHandler�que_hdlrrAr�
que_loggerrr2rwr=rfrCrCrDrE�
s
zQueueHandlerTest.setUpcCrr�)r�rFrrNrfrCrCrDrN�
r	zQueueHandlerTest.tearDowncCs�|j�|���|�tj|jj�|j�|���|�tj|jj�|��}|j�|�|j��}|�	t
|tj��|�
|j|jj�|�
|j|jf|df�dSr�)r�r�rgrr��Empty�
get_nowaitr�r�r>r�r�	LogRecordrTrArr<)r?rr�rCrCrD�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})rA�	levelnamer
)rgrr�rwr�rAr6r7r�r9r�r�r�r�rTrr
)r?rr��log_format_str�
formatted_msgr0�
log_recordrCrCrD�test_formatting�
s�
z QueueHandlerTest.test_formatting�
QueueListenerz5logging.handlers.QueueListener required for this testcCs�tt���}tj�|j|�}|��z|j�	|�
��|j�|�
��|j�|�
��W|�
�n|�
�w|�|jtjdd��|�|jtjdd��|�|jtjdd��|��tt���}|�tj�tjj|j|dd�}|��z|j�	|�
��|j�|�
��|j�|�
��W|�
�n|�
�w|�|jtjdd��|�|jtjdd��|�|jtjd	d��|��dS)
Nrr)r�r
rtruT)�respect_handler_levelrvrxrz)r	r�Matcherrr;r�r�rTr�r�rgr�r[r�r>�matchesrwrsrqrFr2r )r?r��listenerrCrCrD�test_queue_listener	s6�z$QueueHandlerTest.test_queue_listenerc
Cs�tj�|j|j�}|��zddWnty1}z|}|jj|�	�|d�WYd}~nd}~ww|jj
|�	�dd�|��|�|j
�����d�d�|�|j
�����d�d�dS)Nrdr�r�T��
stack_info�	Traceback�Stack)rr;r�r�r5rT�ZeroDivisionErrorr�rKrgr�r�rTr1rRr�r�)r?r�r��excrCrCrD�&test_queue_listener_with_StreamHandler,s �� z7QueueHandlerTest.test_queue_listener_with_StreamHandlercCsd|j�|j�|j�|j�tj�|j	|j�}|�
�|j�d�|��|�
|j����d�dS)Nr�zque -> ERROR: error)r�r9r8r�r=r5rr;r�r�rTr�r�rTr1rRr�)r?r�rCrCrD�*test_queue_listener_with_multiple_handlers<sz;QueueHandlerTest.test_queue_listener_with_multiple_handlersN)rirjrkrQrErNr�r�r}�
skipUnlessrrr;r�rrrCrCrCrDr��
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�two�three�four�fiveN)
rrr2r3r;r�r=r�rTr�r�rGrF)�	log_queuer�r�r�r�rCrCrD�
setup_and_logUs






zQueueListenerTest.setup_and_logrcCsJt|j�D]}t��}|�|d|��|f�q|�|jd|jd�dS�N�%s_%srEz&correct number of handled log messages)r@�repeatr�r�rr�rT�
call_count�r?�mock_handlerrrCrCrD�#test_handle_called_with_queue_queuems�z5QueueListenerTest.test_handle_called_with_queue_queuecCsbt��t|j�D]}t��}|�|d|��|f�|��|�	�q	|�
|jd|jd�dSr)r�*skip_if_broken_multiprocessing_synchronizer@r�multiprocessingr�rr�rFr�rTrrrCrCrD� test_handle_called_with_mp_queueus
�z2QueueListenerTest.test_handle_called_with_mp_queueccs*�z	|��VqtjygYSwr�)r�r�r�)rrCrCrD�get_all_from_queue�s�
��z$QueueListenerTest.get_all_from_queuecCs�t��t|j�D]7}t��}|�|d|��|f�t|�	|��}|�
�|��gtj
jjgg}|�||ddd�|D��q	dS)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.
            rz&Found unexpected messages in queue: %scSs"g|]
}t|tj�r
|jn|�qSrC)r�rr�r)rr�rCrCrDr�s
��zJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>N)rrr@rrr�rr��listrrFr�rr;r��	_sentinelr�)r?rr�r�r`rCrCrD�$test_no_messages_in_queue_after_stop�s 	����z6QueueListenerTest.test_no_messages_in_queue_after_stopcCs\t��}tj�|�}|��|��|�t��
|�	�Wd�dS1s'wYdSr�)
r�r�rr;r�rTr�rr(�	task_done)r?rr�rCrCrD�test_calls_task_done_after_stop�s
"�z1QueueListenerTest.test_calls_task_done_after_stopN)rirjrkrlr�staticmethodrrr�rr;r�rrrrrrCrCrCrDrMs



rc@s eZdZdd�ZeZdd�ZdS)�UTCcCstSr�)�ZERO�r?�dtrCrCrD�	utcoffset�r'z
UTC.utcoffsetcCsdS)Nr!rCr#rCrCrD�tzname�r'z
UTC.tznameN)rirjrkr%�dstr&rCrCrCrDr!�sr!c@r�)�AssertErrorMessagec
OsVz|jdg|�Ri|��WdS|y*}z|�|t|��WYd}~dSd}~ww)NrC)rrTr)r?rKr
r<r'r�rCrCrD�assert_error_message�s��z'AssertErrorMessage.assert_error_messageN)rirjrkr)rCrCrCrDr(�r�r(c@sfeZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dS)�
FormatterTestc	Cs8dtjtj�ddd�dddddd�|_d	d	d
ii|_dS)Nzformatter.testr!�toz	dummy.extrzMessage with %d %s)r��placeholders)rAr��pathname�linenor��funcrr<�customi�)rr3rr!r��common�variantsrfrCrCrDrE�s��
�zFormatterTest.setUpNcCs,t|j�}|dur|�|j|�t�|�Sr�)r�r1rIr2rr�)r?rA�resultrCrCrD�
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)s�%(asctime)sz%(asctime)-15sz%(asctime)#15s�
r4rr6rTr�rr(r �usesTimer>�r?r�r�rCrCrD�test_percent�s




zFormatterTest.test_percentcCs�|��}tjddd�}|�|�|�d�tjddd�}|�t|j|�tjddd�}|�|���tjddd�}|�	|���tjddd�}|�	|���tjd	dd�}|�	|���dS)
Nz
$%{message}%$�{�rD�$%Message with 2 placeholders%$z{random}z	{message}�	{asctime}z{asctime!s:15}z{asctime:15}r6r8rCrCrD�test_braces�szFormatterTest.test_bracescCs|��}tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�t|j|�|�|���tjd	dd�}|�	|���tjd
dd�}|�	|���tjddd�}|�|���tjddd�}|�	|���dS)N�
${message}rCr;zMessage with 2 placeholdersz$messagez$$%${message}%$$r<z	${random}z
${asctime}z$asctimez${asctime}--r6r8rCrCrD�test_dollars�s$zFormatterTest.test_dollarscCst�d�}|�|jd�t�d�}|�|jd�t�d�}|�|jd�t�d�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjd	dd�}|�|jd	�tjd
dd�}|�|jd
�tjddd�}|�|jd�tjddd�}|�|jd�tjd
dd�}|�|jd
�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�tjddd�}|�|jd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd�|�ttjd �|�ttjd!�|jtd"tjd#dd�|jtd$tjd%dd�|�td&�|jttjd'dd�|jtd(tjd)dd�|jtd*tjd+dd�|jttjd,dd�|jttjd-dd�|jttjd.dd�|jttjd/dd�|jtd0tjd1dd�|jtd2tjd3dd�|jttjd4dd�|jttjd5dd�|jttjd6dd�|jttjd7dd�|jttjd8dd�|jttjd9dd�|jttjd:dd�|jttjd;dd�|jttjd<dd�|jtd=tjd>dd�|jtd=tjd?dd�|jtd=tjd@dd�|jtd$tjddd�|jttjd%dd�|jtd$tjdAdd�|jttjdBdd�dS)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} - $messagerCz$bar $$z	$bar $$$$z%(asctime)Zz%(asctime)bz%(asctime)*z
%(asctime)*3sz%(asctime)_r=r?z
%(foo)#12.3*fz%(foo)0*.8*fz;invalid format: invalid field name/expression: 'name-thing'z{name-thing}zinvalid format: no fieldsr5zinvalid 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 stringzprocess}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 $$$zbar $zfoo $.r�z	${asctime)rr6rT�_fmtrr(r)�r?r�rCrCrD�test_format_validates�



������������z"FormatterTest.test_format_validatecCs�gd�}gd�}t||�D]T\}}tj||ddid�}|��}|�|�|�d�|�d�}|�|�|�d�tj||d�}|��}|�t|j|�tj||d	did�}|�d�}|�|�|�d�q
dS)
N)z%(custom)s %(message)sz{custom} {message}z$custom $message)�%r:rCr0�Default)rDrz#Default Message with 2 placeholdersz 1234 Message with 2 placeholdersr;zNon-existing)rVrr6r4rTr�rr()r?�fmts�stylesr&rDr�r�rCrCrD�test_defaults_parameter�s

�z%FormatterTest.test_defaults_parametercCs|�ttjddd�dS)N�x)rr(rr6rfrCrCrD�test_invalid_style�sz FormatterTest.test_invalid_stylec
Cs�|��}t�dddddddt�}t�|�d����|_d|_t	�
d�}tj|_|�
|�|�d	�|�
|�|d
�d�|�|�|�
|jd	�dS)N��r?��r�r�{�%(asctime)s %(message)sz1993-04-21 08:03:00,123z%Y:%dz1993:21)r4�datetime�utcrA�mktime�
astimezone�	timetuple�created�msecsrr6�gmtime�	converterrT�
formatTimer��asctime)r?r�r$r�rCrCrD�	test_time�s

zFormatterTest.test_timec
CslGdd�dtj�}|��}t�ddddddd	t�}t�|�d����|_	|�}tj
|_|�|�
|�d
�dS)Nc@seZdZdZdZdS)zDFormatterTest.test_default_msec_format_none.<locals>.NoMsecFormatterNz%d/%m/%Y %H:%M:%S)rirjrk�default_msec_format�default_time_formatrCrCrCrD�NoMsecFormatter�sr^rKr?rLrMr�rrNz21/04/1993 08:03:00)rr6r4rPrQrArRrSrTrUrWrXrTrY)r?r^r�r$r�rCrCrD�test_default_msec_format_none�sz+FormatterTest.test_default_msec_format_nonecCsXtjdddd�}td�D]}t�d�t�dd|d	i�}|�|�}|�d
|�qdS)Nz!{asctime}.{msecs:03.0f} {message}r:z%Y-%m-%d %H:%M:%S)r&rDr{i�	g-C��6:?rz
Message %drdz.1000)rr6r@rArCr�r��assertNotIn)r?r�rr�rbrCrCrD�test_issue_89047�s

�zFormatterTest.test_issue_89047r�)rirjrkrEr4r9r>r@rCrHrJr[r_rarCrCrCrDr*�s
r*c@r�)�TestBufferingFormattercC�dt|�S)Nz[(%d)�rU�r?�recordsrCrCrD�formatHeader�r#z#TestBufferingFormatter.formatHeadercCrc)Nz(%d)]rdrerCrCrD�formatFooter�r#z#TestBufferingFormatter.formatFooterN)rirjrkrgrhrCrCrCrDrb�r�rbc@r�)�BufferingFormatterTestcCs"t�ddi�t�ddi�g|_dS)Nrr	r
)rr�rfrfrCrCrDrE�s
�zBufferingFormatterTest.setUpcCs2t��}|�d|�g��|�d|�|j��dS)Nr�onetwo)r�BufferingFormatterrTr�rfrBrCrCrD�test_default�sz#BufferingFormatterTest.test_defaultcCsDt�}|�d|�|j��t�d�}t|�}|�d|�|j��dS)Nz[(2)onetwo(2)]z
<%(message)s>z[(2)<one><two>(2)])rbrTr�rfrr6)r?r��lfrCrCrD�test_custom�s

z"BufferingFormatterTest.test_customN)rirjrkrErlrnrCrCrCrDri�sric@r�)�
ExceptionTestcCs�|j}t�}|�|�ztd��tjddd�Y|�|�|��|jd}|�	|j
�d��|�	|j
�d��|�	|j
�d��|�	|j
�d	��dS)
Nr��failedTr�rz#Traceback (most recent call last):
z!
RuntimeError: deliberate mistake�Stack (most recent call last):
z,logging.exception('failed', stack_info=True))r,�RecordingHandlerr=r�rrKrGrFrfr>�exc_textr�r�r�)r?r�rMrCrCrDr��s


zExceptionTest.test_formattingN)rirjrkr�rCrCrCrDro�r�roc@r�)�LastResortTestc	Cs�|j}|�|j�tj}tj}z�t���"}|�d�|�	|�
�d�|�d�|�	|�
�d�Wd�n1s9wYdt_t���}|�d�d}|�	|�
�|�Wd�n1s_wYt���}|�d�|�	|�
�d�Wd�n1s�wYd|j_
dt_t���}|�d�|�	|�
�d�Wd�n1s�wYW|�|j�|t_|t_dSW|�|j�|t_|t_dS|�|j�|t_|t_w)NzThis should not appearrz
Final chance!zFinal chance!
z-No handlers could be found for logger "root"
F)r,rGr5r�
lastResortr�rr�r�rTrRr�r�emittedNoHandlerWarningr=)r?rm�old_lastresort�old_raise_exceptionsr�rrCrCrD�test_last_resortsJ


�

�

�

�
�
�zLastResortTest.test_last_resortN)rirjrkryrCrCrCrDrtr�rtc@r�)�FakeHandlerc	Cs$dD]
}t|||�|||��qdS)N)rf�flushrFrg)�setattr�record_call)r?�
identifier�calledr0rCrCrDra7s�zFakeHandler.__init__cs���fdd�}|S)Ncs��d�����dS)Nz{} - {})r�r�rC�rr~�method_namerCrD�inner<rXz&FakeHandler.record_call.<locals>.innerrC)r?r~r�rr�rCr�rDr};szFakeHandler.record_callN)rirjrkrar}rCrCrCrDrz5srzcr\)rrcs tt|�j|i|��g|_dSr�)r`rrrarf)r?r<r'rdrCrDraCs
zRecordingHandler.__init__cCs|j�|�dS)z&Keep track of all the emitted records.N)rfr�r�rCrCrDrGszRecordingHandler.handle)rirjrkrarrirCrCrdrDrrAsrrcs�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�)r`r�rErrr�r�r|)r?�raise_exceptionsrdrCrDrEPszShutdownTest.setUpcs�fdd�}|S)Ncs���r�rCrC�r�rCrDr�Xsz'ShutdownTest.raise_error.<locals>.innerrC)r?r�r�rCr�rD�raise_errorWszShutdownTest.raise_errorcCsbtd|j�}td|j�}td|j�}ttjj|||g�}tjt|�d�gd�}|�||j�dS)Nrrdr���handlerList)z2 - acquirez	2 - flushz	2 - closez2 - releasez1 - acquirez	1 - flushz	1 - closez1 - releasez0 - acquirez	0 - flushz	0 - close�0 - release)	rzrr�rr�r�r�rrT)r?�handler0�handler1�handler2r;r`rCrCrD�test_no_failure\szShutdownTest.test_no_failurecCsRtd|j�}t|||�|��tj�|�g}tjt|�d�|�	d|jd�dS)Nrr�r�r)
rzrr|r�rr�r�r�rrT)r?r0r�r�r;rCrCrD�_test_with_failure_in_methodls
z)ShutdownTest._test_with_failure_in_methodcC�|�dt�dS�Nrf�r�r'rfrCrCrD�test_with_ioerror_in_acquireur�z)ShutdownTest.test_with_ioerror_in_acquirecCr��Nr{r�rfrCrCrD�test_with_ioerror_in_flushxr�z'ShutdownTest.test_with_ioerror_in_flushcCr��NrFr�rfrCrCrD�test_with_ioerror_in_close{r�z'ShutdownTest.test_with_ioerror_in_closecCr�r��r�r(rfrCrCrD�test_with_valueerror_in_acquire~r�z,ShutdownTest.test_with_valueerror_in_acquirecCr�r�r�rfrCrCrD�test_with_valueerror_in_flush�r�z*ShutdownTest.test_with_valueerror_in_flushcCr�r�r�rfrCrCrD�test_with_valueerror_in_close�r�z*ShutdownTest.test_with_valueerror_in_closecC�dt_|�dt�dS)NFrf�rr�r��
IndexErrorrfrCrCrD�.test_with_other_error_in_acquire_without_raise��z;ShutdownTest.test_with_other_error_in_acquire_without_raisecCr�)NFr{r�rfrCrCrD�,test_with_other_error_in_flush_without_raise�r�z9ShutdownTest.test_with_other_error_in_flush_without_raisecCr�)NFrFr�rfrCrCrD�,test_with_other_error_in_close_without_raise�r�z9ShutdownTest.test_with_other_error_in_close_without_raisecC�dt_|�t|jdt�dS)NTrf�rr�rr�r�rfrCrCrD�+test_with_other_error_in_acquire_with_raise��
�z8ShutdownTest.test_with_other_error_in_acquire_with_raisecCr�)NTr{r�rfrCrCrD�)test_with_other_error_in_flush_with_raise�r�z6ShutdownTest.test_with_other_error_in_flush_with_raisecCr�)NTrFr�rfrCrCrD�)test_with_other_error_in_close_with_raise�r�z6ShutdownTest.test_with_other_error_in_close_with_raise)rirjrkrlrEr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rirCrCrdrDr�Ls$	r�c@szeZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�ZdS)�ModuleLevelMiscTestz)Test suite for some module level methods.cCs�tjjj}|�|d�|�tj|�t�d�|�tjjjd�|�ttjd�Gdd�d�}|�ttj|��t�d�t��|�tjjjtj	�dS)Nr�S�
doesnotexistsc@r))z;ModuleLevelMiscTest.test_disable.<locals>._NotAnIntOrStringNr+rCrCrCrD�_NotAnIntOrString�r,r��WARN)
rrmrrJrTr�rr(r�rq)r?�old_disabler�rCrCrD�test_disable�s


z ModuleLevelMiscTest.test_disableNcs�g�t�|td�fdd��t�}tj�|�tt|�}|dur'||d|�n|d|�|�t|j	�d�|j	d}|�|�
�d|�|durJ|ntt|���}|�|j|�|��g�dS)N�basicConfigcs��||f�Sr�r�)r3�kw�rrCrD�<lambda>��z/ModuleLevelMiscTest._test_log.<locals>.<lambda>ztest me: %rrdr)
rrrrrrmr=r(rTrUrf�
getMessage�upperr�)r?r0r��	recording�
log_methodr��expected_levelrCr�rD�	_test_log�s 

�


zModuleLevelMiscTest._test_logcC�|�dtj�dS�Nr�)r�rrsrfrCrCrD�test_log�rTzModuleLevelMiscTest.test_logcC�|�d�dS�Nr��r�rfrCrCrD�
test_debug�r�zModuleLevelMiscTest.test_debugcCr��Nr�r�rfrCrCrD�	test_info�r�zModuleLevelMiscTest.test_infocCr��Nr�r�rfrCrCrD�test_warning�r�z ModuleLevelMiscTest.test_warningcCr��Nr�r�rfrCrCrD�
test_error�r�zModuleLevelMiscTest.test_errorcCr��Nr[r�rfrCrCrD�
test_critical�r�z!ModuleLevelMiscTest.test_criticalcCs^|�ttjt�Gdd�dtj�}t�|�|�t��|�t�tj�|�t��tj�dS)Nc@r))z;ModuleLevelMiscTest.test_set_logger_class.<locals>.MyLoggerNr+rCrCrCrDr��r,r�)rr�rr�r�r�rT�getLoggerClass)r?r�rCrCrD�test_set_logger_class�s
z)ModuleLevelMiscTest.test_set_logger_classc	sg�G�fdd�dt���}t�|�t�d�}|��dg�t��}t�|�}|�|�zD|�	tj
�|�d�|�|���
�d�|�d�|�d�|�	tj�|�d�|�|��d�W|�|�|��t�tj�dS|�|�|��t�tj�w)Ncs&eZdZdejf��fdd�	Z�ZS)z@ModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLoggerr�cst��||���d�dS)N�initialized)r`rar�)r?rAr�)rer
rCrDra�szIModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLogger.__init__)rirjrkrr�rarirC�r
rdrDr��sr��just_some_loggerr��hellorr)rr�r�rrTr/r0r4r=r2r3r�rRr��truncaterMryrGrFr�)r?r�r�r1rMrCr�rD�test_subclass_logger_cache�s.









�z.ModuleLevelMiscTest.test_subclass_logger_cachecCs>t�d�}td|�\}}}|��}|�d|�|�d|�dS)Na*
            import logging

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

            a = A()
        �-czexception in __del__zValueError: some error)r"r#rr�r��r?�code�rc�out�errrCrCrD�test_logging_at_shutdowns

z,ModuleLevelMiscTest.test_logging_at_shutdowncCsvtj}|�tj|�t�d|�d��}td|�t|dd��}|�|�	��
�d�Wd�dS1s4wYdS)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�rr^zERROR:root:log in __del__)r�TESTFNr�rr"r#rrbrTr[r)r?rpr��fprCrCrD�test_logging_at_shutdown_open&s
�
"�z1ModuleLevelMiscTest.test_logging_at_shutdown_opencCs>t�d�}td|�\}}}|��}|�d|�|�|d�dS)Nz�
            import logging

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

            rec()
        r�z#Cannot recover from stack overflow.rd)r"r#rr�r`rTr�rCrCrD�test_recursion_errorEs

	z(ModuleLevelMiscTest.test_recursion_errorr�)rirjrkrlr�r�r�r�r�r�r�r�r�r�r�r�r�rCrCrCrDr��s
r�c@s:eZdZdd�Zdd�Zeddd��Zdd	�Zd
d�ZdS)
�
LogRecordTestcCs6t�i�}t|�}|�|�d��|�|�d��dS)Nz<LogRecord: �>)rr�rr>r�r�)r?r�rbrCrCrD�test_str_repWs
zLogRecordTest.test_str_repcCsjt�}t��}|�|�ddi}t�d|�|�|jdj|�|�|jdj	d�|�
|�|��dS)N�less�morezless is %(less)srzless is more)rrrrr=r�r�rfr<rTr
rGrF)r?rMr�r�rCrCrD�
test_dict_arg]s

zLogRecordTest.test_dict_argNc	Cs�tj}|t_zBddl}|��j}t�dd|��i�}t�tj	dd��t�dd|��i�}Wd�n1s7wY||j
|j
d�}W|t_n|t_w|rV|�|�dS|S)Nrr�msg1_r�msg2_)�processName�r1.processName�r2.processName)r�logMultiprocessingr�current_processrAr�r�	swap_itemr�modulesr�rw)	r�r�r��prev_logMultiprocessing�mprA�r1�r2�resultsrCrCrD�_extract_logrecord_process_namehs"
��z-LogRecordTest._extract_logrecord_process_namec	Csdtjv}zy|�tjd�d}t�i�}|�|jd�|�d|�}|�d|d�|�d|d�|�d|d�ddl}|�	�\}}|j
|jd	||fd
�}|��|��}|�
d|d�|�|d|d�|�d|d�|��W|r}ddl}dSdS|r�ddl}w)NrT�MainProcessrdr�r�r�rr�rL)rr�rTrr�r�r�r�r�Pipe�ProcessrTr��assertNotEqualr�)	r?�multiprocessing_imported�LOG_MULTI_PROCESSINGr�r�r�parent_conn�
child_connr�rCrCrD�test_multiprocessing�s4

�
�
z"LogRecordTest.test_multiprocessingcCs�t�i�}|j}||j�||j�||j�||j�tj}tj}tj	}z1dt_dt_dt_	t�i�}|j
}||j�||j�||j�||j�W|t_|t_|t_	dS|t_|t_|t_	w)NF)rr��assertIsNotNoner�
threadName�processr��
logThreads�logProcessesr�r�)r?r��NOT_NONE�log_threads�
log_processes�log_multiprocessing�NONErCrCrD�
test_optional�s2









�zLogRecordTest.test_optionalr�)	rirjrkr�r�r r�r�rrCrCrCrDr�Vs$r�cs�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!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd9d+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Z�ZS):�BasicConfigTestz#Test suite for logging.basicConfig.csVtt|���tjj|_tj��|_tj	dd�|_
tjj|_|�
|j�gtj_dSr�)r`rrErrmr;rrrr r!r�r.r�rfrfrdrCrDrE�s

zBasicConfigTest.setUpcs<tjjdd�D]}tj�|�|��qtt|���dSr�)rrmr;rGrFr`rrNrrdrCrDrN�s
zBasicConfigTest.tearDowncCsJttjd|j�tj��tj�|j�|jtj	dd�<tj�
|j�dS)Nr;)r|rrmr;rrHrIrr!r r2r.rfrCrCrDrf�s

zBasicConfigTest.cleanupcCs�t��|�ttjj�d�tjjd}|�|tj�|�|jt	j
�|j}|�|jj
tj�|�|j�|�|jtj�|�tjj|j�dS)Nrdr)rr�rTrUrmr;rr4r1rr�r0r�rA�BASIC_FORMATr�r{�PercentStyler�r.)r?r�r0rCrCrD�test_no_kwargs�szBasicConfigTest.test_no_kwargscC�ht���&}tjtjdd�t�d�tj�d�|�|�	��
�d�Wd�dS1s-wYdS)Nr:�r1rD�Log an errorr�ERROR:root:Log an error�rr.rr�rrLr�rMrTrRr�rSrCrCrD�test_strformatstyle��

�"�z#BasicConfigTest.test_strformatstylecCr	)NrCr
rrrr
rSrCrCrD�test_stringtemplatestyle�rz(BasicConfigTest.test_stringtemplatestylecCs�dd�}tjddd�|�ttjj�d�tjjd}|�|tj�tjdddd	�}|�|jj	|jj	�|�|jj
|jj
�|�|||d�dS)
NcS�|��|��t�|�dSr�rb�re�h2r.rCrCrDrf��z.BasicConfigTest.test_filename.<locals>.cleanup�test.logr)rpr
rdrr3r^)rr�rTrUrmr;rr6r1�moderAr��r?rfr�r`rCrCrD�
test_filename�szBasicConfigTest.test_filenamecCsVdd�}tjddd�tjjd}t�dd�}|�|jj|jj�|�|||d�dS)NcSrr�rbrrCrCrDrfrz.BasicConfigTest.test_filemode.<locals>.cleanupr�wb�rp�filemoder)	rr�rmr;r6rTr1rr�rrCrCrD�
test_filemodeszBasicConfigTest.test_filemodecCs`t��}|�|j�tj|d�|�ttjj	�d�tjj	d}|�
|tj�|�|j|�dS)Nr_rdr)
r/r0r�rFrr�rTrUrmr;rr4r1)r?r1r�rCrCrD�test_streamszBasicConfigTest.test_streamcCs.tjdd�tjjdj}|�|jjd�dS)Nz%(asctime)s - %(message)s)r�r)rr�rmr;r0rTr�rA�r?r0rCrCrD�test_format&�zBasicConfigTest.test_formatcCs,tjdd�tjjdj}|�|jd�dS)Nr�)r{r)rr�rmr;r0rTr{rrCrCrD�test_datefmt,szBasicConfigTest.test_datefmtcCs.tjdd�tjjdj}|�|jtj�dS)NrCr;r)rr�rmr;r0rr�r�rrCrCrD�
test_style2r zBasicConfigTest.test_stylecCsTtjj}|�tjj|�tjdd�|�tjjd�tjdd�|�tjjd�dS)N�9)r��:)rrmr�r�r2r�rT)r?�	old_levelrCrCrD�
test_level8szBasicConfigTest.test_levelcCsp|j}t��g}tj}|ttjd|d�|ttjd|d�|ttj||d�|ttjtjd�tjddd�dS)Nr)rpr1)rpr;)r1r;)�loglevelr3r)rrr4rr�r(r�ry)r?rr;r1rCrCrD�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�)r;rrd)rr4rrLr6r9r�r�rmr;r�r0)r?r;r�rCrCrD�
test_handlersQs
�zBasicConfigTest.test_handlerscCs�t��}t��}t�|�g}t�|�g}tjtj|d�t�d�t�d�t�d�|�	t
tjj�d�tjtj
|dd�t�d�t�d�t�d�|�	t
tjj�d�|�	|����d�|�	|����d	�dS)
Nr1rr�r�rdT)r�r;�forcezWARNING:root:warnz WARNING:root:warn
INFO:root:info)r/r0rr4r�rwr�r�r�rTrUrmr;ryrRr�)r?�
old_string_io�
new_string_io�old_handlers�new_handlersrCrCrD�
test_forcebs,



�


��zBasicConfigTest.test_forcecCsz^d}tjd|ddtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�t�
d�W|��tddd	��}|�
���}Wd�n1sMwYt�d�|�|d�dS|��tddd	��}|�
���}Wd�n1szwYt�d�|�|d�w)
Nrrr�%(message)s�rpr
�errorsr�r�rdr�.The Øresund Bridge joins Copenhagen to Malmör^�rr�r3rTrUrmr;rr6r
r�rFrbr[r�rrc�r?r
r�r�r�rCrCrD�
test_encodingws6��
���
�zBasicConfigTest.test_encodingcCsz^d}tjd|ddtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�t�
d�W|��tdd	d
��}|�
���}Wd�n1sMwYt�d�|�|d�dS|��tdd	d
��}|�
���}Wd�n1szwYt�d�|�|d�w)Nrzrrr0r1rdrr3rr^z*The resund Bridge joins Copenhagen to Malmr4r5rCrCrD�test_encoding_errors�s.��
��
z$BasicConfigTest.test_encoding_errorscCs"zdd}tjd|dtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�|�|j
d�t�d�W|��t
dd	d
��}|����}Wd�n1sSwYt�d�|�|d�dS|��t
dd	d
��}|����}Wd�n1s�wYt�d�|�|d�w)Nrzrr0)rpr
r�r�rdr�backslashreplaceu<😂: ☃️: The Øresund Bridge joins Copenhagen to Malmörr^zL\U0001f602: \u2603\ufe0f: The \xd8resund Bridge joins Copenhagen to Malm\xf6)rr�r3rTrUrmr;rr6r
r2r�rFrbr[r�rrcr5rCrCrD�test_encoding_errors_default�s.��
��
z,BasicConfigTest.test_encoding_errors_defaultcsRz|d}tjd|ddtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�|�
|j�g��fdd�}||_t�
d	�|���|�d
�d�W|��tddd��}|����}Wd�n1skwYt�d�|�|d
�dS|��tddd��}|����}Wd�n1s�wYt�d�|�|d
�w)Nrzrr0r1rdrcs t��\}}}��t|��dSr�)rr�r�r)r�rHr�r�rCrD�dummy_handle_error�szEBasicConfigTest.test_encoding_errors_none.<locals>.dummy_handle_errorr3z:'ascii' codec can't encode character '\xd8' in position 4:rr^r)rr�r3rTrUrmr;rr6r
r�r2r�r�r>r�rFrbr[r�rrc)r?r
r�r:r�r�rCr�rD�test_encoding_errors_none�s>�

��
��
z)BasicConfigTest.test_encoding_errors_noneNcsfg�tj����fdd�}t��td|�tt|�}|dur$||d�n|d����difg�dS)Ncs<��tjj}tj�d���tjj|���||f�dS)N�d)rrmr�r2r�r�)r3r�r%�r�old_basic_configr?rCrD�my_basic_config�s
z2BasicConfigTest._test_log.<locals>.my_basic_configr�ztest merC)rr�rrr(rT)r?r0r�r?r�rCr=rDr��s
zBasicConfigTest._test_logcCr�r�)r�rrwrfrCrCrDr��rTzBasicConfigTest.test_logcCr�r�r�rfrCrCrDr��r�zBasicConfigTest.test_debugcCr�r�r�rfrCrCrDr��r�zBasicConfigTest.test_infocCr�r�r�rfrCrCrDr��r�zBasicConfigTest.test_warningcCr�r�r�rfrCrCrDr��r�zBasicConfigTest.test_errorcCr�r�r�rfrCrCrDr��r�zBasicConfigTest.test_criticalr�) rirjrkrlrErNrfrrrrrrrr!r"r&r(r)r/r6r7r9r;r�r�r�r�r�r�r�rirCrCrdrDr�s:	


"rcsLeZdZ�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�<dSr�)rr rC��old_handler_listrCrDrf	rTz(LoggerAdapterTest.setUp.<locals>.cleanup�r�r�)r`r@rErr rrr�rmr�r=r�rGrFr�r��adapter)r?rfrdrArDrE�s
zLoggerAdapterTest.setUpc
C�d}d}zddWnty&}z|}|j�||j�WYd}~nd}~ww|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dS�Nztesting exception: %rrdr)rrDrKr�rTrUrfr�rrsrr<r�re�
__traceback__�r?rrr�r�rCrCrD�test_exception�"���z LoggerAdapterTest.test_exceptionc
Cs�zddWnty}z|}WYd}~nd}~ww|jjd|d�|�t|jj�d�|jjd}|�|j|j||j	f�dS)Nrdrz
exc_info testr�)
rrDrKrTrUr�rfr�rerG)r?r�rr�rCrCrD�test_exception_excinfo!s���z(LoggerAdapterTest.test_exception_excinfocCshd}|j�||j�|�t|jj�d�|jjd}|�|jtj�|�|j	|�|�|j
|jf�dS)Nzcritical test! %rrdr)rDr[r�rTrUrfr�rrqrr<)r?rr�rCrCrDr�.szLoggerAdapterTest.test_criticalcCsD|jjjj}d|jjj_|�t|jjjd|�|�|j�d��dS)N�!rJ� )rDr�rrJr�r|r �isEnabledFor�r?r�rCrCrD�test_is_enabled_for8s�z%LoggerAdapterTest.test_is_enabled_forcCsN|�|j���|jjD]}|j�|�q|�|j���|�|j���dSr�)r>rDr:r�r;rGr r�rCrCrD�test_has_handlers?s
z#LoggerAdapterTest.test_has_handlerscCsRGdd�dtj�}d}||jdd�}||dd�}d|_|�t|�t|��|�tj||j�|�t	|jj
�d�|jj
d}|�|jtj�|�|jd|���|�|j
|jf�|j}|�|j|�|�|jj|�t�}z||_|�|j|�|�|j|�|�|jj|�W||_n||_w|�|j|�|�|j|�|�|jj|�dS)	Nc@r�)z.LoggerAdapterTest.test_nested.<locals>.Adapter�AdaptercSs|j�d|��|fSr��r�)r?rr'rCrCrDr�L�z6LoggerAdapterTest.test_nested.<locals>.Adapter.processN)rirjrkr�r�rCrCrCrDrRIsrRzAdapters can be nested, yo.rC�AdapterAdapterrdrzAdapter AdapterAdapter )rr�r�r�rTr�r�rqr�rUrfr�rr<rr�r�)r?rRrrD�adapter_adapterr��orig_manager�temp_managerrCrCrD�test_nestedHs2zLoggerAdapterTest.test_nested)rirjrkrErIrKr�rPrQrYrirCrCrdrDr@�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�Zdd �Zd!d"�Z�ZS)#�
LoggerTestcsbtt|���t�|_tjdd�|_|j�|j�|�	|jj
|j�|�	|jj�|�	tj�dS)N�blah�rA)
r`rZrErrr�rr�r�r=r�rGrFr�rfrdrCrDrElszLoggerTest.setUpcCs,|�td|jjd�|�td|jjd�dS)Nz,Level not an integer or a valid string: Nonez.Level not an integer or a valid string: (0, 0))rr)r)r�r�r2rfrCrCrD�test_set_invalid_levelus��z!LoggerTest.test_set_invalid_levelc
CrErF)rr�rKr�rTrUrfr�rrsrr<r�rerGrHrCrCrDrI}rJzLoggerTest.test_exceptioncCsHt�tdd��|�t|jjdd�Wd�dS1swYdS)Nr�Tr~�test message)r�	swap_attrrrr�r�r�rfrCrCrD�!test_log_invalid_level_with_raise�s"�z,LoggerTest.test_log_invalid_level_with_raisecCsBt�tdd��|j�dd�Wd�dS1swYdS)Nr�Fr~r^)rr_rr�r�rfrCrCrD�test_log_invalid_level_no_raise�s"�z*LoggerTest.test_log_invalid_level_no_raisecsPg�t�|tjd�fdd��|jjdd�|�t��d�|�d�d�dS)	N�print_stackcs��|���Sr�)r�rR)r�r(r�rCrDr��r�z=LoggerTest.test_find_caller_with_stack_info.<locals>.<lambda>Tr�rdrqr)rrr�	tracebackr��
findCallerrTrUrfrCr�rD� test_find_caller_with_stack_info�s
�z+LoggerTest.test_find_caller_with_stack_infocsd���fdd���fdd���fdd�}�jj}|���|djd	�|dj}�d7�|���|djd
���|dj|�|dj}�d7�|���|djd���|dj|�|dj}�d7�|���|djd���|dj|�dS)
Nrdcs�jjd�d�dS)Nr)�
stacklevel)r�r�rC)r?�	the_levelrCrD�	innermost�rTz>LoggerTest.test_find_caller_with_stacklevel.<locals>.innermostc�
��dSr�rCrC)rhrCrDr��r�z:LoggerTest.test_find_caller_with_stacklevel.<locals>.innercrir�rCrC)r�rCrD�outer�r�z:LoggerTest.test_find_caller_with_stacklevel.<locals>.outerrrhr�rj� test_find_caller_with_stacklevel)r�rfrTr�r.ru)r?rjrfr.rC)r�rhr?rgrDrk�s,


z+LoggerTest.test_find_caller_with_stacklevelc
Cs�d}d}d}}}}}}}	t�|||||||||	�	}
dt|
j���D]}|di}|jt|jj|||||||||	d�q(dS)N�	my record�
)r
rZ�
some value�r��sinfo)	r�_logRecordFactoryrY�__dict__�keysrr�r��
makeRecord)
r?rAr�r.�lnorr<r�r/rp�rvr�r�rCrCrD�%test_make_record_with_extra_overwrite�s�
��z0LoggerTest.test_make_record_with_extra_overwritecCs\d}d}d}}}}}}}	ddi}
|jj||||||||
|	d�	}|�d|j�dS)Nrlrm�	valid_keyrnro)r�rtr�rr)r?rAr�r.rurr<r�r/rpr�r3rCrCrD�(test_make_record_with_extra_no_overwrite�s�z3LoggerTest.test_make_record_with_extra_no_overwritecCs>|�|j���|jjD]}|j�|�q|�|j���dSr�)r>r�r:r;rGr r�rCrCrDrQ�szLoggerTest.test_has_handlerscCs"t�d�}d|_|�|���dS)Nz
blah.childF)rrrr r:)r?�child_loggerrCrCrD�test_has_handlers_no_propagate�s
z)LoggerTest.test_has_handlers_no_propagatecCs>|jjj}d|jj_|�t|jjd|�|�|j�d��dS)N�rJ�)r�rrJr�r|r rNrOrCrCrDrP�s

zLoggerTest.test_is_enabled_forcCs`|jj}|jjj}d|j_d|jj_|�t|jd|�|�t|jjd|�|�|j�d��dS)NTrLrrJr})r�rrrJr�r|r rN)r?�old_disabledr�rCrCrD�#test_is_enabled_for_disabled_logger�s

z.LoggerTest.test_is_enabled_for_disabled_loggercCs�t��}|�|tj�|�|t�d��|�|t�d��|�|t�d��|�|t�d�j�|�|t�d�j�|�|t�d�j�|�|t�d��|�|t�d�j�dS)Nrrmr��foo.bar�)rrr�rm�parent�assertIsNot)r?rmrCrCrD�test_root_logger_aliases�sz#LoggerTest.test_root_logger_aliasescCs$|�ttjt�|�ttjd�dS)Nsfoo)rr�rr�anyrfrCrCrD�test_invalid_namesszLoggerTest.test_invalid_namescCsNttjd�D]}dD]}t�|�}t�||�}t�|�}|�||�qqdS)Nrd)rrmr�r�zbaz.bar)r@r��HIGHEST_PROTOCOLrrr�r�r�)r?�protorAr�rb�	unpickledrCrCrD�
test_picklings

��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�r�TF)r,rrr2rsrTr-�_cacher>rNr r3rqr�rJ)r?rmr*r+rCrCrD�test_cachingsH

zLoggerTest.test_caching)rirjrkrEr]rIr`rarerkrwryrQr{rPrr�r�r�r�rirCrCrdrDrZjs$	

	
rZc@r�)�BaseFileTestz1Base class for handler tests that write log filescCs0t�|�t�dd�\}|_t�|�g|_dS)NrKztest_logging-2-)rrErrr.rrF�rmfiles)r?r-rCrCrDrEHs


zBaseFileTest.setUpcCs>|jD]}t�|�qtj�|j�rt�|j�t�|�dSr�)r�rrr!r"r.rrN)r?r.rCrCrDrNNs

zBaseFileTest.tearDowncCs*|jtj�|�d|d�|j�|�dS)z7Assert a log file is there and register it for deletionzLog file %r does not exist�rN)r>rr!r"r�r�)r?rprCrCrD�
assertLogFileUs�zBaseFileTest.assertLogFilec
Cst�dtjdd|��ddd�S)Nrr�rd)rr�r3rgrfrCrCrD�next_rec[s�zBaseFileTest.next_recN)rirjrkrlrErNr�r�rCrCrCrDr�Esr�c@r�)�FileHandlerTestcCszt�|j�tj|jddd�}|�|j�|�tj�	|j��|�
t�i��|�|j�|�
tj�	|j��|��dS)NrTr)rrr.rr6r�r1r r!r"rr�r�r>rF)r?�fhrCrCrD�
test_delay`szFileHandlerTest.test_delaycCs�t�|j�tj|jddd�}|�t�d��|�|���|�	�|�|���t
|j��}|�|���
�d�Wd�dS1sDwYdS)Nrr2)r
rr0rr)rrr.rr6r9r6rr�rFrbrTr[r�)r?r�r�rCrCrD�%test_emit_after_closing_in_write_modejs"�z5FileHandlerTest.test_emit_after_closing_in_write_modeN)rirjrkr�r�rCrCrCrDr�_s
r�c@sDeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Ze�	�dd��Z
d
S)�RotatingFileHandlerTestcCs`tjj|jddd�}|�|�d��|��tjjtjddd�}|�|�|�	���|��dS)Nrr�r
�maxBytesrd)
rr;r7r.r �shouldRolloverrFr�devnullr��r?�rhrCrCrD�test_should_not_rollovervs��z0RotatingFileHandlerTest.test_should_not_rollovercCs4tjj|jddd�}|�|�|����|��dS)Nrrdr�)rr;r7r.r>r�r�rFr�rCrCrD�test_should_rollover�sz,RotatingFileHandlerTest.test_should_rollovercCs8tjj|jdd�}|�|���|�|j�|��dS)Nrr^)rr;r7r.rr�r�rFr�rCrCrD�test_file_created�sz)RotatingFileHandlerTest.test_file_createdcCs�dd�}tjj|jdddd�}||_|�|���|�|j�|�|���|�||jd��|�|���|�||jd��|�t	j
�||jd	���|��dS)
NcS�|dS�N�.testrCr\rCrCrD�namer�r�z>RotatingFileHandlerTest.test_rollover_filenames.<locals>.namerrr�rd�r
�backupCountr��.1�.2�.3)
rr;r7r.r�rr�r�r rr!r"rF)r?r�r�rCrCrD�test_rollover_filenames�s
�z/RotatingFileHandlerTest.test_rollover_filenamescCs�Gdd�dtjj�}||jdddd�}|�|�|j�|jd�|�|���|�|j�|�|���|�|�|jd�d	�|�	t
j�|�|jd���|�
�dS)
Nc@r�)zZRotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotatorcSs|dSr�rC)r?rArCrCrDr��r�z`RotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotator.namercSs$tj�|�rt�||d�dSdS)N�.rotated)rr!r"rk)r?�source�destrCrCrD�rotator�s�zbRotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotator.rotatorN)rirjrkr�r�rCrCrCrD�HandlerWithNamerAndRotator�r�r�rr�rdr�r�r�r�)rr;r7r.rTr�rr�r�r rr!r"rF)r?r�r�rCrCrD�test_namer_rotator_inheritance�s
�z6RotatingFileHandlerTest.test_namer_rotator_inheritancecCs�dd�}dd�}tjj|jdddd�}||_||_|��}|�|�|�|j�|��}|�|�||jd	�}|�|�t	j
}t|d
��}|��}	t
�|	�}
|�|
�d�|j|�Wd�n1sewY|�|���||jd�}|�|�t|d
��}|��}	t
�|	�}
|�|
�d�|j|�Wd�n1s�wY|�|���||jd�}t|d
��}|��}	t
�|	�}
|�|
�d�|j|�Wd�n1s�wY|�t	j�||jd
���|��dS)NcSr�)Nz.gzrCr\rCrCrDr��r�z3RotatingFileHandlerTest.test_rotator.<locals>.namerc	Ss�t|d��,}|��}t�|d�}t|d��
}|�|�Wd�n1s%wYWd�n1s4wYt�|�dS)N�rbr
r)rbr[�zlib�compressr�rrc)r�r��sfr��
compressed�dfrCrCrDr��s���z5RotatingFileHandlerTest.test_rotator.<locals>.rotatorrr�rdr�r�r�rzr�r�)rr;r7r.r�r�r�rr�r�lineseprbr[r��
decompressrTr�rr r!r"rF)r?r�r�r��m1�m2r.�newliner�r�r�rCrCrD�test_rotator�sJ
�



�

�
�z$RotatingFileHandlerTest.test_rotatorN)rirjrkr�r�r�r�r�r�
requires_zlibr�rCrCrCrDr�usr�c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TimedRotatingFileHandlerTestcCsJtjjtjdddd�}t�d�t�ddi�}|�|�	|��|�
�dS)N�Srrd�r
r�皙�����?rztesting - device file)rr;r8rr�rArCr�r r�rF)r?r�r�rCrCrDr��s
�
z5TimedRotatingFileHandlerTest.test_should_not_rolloverc	s�tjj|jdddd�}t�d�}|�|�t�ddi�}|�|�|�|j�t	�
d�t�dd	i�}|�|�|��d
}tj�
�}d}t|�D]"}|tj|d�}	|j|	�d
��tj���}|rk|j���nqId|}
|s�tj�|j�\}��fdd�t�|�D�}td|�d�tjd�td|tjd�|D]*}
td|
�tj�||
�}t|d��}t|���Wd�n1s�wYq�|j||
d�dS)Nr�rrdr�rOrztesting - initialr�ztesting - after delayFi,��secondsz.%Y-%m-%d_%H-%M-%Sz,No rotated files found, went back %d secondscsg|]	}|���r|�qSrC)r�)rr��r.rCrDrsz>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�)rr;r8r.r6r9r�rr�rArCrFrPr�r@�	timedelta�strftimerr!r"r�r�r��listdirrVrr�r�rbr[r>)r?r�r&r�r��foundr��GO_BACK�secs�prevr�dn�filesr�r!�tfrCr�rD�
test_rollover�sJ
�





���z*TimedRotatingFileHandlerTest.test_rollovercCsX|j}|ttjj|jdddd�|ttjj|jdddd�|ttjj|jdddd�dS)N�XrTr�W�W7)rr(rr;r8r.)r?rrCrCrD�test_invalids

�

�


�z)TimedRotatingFileHandlerTest.test_invalidc	Cs�d}t�ddd�}tjj|jddddd|d�}z#|�|�}|�||d�|�|d	�}|�||d
�W|��dS|��w)Nr�r�MIDNIGHTrdT�r
�when�intervalr�rQ�atTime��жi@�)	rPrArr;r8r.�computeRolloverrTrF)r?�currentTimer�r�r_rCrCrD�"test_compute_rollover_daily_attimes�
z?TimedRotatingFileHandlerTest.test_compute_rollover_daily_attimec	
Cs8tt���}||d}t�ddd�}t�|�j}td�D]|}tjj|j	dd|ddd|d	�}ze||kr;d||}n||}|d9}|d
7}||7}|�
|�}||krbtdtj�tdt
��|�||�||krp|d
7}|�
|d�}||kr�tdtj�tdt
��|�||�W|��q|��wdS)N�Qr�r�rzW%drdTr�r�zfailed in timezone: %dzlocal vars: %si�:	r�)r�rArPrW�tm_wdayr@rr;r8r.r�rV�timezone�localsrTrF)	r?r��todayr��wday�dayr�r`r_rCrCrD�#test_compute_rollover_weekly_attime.s<�
�z@TimedRotatingFileHandlerTest.test_compute_rollover_weekly_attimec	Cs�tjdd�}|�tj|�g}tj��}td�D]}|�|�	d��|tj
dd�7}qd}g}g}|D]B}tj�
|d|�}	tjj|	d	dd
dd�}
|�|
�|�d
�rb|D]}|�d||f�qUq3dd�|
_|D]}|�d||f�qiq3|D]}tj�
||�}	t|	d��}
Wd�n1s�wYqxt|�D]\\}}||}
|
��}|�t|�d�|�d
�r�d|}	|D]}tj�|�\}}|�|�|	��q�q�|D]&}tj�|�\}}|�|�d��|�|�|d�o�|t|�d���q�q�dS)NrwrSrz%Y-%m-%d_%H-%M-%SrEr�)�a.bza.b.czd.ezd.e.fz%s.logrbr�T)r�r�r�rr�z	%s.log.%scSs|�dd�dS)NrKr)rkr\rCrCrDr�mszKTimedRotatingFileHandlerTest.test_compute_files_to_delete.<locals>.<lambda>z	%s.%s.logrr�z%s.log.rKr�r�)r�mkdtempr��shutil�rmtreerPr�r@r�r�r�rr!r�rr;r8r�r�rb�	enumerate�getFilesToDeleterTrUr�r>r��isdigit)r?�wd�timesr$r�prefixesr��rotatorsr�r�r�r�r.r��
candidatesr�r�rCrCrD�test_compute_files_to_deleteVsd

�

�
���
����z9TimedRotatingFileHandlerTest.test_compute_files_to_deleteN)	rirjrkr�r�r�r�r�r�rCrCrCrDr��s
*	(r�cKstjdi|��tjdd�S)Nrdr�rC)rPr�)r�rCrCrDr��sr�)r�rd)�M�<)�Hi)�Dr�)r�r��W0r?�)�days�hoursc

CsVtjj|jd|dddd�}d}|�|�}||kr�|dkr�zg|jr&t�|�}nt�|�}|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
�Wnt
y�}zt
d|tjd
�WYd}~nd}~ww|�||�|��dS)NrrdrT)r
r�r�r�rQgr�r�r?rEr�z
t: %s (%s)r�zcurrentHour: %szcurrentMinute: %szcurrentSecond: %szr: %sz
result: %sz exception in diagnostic code: %s)rr;r8r.r�rQrArW�	localtime�	_MIDNIGHTrVrr�rUrTrF)
r?r��expr�r�r_r��currentHour�
currentMinute�
currentSecondr�r3r�rCrCrD�test_compute_rollover�sD�

�����rztest_compute_rollover_%sz>win32evtlog/win32evtlogutil/pywintypes required for this test.c@r�)�NTEventLogHandlerTestc
Cs�d}t�d|�}t�|�}ztj�d�}Wntjy-}z|jdkr(t	�
d���d}~wwt�ddi�}|�|�|�
�|�|t�|��tjtjB}d}d}	t�|||	�}
|
D]}|jdkrbqZt�||�}|d	krmqZd
}d|	}|j||d�dS)
N�Application�test_loggingrEz#Insufficient privileges to run testrzTest Log MessageFr<zTest Log Message
Tz3Record not found in event log, went back %d recordsr�)�win32evtlog�OpenEventLog�GetNumberOfEventLogRecordsrr;�NTEventLogHandler�
pywintypesr��winerrorr}�SkipTestr�rrF�
assertLess�EVENTLOG_BACKWARDS_READ�EVENTLOG_SEQUENTIAL_READ�ReadEventLog�
SourceName�win32evtlogutil�SafeFormatMessager>)r?�logtype�elh�num_recsrMr�r��flagsr�r��eventsrrCrCrDr��s>


��
�
z NTEventLogHandlerTest.test_basicN)rirjrkr�rCrCrCrDr�r�rc@r�)�MiscTestCasecCshd�}tj|t|d�dS)N>
rmr��FiltererrQ�
RootLoggerr��PlaceHolderr�currentframer��StrFormatStyler�r�)�not_exported)r�check__all__r)r?r rCrCrD�test__all__�szMiscTestCase.test__all__N)rirjrkr"rCrCrCrDr�r�rcCs*t�dd�}|��t�|jddd�dS)N�LC_ALLr)r�run_with_locale�	__enter__r}�addModuleCleanup�__exit__)�cmrCrCrD�setUpModule�sr)�__main__r�)�rlr�logging.handlers�logging.configrr4rrPr4r�r/r�rrr�rDrOr�r�r�rr�test.support.script_helperrrrr�test.supportrrrr�test.support.logging_helperr	r"rQrAr}rr��http.serverr
r�urllib.parserr
�socketserverrrrrr�simplefilter�DeprecationWarningr�r�rrrr�r��TestCaserrmr��SILENTr��TERSE�EFFUSIVEr�r��	TALKATIVEr��
CHATTERBOX�BORINGr@r�r�r�r�r�r�r�r�r�r4r�r�r�r�r�r�r�r�r�rr�r�r�rr6rr r�r�rr�r�r�r�r��IPV6_ENABLEDr�r�r�rrr"r$r(r*r-r�r�r�r�r�r�r;r�
unittest.mockrrr�r"�tzinfor!rQr(r*rkrbrirortrzr rrr�r�r�rr@rZr�r�r�r�r�r�r�rr|rrr)ri�mainrCrCrCrD�<module>sz

���mF�
YT,J2)/ hdY@C�M41
(v#k
`	'W4hBl\k(�!
#
�

Youez - 2016 - github.com/yon3zu
LinuXploit