Sindbad~EG File Manager

Current Path : /usr/local/lib/python3.9/test/__pycache__/
Upload File :
Current File : //usr/local/lib/python3.9/test/__pycache__/test_logging.cpython-39.pyc

a

��g��@s0dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlZddlmZmZddlmZddlmZddlmZddlZddl Z ddl!Z!ddl"Z"ddl#Z#ddl$Z$ddl%Z%ddl&m'Z'm(Z(ddl)Z)ddl*m+Z+m,Z,dd	l-m.Z.m/Z/m0Z0m1Z1zddl2Z2ddl3Z3ddl4Z4Wn e5�y�dZ2Z3Z4Yn0zddl6Z6Wne5�y�Yn0Gd
d�de"j7�Z8Gdd
�d
e8�Z9Gdd�de8�Z:dZ;dZ<dZ=dZ>dZ?dZ@dZAdZBdZCdZDeEeDe;d�ZFe;de<de=de>de?de@d eAd!eBd"eCd#eDd$i
ZGGd%d&�d&ejH�ZIGd'd(�d(ejH�ZJGd)d*�d*e8�ZKGd+d,�d,e8�ZLGd-d.�d.eM�ZNGd/d0�d0ejO�ZPGd1d2�d2eM�ZQGd3d4�d4e8�ZRGd5d6�d6e)jS�ZTGd7d8�d8eM�ZUGd9d:�d:eUe'�ZVGd;d<�d<eUe0�ZWGd=d>�d>eUe.�ZXeYed?��rVGd@dA�dAeW�ZZGdBdC�dCeX�Z[GdDdE�dEe8�Z\GdFdG�dGe8�Z]GdHdI�dIej^�Z_GdJdK�dKe8�Z`GdLdM�dMe8�ZadNdO�Zbe"�ceYed?�dP�GdQdR�dRea��ZdGdSdT�dTe8�Zee"�ceYed?�dP�GdUdV�dVee��ZfGdWdX�dXe8�Zge"�ceYed?�dP�GdYdZ�dZeg��Zhe"�cejid[�Gd\d]�d]eg��ZjGd^d_�d_e8�ZkGd`da�dae8�ZlGdbdc�dce8�ZmGddde�dee8�Znd�dfdg�ZoGdhdi�di�Zpdjdk�ZqGdldm�dmejO�ZrGdndo�doe8�ZsGdpdq�dqe8�ZtGdrds�dse8�ZuGdtdu�duejv�ZwGdvdw�dwe8�ZxGdxdy�dye8�ZyeYejzdz��rZddl{Z{dd{l|m}Z}Gd|d}�d}e8�Z~e�d�Z�Gd~d�dej��Z�e��Z�Gd�d��d�e"j7�Z�Gd�d��d�ej��Z�Gd�d��d�e"j7�Z�Gd�d��d�e8�Z�Gd�d��d�e8�Z�Gd�d��d��Z�Gd�d��d�ej��Z�Gd�d��d�e8�Z�Gd�d��d�e8�Z�Gd�d��d�e8�Z�Gd�d��d�e"j7�Z�Gd�d��d�e"j7�Z�Gd�d��d�e8�Z�Gd�d��d�e8�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"�ce2d��Gd�d��d�e8��Z�Gd�d��d�e"j7�Z�d�d��Z�e�d�k�r,e"���dS)�zoTest harness for the logging module. Run all tests.

Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.
�N)�assert_python_ok�assert_python_failure)�support)�
socket_helper)�TestHandler)�
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��zvtj�	�|_
tjdd�|_|�	�|_
}tj�	�|_tj�	�|_i|_}|D]}t||dd�||<qpWt��n
t��0t�d�|_t�d�|_t�d�|_|j��|_t��|_|j�tj�t�|j�|_ t�!|j"�|_#|j �$|j#�|j�%��r:|jj&|jj&}t'd|��|j�%��rb|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.9/test/test_logging.py�setUpPsB

�
zBaseTest.setUpcCs8|j��|j�|j�|jjrB|jjd}|j�|�|��q|j�|j�t�	�z�tj
��tj
�|j
�tj��tj�|j�tj��tj�|j�|jtjdd�<t��j}d|_|j}|��|�|j�|j}|jD] }||dur�|||j|_q�Wt��n
t��0|��tj|j�dS)zJRemove our logging stream, and restore the original logging
        level.rN) r,�closer'�
removeHandlerr0r6r-r)rrr �clear�updater!rrrrrrrr�disablerrr"rr$Z
doCleanupsrZthreading_cleanupr)r:�hrrr"r;r<r<r=�tearDownzs8






zBaseTest.tearDownNc	Cs�|p|j}t�|p|j�}|����}|�t|�t|��t||�D]8\}}|�	|�}|sh|�
d|�|�t|���|�qD|�
�}|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)	r:Zexpected_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�r:r<r<r=�next_message�szBaseTest.next_message)NN)�__name__�
__module__�__qualname__�__doc__r2rHrZr>rErXr\r<r<r<r=rHs*"
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))rb�CRITICAL�1)rb�ERROR�2)rcre�3)rcrg�4)rc�WARNING�5)rc�INFO�6)rdre�7)rdrg�8)rdrk�9)rdrm�10)rdr.�11)r\rrr-rg�
LoggerAdapterrmr.�logre�error�warning�info�debugrX)r:�mrbrcrdr<r<r=�	test_flat�s.

zBuiltinLevelsTest.test_flatcCs�|j}t�d�}|�tj�t�d�}|�tj�|�tj|��|�|��|�	|��|�
|��|�|��|�ddg�dS)Nrc�INF.ERR)r|rerf)r|rgrh�
r\rrr-rmrgrurervrwrxryrX)r:rzrc�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|��|�|��|�|��|�	|��|�
|��|�|��|�gd��dS)Nrcr|�	INF.UNDEF�
INF.ERR.UNDEF�UNDEF))r�rerf)r�rgrh)r�rkri)r�rmrj)r�rerl)r�rgrnr})r:rzrcr~Z	INF_UNDEFZ
INF_ERR_UNDEFr�r<r<r=�test_nested_inherited�s&




z'BuiltinLevelsTest.test_nested_inheritedcCs�|j}t�d�}t�d�}t�d�}|�tj�|�tj|��|�|��|�tj|��|�|��|�|��|�|��|�	gd��dS)Nrc�INF.BADPARENT.UNDEF�
INF.BADPARENT))r�rerf)r�rmrh)r�reri)r�rmrj)
r\rrr-rmru�FATALrxryrX)r:rzrcZ
GRANDCHILDZCHILDr<r<r=�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.rmN)rKr�getLevelNamermr[r<r<r=�test_regression_22386;sz'BuiltinLevelsTest.test_regression_22386cCst�d�}|�|tj�dS)Nr�)rr�rKr�)r:�fatalr<r<r=�test_issue27935@s
z!BuiltinLevelsTest.test_issue27935cCs`t�tjd�|�tjtjd�|�t�tj�d�|�t�tj�d�|�t�d�tj�dS)z&See issue #29220 for more information.rrm�NOTSETN)r�addLevelNamerm�
addCleanuprKr�r�r[r<r<r=�test_regression_29220Ds
z'BuiltinLevelsTest.test_regression_29220N)r]r^r_r`r{rr�r�r�r�r�r<r<r<r=ra�s/#rac@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�W|�	|�n|�	|�0dS)N�	spam.eggsr�spam�spam.eggs.fish�spam.bakedbeans�r�rmrh�r�rmri)
r�Filterr'r6�	addFilterrrxr\rX�removeFilter)r:Zfilter_�handlerr��	spam_eggs�spam_eggs_fish�spam_bakedbeansr<r<r=�test_filterPs"





�zBasicFilterTest.test_filterc	Cs�dd�}|jjd}z�|�|�t�d�}t�d�}t�d�}t�d�}|�|���|�|���|�|���|�|���|�dd	g�W|�|�n|�|�0dS)
NcSs&|j�d�}d�|dd��}|dkS)N�.�r�)r;�split�join)�record�parts�prefixr<r<r=�
filterfunclsz8BasicFilterTest.test_callable_filter.<locals>.filterfuncrr�r�r�r�r�r�)	r'r6r�rrrxr\rXr�)r:r�r�r�r�r�r�r<r<r=�test_callable_filterhs"




�z$BasicFilterTest.test_callable_filtercCs*t��}t�ddi�}|�|�|��dS)Nr;r�)rr��
makeLogRecordr9�filter)r:�f�rr<r<r=�test_empty_filter�sz!BasicFilterTest.test_empty_filterN)r]r^r_r`r�r�r�r<r<r<r=r�Lsr��x�w�v�u�t�s�r�q�p�orY�Silent�Taciturn�Terse�Effusive�Sociable�Verbose�	TalkativeZ	Garrulous�
Chatterbox�Boringc@seZdZdZdd�ZdS)�GarrulousFilterz)A filter which blocks garrulous messages.cCs
|jtkS�N)�levelno�	GARRULOUS�r:r�r<r<r=r��szGarrulousFilter.filterN�r]r^r_r`r�r<r<r<r=r��sr�c@seZdZdZdd�ZdS)�VerySpecificFilterz5A filter which blocks sociable and taciturn messages.cCs|jttfvSr�)r��SOCIABLE�TACITURNr�r<r<r=r��szVerySpecificFilter.filterNr�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.�^[\w.]+ -> (\w+): (\d+)$cCs,t�|�t��D]\}}t�||�qdSr�)rr>�my_logging_levels�itemsrr�)r:�k�vr<r<r=r>�s
z CustomLevelsAndFiltersTest.setUpcCstD]}|�||���qdSr�)�LEVEL_RANGErur\)r:�loggerZlvlr<r<r=�log_at_all_levels�sz,CustomLevelsAndFiltersTest.log_at_all_levelscCs*|j�t�|�|j�|�gd��dS)N)�r�rl�r�rn�r�ro�r�rp�r�rq�r�rr)r'r-�VERBOSEr�rXr[r<r<r=�test_logger_filter�sz-CustomLevelsAndFiltersTest.test_logger_filterc	Cs`|jjd�t�z2|�|j�|�gd��W|jjd�tj�n|jjd�tj�0dS)Nr)r�r�r�r�r�)r'r6r-r�r�rXrr�r[r<r<r=�test_handler_filter�s
z.CustomLevelsAndFiltersTest.test_handler_filterc	Cs�|jjd}d}t�}|�|�zl|�|j�gd�}|�|�t�}|j�|�|�|j�|�|gd��W|r�|j�|�|�|�n|r�|j�|�|�|�0dS)Nr)	)r�rf)r�rh)r�rjr�r�r�r�r�r�))r�rs)r�Z12)r�Z14)r�Z15)r�Z17)r�Z18)r�Z20)r'r6r�r�r�rXr�r�)r:r�Zspecific_filterZgarrZfirst_linesr<r<r=�test_specific_filters�s$

