Merge lp:~adiroiban/twisted/twisted-5259 into lp:twisted

Proposed by Adi Roiban
Status: Merged
Merge reported by: Jean-Paul Calderone
Merged at revision: not available
Proposed branch: lp:~adiroiban/twisted/twisted-5259
Merge into: lp:twisted
Diff against target: 97 lines (+76/-0)
2 files modified
twisted/protocols/ftp.py (+17/-0)
twisted/test/test_ftp.py (+59/-0)
To merge this branch: bzr merge lp:~adiroiban/twisted/twisted-5259
Reviewer Review Type Date Requested Status
Twisted-dev Pending
Review via email: mp+74827@code.launchpad.net

Description of the change

I have implemented removeDirectory, in the same way removeFile was already implemented.

RFC 595 specifies that RMD should have the same behavior as DELE.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'twisted/protocols/ftp.py'
2--- twisted/protocols/ftp.py 2011-04-10 14:17:53 +0000
3+++ twisted/protocols/ftp.py 2011-09-09 16:40:19 +0000
4@@ -2759,6 +2759,23 @@
5 """
6 return self.queueStringCommand('DELE ' + self.escapePath(path))
7
8+ def removeDirectory(self, path):
9+ """
10+ Delete a directory on the server.
11+
12+ L{removeDirectory} issues a I{RMD} command to the server to remove the
13+ indicated file. Described in RFC959.
14+
15+ @param path: The path to the directory to delete. May be relative to
16+ the current dir.
17+ @type path: C{str}
18+
19+ @return: A L{Deferred} which fires when the server responds. On error,
20+ it is errbacked with either L{CommandFailed} or L{BadResponse}. On
21+ success, it is called back with a list of response lines.
22+ @rtype: L{Deferred}
23+ """
24+ return self.queueStringCommand('RMD ' + self.escapePath(path))
25
26 def cdup(self):
27 """
28
29=== modified file 'twisted/test/test_ftp.py'
30--- twisted/test/test_ftp.py 2011-07-14 18:05:14 +0000
31+++ twisted/test/test_ftp.py 2011-09-09 16:40:19 +0000
32@@ -1888,6 +1888,65 @@
33 map(self.client.lineReceived, response)
34 return d.addCallback(self.assertTrue)
35
36+ def test_removeDirectory(self):
37+ """
38+ L{ftp.FTPClient.removeDirectory} sends a I{RMD} command to the server
39+ for the indicated file and returns a Deferred which fires after the
40+ server sends a 250 response code.
41+ """
42+ self._testLogin()
43+ d = self.client.removeDirectory('/tmp/test')
44+ self.assertEqual(self.transport.value(), 'RMD /tmp/test\r\n')
45+ response = '250 Requested file action okay, completed.'
46+ self.client.lineReceived(response)
47+ return d.addCallback(self.assertEqual, [response])
48+
49+
50+ def test_failedRemoveDirectory(self):
51+ """
52+ If the server returns a response code other than 250 in response to a
53+ I{RMD} sent by L{ftp.FTPClient.removeDirectory}, the L{Deferred}
54+ returned by C{removeDirectory} is errbacked with a L{Failure} wrapping
55+ a L{CommandFailed}.
56+ """
57+ self._testLogin()
58+ d = self.client.removeDirectory("/tmp/test")
59+ self.assertEqual(self.transport.value(), 'RMD /tmp/test\r\n')
60+ response = '501 Syntax error in parameters or arguments.'
61+ self.client.lineReceived(response)
62+ d = self.assertFailure(d, ftp.CommandFailed)
63+ d.addCallback(lambda exc: self.assertEqual(exc.args, ([response],)))
64+ return d
65+
66+
67+ def test_unparsableRemoveDirectoryResponse(self):
68+ """
69+ If the server returns a response line which cannot be parsed, the
70+ L{Deferred} returned by L{ftp.FTPClient.removeDirectory} is errbacked
71+ with a L{BadResponse} containing the response.
72+ """
73+ self._testLogin()
74+ d = self.client.removeDirectory("/tmp/test")
75+ response = '765 blah blah blah'
76+ self.client.lineReceived(response)
77+ d = self.assertFailure(d, ftp.BadResponse)
78+ d.addCallback(lambda exc: self.assertEqual(exc.args, ([response],)))
79+ return d
80+
81+
82+ def test_multilineRemoveDirectoryResponse(self):
83+ """
84+ If the server returns multiple response lines, the L{Deferred} returned
85+ by L{ftp.FTPClient.removeDirectory} is still fired with a true value
86+ if the ultimate response code is 250.
87+ """
88+ self._testLogin()
89+ d = self.client.removeDirectory("/tmp/test")
90+ response = ['250-perhaps a progress report',
91+ '250 okay']
92+ map(self.client.lineReceived, response)
93+ return d.addCallback(self.assertTrue)
94+
95
96
97 class FTPClientBasicTests(unittest.TestCase):

Subscribers

People subscribed via source and target branches

to all changes: