1
# Copyright (c) 2001-2009 Twisted Matrix Laboratories.
2
# See LICENSE for details.
5
Exceptions and errors for use in twisted.internet modules.
7
Maintainer: Itamar Shtull-Trauring
12
from twisted.python import deprecate
13
from twisted.python.versions import Version
17
class BindError(Exception):
18
"""An error occurred binding to an interface"""
23
s = '%s: %s' % (s, ' '.join(self.args))
27
class CannotListenError(BindError):
28
"""This gets raised by a call to startListening, when the object cannot start listening.
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}
35
def __init__(self, interface, port, socketError):
36
BindError.__init__(self, interface, port, socketError)
37
self.interface = interface
39
self.socketError = socketError
42
iface = self.interface or 'any'
43
return "Couldn't listen on %s:%s: %s." % (iface, self.port,
47
class MulticastJoinError(Exception):
49
An attempt to join a multicast group failed.
53
class MessageLengthError(Exception):
54
"""Message is too long to send"""
59
s = '%s: %s' % (s, ' '.join(self.args))
64
class DNSLookupError(IOError):
65
"""DNS lookup failed"""
70
s = '%s: %s' % (s, ' '.join(self.args))
75
class ConnectInProgressError(Exception):
76
"""A connect operation was started and isn't done yet."""
81
class ConnectError(Exception):
82
"""An error occurred while connecting"""
84
def __init__(self, osError=None, string=""):
85
self.osError = osError
86
Exception.__init__(self, string)
89
s = self.__doc__ or self.__class__.__name__
91
s = '%s: %s' % (s, self.osError)
93
s = '%s: %s' % (s, self[0])
98
class ConnectBindError(ConnectError):
102
class UnknownHostError(ConnectError):
103
"""Hostname couldn't be looked up"""
106
class NoRouteError(ConnectError):
107
"""No route to host"""
110
class ConnectionRefusedError(ConnectError):
111
"""Connection was refused by other side"""
114
class TCPTimedOutError(ConnectError):
115
"""TCP connection timed out"""
118
class BadFileError(ConnectError):
119
"""File used for UNIX socket is no good"""
122
class ServiceNameUnknownError(ConnectError):
123
"""Service name given as port is unknown"""
126
class UserError(ConnectError):
127
"""User aborted connection"""
130
class TimeoutError(UserError):
131
"""User timeout caused connection failure"""
133
class SSLError(ConnectError):
134
"""An SSL error occurred"""
136
class VerifyError(Exception):
137
"""Could not verify something that was supposed to be signed.
140
class PeerVerifyError(VerifyError):
141
"""The peer rejected our verify error.
144
class CertificateError(Exception):
146
We did not find a certificate where we expected to find one.
152
errno.ENETUNREACH: NoRouteError,
153
errno.ECONNREFUSED: ConnectionRefusedError,
154
errno.ETIMEDOUT: TCPTimedOutError,
156
if hasattr(errno, "WSAECONNREFUSED"):
157
errnoMapping[errno.WSAECONNREFUSED] = ConnectionRefusedError
158
errnoMapping[errno.WSAENETUNREACH] = NoRouteError
162
def getConnectError(e):
163
"""Given a socket exception, return connection error."""
167
return ConnectError(string=e)
169
if hasattr(socket, 'gaierror') and isinstance(e, socket.gaierror):
171
klass = UnknownHostError
173
klass = errnoMapping.get(number, ConnectError)
174
return klass(number, string)
178
class ConnectionClosed(Exception):
180
Connection was closed, whether cleanly or non-cleanly.
185
class ConnectionLost(ConnectionClosed):
186
"""Connection to the other side was lost in a non-clean fashion"""
191
s = '%s: %s' % (s, ' '.join(self.args))
197
class ConnectionDone(ConnectionClosed):
198
"""Connection was closed cleanly"""
203
s = '%s: %s' % (s, ' '.join(self.args))
208
class ConnectionFdescWentAway(ConnectionLost):
212
class AlreadyCalled(ValueError):
213
"""Tried to cancel an already-called event"""
218
s = '%s: %s' % (s, ' '.join(self.args))
223
class AlreadyCancelled(ValueError):
224
"""Tried to cancel an already-cancelled event"""
229
s = '%s: %s' % (s, ' '.join(self.args))
235
class PotentialZombieWarning(Warning):
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.
240
Deprecated in Twisted 10.0.
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 "
250
deprecate.deprecatedModuleAttribute(
251
Version("Twisted", 10, 0, 0),
252
"There is no longer any potential for zombie process.",
254
"PotentialZombieWarning")
258
class ProcessDone(ConnectionDone):
259
"""A process has ended without apparent errors"""
261
def __init__(self, status):
262
Exception.__init__(self, "process finished with exit code 0")
268
class ProcessTerminated(ConnectionLost):
269
"""A process has ended with a probable error condition"""
271
def __init__(self, exitCode=None, signal=None, status=None):
272
self.exitCode = exitCode
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)
281
class ProcessExitedAlready(Exception):
283
The process has already exited and the operation requested can no longer
288
class NotConnectingError(RuntimeError):
289
"""The Connector was not connecting when it was asked to stop connecting"""
294
s = '%s: %s' % (s, ' '.join(self.args))
298
class NotListeningError(RuntimeError):
299
"""The Port was not listening when it was asked to stop listening"""
304
s = '%s: %s' % (s, ' '.join(self.args))
309
class ReactorNotRunning(RuntimeError):
311
Error raised when trying to stop a reactor which is not running.
315
class ReactorAlreadyRunning(RuntimeError):
317
Error raised when trying to start the reactor multiple times.