�z0CustomLevelsAndFiltersTest.test_specific_filtersN)
r]r^r_r`rHr>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�Handlerr;rK�assertRaises�NotImplementedError�emit�r:rDr<r<r=�	test_nameszHandlerTest.test_namec
Cs�tjdv�rXdD]�}t��\}}t�|�|s8t�|�tjj	|dd�}|r�|j
|j}}|�|d�|�|d�t�
ddi�}|�|�t�|�|�tj�|��|�|�|�tj�|��n|�|j
d�|�|jd�|��|rt�|�qtjdk�r
d	}nd
}z4tj�|�}|�|j|j�|�|j�|��Wnt�yVYn0dD]@}	|	dk�r�|�ttjjd
d|	�ntj�d
d|	�}|���q\tj�d�}t�
i�}|�|�|��|��tj�d�}|�|�|��|��dS)N��linux�darwin)TFT��delay����msgZTestr�z/var/run/syslogz/dev/log)�GET�POST�PUTr��	localhostz/logrrY)�sys�platform�tempfile�mkstemp�osr?�unlinkrr6�WatchedFileHandler�dev�inorKr��handle�assertFalse�path�existsr9�
SysLogHandlerZfacilityZLOG_USERZ
unixsocket�OSErrorr��
ValueError�HTTPHandlerZBufferingHandlerZshouldFlush)
r:�existing�fd�fnrDr�r�r�Zsockname�methodr<r<r=�test_builtin_handlers!s\




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

        See Issue #27493.
        �w�arDr�N)r�r�r�r?r��pathlib�Pathr�FileHandlerr6�RotatingFileHandler�TimedRotatingFileHandlerr�r�r�r9r�r�)r:rrZpfnZcases�cls�argsrDr<r<r=�test_path_objectsWs


�
zHandlerTest.test_path_objects�ntz/WatchedFileHandler not appropriate for Windows.c
sN�fdd�}d}d}d�_d�_dD�]"}t�dd�\}}t�|�tj|||fd�}d|_|�	�t
jj||d	�}t
�
d
�}	|�|	�z�t|�D]^}
t�d�t
�dd
i�}zt���_|�|�Wq�ty�td�j�jf��Yq�0q�W|��|��tj�|��rHt�|�q$|��|��tj�|��rFt�|�0q$dS)Nc	sTt|�D]F}zt�|�t���_Wnty6Yn0t�dt�dd��qdS)Ng����Mbp?r�)	�ranger�r��time�
deletion_timer��sleep�random�randint)ZfnameZtries�_r[r<r=�remove_loopqs
z*HandlerTest.test_race.<locals>.remove_loopi��FT�.logztest_logging-3-��targetr
Tr�z'%(asctime)s: %(levelname)s: %(message)s�{�G�zt?r�ZtestingzDeleted at %s, opened at %s)Zhandle_timerr�r�r�r?�	threading�Thread�daemon�startrr6r�r1r4rrrr�r��	Exception�printr�r�r�r�)r:rZ	del_countZ	log_countr�rrZremoverrDr�rr�r<r[r=�	test_racensH	





���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�nt�d�0n(|�d����|��tj|dd
�dS)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_handlerr[��	__class__r<r=r(�s
�zJHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.__init__cSs6|j��z|j�|�W|j��n|j��0dSr�)r*�acquirer��releaser�r<r<r=r��s
zFHandlerTest.test_post_fork_child_no_deadlock.<locals>._OurHandler.emit�r]r^r_r(r��
__classcell__r<r<r+r=�_OurHandler�sr1rz*because we need at least one for this testrY� test_post_fork_child_no_deadlockcsVt��z>���z�����d�W���n
���0Wt��n
t��0dS)N��?)rrr-�set�waitr.r$r<�Z+fork_happened__release_locks_and_end_threadZlocks_held__ready_to_forkZrefed_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)rr;z#Child process did not deadlock. \o/z&Parent process returned from fork. \o/)�exitcodeN)rr�rKrLrr�r*r,r?r;�
assertGreater�_at_fork_reinit_lock_weaksetrr8r-r.r�Eventrr!r5r�r%rx�_exitr4r�rZwait_process)r:r1Ztest_loggerr7Zlock_holder_thread�pidr<r6r=r2�s8


�
z,HandlerTest.test_post_fork_child_no_deadlockN)
r]r^r_r�rr�unittestZskipIfr�r;r$�hasattrr2r<r<r<r=r�s6
0r�c@seZdZdd�ZdS)�	BadStreamcCstd��dS)N�deliberate mistake)�RuntimeError�r:�datar<r<r=�write�szBadStream.writeN)r]r^r_rEr<r<r<r=r@�sr@c@seZdZdd�ZdS)�TestStreamHandlercCs
||_dSr�)�error_recordr�r<r<r=�handleError�szTestStreamHandler.handleErrorN)r]r^r_rHr<r<r<r=rF�srFc@seZdZejZdZdS)�StreamWithIntNamer�N)r]r^r_rr��levelr;r<r<r<r=rI�srIc@s$eZdZdd�Zdd�Zdd�ZdS)�StreamHandlerTestcCs�tt��}t�i�}tj}z�|�|�|�|j|�t�t��}t	�
��.}|�|�d}|�||���Wd�n1s|0Ydt_t	�
��*}|�|�|�
d|���Wd�n1s�0YW|t_n|t_0dS)Nz"
RuntimeError: deliberate mistake
Fr)rFr@rr��raiseExceptionsr��assertIsrGr/r�captured_stderr�assertInrIrK)r:rDr�Z	old_raise�stderrr�r<r<r=�test_error_handling�s 




.

0z%StreamHandlerTest.test_error_handlingcCsVt��}t��}|�|�}|�|tj�|�|�}|�||�|�|�}|�|�dS)z3
        Test setting the handler's stream
        N)	rr/r*r+�	setStreamrMr�rP�assertIsNone)r:rDr,�oldrTr<r<r=�test_stream_settings


z%StreamHandlerTest.test_stream_settingcCs t�t��}|�t|�d�dS)Nz<StreamHandler 2 (NOTSET)>)rr/rIrK�reprr�r<r<r=�'test_can_represent_stream_with_int_namesz9StreamHandlerTest.test_can_represent_stream_with_int_nameN)r]r^r_rQrUrWr<r<r<r=rK�srKc@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)�mapZdecode_datarYF)
�smtpd�
SMTPServerr(�socket�getsockname�port�_handler�_thread�_quit�
poll_interval)r:�addrr�rb�sockmapr<r<r=r(8s�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�rcpttosrDr<r<r=�process_messageAs
zTestSMTPServer.process_messagecCs0tj|j|jfd�|_}|�d�|��dS)zG
        Start the server running on a separate daemon thread.
        rTN�rr�
serve_foreverrbr`�	setDaemonr!�r:�tr<r<r=r!Ms
�
zTestSMTPServer.startcCs|jstj||jdd�qdS)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`.
        rY)rY�countN)ra�asyncoreZloop�_map�r:rbr<r<r=rjVszTestSMTPServer.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)rYZ
ignore_all)rar�join_threadr`r?roZ	close_allrpr[r<r<r=�stopas
zTestSMTPServer.stopN)	r]r^r_r`r(rhr!rjrsr<r<r<r=rX#s		rXcs8eZdZdZdd�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`rbr_rr;�ready)r:r�rbr<r<r=r(}szControlMixin.__init__cCs0tj|j|jfd�|_}|�d�|��dS)zI
        Create a daemon thread to run the server, and start it.
        rTNrirlr<r<r=r!�s
�
zControlMixin.startcs|j��tt|��|�dS)z^
        Run the server. Set the ready flag before entering the
        service loop.
        N)rur4r'rtrjrqr+r<r=rj�s
zControlMixin.serve_forevercCs:|��|jdur$t�|j�d|_|��|j��dS)zK
        Tell the server thread to stop, and wait for it to do so.
        N)�shutdownr`rrr�server_closerurAr[r<r<r=rs�s
zControlMixin.stop)	r]r^r_r`r(r!rjrsr0r<r<r+r=rtms
	rtc@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.
    r3FNcs<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)r:r;�defaultr<r<r=�__getattr__�s
zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.__getattr__cSs|j�|�dSr���serverr_r[r<r<r=rz�szMTestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.process_requestcs �rt�|�j|g|�R�dSr�)r'�log_message)r:�formatr
)�DelegatingHTTPRequestHandlerr,rur<r=r��s���zITestHTTPServer.__init__.<locals>.DelegatingHTTPRequestHandler.log_message)N)r]r^r_r}rzr�r0r<�r�rur+r=r��s
r�)rrr(rt�sslctx)r:rcr�rbrur�r<r�r=r(�s
zTestHTTPServer.__init__c
Cshz(|j��\}}|jr&|jj|dd�}Wn6ty^}ztj�d|��WYd}~n
d}~00||fS)NT)Zserver_sidezGot an error:
%s
)r\�acceptr�Zwrap_socketr�r�rPrE)r:�sockrc�er<r<r=�get_request�szTestHTTPServer.get_request)r3FN)r]r^r_r`r(r�r<r<r<r=rx�s

�
rxcs.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.
    Tr3cCs2Gdd�dt�}t�||||�t�|||�dS)Nc@seZdZdd�ZdS)z;TestTCPServer.__init__.<locals>.DelegatingTCPRequestHandlercSs|j�|�dSr�r~r[r<r<r=r��szBTestTCPServer.__init__.<locals>.DelegatingTCPRequestHandler.handleN)r]r^r_r�r<r<r<r=�DelegatingTCPRequestHandler�sr�)rr
r(rt)r:rcr�rb�bind_and_activater�r<r<r=r(�s

�zTestTCPServer.__init__cs"tt|���|j��d|_dS�NrY)r'r��server_bindr\r]r^r[r+r<r=r��szTestTCPServer.server_bind)r3T)r]r^r_r`Zallow_reuse_addressr(r�r0r<r<r+r=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.
    r3Tcs<G�fdd�dt��t�||�|�t�|||�d|_dS)Ncs&eZdZdd�Z��fdd�Z�ZS)z;TestUDPServer.__init__.<locals>.DelegatingUDPRequestHandlercSs|j�|�dSr�r~r[r<r<r=r��szBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.handlecsB|j��}|r>zt�|���Wnty<|jjs8�Yn0dSr�)ZwfilerIr'�finishr�r�_closedrC)�DelegatingUDPRequestHandlerr,r<r=r��s
zBTestUDPServer.__init__.<locals>.DelegatingUDPRequestHandler.finish)r]r^r_r�r�r0r<�r�r+r=r��sr�F)rrr(rtr�)r:rcr�rbr�r<r�r=r(�s�zTestUDPServer.__init__cs"tt|���|j��d|_dSr�)r'r�r�r\r]r^r[r+r<r=r�szTestUDPServer.server_bindcstt|���d|_dS)NT)r'r�rwr�r[r+r<r=rwszTestUDPServer.server_close)r3T)r]r^r_r`r(r�rwr0r<r<r+r=r��s�
r��AF_UNIXc@seZdZejZdS)�TestUnixStreamServerN�r]r^r_r\r��address_familyr<r<r<r=r�sr�c@seZdZejZdS)�TestUnixDatagramServerNr�r<r<r<r=r�sr�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?�meZyouZLog)�timeoutr�u	Hello ✓rYz
Subject: Log
u

Hello ✓)rXrZHOSTrhr!r^rr6ZSMTPHandler�TIMEOUTrKZtoaddrs�messagesr�rr;�handledr�r5rsr9�is_setrLrO�endswithr?)
r:rdrrcrDr�rerfrgrDr<r<r=�
test_basic#s0��

zSMTPHandlerTest.test_basiccGs|j�|�|j��dSr�)r��appendr�r4)r:r
r<r<r=rh;szSMTPHandlerTest.process_messageN)r]r^r_rZLONG_TIMEOUTr�r�rhr<r<r<r=r�sr�c@s<eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�MemoryHandlerTestzTests for the MemoryHandler.r�cCsFt�|�tj�dtj|j�|_t�d�|_	d|j	_
|j	�|j�dS)N�
Zmemr)rr>rr6�
MemoryHandlerrkr0�mem_hdlrr�
mem_logger�	propagater8r[r<r<r=r>Fs
�zMemoryHandlerTest.setUpcCs|j��t�|�dSr�)r�r?rrEr[r<r<r=rENs
zMemoryHandlerTest.tearDowncCs�|j�|���|�g�|j�|���|�g�|j�|���gd�}|�|�dD]b}td�D]}|j�|���qf|�|�|j�|���|dd�t||d�D�}|�|�qZ|j�|���|�|�dS)N)�r.rf�rmrh)rkri)r��	cSsg|]}dt|�f�qS)r.)�str)�.0�ir<r<r=�
<listcomp>h�z0MemoryHandlerTest.test_flush.<locals>.<listcomp>r�)r�ryr\rXrxrwr)r:�lines�nr�r<r<r=�
test_flushRs 



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�r�r�FN)r�ryr\rXrxr@r�r?rr6r�rkr0r8)r:r�r<r<r=�test_flush_on_closens,


�
�


z%MemoryHandlerTest.test_flush_on_closec
Cs�Gdd�d�}||j�}zV|j�|�td�D]&}t�d�|j�d�|j�d�q.W|jD]}t	�
|�q^n|jD]}t	�
|�qv0dS)Nc@s$eZdZdd�Zdd�Zdd�ZdS)zZMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandlercSs||_g|_dSr�)r��threads)r:r�r<r<r=r(�szcMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.__init__cSs|j�d�dSr�)r��	setTargetr[r<r<r=�removeTarget�szgMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.removeTargetcSs&tj|jd�}|j�|�|��dS)N)r)rrr�r�r�r!)r:r��threadr<r<r=r��szaMemoryHandlerTest.test_race_between_set_target_and_flush.<locals>.MockRaceConditionHandler.handleN)r]r^r_r(r�r�r<r<r<r=�MockRaceConditionHandler�sr�r�rznot flushedZflushed)r�r�rrrr�rxrwr�rrr)r:r�rrr�r<r<r=�&test_race_between_set_target_and_flush�s


