AlkantarClanX12

Your IP : 18.117.105.230


Current Path : /opt/alt/python311/lib64/python3.11/logging/__pycache__/
Upload File :
Current File : //opt/alt/python311/lib64/python3.11/logging/__pycache__/handlers.cpython-311.opt-1.pyc

�

c��f����t�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZddl
Z
ddlZddlZdZdZdZdZdZdZd	ZGd
�dej��ZGd�d
e��ZGd�de��ZGd�dej��ZGd�dej��ZGd�de��ZGd�dej��ZGd�dej��Z Gd�dej��Z!Gd�dej��Z"Gd�dej��Z#Gd �d!e#��Z$Gd"�d#ej��Z%Gd$�d%e&��Z'dS)&z�
Additional handlers for the logging package for Python. The core package is
based on PEP 282 and comments thereto in comp.lang.python.

Copyright (C) 2001-2021 Vinay Sajip. All Rights Reserved.

To use, simply 'import logging.handlers' and log away!
�N)�ST_DEV�ST_INO�ST_MTIMEi<#i=#i>#i?#i�Qc�4�eZdZdZdZdZdd�Zd�Zd�Zd�Z	dS)	�BaseRotatingHandlerz�
    Base class for handlers that rotate log files at a certain point.
    Not meant to be instantiated directly.  Instead, use RotatingFileHandler
    or TimedRotatingFileHandler.
    NFc�z�tj�||||||���||_||_||_dS)zA
        Use the specified filename for streamed logging
        ��mode�encoding�delay�errorsN)�logging�FileHandler�__init__rrr��self�filenamerrr
rs      �7/opt/alt/python311/lib64/python3.11/logging/handlers.pyrzBaseRotatingHandler.__init__6sM��	��$�$�T�8�$�.6�e�,2�	%�	4�	4�	4���	� ��
������c���	|�|��r|���tj�||��dS#t
$r|�|��YdSwxYw)z�
        Emit a record.

        Output the record to the file, catering for rollover as described
        in doRollover().
        N)�shouldRollover�
doRolloverrr�emit�	Exception�handleError�r�records  rrzBaseRotatingHandler.emitAs���	%��"�"�6�*�*�
"����!�!�!���$�$�T�6�2�2�2�2�2���	%�	%�	%����V�$�$�$�$�$�$�	%���s�A	A
�
A0�/A0c�^�t|j��s|}n|�|��}|S)a�
        Modify the filename of a log file when rotating.

        This is provided so that a custom filename can be provided.

        The default implementation calls the 'namer' attribute of the
        handler, if it's callable, passing the default name to
        it. If the attribute isn't callable (the default is None), the name
        is returned unchanged.

        :param default_name: The default name for the log file.
        )�callable�namer)r�default_name�results   r�rotation_filenamez%BaseRotatingHandler.rotation_filenameOs3����
�#�#�	.�!�F�F��Z�Z��-�-�F��
rc���t|j��s8tj�|��rtj||��dSdS|�||��dS)aL
        When rotating, rotate the current log.

        The default implementation calls the 'rotator' attribute of the
        handler, if it's callable, passing the source and dest arguments to
        it. If the attribute isn't callable (the default is None), the source
        is simply renamed to the destination.

        :param source: The source filename. This is normally the base
                       filename, e.g. 'test.log'
        :param dest:   The destination filename. This is normally
                       what the source is rotated to, e.g. 'test.log.1'.
        N)r �rotator�os�path�exists�rename)r�source�dests   r�rotatezBaseRotatingHandler.rotatebsj�����%�%�	'��w�~�~�f�%�%�
(��	�&�$�'�'�'�'�'�
(�
(�
�L�L���&�&�&�&�&r)NFN)
�__name__�
__module__�__qualname__�__doc__r!r&rrr$r-�rrrr-sk��������

�E��G�	�	�	�	�%�%�%����&'�'�'�'�'rrc�*�eZdZdZ		d	d�Zd�Zd�ZdS)
�RotatingFileHandlerz�
    Handler for logging to a set of files, which switches from one file
    to the next when the current file reaches a certain size.
    �arNFc��|dkrd}d|vrtj|��}t�||||||���||_||_dS)a�
        Open the specified file and use it as the stream for logging.

        By default, the file grows indefinitely. You can specify particular
        values of maxBytes and backupCount to allow the file to rollover at
        a predetermined size.

        Rollover occurs whenever the current log file is nearly maxBytes in
        length. If backupCount is >= 1, the system will successively create
        new files with the same pathname as the base file, but with extensions
        ".1", ".2" etc. appended to it. For example, with a backupCount of 5
        and a base file name of "app.log", you would get "app.log",
        "app.log.1", "app.log.2", ... through to "app.log.5". The file being
        written to is always "app.log" - when it gets filled up, it is closed
        and renamed to "app.log.1", and if files "app.log.1", "app.log.2" etc.
        exist, then they are renamed to "app.log.2", "app.log.3" etc.
        respectively.

        If maxBytes is zero, rollover never occurs.
        rr5�b�rr
rN)�io�
text_encodingrr�maxBytes�backupCount)rrrr;r<rr
rs        rrzRotatingFileHandler.__init__|sm��6�a�<�<��D��d�?�?��'��1�1�H��$�$�T�8�T�H�+0��	%�	A�	A�	A� ��
�&����rc��|jr |j���d|_|jdk�r/t|jdz
dd��D]�}|�d|j|fz��}|�d|j|dzfz��}tj�|��rHtj�|��rt
j	|��t
j
||����|�|jdz��}tj�|��rt
j	|��|�|j|��|js|�
��|_dSdS)z<
        Do a rollover, as described in __init__().
        Nr����z%s.%dz.1)�stream�closer<�ranger$�baseFilenamer'r(r)�remover*r-r
�_open)r�i�sfn�dfns    rrzRotatingFileHandler.doRollover�sq���;�	��K�������D�K���a����4�+�a�/��B�7�7�
(�
(���,�,�W��8I�1�7M�-M�N�N���,�,�W��8I�89�A��8?�.?�@�@���7�>�>�#�&�&�(��w�~�~�c�*�*�'��	�#�����I�c�3�'�'�'���(�(��):�T�)A�B�B�C��w�~�~�c�"�"�
��	�#�����K�K��)�3�/�/�/��z�	'��*�*�,�,�D�K�K�K�	'�	'rc��tj�|j��r&tj�|j��sdS|j�|���|_|jdkrgd|�|��z}|j�	dd��|j�
��t|��z|jkrdSdS)z�
        Determine if rollover should occur.

        Basically, see if the supplied record would cause the file to exceed
        the size limit we have.
        FNrz%s
�T)r'r(r)rC�isfiler@rEr;�format�seek�tell�len�rr�msgs   rrz"RotatingFileHandler.shouldRollover�s����7�>�>�$�+�,�,�	�R�W�^�^�D�DU�5V�5V�	��5��;���*�*�,�,�D�K��=�1����4�;�;�v�.�.�.�C��K���Q��"�"�"��{���!�!�C��H�H�,��
�=�=��t��ur)r5rrNFN)r.r/r0r1rrrr2rrr4r4ws[��������DE�48�"'�"'�"'�"'�H'�'�'�.����rr4c�8�eZdZdZ			dd�Zd�Zd	�Zd
�Zd�ZdS)
�TimedRotatingFileHandlerz�
    Handler for logging to a file, rotating the log file at certain timed
    intervals.

    If backupCount is > 0, when rollover is done, no more than backupCount
    files are kept - the oldest ones are deleted.
    �hr>rNFc
