a
    xd                     @   sj   d dl mZ d dlZddlmZ ddlmZ d dlZh dZh dZ	G dd	 d	eZ
dddZdd ZdS )    )partialN   )AsyncResource)async_wraps>   closefdbuffermodeerrorsline_bufferingwritablenewlinesisattyname	getbufferfilenoreadableencodingseekablegetvaluerawclosed>   readtruncateflushtellpeekread1seekreadinto	readinto1readline
writelinesreadall	readlineswritec                       s\   e Zd ZdZdd Zedd Zdd Z fdd	Zd
d Z	dd Z
dd Zdd Z  ZS )AsyncIOWrapperaI  A generic :class:`~io.IOBase` wrapper that implements the :term:`asynchronous
    file object` interface. Wrapped methods that could block are executed in
    :meth:`trio.to_thread.run_sync`.

    All properties and methods defined in in :mod:`~io` are exposed by this
    wrapper, if they exist in the wrapped file object.

    c                 C   s
   || _ d S N_wrapped)selffile r+   E/var/www/html/Ranjet/env/lib/python3.9/site-packages/trio/_file_io.py__init__=   s    zAsyncIOWrapper.__init__c                 C   s   | j S )z.object: A reference to the wrapped file objectr'   r)   r+   r+   r,   wrapped@   s    zAsyncIOWrapper.wrappedc                    sb   |t v rt| j|S |tv rVt| j| t| j| jj| fdd}t| || |S t|d S )Nc                     s(   t  g| R i |}tj|I d H S r&   )r   trio	to_threadrun_sync)argskwargsfuncmethr+   r,   wrapperL   s    z+AsyncIOWrapper.__getattr__.<locals>.wrapper)_FILE_SYNC_ATTRSgetattrr(   _FILE_ASYNC_METHODSr   	__class__setattrAttributeError)r)   r   r8   r+   r6   r,   __getattr__F   s    zAsyncIOWrapper.__getattr__c                    sB   t t  }| fddtD  | fddtD  |S )Nc                 3   s   | ]}t  j|r|V  qd S r&   hasattrr/   .0ar.   r+   r,   	<genexpr>Y       z)AsyncIOWrapper.__dir__.<locals>.<genexpr>c                 3   s   | ]}t  j|r|V  qd S r&   r@   rB   r.   r+   r,   rE   Z   rF   )setsuper__dir__updater9   r;   )r)   attrsr<   r.   r,   rI   W   s    zAsyncIOWrapper.__dir__c                 C   s   | S r&   r+   r.   r+   r+   r,   	__aiter__]   s    zAsyncIOWrapper.__aiter__c                    s   |   I d H }|r|S td S r&   )r    StopAsyncIteration)r)   liner+   r+   r,   	__anext__`   s    zAsyncIOWrapper.__anext__c                    s   t j| jjI dH }t|S )zLike :meth:`io.BufferedIOBase.detach`, but async.

        This also re-wraps the result in a new :term:`asynchronous file object`
        wrapper.

        N)r0   r1   r2   r(   detach	wrap_file)r)   r   r+   r+   r,   rQ   g   s    zAsyncIOWrapper.detachc                    sV   t jdd& t j| jjI dH  W d   n1 s80    Y  t j I dH  dS )zLike :meth:`io.IOBase.close`, but async.

        This is also shielded from cancellation; if a cancellation scope is
        cancelled, the wrapped file object will still be safely closed.

        T)ZshieldN)r0   ZCancelScoper1   r2   r(   closeZlowlevelZcheckpoint_if_cancelledr.   r+   r+   r,   acloser   s    	4zAsyncIOWrapper.aclose)__name__
__module____qualname____doc__r-   propertyr/   r?   rI   rM   rP   rQ   rT   __classcell__r+   r+   rL   r,   r%   3   s   	
r%   rTc           	         s,   t tjtj| |||||||	I dH }|S )a+  Asynchronous version of :func:`io.open`.

    Returns:
        An :term:`asynchronous file object`

    Example::

        async with await trio.open_file(filename) as f:
            async for line in f:
                pass

        assert f.closed

    See also:
      :func:`trio.Path.open`

    N)rR   r0   r1   r2   ioopen)	r*   r   	bufferingr   r	   newliner   opener_filer+   r+   r,   	open_file   s    rc   c                    s:    fdd}|dr$|ds2|ds2t d t S )a[  This wraps any file object in a wrapper that provides an asynchronous
    file object interface.

    Args:
        file: a :term:`file object`

    Returns:
        An :term:`asynchronous file object` that wraps ``file``

    Example::

        async_file = trio.wrap_file(StringIO('asdf'))

        assert await async_file.read() == 'asdf'

    c                    s   t  | ott | S r&   )rA   callabler:   )attrr*   r+   r,   has   s    zwrap_file.<locals>.hasrS   r   r$   zK{} does not implement required duck-file methods: close and (read or write))	TypeErrorformatr%   )r*   rg   r+   rf   r,   rR      s    rR   )r[   r\   NNNTN)	functoolsr   r]   abcr   Z_utilr   r0   r9   r;   r%   rc   rR   r+   r+   r+   r,   <module>   s    P       
#