�
z8MemoryHandlerTest.test_race_between_set_target_and_flushN)
r]r^r_r`rHr>rEr�r�r�r<r<r<r=r�?sr�c@seZdZdZdd�ZdS)�ExceptionFormatterzA special exception formatter.cCsd|djS)Nz
Got a [%s]r)r])r:�eir<r<r=�formatException�sz"ExceptionFormatter.formatExceptionN)r]r^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,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=
    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|fi|��dSr�)r*r+�textwrap�dedentr�config�
fileConfig)r:�conf�kwargs�filer<r<r=�apply_config�szConfigFileTest.apply_configcCsvt���Z}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�Wd�n1sh0YdS�N�rgrhr&�
r�captured_stdoutr��config0rrrxr\rvrX�r:�outputr�r<r<r=�test_config0_ok�s
��zConfigFileTest.test_config0_okcCs�t���~}t�t�|j��}t��}|�	|�t
j�|�t
�
�}|�|���|�|���|jdg|d�|�g�Wd�n1s�0YdSr�)rr�r*r+r�r�r��configparser�ConfigParserZ	read_filerr�r�rrxr\rvrX)r:r�r�Zcpr�r<r<r=�test_config0_using_cp_ok�s

��z'ConfigFileTest.test_config0_using_cp_okcCsxt���\}|�|�t�d�}|�|���|�|���|jddg|d�|�g�Wd�n1sj0YdS�N�compiler.parser�rmrfr�r&�	rr�r�rrrxr\rvrX�r:r�r�r�r<r<r=�test_config1_ok�s


��zConfigFileTest.test_config1_okcCs|�t|j|j�dSr��r�r"r��config2r[r<r<r=�test_config2_failure�sz#ConfigFileTest.test_config2_failurecCs|�t|j|j�dSr��r�r"r��config3r[r<r<r=�test_config3_failure�sz#ConfigFileTest.test_config3_failurec	Cs�t���r}|�|j�t��}z
t��WntyDt�d�Yn0tj	�
d�|�|��d�|�
g�Wd�n1s�0YdS�Nzjust testingrz-ERROR:root:just testing
Got a [RuntimeError]
)rr�r��config4rrrB�	exceptionr��stdout�seekrKrIrXr�r<r<r=�test_config4_ok�s


�zConfigFileTest.test_config4_okcCs|j|jd�dS�N)r��r��config5r[r<r<r=�test_config5_ok�szConfigFileTest.test_config5_okcCs|j|jd�dSr�)r��config6r[r<r<r=�test_config6_ok�szConfigFileTest.test_config6_okcCsJt���v}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
gd�|d�|�
g�Wd�n1s�0Yt����}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
gd�|d�|�
g�Wd�n1�s<0YdS�Nr�zcompiler-hyphenated)r�r�)rerir&�compiler.lexer))rmrj)rgrl)rmrn)rgro)rr�r��config1arrrxr\rv�criticalrX�config7r�r�r:r�r�Z
hyphenatedr<r<r=�test_config7_ok�s2



�(



�zConfigFileTest.test_config7_okcCs�dd�}|���bt�dd�\}}t�|�tjdkrB|�dd�}|jj|d�}|�	|�|�	|�Wd�n1sx0Yt
jjd	}|�
|||�dS)
NcSs|��t�|�dSr��r?r��remove��h1rr<r<r=�cleanup*sz/ConfigFileTest.test_config8_ok.<locals>.cleanupr�test_logging-X-r�\z\\)r�r)�check_no_resource_warningr�r�r�r?r;�replace�config8r�r�r�rootr6r�)r:r�rrr�r�r<r<r=�test_config8_ok(s



(zConfigFileTest.test_config8_okcCsZ|�|j�t�d�}|�|j�|�|j�|�|j�|j|jdd�|�|j�dS)NZsome_pristine_loggerF)�disable_existing_loggers)r��disable_testrrr�rr9�r:r�r<r<r=�test_logger_disabling?s
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�rKrrr6r;)r:Ztest_configr<r<r=�test_config_set_handler_namesHs
z,ConfigFileTest.test_config_set_handler_namesc
Cs�t�d���}tjddd�\}}zPt�||�d��t�|�t	j
j|tdddd	d
dd�id
�d�Wt�
|�nt�
|�0dS)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�asciirYFr�z5%(asctime)s [%(process)d] [%(levelname)s] %(message)sz[%Y-%m-%d %H:%M:%S %z]zlogging.Formatter)r��datefmt�class)�versionr��
formatters)�defaultsN)r�r��stripr�r�r�rE�encoder?rr�r��dictr�)r:Zinirrr<r<r=�!test_defaults_do_no_interpolation`s&
����z0ConfigFileTest.test_defaults_do_no_interpolationN)!r]r^r_r`rr�rHr��config1r�r�r�r�r�r�r�r�r�rr�r�r�r�r�r�r�r�r�r�r�rrrr<r<r<r=r��s@  ��*&+	r�c@s@eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dd�Zd
S)�SocketHandlerTestzTest for SocketHandler objects.�r�rc
Cs�t�|�d|_|_|_z$|�|j|jd�|_}|��Wn,t	yl}z||_WYd}~dSd}~00|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.N�{�G�z�?r�rr)rr>r�	sock_hdlr�server_exception�server_class�address�
handle_socketr!r�rur5rr6Z
SocketHandler�
isinstance�server_addressrPr^�
log_outputr'r@r8r�	Semaphorer��r:rr�Zhclsr<r<r=r>�s&
�

zSocketHandlerTest.setUpc	CsNz<|jr |j�|j�|j��|jr0|j��Wt�|�nt�|�0dS)zShutdown the TCP server.N)rr'r@r?rrsrrEr[r<r<r=rE�s
zSocketHandlerTest.tearDowncCs�|j}|�d�}t|�dkrq�t�d|�d}|�|�}t|�|kr\||�|t|��}q8t�|�}t�|�}|j	|j
d7_	|j��qdS)Nr�>Lr�
)
�
connection�recvrL�struct�unpack�pickle�loadsrr�rr�r�r.)r:�request�conn�chunk�slen�objr�r<r<r=r�s



zSocketHandlerTest.handle_socketcCsV|jr|�|j�t�d�}|�d�|j��|�d�|j��|�|j	d�dS)NZtcpr��eggs�
spam
eggs
)
r�skipTestrrrvr�r-ryrKrrr<r<r=�test_output�s




zSocketHandlerTest.test_outputcCs�|jr|�|j�d|j_|j��ztd��WntyN|j�d�Yn0|j�	d�t
�
�}|�|jj|�t
�
|jj|d�|j�	d�dS)Ng@zDeliberate mistakez
Never sentzNever sent, eitherr�zNor this)rr/rZ
retryStartrrsrBr'r�rvrr9Z	retryTimer)r:�nowr<r<r=�
test_noserver�s
zSocketHandlerTest.test_noserverN)r]r^r_r`r�rrr>rErr0r2r<r<r<r=r�srcCs*tjddd�\}}t�|�t�|�|S)Nrz.sockr)r�r�r�r?r�)rrr<r<r=�_get_temp_domain_socket�s

r3zUnix sockets requiredc@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixSocketHandlerTestz)Test for SocketHandler with unix sockets.r�cCst�|_t�|�dSr�)r3rrr>r[r<r<r=r>�szUnixSocketHandlerTest.setUpcCst�|�t�|j�dSr�)rrErr�rr[r<r<r=rE�s
zUnixSocketHandlerTest.tearDownN)
r]r^r_r`r?r\r�rr>rEr<r<r<r=r4�s

r4c@s8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�DatagramHandlerTestzTest for DatagramHandler.rc
Cs�t�|�d|_|_|_z$|�|j|jd�|_}|��Wn,t	yl}z||_WYd}~dSd}~00|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.Nrr�rr)rr>rrrrr�handle_datagramr!r�rur5rr6ZDatagramHandlerrrrPr^rr'r@r8rr;r�rr<r<r=r>s&
�

zDatagramHandlerTest.setUpc	CsNz<|jr|j��|jr0|j�|j�|j��Wt�|�nt�|�0dS)zShutdown the UDP server.N)rrsrr'r@r?rrEr[r<r<r=rEs
zDatagramHandlerTest.tearDowncCsTt�dd�}|jt|�d�}t�|�}t�|�}|j|j	d7_|j
��dS)Nr rr!)r$�pack�packetrLr&r'rr�rr�r�r4)r:r(r+r8r,r�r<r<r=r6*s

z#DatagramHandlerTest.handle_datagramcCs`|jr|�|j�t�d�}|�d�|j��|j��|�d�|j��|�|j	d�dS)NZudpr�r-r.)
rr/rrrvr�r5rArKrrr<r<r=r02s





zDatagramHandlerTest.test_outputN�r]r^r_r`r�rrr>rEr6r0r<r<r<r=r5�sr5c@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixDatagramHandlerTestz,Test for DatagramHandler using Unix sockets.r�cCst�|_t�|�dSr�)r3rr5r>r[r<r<r=r>FszUnixDatagramHandlerTest.setUpcCst�|�t�|j�dSr�)r5rErr�rr[r<r<r=rEKs
z UnixDatagramHandlerTest.tearDownN�
r]r^r_r`r?r\r�rr>rEr<r<r<r=r:>s

r:c@s8eZdZdZeZdZdd�Zdd�Zdd�Z	d	d
�Z
dS)�SysLogHandlerTestz!Test for SysLogHandler using UDP.rc
Cs�t�|�d|_|_|_z$|�|j|jd�|_}|��Wn,t	yl}z||_WYd}~dSd}~00|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.Nrrr)rr>r�sl_hdlrrrrr6r!r�rur5rr6r�rrrPr^rr'r@r8rr;r�rr<r<r=r>Vs&
�

zSysLogHandlerTest.setUpc	CsNz<|jr|j��|jr0|j�|j�|j��Wt�|�nt�|�0dS)zShutdown the server.N)rrsr=r'r@r?rrEr[r<r<r=rEps
zSysLogHandlerTest.tearDowncCs|j|_|j��dSr�)r8rr�r4)r:r(r<r<r=r6{sz!SysLogHandlerTest.handle_datagramcCs�|jr|�|j�t�d�}|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�|j�	�d|j
_|�d�|j��|�|jd�dS)NZslh�späms
<11>spämFs	<11>spämuhäm-s<11>häm-späm)
rr/rrrvr�r5rKrrAr=Z
append_nul�identrr<r<r=r0s 








zSysLogHandlerTest.test_outputNr9r<r<r<r=r<Osr<c@s.eZdZdZeed�reZdd�Zdd�Z	dS)�UnixSysLogHandlerTestz)Test for SysLogHandler with Unix sockets.r�cCst�|_t�|�dSr�)r3rr<r>r[r<r<r=r>�szUnixSysLogHandlerTest.setUpcCst�|�t�|j�dSr�)r<rErr�rr[r<r<r=rE�s
zUnixSysLogHandlerTest.tearDownNr;r<r<r<r=r@�s

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|���dSr�)r\�AF_INET6rr�r'rAr>r[r+r<r=r>�s
zIPv6SysLogHandlerTest.setUpcstj|j_tt|���dSr�)r\�AF_INETrr�r'rArEr[r+r<r=rE�s
zIPv6SysLogHandlerTest.tearDown)
r]r^r_r`r�rrr>rEr0r<r<r+r=rA�s
rAc@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)rr>rr;r�r[r<r<r=r>�s
zHTTPHandlerTest.setUpcCsr|j|_t|j�|_|jdkrRz t|jd�}|j�|�|_Wnd|_Yn0|�	d�|�
�|j��dS)Nr�zContent-Length��)
�commandr	r��log_data�intZheadersZrfilerR�	post_dataZ
send_responseZend_headersr�r4)r:r(Zrlenr<r<r=�handle_request�s

zHTTPHandlerTest.handle_requestc	Cs�t�d�}|j}|�|jjd�dD�]�}d}|r�zddl}WntyVd}Yq�0tj�	t
�}tj�|d�}|�|j
�}|�|�|j|d�}	nd}d}	t||jd|d�|_}
|
��|
j��d	|
j}|o�|}tjj|d
||	dd�|_d|_|�|j�d
D]�}
|
|j_|j��d}|�|�|j��|�|jjd
�|�|j |
�|
dk�rlt!|jj"�}nt!|j#�$d��}|�|ddg�|�|ddg�|�|d|g��q|j�%�|j�|j�|j�&�q&dS)N�httprrrzkeycert.pem)Zcafiler)r�zlocalhost:%dz/frob)�foo�bar)�secure�contextZcredentials)r�r�r>r��utf-8r;�funcNamer0r�)'rrr'r@r6�ssl�ImportErrorr�r��dirname�__file__r�Z
SSLContextZPROTOCOL_TLS_SERVERZload_cert_chainZcreate_default_contextrxrJrr!rur5Zserver_portr�Zh_hdlrrGr8rr�rArvrKrFr
�queryrI�decodersr?)r:r�r'rNrcrRr��hereZlocalhost_certrOr�hostZ
secure_clientrr��dr<r<r=r0�s`



�


�




zHTTPHandlerTest.test_outputN)r]r^r_r`r>rJr0r<r<r<r=rD�s
rDc@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)rr>�
_survivorsr[r<r<r=r>s
zMemoryTest.setUpcGs.|D]$}t|�t|�f}t�|�|j|<qdS)zKWatch the given objects for survival, by creating weakrefs to
        them.N)�idrV�weakref�refr\)r:r
r,�keyr<r<r=�_watch_for_survival
szMemoryTest._watch_for_survivalcCs\t��g}|j��D] \\}}}|�dur|�|�q|rX|�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�r�rOrLr�)r:ZdeadZid_�repr_r_r<r<r=�_assertTruesurvivals
�zMemoryTest._assertTruesurvivalcCs�|j�tj�t�d�}|�|�|�tj�|j�|���|�|���|�	dg�~|�
�t�d�}|�|���|�	ddg�dS)NrL)rLr.rh)rLr.ri)r'r-rrmrrar.ryr\rXrd)r:rLrMr<r<r=�test_persistent_loggerss"

�
�z"MemoryTest.test_persistent_loggersN)r]r^r_r`r>rardrer<r<r<r=r[s
r[c@seZdZdd�Zdd�ZdS)�EncodingTestc	Cs�t�d�}t�dd�\}}t�|�d}z�tj|dd�}|�|�z |�|�W|�	|�|��n|�	|�|��0t
|dd�}z |�|���
�|�W|��n
|��0Wtj�|�r�t�|�ntj�|�r�t�|�0dS)N�testrztest_logging-1-ufoo€rP��encoding)rrr�r�r�r?r	r8rwr@r)rKrR�rstripr��isfiler�)r:rurrrDr�r�r<r<r=�test_encoding_plain_file6s*




�

�z%EncodingTest.test_encoding_plain_filec	Cs�t�d�}d}t�d�}d|_t��}||d�}t�|�}|�|�z |�	|�W|�
|�|��n|�
|�|��0|��}|�
|d�dS)Nrguдо свидания�cp1251�stricts�� �������
)rr�codecs�	getwriterrir*�BytesIOr/r8rwr@r?rIrK)r:ru�messageZwriter_classr,�writerr�rWr<r<r=�test_encoding_cyrillic_unicodePs 






