~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/twisted/internet/error.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
 
2
# See LICENSE for details.
 
3
 
 
4
"""
 
5
Exceptions and errors for use in twisted.internet modules.
 
6
 
 
7
Maintainer: Itamar Shtull-Trauring
 
8
"""
 
9
 
 
10
import socket
 
11
 
 
12
from twisted.python import deprecate
 
13
from twisted.python.versions import Version
 
14
 
 
15
 
 
16
 
 
17
class BindError(Exception):
 
18
    """An error occurred binding to an interface"""
 
19
 
 
20
    def __str__(self):
 
21
        s = self.__doc__
 
22
        if self.args:
 
23
            s = '%s: %s' % (s, ' '.join(self.args))
 
24
        s = '%s.' % s
 
25
        return s
 
26
 
 
27
class CannotListenError(BindError):
 
28
    """This gets raised by a call to startListening, when the object cannot start listening.
 
29
 
 
30
    @ivar interface: the interface I tried to listen on
 
31
    @ivar port: the port I tried to listen on
 
32
    @ivar socketError: the exception I got when I tried to listen
 
33
    @type socketError: L{socket.error}
 
34
    """
 
35
    def __init__(self, interface, port, socketError):
 
36
        BindError.__init__(self, interface, port, socketError)
 
37
        self.interface = interface
 
38
        self.port = port
 
39
        self.socketError = socketError
 
40
 
 
41
    def __str__(self):
 
42
        iface = self.interface or 'any'
 
43
        return "Couldn't listen on %s:%s: %s." % (iface, self.port,
 
44
                                                 self.socketError)
 
45
 
 
46
 
 
47
class MulticastJoinError(Exception):
 
48
    """
 
49
    An attempt to join a multicast group failed.
 
50
    """
 
51
 
 
52
 
 
53
class MessageLengthError(Exception):
 
54
    """Message is too long to send"""
 
55
 
 
56
    def __str__(self):
 
57
        s = self.__doc__
 
58
        if self.args:
 
59
            s = '%s: %s' % (s, ' '.join(self.args))
 
60
        s = '%s.' % s
 
61
        return s
 
62
 
 
63
 
 
64
class DNSLookupError(IOError):
 
65
    """DNS lookup failed"""
 
66
 
 
67
    def __str__(self):
 
68
        s = self.__doc__
 
69
        if self.args:
 
70
            s = '%s: %s' % (s, ' '.join(self.args))
 
71
        s = '%s.' % s
 
72
        return s
 
73
 
 
74
 
 
75
class ConnectInProgressError(Exception):
 
76
    """A connect operation was started and isn't done yet."""
 
77
 
 
78
 
 
79
# connection errors
 
80
 
 
81
class ConnectError(Exception):
 
82
    """An error occurred while connecting"""
 
83
 
 
84
    def __init__(self, osError=None, string=""):
 
85
        self.osError = osError
 
86
        Exception.__init__(self, string)
 
87
 
 
88
    def __str__(self):
 
89
        s = self.__doc__ or self.__class__.__name__
 
90
        if self.osError:
 
91
            s = '%s: %s' % (s, self.osError)
 
92
        if self[0]:
 
93
            s = '%s: %s' % (s, self[0])
 
94
        s = '%s.' % s
 
95
        return s
 
96
 
 
97
 
 
98
class ConnectBindError(ConnectError):
 
99
    """Couldn't bind"""
 
100
 
 
101
 
 
102
class UnknownHostError(ConnectError):
 
103
    """Hostname couldn't be looked up"""
 
104
 
 
105
 
 
106
class NoRouteError(ConnectError):
 
107
    """No route to host"""
 
108
 
 
109
 
 
110
class ConnectionRefusedError(ConnectError):
 
111
    """Connection was refused by other side"""
 
112
 
 
113
 
 
114
class TCPTimedOutError(ConnectError):
 
115
    """TCP connection timed out"""
 
116
 
 
117
 
 
118
class BadFileError(ConnectError):
 
119
    """File used for UNIX socket is no good"""
 
120
 
 
121
 
 
122
class ServiceNameUnknownError(ConnectError):
 
123
    """Service name given as port is unknown"""
 
124
 
 
125
 
 
126
class UserError(ConnectError):
 
127
    """User aborted connection"""
 
128
 
 
129
 
 
130
class TimeoutError(UserError):
 
131
    """User timeout caused connection failure"""
 
132
 
 
133
class SSLError(ConnectError):
 
134
    """An SSL error occurred"""
 
135
 
 
136
class VerifyError(Exception):
 
137
    """Could not verify something that was supposed to be signed.
 
138
    """
 
139
 
 
140
class PeerVerifyError(VerifyError):
 
141
    """The peer rejected our verify error.
 
142
    """
 
143
 
 
144
class CertificateError(Exception):
 
145
    """
 
146
    We did not find a certificate where we expected to find one.
 
147
    """
 
148
 
 
149
try:
 
150
    import errno
 
151
    errnoMapping = {
 
152
        errno.ENETUNREACH: NoRouteError,
 
153
        errno.ECONNREFUSED: ConnectionRefusedError,
 
154
        errno.ETIMEDOUT: TCPTimedOutError,
 
155
    }
 
156
    if hasattr(errno, "WSAECONNREFUSED"):
 
157
        errnoMapping[errno.WSAECONNREFUSED] = ConnectionRefusedError
 
158
        errnoMapping[errno.WSAENETUNREACH] = NoRouteError
 
159
except ImportError:
 
160
    errnoMapping = {}
 
161
 
 
162
def getConnectError(e):
 
