summaryrefslogtreecommitdiff
path: root/Lib/test/test_ftplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2010-04-09 22:41:31 +0000
committerAntoine Pitrou <solipsis@pitrou.net>2010-04-09 22:41:31 +0000
commit343314a11c6d91c2483c53d3871d3d69f8065fe7 (patch)
tree55c0724770da6ff5a8a2b8ea9ca7bb3a2bf7191e /Lib/test/test_ftplib.py
parent9c6cd56e9177cda47f3b836159696f6471408b47 (diff)
downloadcpython-git-343314a11c6d91c2483c53d3871d3d69f8065fe7.tar.gz
Revert r79915 (temporary commit to check for buildbots -> the fix was successful)
Diffstat (limited to 'Lib/test/test_ftplib.py')
-rw-r--r--Lib/test/test_ftplib.py47
1 files changed, 11 insertions, 36 deletions
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 4f6d1c12b2..182d5a7c74 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -29,7 +29,6 @@ NLST_DATA = 'foo\r\nbar\r\n'
class DummyDTPHandler(asynchat.async_chat):
- dtp_conn_closed = False
def __init__(self, conn, baseclass):
asynchat.async_chat.__init__(self, conn)
@@ -40,13 +39,8 @@ class DummyDTPHandler(asynchat.async_chat):
self.baseclass.last_received_data += self.recv(1024)
def handle_close(self):
- # XXX: this method can be called many times in a row for a single
- # connection, including in clear-text (non-TLS) mode.
- # (behaviour witnessed with test_data_connection)
- if not self.dtp_conn_closed:
- self.baseclass.push('226 transfer complete')
- self.close()
- self.dtp_conn_closed = True
+ self.baseclass.push('226 transfer complete')
+ self.close()
class DummyFTPHandler(asynchat.async_chat):
@@ -259,7 +253,6 @@ if ssl is not None:
"""An asyncore.dispatcher subclass supporting TLS/SSL."""
_ssl_accepting = False
- _ssl_closing = False
def secure_connection(self):
self.socket = ssl.wrap_socket(self.socket, suppress_ragged_eofs=False,
@@ -284,36 +277,15 @@ if ssl is not None:
else:
self._ssl_accepting = False
- def _do_ssl_shutdown(self):
- self._ssl_closing = True
- try:
- self.socket = self.socket.unwrap()
- except ssl.SSLError, err:
- if err.args[0] in (ssl.SSL_ERROR_WANT_READ,
- ssl.SSL_ERROR_WANT_WRITE):
- return
- except socket.error, err:
- # Any "socket error" corresponds to a SSL_ERROR_SYSCALL return
- # from OpenSSL's SSL_shutdown(), corresponding to a
- # closed socket condition. See also:
- # http://www.mail-archive.com/openssl-users@openssl.org/msg60710.html
- pass
- self._ssl_closing = False
- super(SSLConnection, self).close()
-
def handle_read_event(self):
if self._ssl_accepting:
self._do_ssl_handshake()
- elif self._ssl_closing:
- self._do_ssl_shutdown()
else:
super(SSLConnection, self).handle_read_event()
def handle_write_event(self):
if self._ssl_accepting:
self._do_ssl_handshake()
- elif self._ssl_closing:
- self._do_ssl_shutdown()
else:
super(SSLConnection, self).handle_write_event()
@@ -343,9 +315,12 @@ if ssl is not None:
raise
def close(self):
- if (isinstance(self.socket, ssl.SSLSocket) and
- self.socket._sslobj is not None):
- self._do_ssl_shutdown()
+ try:
+ if isinstance(self.socket, ssl.SSLSocket):
+ if self.socket._sslobj is not None:
+ self.socket.unwrap()
+ finally:
+ super(SSLConnection, self).close()
class DummyTLS_DTPHandler(SSLConnection, DummyDTPHandler):
@@ -622,21 +597,21 @@ class TestTLS_FTPClass(TestCase):
sock = self.client.transfercmd('list')
self.assertNotIsInstance(sock, ssl.SSLSocket)
sock.close()
- self.assertEqual(self.client.voidresp(), "226 transfer complete")
+ self.client.voidresp()
# secured, after PROT P
self.client.prot_p()
sock = self.client.transfercmd('list')
self.assertIsInstance(sock, ssl.SSLSocket)
sock.close()
- self.assertEqual(self.client.voidresp(), "226 transfer complete")
+ self.client.voidresp()
# PROT C is issued, the connection must be in cleartext again
self.client.prot_c()
sock = self.client.transfercmd('list')
self.assertNotIsInstance(sock, ssl.SSLSocket)
sock.close()
- self.assertEqual(self.client.voidresp(), "226 transfer complete")
+ self.client.voidresp()
def test_login(self):
# login() is supposed to implicitly secure the control connection