finalization
This commit is contained in:
parent
396f7fa6e9
commit
e5eb222799
|
|
@ -1,2 +1,3 @@
|
|||
from ._aftplib import AFTP
|
||||
from .operations import download_text
|
||||
from ftplib import Error as FTPLibError
|
||||
|
|
|
|||
|
|
@ -58,15 +58,20 @@ class AFTP(ftplib.FTP):
|
|||
def _finalize():
|
||||
fp.close()
|
||||
conn.close()
|
||||
self.voidresp()
|
||||
|
||||
try:
|
||||
while True:
|
||||
try:
|
||||
line = await trio.to_thread.run_sync(fp.readline)
|
||||
if not line:
|
||||
break
|
||||
yield line
|
||||
finally:
|
||||
except Exception:
|
||||
await trio.to_thread.run_sync(_finalize)
|
||||
|
||||
raise
|
||||
if not line:
|
||||
await trio.to_thread.run_sync(_finalize)
|
||||
await trio.to_thread.run_sync(self.voidresp) # check the response code
|
||||
break
|
||||
try:
|
||||
yield line
|
||||
except GeneratorExit:
|
||||
await trio.to_thread.run_sync(_finalize)
|
||||
raise
|
||||
|
||||
|
|
|
|||
|
|
@ -8,3 +8,4 @@ async def test_tso_sinaf():
|
|||
path='MIC.NAF.MZ.BBD2.M130D001.D200306')) as _text:
|
||||
async for line in _text:
|
||||
assert line.count('@') == 15
|
||||
break
|
||||
|
|
|
|||
Loading…
Reference in New Issue