U
    ˆjÀ  ã                   @   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eeee d	d
œdd„Zeedœdd„ƒZeedœdd„ƒZeedœdd„ƒZed	dœdd„ƒZeedœdd„ƒZd	dœdd„Zd	dœdd„Zedœdd„Zedœdd„Zed	d œd!d"„Zee d	d#œd$d%„Ze d	d&œ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   ZTwistedé   é   c                 C   s   | j S ©N©Ú
_softspace©Úself© r   ú6/tmp/pip-unpacked-wheel-j5h_c8_q/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k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__)r   c                 C   s   | j S )zm
        Read-only property.  Is the file closed?

        @return: true if closed, otherwise false.
        ©r!   r   r   r   r   Úclosed@   s    zLoggingFile.closedc                 C   s   | j S )zU
        Read-only property.   File encoding.

        @return: an encoding.
        )r   r   r   r   r   r   I   s    zLoggingFile.encodingc                 C   s   dS )zG
        Read-only property.  File mode.

        @return: "w"
        Úwr   r   r   r   r   ÚmodeR   s    zLoggingFile.modec                 C   s   dS )z_
        Read-only property.  Types of newlines encountered.

        @return: L{None}
        Nr   r   r   r   r   Únewlines[   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.
        z
<{} {}#{}>)Ú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   Úcloser   s    zLoggingFile.closec                 C   s   dS )z3
        No-op; this file does not buffer.
        Nr   r   r   r   r   Úflushx   s    zLoggingFile.flushc                 C   s   dS )zp
        Returns an invalid file descriptor, since this is not backed by an FD.

        @return: C{-1}
        éÿÿÿÿr   r   r   r   r   Úfileno~   s    zLoggingFile.filenoc                 C   s   dS )zK
        A L{LoggingFile} is not a TTY.

        @return: C{False}
        Fr   r   r   r   r   Úisatty†   s    zLoggingFile.isatty)Úmessager   c                 C   sr   | j rtdƒ‚t|tƒr&| | j¡}n|}| j|  d¡}|d | _|dd… }|D ]}| jj	| j
d|d� qTdS )zW
        Log the given message.

        @param message: The message to write.
        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   r2   ÚtextÚlinesÚliner   r   r   ÚwriteŽ   s    

zLoggingFile.write)r;   r   c                 C   s   |D ]}|   |¡ qdS )zj
        Log each of the given lines as a separate message.

        @param lines: Data to write.
        N)r=   )r   r;   r<   r   r   r   Ú
writelines£   s    zLoggingFile.writelines)Úargsr   c                 G   s   t dƒ‚dS )zW
        Template for unsupported operations.

        @param args: Arguments.
        zunsupported operationN)ÚOSError)r   r?   r   r   r   Ú_unsupported¬   s    zLoggingFile._unsupported)*r*   Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úsetterr	   Úinfor
   r   r   Ústrr"   ÚpropertyÚboolr$   r   r&   r'   r,   r-   r.   Úintr0   r1   r   r=   r   r>   ÚobjectrA   ÚreadÚnextÚreadlineÚ	readlinesZ
xreadlinesÚseekÚtellÚtruncater   r   r   r   r      sN   


üû	r   )rD   r   Útypingr   r   r   Z
constantlyr   Úincrementalr   Ztwisted.python.deprecater   Z_levelsr	   Z_loggerr
   r   r   r   r   r   Ú<module>   s   