-
Notifications
You must be signed in to change notification settings - Fork 49
/
Copy pathexception.py
80 lines (60 loc) · 2.21 KB
/
exception.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
from __future__ import absolute_import, print_function, unicode_literals
from wolframclient.language.exceptions import WolframLanguageException
from wolframclient.utils.logger import str_trim
class RequestException(WolframLanguageException):
"""Error in an HTTP request."""
def __init__(self, response, msg=None):
self.response = response
if msg:
self.msg = msg
else:
try:
self.msg = response.text()
except UnicodeDecodeError:
self.msg = "Failed to decode request body."
def __str__(self):
if hasattr(self.response, "status"):
if callable(self.response.status):
status = self.response.status()
else:
status = self.response.status
elif hasattr(self.response, "status_code"):
status = self.response.status_code
else:
status = "N/A"
return "<status: {}> {}".format(status, self.msg or "")
class AuthenticationException(RequestException):
"""Error in an authentication request."""
class WolframKernelException(WolframLanguageException):
"""Error while interacting with a Wolfram kernel."""
class WolframEvaluationException(WolframLanguageException):
"""Error after an evaluation raising messages."""
def __init__(self, error, result=None, messages=[]):
self.error = error
self.result = result
if isinstance(messages, list):
self.messages = messages
else:
self.messages = [messages]
def __str__(self):
return self.error
def __repr__(self):
return "<%s error=%s, expr=%s, messages=%i>:" % (
self.__class__.__name__,
self.error,
str_trim(self.result),
len(self.messages),
)
class SocketException(WolframLanguageException):
"""Error while operating on socket."""
class WolframParserException(WolframLanguageException):
"""Error while deserializing WXF bytes."""
__all__ = [
"WolframLanguageException",
"RequestException",
"AuthenticationException",
"WolframKernelException",
"SocketException",
"WolframParserException",
"WolframEvaluationException",
]