summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ftplib.py
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2009-11-27 13:18:34 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2009-11-27 13:18:34 (GMT)
commitacbe3bdbab14da04c9be5278d1b6f0df8cff2729 (patch)
treedadcb5e6171251c2b1095ac995b1239f5daca7f8 /Lib/test/test_ftplib.py
parent2600a33219374c97c9f82ab03a2c8848a0bf63eb (diff)
downloadcpython-acbe3bdbab14da04c9be5278d1b6f0df8cff2729.zip
cpython-acbe3bdbab14da04c9be5278d1b6f0df8cff2729.tar.gz
cpython-acbe3bdbab14da04c9be5278d1b6f0df8cff2729.tar.bz2
Issue #6845: Add restart support for binary upload in ftplib. The
`storbinary()` method of FTP and FTP_TLS objects gains an optional `rest` argument. Patch by Pablo Mouzo. (note: the patch also adds a test for the rest argument in retrbinary())
Diffstat (limited to 'Lib/test/test_ftplib.py')
-rw-r--r--Lib/test/test_ftplib.py28
1 files changed, 27 insertions, 1 deletions
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index f8a5b9c..fb9d55b 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -55,6 +55,7 @@ class DummyFTPHandler(asynchat.async_chat):
self.last_received_cmd = None
self.last_received_data = ''
self.next_response = ''
+ self.rest = None
self.push('220 welcome')
def collect_incoming_data(self, data):
@@ -168,10 +169,19 @@ class DummyFTPHandler(asynchat.async_chat):
def cmd_stor(self, arg):
self.push('125 stor ok')
+ def cmd_rest(self, arg):
+ self.rest = arg
+ self.push('350 rest ok')
+
def cmd_retr(self, arg):
self.push('125 retr ok')
- self.dtp.push(RETR_DATA)
+ if self.rest is not None:
+ offset = int(self.rest)
+ else:
+ offset = 0
+ self.dtp.push(RETR_DATA[offset:])
self.dtp.close_when_done()
+ self.rest = None
def cmd_list(self, arg):
self.push('125 list ok')
@@ -444,6 +454,15 @@ class TestFTPClass(TestCase):
self.client.retrbinary('retr', received.append)
self.assertEqual(''.join(received), RETR_DATA)
+ def test_retrbinary_rest(self):
+ for rest in (0, 10, 20):
+ received = []
+ self.client.retrbinary('retr', received.append, rest=rest)
+ self.assertEqual(''.join(received), RETR_DATA[rest:],
+ msg='rest test case %d %d %d' % (rest,
+ len(''.join(received)),
+ len(RETR_DATA[rest:])))
+
def test_retrlines(self):
received = []
self.client.retrlines('retr', received.append)
@@ -459,6 +478,13 @@ class TestFTPClass(TestCase):
self.client.storbinary('stor', f, callback=lambda x: flag.append(None))
self.assertTrue(flag)
+ def test_storbinary_rest(self):
+ f = StringIO.StringIO(RETR_DATA)
+ for r in (30, '30'):
+ f.seek(0)
+ self.client.storbinary('stor', f, rest=r)
+ self.assertEqual(self.server.handler.rest, str(r))
+
def test_storlines(self):
f = StringIO.StringIO(RETR_DATA.replace('\r\n', '\n'))
self.client.storlines('stor', f)