[issue4972] let's equip ftplib.FTP with __enter__ and __exit__
Alexander Belopolsky
report at bugs.python.org
Mon Jan 19 22:21:58 CET 2009
Alexander Belopolsky <belopolsky at users.sourceforge.net> added the comment:
On Mon, Jan 19, 2009 at 2:01 PM, Tarek Ziadé <report at bugs.python.org> wrote:
>
> Tarek Ziadé <ziade.tarek at gmail.com> added the comment:
>
>> What is the rationale for swallowing all socket exceptions except
>> "Connection reset by peer" in __exit__?
>
> I am catching just the error that raises if the connection is closed
> when calling quit()
>
I see. I misread the double negative "except errno NOT equals 54", but
I still don't see the rationale for that exception. I any case, I
don't think your patch implements that because SMTP transforms socket
errors into SMTPServer* errors in send():
if self.sock:
try:
self.sock.sendall(str)
except socket.error:
self.close()
raise SMTPServerDisconnected('Server not connected')
else:
raise SMTPServerDisconnected('please run connect() first')
so you will never see a socket error from quit().
Furthermore, I don't think you should ignore return code from quit():
you should raise an error if it returns anything but 221.
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4972>
_______________________________________
More information about the Python-bugs-list
mailing list