1
# Xlib.error -- basic error classes
3
# Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
10
# This program is distributed in the hope that it will be useful,
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
# GNU General Public License for more details.
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25
# Xlib.protocol modules
26
from Xlib.protocol import rq
29
class DisplayError(Exception):
30
def __init__(self, display):
31
self.display = display
34
return 'Display error "%s"' % self.display
36
class DisplayNameError(DisplayError):
38
return 'Bad display name "%s"' % self.display
40
class DisplayConnectionError(DisplayError):
41
def __init__(self, display, msg):
42
self.display = display
46
return 'Can\'t connect to display "%s": %s' % (self.display, self.msg)
48
class ConnectionClosedError(Exception):
49
def __init__(self, whom):
53
return 'Display connection closed by %s' % self.whom
56
class XauthError(Exception): pass
57
class XNoAuthError(Exception): pass
59
class ResourceIDError(Exception): pass
62
class XError(rq.GetAttrData, Exception):
63
_fields = rq.Struct( rq.Card8('type'), # Always 0
65
rq.Card16('sequence_number'),
66
rq.Card32('resource_id'),
67
rq.Card16('minor_opcode'),
68
rq.Card8('major_opcode'),
72
def __init__(self, display, data):
73
self._data, data = self._fields.parse_binary(data, display, rawdict = 1)
77
for f in ('code', 'resource_id', 'sequence_number',
78
'major_opcode', 'minor_opcode'):
79
s.append('%s = %s' % (f, self._data[f]))
81
return '%s: %s' % (self.__class__, string.join(s, ', '))
83
class XResourceError(XError):
84
_fields = rq.Struct( rq.Card8('type'), # Always 0
86
rq.Card16('sequence_number'),
87
rq.Resource('resource_id'),
88
rq.Card16('minor_opcode'),
89
rq.Card8('major_opcode'),
93
class BadRequest(XError): pass
94
class BadValue(XError): pass
95
class BadWindow(XResourceError): pass
96
class BadPixmap(XResourceError): pass
97
class BadAtom(XError): pass
98
class BadCursor(XResourceError): pass
99
class BadFont(XResourceError): pass
100
class BadMatch(XError): pass
101
class BadDrawable(XResourceError): pass
102
class BadAccess(XError): pass
103
class BadAlloc(XError): pass
104
class BadColor(XResourceError): pass
105
class BadGC(XResourceError): pass
106
class BadIDChoice(XResourceError): pass
107
class BadName(XError): pass
108
class BadLength(XError): pass
109
class BadImplementation(XError): pass
112
X.BadRequest: BadRequest,
113
X.BadValue: BadValue,
114
X.BadWindow: BadWindow,
115
X.BadPixmap: BadPixmap,
117
X.BadCursor: BadCursor,
119
X.BadMatch: BadMatch,
120
X.BadDrawable: BadDrawable,
121
X.BadAccess: BadAccess,
122
X.BadAlloc: BadAlloc,
123
X.BadColor: BadColor,
125
X.BadIDChoice: BadIDChoice,
127
X.BadLength: BadLength,
128
X.BadImplementation: BadImplementation,
133
def __init__(self, *errors):
134
self.error_types = errors
138
def __call__(self, error, request):
140
for etype in self.error_types:
141
if isinstance(error, etype):
143
self.request = request
149
self.request = request
155
def get_request(self):