Skip to content

Commit 24befa8

Browse files
committed
merge with 3.1
2 parents 4c1aebd + 0b5c21f commit 24befa8

3 files changed

Lines changed: 21 additions & 1 deletion

File tree

Lib/ftplib.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,12 +241,13 @@ def abort(self):
241241
This does not follow the procedure from the RFC to send Telnet
242242
IP and Synch; that doesn't seem to work with the servers I've
243243
tried. Instead, just send the ABOR command as OOB data.'''
244-
line = 'ABOR' + CRLF
244+
line = b'ABOR' + B_CRLF
245245
if self.debugging > 1: print('*put urgent*', self.sanitize(line))
246246
self.sock.sendall(line, MSG_OOB)
247247
resp = self.getmultiline()
248248
if resp[:3] not in {'426', '225', '226'}:
249249
raise error_proto(resp)
250+
return resp
250251

251252
def sendcmd(self, cmd):
252253
'''Send a command and return the response.'''
@@ -781,6 +782,15 @@ def storlines(self, cmd, fp, callback=None):
781782
conn.close()
782783
return self.voidresp()
783784

785+
def abort(self):
786+
# overridden as we can't pass MSG_OOB flag to sendall()
787+
line = b'ABOR' + B_CRLF
788+
self.sock.sendall(line)
789+
resp = self.getmultiline()
790+
if resp[:3] not in {'426', '225', '226'}:
791+
raise error_proto(resp)
792+
return resp
793+
784794
__all__.append('FTP_TLS')
785795
all_errors = (Error, IOError, EOFError, ssl.SSLError)
786796

Lib/test/test_ftplib.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ class DummyFTPHandler(asynchat.async_chat):
6161

6262
def __init__(self, conn):
6363
asynchat.async_chat.__init__(self, conn)
64+
# tells the socket to handle urgent data inline (ABOR command)
65+
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_OOBINLINE, 1)
6466
self.set_terminator(b"\r\n")
6567
self.in_buffer = []
6668
self.dtp = None
@@ -181,6 +183,9 @@ def cmd_quit(self, arg):
181183
self.push('221 quit ok')
182184
self.close()
183185

186+
def cmd_abor(self, arg):
187+
self.push('226 abor ok')
188+
184189
def cmd_stor(self, arg):
185190
self.push('125 stor ok')
186191

@@ -491,6 +496,9 @@ def test_quit(self):
491496
# Ensure the connection gets closed; sock attribute should be None
492497
self.assertEqual(self.client.sock, None)
493498

499+
def test_abort(self):
500+
self.client.abort()
501+
494502
def test_retrbinary(self):
495503
def callback(data):
496504
received.append(data.decode('ascii'))

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@ Core and Builtins
8383
Library
8484
-------
8585

86+
- Issue #12002: ftplib's abort() method raises TypeError.
87+
8688
- Issue 11999: fixed sporadic sync failure mailbox.Maildir due to its trying to
8789
detect mtime changes by comparing to the system clock instead of to the
8890
previous value of the mtime.

0 commit comments

Comments
 (0)