�

z+EncodingTest.test_encoding_cyrillic_unicodeN)r]r^r_rlrtr<r<r<r=rf5srfc@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
�Wd�n1s�0YdS)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*r+r/rr8�warnr@rIr?r9�find�showwarningrK)r:r,rDr�rWZa_filer<r<r=�
test_warningshs,






��zWarningsTest.test_warningscCs�t���vt�d�|�tjd�t�d�}|�|jg�t�dt	dd�|�t
|j�d�|�|jdtj�Wd�n1s�0YdS)	NTFrxryrzr{rYr)
r|r}rr~r�rrKr6r�r�rL�assertIsInstance�NullHandlerrr<r<r=�test_warnings_no_handlers�s


z&WarningsTest.test_warnings_no_handlersN)r]r^r_r�r�r<r<r<r=rufsrucCst�||�Sr�)rr1)r�r	r<r<r=�
formatFunc�sr�c@seZdZddd�ZdS)�myCustomFormatterNcCsdSr�r<)r:�fmtr	r<r<r=r(�szmyCustomFormatter.__init__)N)r]r^r_r(r<r<r<r=r��sr�cCst��Sr�)rr/r<r<r<r=�handlerFunc�sr�c@seZdZdS)�
CustomHandlerN�r]r^r_r<r<r<r=r��sr�c
@seZdZdZejZdZddddiidddd	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��ZFdsS)��ConfigDictTestz)Reading logging config from a dictionary.r�rY�form1r�z%(levelname)s ++ %(message)srzlogging.StreamHandlerr�zext://sys.stdout)r
�	formatterrJr,rk�rJr6)rrr6r�r�r.rJ)rrr6�loggersr�zext://sys.stdboutZNTOSETZWRANINGZmisspelled_namez.ExceptionFormatterz"%(levelname)s:%(name)s:%(message)s)�()r�z.formatFunc)r�Zform2Zform3r�)rZhand2z.CustomHandlerzinvalid parameter name)r
r�rJr,rqr�F)�compilerr�)rr�rr6r�r�Trm)rZincrementalr6r�Zfilt1r;)r
r�rJr,�filters)rJr�)rrr�r6r�r�zcfg://true_formatterszcfg://handler_configs[hand1])r�true_formatters�handler_configsrr6r�r�)r�r�rr6r�r�r�rM�!
)rL�
terminator)r
r�rJr,r��mySimpleFormatterz1%(asctime)s (%(name)s) %(levelname)s: %(message)s�$)r��style)r
rJr�zlogging.handlers.MemoryHandler��
fileGlobal)r
Zcapacityr�rrJ)r��bufferGlobal�mymoduler��true)rJr6r�)rrr6r�)r�r��validate�my_test_logger_custom_formatter)r
r�r�z.myCustomFormattercCstj�|�dSr�)rr�Z
dictConfig)r:r�r<r<r=r��szConfigDictTest.apply_configcCsvt���Z}|�|j�t��}|�|���|�|���|j	dg|d�|�	g�Wd�n1sh0YdSr�r�r�r<r<r=r��s
��zConfigDictTest.test_config0_okcCsxt���\}|�|�t�d�}|�|���|�|���|jddg|d�|�g�Wd�n1sj0YdSr�r�r�r<r<r=r��s


��zConfigDictTest.test_config1_okcCs|�t|j|j�dSr�r�r[r<r<r=r��sz#ConfigDictTest.test_config2_failurecCs|�t|j|j�dSr�)r�r"r��config2ar[r<r<r=�test_config2a_failure�sz$ConfigDictTest.test_config2a_failurecCs|�t|j|j�dSr�)r�r"r��config2br[r<r<r=�test_config2b_failure�sz$ConfigDictTest.test_config2b_failurecCs|�t|j|j�dSr�r�r[r<r<r=r��sz#ConfigDictTest.test_config3_failurec	Cs�t���j}|�|j�z
t��Wnty<t�d�Yn0tj�	d�|�
|��d�|�g�Wd�n1sx0YdSr�)
rr�r�r�rBrr�r�r�r�rKrIrX�r:r�r<r<r=r��s


�zConfigDictTest.test_config4_okc	Cs�t���j}|�|j�z
t��Wnty<t�d�Yn0tj�	d�|�
|��d�|�g�Wd�n1sx0YdSr�)
rr�r��config4arBrr�r�r�r�rKrIrXr�r<r<r=�test_config4a_ok�s


�zConfigDictTest.test_config4a_okcCs|j|jd�dSr�r�r[r<r<r=r��szConfigDictTest.test_config5_okcCs|�t|j|j�dSr�)r�r"r�r�r[r<r<r=�test_config6_failure�sz#ConfigDictTest.test_config6_failurecCst���^}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�Wd�n1sl0Yt���t}|�|j
�t�d�}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�Wd�n1s�0YdS)Nr�r�r�r&r��rmri�rgrj)
rr�r�rrrrxr\rvrXr�r9rr�r<r<r=r��s4

��(


��zConfigDictTest.test_config7_okcCs$t���^}|�|j�t�d�}|�|���|�|���|j	ddg|d�|�	g�Wd�n1sl0Yt����}|�|j
�t�d�}|�|j�|�|���|�|���t�d�}|�|���|�|���|j	gd�|d�|�	g�Wd�n1�s0YdS)Nr�r�r�r&r�)r�r��rmrl�rgrn)
rr�r�rrrrxr\rvrXr�r�rr�r<r<r=�test_config_8_ok�s2

��(



�zConfigDictTest.test_config_8_okcCsJt���v}|�|j�t�d�}t�d�}|�|���|�|���|�	|���|j
gd�|d�|�
g�Wd�n1s�0Yt����}|�|j�t�d�}|�|j
�|�|���|�|���t�d�}|�|���|�|���|�	|���|j
gd�|d�|�
g�Wd�n1�s<0YdSr�)rr�r�r�rrrxr\rvr�rX�config8ar�rr�r<r<r=�test_config_8a_oks2



�(



�z ConfigDictTest.test_config_8a_okcCs�t����}|�|j�t�d�}|�|���|jg|d�|�|j	�|�|���|jg|d�|�|j
�|�|���|jdg|d�Wd�n1s�0YdS)Nr�r&r�)rr�r��config9rrrxr\rX�config9a�config9br�r<r<r=�test_config_9_ok?s

��zConfigDictTest.test_config_9_okcCs�t����}|�|j�t�d�}|�|���t�d�}|�|���t�d�}|�|���t�d�}|�|���|j	ddg|d�Wd�n1s�0YdS�Nr�r�r�zcompiler.parser.codegen)rkrfr�r&)
rr�r��config10rrrwr\rvrXr�r<r<r=�test_config_10_okQs 




��z ConfigDictTest.test_config_10_okcCs|�|j�dSr�)r��config11r[r<r<r=�test_config11_okdszConfigDictTest.test_config11_okcCs|�t|j|j�dSr�)r�r"r��config12r[r<r<r=�test_config12_failuregsz$ConfigDictTest.test_config12_failurecCs|�t|j|j�dSr�)r�r"r��config13r[r<r<r=�test_config13_failurejsz$ConfigDictTest.test_config13_failurecCs|t���`}|�|j�tjd}|�|jd�|�|jd�t�	d�|�
|���d��Wd�n1sn0YdS)NrrMr�ZExclamationz
Exclamation!
)
rr�r��config14rrrKrLr�rwr9rIr�)r:r�rDr<r<r=�test_config14_okms


zConfigDictTest.test_config14_okcCs�dd�}|���Zt�dd�\}}t�|�ddd|d�id	dgid
�}|�|�|�|�Wd�n1sp0Ytjjd}|�	|||�dS)NcSs|��t�|�dSr�r�r�r<r<r=r�xsz0ConfigDictTest.test_config15_ok.<locals>.cleanuprr�rYr�zlogging.FileHandler)r
�filenamer6�rr6r�r)
r�r�r�r�r?r�rr�r6r�)r:r�rrr�r�r<r<r=�test_config15_okv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|�}	|	dkr�|�||d��}
||
7}|	|
8}	q�|��W|j�d�tj��t�|�n"|j�d�tj��t�|�0dS)NrPrg@r�r )rrr��listenr!rur5r^rAr\rC�SOCK_STREAM�
settimeout�connectr$r7rL�sendr?Z
stopListeningrrr)r:�textZverifyrmr^r�r+rWZ	sentsofar�left�sentr<r<r=�setup_via_listener�s2






�
z!ConfigDictTest.setup_via_listenercCs�t����}|�t�|j��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�|�	��t�d�}|�
|�	��|jddg|d�Wd�n1s�0YdSr�)rr�r��json�dumpsr�rrrwr\rvrXr�r<r<r=�test_listen_config_10_ok�s 




��z'ConfigDictTest.test_listen_config_10_okcCs�t���d}|�t�tj��t�d�}|�	|�
��|�|�
��|jddg|d�|�g�Wd�n1sr0YdSr�)
rr�r�r�r�r�rrrrxr\rvrXr�r<r<r=�test_listen_config_1_ok�s

��z&ConfigDictTest.test_listen_config_1_okcCs�dd�}dd�}t�d�}t�tj�}t���8}|�||�|�	|�
��|�|�
��Wd�n1sl0Y|jg|d�|jddgd	d
�t���@}|�|�t�d�}|�	|�
��|�|�
��Wd�n1s�0Y|jddg|d�|jddgd	d
�t���L}|�|ddd
�|�t�d�}|�	|�
��|�|�
��Wd�n1�sn0Y|jddg|d�|jddgd	d
�dS)NcSsdSr�r<��stuffr<r<r=�verify_fail�sz6ConfigDictTest.test_listen_verify.<locals>.verify_failcSs|ddd�S)Nr�r<r�r<r<r=�verify_reverse�sz9ConfigDictTest.test_listen_verify.<locals>.verify_reverser�r&r�r�r�)rSr�r�r�r�r�)
rrr�r�r�rrr�r�rxr\rvrX)r:r�r�r�Zto_sendr�r<r<r=�test_listen_verify�sb

,��


,����

.����z!ConfigDictTest.test_listen_verifycCs|�t|j|j�dSr�)r�r�r��out_of_orderr[r<r<r=�test_out_of_order
sz ConfigDictTest.test_out_of_ordercCs\t�|j�}d|ddd<|�|�t�d�jd}|�|jtj	�|�|j
jtj�dS)Nz-${asctime} (${name}) ${levelname}: ${message}rr�r�r�r)
r�deepcopyr�r�rrr6r�rr�r��_style�StringTemplateStyle�r:r�r�r<r<r=�#test_out_of_order_with_dollar_style
s

�z2ConfigDictTest.test_out_of_order_with_dollar_stylecCs.|�|j�t�d�jd}|�|jt�dS�Nr�r)r��custom_formatter_class_validaterrr6r�r�r��r:r�r<r<r=�)test_custom_formatter_class_with_validate
sz8ConfigDictTest.test_custom_formatter_class_with_validatecCs.|�|j�t�d�jd}|�|jt�dSr�)r�� custom_formatter_class_validate2rrr6r�r�r�r�r<r<r=�*test_custom_formatter_class_with_validate2 
sz9ConfigDictTest.test_custom_formatter_class_with_validate2cCsF|j��}d|ddd<|�|�t�d�jd}|�|jt�dS)Nr�rr�r�r�r)	r�rr�rrr6r�r�r�r�r<r<r=�9test_custom_formatter_class_with_validate2_with_wrong_fmt%
s


zHConfigDictTest.test_custom_formatter_class_with_validate2_with_wrong_fmtcCs|�t|j|j�dSr�)r�r�r�� custom_formatter_class_validate3r[r<r<r=�*test_custom_formatter_class_with_validate3.
sz9ConfigDictTest.test_custom_formatter_class_with_validate3cCs|�t|j|j�dSr�)r�r�r��custom_formatter_with_functionr[r<r<r=�,test_custom_formatter_function_with_validate1
sz;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)rYr��)r�b�cr�r�)rZr�)�g)rDr��jr��lrzr�)�ozcfg://alist�p)ZatupleZalistZadictZnest1Znest2Znest3zcfg://atuple[1]r�zcfg://alist[1]r�zcfg://nest1[1][0]rDzcfg://nest2[1][1]z
cfg://adict.dzcfg://adict[f]zcfg://nest3rYzcfg://nosuchzcfg://!zcfg://adict[2])	rr�ZBaseConfiguratorrK�convert�popr��KeyErrorr�)r:rZZbcr�r<r<r=�test_baseconfig4
s&�
zConfigDictTest.test_baseconfigcs�ddlm�G�fdd�dtj�}�dddg�}|dd	gd
�}dd||d
�iddgd�d�}t���$}|�|�t�d�Wd�n1s�0Y|�|�	�d�dS)Nr��
namedtuplecs*eZdZ��fdd�Z�fdd�Z�ZS)z1ConfigDictTest.test_namedtuple.<locals>.MyHandlercst�j|i|��||_dSr�)r'r(�resource)r:r�r
r�)r,r�r<r=r(O
sz:ConfigDictTest.test_namedtuple.<locals>.MyHandler.__init__cs$|jd|jj��7_t��|�S�N� )r�r��typer'r�r�r+r<r=r�S
sz6ConfigDictTest.test_namedtuple.<locals>.MyHandler.emitr/r<r�r+r=�	MyHandlerN
sr��Resourcer��labelsZmy_typer)r�r�rYZ	myhandler)r�r�rmr�r�zsome logzsome log my_type
)
�collectionsr�rr/rrNr�rxrKrI)r:r�r�r�r�rPr<r�r=�test_namedtupleJ
s 	��
�


(zConfigDictTest.test_namedtuple)N)Gr]r^r_r`rr�rHr�rr�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�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�r�r�r�r�r�r�r�r<r<r<r=r��s�����	������	��������	��������	��������	��������	��������	��������	�����������#����	��������
��������	��������
��	������
��	������	��������������������
����#���������!������������������ �����
����������!����	�������	�������	�������	���!+	
>
	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��|�dSr��r�)r:rJr�r