��tj|��}t�||d|||	���|���|_||_||_||_|jdkrd|_	d|_
d}
�n)|jdkrd|_	d	|_
d
}
�n|jdkrd|_	d
|_
d}
n�|jdks|jdkrd|_	d|_
d}
n�|j�d��r�d|_	t|j��dkrtd|jz���|jddks|jddkrtd|jz���t|jd��|_d|_
d}
ntd|jz���t!j|
t j��|_|j	|z|_	|j}t*j�|��r t+j|��t2}n tt5j����}|�|��|_dS)Nr5r8�Sr>z%Y-%m-%d_%H-%M-%Sz0(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}-\d{2}(?!\d)�M�<z%Y-%m-%d_%H-%Mz*(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}-\d{2}(?!\d)�H�z%Y-%m-%d_%Hz$(?<!\d)\d{4}-\d{2}-\d{2}_\d{2}(?!\d)�D�MIDNIGHTrz%Y-%m-%dz(?<!\d)\d{4}-\d{2}-\d{2}(?!\d)�Wi�:	rJzHYou must specify a day for weekly rollover from 0 to 6 (0 is Monday): %s�0�6z-Invalid day specified for weekly rollover: %sz'Invalid rollover interval specified: %s)r9r:rr�upper�whenr<�utc�atTime�interval�suffix�
startswithrO�
ValueError�int�	dayOfWeek�re�compile�ASCII�extMatchrCr'r(r)�statr�time�computeRollover�
rolloverAt)rrrardr<rr
rbrcrrm�ts            rrz!TimedRotatingFileHandler.__init__�s@���#�H�-�-���$�$�T�8�S�8�+0��	%�	A�	A�	A��J�J�L�L��	�&����������9�����D�M�-�D�K�J�H�H�
�Y�#�
�
��D�M�*�D�K�D�H�H�
�Y�#�
�
�#�D�M�'�D�K�>�H�H�
�Y�#�
�
���j�!8�!8�(�D�M�$�D�K�8�H�H�
�Y�
!�
!�#�
&�
&�
	T�,�D�M��4�9�~�~��"�"� �!k�nr�nw�!w�x�x�x��y��|�c�!�!�T�Y�q�\�C�%7�%7� �!P�SW�S\�!\�]�]�]� ���1��.�.�D�N�$�D�K�8�H�H��F���R�S�S�S��
�8�R�X�6�6��
��
��0��
��$��
�7�>�>�(�#�#�	!����!�!�(�+�A�A��D�I�K�K� � �A��.�.�q�1�1����rc��||jz}|jdks|j�d���r�|jrt	j|��}nt	j|��}|d}|d}|d}|d}|j�t}n,|jj	dz|jj
zdz|jjz}||dz|zdz|zz
}	|	d	kr|	tz
}	|d
zdz}||	z}|j�d��rV|}
|
|jkr3|
|jkr|j|
z
}nd|
z
|jzd
z}||tzz
}||jtdzz
z
}n||jtz
z
}|jsS|d}t	j|��d}
||
kr+|s"d
}t	j|dz
��dsd	}nd}||z
}|S)zI
        Work out the rollover time based on the specified time.
        r\r]����NrXrr>�r?���rZ)
rdrarfrbro�gmtime�	localtimerc�	_MIDNIGHT�hour�minute�secondri)r�currentTimer#rr�currentHour�
currentMinute�
currentSecond�
currentDay�	rotate_ts�r�day�
daysToWait�dstNow�
dstAtRollover�addends               rrpz(TimedRotatingFileHandler.computeRollovers���t�}�,���9�
�"�"�d�i�&:�&:�3�&?�&?�"��x�
0��K��,�,����N�;�/�/���A�$�K��a�D�M��a�D�M��1��J��{�"�%�	�	�"�k�.��3�d�k�6H�H�"�L��K�&�'�	��k�B�.��>�"�D����A��A�v�v��Y���(�1�n��1�
� �1�_�F� �y�#�#�C�(�(�

4� ���$�.�(�(��T�^�+�+�%)�^�c�%9�
�
�%&��W�t�~�%=��%A�
��j�9�4�4�F��$�-�)�a�-�7�7����$�-�)�3�3���8�

%��2��� $��v� 6� 6�r� :�
��]�*�*�!�&�!&��#�~�f�T�k�:�:�2�>�'�%&�F��!%���f�$�F��
rc�(�ttj����}||jkrftj�|j��r@tj�|j��s|�|��|_dSdSdS)z�
        Determine if rollover should occur.

        record is not used, as we are just comparing times, but it is needed so
        the method signatures are the same
        FT)	rhrorqr'r(r)rCrKrp)rrrrs   rrz'TimedRotatingFileHandler.shouldRolloverbs{��
��	������������w�~�~�d�/�0�0�
������HY�9Z�9Z�
�#'�"6�"6�q�"9�"9����u��4��urc���tj�|j��\}}tj|��}g}|j�|dz}t
|��}|D]g}|d|�|krW||d�}|j�|��r3|�	tj�
||�����hn�|D]�}|j�|��}	|	r�|�|jdz|	dz��}
tj�|
��|kr4|�	tj�
||����n2|j�||	�
��dz��}	|	����t
|��|jkrg}n3|���|dt
|��|jz
�}|S)z�
        Determine the files to delete when rolling over.

        More specific than the earlier method, which just used glob.glob().
        N�.rr>)r'r(�splitrC�listdirr!rOrm�	fullmatch�append�join�search�basename�startr<�sort)r�dirName�baseName�	fileNamesr#�prefix�plen�fileNamere�mrHs           r�getFilesToDeletez)TimedRotatingFileHandler.getFilesToDeleteus����G�M�M�$�*;�<�<�����J�w�'�'�	����:����^�F��v�;�;�D�%�
