forked from oracle/graalpython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
189 lines (160 loc) · 6.38 KB
/
exceptions.py
File metadata and controls
189 lines (160 loc) · 6.38 KB
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
# Copyright (c) 2018, 2019, Oracle and/or its affiliates. All rights reserved.
# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
#
# The Universal Permissive License (UPL), Version 1.0
#
# Subject to the condition set forth below, permission is hereby granted to any
# person obtaining a copy of this software, associated documentation and/or
# data (collectively the "Software"), free of charge and under any and all
# copyright rights in the Software, and any and all patent rights owned or
# freely licensable by each licensor hereunder covering either (i) the
# unmodified Software as contributed to or provided by such licensor, or (ii)
# the Larger Works (as defined below), to deal in both
#
# (a) the Software, and
#
# (b) any piece of software and/or hardware listed in the lrgrwrks.txt file if
# one is included with the Software each a "Larger Work" to which the Software
# is contributed by such licensors),
#
# without restriction, including without limitation the rights to copy, create
# derivative works of, display, perform, and distribute the Software and make,
# use, sell, offer for sale, import, export, have made, and have sold the
# Software and the Larger Work(s), and to sublicense the foregoing rights on
# either these or other terms.
#
# This license is subject to the following condition:
#
# The above copyright notice and either this complete permission notice or at a
# minimum a reference to the UPL must be included in all copies or substantial
# portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# ----------------------------------------------------------------------------------------------------------------------
#
# the exceptions / errors
#
# ----------------------------------------------------------------------------------------------------------------------
def SystemExit__init__(self, *args):
if len(args) > 1:
self.code = args
elif len(args) == 1:
self.code = args[0]
else:
self.code = 0
BaseException.__init__(self, *args)
SystemExit.__init__ = SystemExit__init__
del SystemExit__init__
def ImportError__init__(self, msg, name=None, path=None):
self.message = msg
self.name = name
self.path = path
ImportError.__init__ = ImportError__init__
del ImportError__init__
def ModuleNotFoundError__init__(self, msg, name=None):
self.msg = msg
self.name = name
ModuleNotFoundError.__init__ = ModuleNotFoundError__init__
del ModuleNotFoundError__init__
def ModuleNotFoundError__str__(self):
if self.name is not None:
return "ModuleNotFound: '" + self.name + "'. " + self.msg
else:
return "ModuleNotFound: " + self.msg
ModuleNotFoundError__str__.__init__ = ModuleNotFoundError__str__
del ModuleNotFoundError__str__
# EnvironmentError is just an alias of OSError (i.e. 'EnvironmentError is OSError == True')
EnvironmentError = OSError
def StopIteration__value__get(self):
if not hasattr(self, "__value__"):
if self.args:
self.__value__ = self.args[0]
else:
self.__value__ = None
return self.__value__
def StopIteration__value__set(self, arg):
self.__value__ = arg
def StopIteration__repr__(self):
return "StopIteration%s" % repr(self.args)
StopIteration.value = property(fget=StopIteration__value__get, fset=StopIteration__value__set)
StopIteration.__repr__ = StopIteration__repr__
# These errors are just an alias of OSError (i.e. 'EnvironmentError is OSError == True')
EnvironmentError = OSError
IOError = OSError
import errno
_errnomap = {
errno.EISDIR: IsADirectoryError,
errno.EAGAIN: BlockingIOError,
errno.EALREADY: BlockingIOError,
errno.EINPROGRESS: BlockingIOError,
errno.EWOULDBLOCK: BlockingIOError,
errno.EPIPE: BrokenPipeError,
errno.ESHUTDOWN: BrokenPipeError,
errno.ECHILD: ChildProcessError,
errno.ECONNABORTED: ConnectionAbortedError,
errno.ECONNREFUSED: ConnectionRefusedError,
errno.ECONNRESET: ConnectionResetError,
errno.EEXIST: FileExistsError,
errno.ENOENT: FileNotFoundError,
errno.ENOTDIR: NotADirectoryError,
errno.EINTR: InterruptedError,
errno.EACCES: PermissionError,
errno.EPERM: PermissionError,
errno.ESRCH: ProcessLookupError,
errno.ETIMEDOUT: TimeoutError
}
def _oserror_use_init(subtype):
return subtype.__init__ is not OSError.__init__ and subtype.__new__ is OSError.__new__
def _oserror_init(self, *arg):
narg = len(arg)
self.errno = None
self.strerror = None
self.filename = None
self.filename2 = None
if (2 <= narg and narg <= 5):
self.errno = arg[0]
self.strerror = arg[1]
if(narg >= 5):
self.filename2 = arg[4]
if(narg >= 3):
self.filename = arg[2]
def OSError__new__(subtype, *args, **kwds):
newtype = subtype
if (not _oserror_use_init(newtype) and len(args) > 1):
myerrno = args[0]
if (type(myerrno) is int and subtype is OSError and myerrno in _errnomap):
newtype = _errnomap[myerrno]
self = BaseException.__new__(newtype, *args, **kwds)
self.errno = self.strerror = self.filename = self.filename2 = None
if (not _oserror_use_init(newtype)):
_oserror_init(self, *args)
return self
def OSError__init__(self, *args, **kwds):
if (not _oserror_use_init(type(self))):
return None
_oserror_init(self, *args)
def OSError__str__(self):
if (self.filename):
if(self.filename2):
return "[Errno %i] %s: %s -> %s" % (self.errno, self.strerror, self.filename, self.filename2)
else:
return "[Errno %i] %s: %s" % (self.errno, self.strerror, self.filename)
if(self.errno and self.strerror):
return "[Errno %i] %s" % (self.errno, self.strerror)
return BaseException.__str__(self)
OSError.__new__ = OSError__new__
OSError.__init__ = OSError__init__
OSError.__str__ = OSError__str__
OSError.errno = -1
OSError.strerror = None
OSError.filename = None
OSError.filename2 = None
del OSError__init__
del OSError__new__
del OSError__str__