�exc_info�extra�Zloggedr<r=�_logn
sz;ManagerTest.test_manager_loggerclass.<locals>.MyLogger._log)NN)r]r^r_rr<rr<r=�MyLoggerm
srrgzshould appear in loggedzshould not appear in logged)
r�Logger�Managerr��	TypeError�setLoggerClassrHrrwrK)r:r�manr�r<rr=�test_manager_loggerclassj
s




z$ManagerTest.test_manager_loggerclasscCs,t�d�}t�}|�|�|�|j|�dSr�)rr�object�setLogRecordFactoryrK�logRecordFactory)r:rrUr<r<r=�test_set_log_record_factoryz
s

z'ManagerTest.test_set_log_record_factoryN)r]r^r_rrr<r<r<r=ri
src@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�defZghi�abc.defzabc.def.ghi)rr�getChildrM)r:r��l1�l2�c1�c2Zc3r<r<r=�test_child_loggers�
s






z"ChildLoggerTest.test_child_loggersN)r]r^r_rr<r<r<r=r�
src@seZdZdS)�DerivedLogRecordNr�r<r<r<r=r�
src@s$eZdZdd�Zdd�Zdd�ZdS)�LogRecordFactoryTestcCsBGdd�dtj�}t�|�|t�|_|j�|j�t��|_	dS)Nc@seZdZdd�Zdd�ZdS)z2LogRecordFactoryTest.setUp.<locals>.CheckingFiltercSs
||_dSr�)r)r:rr<r<r=r(�
sz;LogRecordFactoryTest.setUp.<locals>.CheckingFilter.__init__cSs,t|�}||jur(d||jf}t|��dS)Nz)Unexpected LogRecord type %s, expected %sT)r�rr	)r:r�rmr�r<r<r=r��
s
�z9LogRecordFactoryTest.setUp.<locals>.CheckingFilter.filterN)r]r^r_r(r�r<r<r<r=�CheckingFilter�
sr)
rr�rr>rr�r'r��getLogRecordFactory�orig_factory)r:rr<r<r=r>�
s


zLogRecordFactoryTest.setUpcCs(|j�|j�t�|�t�|j�dSr�)r'r�r�rrErrrr[r<r<r=rE�
s
zLogRecordFactoryTest.tearDowncCs@|�t|jj|���t�t�|j�|���|�	dg�dS)N)r�rgrh)
r�r	r'rwr\rrrrvrXr[r<r<r=�test_logrecord_class�
s�
�z)LogRecordFactoryTest.test_logrecord_classN)r]r^r_r>rEr r<r<r<r=r�
src@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�ZqueF)rr>�queue�Queuerr6�QueueHandler�que_hdlrr;r�
que_loggerr�r-rkr8r[r<r<r=r>�
s
zQueueHandlerTest.setUpcCs|j��t�|�dSr�)r%r?rrEr[r<r<r=rE�
s
zQueueHandlerTest.tearDowncCs�|j�|���|�tj|jj�|j�|���|�tj|jj�|��}|j�|�|j��}|�	t
|tj��|�
|j|jj�|�
|j|jf|df�dSr�)r&ryr\r�r"�Empty�
get_nowaitrxrwr9rr�	LogRecordrKr;r�r
)r:r�rDr<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})r;�	levelnamerr)r\rr�rkr�r;r1r2r%r4r&rwr"r(rKr�rr)r:r�r+Zlog_format_strZ
formatted_msgr�Z
log_recordr<r<r=�test_formatting�
s�
z QueueHandlerTest.test_formatting�
QueueListenerz5logging.handlers.QueueListener required for this testcCs�tt���}tj�|j|�}|��z<|j�	|�
��|j�|�
��|j�|�
��W|�
�n
|�
�0|�|jtjdd��|�|jtjdd��|�|jtjdd��|��tt���}|�tj�tjj|j|dd�}|��z<|j�	|�
��|j�|�
��|j�|�
��W|�
�n
|�
�0|�|jtjdd��|�|jtjdd��|�|jtjd	d��|��dS)
Nrf)r�rrrhriT)Zrespect_handler_levelrjrlrn)rrZMatcherrr6r-r"r!r&rwr\rvr�rsr9�matchesrkrgrer?r-r�)r:r��listenerr<r<r=�test_queue_listener�
s6�z$QueueHandlerTest.test_queue_listenerc
Cs�tj�|j|j�}|��zddWn<tyb}z$|}|jj|�	�|d�WYd}~n
d}~00|�
�|�|j�
����d�d�dS)NrYr�rZ	Traceback)rr6r-r"r0r!�ZeroDivisionErrorr&r�r\rsrKr,rIrrn)r:r/r��excr<r<r=�&test_queue_listener_with_StreamHandlers*z7QueueHandlerTest.test_queue_listener_with_StreamHandlercCsd|j�|j�|j�|j�tj�|j	|j�}|�
�|j�d�|��|�
|j����d�dS)Nrvzque -> ERROR: error)r%r4r3r&r8r0rr6r-r"r!rvrsrKr,rIr)r:r/r<r<r=�*test_queue_listener_with_multiple_handlerssz;QueueHandlerTest.test_queue_listener_with_multiple_handlersN)r]r^r_rHr>rEr*r,r>�
skipUnlessr?rr6r0r4r5r<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.r6r$r8r-r!rxrsr@r?)�	log_queuer?r�r�r/r<r<r=�
setup_and_log,s






zQueueListenerTest.setup_and_logr�cCsJt|j�D]$}t��}|�|d|��|f�q
|�|jd|jd�dS�N�%s_%sr�z&correct number of handled log messages)r�repeatr"r#r=r]rK�
call_count�r:Zmock_handler�r<r<r<r=�#test_handle_called_with_queue_queueDs�z5QueueListenerTest.test_handle_called_with_queue_queuecCsbt��t|j�D]4}t��}|�|d|��|f�|��|�	�q|�
|jd|jd�dSr>)r�*skip_if_broken_multiprocessing_synchronizerr@�multiprocessingr#r=r]r?rrrKrArBr<r<r=� test_handle_called_with_mp_queueLs
�z2QueueListenerTest.test_handle_called_with_mp_queueccs.z|��VqWntjy(gYS0dSr�)r(r"r')r<r<r<r=�get_all_from_queueYsz$QueueListenerTest.get_all_from_queuecCs�t��t|j�D]n}t��}|�|d|��|f�t|�	|��}|�
�|��gtj
jjgg}|�||ddd�|D��qdS)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.
            r?z&Found unexpected messages in queue: %scSs"g|]}t|tj�r|jn|�qSr<)rrr)r�)r�rzr<r<r=r�vs�zJQueueListenerTest.test_no_messages_in_queue_after_stop.<locals>.<listcomp>N)rrDrr@rEr#r=r]�listrGr?rrrr6r-�	_sentinelrO)r:r�r"r�rUr<r<r=�$test_no_messages_in_queue_after_stopas	���z6QueueListenerTest.test_no_messages_in_queue_after_stopcCsZt��}tj�|�}|��|��|�t��|�	�Wd�n1sL0YdSr�)
r"r#rr6r-r!rsr�r��	task_done)r:r<r/r<r<r=�test_calls_task_done_after_stopysz1QueueListenerTest.test_calls_task_done_after_stopN)r]r^r_r`r@�staticmethodr=r7r
rr6r-rCrFrGrJrLr<r<r<r=r8$s



r8c@s eZdZdd�ZeZdd�ZdS)�UTCcCstSr�)�ZERO�r:�dtr<r<r=�	utcoffset�sz
UTC.utcoffsetcCsdS)NrNr<rPr<r<r=�tzname�sz
UTC.tznameN)r]r^r_rR�dstrSr<r<r<r=rN�srNc@s^eZdZdd�Zddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�ZdS)�
FormatterTestc	Cs0dtjtj�ddd�dddddd�|_i|_dS)	Nzformatter.testr��toz	dummy.extr{zMessage with %d %s)r�Zplaceholders)r;rJ�pathname�linenor�funcr�r
)rr.r�r�r��common�variantsr[r<r<r=r>�s�
zFormatterTest.setUpNcCs,t|j�}|dur"|�|j|�t�|�Sr�)rrZrBr[rr�)r:r;�resultr<r<r=�
get_record�s
zFormatterTest.get_recordc
OsTz|j|g|�Ri|��Wn2|yN}z|�||j�WYd}~n
d}~00dSr�)r�rKrr)r:r�rrr
r�r�r<r<r=�assert_error_message�sz"FormatterTest.assert_error_messagecCs�|��}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�
r]rr1rKr�r�r�r��usesTimer9�r:r�r�r<r<r=�test_percent�s




zFormatterTest.test_percentcCs�|��}tjddd�}|�|�|�d�tjddd�}|�t|j|�tjddd�}|�|���tjddd�}|�	|���tjddd�}|�	|���tjd	dd�}|�	|���dS)
Nz
$%{message}%$�{�r��$%Message with 2 placeholders%$z{random}z	{message}�	{asctime}z{asctime!s:15}z{asctime:15}r`rbr<r<r=�test_braces�szFormatterTest.test_bracescCs|��}tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�|�|�d�tjddd�}|�t|j|�|�|���tjd	dd�}|�	|���tjd
dd�}|�	|���tjddd�}|�|���tjddd�}|�	|���dS)N�
${message}r�rezMessage with 2 placeholdersz$messagez$$%${message}%$$rfz	${random}z
${asctime}z$asctimez${asctime}--r`rbr<r<r=�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�|jtd0tjd2dd�|jttjd3dd�|jttjd4dd�|jttjd5dd�|jttjd6dd�|jttjd7dd�|jttjd8dd�|jttjd9dd�|jttjd:dd�|jttjd;dd�|jtd<tjd=dd�|jtd<tjd>dd�|jtd<tjd?dd�|jtd$tjddd�|jttjd%dd�|jtd$tjd@dd�|jttjdAdd�dS)BNzM%(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']}rdrez{process:.2f} - {custom.f:.4f}z{customfield!s:#<30}z{message!r}z{message!s}z{message!a}z{process!r:4.2}z8{process!s:<#30,.12f}- {custom:=+#30,.1d} - {module:^30}z{process!s:{w},.{p}}z{foo:12.{p}}z{foo:{w}.6}z{foo[0].bar[1].baz}z{foo[k1].bar[k2].baz}z{12[k1].bar[k2].baz}z${asctime} - $messager�z$bar $$z	$bar $$$$z%(asctime)Zz%(asctime)bz%(asctime)*z
%(asctime)*3sz%(asctime)_rgriz
%(foo)#12.3*fz%(foo)0*.8*fz+invalid field name/expression: 'name-thing'z{name-thing}zinvalid format: no fieldsr_zinvalid conversion: 'Z'z{asctime!s:#30,15f}z7invalid format: expected ':' after conversion specifierz{asctime!aa:15}zbad specifier: '.2ff'z{process:.2ff}z
{process:.2Z}z{process!s:<##30,12g}z{process!s:<#30#,12g}z{process!s:{{w}},{{p}}}z,invalid format: unmatched '{' in format specz{processzprocess}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 $.rLz	${asctime)rr1rK�_fmtr�r�r^�r:r�r<r<r=�test_format_validate�s�



������������z"FormatterTest.test_format_validatecCs|�ttjddd�dS)N�x)r�r�rr1r[r<r<r=�test_invalid_stylevsz 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)r]�datetime�utcr�mktime�
astimezone�	timetuple�created�msecsrr1�gmtime�	converterrK�
formatTimer��asctime)r:r�rQr�r<r<r=�	test_timeys

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)r]r^r_�default_msec_format�default_time_formatr<r<r<r=�NoMsecFormatter�sr�rprrqrrr�rrsz21/04/1993 08:03:00)rr1r]rurvrrwrxryrzr|r}rKr~)r:r�r�rQr�r<r<r=�test_default_msec_format_none�sz+FormatterTest.test_default_msec_format_none)N)
r]r^r_r>r]r^rcrhrjrmror�r�r<r<r<r=rU�s
rUc@seZdZdd�Zdd�ZdS)�TestBufferingFormattercCsdt|�S)Nz[(%d)�rL�r:�recordsr<r<r=�formatHeader�sz#TestBufferingFormatter.formatHeadercCsdt|�S)Nz(%d)]r�r�r<r<r=�formatFooter�sz#TestBufferingFormatter.formatFooterN)r]r^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�r[r<r<r=r>�s�zBufferingFormatterTest.setUpcCs2t��}|�d|�g��|�d|�|j��dS)NrZonetwo)r�BufferingFormatterrKr�r�rlr<r<r=�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)])r�rKr�r�rr1)r:r�Zlfr<r<r=�test_custom�s

z"BufferingFormatterTest.test_customN)r]r^r_r>r�r�r<r<r<r=r��sr�c@seZdZdd�ZdS)�
ExceptionTestcCs�|j}t�}|�|�ztd��Wntjddd�Yn0|�|�|��|jd}|�	|j
�d��|�	|j
�d��|�	|j
�d��|�	|j
�d	��dS)
NrAZfailedT��
stack_inforz#Traceback (most recent call last):
z!
RuntimeError: deliberate mistake�Stack (most recent call last):
z,logging.exception('failed', stack_info=True))r'�RecordingHandlerr8rBrr�r@r?r�r9�exc_textryr�r�)r:r�rDr<r<r=r,�s


