~sschwarzer/ftputil

e1b28c362dc9f1cb894bda37e359292ba07fa9a9 — Stefan Schwarzer 4 years ago dafcbed
Catch `EOFError` in `_available_child`

If `host._session.pwd` raises an `EOFError`, catch it and don't
consider the affected child host for a new file-like object.
2 files changed, 12 insertions(+), 0 deletions(-)

M ftputil/host.py
M test/test_file.py
M ftputil/host.py => ftputil/host.py +5 -0
@@ 181,6 181,11 @@ class FTPHost(object):
                # an FTP session timeout.
                except OSError:
                    continue
                # The server may close the connection which may cause
                # `host._session.getline` raise an `EOFError` (see
                # ticket #114).
                except EOFError:
                    continue
                else:
                    # Everything's ok; use this `FTPHost` instance.
                    return host

M test/test_file.py => test/test_file.py +7 -0
@@ 281,3 281,10 @@ class TestAvailableChild(object):
        session.
        """
        self._test_with_pwd_error(OSError)

    def test_pwd_with_EOFError(self):
        """
        Test if an `EOFError` in `_session.pwd` skips the child
        session.
        """
        self._test_with_pwd_error(EOFError)