U
    
W[k                     @   s,   d Z ddlZddlmZ G dd deZdS )z
File-like object that logs.
    N   )LogLevelc                   @   s   e Zd ZdZdZejdfddZedd Z	edd	 Z
ed
d Zedd Zedd Zdd Zdd Zdd Zdd Zdd Zdd Zdd ZeZeZeZeZeZeZeZeZdS )LoggingFilean  
    File-like object that turns C{write()} calls into logging events.

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

    @ivar softspace: File-like L{'softspace' attribute <file.softspace>}; zero
        or one.
    @type softspace: L{int}
    r   Nc                 C   s6   || _ || _|dkr t | _n|| _d| _d| _dS )at  
        @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()}.
        @type encoding: L{str}

        @param log: The logger to send events to.
        @type log: L{Logger}
        N F)levellogsysgetdefaultencoding	_encoding_buffer_closed)selfZloggerr   encoding r   4/usr/lib/python3/dist-packages/twisted/logger/_io.py__init__   s    zLoggingFile.__init__c                 C   s   | j S )z
        Read-only property.  Is the file closed?

        @return: true if closed, otherwise false.
        @rtype: L{bool}
        r   r   r   r   r   closed8   s    zLoggingFile.closedc                 C   s   | j S )zl
        Read-only property.   File encoding.

        @return: an encoding.
        @rtype: L{str}
        )r
   r   r   r   r   r   C   s    zLoggingFile.encodingc                 C   s   dS )z^
        Read-only property.  File mode.

        @return: "w"
        @rtype: L{str}
        wr   r   r   r   r   modeN   s    zLoggingFile.modec                 C   s   dS )zw
        Read-only property.  Types of newlines encountered.

        @return: L{None}
        @rtype: L{None}
        Nr   r   r   r   r   newlinesY   s    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.
        @rtype: L{str}
        z<{0} {1}#{2}>)format	__class____name__r   	namespacer   namer   r   r   r   r   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   closev   s    zLoggingFile.closec                 C   s   dS )z3
        No-op; this file does not buffer.
        Nr   r   r   r   r   flush}   s    zLoggingFile.flushc                 C   s   dS )z
        Returns an invalid file descriptor, since this is not backed by an FD.

        @return: C{-1}
        @rtype: L{int}
        r   r   r   r   r   fileno   s    zLoggingFile.filenoc                 C   s   dS )zc
        A L{LoggingFile} is not a TTY.

        @return: C{False}
        @rtype: L{bool}
        Fr   r   r   r   r   isatty   s    zLoggingFile.isattyc                 C   sl   | j rtdt|tr$|| j}| j| d}|d | _|dd }|D ]}| jj	| j
d|d qNdS )z
        Log the given message.

        @param string: Data to write.
        @type string: L{bytes} in this file's preferred encoding or L{unicode}
        zI/O operation on closed file
r   r   z{log_io})r   Zlog_ioN)r   
ValueError
isinstancebytesdecoder
   r   splitr   emitr   )r   stringlinesliner   r   r   write   s    

zLoggingFile.writec                 C   s   |D ]}|  | qdS )z
        Log each of the given lines as a separate message.

        @param lines: Data to write.
        @type lines: iterable of L{unicode} or L{bytes} in this file's
            declared encoding
        N)r,   )r   r*   r+   r   r   r   
writelines   s    zLoggingFile.writelinesc                 G   s   t ddS )z~
        Template for unsupported operations.

        @param args: Arguments.
        @type args: tuple of L{object}
        zunsupported operationN)IOError)r   argsr   r   r   _unsupported   s    zLoggingFile._unsupported)r   
__module____qualname____doc__Z	softspacer   infor   propertyr   r   r   r   r   r   r   r    r!   r,   r-   r0   readnextreadline	readlinesZ
xreadlinesseektelltruncater   r   r   r   r      s8   











r   )r3   r   Z_levelsr   objectr   r   r   r   r   <module>   s   