zExceptionTest.test_formattingN)r]r^r_r,r<r<r<r=r��sr�c@seZdZdd�ZdS)�LastResortTestc	Cs�|j}|�|j�tj}tj}�zZt���D}|�d�|�	|�
�d�|�d�|�	|�
�d�Wd�n1st0Ydt_t���.}|�d�d}|�	|�
�|�Wd�n1s�0Yt���*}|�d�|�	|�
�d�Wd�n1�s0Yd|j_
dt_t���*}|�d�|�	|�
�d�Wd�n1�sV0YW|�|j�|t_|t_n|�|j�|t_|t_0dS)NzThis should not appearrz
Final chance!zFinal chance!
z-No handlers could be found for logger "root"
F)r'r@r0r�
lastResortrLrrNryrKrIrwr�emittedNoHandlerWarningr8)r:r�Zold_lastresortZold_raise_exceptionsrPr�r<r<r=�test_last_resort�s:


.

.

0

2�zLastResortTest.test_last_resortN)r]r^r_r�r<r<r<r=r��sr�c@seZdZdd�Zdd�ZdS)�FakeHandlerc	Cs$dD]}t|||�|||��qdS)N)r-�flushr?r.)�setattr�record_call)r:�
identifier�calledrr<r<r=r(�szFakeHandler.__init__cs���fdd�}|S)Ncs��d�����dS)Nz{} - {})r�r�r<�r�r��method_namer<r=�inner�sz&FakeHandler.record_call.<locals>.innerr<)r:r�r�r�r�r<r�r=r��szFakeHandler.record_callN)r]r^r_r(r�r<r<r<r=r��sr�cs$eZdZ�fdd�Zdd�Z�ZS)r�cs tt|�j|i|��g|_dSr�)r'r�r(r�)r:r
r�r+r<r=r(�szRecordingHandler.__init__cCs|j�|�dS)z&Keep track of all the emitted records.N)r�r�r�r<r<r=r��szRecordingHandler.handle)r]r^r_r(r�r0r<r<r+r=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)NrL)r'r�r>r�rrLr�r�)r:Zraise_exceptionsr+r<r=r>szShutdownTest.setUpcs�fdd�}|S)Ncs
���dSr�r<r<�rvr<r=r�sz'ShutdownTest.raise_error.<locals>.innerr<)r:rvr�r<r�r=�raise_error
szShutdownTest.raise_errorcCsbtd|j�}td|j�}td|j�}ttjj|||g�}tjt|�d�gd�}|�||j�dS)NrrYr���handlerList)z2 - acquirez	2 - flushz	2 - closez2 - releasez1 - acquirez	1 - flushz	1 - closez1 - releasez0 - acquirez	0 - flushz	0 - close�0 - release)	r�r�rYrr^r_rvrHrK)r:Zhandler0Zhandler1Zhandler2r6rUr<r<r=�test_no_failureszShutdownTest.test_no_failurecCsRtd|j�}t|||�|��tj�|�g}tjt|�d�|�	d|jd�dS)Nrr�r�r�)
r�r�r�r�rr^r_rvrHrK)r:rrvr�r6r<r<r=�_test_with_failure_in_method"s
z)ShutdownTest._test_with_failure_in_methodcCs|�dt�dS�Nr-�r�r�r[r<r<r=�test_with_ioerror_in_acquire+sz)ShutdownTest.test_with_ioerror_in_acquirecCs|�dt�dS�Nr�r�r[r<r<r=�test_with_ioerror_in_flush.sz'ShutdownTest.test_with_ioerror_in_flushcCs|�dt�dS�Nr?r�r[r<r<r=�test_with_ioerror_in_close1sz'ShutdownTest.test_with_ioerror_in_closecCs|�dt�dSr��r�r�r[r<r<r=�test_with_valueerror_in_acquire4sz,ShutdownTest.test_with_valueerror_in_acquirecCs|�dt�dSr�r�r[r<r<r=�test_with_valueerror_in_flush7sz*ShutdownTest.test_with_valueerror_in_flushcCs|�dt�dSr�r�r[r<r<r=�test_with_valueerror_in_close:sz*ShutdownTest.test_with_valueerror_in_closecCsdt_|�dt�dS)NFr-�rrLr��
IndexErrorr[r<r<r=�.test_with_other_error_in_acquire_without_raise=sz;ShutdownTest.test_with_other_error_in_acquire_without_raisecCsdt_|�dt�dS)NFr�r�r[r<r<r=�,test_with_other_error_in_flush_without_raiseAsz9ShutdownTest.test_with_other_error_in_flush_without_raisecCsdt_|�dt�dS)NFr?r�r[r<r<r=�,test_with_other_error_in_close_without_raiseEsz9ShutdownTest.test_with_other_error_in_close_without_raisecCsdt_|�t|jdt�dS)NTr-�rrLr�r�r�r[r<r<r=�+test_with_other_error_in_acquire_with_raiseIs
�z8ShutdownTest.test_with_other_error_in_acquire_with_raisecCsdt_|�t|jdt�dS)NTr�r�r[r<r<r=�)test_with_other_error_in_flush_with_raiseNs
�z6ShutdownTest.test_with_other_error_in_flush_with_raisecCsdt_|�t|jdt�dS)NTr?r�r[r<r<r=�)test_with_other_error_in_close_with_raiseSs
�z6ShutdownTest.test_with_other_error_in_close_with_raise)r]r^r_r`r>r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r0r<r<r+r=r�s"	r�c@sreZdZdZdd�Zddd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�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�SZ
doesnotexistsc@seZdZdS)z;ModuleLevelMiscTest.test_disable.<locals>._NotAnIntOrStringNr�r<r<r<r=�_NotAnIntOrStringhsr��WARN)
rr�rrCrKr�r�r�r	re)r:�old_disabler�r<r<r=�test_disable]s


z ModuleLevelMiscTest.test_disableNcs�g�t�|td�fdd��t�}tj�|�tt|�}|durN||d|�n
|d|�|�t|j	�d�|j	d}|�|�
�d|�|dur�|ntt|���}|�|j|�|��g�dS)N�basicConfigcs��||f�Sr�r)r�kw�r�r<r=�<lambda>wr�z/ModuleLevelMiscTest._test_log.<locals>.<lambda>ztest me: %rrYr)
rr7rr�r�r8r#rKrLr��
getMessage�upperr�)r:rrJ�	recording�
log_methodr�Zexpected_levelr<r�r=�	_test_logts 

�


zModuleLevelMiscTest._test_logcCs|�dtj�dS�Nru)r�rrgr[r<r<r=�test_log�szModuleLevelMiscTest.test_logcCs|�d�dS�Nry�r�r[r<r<r=�
test_debug�szModuleLevelMiscTest.test_debugcCs|�d�dS�Nrxr�r[r<r<r=�	test_info�szModuleLevelMiscTest.test_infocCs|�d�dS�Nrwr�r[r<r<r=�test_warning�sz ModuleLevelMiscTest.test_warningcCs|�d�dS�Nrvr�r[r<r<r=�
test_error�szModuleLevelMiscTest.test_errorcCs|�d�dS�Nr�r�r[r<r<r=�
test_critical�sz!ModuleLevelMiscTest.test_criticalcCs^|�ttjt�Gdd�dtj�}t�|�|�t��|�t�tj�|�t��tj�dS)Nc@seZdZdS)z;ModuleLevelMiscTest.test_set_logger_class.<locals>.MyLoggerNr�r<r<r<r=r�sr)r�r	rr
r
rrK�getLoggerClass)r:rr<r<r=�test_set_logger_class�s
z)ModuleLevelMiscTest.test_set_logger_classc	sg�G�fdd�dt���}t�|�t�d�}|��dg�t��}t�|�}|�|�z�|�	tj
�|�d�|�|���
�d�|�d�|�d�|�	tj�|�d�|�|��d�W|�|�|��t�tj�n |�|�|��t�tj�0dS)Ncs&eZdZdejf��fdd�	Z�ZS)z@ModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLoggerrcst��||���d�dS)N�initialized)r'r(r�)r:r;rJ)r,rrr<r=r(�szIModuleLevelMiscTest.test_subclass_logger_cache.<locals>.MyLogger.__init__)r]r^r_rr�r(r0r<�rrr+r=r�srZjust_some_loggerr�Zhellorr)rr�r
rrKr*r+r/r8r-r.ryrIr�truncater�rmr@r?r)r:rr�r,rDr<r�r=�test_subclass_logger_cache�s.








�
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()�-czexception in __del__zValueError: some error)rrWrO�r:�code�rc�out�errr<r<r=�test_logging_at_shutdown�s
z,ModuleLevelMiscTest.test_logging_at_shutdowncCs8d}td|�\}}}|��}|�d|�|�|d�dS)Nz�if 1:
            import logging

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

            rec()r�z#Cannot recover from stack overflow.rY)rrWZassertNotInrKr�r<r<r=�test_recursion_error�s
z(ModuleLevelMiscTest.test_recursion_error)N)r]r^r_r`r�r�r�r�r�r�r�r�r�r�r�r�r<r<r<r=r�Ys
r�c@s,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�
LogRecordTestcCs6t�i�}t|�}|�|�d��|�|�d��dS)Nz<LogRecord: �>)rr�r�r9ryr�)r:r�rWr<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�rrr8rwrMr�r
rKrrr@r?)r:rDr�rZr<r<r=�
test_dict_arg�s

zLogRecordTest.test_dict_argcCsZt�i�}|�|jd�z*ddl}t�i�}|�|j|��j�WntyTYn0dS)N�MainProcessr)rr�rK�processNamerE�current_processr;rS)r:r��mpr<r<r=�test_multiprocessing�s

z"LogRecordTest.test_multiprocessingcCs�t�i�}|j}||j�||j�||j�||j�tj}tj}tj	}z`dt_dt_dt_	t�i�}|j
}||j�||j�||j�||j�W|t_|t_|t_	n|t_|t_|t_	0dS)NF)rr��assertIsNotNoner��
threadName�processr��
logThreads�logProcesses�logMultiprocessingrS)r:r�ZNOT_NONEZlog_threadsZ
log_processesZlog_multiprocessing�NONEr<r<r=�
test_optionals2








�zLogRecordTest.test_optionalN)r]r^r_r�r�r�r�r<r<r<r=r��s
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'r�r>rr�r6rrrrrrJr)r�r�r[r+r<r=r>$s

zBasicConfigTest.setUpcs<tjjdd�D]}tj�|�|��qtt|���dSr�)rr�r6r@r?r'r�rEr�r+r<r=rE-s
zBasicConfigTest.tearDowncCsJttjd|j�tj��tj�|j�|jtj	dd�<tj�
|j�dS)Nr6)r�rr�r6rrArBrrrr-r)r[r<r<r=r�3s

zBasicConfigTest.cleanupcCs�t��|�ttjj�d�tjjd}|�|tj�|�|jt	j
�|j}|�|jj
tj�|�|j�|�|jtj�|�tjj|j�dS)NrYr)rr�rKrLr�r6r�r/r,r�rPr�r�rk�BASIC_FORMATrSr	�PercentStylerJr))r:r�r�r<r<r=�test_no_kwargs:szBasicConfigTest.test_no_kwargscCsft���J}tjtjdd�t�d�tj�d�|�|�	��
�d�Wd�n1sX0YdS)Nrd�r,r��Log an errorr�ERROR:root:Log an error�rr�rr�r�r�rvr�rKrIrr�r<r<r=�test_strformatstyleNs

�z#BasicConfigTest.test_strformatstylecCsft���J}tjtjdd�t�d�tj�d�|�|�	��
�d�Wd�n1sX0YdS)Nr�r�r�rr�rr�r<r<r=�test_stringtemplatestyleVs

