Giampaolo Rodola' <billiej...@users.sourceforge.net> added the comment:

As for ftplib patch you should make sure that close() gets called in any
case but never more than once.
You can use "finally" to satisfy the first requirement and "self.sock is
not None" to check the second condition:



+    def __exit__(self, *args):
+        """Context management protocol.
+
+        Will try to quit() if active, then close().
+        If not active, a simple close() call is made.
+        """
+        if self.sock is not None and self.getwelcome() is not None:
+            try:
+                self.quit()
+            except socket.error, e:
+                # [Errno 61] is Connection refused
+                # if the error is different, we want to raise it.
+                if e.errno != 61:
+                    raise
+            finally:
+                if self.sock is not None:
+                    self.close()
+        else:
+            self.close()

----------
nosy: +giampaolo.rodola

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue4972>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to