gh-131888: fix ResourceWarning in test_ftplib (#131889)

This commit is contained in:
Thomas Grainger 2025-04-02 13:30:19 +01:00 committed by GitHub
parent ab2a3dda1d
commit b0f77c4d25
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -81,7 +81,7 @@ class DummyDTPHandler(asynchat.async_chat):
# (behaviour witnessed with test_data_connection)
if not self.dtp_conn_closed:
self.baseclass.push('226 transfer complete')
self.close()
self.shutdown()
self.dtp_conn_closed = True
def push(self, what):
@ -95,6 +95,9 @@ class DummyDTPHandler(asynchat.async_chat):
def handle_error(self):
default_error_handler()
def shutdown(self):
self.close()
class DummyFTPHandler(asynchat.async_chat):
@ -227,7 +230,7 @@ class DummyFTPHandler(asynchat.async_chat):
def cmd_quit(self, arg):
self.push('221 quit ok')
self.close()
self.shutdown()
def cmd_abor(self, arg):
self.push('226 abor ok')
@ -314,7 +317,7 @@ class DummyFTPServer(asyncore.dispatcher, threading.Thread):
self.handler_instance = self.handler(conn, encoding=self.encoding)
def handle_connect(self):
self.close()
self.shutdown()
handle_read = handle_connect
def writable(self):
@ -426,12 +429,12 @@ if ssl is not None:
def handle_error(self):
default_error_handler()
def close(self):
def shutdown(self):
if (isinstance(self.socket, ssl.SSLSocket) and
self.socket._sslobj is not None):
self._do_ssl_shutdown()
else:
super(SSLConnection, self).close()
self.close()
class DummyTLS_DTPHandler(SSLConnection, DummyDTPHandler):