/usr/lib/python2.7/dist-packages/libopensesame/exceptions.py is in opensesame 0.27.4-2.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #-*- coding:utf-8 -*-
"""
This file is part of OpenSesame.
OpenSesame is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
OpenSesame is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenSesame. If not, see <http://www.gnu.org/licenses/>.
"""
import traceback
class form_error(Exception):
"""
A form_error is thrown when an error occurs in a form or a form widget.
"""
def __init__(self, value, full=True):
if type(value) == str:
self.value = unicode(value, errors=u'ignore')
else:
self.value = value
self.full = full
def __str__(self):
if self.full:
return u'<b>Error:</b> Form error<br /><b>Description</b>: %s' % \
self.value
return self.value
class script_error(Exception):
"""
A form_error is thrown when parsing a script using the from_string()
functions fails.
"""
def __init__(self, value, full=True):
if type(value) == str:
self.value = unicode(value, errors=u'ignore')
else:
self.value = value
self.full = full
def __str__(self):
if self.full:
return u'<b>Error:</b> Script error<br /><b>Description</b>: %s' % \
self.value
return self.value
class runtime_error(Exception):
"""
A runtime error is thrown when somethingg oes wrong while running a script,
which includes the preparation phase.
"""
def __init__(self, value):
if type(value) == str:
self.value = unicode(value, errors=u'ignore')
else:
self.value = value
def __str__(self):
return u'<b>Error:</b> Runtime error<br /><b>Description</b>: %s' % \
self.value
class inline_error(runtime_error):
"""
An inline error is thrown when something goes wrong in an inline_script
item. The Python traceback is parsed and returned.
"""
def __init__(self, item_name, phase, exception):
self.name = item_name
self.phase = phase
# Split the traceback
l = traceback.format_exc(exception).split("\n")
# Print the traceback to the stdout
for r in l:
print r
# We are only interested in the last two lines
l = l[-3:]
s = u'<b>Error</b>: Inline script error'
s += u'<br /><b>In</b>: %s (%s phase)' % (item_name, phase)
s += u'<br />' + self.parse_line(l[0])
s += u'<br /><br /><b>Python traceback</b>:'
for r in l[1:]:
s += u'<br />%s' % r
s += u'<br /><i>Full traceback in debug window</i>'
self.value = s
def parse_line(self, s):
s = s.replace(u'File "<string>", line', u'<b>Line:</b>')
s = s.replace(u', in <module>', u'')
return s
def __str__(self):
return self.value
|