%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/python/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/python/__pycache__/logfile.cpython-312.pyc

�

Ϫ�f�'����dZddlZddlZddlZddlZddlmZmZmZddl	m
Z
Gd�d�ZGd�de�Ze
je�Gd	�d
e�Ze
je�Gd�d�Zy)
z!
A rotating, browsable log file.
�N)�BinaryIO�Optional�cast)�
threadablec	�t�eZdZdZddgZ	ddededeeddfd	�Ze	d
��Z
d�Zd�Zd
�Z
d�Zd�Zd�Zd�Zy)�BaseLogFilez<
    The base class for a log file that can be rotated.
    �write�rotateN�name�	directory�defaultMode�returnc��||_||_tjj	||�|_|�rtjj|j�rIt
jtj|j�tj�|_	n||_	|j�y)a
        Create a log file.

        @param name: name of the file
        @param directory: directory holding the file
        @param defaultMode: permissions used to create the file. Default to
        current permissions of the file if the file exists.
        N)rr�os�path�join�exists�stat�S_IMODE�ST_MODEr
�	_openFile)�selfrrr
s    �8/usr/lib/python3/dist-packages/twisted/python/logfile.py�__init__zBaseLogFile.__init__s��#�����	��G�G�L�L��D�1��	���2�7�7�>�>�$�)�)�#<�.2�l�l�����	�	�"�4�<�<�0�/�D�� +�D������c���tjj|�}|tjj|�tjj	|�g|��i|��S)z=
        Construct a log file from a full file path.
        )rr�abspath�basename�dirname)�cls�filename�args�kwargs�logPaths     r�fromFullPathzBaseLogFile.fromFullPath2sJ��
�'�'�/�/�(�+���2�7�7�#�#�G�,�b�g�g�o�o�g�.F�X��X�QW�X�Xrc��t�)zc
        Override with a method to that returns true if the log
        should be rotated.
        )�NotImplementedError�rs r�shouldRotatezBaseLogFile.shouldRotate:s
��
"�!rc���d|_tjj|j�rGt	t
t
|jdd��|_|jjdd�n�|j�Vtjd�}	t	t
t
|jdd��|_tj|�n*t	t
t
|jdd��|_|j�,	tj|j|j�yy#tj|�wxYw#t$rYywxYw)z[
        Open the log file.

        The log file is always opened in binary mode.
        Fzrb+r�Ni�zwb+)
�closedrrrrr�open�_file�seekr
�umask�chmod�OSError)r�oldUmasks  rrzBaseLogFile._openFileAs������
�7�7�>�>�$�)�)�$��h��T�Y�Y��q�(A�B�D�J��J�J�O�O�A�q�!����+��8�8�E�?��'�!%�h��T�Y�Y��q�0I�!J�D�J��H�H�X�&�!�(�D����E�1�,E�F��
����'�
�������D�$4�$4�5�(���H�H�X�&���
��
�s�*D=�*E�=E�	E#�"E#c���|j�r |j�|j�t|t�r|jd�}|jj|�y)z�
        Write some data to the file.

        @param data: The data to write.  Text will be encoded as UTF-8.
        @type data: L{bytes} or L{unicode}
        �utf8N)r)�flushr
�
isinstance�str�encoder.r	�r�datas  rr	zBaseLogFile.write\sL�������J�J�L��K�K�M��d�C� ��;�;�v�&�D��
�
����rc�8�|jj�y)z!
        Flush the file.
        N)r.r6r(s rr6zBaseLogFile.flushjs��	
�
�
���rc�J�d|_|jj�|`y)z[
        Close the file.

        The file cannot be used once it has been closed.
        TN)r,r.�closer(s rr>zBaseLogFile.closeps ������
�
�����Jrc�D�|j�|j�y)a"
        Reopen the log file. This is mainly useful if you use an external log
        rotation tool, which moves under your feet.

        Note that on Windows you probably need a specific API to rename the
        file, as it's not supported to simply use os.rename, for example.
        N)r>rr(s r�reopenzBaseLogFile.reopenzs��	
�
�
�����rc�,�t|j�S)z>
        Return a LogReader for the current log file.
        )�	LogReaderrr(s r�
getCurrentLogzBaseLogFile.getCurrentLog�s������#�#r�N)�__name__�
__module__�__qualname__�__doc__�synchronizedr8r�intr�classmethodr%r)rr	r6r>r@rC�rrrrs|����X�&�L�GK����$'��6>�s�m��	
��,�Y��Y�"��6���	�$rrc�H�eZdZdZ			dd�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zy)�LogFilezf
    A log file that can be rotated.

    A rotateLength of None disables automatic log rotation.
    Nc�P�tj||||�||_||_y)a`
        Create a log file rotating on length.

        @param name: file name.
        @type name: C{str}
        @param directory: path of the log file.
        @type directory: C{str}
        @param rotateLength: size of the log file where it rotates. Default to
            1M.
        @type rotateLength: C{int}
        @param defaultMode: mode used to create the file.
        @type defaultMode: C{int}
        @param maxRotatedFiles: if not None, max number of log files the class
            creates. Warning: it removes all log files above this number.
        @type maxRotatedFiles: C{int}
        N)rr�rotateLength�maxRotatedFiles)rrrrPr
rQs      rrzLogFile.__init__�s(��0	���T�4��K�@�(���.��rc�l�tj|�|jj�|_yrD)rrr.�tell�sizer(s rrzLogFile._openFile�s"�����d�#��J�J�O�O�%��	rc�P�|jxr|j|jk\S)zL
        Rotate when the log file size is larger than rotateLength.
        )rPrTr(s rr)zLogFile.shouldRotate�s$��� � �C�T�Y�Y�$�2C�2C�%C�Crc��d|j|fz}tjj|�std��t	|�S)zK
        Given an integer, return a LogReader for an old log file.
        �%s.%d�no such logfile exists)rrr�
ValueErrorrB�r�
identifierr!s   r�getLogzLogFile.getLog�s>���d�i�i��4�4���w�w�~�~�h�'��5�6�6���"�"rc�l�tj||�|xjt|�z
c_y)z.
        Write some data to the file.
        N)rr	rT�lenr:s  rr	z
LogFile.write�s&��	���$��%��	�	�S��Y��	rc��tj|jtj�r.tj|jtj�sy|j�}|j
�|D]y}|j�4||jk\r%tjd|j|fz��Ctjd|j|fzd|j|dzfz��{|jj�tj|jd|jz�|j�y)z�
        Rotate the file and create a new one.

        If it's not possible to open new logfile, this will fail silently,
        and continue logging to old logfile.
        NrW�z%s.1)
r�accessr�W_OKr�listLogs�reverserQ�remove�renamer.r>r)r�logs�is   rr
zLogFile.rotate�s����	�	�$�.�.�"�'�'�2�r�y�y����B�G�G�7T���}�}��������	R�A��#�#�/�A��9M�9M�4M��	�	�'�T�Y�Y��N�2�3��	�	�'�T�Y�Y��N�2�G�t�y�y�!�a�%�>P�4P�Q�		R�
	
�
�
����
�	�	�$�)�)�V�d�i�i�/�0����rc��g}tjd|jz�D]3}	t|jd�d�}|r|j	|��5|j
�|S#t
$rY�SwxYw)zM
        Return sorted list of integers - the old logs' identifiers.
        z%s.*�.���)�globrrJ�split�appendrY�sort)r�resultr�counters    rrczLogFile.listLogs�sz�����I�I�f�t�y�y�0�1�	�D�
