Skip to content

Commit 62e5e75

Browse files
geoffjukeswillmcgugan
authored andcommitted
Enable timeout in URI (#173)
* Honor `create` option in opener Ported fix from fs.sshfs All credit to @althonos althonos/fs.sshfs@48664f2 * Switch to CreateFailed.catch_all decorator as suggested * Enable `timeout` in URI I almost exclusively use the URI syntax for filesystems, and I have at least 2 FTP servers that are occasionally slow to respond. This allows me to specify a timeout in the URI for those servers. * Fixed open_ftp* tests and added test Fixed the open_ftp* tests and added an additional test for the `timeout` parameter * Renamed test to conform to standard * Added URL Parameter decode test
1 parent 8694573 commit 62e5e75

File tree

2 files changed

+34
-3
lines changed

2 files changed

+34
-3
lines changed

fs/opener/ftpfs.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def open_fs(self,
4545
port=ftp_port,
4646
user=parse_result.username,
4747
passwd=parse_result.password,
48-
proxy=parse_result.params.get('proxy')
48+
proxy=parse_result.params.get('proxy'),
49+
timeout=int(parse_result.params.get('timeout', '10'))
4950
)
5051
if dir_path:
5152
if create:

tests/test_opener.py

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,20 @@ def test_parse_params_multiple(self):
102102
)
103103
self.assertEqual(expected, parsed)
104104

105+
def test_parse_params_timeout(self):
106+
parsed = opener.parse('ftp://ftp.example.org?timeout=30')
107+
expected = ParseResult(
108+
'ftp',
109+
None,
110+
None,
111+
'ftp.example.org',
112+
{
113+
'timeout':'30'
114+
},
115+
None
116+
)
117+
self.assertEqual(expected, parsed)
118+
105119
def test_parse_user_password_proxy(self):
106120
parsed = opener.parse('ftp://user:[email protected]?proxy=ftp.proxy.org')
107121
expected = ParseResult(
@@ -140,6 +154,20 @@ def test_parse_resource_decode(self):
140154
)
141155
self.assertEqual(expected, parsed)
142156

157+
def test_parse_params_decode(self):
158+
parsed = opener.parse('ftp://ftp.example.org?decode=is%20working')
159+
expected = ParseResult(
160+
'ftp',
161+
None,
162+
None,
163+
'ftp.example.org',
164+
{
165+
'decode':'is working'
166+
},
167+
None
168+
)
169+
self.assertEqual(expected, parsed)
170+
143171

144172
class TestRegistry(unittest.TestCase):
145173

@@ -309,10 +337,12 @@ def test_user_data_opener(self):
309337
@mock.patch("fs.ftpfs.FTPFS")
310338
def test_open_ftp(self, mock_FTPFS):
311339
open_fs('ftp://foo:[email protected]')
312-
mock_FTPFS.assert_called_once_with('ftp.example.org', passwd='bar', port=21, user='foo', proxy=None)
340+
mock_FTPFS.assert_called_once_with('ftp.example.org', passwd='bar', port=21, user='foo', proxy=None,
341+
timeout=10)
313342

314343
@mock.patch("fs.ftpfs.FTPFS")
315344
def test_open_ftp_proxy(self, mock_FTPFS):
316345
open_fs('ftp://foo:[email protected]?proxy=ftp.proxy.org')
317-
mock_FTPFS.assert_called_once_with('ftp.example.org', passwd='bar', port=21, user='foo', proxy='ftp.proxy.org')
346+
mock_FTPFS.assert_called_once_with('ftp.example.org', passwd='bar', port=21, user='foo', proxy='ftp.proxy.org',
347+
timeout=10)
318348

0 commit comments

Comments
 (0)