U
    “öhø  ã                   @   s\   d Z ddlmZ ddlmZ ddlmZ G dd„ dƒZG dd„ deƒZG d	d
„ d
eeƒZ	dS )zVarious base classes.é    )Ú	Awaitable)ÚAbstractAsyncContextManager)Úget_running_loopc                       s@   e Zd Zdd„ Zedd„ ƒZdd„ Z‡ fdd„Zd	d
„ Z‡  Z	S )Ú	AsyncBasec                 C   s   || _ || _|| _d S ©N)Ú_fileZ	_executorÚ	_ref_loop)ÚselfÚfileÚloopÚexecutor© r   ú1/tmp/pip-unpacked-wheel-vua3_usf/aiofiles/base.pyÚ__init__   s    zAsyncBase.__init__c                 C   s   | j p
tƒ S r   )r   r   ©r	   r   r   r   Ú_loop   s    zAsyncBase._loopc                 C   s   | S )zWe are our own iterator.r   r   r   r   r   Ú	__aiter__   s    zAsyncBase.__aiter__c                    s   t ƒ  ¡ d t| jƒ S )Nz
 wrapping )ÚsuperÚ__repr__Úreprr   r   ©Ú	__class__r   r   r      s    zAsyncBase.__repr__c                 Ã   s   |   ¡ I dH }|r|S t‚dS )zSimulate normal file iteration.N)ÚreadlineÚStopAsyncIteration)r	   Úliner   r   r   Ú	__anext__   s    zAsyncBase.__anext__)
Ú__name__Ú
__module__Ú__qualname__r   Úpropertyr   r   r   r   Ú__classcell__r   r   r   r   r      s   
r   c                       s6   e Zd Z‡ fdd„Zedd„ ƒZejdd„ ƒZ‡  ZS )ÚAsyncIndirectBasec                    s    || _ || _tƒ  d ||¡ d S r   )Ú	_indirectÚ_namer   r   )r	   Únamer   r   Zindirectr   r   r   r   "   s    zAsyncIndirectBase.__init__c                 C   s   |   ¡ S r   )r"   r   r   r   r   r   '   s    zAsyncIndirectBase._filec                 C   s   d S r   r   )r	   Úvr   r   r   r   +   s    )r   r   r   r   r   r   Úsetterr    r   r   r   r   r!   !   s
   
r!   c                   @   s4   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚAiofilesContextManagerz/An adjusted async context manager for aiofiles.©Ú_coroÚ_objc                 C   s   || _ d | _d S r   r(   )r	   Úcoror   r   r   r   5   s    zAiofilesContextManager.__init__c                 c   s"   | j d kr| j ¡ E d H | _ | j S r   )r*   r)   Ú	__await__r   r   r   r   r,   9   s    
z AiofilesContextManager.__await__c                 Ã   s
   | I d H S r   r   r   r   r   r   Ú
__aenter__>   s    z!AiofilesContextManager.__aenter__c                 Ã   s*   t ƒ  d | jjj|||¡I d H  d | _d S r   )r   Zrun_in_executorr*   r   Ú__exit__)r	   Úexc_typeÚexc_valÚexc_tbr   r   r   Ú	__aexit__A   s        ÿ
z AiofilesContextManager.__aexit__N)	r   r   r   Ú__doc__Ú	__slots__r   r,   r-   r2   r   r   r   r   r'   0   s   r'   N)
r3   Úcollections.abcr   Ú
contextlibr   Zasyncior   r   r!   r'   r   r   r   r   Ú<module>   s   