def _convert_error(self, f): if f.check(NoSuchChildError): childname = f.value.args[0].encode("utf-8") msg = "'%s' doesn't exist" % childname raise ftp.FileNotFoundError(msg) if f.check(ExistingChildError): msg = f.value.args[0].encode("utf-8") raise ftp.FileExistsError(msg) return f
def vfsToFtpError(vfsError): """ Map vfs errors to the corresponding ftp errors, if it exists. """ if isinstance(vfsError, ivfs.NotFoundError): return defer.fail(ftp.FileNotFoundError(vfsError)) elif isinstance(vfsError, ivfs.AlreadyExistsError): return defer.fail(ftp.FileExistsError(vfsError)) return defer.fail(vfsError)
def _get_or_create_directories(self, node, path): if not IDirectoryNode.providedBy(node): # unfortunately it is too late to provide the name of the # blocking directory in the error message. raise ftp.FileExistsError("cannot create directory because there " "is a file in the way") if not path: return defer.succeed(node) d = node.get(path[0]) def _maybe_create(f): f.trap(NoSuchChildError) return node.create_subdirectory(path[0]) d.addErrback(_maybe_create) d.addCallback(self._get_or_create_directories, path[1:]) return d