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