U
    
W[^  ã                   @   s"   d Z ddlmZ G dd„ dƒZdS )z°
Experimental optimization

This module provides a single mixin class which allows protocols to
collapse numerous small writes into a single larger one.

@author: Jp Calderone
é    )Úreactorc                   @   s<   e Zd ZdZdZdZdZdd„ Zdd„ Zdd	„ Z	d
d„ Z
dS )ÚBufferingMixinz+
    Mixin which adds write buffering.
    Ng        c                 C   s   t  | j| j¡S ©N)r   Z	callLaterÚDELAYÚflush©Úself© r	   ú5/usr/lib/python3/dist-packages/twisted/conch/mixin.pyÚschedule   s    zBufferingMixin.schedulec                 C   s   |  | j¡ d S r   )Úresetr   )r   Útokenr	   r	   r
   Ú
reschedule   s    zBufferingMixin.reschedulec                 C   s8   | j dkrg | _|  ¡ | _ n|  | j ¡ | j |¡ dS )a  
        Buffer some bytes to be written soon.

        Every call to this function delays the real write by C{self.DELAY}
        seconds.  When the delay expires, all collected bytes are written
        to the underlying transport using L{ITransport.writeSequence}.
        N)Ú_delayedWriteCallÚdatar   r   Úappend)r   r   r	   r	   r
   Úwrite!   s
    
zBufferingMixin.writec                 C   s   d| _ | j | j¡ d| _dS )z/
        Flush the buffer immediately.
        N)r   Z	transportZwriteSequencer   r   r	   r	   r
   r   1   s    zBufferingMixin.flush)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r	   r	   r	   r
   r      s   r   N)r   Ztwisted.internetr   r   r	   r	   r	   r
   Ú<module>   s   	