dspace-api-toolkit 0.1.1__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- dspace_api/__init__.py +75 -0
- dspace_api/_base.py +407 -0
- dspace_api/_containers.py +217 -0
- dspace_api/_version.py +4 -0
- dspace_api/auth.py +467 -0
- dspace_api/authorizations.py +486 -0
- dspace_api/bundles.py +1193 -0
- dspace_api/collections.py +1069 -0
- dspace_api/communities.py +363 -0
- dspace_api/config.py +254 -0
- dspace_api/discovery.py +920 -0
- dspace_api/entity_types.py +127 -0
- dspace_api/epersons.py +647 -0
- dspace_api/exceptions.py +110 -0
- dspace_api/groups.py +599 -0
- dspace_api/items.py +549 -0
- dspace_api/metadata.py +742 -0
- dspace_api/permissions.py +1052 -0
- dspace_api/projection.py +292 -0
- dspace_api/relationships.py +694 -0
- dspace_api/session.py +538 -0
- dspace_api/site.py +98 -0
- dspace_api/utils.py +519 -0
- dspace_api/versions.py +292 -0
- dspace_api/vocabulary.py +365 -0
- dspace_api/workflow.py +893 -0
- dspace_api/workspaces.py +1404 -0
- dspace_api_toolkit-0.1.1.dist-info/METADATA +211 -0
- dspace_api_toolkit-0.1.1.dist-info/RECORD +32 -0
- dspace_api_toolkit-0.1.1.dist-info/WHEEL +5 -0
- dspace_api_toolkit-0.1.1.dist-info/licenses/LICENSE +28 -0
- dspace_api_toolkit-0.1.1.dist-info/top_level.txt +1 -0
dspace_api/exceptions.py
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Custom exceptions for DSpace API client
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
class DSpaceError(Exception):
|
|
7
|
+
"""Base exception class for DSpace API errors"""
|
|
8
|
+
|
|
9
|
+
def __init__(self, message, status_code=None, response_text=None):
|
|
10
|
+
super().__init__(message)
|
|
11
|
+
self.status_code = status_code
|
|
12
|
+
self.response_text = response_text
|
|
13
|
+
|
|
14
|
+
class AuthenticationError(DSpaceError):
|
|
15
|
+
"""Exception raised for authentication-related errors"""
|
|
16
|
+
pass
|
|
17
|
+
|
|
18
|
+
class AuthorizationError(DSpaceError):
|
|
19
|
+
"""Exception raised for authorization/permission errors"""
|
|
20
|
+
pass
|
|
21
|
+
|
|
22
|
+
class UserAgreementRequired(AuthorizationError):
|
|
23
|
+
"""
|
|
24
|
+
DSpace-CRIS refused the request because the logged-in user has not
|
|
25
|
+
accepted the end-user agreement (403 "No user agreement accepted").
|
|
26
|
+
|
|
27
|
+
Accept it once with client.epersons.accept_end_user_agreement(...),
|
|
28
|
+
mark service accounts with ignore_end_user_agreement(...), or set
|
|
29
|
+
DSpaceConfig(accept_user_agreement=True) / DSPACE_ACCEPT_USER_AGREEMENT=true
|
|
30
|
+
to let the toolkit accept it for the logged-in user automatically.
|
|
31
|
+
"""
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
class NotFoundError(DSpaceError):
|
|
35
|
+
"""Exception raised when a resource is not found"""
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
class BadRequestError(DSpaceError):
|
|
39
|
+
"""Exception raised for bad request errors (400)"""
|
|
40
|
+
pass
|
|
41
|
+
|
|
42
|
+
class ValidationError(DSpaceError):
|
|
43
|
+
"""Exception raised for validation errors"""
|
|
44
|
+
pass
|
|
45
|
+
|
|
46
|
+
class ServerError(DSpaceError):
|
|
47
|
+
"""Exception raised for server errors (5xx)"""
|
|
48
|
+
pass
|
|
49
|
+
|
|
50
|
+
class SessionError(DSpaceError):
|
|
51
|
+
"""Exception raised for session-related errors"""
|
|
52
|
+
pass
|
|
53
|
+
|
|
54
|
+
def handle_response_error(response, operation_name="API operation"):
|
|
55
|
+
"""
|
|
56
|
+
Handle HTTP response errors and raise appropriate exceptions
|
|
57
|
+
|
|
58
|
+
Parameters:
|
|
59
|
+
response: requests.Response object
|
|
60
|
+
operation_name: Description of the operation for error context
|
|
61
|
+
|
|
62
|
+
Raises:
|
|
63
|
+
Appropriate DSpaceError subclass based on status code
|
|
64
|
+
"""
|
|
65
|
+
status_code = response.status_code
|
|
66
|
+
|
|
67
|
+
if status_code == 400:
|
|
68
|
+
raise BadRequestError(
|
|
69
|
+
f"{operation_name} failed: Bad Request",
|
|
70
|
+
status_code=status_code,
|
|
71
|
+
response_text=response.text
|
|
72
|
+
)
|
|
73
|
+
elif status_code == 401:
|
|
74
|
+
raise AuthenticationError(
|
|
75
|
+
f"{operation_name} failed: Unauthorized",
|
|
76
|
+
status_code=status_code,
|
|
77
|
+
response_text=response.text
|
|
78
|
+
)
|
|
79
|
+
elif status_code == 403 and "No user agreement accepted" in (response.text or ""):
|
|
80
|
+
raise UserAgreementRequired(
|
|
81
|
+
f"{operation_name} failed: Forbidden - the logged-in user has not accepted the end-user "
|
|
82
|
+
"agreement (DSpace-CRIS). Accept it, or set accept_user_agreement=True / "
|
|
83
|
+
"DSPACE_ACCEPT_USER_AGREEMENT=true",
|
|
84
|
+
status_code=status_code,
|
|
85
|
+
response_text=response.text
|
|
86
|
+
)
|
|
87
|
+
elif status_code == 403:
|
|
88
|
+
raise AuthorizationError(
|
|
89
|
+
f"{operation_name} failed: Forbidden",
|
|
90
|
+
status_code=status_code,
|
|
91
|
+
response_text=response.text
|
|
92
|
+
)
|
|
93
|
+
elif status_code == 404:
|
|
94
|
+
raise NotFoundError(
|
|
95
|
+
f"{operation_name} failed: Not Found",
|
|
96
|
+
status_code=status_code,
|
|
97
|
+
response_text=response.text
|
|
98
|
+
)
|
|
99
|
+
elif 500 <= status_code < 600:
|
|
100
|
+
raise ServerError(
|
|
101
|
+
f"{operation_name} failed: Server Error",
|
|
102
|
+
status_code=status_code,
|
|
103
|
+
response_text=response.text
|
|
104
|
+
)
|
|
105
|
+
else:
|
|
106
|
+
raise DSpaceError(
|
|
107
|
+
f"{operation_name} failed: Unexpected status {status_code}",
|
|
108
|
+
status_code=status_code,
|
|
109
|
+
response_text=response.text
|
|
110
|
+
)
|