[issue4972] let's equip ftplib.FTP with __enter__ and __exit__

Tarek Ziadé report at bugs.python.org
Mon Jan 19 20:01:23 CET 2009


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()


> In any case, it is better to use errno.ECONNRESET instead of literal 54.

Right

> Note that SMTP.quit() calls SMTP.close(), so in the normal termination 
> case, close will be called twice.  This is not a real problem since 
> SMTP.close() is a noop on a closed SMTP object, but it does not look 
> right.

Right i'll fix that

Thanks for teh feedback
The double call to close() also makes error path harder to analyze.  It 
appears that if a socket error is raised in the first call to close, it 
gets caught only to be raised again in the second call (assuming a 
persistent error).

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4972>
_______________________________________


More information about the Python-bugs-list mailing list