Пример #1
0
 def _translate_gio_error(self, err, path, extra=None):
     if 'gio' in debug.debug_flags:
         mutter("GIO Error: %s %s" % (str(err), path))
     if extra is None:
         extra = str(err)
     if err.code == gio.ERROR_NOT_FOUND:
         raise errors.NoSuchFile(path, extra=extra)
     elif err.code == gio.ERROR_EXISTS:
         raise errors.FileExists(path, extra=extra)
     elif err.code == gio.ERROR_NOT_DIRECTORY:
         raise errors.NotADirectory(path, extra=extra)
     elif err.code == gio.ERROR_NOT_EMPTY:
         raise errors.DirectoryNotEmpty(path, extra=extra)
     elif err.code == gio.ERROR_BUSY:
         raise errors.ResourceBusy(path, extra=extra)
     elif err.code == gio.ERROR_PERMISSION_DENIED:
         raise errors.PermissionDenied(path, extra=extra)
     elif err.code == gio.ERROR_HOST_NOT_FOUND:
         raise errors.PathError(path, extra=extra)
     elif err.code == gio.ERROR_IS_DIRECTORY:
         raise errors.PathError(path, extra=extra)
     else:
         mutter('unable to understand error for path: %s: %s', path, err)
         raise errors.PathError(path,
                                extra="Unhandled gio error: " + str(err))
Пример #2
0
 def _translate_error(self, resp, orig_path=None):
     """Raise an exception from a response"""
     if resp is None:
         what = None
     else:
         what = resp[0]
     if what == 'ok':
         return
     elif what == 'NoSuchFile':
         if orig_path is not None:
             error_path = orig_path
         else:
             error_path = resp[1]
         raise errors.NoSuchFile(error_path)
     elif what == 'error':
         raise errors.SmartProtocolError(unicode(resp[1]))
     elif what == 'FileExists':
         raise errors.FileExists(resp[1])
     elif what == 'DirectoryNotEmpty':
         raise errors.DirectoryNotEmpty(resp[1])
     elif what == 'ShortReadvError':
         raise errors.ShortReadvError(resp[1], int(resp[2]),
                                      int(resp[3]), int(resp[4]))
     elif what in ('UnicodeEncodeError', 'UnicodeDecodeError'):
         encoding = str(resp[1]) # encoding must always be a string
         val = resp[2]
         start = int(resp[3])
         end = int(resp[4])
         reason = str(resp[5]) # reason must always be a string
         if val.startswith('u:'):
             val = val[2:].decode('utf-8')
         elif val.startswith('s:'):
             val = val[2:].decode('base64')
         if what == 'UnicodeDecodeError':
             raise UnicodeDecodeError(encoding, val, start, end, reason)
         elif what == 'UnicodeEncodeError':
             raise UnicodeEncodeError(encoding, val, start, end, reason)
     elif what == "ReadOnlyError":
         raise errors.TransportNotPossible('readonly transport')
     elif what == "ReadError":
         if orig_path is not None:
             error_path = orig_path
         else:
             error_path = resp[1]
         raise errors.ReadError(error_path)
     elif what == "PermissionDenied":
         if orig_path is not None:
             error_path = orig_path
         else:
             error_path = resp[1]
         raise errors.PermissionDenied(error_path)
     else:
         raise errors.SmartProtocolError('unexpected smart server error: %r' % (resp,))
Пример #3
0
    def _translate_io_exception(self,
                                e,
                                path,
                                more_info='',
                                failure_exc=PathError):
        """Translate a paramiko or IOError into a friendlier exception.

        :param e: The original exception
        :param path: The path in question when the error is raised
        :param more_info: Extra information that can be included,
                          such as what was going on
        :param failure_exc: Paramiko has the super fun ability to raise completely
                           opaque errors that just set "e.args = ('Failure',)" with
                           no more information.
                           If this parameter is set, it defines the exception
                           to raise in these cases.
        """
        # paramiko seems to generate detailless errors.
        self._translate_error(e, path, raise_generic=False)
        if getattr(e, 'args', None) is not None:
            if (e.args == ('No such file or directory', )
                    or e.args == ('No such file', )):
                raise NoSuchFile(path, str(e) + more_info)
            if (e.args == ('mkdir failed', )
                    or e.args[0].startswith('syserr: File exists')):
                raise FileExists(path, str(e) + more_info)
            # strange but true, for the paramiko server.
            if (e.args == ('Failure', )):
                raise failure_exc(path, str(e) + more_info)
            # Can be something like args = ('Directory not empty:
            # '/srv/bazaar.launchpad.net/blah...: '
            # [Errno 39] Directory not empty',)
            if (e.args[0].startswith('Directory not empty: ')
                    or getattr(e, 'errno', None) == errno.ENOTEMPTY):
                raise errors.DirectoryNotEmpty(path, str(e))
            if e.args == ('Operation unsupported', ):
                raise errors.TransportNotPossible()
            mutter('Raising exception with args %s', e.args)
        if getattr(e, 'errno', None) is not None:
            mutter('Raising exception with errno %s', e.errno)
        raise e
Пример #4
0
 def test_translateDirectoryNotEmpty(self):
     exception = bzr_errors.DirectoryNotEmpty(self.getPathSegment())
     self.do_translation_test(
         exception, filetransfer.FX_FAILURE)