~sschwarzer/ftputil

26c1ed8d88d35a635ace7d23965feddf5d5686da — Stefan Schwarzer 12 years ago de0ea43
Handle status code 150 for an incomplete transfer (see ticket #51).
2 files changed, 19 insertions(+), 4 deletions(-)

M _test_real_ftp.py
M ftp_file.py
M _test_real_ftp.py => _test_real_ftp.py +14 -1
@@ 569,7 569,18 @@ class RealFTPTest(unittest.TestCase):
    # other tests
    #
    def test_open_for_reading(self):
        # test for issue #17, http://ftputil.sschwarzer.net/trac/ticket/17
        # test for issues #17 and #51,
        #  http://ftputil.sschwarzer.net/trac/ticket/17 and
        #  http://ftputil.sschwarzer.net/trac/ticket/51
        file1 = self.host.file("debian-keyring.tar.gz", 'rb')
        time.sleep(1)
        # depending on the FTP server, this might return a status code
        #  unexpected by `ftplib`, or block the socket connection until
        #  a server-side timeout
        file1.close()

    def test_subsequent_reading(self):
        # opening a file for reading
        file1 = self.host.file("debian-keyring.tar.gz", 'rb')
        file1.close()
        # make sure that there are no problems if the connection is reused


@@ 614,4 625,6 @@ because it has to wait to test the timezone calculation.
    # get login data only once, not for each test
    server, user, password = get_login_data()
    unittest.main()
    import __main__
    #unittest.main(__main__, "RealFTPTest.test_open_for_reading")


M ftp_file.py => ftp_file.py +5 -3
@@ 215,10 215,12 @@ class _FTPFile(object):
            try:
                ftp_error._try_with_ioerror(self._session.voidresp)
            except ftp_error.FTPIOError, exception:
                # ignore some errors, see ticket #17 at
                #  http://ftputil.sschwarzer.net/trac/ticket/17
                # ignore some errors, see tickets #51 and #17 at
                #  http://ftputil.sschwarzer.net/trac/ticket/51 and
                #  http://ftputil.sschwarzer.net/trac/ticket/17,
                #  respectively
                error_code = str(exception).split()[0]
                if error_code not in ("426", "450", "451"):
                if error_code not in ("150", "426", "450", "451"):
                    raise
        finally:
            # if something went wrong before, the file is probably