U
    uõ?dµ
  ã                   @   s:   d dl Z d dlmZmZ ddlmZ G dd„ de jƒZdS )é    N)ÚOptionalÚcasté   )Útcp_nodelayc                   @   s    e Zd ZdZejddœdd„Zeedœdd„ƒZ	ddœd	d
„Z
ddœdd„Zddœdd„Zddœdd„Zejddœdd„Zee ddœdd„Zddœdd„ZdS )ÚBaseProtocol)Ú_loopÚ_pausedÚ_drain_waiterZ_connection_lostÚ_reading_pausedÚ	transportN)ÚloopÚreturnc                 C   s"   || _ d| _d | _d| _d | _d S ©NF)r   r   r	   r
   r   )Úselfr   © r   ú9/tmp/pip-unpacked-wheel-_pk67_um/aiohttp/base_protocol.pyÚ__init__   s
    zBaseProtocol.__init__)r   c                 C   s
   | j dk	S )z&Return True if the connection is open.N)r   ©r   r   r   r   Ú	connected   s    zBaseProtocol.connectedc                 C   s   | j r
t‚d| _ d S ©NT)r   ÚAssertionErrorr   r   r   r   Úpause_writing   s    
zBaseProtocol.pause_writingc                 C   s:   | j s
t‚d| _ | j}|d k	r6d | _| ¡ s6| d ¡ d S r   )r   r   r	   ÚdoneÚ
set_result©r   Úwaiterr   r   r   Úresume_writing"   s    
zBaseProtocol.resume_writingc              
   C   sD   | j s@| jd k	r@z| j ¡  W n tttfk
r8   Y nX d| _ d S r   )r
   r   Úpause_readingÚAttributeErrorÚNotImplementedErrorÚRuntimeErrorr   r   r   r   r   ,   s    zBaseProtocol.pause_readingc              
   C   sD   | j r@| jd k	r@z| j ¡  W n tttfk
r8   Y nX d| _ d S r   )r
   r   Úresume_readingr   r   r    r   r   r   r   r!   4   s    zBaseProtocol.resume_reading)r   r   c                 C   s    t tj|ƒ}t|dƒ || _d S r   )r   ÚasyncioÚ	Transportr   r   )r   r   Útrr   r   r   Úconnection_made<   s    
zBaseProtocol.connection_made)Úexcr   c                 C   sV   d | _ | jsd S | j}|d kr"d S d | _| ¡ r4d S |d krH| d ¡ n
| |¡ d S )N)r   r   r	   r   r   Zset_exception)r   r&   r   r   r   r   Úconnection_lostA   s    zBaseProtocol.connection_lostc                 Ã   sJ   | j stdƒ‚| jsd S | j}|d kr6| j ¡ }|| _t |¡I d H  d S )NzConnection lost)r   ÚConnectionResetErrorr   r	   r   Zcreate_futurer"   Zshieldr   r   r   r   Ú_drain_helperQ   s    
zBaseProtocol._drain_helper)Ú__name__Ú
__module__Ú__qualname__Ú	__slots__r"   ZAbstractEventLoopr   ÚpropertyÚboolr   r   r   r   r!   ZBaseTransportr%   r   ÚBaseExceptionr'   r)   r   r   r   r   r      s   	
r   )r"   Útypingr   r   Ztcp_helpersr   ÚProtocolr   r   r   r   r   Ú<module>   s   