Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- === modified file 'bzrlib/errors.py'
- --- bzrlib/errors.py 2012-07-19 19:27:22 +0000
- +++ bzrlib/errors.py 2012-07-26 12:16:40 +0000
- @@ -1618,6 +1618,14 @@
- self.exc_type, self.exc_value, self.exc_tb)
- self.traceback_text = ''.join(traceback_strings)
- +class TransportOperationNotSupported(TransportError):
- +
- + _fmt = "Transport operation is not supported: %(operation)s%(msg)s"
- +
- + def __init__(self, operation, msg=None):
- + if msg != None:
- + self.msg = "\n" + msg
- + self.operation = operation
- # A set of semi-meaningful errors which can be thrown
- class TransportNotPossible(TransportError):
- === modified file 'bzrlib/tests/test_sftp_transport.py'
- --- bzrlib/tests/test_sftp_transport.py 2012-02-23 23:26:35 +0000
- +++ bzrlib/tests/test_sftp_transport.py 2012-07-27 14:04:34 +0000
- @@ -497,3 +497,18 @@
- # No prompts should've been printed, stdin shouldn't have been read
- self.assertEquals("", stdout.getvalue())
- self.assertEquals(0, ui.ui_factory.stdin.tell())
- +
- +class TestUnsupportedOperationExceptionTranslation(TestCaseWithSFTPServer):
- + """Test that unsupported operation exception from Paramiko is correctly
- + translated into TransportOperationNotSupported."""
- +
- + def test_sftp_unsupported_rename_operation(self):
- + t = self.get_transport()
- +
- + e = self.assertRaises(
- + errors.TransportOperationNotSupported("rename",
- + "unable to rename"),
- + t._translate_io_exception,
- + IOError("Operation unsupported"),
- + "unable to rename", operation="rename")
- + self.assertEquals(e, "TransportOperationNotSupported: Transport operation is not supported: rename")
- \ No newline at end of file
- === modified file 'bzrlib/transport/sftp.py'
- --- bzrlib/transport/sftp.py 2011-12-19 13:23:58 +0000
- +++ bzrlib/transport/sftp.py 2012-07-27 14:10:00 +0000
- @@ -671,7 +671,7 @@
- return FileFileStream(self, relpath, handle)
- def _translate_io_exception(self, e, path, more_info='',
- - failure_exc=PathError):
- + failure_exc=PathError, operation=None):
- """Translate a paramiko or IOError into a friendlier exception.
- :param e: The original exception
- @@ -683,6 +683,7 @@
- no more information.
- If this parameter is set, it defines the exception
- to raise in these cases.
- + :param operation: Operation that failed (needs to check if it's supported)
- """
- # paramiko seems to generate detailless errors.
- self._translate_error(e, path, raise_generic=False)
- @@ -703,7 +704,8 @@
- or getattr(e, 'errno', None) == errno.ENOTEMPTY):
- raise errors.DirectoryNotEmpty(path, str(e))
- if e.args == ('Operation unsupported',):
- - raise errors.TransportNotPossible()
- + raise errors.TransportOperationNotSupported(operation, more_info)
- + # raise errors.TransportNotPossible(more_info)
- mutter('Raising exception with args %s', e.args)
- if getattr(e, 'errno', None) is not None:
- mutter('Raising exception with errno %s', e.errno)
- @@ -732,7 +734,7 @@
- self._remote_path(rel_to))
- except (IOError, paramiko.SSHException), e:
- self._translate_io_exception(e, rel_from,
- - ': unable to rename to %r' % (rel_to))
- + ': unable to rename to %r' % (rel_to), "rename")
- def _rename_and_overwrite(self, abs_from, abs_to):
- """Do a fancy rename on the remote server.
- @@ -746,7 +748,7 @@
- unlink_func=sftp.remove)
- except (IOError, paramiko.SSHException), e:
- self._translate_io_exception(e, abs_from,
- - ': unable to rename to %r' % (abs_to))
- + ': unable to rename to %r' % (abs_to), operation="rename")
- def move(self, rel_from, rel_to):
- """Move the item at rel_from to the location at rel_to"""
- @@ -760,7 +762,8 @@
- try:
- self._get_sftp().remove(path)
- except (IOError, paramiko.SSHException), e:
- - self._translate_io_exception(e, path, ': unable to delete')
- + self._translate_io_exception(e, path, ': unable to delete',
- + operation="delete")
- def external_url(self):
- """See bzrlib.transport.Transport.external_url."""
- @@ -793,7 +796,8 @@
- try:
- return self._get_sftp().rmdir(path)
- except (IOError, paramiko.SSHException), e:
- - self._translate_io_exception(e, path, ': failed to rmdir')
- + self._translate_io_exception(e, path, ': failed to rmdir',
- + operation="rmdir")
- def stat(self, relpath):
- """Return the stat information for a file."""
- @@ -809,7 +813,8 @@
- try:
- return self._get_sftp().readlink(path)
- except (IOError, paramiko.SSHException), e:
- - self._translate_io_exception(e, path, ': unable to readlink')
- + self._translate_io_exception(e, path, ': unable to readlink',
- + operation="readlink")
- def symlink(self, source, link_name):
- """See Transport.symlink."""
- @@ -823,7 +828,8 @@
- )
- except (IOError, paramiko.SSHException), e:
- self._translate_io_exception(e, link_name,
- - ': unable to create symlink to %r' % (source))
- + ': unable to create symlink to %r' % (source),
- + operation="symlink")
- def lock_read(self, relpath):
- """
- @@ -884,7 +890,7 @@
- return SFTPFile(self._get_sftp(), handle, 'wb', -1)
- except (paramiko.SSHException, IOError), e:
- self._translate_io_exception(e, abspath, ': unable to open',
- - failure_exc=FileExists)
- + failure_exc=FileExists, operation="open")
- def _can_roundtrip_unix_modebits(self):
- if sys.platform == 'win32':
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement