HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/tests/unit/__pycache__/test_handler.cpython-37.pyc
B

�P�e��	@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
mZmZmZddlmZmZdZGdd�de�Zejd	d
��Zdd�Zej�d
dd�d�dfdefddgdegfg�dd��Zdd�Zdd�Zdd�Z ejj!ej"ddkdd�dd��Z#ejj!ej"ddkd d�d!d"��Z$d#d$�Z%d%d&�Z&d'd(�Z'd)d*�Z(d+d,�Z)d-d.�Z*d/d0�Z+d1d2�Z,d3d4�Z-d5d6�Z.d7d8�Z/d9d:�Z0dS);z�pytests for the formatting and construction of GELF logs by the graypy
logging handlers

.. note::

    These tests mock sending to Graylog and do not require an active graylog
    instance to operate.
�N)�BaseGELFHandler�GELFHTTPHandler�GELFTLSHandler)�handler�logger�formatted_logger)�MOCK_LOG_RECORD�MOCK_LOG_RECORD_NAMEu�c@seZdZdd�ZdS)�	TestClasscCsdS)Nz<TestClass>�)�selfrr�H/opt/alt/python37/lib/python3.7/site-packages/tests/unit/test_handler.py�__repr__ szTestClass.__repr__N)�__name__�
__module__�__qualname__rrrrr
r
sr
ccs^y$tj�|d��}|VWdQRXWn4tk
rXtj�|d��}|VWdQRXYnXdS)N�send�emit)�mock�patch�object�	Exception)r�	mock_sendrrr
r$srcCs�|jgkst�|j\\\}}t|tj�rDt�tdd��|��	d��Syt�t
�|��	d��St
jk
r�yt�|�	d��St
k
r�t�|dd��	d��SXYnXdS)NF)�compresszutf-8���)Zcall_args_list�AssertionError�
isinstance�logging�	LogRecord�json�loadsr�
makePickle�decode�zlib�
decompress�errorr)r�arg�_rrr
�get_mock_send_arg.sr(zmessage,expected)u€u€u€zutf-8���acCs"|t�t�|��d��kst�dS)Nzutf-8)rr rZ_pack_gelf_dictr"r)�message�expectedrrr
�	test_pack@s
r-cCs~ytd��Wn"tk
r.|jddd�YnXt|�}d|dksHt�|d�d�sZt�|d�d�sz|d�d	�szt�d
S)zyCheck that a the ``full_message`` traceback info is passed when
    the ``exc_info=1`` flag is given within a log messagezSyntax error�Failed�)�exc_info�
short_message�full_messagez"Traceback (most recent call last):zSyntaxError: Syntax errorzSyntaxError: Syntax error
N)�SyntaxErrorr%r(r�
startswith�endswith)rrr&rrr
�test_manual_exc_info_handlerOsr6cCszytd��Wntk
r*|�d�YnXt|�}d|dksDt�|d�d�sVt�|d�d�sv|d�d�svt�dS)NzSyntax errorr.r1r2z"Traceback (most recent call last):zSyntaxError: Syntax errorzSyntaxError: Syntax error
)r3�	exceptionr(rr4r5)rrr&rrr
�test_normal_exception_handlerasr8cCs&|�d�t|�}d|dks"t�dS)NuMensaje de registro españolr1)r%r(r)rrr&rrr
�test_unicodeqs
r9�zpython2 only)�reasoncCs*|�d�t|�}dt|dks&t�dS)NsBroken � log messagezBroken %s log messager1)r%r(�UNICODE_REPLACEMENTr)rr�decodedrrr
�test_broken_unicode_python2ws
r>zpython3 onlycCs&|�d�t|�}d|dks"t�dS)NsBroken � log messagezb'Broken \xde log message'r1)r%r(r)rrr=rrr
�test_broken_unicode_python3�s
r?cCs>|jdddid�t|�}d|dks*t�d|dks:t�dS)NzLog message�foo�bar)�extrar1�_foo)r%r(r)rrr=rrr
�test_extra_field�srDcCsF|jddddgid�t|�}d|dks.t�ddg|dksBt�dS)NzLog messager@rAZbaz)rBr1rC)r%r(r)rrr=rrr
�	test_list�srEcCs@|jddt�id�t|�}d|dks,t�d|dks<t�dS)NzLog messager@)rBr1z<TestClass>rC)r%r
r(r)rrr=rrr
�test_arbitrary_object�srFc	CsXt�ddddddd�}|jdd	|id
�t|�}d|dks@t�|��|dksTt�dS)
Ni��r:����zLog message�ts)rBzdatetime.datetimeZ_ts)�datetimer%r(r�	isoformat)rr�	timestampr=rrr
�Rtest_message_to_pickle_serializes_datetime_objects_instead_of_blindly_repring_them�s
rPcCs>|jdddid�t|�}d|dks*t�d|dks:t�dS)NzLog message�status�OK)rBr1Z_status)r%r(r)rrr=rrr
�test_status_field_issue�srScCs&t�}t�|t�d|dks"t�dS)N�INFO�
level_name)�dictrZ_add_level_namesrr)�	gelf_dictrrr
�test_add_level_name�srXcCstt��t�dd�kst�t��t�dd�ks0t�t��t�dd�ksHt�dt�dd�ks\t�dt�dd�kspt�dS)zETest all posible resolutions of :meth:`BaseGELFHandler._resolve_host`FNT�	localhost�)�socket�gethostnamerZ
_resolve_hostr�getfqdnrrrr
�test_resolve_host�s
r^cCs<t�}d}t�||t�t|dks(t�d|dks8t�dS)Nz
test facilityZ_logger�facility)rVrZ_set_custom_facilityrr	r)rWr_rrr
�test_set_custom_facility�s
r`cCsJx"|jD]}t|t�rt�d�qW|�d�t|�}d|dksFt�dS)z�Test the ability to set and modify the graypy handler's
    :class:`logging.Formatter` and have the resultant ``short_message`` be
    formatted by the set :class:`logging.Formatter`z)formatting not mocked for GELFHTTPHandlerzLog messagezERROR : Log messager1N)�handlersrr�pytest�skipr%r(r)rrrr=rrr
�test_formatted_logger�s

rdc	Cs&t�t��tddd�WdQRXdS)z~Test constructing :class:`graypy.handler.BaseGELFHandler` with
    specifying conflicting arguments ``fqdn`` and ``localname``TrY)Zfqdn�	localnameN)rb�raises�
ValueErrorrrrrr
�test_invalid_fqdn_localhost�srhc	Cs&t�t��tddd�WdQRXdS)z|Test constructing :class:`graypy.handler.GELFTLSHandler` with
    incorrect arguments specifying server ca cert verificationz	127.0.0.1T)�validateN)rbrfrgrrrrr
�test_invalid_ca_certs�srjc	Cs&t�t��tddd�WdQRXdS)z}Test constructing :class:`graypy.handler.GELFTLSHandler` with
    incorrect arguments specifying client cert/key verificationz	127.0.0.1z	/dev/null)�keyfileN)rbrfrgrrrrr
�test_invalid_client_certs�srl)1�__doc__rMrrr[�sysr#rrbZgraypy.handlerrrrZtests.helperrrrZtests.unit.helperrr	r<rr
Z
yield_fixturerr(�markZparametrize�encoder-r6r8r9Zskipif�version_infor>r?rDrErFrPrSrXr^r`rdrhrjrlrrrr
�<module>sL
	"
"