�z(BasicConfigTest.test_stringtemplatestylecCs�dd�}tjdd�|�ttjj�d�tjjd}|�|tj�t�dd�}|�|jj	|jj	�|�|jj
|jj
�|�|||d�dS)NcSs|��|��t�|�dSr�r��r�Zh2rr<r<r=r�`sz.BasicConfigTest.test_filename.<locals>.cleanup�test.log)r�rYrr)rr�rKrLr�r6r�r	r,�moder;r��r:r�r�rUr<r<r=�
test_filename^szBasicConfigTest.test_filenamecCsVdd�}tjddd�tjjd}t�dd�}|�|jj|jj�|�|||d�dS)NcSs|��|��t�|�dSr�r�rr<r<r=r�rsz.BasicConfigTest.test_filemode.<locals>.cleanupr�wb�r��filemoder)	rr�r�r6r	rKr,rr�rr<r<r=�
test_filemodepszBasicConfigTest.test_filemodecCs`t��}|�|j�tj|d�|�ttjj	�d�tjj	d}|�
|tj�|�|j|�dS)Nr&rYr)
r*r+r�r?rr�rKrLr�r6r�r/r,)r:r,r�r<r<r=�test_stream~szBasicConfigTest.test_streamcCs.tjdd�tjjdj}|�|jjd�dS)Nz%(asctime)s - %(message)s)r�r)rr�r�r6r�rKr�rk�r:r�r<r<r=�test_format�szBasicConfigTest.test_formatcCs,tjdd�tjjdj}|�|jd�dS)NrM)r	r)rr�r�r6r�rKr	r
r<r<r=�test_datefmt�szBasicConfigTest.test_datefmtcCs.tjdd�tjjdj}|�|jtj�dS)Nr�rer)rr�r�r6r�r�r�r�r
r<r<r=�
test_style�szBasicConfigTest.test_stylecCsTtjj}|�tjj|�tjdd�|�tjjd�tjdd�|�tjjd�dS)N�9)rJ�:)rr�rJr�r-r�rK)r:�	old_levelr<r<r=�
test_level�szBasicConfigTest.test_levelcCsp|j}t��g}tj}|ttjd|d�|ttjd|d�|ttj||d�|ttjtjd�tjddd�dS)Nr)r�r,)r�r6)r,r6)Zloglevelrr	)r�rr/r�rPr�r�rm)r:r�r6r,r<r<r=�test_incompatible�s

�
�
�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�)r6rrY)rr/r�r�r1r4r�rMr�r6r�r�)r:r6r�r<r<r=�
test_handlers�s
�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)
Nr�r�rxryrYT)rJr6�forcezWARNING:root:warnz WARNING:root:warn
INFO:root:info)r*r+rr/r�rkrwrxryrKrLr�r6rmrIr)r:Z
old_string_ioZ
new_string_ioZold_handlersZnew_handlersr<r<r=�
test_force�s,



�


��zBasicConfigTest.test_forcecCsz�d}tjd|ddtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�t�
d�W|��tddd	��}|�
���}Wd�n1s�0Yt�d�|�|d�nX|��tddd	��}|�
���}Wd�n1s�0Yt�d�|�|d�0dS)
NrPrrn�%(message)s�r�ri�errorsr�rJrYr�.The Øresund Bridge joins Copenhagen to Malmörh�rr�r.rKrLr�r6r�r	riryr?r)rRrr�r��r:rir�r�rDr<r<r=�
test_encoding�s2�*
��*
�zBasicConfigTest.test_encodingcCsz�d}tjd|ddtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�t�
d�W|��tdd	d
��}|�
���}Wd�n1s�0Yt�d�|�|d�nX|��tdd	d
��}|�
���}Wd�n1s�0Yt�d�|�|d�0dS)Nrr�ignorerrrYrrrPrhz*The resund Bridge joins Copenhagen to Malmrrr<r<r=�test_encoding_errors�s*�*
�*
z$BasicConfigTest.test_encoding_errorscCs$z�d}tjd|dtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�|�|j
d�t�d�W|��t
dd	d
��}|����}Wd�n1s�0Yt�d�|�|d�nX|��t
dd	d
��}|����}Wd�n1s�0Yt�d�|�|d�0dS)Nrrr)r�rir�rJrYr�backslashreplaceu<😂: ☃️: The Øresund Bridge joins Copenhagen to MalmörPrhzL\U0001f602: \u2603\ufe0f: The \xd8resund Bridge joins Copenhagen to Malm\xf6)rr�r.rKrLr�r6r�r	rirryr?r)rRrr�r�rr<r<r=�test_encoding_errors_defaults*�*
�*
z,BasicConfigTest.test_encoding_errors_defaultcsVz�d}tjd|ddtjd�|�ttjj�d�tjjd}|�|tj�|�|j	|�|�
|j�g��fdd�}||_t�
d	�|���|�d
�d�W|��tddd��}|����}Wd�n1s�0Yt�d�|�|d
�nZ|��tddd��}|����}Wd�n1�s00Yt�d�|�|d
�0dS)NrrrrrYrcs t��\}}}��t|��dSr�)r�rr�r�)r�rr�r�r<r=�dummy_handle_error$szEBasicConfigTest.test_encoding_errors_none.<locals>.dummy_handle_errorrz:'ascii' codec can't encode character '\xd8' in position 4:rPrhr)rr�r.rKrLr�r6r�r	rirSrrHryr9rOr?r)rRrr�r�)r:rir�r$r�rDr<r�r=�test_encoding_errors_nones:�

�*
�,
z)BasicConfigTest.test_encoding_errors_noneNcsfg�tj����fdd�}t��td|�tt|�}|durH||d�n|d����difg�dS)Ncs<��tjj}tj�d���tjj|���||f�dS)N�d)rr�rJr-r�r�)rr�r�r�Zold_basic_configr:r<r=�my_basic_config;s
z2BasicConfigTest._test_log.<locals>.my_basic_configr�ztest mer<)rr�rr7r#rK)r:rrJr(r�r<r'r=r�6s
zBasicConfigTest._test_logcCs|�dtj�dSr�)r�rrkr[r<r<r=r�MszBasicConfigTest.test_logcCs|�d�dSr�r�r[r<r<r=r�PszBasicConfigTest.test_debugcCs|�d�dSr�r�r[r<r<r=r�SszBasicConfigTest.test_infocCs|�d�dSr�r�r[r<r<r=r�VszBasicConfigTest.test_warningcCs|�d�dSr�r�r[r<r<r=r�YszBasicConfigTest.test_errorcCs|�d�dSr�r�r[r<r<r=r�\szBasicConfigTest.test_critical)N) r]r^r_r`r>rEr�r�rrrrrrrrrrrrrr!r#r%r�r�r�r�r�r�r�r0r<r<r+r=r� s8	

"
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�<dSr�)rrr<�Zold_handler_listr<r=r�ksz(LoggerAdapterTest.setUp.<locals>.cleanup�r�r)r'r)r>rrr�r�r�r�r8r�r@r?rvrt�adapter)r:r�r+r*r=r>as
zLoggerAdapterTest.setUpc
Cs�d}d}zddWn8tyL}z |}|j�||j�WYd}~n
d}~00|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dS�Nztesting exception: %rrYr)r2r,r�r�rKrLr�r�rrgr�r
rr,�
__traceback__�r:r�r3r�r�r<r<r=�test_exceptionrs&�z LoggerAdapterTest.test_exceptionc
Cs�zddWn(ty4}z|}WYd}~n
d}~00|jjd|d�|�t|jj�d�|jjd}|�|j|j||j	f�dS)NrYrz
exc_info testr1)
r2r,r�rKrLr�r�rr,r.)r:r�r3r�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! %rrYr)r,r�r�rKrLr�r�rrer�r
)r:r�r�r<r<r=r��szLoggerAdapterTest.test_criticalcCsD|jjjj}d|jjj_|�t|jjjd|�|�|j�d��dS)N�!rC� )r,r�rrCr�r�r��isEnabledFor�r:r�r<r<r=�test_is_enabled_for�s�z%LoggerAdapterTest.test_is_enabled_forcCsN|�|j���|jjD]}|j�|�q|�|j���|�|j���dSr�)r9r,r5r�r6r@r�r�r<r<r=�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||_0|�|j|�|�|j|�|�|jj|�dS)	Nc@seZdZdZdd�ZdS)z.LoggerAdapterTest.test_nested.<locals>.Adapter�AdaptercSs|j�d|��|fSr��r�)r:r�r�r<r<r=r��sz6LoggerAdapterTest.test_nested.<locals>.Adapter.processN)r]r^r_r�r�r<r<r<r=r8�sr8zAdapters can be nested, yo.r+ZAdapterAdapterrYrzAdapter AdapterAdapter )rrtr�r�rKrVrurer�rLr�r�r�r
rrMr
)r:r8r�r,Zadapter_adapterr�Zorig_managerZtemp_managerr<r<r=�test_nested�s2zLoggerAdapterTest.test_nested)r]r^r_r>r0r1r�r6r7r:r0r<r<r+r=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�Zdd �Zd!d"�Z�ZS)#�
LoggerTestcsbtt|���t�|_tjdd�|_|j�|j�|�	|jj
|j�|�	|jj�|�	tj�dS)NZblah�r;)
r'r;r>r�r�rrr�r8r�r@r?rvr[r+r<r=r>�szLoggerTest.setUpcCs|�t|jjt��dSr�)r�r	r�r-r
r[r<r<r=�test_set_invalid_level�sz!LoggerTest.test_set_invalid_levelc
Cs�d}d}zddWn8tyL}z |}|j�||j�WYd}~n
d}~00|�t|jj�d�|jjd}|�|jtj	�|�|j
|�|�|j|jf�|�|j|j
||jf�dSr-)r2r�r�r�rKrLr�r�rrgr�r
rr,r.r/r<r<r=r0�s&�zLoggerTest.test_exceptioncCsFt�tdd��$|�t|jjdd�Wd�n1s80YdS)NrLTrr�test message)r�	swap_attrrr�r	r�rur[r<r<r=�!test_log_invalid_level_with_raise�sz,LoggerTest.test_log_invalid_level_with_raisecCs@t�tdd��|j�dd�Wd�n1s20YdS)NrLFrrr>)rr?rr�rur[r<r<r=�test_log_invalid_level_no_raise�sz*LoggerTest.test_log_invalid_level_no_raisecsPg�t�|tjd�fdd��|jjdd�|�t��d�|�d�d�dS)	N�print_stackcs��|���Sr�)r�rI)r�r�r�r<r=r��r�z=LoggerTest.test_find_caller_with_stack_info.<locals>.<lambda>Tr�rYr�r)rr7r�	tracebackr��
findCallerrKrLr[r<r�r=� 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)
NrYcs�jjd�d�dS)Nrg)�
stacklevel)r�rwr<)r:�	the_levelr<r=�	innermostsz>LoggerTest.test_find_caller_with_stacklevel.<locals>.innermostcs
��dSr�r<r<)rHr<r=r�sz:LoggerTest.test_find_caller_with_stacklevel.<locals>.innercs
��dSr�r<r<)r�r<r=�outersz:LoggerTest.test_find_caller_with_stacklevel.<locals>.outerr�rHr�rI� test_find_caller_with_stacklevel)r�r�rKrQrXr9)r:rIr�rXr<)r�rHr:rGr=rJ�s,


z+LoggerTest.test_find_caller_with_stacklevelc
Cs�d}d}d}}}}}}}	t�|||||||||	�	}
dt|
j���D]0}|di}|jt|jj|||||||||	d�qPdS)N�	my record�
)rrr�
some value�r�sinfo)	r�_logRecordFactoryrP�__dict__�keysr�r�r��
makeRecord)
r:r;rJr�lnor�r
rrYrO�rvr`rr<r<r=�%test_make_record_with_extra_overwrites�
�z0LoggerTest.test_make_record_with_extra_overwritecCs\d}d}d}}}}}}}	ddi}
|jj||||||||
|	d�	}|�d|j�dS)NrKrLZ	valid_keyrMrN)r�rSrOrQ)r:r;rJrrTr�r
rrYrOrr\r<r<r=�(test_make_record_with_extra_no_overwrite)s�z3LoggerTest.test_make_record_with_extra_no_overwritecCs>|�|j���|jjD]}|j�|�q|�|j���dSr�)r9r�r5r6r@r�r�r<r<r=r72szLoggerTest.test_has_handlerscCs"t�d�}d|_|�|���dS)Nz
blah.childF)rrr�r�r5)r:Zchild_loggerr<r<r=�test_has_handlers_no_propagate9s
z)LoggerTest.test_has_handlers_no_propagatecCs>|jjj}d|jj_|�t|jjd|�|�|j�d��dS)N�rC�)r�rrCr�r�r�r4r5r<r<r=r6>s

