8000 [3.12] gh-131888: fix ResourceWarning in test_ftplib (GH-131889) by miss-islington · Pull Request #132010 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.12] gh-131888: fix ResourceWarning in test_ftplib (GH-131889) #132010

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 2, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-131888: fix ResourceWarning in test_ftplib (GH-131889)
(cherry picked from commit b0f77c4)

Co-authored-by: Thomas Grainger <tagrain@gmail.com>
  • Loading branch information
graingert authored and miss-islington committed Apr 2, 2025
commit 90a76ea36eb3cf8c4c92e5334e5f1c315860d494
13 changes: 8 additions & 5 deletions Lib/test/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def handle_close(self):
# (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):
Expand All @@ -94,6 +94,9 @@ def push(self, what):
def handle_error(self):
default_error_handler()

def shutdown(self):
self.close()


class DummyFTPHandler(asynchat.async_chat):

Expand Down Expand Up @@ -226,7 +229,7 @@ def cmd_type(self, arg):

def cmd_quit(self, arg):
self.push('221 quit ok')
self.close()
self.shutdown()

def cmd_abor(self, arg):
self.push('226 abor ok')
Expand Down Expand Up @@ -313,7 +316,7 @@ def handle_accepted(self, conn, addr):
self.handler_instance = self.handler(conn, encoding=self.encoding)

def handle_connect(self):
self.close()
self.shutdown()
handle_read = handle_connect

def writable(self):
Expand Down Expand Up @@ -425,12 +428,12 @@ def recv(self, buffer_size):
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):
Expand Down
Loading
0