diff --git a/cs3client/auth.py b/cs3client/auth.py index a594094..7ac13c6 100644 --- a/cs3client/auth.py +++ b/cs3client/auth.py @@ -17,7 +17,7 @@ from cs3.rpc.v1beta1.code_pb2 import CODE_OK from .cs3client import CS3Client -from .exceptions.exceptions import AuthenticationException, SecretNotSetException +from .exceptions import AuthenticationException, SecretNotSetException from .config import Config diff --git a/cs3client/exceptions/__init__.py b/cs3client/exceptions/__init__.py index e69de29..0fe71a7 100644 --- a/cs3client/exceptions/__init__.py +++ b/cs3client/exceptions/__init__.py @@ -0,0 +1,74 @@ +""" +exceptions + +Custom exception classes for the CS3 client. +Where applicable, the default values correspond to the Linux standard error strings. + +Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti. +Emails: rasmus.oscar.welander@cern.ch, diogo.castro@cern.ch, giuseppe.lopresti@cern.ch +Last updated: 01/08/2024 +""" + + +class AuthenticationException(Exception): + """ + Standard error thrown when attempting an operation without the required access rights + """ + + def __init__(self, message: str = "Operation not permitted"): + super().__init__(message) + + +class NotFoundException(IOError): + """ + Standard file missing message + """ + + def __init__(self, message: str = "No such file or directory"): + super().__init__(message) + + +class SecretNotSetException(Exception): + """ + Standard file missing message + """ + + def __init__(self, message: str = "Secret was not set, unable to authenticate"): + super().__init__(message) + + +class FileLockedException(IOError): + """ + Standard error thrown when attempting to overwrite a file/xattr with a mistmatched lock, + or when a lock operation cannot be performed because of failed preconditions + """ + + def __init__(self, message: str = "Lock mismatch"): + super().__init__(message) + + +class UnknownException(Exception): + """ + Standard exception to be thrown when we get an error that is unknown, e.g. not defined in the cs3api + """ + + def __init__(self, message: str = ""): + super().__init__(message) + + +class AlreadyExistsException(IOError): + """ + Standard error thrown when attempting to create a resource that already exists + """ + + def __init__(self, message: str = "File exists"): + super().__init__(message) + + +class UnimplementedException(Exception): + """ + Standard error thrown when attempting to use a feature that is not implemented + """ + + def __init__(self, message: str = "Not implemented"): + super().__init__(message) diff --git a/cs3client/exceptions/exceptions.py b/cs3client/exceptions/exceptions.py deleted file mode 100644 index cf8587e..0000000 --- a/cs3client/exceptions/exceptions.py +++ /dev/null @@ -1,74 +0,0 @@ -""" -exceptions.py - -Custom exception classes for the CS3 client. -Where applicable, the default values correspond to the Linux standard error strings. - -Authors: Rasmus Welander, Diogo Castro, Giuseppe Lo Presti. -Emails: rasmus.oscar.welander@cern.ch, diogo.castro@cern.ch, giuseppe.lopresti@cern.ch -Last updated: 01/08/2024 -""" - - -class AuthenticationException(Exception): - """ - Standard error thrown when attempting an operation without the required access rights - """ - - def __init__(self, message: str = "Operation not permitted"): - super().__init__(message) - - -class NotFoundException(IOError): - """ - Standard file missing message - """ - - def __init__(self, message: str = "No such file or directory"): - super().__init__(message) - - -class SecretNotSetException(Exception): - """ - Standard file missing message - """ - - def __init__(self, message: str = "Secret was not set, unable to authenticate"): - super().__init__(message) - - -class FileLockedException(IOError): - """ - Standard error thrown when attempting to overwrite a file/xattr with a mistmatched lock, - or when a lock operation cannot be performed because of failed preconditions - """ - - def __init__(self, message: str = "Lock mismatch"): - super().__init__(message) - - -class UnknownException(Exception): - """ - Standard exception to be thrown when we get an error that is unknown, e.g. not defined in the cs3api - """ - - def __init__(self, message: str = ""): - super().__init__(message) - - -class AlreadyExistsException(IOError): - """ - Standard error thrown when attempting to create a resource that already exists - """ - - def __init__(self, message: str = "File exists"): - super().__init__(message) - - -class UnimplementedException(Exception): - """ - Standard error thrown when attempting to use a feature that is not implemented - """ - - def __init__(self, message: str = "Not implemented"): - super().__init__(message) diff --git a/cs3client/file.py b/cs3client/file.py index e7d1b30..efd9fee 100644 --- a/cs3client/file.py +++ b/cs3client/file.py @@ -20,7 +20,7 @@ from .config import Config -from .exceptions.exceptions import AuthenticationException, FileLockedException +from .exceptions import AuthenticationException, FileLockedException from .cs3resource import Resource from .statuscodehandler import StatusCodeHandler diff --git a/cs3client/statuscodehandler.py b/cs3client/statuscodehandler.py index 1c2d1fe..9205981 100644 --- a/cs3client/statuscodehandler.py +++ b/cs3client/statuscodehandler.py @@ -10,7 +10,7 @@ import cs3.rpc.v1beta1.code_pb2 as cs3code import cs3.rpc.v1beta1.status_pb2 as cs3status -from .exceptions.exceptions import AuthenticationException, NotFoundException, \ +from .exceptions import AuthenticationException, NotFoundException, \ UnknownException, AlreadyExistsException, FileLockedException, UnimplementedException from .config import Config diff --git a/docs/source/exceptions.rst b/docs/source/exceptions.rst index 5ba9cc0..3dd6db4 100644 --- a/docs/source/exceptions.rst +++ b/docs/source/exceptions.rst @@ -1,7 +1,7 @@ exceptions Module ================= -.. automodule:: exceptions.exceptions +.. automodule:: exceptions :members: :undoc-members: :show-inheritance: \ No newline at end of file diff --git a/tests/test_app.py b/tests/test_app.py index 0233797..11af905 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -12,7 +12,7 @@ from unittest.mock import Mock, patch import pytest -from cs3client.exceptions.exceptions import ( +from cs3client.exceptions import ( AuthenticationException, NotFoundException, UnknownException, diff --git a/tests/test_checkpoint.py b/tests/test_checkpoint.py index d005965..be6e63e 100644 --- a/tests/test_checkpoint.py +++ b/tests/test_checkpoint.py @@ -12,7 +12,7 @@ import pytest import cs3.rpc.v1beta1.code_pb2 as cs3code -from cs3client.exceptions.exceptions import ( +from cs3client.exceptions import ( AuthenticationException, NotFoundException, UnknownException, diff --git a/tests/test_file.py b/tests/test_file.py index 7e83afa..4120795 100644 --- a/tests/test_file.py +++ b/tests/test_file.py @@ -13,7 +13,7 @@ import cs3.rpc.v1beta1.code_pb2 as cs3code from cs3client.cs3resource import Resource -from cs3client.exceptions.exceptions import ( +from cs3client.exceptions import ( AuthenticationException, NotFoundException, FileLockedException, diff --git a/tests/test_share.py b/tests/test_share.py index 295c928..1185188 100644 --- a/tests/test_share.py +++ b/tests/test_share.py @@ -15,7 +15,7 @@ import cs3.storage.provider.v1beta1.resources_pb2 as cs3spr import cs3.rpc.v1beta1.code_pb2 as cs3code -from cs3client.exceptions.exceptions import ( +from cs3client.exceptions import ( AuthenticationException, NotFoundException, UnknownException, diff --git a/tests/test_user.py b/tests/test_user.py index 837b183..c62146a 100644 --- a/tests/test_user.py +++ b/tests/test_user.py @@ -12,7 +12,7 @@ from unittest.mock import Mock, patch import cs3.rpc.v1beta1.code_pb2 as cs3code -from cs3client.exceptions.exceptions import ( +from cs3client.exceptions import ( AuthenticationException, NotFoundException, UnknownException,