G�
G���E�T�E�?�f�,�,�%�d�e�e�_�F��}�.�.�v�6�6�G��
�
�b�g�l�l�7�H�&E�&E�F�F�F��	
G�&�
F�
F��
�M�(�(��2�2���F��*�*�T�%6��%<�q��t�%C�D�D�C��w�'�'��,�,��8�8��
�
�b�g�l�l�7�H�&E�&E�F�F�F���
�,�,�X�q�w�w�y�y�1�}�E�E�A��F���v�;�;��)�)�)��F�F��K�K�M�M�M��;�S��[�[�4�+;�;�;�<�F��
rc�f�ttj����}|j|jz
}|jrtj|��}nZtj|��}tj|��d}|d}||kr|rd}nd}tj||z��}|�|jdztj	|j
|��z��}tj�
|��rdS|jr |j���d|_|�|j|��|jdkr+|���D]}tj|���|js|���|_|�|��|_dS)ax
        do a rollover; in this case, a date/time stamp is appended to the filename
        when the rollover happens.  However, you want the file to be named for the
        start of the interval, not the current time.  If there is a backup count,
        then we have to get a list of matching filenames, sort them and remove
        the one with the oldest suffix.
        r?rZryr�Nr)rhrorqrdrbrzr{r$rC�strftimerer'r(r)r@rAr-r<r�rDr
rErp)	rr�rr�	timeTupler��dstThenr�rH�ss	         rrz#TimedRotatingFileHandler.doRollover�s����$�)�+�+�&�&���O�d�m�+���8�	7���A���I�I���q�)�)�I��^�K�0�0��4�F���m�G��� � ��#�!�F�F�"�F� �N�1�v�:�6�6�	��$�$�T�%6��%<�%)�]�4�;�	�%J�%J�&K�L�L��
�7�>�>�#���	��F��;�	��K�������D�K����D�%�s�+�+�+���a����*�*�,�,�
�
���	�!������z�	'��*�*�,�,�D�K��.�.�{�;�;����r)rTr>rNFFNN)	r.r/r0r1rrprr�rr2rrrSrS�s���������DE�?C��A2�A2�A2�A2�FK�K�K�Z���&$�$�$�L&<�&<�&<�&<�&<rrSc�0�eZdZdZ		d	d�Zd�Zd�Zd�ZdS)
�WatchedFileHandlera�
    A handler for logging to a file, which watches the file
    to see if it has changed while in use. This can happen because of
    usage of programs such as newsyslog and logrotate which perform
    log file rotation. This handler, intended for use under Unix,
    watches the file to see if it has changed since the last emit.
    (A file has changed if its device or inode have changed.)
    If it has changed, the old file stream is closed, and the file
    opened to get a new stream.

    This handler is not appropriate for use under Windows, because
    under Windows open files cannot be moved or renamed - logging
    opens the files with exclusive locks - and so there is no need
    for such a handler. Furthermore, ST_INO is not supported under
    Windows; stat always returns zero for this value.

    This handler is based on a suggestion and patch by Chad J.
    Schroeder.
    r5NFc���d|vrtj|��}tj�||||||���d\|_|_|���dS)Nr7r
)r?r?)r9r:rrr�dev�ino�_statstreamrs      rrzWatchedFileHandler.__init__�sq���d�?�?��'��1�1�H���$�$�T�8�$�.6�e�,2�	%�	4�	4�	4�$����$�(��������rc��|jrRtj|j�����}|t|t
c|_|_dSdS�N)r@r'�fstat�filenorrr�r��r�sress  rr�zWatchedFileHandler._statstream�sO���;�	<��8�D�K�.�.�0�0�1�1�D�!%�f��t�F�|��D�H�d�h�h�h�	<�	<rc��	tj|j��}n#t$rd}YnwxYw|r,|t|jks|t|jkrq|j�h|j�	��|j�
��d|_|���|_|���dSdSdS)z�
        Reopen log file if needed.

        Checks if the underlying file has changed, and if it
        has, close the old stream and reopen the file to get the
        current stream.
        N)
r'rnrC�FileNotFoundErrorrr�rr�r@�flushrArEr�r�s  r�reopenIfNeededz!WatchedFileHandler.reopenIfNeeded�s���	��7�4�,�-�-�D�D�� �	�	�	��D�D�D�	�����	#�t�F�|�t�x�/�/�4��<�4�8�3K�3K��{�&���!�!�#�#�#���!�!�#�#�#�"���"�j�j�l�l���� � �"�"�"�"�"�'�&�4L�3Ks��+�+c�n�|���tj�||��dS)z�
        Emit a record.

        If underlying file has changed, reopen the file before emitting the
        record to it.
        N)r�rrrrs  rrzWatchedFileHandler.emits5��	
�������� � ��v�.�.�.�.�.r)r5NFN)r.r/r0r1rr�r�rr2rrr�r��si��������&AF������<�<�<�
#�#�#�8/�/�/�/�/rr�c�D�eZdZdZd�Zdd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�ZdS)
�
SocketHandlera
    A handler class which writes logging records, in pickle format, to
    a streaming socket. The socket is kept open across logging calls.
    If the peer resets it, an attempt is made to reconnect on the next call.
    The pickle which is sent is that of the LogRecord's attribute dictionary
    (__dict__), so that the receiver does not need to have the logging module
    installed in order to process the logging event.

    To unpickle the record at the receiving end into a LogRecord, use the
    makeLogRecord function.
    c���tj�|��||_||_|�||_n	||f|_d|_d|_d|_d|_	d|_
d|_dS)a
        Initializes the handler with a specific host address and port.

        When the attribute *closeOnError* is set to True - if a socket error
        occurs, the socket is silently closed and then reopened on the next
        logging call.
        NFg�?g>@g@)r�Handlerr�host�port�address�sock�closeOnError�	retryTime�
retryStart�retryMax�retryFactor�rr�r�s   rrzSocketHandler.__init__su��	�� � ��&�&�&���	���	��<��D�L�L� �$�<�D�L���	�!�����������
�����rr>c�F�|j�tj|j|���}n}tjtjtj��}|�|��	|�|j��n##t$r|�	���wxYw|S)zr
        A factory method which allows subclasses to define the precise
        type of socket they want.
        N��timeout)
r��socket�create_connectionr��AF_UNIX�SOCK_STREAM�
settimeout�connect�OSErrorrA)rr�r#s   r�
makeSocketzSocketHandler.makeSocket3s���
�9� ��-�d�l�G�L�L�L�F�F��]�6�>�6�3E�F�F�F����g�&�&�&�
����t�|�,�,�,�,���
�
�
��������
�����
s�#A>�> Bc�h�tj��}|j�d}n||jk}|r�	|���|_d|_dS#t$rW|j�
|j|_n0|j|jz|_|j|jkr|j|_||jz|_YdSwxYwdS)z�
        Try to create a socket, using an exponential backoff with
        a max retry time. Thanks to Robert Olson for the original patch
        (SF #815911) which has been slightly refactored.
        NT)	ror�r�r�r�r��retryPeriodr�r�)r�now�attempts   r�createSocketzSocketHandler.createSocketDs����i�k�k���>�!��G�G��d�n�,�G��	8�
