Skip to content

Commit 3723642

Browse files
darguetawillmcgugan
authored andcommitted
[FTPFS] Handle EOFError (#315)
* Handle EOFError (closes #292) * Update CHANGELOG and CONTRIBUTORS
1 parent c23cfca commit 3723642

File tree

3 files changed

+19
-3
lines changed

3 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1111

1212
- `MemFS` now immediately releases all memory it holds when `close()` is called,
1313
rather than when it gets garbage collected. Closes [issue #308](https://github.com/PyFilesystem/pyfilesystem2/issues/308).
14+
- `FTPFS` now translates `EOFError` into `RemoteConnectionError`. Closes [#292](https://github.com/PyFilesystem/pyfilesystem2/issues/292)
1415

1516
## [2.4.8] - 2019-06-12
1617

fs/ftpfs.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ def ftp_errors(fs, path=None):
7777
raise errors.RemoteConnectionError(
7878
msg="unable to connect to {}".format(fs.host)
7979
)
80+
except EOFError:
81+
raise errors.RemoteConnectionError(msg="lost connection to {}".format(fs.host))
8082
except error_temp as error:
8183
if path is not None:
8284
raise errors.ResourceError(

tests/test_ftpfs.py

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from __future__ import unicode_literals
55

66
import socket
7-
import ftplib
87
import os
98
import platform
109
import shutil
@@ -114,6 +113,20 @@ def test_manager(self):
114113
with ftp_errors(mem_fs):
115114
raise error_perm("999 foo")
116115

116+
def test_manager_with_host(self):
117+
mem_fs = open_fs("mem://")
118+
mem_fs.host = "ftp.example.com"
119+
120+
with self.assertRaises(errors.RemoteConnectionError) as err_info:
121+
with ftp_errors(mem_fs):
122+
raise EOFError
123+
self.assertEqual(str(err_info.exception), "lost connection to ftp.example.com")
124+
125+
with self.assertRaises(errors.RemoteConnectionError) as err_info:
126+
with ftp_errors(mem_fs):
127+
raise socket.error
128+
self.assertEqual(str(err_info.exception), "unable to connect to ftp.example.com")
129+
117130

118131
@attr("slow")
119132
class TestFTPFS(FSTestCases, unittest.TestCase):
@@ -167,7 +180,7 @@ def tearDown(self):
167180

168181
def test_ftp_url(self):
169182
self.assertEqual(self.fs.ftp_url, "ftp://{}:{}@{}:{}".format(self.user, self.pasw, self.server.host, self.server.port))
170-
183+
171184
def test_geturl(self):
172185
self.fs.makedir("foo")
173186
self.fs.create("bar")
@@ -251,7 +264,7 @@ def make_fs(self):
251264
def test_features(self):
252265
pass
253266

254-
267+
255268
@attr("slow")
256269
class TestAnonFTPFS(FSTestCases, unittest.TestCase):
257270

0 commit comments

Comments
 (0)