zLoggerTest.test_is_enabled_forcCs`|jj}|jjj}d|j_d|jj_|�t|jd|�|�t|jjd|�|�|j�d��dS)NTrqrrCrZ)r�rrrCr�r�r�r4)r:Zold_disabledr�r<r<r=�#test_is_enabled_for_disabled_loggerDs

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)Nrr�rL�foo.bar�)rrrMr��parentZassertIsNot)r:r�r<r<r=�test_root_logger_aliasesPsz#LoggerTest.test_root_logger_aliasescCs$|�ttjt�|�ttjd�dS)Nsfoo)r�r	rr�anyr[r<r<r=�test_invalid_names]szLoggerTest.test_invalid_namescCsNttjd�D]:}dD]0}t�|�}t�||�}t�|�}|�||�qqdS)NrY)rr�rLr\zbaz.bar)rr&�HIGHEST_PROTOCOLrrr�r'rM)r:�protor;r�rWZ	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)NrrTF)r'rrr-rgrKr(�_cacher9r4r�r.rer�rC)r:r�r%r&r<r<r=�test_cachingisH

zLoggerTest.test_caching)r]r^r_r>r=r0r@rArErJrVrWr7rXr6r[r_rardrfr0r<r<r+r=r;�s"	

	
r;c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�BaseFileTestz1Base class for handler tests that write log filescCs0t�|�t�dd�\}|_t�|�g|_dS)Nrztest_logging-2-)rr>r�r�rr�r?�rmfiles)r:rr<r<r=r>�s

zBaseFileTest.setUpcCs>|jD]}t�|�qtj�|j�r0t�|j�t�|�dSr�)rhr�r�r�r�rrrE)r:rr<r<r=rE�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)r9r�r�r�rhr�)r:r�r<r<r=�
assertLogFile�s�zBaseFileTest.assertLogFileN)r]r^r_r`r>rErjr<r<r<r=rg�srgc@seZdZdd�ZdS)�FileHandlerTestcCsxt�|j�tj|jdd�}|�|j�|�tj�	|j��|�
t�i��|�|j�|�
tj�	|j��|��dS)NTr�)r�r�rrr	rSr,r�r�r�r�r�r�r9r?)r:�fhr<r<r=�
test_delay�szFileHandlerTest.test_delayN)r]r^r_rmr<r<r<r=rk�srkc@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	�
�d
d��ZdS)�RotatingFileHandlerTestc
Cst�dtjdd|��ddd�S)Nr�r�rY)rr)r.r\r[r<r<r=�next_rec�s�z RotatingFileHandlerTest.next_reccCs^tjj|jdd�}|�|�d��|��tjjtjddd�}|�|�|�	���|��dS)Nr��maxBytesrPrY)rirq)
rr6r
rr��shouldRolloverr?r��devnullro�r:�rhr<r<r=�test_should_not_rollover�s�z0RotatingFileHandlerTest.test_should_not_rollovercCs2tjj|jdd�}|�|�|����|��dS)NrYrp)rr6r
rr9rrror?rtr<r<r=�test_should_rollover�sz,RotatingFileHandlerTest.test_should_rollovercCs4tj�|j�}|�|���|�|j�|��dSr�)rr6r
rr�rorjr?rtr<r<r=�test_file_created�sz)RotatingFileHandlerTest.test_file_createdcCs�dd�}tjj|jddd�}||_|�|���|�|j�|�|���|�||jd��|�|���|�||jd��|�t	j
�||jd���|��dS)	NcSs|dS�N�.testr<r<r<r<r=�namer�sz>RotatingFileHandlerTest.test_rollover_filenames.<locals>.namerr�rY��backupCountrq�.1�.2�.3)
rr6r
rr{r�rorjr�r�r�r�r?)r:r{rur<r<r=�test_rollover_filenames�s�z/RotatingFileHandlerTest.test_rollover_filenamescCs�Gdd�dtjj�}||jddd�}|�|�|j�|jd�|�|���|�|j�|�|���|�|�|jd�d�|�	t
j�|�|jd���|�
�dS)	Nc@seZdZdd�Zdd�ZdS)zZRotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotatorcSs|dSryr<)r:r;r<r<r=r{�sz`RotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotator.namercSs tj�|�rt�||d�dS)N�.rotated)r�r�r�r�)r:�source�destr<r<r=�rotator�szbRotatingFileHandlerTest.test_namer_rotator_inheritance.<locals>.HandlerWithNamerAndRotator.rotatorN)r]r^r_r{r�r<r<r<r=�HandlerWithNamerAndRotator�sr�r�rYr|rzr~r�)rr6r
rrKr{r�rorjr�r�r�r�r?)r:r�rur<r<r=�test_namer_rotator_inheritance�s�z6RotatingFileHandlerTest.test_namer_rotator_inheritancecCs�dd�}dd�}tjj|jddd�}||_||_|��}|�|�|�|j�|��}|�|�||jd�}|�|�t	j
}t|d	��:}|��}	t
�|	�}
|�|
�d
�|j|�Wd�n1s�0Y|�|���||jd�}|�|�t|d	��:}|��}	t
�|	�}
|�|
�d
�|j|�Wd�n1�sD0Y|�|���||jd�}t|d	��:}|��}	t
�|	�}
|�|
�d
�|j|�Wd�n1�s�0Y|�t	j�||jd���|��dS)
NcSs|dS)Nz.gzr<r<r<r<r=r{sz3RotatingFileHandlerTest.test_rotator.<locals>.namerc	Ss�t|d��X}|��}t�|d�}t|d��}|�|�Wd�n1sJ0YWd�n1sh0Yt�|�dS)N�rbr�r)r)rR�zlib�compressrEr�r�)r�r�ZsfrD�
compressed�dfr<r<r=r�
sFz5RotatingFileHandlerTest.test_rotator.<locals>.rotatorr�rYr|r~r�rrr�)rr6r
rr�r{ror�rjr��linesepr)rRr��
decompressrKrWr�r�r�r�r?)r:r{r�ruZm1Zm2r�newliner�r�rDr<r<r=�test_rotatorsD�



6

8
8z$RotatingFileHandlerTest.test_rotatorN)r]r^r_rorvrwrxr�r�rZ
requires_zlibr�r<r<r<r=rn�s
rnc@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�TimedRotatingFileHandlerTestcCsJtjjtjdddd�}t�d�t�ddi�}|�|�	|��|�
�dS)N�SrPrY)rir}皙�����?r�ztesting - device file)rr6rr�rsrrr�r�rrr?)r:rlr�r<r<r=rv3s
�
z5TimedRotatingFileHandlerTest.test_should_not_rolloverc	s�tjj|jddd�}t�d�}|�|�t�ddi�}|�|�|�|j�t	�
d�t�ddi�}|�|�|��d	}tj�
�}d
}t|�D]D}|tj|d�}	|j|	�d��tj���}|r�|j���q�q�d
|}
|�s�tj�|j�\}��fdd�t�|�D�}td|�d�tjd�td|tjd�|D]X}
td|
�tj�||
�}t|d��}t|���Wd�n1�s�0Y�q<|j||
d�dS)Nr�rY)r}rtr�ztesting - initialr�ztesting - after delayFi,�Zsecondsz.%Y-%m-%d_%H-%M-%Sz,No rotated files found, went back %d secondscsg|]}|���r|�qSr<)ry)r�r��rr<r=r�]r�z>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�ri)rr6rrr1r4r�r�rjrrr?rur1r�	timedelta�strftimer�r�r�rhr�r��listdirr#r�rPr�r)rRr9)r:rlr�Zr1Zr2�foundr1�GO_BACK�secs�prevr�Zdn�filesr�r�Ztfr<r�r=�
test_rollover=sD�





0z*TimedRotatingFileHandlerTest.test_rollovercCsR|j}|ttjj|jddd�|ttjj|jddd�|ttjj|jddd�dS)N�XTr��WZW7)r�r�rr6rr)r:r�r<r<r=�test_invalidgs
�
�
�z)TimedRotatingFileHandlerTest.test_invalidcCs�d}t�ddd�}tjj|jdddd|d�}zD|�|�}|�||d�|�|d�}|�||d	�W|��n
|��0dS)
Nr��MIDNIGHTrYT��when�intervalr}rv�atTime��жi@�)	rurrr6rr�computeRolloverrKr?)r:�currentTimer�rurTr<r<r=�"test_compute_rollover_daily_attimeps�
z?TimedRotatingFileHandlerTest.test_compute_rollover_daily_attimec		Cs:tt���}||d}t�ddd�}t�|�j}td�D]�}tjj|j	d|ddd|d�}z�||krtd||}n||}|d9}|d	7}||7}|�
|�}||kr�td
tj�tdt
��|�||�||kr�|d7}|�
|d
�}||k�rtd
tj�tdt
��|�||�W|��q:|��0q:dS)N�Qr�r�zW%drYTr�r�zfailed in timezone: %dzlocal vars: %si�:	r�)rHrrur|�tm_wdayrrr6rrr�r#�timezone�localsrKr?)	r:r�Ztodayr�ZwdayZdayrurUrTr<r<r=�#test_compute_rollover_weekly_attime�s:�

z@TimedRotatingFileHandlerTest.test_compute_rollover_weekly_attimec	Cstjdd�}|�tj|�g}tj��}td�D]$}|�|�	d��|tj
dd�7}q0d}g}g}|D]�}tj�
|d|�}	tjj|	d	dd
dd�}
|�|
�|�d
�r�|D]}|�d||f�q�qfdd�|
_|D]}|�d||f�q�qf|D]>}tj�
||�}	t|	d��}
Wd�q�1�s$0Yq�t|�D]�\}}||}
|
��}|�t|�d�|�d
��r�d|}	|D]&}tj�|�\}}|�|�|	���qxnV|D]P}tj�|�\}}|�|�d��|�|�|d��o�|t|�d����q��q8dS)Nrr9r�z%Y-%m-%d_%H-%M-%Sr�r�)�a.bza.b.czd.ezd.e.fz%s.logrWr�T)r�r�r}r�r�z	%s.log.%scSs|�dd�dS)Nrr)r�r<r<r<r=r��r�zKTimedRotatingFileHandlerTest.test_compute_files_to_delete.<locals>.<lambda>z	%s.%s.logrr�z%s.log.rr�r�)r��mkdtempr��shutil�rmtreerur1rr�r�r�r�r�r�rr6rryr{r)�	enumerateZgetFilesToDeleterKrLr�r9r��isdigit)r:Zwd�timesrQr��prefixesr�Zrotatorsr�r�r�rmrr�Z
candidatesr�rZr<r<r=�test_compute_files_to_delete�sV

�


"�z9TimedRotatingFileHandlerTest.test_compute_files_to_deleteN)	r]r^r_rvr�r�r�r�r�r<r<r<r=r�2s
*	(r�cKstjfi|��tjdd�S)NrYr�)rur�)r�r<r<r=r��sr�)r�rY)�M�<)�Hi)�Dr�)r�r�ZW0r�)ZdaysZhoursc

CsZtjj|j|dddd�}d}|�|�}||k�rB|dk�rBz�|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�Wn8t
�y@}zt
d|tjd�WYd}~n
d}~00|�||�|��dS)NrYrT)r�r�r}rvgr�r�rr�r�z
t: %s (%s)r�zcurrentHour: %szcurrentMinute: %szcurrentSecond: %szr: %sz
result: %sz exception in diagnostic code: %s)rr6rrr�rvrr|�	localtimeZ	_MIDNIGHTr#r�rPr"rKr?)
r:r��exprur�rTrmZcurrentHourZ
currentMinuteZ
currentSecondr�r\r�r<r<r=�test_compute_rollover�s@�



���(r�ztest_compute_rollover_%sz>win32evtlog/win32evtlogutil/pywintypes required for this test.c@seZdZdd�ZdS)�NTEventLogHandlerTestc
Cs
d}t�d|�}t�|�}ztj�d�}Wn<tjyf}z"|jdkrPt	�
d���WYd}~n
d}~00t�ddi�}|�|�|�
�|�|t�|��tjtjB}d}d}	t�|||	�}
|
D].}|jdkr�q�t�||�}|d	kr�q�d
}q�q�d|	}|j||d�dS)
NZApplicationZtest_loggingr�z#Insufficient privileges to run testr�zTest Log MessageFr&zTest Log Message
Tz3Record not found in event log, went back %d recordsri)�win32evtlogZOpenEventLogZGetNumberOfEventLogRecordsrr6ZNTEventLogHandler�
pywintypesrv�winerrorr>ZSkipTestr�r�r?Z
assertLessZEVENTLOG_BACKWARDS_READZEVENTLOG_SEQUENTIAL_READZReadEventLogZ
SourceName�win32evtlogutilZSafeFormatMessager9)r:ZlogtypeZelhZnum_recsrDr�r��flagsr�r��eventsr�r<r<r=r�
s:



�
z NTEventLogHandlerTest.test_basicN)r]r^r_r�r<r<r<r=r�sr�c@seZdZdd�ZdS)�MiscTestCasecCshd�}tj|t|d�dS)N>
�Filterer�PlaceHolder�
RootLoggerr�rr��StrFormatStyler��currentframerr�r�r�)�	blacklist)rZcheck__all__r)r:r�r<r<r=�test__all__-szMiscTestCase.test__all__N)r]r^r_r�r<r<r<r=r�,sr�cCs*t�dd�}|��t�|jddd�dS)N�LC_ALLr)rZrun_with_locale�	__enter__r>ZaddModuleCleanup�__exit__)�cmr<r<r=�setUpModule9sr��__main__)N)�r`rZlogging.handlersZlogging.configror�rrurr&r*rbr�r�r"rrFr�r\r$r�r�Ztest.support.script_helperrrrgrZtest.supportrZtest.support.logging_helperrr�rrr>r|r^roZhttp.serverrrrZ�urllib.parser	r
�socketserverrrr
rr�r�r�rSr�ZTestCaserrar�ZSILENTr�ZTERSEZEFFUSIVEr�r�Z	TALKATIVEr�Z
CHATTERBOXZBORINGrr�r�r�r�r�r�r�r
r@r/rFrIrKr[rXrtrxr�r�r?r�r�r�r�r1r�r�rr3r6r4r5r:r<r@ZIPV6_ENABLEDrArDr[rfrur�r�r�r�r�rrr)rrr!r6rEZ
unittest.mockr7r8r�rOZtzinforNrvrUr�r�r�r�r�r�r�r�r�r�r�r�r)r;rgrkrnr�r�r�r�r�r�r�r�r�r]�mainr<r<r<r=�<module>sdmF�
YT,J2)/ hbY@C�M41(
W#i`
	'W5BlWn(�!
#



Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists