HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //proc/self/root/usr/lib/python3/dist-packages/twisted/python/__pycache__/logfile.cpython-38.pyc
U

��W[c'�@s�dZddlmZmZddlZddlZddlZddlZddlm	Z	ddl
mZddlm
Z
eGdd�d��ZGd	d
�d
e�Ze	�e�Gdd�de�Ze	�e�eGd
d�d��ZdS)z!
A rotating, browsable log file.
�)�division�absolute_importN)�
threadable)�	_oldStyle)�unicodec@sjeZdZdZddgZddd�Zdd�Zee�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�BaseLogFilez<
    The base class for a log file that can be rotated.
    �write�rotateNcCs`||_||_tj�||�|_|dkrNtj�|j�rNt�t�|j�tj�|_	n||_	|�
�dS)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)�	directory�name�os�path�join�exists�stat�S_IMODE�ST_MODE�defaultMode�	_openFile)�selfrr
r�r�8/usr/lib/python3/dist-packages/twisted/python/logfile.py�__init__s	zBaseLogFile.__init__cOs.tj�|�}|tj�|�tj�|�f|�|�S)z=
        Construct a log file from a full file path.
        )rr
�abspath�basename�dirname)�cls�filename�args�kwargsZlogPathrrr�fromFullPath0s
���zBaseLogFile.fromFullPathcCst�dS)zc
        Override with a method to that returns true if the log
        should be rotated.
        N)�NotImplementedError�rrrr�shouldRotate:szBaseLogFile.shouldRotatec	Cs�d|_tj�|j�r4t|jdd�|_|j�dd�nH|jdk	rlt�d�}zt|jdd�|_W5t�|�Xnt|jdd�|_|jdk	r�zt�	|j|j�Wnt
k
r�YnXdS)z[
        Open the log file.

        The log file is always opened in binary mode.
        Fzrb+r�Ni�zwb+)�closedrr
r�open�_file�seekr�umask�chmod�OSError)rZoldUmaskrrrrBs


zBaseLogFile._openFilecCs<|��r|��|��t|t�r,|�d�}|j�|�dS)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	�
isinstancer�encoder'r�r�datarrrr^s

zBaseLogFile.writecCs|j��dS)z!
        Flush the file.
        N)r'r-r"rrrr-mszBaseLogFile.flushcCsd|_|j��d|_dS)z[
        Close the file.

        The file cannot be used once it has been closed.
        TN)r%r'�closer"rrrr2ts
zBaseLogFile.closecCs|��|��dS)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)r2rr"rrr�reopenszBaseLogFile.reopencCs
t|j�S)z>
        Return a LogReader for the current log file.
        )�	LogReaderr
r"rrr�
getCurrentLog�szBaseLogFile.getCurrentLog)N)�__name__�
__module__�__qualname__�__doc__Zsynchronizedrr �classmethodr#rrr-r2r3r5rrrrrs
rc@sReZdZdZddd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�ZdS)�LogFilezf
    A log file that can be rotated.

    A rotateLength of None disables automatic log rotation.
    �@BNcCs t�||||�||_||_dS)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
r=rr>rrrr�szLogFile.__init__cCst�|�|j��|_dS�N)rrr'�tell�sizer"rrrr�s
zLogFile._openFilecCs|jo|j|jkS)zL
        Rotate when the log file size is larger than rotateLength.
        )r=rAr"rrrr#�szLogFile.shouldRotatecCs*d|j|f}tj�|�s"td��t|�S)zK
        Given an integer, return a LogReader for an old log file.
        �%s.%d�no such logfile exists)r
rr�
ValueErrorr4�rZ
identifierrrrr�getLog�szLogFile.getLogcCs"t�||�|jt|�7_dS)z.
        Write some data to the file.
        N)rrrA�lenr0rrrr�sz
LogFile.writecCs�t�|jtj�r t�|jtj�s$dS|��}|��|D]R}|jdk	rf||jkrft�d|j|f�q8t�	d|j|fd|j|df�q8|j
��t�	|jd|j�|��dS)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.
        NrB�z%s.1)
r�accessr
�W_OKr
�listLogs�reverser>�remove�renamer'r2r)rZlogs�irrrr	�s &
zLogFile.rotatec	Cs`g}t�d|j�D]>}z$t|�d�d�}|r:|�|�Wqtk
rPYqXq|��|S)zM
        Return sorted list of integers - the old logs' identifiers.
        z%s.*�.���)�globr
�int�split�appendrD�sort)r�resultrZcounterrrrrK�szLogFile.listLogscCst�|�}|d=|S)NrA�r�__getstate__�r�staterrrrY�s
zLogFile.__getstate__)r<NN)r6r7r8r9rrr#rFrr	rKrYrrrrr;�s�
	r;c@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�DailyLogFilezFA log file that is rotated daily (at or after midnight localtime)
    cCs&t�|�|�t�|j�d�|_dS)N�)rr�toDaterrr
�lastDater"rrrr�s
zDailyLogFile._openFilecCs|��|jkS)z1Rotate when the date has changed since last write)r^r_r"rrrr#�szDailyLogFile.shouldRotatecGstj|�dd�S)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)rrrrrr^�szDailyLogFile.toDatec
Cs:zd�tt|��WSd�tt|�|���YSXdS)z>Return the suffix given a (year, month, day) tuple or unixtime�_N)r�map�strr^)rZ	tupledaterrr�suffix	szDailyLogFile.suffixcCsH|�|�|jkr|��Sd|j|�|�f}tj�|�s@td��t|�S)z:Given a unix time, return a LogReader for an old log file.�%s.%srC)	r^r_r5r
rfrrrDr4rErrrrFszDailyLogFile.getLogcCs"t�||�t|j|���|_dS)zWrite some data to the log fileN)rr�maxr_r^r0rrrrszDailyLogFile.writecCsnt�|jtj�r t�|jtj�s$dSd|j|�|j�f}tj�|�rJdS|j�	�t�
|j|�|��dS)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.
        Nrg)rrIr
rJr
rfr_rr'r2rNr)r�newpathrrrr	"s 
zDailyLogFile.rotatecCst�|�}|d=|S)Nr_rXrZrrrrY1s
zDailyLogFile.__getstate__N)r6r7r8r9rr#r^rfrFrr	rYrrrrr\�s
	r\c@s*eZdZdZdd�Zd
dd�Zdd�Zd	S)r4zRead from a log file.cCst|d�|_dS)z�
        Open the log file for reading.

        The comments about binary-mode for L{BaseLogFile._openFile} also apply
        here.
        �rN)r&r')rrrrrr=szLogReader.__init__�
cCs2g}t|�D] }|j��}|s"q.|�|�q|S)zRead a list of lines from the log file.

        This doesn't returns all of the files lines - call it multiple times.
        )�ranger'�readlinerU)r�linesrWrO�linerrr�	readLinesFs
zLogReader.readLinescCs|j��dSr?)r'r2r"rrrr2SszLogReader.closeN)rk)r6r7r8r9rrpr2rrrrr49s	

r4)r9Z
__future__rrrrRrarZtwisted.pythonrZtwisted.python._oldstylerZtwisted.python.compatrrr;Zsynchronizer\r4rrrr�<module>s |^
B