diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-27 13:23:26 +0000 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2009-11-27 13:23:26 +0000 |
commit | 648bcd706882a5ed83b7455ab3cf68734f92c6a4 (patch) | |
tree | 2da19c61e238ecd62565fbcd89ff344531f395f1 /Lib/test/test_ftplib.py | |
parent | 1a305fd141ebe4295d554d8b127ab982858a079e (diff) | |
download | cpython-git-648bcd706882a5ed83b7455ab3cf68734f92c6a4.tar.gz |
Merged revisions 76546 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r76546 | antoine.pitrou | 2009-11-27 14:18:34 +0100 (ven., 27 nov. 2009) | 7 lines
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.py | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 708ac41922..a4ce8e1df0 100644 --- a/Lib/test/test_ftplib.py +++ b/Lib/test/test_ftplib.py @@ -57,6 +57,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): @@ -170,10 +171,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') @@ -450,6 +460,17 @@ class TestFTPClass(TestCase): self.client.retrbinary('retr', callback) self.assertEqual(''.join(received), RETR_DATA) + def test_retrbinary_rest(self): + def callback(data): + received.append(data.decode('ascii')) + for rest in (0, 10, 20): + received = [] + self.client.retrbinary('retr', callback, 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) @@ -465,6 +486,13 @@ class TestFTPClass(TestCase): self.client.storbinary('stor', f, callback=lambda x: flag.append(None)) self.assertTrue(flag) + def test_storbinary_rest(self): + f = io.BytesIO(RETR_DATA.replace('\r\n', '\n').encode('ascii')) + 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 = io.BytesIO(RETR_DATA.replace('\r\n', '\n').encode('ascii')) self.client.storlines('stor', f) |