forked from SeattleTestbed/repy_v2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exception_hierarchy.py
262 lines (212 loc) · 6.34 KB
/
exception_hierarchy.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
"""
This file contains the exception hierarchy for repy. This allows repy modules
to import a single file to have access to all the defined exceptions.
"""
# This list maintains the exceptions that are exported to the user
# If the exception is not listed here, the user cannot explicitly
# catch that error.
_EXPORTED_EXCEPTIONS = ["RepyException",
"RepyArgumentError",
"CodeUnsafeError",
"ContextUnsafeError",
"ResourceUsageError",
"ResourceExhaustedError",
"ResourceForbiddenError",
"FileError",
"FileNotFoundError",
"FileInUseError",
"SeekPastEndOfFileError",
"FileClosedError",
"LockDoubleReleaseError",
"NetworkError",
"NetworkAddressError",
"AlreadyListeningError",
"DuplicateTupleError",
"CleanupInProgressError",
"InternetConnectivityError",
"AddressBindingError",
"ConnectionRefusedError",
"LocalIPChanged",
"SocketClosedLocal",
"SocketClosedRemote",
"SocketWouldBlockError",
"TCPServerSocketInvalidError",
"TimeoutError",
]
##### High-level, generic exceptions
class InternalRepyError (Exception):
"""
All Fatal Repy Exceptions derive from this exception.
This error should never make it to the user-code.
"""
pass
class RepyException (Exception):
"""All Repy Exceptions derive from this exception."""
pass
class RepyArgumentError (RepyException):
"""
This Exception indicates that an argument was provided
to a repy API as an in-appropriate type or value.
"""
pass
class TimeoutError (RepyException):
"""
This generic error indicates that a timeout has
occurred.
"""
pass
##### Code Safety Exceptions
class CodeUnsafeError (RepyException):
"""
This indicates that the static code analysis failed due to
unsafe constructions or a syntax error.
"""
pass
class ContextUnsafeError (RepyException):
"""
This indicates that the context provided to evaluate() was
unsafe, and could not be converted into a SafeDict.
"""
pass
##### Resource Related Exceptions
class ResourceUsageError (RepyException):
"""
All Resource Usage Exceptions derive from this exception.
"""
pass
class ResourceExhaustedError (ResourceUsageError):
"""
This Exception indicates that a resource has been
Exhausted, and that the operation has failed for that
reason.
"""
pass
class ResourceForbiddenError (ResourceUsageError):
"""
This Exception indicates that a specified resource
is forbidden, and cannot be used.
"""
pass
##### File Related Exceptions
class FileError (RepyException):
"""All File-Related Exceptions derive from this exception."""
pass
class FileNotFoundError (FileError):
"""
This Exception indicates that a file which does not exist was
used as an argument to a function expecting a real file.
"""
pass
class FileInUseError (FileError):
"""
This Exception indicates that a file which is in use was
used as an argument to a function expecting the file to
be un-used.
"""
pass
class SeekPastEndOfFileError (FileError):
"""
This Exception indicates that an attempt was made to
seek past the end of a file.
"""
pass
class FileClosedError (FileError):
"""
This Exception indicates that the file is closed,
and that the operation is therfor invalid.
"""
pass
##### Safety exceptions from safe.py
class SafeException(RepyException):
"""Base class for Safe Exceptions"""
def __init__(self,*value):
self.value = str(value)
def __str__(self):
return self.value
class CheckNodeException(SafeException):
"""AST Node class is not in the whitelist."""
pass
class CheckStrException(SafeException):
"""A string in the AST looks insecure."""
pass
class RunBuiltinException(SafeException):
"""During the run a non-whitelisted builtin was called."""
pass
##### Lock related exceptions
class LockDoubleReleaseError(RepyException):
"""
This exception indicates that an attempt was made to
release a lock that was not acquired.
"""
pass
##### Network exceptions
class NetworkError (RepyException):
"""
This exception parent-classes all of the networking exceptions.
"""
pass
class NetworkAddressError (NetworkError):
"""
This exception is raised when a DNS lookup fails.
"""
pass
class AlreadyListeningError (NetworkError):
"""
This exception indicates that there is an existing
listen on the local IP / Port pair that are specified.
"""
pass
class DuplicateTupleError (NetworkError):
"""
This exception indicates that there is another socket
which has a duplicate tuple (local ip, local port, remote ip, remote port)
"""
pass
class CleanupInProgressError (NetworkError):
"""
This exception indicates that the socket is still
being cleaned up by the operating system, and that
it is unavailable.
"""
pass
class InternetConnectivityError (NetworkError):
"""
This exception is raised when there is no route to an IP passed to
sendmessage or openconnection.
"""
pass
class AddressBindingError (NetworkError):
"""
This exception is raised when binding to an ip and port fails.
"""
pass
class ConnectionRefusedError (NetworkError):
"""
This exception is raised when a TCP connection request is refused.
"""
pass
class LocalIPChanged (NetworkError):
"""
This exception indicates that the local IP has changed.
"""
pass
class SocketClosedLocal (NetworkError):
"""
This indicates that the socket was closed locally.
"""
pass
class SocketClosedRemote (NetworkError):
"""
This indicates that the socket was closed on the remote end.
"""
pass
class SocketWouldBlockError (NetworkError):
"""
This indicates that the socket operation would have blocked.
"""
pass
class TCPServerSocketInvalidError(NetworkError):
"""
This indicates that the TCP server socket has become invalid, e.g.
because the local IP address changed.
"""