~bennabiy/+junk/python-xlib

« back to all changes in this revision

Viewing changes to .pc/python3.patch/Xlib/error.py

  • Committer: Package Import Robot
  • Author(s): Andrew Shadura, Ramkumar Ramachandra, Andrew Shadura
  • Date: 2015-08-13 08:14:19 UTC
  • mfrom: (6.1.2 sid)
  • Revision ID: package-import@ubuntu.com-20150813081419-hdefinnghp2iydkx
Tags: 0.14+20091101-3
[ Ramkumar Ramachandra ]
* Remove useless debugging output (Closes: #565996)

[ Andrew Shadura ]
* Switch to 3.0 (quilt) format.
* Rename patches.
* Use debhelper 9 in its short form.
* Use pybuild.
* Bump Standards-Version.
* Don't build or install PostScript documentation and info files.
* Use system-provided texi2html instead of a shipped version
  (Closes: #795057).
* Update debian/copyright (Closes: #795057).
* Don't install Makefile or texi2html with the documentation.
* Set executable bit for examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Xlib.error -- basic error classes
 
2
#
 
3
#    Copyright (C) 2000 Peter Liljenberg <petli@ctrl-c.liu.se>
 
4
#
 
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.
 
9
#
 
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.
 
14
#
 
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
 
18
 
 
19
# Standard modules
 
20
import string
 
21
 
 
22
# Xlib modules
 
23
import X
 
24
 
 
25
# Xlib.protocol modules
 
26
from Xlib.protocol import rq
 
27
 
 
28
 
 
29
class DisplayError(Exception):
 
30
    def __init__(self, display):
 
31
        self.display = display
 
32
 
 
33
    def __str__(self):
 
34
        return 'Display error "%s"' % self.display
 
35
 
 
36
class DisplayNameError(DisplayError):
 
37
    def __str__(self):
 
38
        return 'Bad display name "%s"' % self.display
 
39
 
 
40
class DisplayConnectionError(DisplayError):
 
41
    def __init__(self, display, msg):
 
42
        self.display = display
 
43
        self.msg = msg
 
44
 
 
45
    def __str__(self):
 
46
        return 'Can\'t connect to display "%s": %s' % (self.display, self.msg)
 
47
 
 
48
class ConnectionClosedError(Exception):
 
49
    def __init__(self, whom):
 
50
        self.whom = whom
 
51
 
 
52
    def __str__(self):
 
53
        return 'Display connection closed by %s' % self.whom
 
54
 
 
55
 
 
56
class XauthError(Exception): pass
 
57
class XNoAuthError(Exception): pass
 
58
 
 
59
class ResourceIDError(Exception): pass
 
60
 
 
61
 
 
62
class XError(rq.GetAttrData, Exception):
 
63
    _fields = rq.Struct( rq.Card8('type'),  # Always 0
 
64
                         rq.Card8('code'),
 
65
                         rq.Card16('sequence_number'),
 
66
                         rq.Card32('resource_id'),
 
67
                         rq.Card16('minor_opcode'),
 
68
                         rq.Card8('major_opcode'),
 
69
                         rq.Pad(21)
 
70
                         )
 
71
 
 
72
    def __init__(self, display, data):
 
73
        self._data, data = self._fields.parse_binary(data, display, rawdict = 1)
 
74
 
 
75
    def __str__(self):
 
76
        s = []
 
77
        for f in ('code', 'resource_id', 'sequence_number',
 
78
                  'major_opcode', 'minor_opcode'):
 
79
            s.append('%s = %s' % (f, self._data[f]))
 
80
 
 
81
        return '%s: %s' % (self.__class__, string.join(s, ', '))
 
82
 
 
83
class XResourceError(XError):
 
84
    _fields = rq.Struct( rq.Card8('type'),  # Always 0
 
85
                         rq.Card8('code'),
 
86
                         rq.Card16('sequence_number'),
 
87
                         rq.Resource('resource_id'),
 
88
                         rq.Card16('minor_opcode'),
 
89
                         rq.Card8('major_opcode'),
 
90
                         rq.Pad(21)
 
91
                         )
 
92
 
 
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
 
110
 
 
111
xerror_class = {
 
112
    X.BadRequest: BadRequest,
 
113
    X.BadValue: BadValue,
 
114
    X.BadWindow: BadWindow,
 
115
    X.BadPixmap: BadPixmap,
 
116
    X.BadAtom: BadAtom,
 
117
    X.BadCursor: BadCursor,
 
118
    X.BadFont: BadFont,
 
119
    X.BadMatch: BadMatch,
 
120
    X.BadDrawable: BadDrawable,
 
121
    X.BadAccess: BadAccess,
 
122
    X.BadAlloc: BadAlloc,
 
123
    X.BadColor: BadColor,
 
124
    X.BadGC: BadGC,
 
125
    X.BadIDChoice: BadIDChoice,
 
126
    X.BadName: BadName,
 
127
    X.BadLength: BadLength,
 
128
    X.BadImplementation: BadImplementation,
 
129
    }
 
130
 
 
131
 
 
132
class CatchError:
 
133
    def __init__(self, *errors):
 
134
        self.error_types = errors
 
135
        self.error = None
 
136
        self.request = None
 
137
 
 
138
    def __call__(self, error, request):
 
139
        if self.error_types:
 
140
            for etype in self.error_types:
 
141
                if isinstance(error, etype):
 
142
                    self.error = error
 
143
                    self.request = request
 
144
                    return 1
 
145
 
 
146
            return 0
 
147
        else:
 
148
            self.error = error
 
149
            self.request = request
 
150
            return 1
 
151
 
 
152
    def get_error(self):
 
153
        return self.error
 
154
 
 
155
    def get_request(self):
 
156
        return self.request
 
157
 
 
158
    def reset(self):
 
159
        self.error = None
 
160
        self.request = None