8� �O�O�-�-��	�!%�������
8�
8�
8��>�)�'+��D�$�$�'+�'7�$�:J�'J�D�$��'�$�-�7�7�+/�=��(�!$�t�'7�!7������
8����		8�	8s� A�AB/�.B/c���|j�|���|jrN	|j�|��dS#t$r$|j���d|_YdSwxYwdS)z�
        Send a pickled string to the socket.

        This function allows for partial sends which can happen when the
        network is busy.
        N)r�r��sendallr�rA�rr�s  r�sendzSocketHandler.send`s����9���������9�	!�
!��	�!�!�!�$�$�$�$�$���
!�
!�
!��	���!�!�!� ��	�	�	�	�
!����	!�	!s�A�*A.�-A.c�L�|j}|r|�|��}t|j��}|���|d<d|d<d|d<|�dd��t
j|d��}tj	dt|����}||zS)z�
        Pickles the record in binary format with a length prefix, and
        returns it ready for transmission across the socket.
        rQN�args�exc_info�messager>z>L)r�rL�dict�__dict__�
getMessage�pop�pickle�dumps�struct�packrO)rr�ei�dummy�dr��slens       r�
makePicklezSocketHandler.makePickless���
�_��
�	(��K�K��'�'�E�
���!�!���$�$�&�&��%����&�	���*�
�	���i������L��A�����{�4��Q���(�(���a�x�rc��|jr)|jr"|j���d|_dStj�||��dS)z�
        Handle an error during logging.

        An error has occurred during logging. Most likely cause -
        connection lost. Close the socket so that we can retry on the
        next event.
        N)r�r�rArr�rrs  rrzSocketHandler.handleError�sS����	6���	6��I�O�O�����D�I�I�I��O�'�'��f�5�5�5�5�5rc��	|�|��}|�|��dS#t$r|�|��YdSwxYw)a
        Emit a record.

        Pickles the record and writes it to the socket in binary format.
        If there is an error with the socket, silently drop the packet.
        If there was a problem with the socket, re-establishes the
        socket.
        N)r�r�rr)rrr�s   rrzSocketHandler.emit�sc��	%�����'�'�A��I�I�a�L�L�L�L�L���	%�	%�	%����V�$�$�$�$�$�$�	%���s�*.�A�Ac��|���	|j}|rd|_|���tj�|��|���dS#|���wxYw�z$
        Closes the socket.
        N)�acquirer�rArr��release�rr�s  rrAzSocketHandler.close�sr��	
������	��9�D��
� ��	��
�
�����O�!�!�$�'�'�'��L�L�N�N�N�N�N��D�L�L�N�N�N�N�����AA/�/BN)r>)r.r/r0r1rr�r�r�r�rrrAr2rrr�r�
s�������
�
����2����"8�8�8�8!�!�!�&���,6�6�6�
%�
%�
%�����rr�c�$�eZdZdZd�Zd�Zd�ZdS)�DatagramHandlera�
    A handler class which writes logging records, in pickle format, to
    a datagram socket.  The pickle which is sent is that of the LogRecord's
    attribute dictionary (__dict__), so that the receiver does not need to
    have the logging module installed in order to process the logging event.

    To unpickle the record at the receiving end into a LogRecord, use the
    makeLogRecord function.

    c�L�t�|||��d|_dS)zP
        Initializes the handler with a specific host address and port.
        FN)r�rr�r�s   rrzDatagramHandler.__init__�s*��	���t�T�4�0�0�0�!����rc��|j�
tj}ntj}tj|tj��}|S)zu
        The factory method of SocketHandler is here overridden to create
        a UDP socket (SOCK_DGRAM).
        )r�r�r��AF_INET�
SOCK_DGRAM)r�familyr�s   rr�zDatagramHandler.makeSocket�s5��
�9���^�F�F��^�F��M�&�&�"3�4�4���rc�|�|j�|���|j�||j��dS)z�
        Send a pickled string to a socket.

        This function no longer allows for partial sends which can happen
        when the network is busy - UDP does not guarantee delivery and
        can deliver packets out of sequence.
        N)r�r��sendtor�r�s  rr�zDatagramHandler.send�s>���9���������	����D�L�)�)�)�)�)rN)r.r/r0r1rr�r�r2rrr�r��sK������	�	�"�"�"�
�
�
�
*�
*�
*�
*�
*rr�c
�|�eZdZdZdZdZdZdZdZdZ	dZ
d	ZdZdZ
dZdZdZdZdZd	Zd
ZdZdZd
ZdZdZdZdZdZdZdZdZdZ dZ!dZ"dZ#eeeeeeee
e	eeed�Z$ide�de�de�de�de�d e�d!e�d"e�d#e�d$e�d%e�d&e�d'e�d(e�d)e
�d*e�d+e�eeee e!e"e#d,��Z%d-d.d/d0d1d2�Z&d3e'fe
d4fd5�Z(d6�Z)d7�Z*d8�Z+d9�Z,d:�Z-d;Z.d<Z/d=�Z0d4S)>�
SysLogHandlera
    A handler class which sends formatted logging records to a syslog
    server. Based on Sam Rushing's syslog module:
    http://www.nightmare.com/squirl/python-ext/misc/syslog.py
    Contributed by Nicolas Untz (after which minor refactoring changes
    have been made).
    rr>rJrtrurvrwrx��	�
���
����������)�alert�crit�critical�debug�emerg�err�error�info�notice�panic�warn�warning�auth�authpriv�console�cron�daemon�ftp�kern�lpr�mail�news�ntp�securityzsolaris-cron�syslog�user�uucp�local0)�local1�local2�local3�local4�local5�local6�local7rrrrr)�DEBUG�INFO�WARNING�ERROR�CRITICAL�	localhostNc��tj�|��||_||_||_d|_|���dS)a
        Initialize a handler.

        If address is specified as a string, a UNIX socket is used. To log to a
        local syslogd, "SysLogHandler(address="/dev/log")" can be used.
        If facility is not specified, LOG_USER is used. If socktype is
        specified as socket.SOCK_DGRAM or socket.SOCK_STREAM, that specific
        socket type will be used. For Unix sockets, you can also specify a
        socktype of None, in which case socket.SOCK_DGRAM will be used, falling
        back to socket.SOCK_STREAM.
        N)rr�rr��facility�socktyper�r�)rr�r6r7s    rrzSysLogHandler.__init__JsN��	�� � ��&�&�&���� ��
� ��
�����������rc��|j}|�tj}tjtj|��|_	|j�|��||_dS#t
$r�|j���|j��tj}tjtj|��|_	|j�|��||_YdS#t
$r|j����wxYwwxYwr�)r7r�r�r�r�r�rAr�)rr��use_socktypes   r�_connect_unixsocketz!SysLogHandler._connect_unixsocket_s���}����!�,�L��m�F�N�L�A�A���	��K����(�(�(�(�D�M�M�M���
	�
	�
	��K�������}�(��!�-�L� �-����E�E�D�K�
���#�#�G�,�,�,� ,��
�
�
�
���
�
�
���!�!�#�#�#��
����
	���s�!A�AD�:!C�%D�Dc�N�|j}|j}t|t��r0d|_	|�|��dS#t$rYdSwxYwd|_|�tj}|\}}tj	||d|��}|st
d���|D]z}|\}}}}	}
dx}}	tj|||��}|tj
kr|�|
��n/#t$r"}
|
}|�|���Yd}
~
�sd}
~
wwxYw|�|�||_||_dS)af
        Try to create a socket and, if it's not a datagram socket, connect it
        to the other end. This method is called during handler initialization,
        but it's not regarded as an error if the other end isn't listening yet
        --- the method will be called again when emitting an event,
        if there is no socket at that point.
        TFNrz!getaddrinfo returns an empty list)
r�r7�
isinstance�str�
unixsocketr:r�r�r��getaddrinfor�r�rA)rr�r7r�r��ress�res�af�proto�_�sarr��excs              rr�zSysLogHandler.createSocketwsz���,���=���g�s�#�#�!	%�"�D�O�

��(�(��1�1�1�1�1���
�
�
����
����$�D�O���!�,�� �J�D�$��%�d�D�!�X�>�>�D��
C��A�B�B�B��
%�
%��-0�*��H�e�Q��!�!��d�%�!�=��X�u�=�=�D��6�#5�5�5����R�(�(�(��E���%�%�%��C��'��
�
�������������%�������	��D�K�$�D�M�M�Ms)�A�
A�A�';C$�$
D�.D�Dc��t|t��r
|j|}t|t��r
|j|}|dz|zS)z�
        Encode the facility and priority. You can pass in strings or
        integers - if strings are passed, the facility_names and
        priority_names mapping dictionaries are used to convert them to
        integers.
        rt)r<r=�facility_names�priority_names)rr6�prioritys   r�encodePriorityzSysLogHandler.encodePriority�sQ���h��$�$�	5��*�8�4�H��h��$�$�	5��*�8�4�H��A�
��)�)rc��|���	|j}|rd|_|���tj�|��|���dS#|���wxYwr�)r�r�rArr�r�r�s  rrAzSysLogHandler.close�sr��	
������	��;�D��
�"����
�
�����O�!�!�$�'�'�'��L�L�N�N�N�N�N��D�L�L�N�N�N�N���r�c�8�|j�|d��S)aK
        Map a logging level name to a key in the priority_names map.
        This is useful in two scenarios: when custom levels are being
        used, and in the case where you can't do a straightforward
        mapping by lowercasing the logging level name because of locale-
        specific issues (see SF #1524081).
        r)�priority_map�get)r�	levelNames  r�mapPriorityzSysLogHandler.mapPriority�s��� �$�$�Y�	�:�:�:r�Tc�^�	|�|��}|jr
|j|z}|jr|dz
}d|�|j|�|j����z}|�d��}|�d��}||z}|js|�	��|j
r{	|j�|��dS#t$rQ|j�
��|�|j��|j�|��YdSwxYw|jtjkr"|j�||j��dS|j�|��dS#t($r|�|��YdSwxYw)z�
        Emit a record.

        The record is formatted, and then sent to the syslog server. If
        exception information is present, it is NOT sent to the server.
        �z<%d>�utf-8N)rL�ident�
append_nulrKr6rQ�	levelname�encoder�r�r>r�r�rAr:r�r7r�r�r�rr)rrrQ�prios    rrzSysLogHandler.emit�s���	%��+�+�f�%�%�C��z�
'��j�3�&����
��v�
���D�/�/��
�04�0@�0@��AQ�0R�0R�T�T�T�D��;�;�w�'�'�D��*�*�W�%�%�C���*�C��;�
$��!�!�#�#�#���

)�*��K�$�$�S�)�)�)�)�)���*�*�*��K�%�%�'�'�'��,�,�T�\�:�:�:��K�$�$�S�)�)�)�)�)�)�*������&�"3�3�3���"�"�3���5�5�5�5�5���#�#�C�(�(�(�(�(���	%�	%�	%����V�$�$�$�$�$�$�	%���s7�B9F	�<C�AD3�/F	�2D3�38F	�-F	�	F,�+F,)1r.r/r0r1�	LOG_EMERG�	LOG_ALERT�LOG_CRIT�LOG_ERR�LOG_WARNING�
LOG_NOTICE�LOG_INFO�	LOG_DEBUG�LOG_KERN�LOG_USER�LOG_MAIL�
LOG_DAEMON�LOG_AUTH�
LOG_SYSLOG�LOG_LPR�LOG_NEWS�LOG_UUCP�LOG_CRON�LOG_AUTHPRIV�LOG_FTP�LOG_NTP�LOG_SECURITY�LOG_CONSOLE�LOG_SOLCRON�
LOG_LOCAL0�
LOG_LOCAL1�
LOG_LOCAL2�
LOG_LOCAL3�
LOG_LOCAL4�
LOG_LOCAL5�
LOG_LOCAL6�
LOG_LOCAL7rIrHrN�SYSLOG_UDP_PORTrr:r�rKrArQrVrWrr2rrr�r��s���������$�I��I��H��G��K��J��H��I��H��H��H��J��H��J��G��H��H��H��L��G��G��L��K��K��J��J��J��J��J��J��J��J�������������

�

�N�
���
���
�	��
�	��	
�
	�
�
�	��

�	��
�	��
�	��
�	��
�	��
�	��
�	��
�	�
�
�	��
� 	��!
�"	�
�#
�$#�"�"�"�"�"�"�1
�
�
�N�<�������L�!,�_�=�"�T�����*���0,%�,%�,%�\*�*�*����;�;�;�
�E��J�&%�&%�&%�&%�&%rr�c�(�eZdZdZ	dd�Zd�Zd�ZdS)�SMTPHandlerzK
    A handler class which sends an SMTP email for each logging event.
    N�@c��tj�|��t|tt
f��r|\|_|_n|dc|_|_t|tt
f��r|\|_|_	nd|_||_
t|t��r|g}||_||_
||_||_dS)ax
        Initialize the handler.

        Initialize the instance with the from and to addresses and subject
        line of the email. To specify a non-standard SMTP port, use the
        (host, port) tuple format for the mailhost argument. To specify
        authentication credentials, supply a (username, password) tuple
        for the credentials argument. To specify the use of a secure
        protocol (TLS), pass in a tuple for the secure argument. This will
        only be used when authentication credentials are supplied. The tuple
        will be either an empty tuple, or a single-value tuple with the name
        of a keyfile, or a 2-value tuple with the names of the keyfile and
        certificate file. (This tuple is passed to the `starttls` method).
        A timeout in seconds can be specified for the SMTP connection (the
        default is one second).
        N)rr�rr<�list�tuple�mailhost�mailport�username�password�fromaddrr=�toaddrs�subject�securer�)rr�r�r�r��credentialsr�r�s        rrzSMTPHandler.__init__�s���$	�� � ��&�&�&��h��u�
�.�.�	:�+3�(�D�M�4�=�=�+3�T�(�D�M�4�=��k�D�%�=�1�1�	!�+6�(�D�M�4�=�=� �D�M� ��
��g�s�#�#�	 ��i�G��������������rc��|jS)z�
        Determine the subject for the email.

        If you want to specify a subject line which is record-dependent,
        override this method.
        )r�rs  r�
getSubjectzSMTPHandler.getSubjects���|�rc�
�	ddl}ddlm}ddl}|j}|s|j}|�|j||j���}|��}|j	|d<d�
|j��|d<|�|��|d<|j
���|d	<|�|�|����|jr^|j�7|���|j|j�|���|�|j|j��|�|��|���dS#t2$r|�|��YdSwxYw)
zd
        Emit a record.

        Format the record and send it to the specified addressees.
        rN)�EmailMessager��From�,�To�Subject�Date)�smtplib�
email.messager��email.utilsr��	SMTP_PORT�SMTPr�r�r�r�r�r��utilsr{�set_contentrLr�r��ehlo�starttls�loginr��send_message�quitrr)rrr�r��emailr��smtprQs        rrzSMTPHandler.emit%s���	%��N�N�N�2�2�2�2�2�2������=�D��
)��(���<�<��
�t�T�\�<�J�J�D��,�.�.�C��-�C��K������.�.�C��I�!�_�_�V�4�4�C�	�N��+�/�/�1�1�C��K��O�O�D�K�K��/�/�0�0�0��}�
9��;�*��I�I�K�K�K�!�D�M�4�;�/�/��I�I�K�K�K��
�
�4�=�$�-�8�8�8����c�"�"�"��I�I�K�K�K�K�K���	%�	%�	%����V�$�$�$�$�$�$�	%���s�EE�F�F)NNr~)r.r/r0r1rr�rr2rrr}r}�sV��������9<�!�!�!�!�F���%�%�%�%�%rr}c�8�eZdZdZd
d�Zd�Zd�Zd�Zd�Zd	�Z	dS)�NTEventLogHandlera�
    A handler class which sends events to the NT Event Log. Adds a
    registry entry for the specified application name. If no dllname is
    provided, win32service.pyd (which contains some basic message
    placeholders) is used. Note that use of these placeholders will make
    your event logs big, as the entire message source is held in the log.
    If you want slimmer logs, you have to pass in the name of your own DLL
    which contains the message definitions you want to use in the event log.
    N�Applicationc
�.�tj�|��	ddl}ddl}||_||_|sttj�	|jj
��}tj�	|d��}tj�|dd��}||_||_
	|j�|||��n-#t$r }t!|dd��dkr�Yd}~nd}~wwxYw|j|_tj|jtj|jtj|jtj|jtj|ji|_dS#t6$rt9d��d|_YdSwxYw)Nrzwin32service.pyd�winerrorrvzWThe Python Win32 extensions for NT (service, event logging) appear not to be available.)rr�r�win32evtlogutil�win32evtlog�appname�_welur'r(r��__file__r��dllname�logtype�AddSourceToRegistryr�getattr�EVENTLOG_ERROR_TYPE�deftyper/�EVENTLOG_INFORMATION_TYPEr0r1�EVENTLOG_WARNING_TYPEr2r3�typemap�ImportError�print)rr�r�r�r�r��es       rrzNTEventLogHandler.__init__Os����� � ��&�&�&�	�/�/�/�/�/�/�/�/�"�D�L�(�D�J��
H��'�-�-��
�(;�<�<���'�-�-���
�3�3���'�,�,�w�q�z�3F�G�G��"�D�L�"�D�L�
��
�.�.�w���I�I�I�I���
�
�
��1�j�$�/�/�1�4�4��5�4�4�4�4�����
����
'�:�D�L��
�+�"G���+�"G���+�"C��
�+�"A�� �+�"A��D�L�L�L���	�	�	��?�
@�
@�
@��D�J�J�J�J�	���s=�BE0�<C�E0�
D�#C>�9E0�>D�A+E0�0 F�Fc��dS)ay
        Return the message ID for the event record. If you are using your
        own messages, you could do this by having the msg passed to the
        logger being an ID rather than a formatting string. Then, in here,
        you could use a dictionary lookup to get the message ID. This
        version returns 1, which is the base message ID in win32service.pyd.
        r>r2rs  r�getMessageIDzNTEventLogHandler.getMessageIDrs	���qrc��dS)z�
        Return the event category for the record.

        Override this if you want to specify your own categories. This version
        returns 0.
        rr2rs  r�getEventCategoryz"NTEventLogHandler.getEventCategory|s	���qrc�L�|j�|j|j��S)a�
        Return the event type for the record.

        Override this if you want to specify your own types. This version does
        a mapping using the handler's typemap attribute, which is set up in
        __init__() to a dictionary which contains mappings for DEBUG, INFO,
        WARNING, ERROR and CRITICAL. If you are using your own levels you will
        either need to override this method or place a suitable dictionary in
        the handler's typemap attribute.
        )r�rO�levelnor�rs  r�getEventTypezNTEventLogHandler.getEventType�s ���|�������=�=�=rc�V�|jr�	|�|��}|�|��}|�|��}|�|��}|j�|j||||g��dS#t$r|�|��YdSwxYwdS)z�
        Emit a record.

        Determine the message ID, event category and event type. Then
        log the message in the NT event log.
        N)	r�r�r�r�rL�ReportEventr�rr)rr�id�cat�typerQs      rrzNTEventLogHandler.emit�s����:�	)�
)��&�&�v�.�.���+�+�F�3�3���(�(��0�0���k�k�&�)�)���
�&�&�t�|�R��d�S�E�J�J�J�J�J���
)�
)�
)�� � ��(�(�(�(�(�(�
)����	)�	)s�A8B�B&�%B&c�D�tj�|��dS)aS
        Clean up this handler.

        You can remove the application name from the registry as a
        source of event log entries. However, if you do this, you will
        not be able to see the events as you intended in the Event Log
        Viewer - it needs to be able to access the registry to get the
        DLL name.
        N)rr�rA�rs rrAzNTEventLogHandler.close�s ��	����d�#�#�#�#�#r)Nr�)
r.r/r0r1rr�r�r�rrAr2rrr�r�Es~��������!�!�!�!�F������>�>�>�)�)�)�"$�$�$�$�$rr�c�0�eZdZdZ		d	d�Zd�Zd�Zd�ZdS)
�HTTPHandlerz^
    A class which sends records to a web server, using either GET or
    POST semantics.
    �GETFNc��tj�|��|���}|dvrt	d���|s|�t	d���||_||_||_||_||_	||_
dS)zr
        Initialize the instance with the host, the request URL, and the method
        ("GET" or "POST")
        )r��POSTzmethod must be GET or POSTNz3context parameter only makes sense with secure=True)rr�rr`rgr��url�methodr�r��context)rr�r�r�r�r�r�s       rrzHTTPHandler.__init__�s���	�� � ��&�&�&���������(�(��9�:�:�:��	1�'�-��0�1�1�
1���	����������&�������rc��|jS)z�
        Default implementation of mapping the log record into a dict
        that is sent as the CGI data. Overwrite in your class.
        Contributed by Franz Glasner.
        )r�rs  r�mapLogRecordzHTTPHandler.mapLogRecord�s����rc��ddl}|r"|j�||j���}n|j�|��}|S)z�
        get a HTTP[S]Connection.

        Override when a custom connection is required, for example if
        there is a proxy.
        rN)r�)�http.client�client�HTTPSConnectionr��HTTPConnection)rr�r��http�
