finalization

This commit is contained in:
c056091 2020-03-13 17:07:28 -03:00
parent 396f7fa6e9
commit e5eb222799
3 changed files with 15 additions and 8 deletions

View File

@ -1,2 +1,3 @@
from ._aftplib import AFTP
from .operations import download_text
from ftplib import Error as FTPLibError

View File

@ -58,15 +58,20 @@ class AFTP(ftplib.FTP):
def _finalize():
fp.close()
conn.close()
self.voidresp()
try:
while True:
while True:
try:
line = await trio.to_thread.run_sync(fp.readline)
if not line:
break
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
finally:
await trio.to_thread.run_sync(_finalize)
except GeneratorExit:
await trio.to_thread.run_sync(_finalize)
raise

View File

@ -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