o
    b                     @   sn   d Z ddlZddlmZmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZ dd	lmZ G d
d dZdS )z
File-like object that logs.
    N)AnyStrIterableOptional)NamedConstant)Version)deprecatedProperty   )LogLevel)Loggerc                	   @   sB  e Zd ZdZdZeedddddd Zejdd Ze	j
d	fd
ededee dd	fddZedefddZedefddZedefddZed+ddZedefddZd+ddZd+ddZdefddZdefd d!Zd"edd	fd#d$Zd%ee dd	fd&d'Zd(e dd	fd)d*Z!e!Z"e!Z#e!Z$e!Z%e!Z&e!Z'e!Z(e!Z)d	S ),LoggingFileac  
    File-like object that turns C{write()} calls into logging events.

    Note that because event formats are L{str}, C{bytes} received via C{write()}
    are converted to C{str}, which is the opposite of what C{file} does.

    @ivar softspace: Attribute to make this class more file-like under Python 2;
        value is zero or one.  Do not use.
    r   Twisted      c                 C      | j S N
_softspaceself r   4/usr/lib/python3/dist-packages/twisted/logger/_io.py	softspace!   s   zLoggingFile.softspacec                 C   s
   || _ d S r   r   )r   valuer   r   r   r   %   s   
Nloggerlevelencodingreturnc                 C   s6   || _ || _|du rt | _n|| _d| _d| _dS )a  
        @param logger: the logger to log through.
        @param level: the log level to emit events with.
        @param encoding: The encoding to expect when receiving bytes via
            C{write()}.  If L{None}, use C{sys.getdefaultencoding()}.
        N F)r   logsysgetdefaultencoding	_encoding_buffer_closed)r   r   r   r   r   r   r   __init__)   s   
zLoggingFile.__init__c                 C   r   )zm
        Read-only property.  Is the file closed?

        @return: true if closed, otherwise false.
        r#   r   r   r   r   closed@      zLoggingFile.closedc                 C   r   )zU
        Read-only property.   File encoding.

        @return: an encoding.
        )r!   r   r   r   r   r   I   r'   zLoggingFile.encodingc                 C      dS )zG
        Read-only property.  File mode.

        @return: "w"
        wr   r   r   r   r   modeR      zLoggingFile.modec                 C   r(   )z_
        Read-only property.  Types of newlines encountered.

        @return: L{None}
        Nr   r   r   r   r   newlines[   r+   zLoggingFile.newlinesc                 C   s   d | jj| jj| jjS )z
        The name of this file; a repr-style string giving information about its
        namespace.

        @return: A file name.
        z
<{} {}#{}>)format	__class____name__r   	namespacer   namer   r   r   r   r1   d   s
   zLoggingFile.namec                 C   s
   d| _ dS )zD
        Close this file so it can no longer be written to.
        TNr%   r   r   r   r   closer   s   
zLoggingFile.closec                 C   r(   )z3
        No-op; this file does not buffer.
        Nr   r   r   r   r   flushx   s   zLoggingFile.flushc                 C   r(   )zp
        Returns an invalid file descriptor, since this is not backed by an FD.

        @return: C{-1}
        r   r   r   r   r   fileno~      zLoggingFile.filenoc                 C   r(   )zK
        A L{LoggingFile} is not a TTY.

        @return: C{False}
        Fr   r   r   r   r   isatty   r6   zLoggingFile.isattymessagec                 C   sr   | j rtdt|tr|| j}n|}| j| d}|d | _|dd }|D ]}| jj	| j
d|d q*dS )zW
        Log the given message.

        @param message: The message to write.
        zI/O operation on closed file
r4   r   z{log_io})r-   log_ioN)r#   
ValueError
isinstancebytesdecoder!   r"   splitr   emitr   )r   r8   textlinesliner   r   r   write   s   

zLoggingFile.writerB   c                 C   s   |D ]}|  | qdS )zj
        Log each of the given lines as a separate message.

        @param lines: Data to write.
        N)rD   )r   rB   rC   r   r   r   
writelines   s   zLoggingFile.writelinesargsc                 G   s   t d)zW
        Template for unsupported operations.

        @param args: Arguments.
        zunsupported operation)OSError)r   rF   r   r   r   _unsupported   s   zLoggingFile._unsupported)r   N)*r/   
__module____qualname____doc__r   r   r   r   setterr	   infor
   r   r   strr$   propertyboolr&   r   r*   r,   r1   r2   r3   intr5   r7   r   rD   r   rE   objectrH   readnextreadline	readlines
xreadlinesseektelltruncater   r   r   r   r      sV    





	r   )rK   r   typingr   r   r   
constantlyr   incrementalr   twisted.python.deprecater   _levelsr	   _loggerr
   r   r   r   r   r   <module>   s   