connections     r�
getConnectionzHTTPHandler.getConnection�sQ��	�����	:���4�4�T�4�<�4�P�P�J�J���3�3�D�9�9�J��rc�<�	ddl}|j}|�||j��}|j}|j�|�|����}|jdkr(|�	d��dkrd}nd}|d||fzz}|�
|j|��|�	d��}|dkr
|d|�}|jdkrF|�d	d
��|�dtt|������|jrtddl}	d|jz�d
��}
d|	�|
������d��z}
|�d|
��|���|jdkr(|�|�d
����|���dS#t.$r|�|��YdSwxYw)zk
        Emit a record.

        Send the record to the web server as a percent-encoded dictionary
        rNr��?�&z%c%s�:r�zContent-typez!application/x-www-form-urlencodedzContent-lengthz%s:%srUzBasic �ascii�
Authorization)�urllib.parser�r�r�r��parse�	urlencoder�r��find�
putrequest�	putheaderr=rOr��base64rY�	b64encode�strip�decode�
endheadersr��getresponserr)rr�urllibr�rTr��data�seprFr�r�s           rrzHTTPHandler.emit�s��#	%������9�D��"�"�4���5�5�A��(�C��<�)�)�$�*;�*;�F�*C�*C�D�D�D��{�e�#�#��H�H�S�M�M�Q�&�&��C�C��C��F�c�4�[�0�0��
�L�L���c�*�*�*��	�	�#���A��A�v�v��B�Q�B�x���{�f�$�$����N�?�A�A�A����,�c�#�d�)�)�n�n�=�=�=���
0��
�
�
��t�/�/�7�7��@�@���v�/�/��2�2�8�8�:�:�A�A�'�J�J�J�����O�Q�/�/�/�
�L�L�N�N�N��{�f�$�$����t�{�{�7�+�+�,�,�,�
�M�M�O�O�O�O�O���	%�	%�	%����V�$�$�$�$�$�$�	%���s�G4G8�8H�H)r�FNN)r.r/r0r1rr�r�rr2rrr�r��si��������KO������(������)%�)%�)%�)%�)%rr�c�0�eZdZdZd�Zd�Zd�Zd�Zd�ZdS)�BufferingHandlerz�
  A handler class which buffers logging records in memory. Whenever each
  record is added to the buffer, a check is made to see if the buffer should
  be flushed. If it should, then flush() is expected to do what's needed.
    c�`�tj�|��||_g|_dS)z>
        Initialize the handler with the buffer size.
        N)rr�r�capacity�buffer)rr�s  rrzBufferingHandler.__init__s,��	�� � ��&�&�&� ��
�����rc�<�t|j��|jkS)z�
        Should the handler flush its buffer?

        Returns true if the buffer is up to capacity. This method can be
        overridden to implement custom flushing strategies.
        )rOr�r�rs  r�shouldFlushzBufferingHandler.shouldFlushs���D�K� � �D�M�1�2rc��|j�|��|�|��r|���dSdS)z�
        Emit a record.

        Append the record. If shouldFlush() tells us to, call flush() to process
        the buffer.
        N)r�r�r�r�rs  rrzBufferingHandler.emit!sK��	
����6�"�"�"����F�#�#�	��J�J�L�L�L�L�L�	�	rc��|���	|j���|���dS#|���wxYw)zw
        Override to implement custom flushing behaviour.

        This version just zaps the buffer to empty.
        N)r�r��clearr�r�s rr�zBufferingHandler.flush,sM��	
������	��K�������L�L�N�N�N�N�N��D�L�L�N�N�N�N���s�A�Ac��	|���tj�|��dS#tj�|��wxYw)zp
        Close the handler.

        This version just flushes and chains to the parent class' close().
        N)r�rr�rAr�s rrAzBufferingHandler.close8sL��	(��J�J�L�L�L��O�!�!�$�'�'�'�'�'��G�O�!�!�$�'�'�'�'���s	�7�!AN)	r.r/r0r1rr�rr�rAr2rrr�r�
si��������
���3�3�3�	�	�	�
�
�
�	(�	(�	(�	(�	(rr�c�B�eZdZdZejddfd�Zd�Zd�Zd�Z	d�Z
dS)	�
MemoryHandlerz�
    A handler class which buffers logging records in memory, periodically
    flushing them to a target handler. Flushing occurs whenever the buffer
    is full, or when an event of a certain severity or greater is seen.
    NTc�f�t�||��||_||_||_dS)a;
        Initialize the handler with the buffer size, the level at which
        flushing should occur and an optional target.

        Note that without a target being set either here or via setTarget(),
        a MemoryHandler is no use to anyone!

        The ``flushOnClose`` argument is ``True`` for backward compatibility
        reasons - the old behaviour is that when the handler is closed, the
        buffer is flushed, even if the flush level hasn't been exceeded nor the
        capacity exceeded. To prevent this, set ``flushOnClose`` to ``False``.
        N)r�r�
flushLevel�target�flushOnClose)rr�r�r�r�s     rrzMemoryHandler.__init__Is6��	�!�!�$��1�1�1�$������(����rc�\�t|j��|jkp|j|jkS)zP
        Check for buffer full or a record at the flushLevel or higher.
        )rOr�r�r�r�rs  rr�zMemoryHandler.shouldFlush]s.���D�K� � �D�M�1�4���4�?�2�	4rc��|���	||_|���dS#|���wxYw)z:
        Set the target handler for this handler.
        N)r�r�r�)rr�s  r�	setTargetzMemoryHandler.setTargetds@��	
������	� �D�K��L�L�N�N�N�N�N��D�L�L�N�N�N�N���s	�3�A	c��|���	|jr=|jD]}|j�|���|j���|���dS#|���wxYw)z�
        For a MemoryHandler, flushing means just sending the buffered
        records to the target, if there is one. Override if you want
        different behaviour.

        The record buffer is only cleared if a target has been set.
        N)r�r�r��handler�r�rs  rr�zMemoryHandler.flushns���	
������	��{�
$�"�k�/�/�F��K�&�&�v�.�.�.�.���!�!�#�#�#��L�L�N�N�N�N�N��D�L�L�N�N�N�N���s�AA0�0Bc���	|jr|���|���	d|_t�|��|���dS#|���wxYw#|���	d|_t�|��|���w#|���wxYwxYw)zi
        Flush, if appropriately configured, set the target to None and lose the
        buffer.
        N)r�r�r�r�r�rAr�r�s rrAzMemoryHandler.closes���
		�� �
��
�
�����L�L�N�N�N�
�"��� �&�&�t�,�,�,���������������������
�L�L�N�N�N�
�"��� �&�&�t�,�,�,���������������������s.�B�!A)�)A?�C'�!C�9C'�C$�$C')r.r/r0r1rr2rr�rr�rAr2rrr�r�Csz��������
-4�M�$�"�)�)�)�)�(4�4�4�������"����rr�c�*�eZdZdZd�Zd�Zd�Zd�ZdS)�QueueHandlera�
    This handler sends events to a queue. Typically, it would be used together
    with a multiprocessing Queue to centralise logging to file in one process
    (in a multi-process application), so as to avoid file write contention
    between processes.

    This code is new in Python 3.2, but this class can be copy pasted into
    user code for use with earlier Python versions.
    c�R�tj�|��||_dS)zA
        Initialise an instance, using the passed queue.
        N)rr�r�queue)rrs  rrzQueueHandler.__init__�s%��	�� � ��&�&�&���
�
�
rc�:�|j�|��dS)z�
        Enqueue a record.

        The base implementation uses put_nowait. You may want to override
        this method if you want to use blocking, timeouts or custom queue
        implementations.
        N)r�
put_nowaitrs  r�enqueuezQueueHandler.enqueue�s ��	
�
���f�%�%�%�%�%rc��|�|��}tj|��}||_||_d|_d|_d|_d|_|S)a�
        Prepare a record for queuing. The object returned by this method is
        enqueued.

        The base implementation formats the record to merge the message and
        arguments, and removes unpickleable items from the record in-place.
        Specifically, it overwrites the record's `msg` and
        `message` attributes with the merged message (obtained by
        calling the handler's `format` method), and sets the `args`,
        `exc_info` and `exc_text` attributes to None.

        You might want to override this method if you want to convert
        the record to a dict or JSON string, or send a modified copy
        of the record while leaving the original intact.
        N)rL�copyr�rQr�r��exc_text�
stack_inforPs   r�preparezQueueHandler.prepare�sT��,�k�k�&�!�!����6�"�"�������
���������� ����
rc��	|�|�|����dS#t$r|�|��YdSwxYw)zm
        Emit a record.

        Writes the LogRecord to the queue, preparing it for pickling first.
        N)r
rrrrs  rrzQueueHandler.emit�sc��	%��L�L����f�-�-�.�.�.�.�.���	%�	%�	%����V�$�$�$�$�$�$�	%���s�(,�A�AN)r.r/r0r1rr
rrr2rrrr�s[�����������&�&�&����B	%�	%�	%�	%�	%rrc�L�eZdZdZdZdd�d�Zd�Zd�Zd�Zd	�Z	d
�Z
d�Zd�ZdS)
�
QueueListenerz�
    This class implements an internal threaded listener which watches for
    LogRecords being added to a queue, removes them and passes them to a
    list of handlers for processing.
    NF)�respect_handler_levelc�>�||_||_d|_||_dS)zW
        Initialise an instance with the specified queue and
        handlers.
        N)r�handlers�_threadr)rrrrs    rrzQueueListener.__init__�s'��
��
� ��
����%:��"�"�"rc�6�|j�|��S)z�
        Dequeue a record and return it, optionally blocking.

        The base implementation uses get. You may want to override this method
        if you want to use timeouts or work with custom queue implementations.
        )rrO)r�blocks  r�dequeuezQueueListener.dequeue�s���z�~�~�e�$�$�$rc�~�tj|j���x|_}d|_|���dS)z�
        Start the listener.

        This starts up a background thread to monitor the queue for
        LogRecords to process.
        )r�TN)�	threading�Thread�_monitorrrr�)rrrs  rr�zQueueListener.start�s8��%�+�4�=�A�A�A�A���q����	���	�	�	�	�	rc��|S)a
        Prepare a record for handling.

        This method just returns the passed-in record. You may want to
        override this method if you need to do any custom marshalling or
        manipulation of the record before passing it to the handlers.
        r2rs  rrzQueueListener.prepare�s	���
rc��|�|��}|jD]3}|jsd}n|j|jk}|r|�|���4dS)z|
        Handle a record.

        This just loops through the handlers offering them the record
        to handle.
        TN)rrrr��levelr)rr�handler�processs    rrzQueueListener.handle	sk�����f�%�%���}�	'�	'�G��-�
:���� �.�G�M�9���
'����v�&�&�&��
	'�	'rc�&�|j}t|d��}		|�d��}||jur|r|���dS|�|��|r|���n#tj$rYdSwxYw�z)z�
        Monitor the queue for records, and ask the handler
        to deal with them.

        This method runs on a separate, internal thread.
        The thread will terminate if it sees a sentinel object in the queue.
        �	task_doneTN)r�hasattrr�	_sentinelr$r�Empty)r�q�
has_task_doners    rrzQueueListener._monitors���
�J����;�/�/�
�	�

����d�+�+���T�^�+�+�$�&����
�
�
��E����F�#�#�#� �"��K�K�M�M�M����;�
�
�
����
����	s�4A<�+A<�<B�Bc�D�|j�|j��dS)z�
        This is used to enqueue the sentinel record.

        The base implementation uses put_nowait. You may want to override this
        method if you want to use timeouts or work with custom queue
        implementations.
        N)rr	r&r�s r�enqueue_sentinelzQueueListener.enqueue_sentinel0s"��	
�
���d�n�-�-�-�-�-rc�n�|���|j���d|_dS)a

        Stop the listener.

        This asks the thread to terminate, and then waits for it to do so.
        Note that if you don't call this before your application exits, there
        may be some records still left on the queue, which won't be processed.
        N)r+rr�r�s r�stopzQueueListener.stop:s5��	
�����������������r)
r.r/r0r1r&rrr�rrrr+r-r2rrrr�s���������
�I�?D�;�;�;�;�;�%�%�%�	�	�	����'�'�'� ���..�.�.�
�
�
�
�
rr)(r1r9rr�r'r�r�rorjrnrrrrrr�DEFAULT_TCP_LOGGING_PORT�DEFAULT_UDP_LOGGING_PORT�DEFAULT_HTTP_LOGGING_PORT�DEFAULT_SOAP_LOGGING_PORTr{�SYSLOG_TCP_PORTr|rrr4rSr�r�r�r�r�r}r�r�r�r�r�objectrr2rr�<module>r4s���"��9�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�8�)�)�)�)�)�)�)�)�)�)�������������#��"��"��"��!��!���	�H'�H'�H'�H'�H'�'�-�H'�H'�H'�TQ�Q�Q�Q�Q�-�Q�Q�Q�fw<�w<�w<�w<�w<�2�w<�w<�w<�rG/�G/�G/�G/�G/��,�G/�G/�G/�Te�e�e�e�e�G�O�e�e�e�N(*�(*�(*�(*�(*�m�(*�(*�(*�TU%�U%�U%�U%�U%�G�O�U%�U%�U%�nN%�N%�N%�N%�N%�'�/�N%�N%�N%�`i$�i$�i$�i$�i$���i$�i$�i$�VX%�X%�X%�X%�X%�'�/�X%�X%�X%�t7(�7(�7(�7(�7(�w��7(�7(�7(�rJ�J�J�J�J�$�J�J�J�ZF%�F%�F%�F%�F%�7�?�F%�F%�F%�Rk�k�k�k�k�F�k�k�k�k�kr