1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
U
Z±dÊã@s ddlmZddlZddlmZddlmZddlZdddd    d
d d d dddddddddhZdddddddddd d!d"d#d$hZ    Gd%d&„d&eƒZ
d.d*d+„Z d,d-„Z dS)/é)ÚpartialNé)Ú AsyncResource)Ú async_wrapsÚclosedÚencodingÚerrorsÚfilenoÚisattyÚnewlinesÚreadableÚseekableÚwritableÚbufferÚrawÚline_bufferingÚclosefdÚnameÚmodeÚgetvalueÚ    getbufferÚflushÚreadÚread1ÚreadallÚreadintoÚreadlineÚ    readlinesÚseekÚtellÚtruncateÚwriteÚ
writelinesÚ    readinto1Úpeekcs\eZdZdZdd„Zedd„ƒZdd„Z‡fdd    „Zd
d „Z    d d „Z
dd„Z dd„Z ‡Z S)ÚAsyncIOWrapperaIA 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.
 
    cCs
||_dS©N©Ú_wrapped)ÚselfÚfile©r+úDd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\trio/_file_io.pyÚ__init__=szAsyncIOWrapper.__init__cCs|jS)z.object: A reference to the wrapped file objectr'©r)r+r+r,Úwrapped@szAsyncIOWrapper.wrappedcsb|tkrt|j|ƒS|tkrVt|j|ƒ‰t|j|jj|ƒ‡fdd„ƒ}t|||ƒ|St|ƒ‚dS)NcŸs"tˆf|ž|Ž}tj |¡IdHSr&)rÚtrioÚ    to_threadÚrun_sync)ÚargsÚkwargsÚfunc©Úmethr+r,ÚwrapperLsz+AsyncIOWrapper.__getattr__.<locals>.wrapper)Ú_FILE_SYNC_ATTRSÚgetattrr(Ú_FILE_ASYNC_METHODSrÚ    __class__ÚsetattrÚAttributeError)r)rr8r+r6r,Ú __getattr__Fs   zAsyncIOWrapper.__getattr__csBttƒ ¡ƒ}| ‡fdd„tDƒ¡| ‡fdd„tDƒ¡|S)Nc3s|]}tˆj|ƒr|VqdSr&©Úhasattrr/©Ú.0Úar.r+r,Ú    <genexpr>Ys z)AsyncIOWrapper.__dir__.<locals>.<genexpr>c3s|]}tˆj|ƒr|VqdSr&r@rBr.r+r,rEZs )ÚsetÚsuperÚ__dir__Úupdater9r;)r)Úattrs©r<r.r,rHWszAsyncIOWrapper.__dir__cCs|Sr&r+r.r+r+r,Ú    __aiter__]szAsyncIOWrapper.__aiter__cÃs| ¡IdH}|r|St‚dSr&)rÚStopAsyncIteration)r)Úliner+r+r,Ú    __anext__`szAsyncIOWrapper.__anext__cÃstj |jj¡IdH}t|ƒS)zLike :meth:`io.BufferedIOBase.detach`, but async.
 
        This also re-wraps the result in a new :term:`asynchronous file object`
        wrapper.
 
        N)r0r1r2r(ÚdetachÚ    wrap_file)r)rr+r+r,rPgszAsyncIOWrapper.detachc    ÃsBtjddtj |jj¡IdHW5QRXtj ¡IdHdS)zÇLike :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)ZshieldN)r0Z CancelScoper1r2r(ÚcloseZlowlevelZcheckpoint_if_cancelledr.r+r+r,Úaclosers     zAsyncIOWrapper.aclose)Ú__name__Ú
__module__Ú __qualname__Ú__doc__r-Úpropertyr/r?rHrLrOrPrSÚ __classcell__r+r+rKr,r%3s    
  r%ÚréÿÿÿÿTc     Ãs,ttj tj||||||||¡    IdHƒ}|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)rQr0r1r2ÚioÚopen)    r*rÚ    bufferingrrÚnewlinerÚopenerÚ_filer+r+r,Ú    open_filesÿÿrbcs:‡fdd„}|dƒr$|dƒs2|dƒs2td ˆ¡ƒ‚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'
 
    cstˆ|ƒottˆ|ƒƒSr&)rAÚcallabler:)Úattr©r*r+r,Úhas¶szwrap_file.<locals>.hasrRrr!zK{} does not implement required duck-file methods: close and (read or write))Ú    TypeErrorÚformatr%)r*rfr+rer,rQ¤s ÿÿrQ)rZr[NNNTN) Ú    functoolsrr\ÚabcrZ_utilrr0r9r;r%rbrQr+r+r+r,Ú<module>s^   îñPø
#