��d�j�j��o�b�1�2����M�M�'�*��		�	���
��
���
��
�s�0A-�-	A9�8A9c�6�tj|�}|d=|S)NrT�r�__getstate__�r�states  rrtzLogFile.__getstate__�s���(�(��.���&�M��r)i@BNN)rErFrGrHrrr)r\r	r
rcrtrLrrrNrN�s;������
/�8&�D�#���(
�rrNc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�DailyLogFilezAA log file that is rotated daily (at or after midnight localtime)c��tj|�|jtj|j
�d�|_y)N�)rr�toDaterrr�lastDater(s rrzDailyLogFile._openFile�s2�����d�#����B�G�G�D�I�I�$6�q�$9�:��
rc�<�|j�|jkDS)z1Rotate when the date has changed since last write)r{r|r(s rr)zDailyLogFile.shouldRotate�s���{�{�}�t�}�}�,�,rc�,�tj|�ddS)aConvert a unixtime to (year, month, day) localtime tuple,
        or return the current (year, month, day) localtime tuple.

        This function primarily exists so you may overload it with
        gmtime, or some cruft to make unit testing possible.
        N�)�time�	localtime)rr"s  rr{zDailyLogFile.toDates���~�~�t�$�R�a�(�(rc	��	djtt|��S#t$r1djtt|j	|���cYSwxYw)z>Return the suffix given a (year, month, day) tuple or unixtime�_)r�mapr8�
BaseExceptionr{)r�	tupledates  r�suffixzDailyLogFile.suffix
sK��	>��8�8�C��Y�/�0�0���	>��8�8�C��T�[�[��%;�<�=�=�	>�s�!�7A�Ac��|j|�|jk(r|j�S|j�d|j	|���}t
jj
|�std��t|�S)z:Given a unix time, return a LogReader for an old log file.rjrX)	r{r|rCrr�rrrYrBrZs   rr\zDailyLogFile.getLogsk���;�;�z�"�d�m�m�3��%�%�'�'��i�i�[��$�+�+�j�"9�!:�;���w�w�~�~�h�'��5�6�6���"�"rc��tj||�t|j|j	��|_y)zWrite some data to the log fileN)rr	�maxr|r{r:s  rr	zDailyLogFile.writes,�����$��%��D�M�M�4�;�;�=�9��
rc���tj|jtj�r.tj|jtj�sy|j�d|j|j���}tjj|�ry|jj�tj|j|�|j�y)z�Rotate the file and create a new one.

        If it's not possible to open new logfile, this will fail silently,
        and continue logging to old logfile.
        Nrj)rrarrbrr�r|rr.r>rfr)r�newpaths  rr
zDailyLogFile.rotate#s����	�	�$�.�.�"�'�'�2�r�y�y����B�G�G�7T���Y�Y�K�q����T�]�]�!;� <�=��
�7�7�>�>�'�"���
�
����
�	�	�$�)�)�W�%����rc�6�tj|�}|d=|S)Nr|rsrus  rrtzDailyLogFile.__getstate__2s���(�(��.���*���rN)rErFrGrHrr)r{r�r\r	r
rtrLrrrxrx�s-��K�;�-�)�>�#�:�
�rrxc�$�eZdZdZd�Zdd�Zd�Zy)rBzRead from a log file.c�$�t|�|_y)z�
        Open the log file for reading.

        The comments about binary-mode for L{BaseLogFile._openFile} also apply
        here.
        N)r-r.)rrs  rrzLogReader.__init__>s���$�Z��
rc��g}t|�D]2}|jj�}|s|S|j|��4|S)zRead a list of lines from the log file.

        This doesn't returns all of the files lines - call it multiple times.
        )�ranger.�readlinern)r�linesrprh�lines     r�	readLineszLogReader.readLinesGsN��
���u��	 �A��:�:�&�&�(�D����
�
�M�M�$��		 �
�
rc�8�|jj�yrD)r.r>r(s rr>zLogReader.closeTs���
�
���rN)�
)rErFrGrHrr�r>rLrrrBrB;s��� ��rrB)rHrlrrr��typingrrr�twisted.pythonrrrN�synchronizerxrBrLrr�<module>r�sz����	���+�+�%�t$�t$�nc�k�c�L�
���w��@�;�@�F�
���|�$��r

Zerion Mini Shell 1.0