Ignore:
Timestamp:
Mar 30, 2013, 10:33:16 PM (6 years ago)
Author:
Stefan Schwarzer <sschwarzer@…>
Branch:
default
Message:
Use context managers to convert to ftputil exceptions.

Example:

  Previously:

    new_dir = _try_with_os_error(self._session.pwd)

  Now:

    with ftplib_error_to_ftp_os_error:
        new_dir = self._session.pwd()

Although the previous approach usually led to shorter code, the new
approach looks more natural.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • ftputil/file.py

    r1187 r1191  
    7575        transfer_type = ('A', 'I')[self._bin_mode]
    7676        command = 'TYPE %s' % transfer_type
    77         ftputil.error._try_with_ioerror(self._session.voidcmd, command)
     77        with ftputil.error.ftplib_error_to_ftp_io_error:
     78            self._session.voidcmd(command)
    7879        # Make transfer command.
    7980        command_type = ('STOR', 'RETR')[self._read_mode]
     
    8485            mode = mode + 'b'
    8586        # Get connection and file object.
    86         self._conn = ftputil.error._try_with_ioerror(
    87                        self._session.transfercmd, command)
     87        with ftputil.error.ftplib_error_to_ftp_io_error:
     88            self._conn = self._session.transfercmd(command)
    8889        self._fo = self._conn.makefile(mode)
    8990        # This comes last so that `close` won't try to close `_FTPFile`
     
    227228            self._fo.close()
    228229            self._fo = None
    229             ftputil.error._try_with_ioerror(self._conn.close)
     230            with ftputil.error.ftplib_error_to_ftp_io_error:
     231                self._conn.close()
    230232            # Set a timeout to prevent waiting until server timeout
    231233            # if we have a server blocking here like in ticket #51.
    232234            self._session.sock.settimeout(self._close_timeout)
    233235            try:
    234                 ftputil.error._try_with_ioerror(self._session.voidresp)
     236                with ftputil.error.ftplib_error_to_ftp_io_error:
     237                    self._session.voidresp()
    235238            except ftputil.error.FTPIOError, exception:
    236239                # Ignore some errors, see tickets #51 and #17 at
Note: See TracChangeset for help on using the changeset viewer.