This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author giampaolo.rodola
Recipients belopolsky, giampaolo.rodola, pitrou, tarek
Date 2009-01-23.01:44:20
SpamBayes Score 7.9381226e-07
Marked as misclassified No
Message-id <1232675063.76.0.114823678626.issue4972@psf.upfronthosting.co.za>
In-reply-to
Content
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()
History
Date User Action Args
2009-01-23 01:44:24giampaolo.rodolasetrecipients: + giampaolo.rodola, belopolsky, pitrou, tarek
2009-01-23 01:44:23giampaolo.rodolasetmessageid: <1232675063.76.0.114823678626.issue4972@psf.upfronthosting.co.za>
2009-01-23 01:44:22giampaolo.rodolalinkissue4972 messages
2009-01-23 01:44:20giampaolo.rodolacreate