163
    """Given a socket exception, return connection error."""
 
164
    try:
 
165
        number, string = e
 
166
    except ValueError:
 
167
        return ConnectError(string=e)
 
168
 
 
169
    if hasattr(socket, 'gaierror') and isinstance(e, socket.gaierror):
 
170
        # only works in 2.2
 
171
        klass = UnknownHostError
 
172
    else:
 
173
        klass = errnoMapping.get(number, ConnectError)
 
174
    return klass(number, string)
 
175
 
 
176
 
 
177
 
 
178
class ConnectionClosed(Exception):
 
179
    """
 
180
    Connection was closed, whether cleanly or non-cleanly.
 
181
    """
 
182
 
 
183
 
 
184
 
 
185
class ConnectionLost(ConnectionClosed):
 
186
    """Connection to the other side was lost in a non-clean fashion"""
 
187
 
 
188
    def __str__(self):
 
189
        s = self.__doc__
 
190
        if self.args:
 
191
            s = '%s: %s' % (s, ' '.join(self.args))
 
192
        s = '%s.' % s
 
193
        return s
 
194
 
 
195
 
 
196
 
 
197
class ConnectionDone(ConnectionClosed):
 
198
    """Connection was closed cleanly"""
 
199
 
 
200
    def __str__(self):
 
201
        s = self.__doc__
 
202
        if self.args:
 
203
            s = '%s: %s' % (s, ' '.join(self.args))
 
204
        s = '%s.' % s
 
205
        return s
 
206
 
 
207
 
 
208
class ConnectionFdescWentAway(ConnectionLost):
 
209
    """Uh""" #TODO
 
210
 
 
211
 
 
212
class AlreadyCalled(ValueError):
 
213
    """Tried to cancel an already-called event"""
 
214
 
 
215
    def __str__(self):
 
216
        s = self.__doc__
 
217
        if self.args:
 
218
            s = '%s: %s' % (s, ' '.join(self.args))
 
219
        s = '%s.' % s
 
220
        return s
 
221
 
 
222
 
 
223
class AlreadyCancelled(ValueError):
 
224
    """Tried to cancel an already-cancelled event"""
 
225
 
 
226
    def __str__(self):
 
227
        s = self.__doc__
 
228
        if self.args:
 
229
            s = '%s: %s' % (s, ' '.join(self.args))
 
230
        s = '%s.' % s
 
231
        return s
 
232
 
 
233
 
 
234
 
 
235
class PotentialZombieWarning(Warning):
 
236
    """
 
237
    Emitted when L{IReactorProcess.spawnProcess} is called in a way which may
 
238
    result in termination of the created child process not being reported.
 
239
 
 
240
    Deprecated in Twisted 10.0.
 
241
    """
 
242
    MESSAGE = (
 
243
        "spawnProcess called, but the SIGCHLD handler is not "
 
244
        "installed. This probably means you have not yet "
 
245
        "called reactor.run, or called "
 
246
        "reactor.run(installSignalHandler=0). You will probably "
 
247
        "never see this process finish, and it may become a "
 
248
        "zombie process.")
 
249
 
 
250
deprecate.deprecatedModuleAttribute(
 
251
    Version("Twisted", 10, 0, 0),
 
252
    "There is no longer any potential for zombie process.",
 
253
    __name__,
 
254
    "PotentialZombieWarning")
 
255
 
 
256
 
 
257
 
 
258
class ProcessDone(ConnectionDone):
 
259
    """A process has ended without apparent errors"""
 
260
 
 
261
    def __init__(self, status):
 
262
        Exception.__init__(self, "process finished with exit code 0")
 
263
        self.exitCode = 0
 
264
        self.signal = None
 
265
        self.status = status
 
266
 
 
267
 
 
268
class ProcessTerminated(ConnectionLost):
 
269
    """A process has ended with a probable error condition"""
 
270
 
 
271
    def __init__(self, exitCode=None, signal=None, status=None):
 
272
        self.exitCode = exitCode
 
273
        self.signal = signal
 
274
        self.status = status
 
275
        s = "process ended"
 
276
        if exitCode is not None: s = s + " with exit code %s" % exitCode
 
277
        if signal is not None: s = s + " by signal %s" % signal
 
278
        Exception.__init__(self, s)
 
279
 
 
280
 
 
281
class ProcessExitedAlready(Exception):
 
282
    """
 
283
    The process has already exited and the operation requested can no longer
 
284
    be performed.
 
285
    """
 
286
 
 
287
 
 
288
class NotConnectingError(RuntimeError):
 
289
    """The Connector was not connecting when it was asked to stop connecting"""
 
290
 
 
291
    def __str__(self):
 
292
        s = self.__doc__
 
293
        if self.args:
 
294
            s = '%s: %s' % (s, ' '.join(self.args))
 
295
        s = '%s.' % s
 
296
        return s
 
297
 
 
298
class NotListeningError(RuntimeError):
 
299
    """The Port was not listening when it was asked to stop listening"""
 
300
 
 
301
    def __str__(self):
 
302
        s = self.__doc__
 
303
        if self.args:
 
304
            s = '%s: %s' % (s, ' '.join(self.args))
 
305
        s = '%s.' % s
 
306
        return s
 
307
 
 
308
 
 
309
class ReactorNotRunning(RuntimeError):
 
310
    """
 
311
    Error raised when trying to stop a reactor which is not running.
 
312
    """
 
313
 
 
314
 
 
315
class ReactorAlreadyRunning(RuntimeError):
 
316
    """
 
317
    Error raised when trying to start the reactor multiple times.
 
318
    """
 
319