24
24
#-----------------------------------------------------------------------------
26
from czmq cimport zmq_strerror, zmq_errno
28
ctypedef char* const_char_ptr "const char*"
30
from cpython cimport PyErr_CheckSignals
32
from libzmq cimport zmq_strerror, zmq_errno
28
34
from zmq.utils.strtypes import bytes
36
def strerror(int errno):
33
39
Return the error string given the error number.
41
cdef const_char_ptr str_e
36
42
# char * will be a bytes object:
37
str_e = zmq_strerror(errnum)
43
str_e = zmq_strerror(errno)
39
45
# Python 2: str is bytes, so we already have the right type
46
52
class ZMQBaseError(Exception):
53
"""Base exception class for 0MQ errors in Python."""
50
57
class ZMQError(ZMQBaseError):
51
"""Base exception class for 0MQ errors in Python."""
53
def __init__(self, error=None):
58
"""Wrap an errno style error.
63
The ZMQ errno or None. If None, then ``zmq_errno()`` is called and
66
Description of the error or None.
70
def __init__(self, errno=None, msg=None):
54
71
"""Wrap an errno style error.
59
The ZMQ errno or None. If None, then zmq_errno() is called and
76
The ZMQ errno or None. If None, then ``zmq_errno()`` is called and
79
Description of the error or None.
64
if type(error) == int:
65
self.strerror = strerror(error)
84
if type(errno) == int:
87
self.strerror = strerror(errno)
68
self.strerror = str(error)
92
self.strerror = str(errno)
95
# flush signals, because there could be a SIGINT
96
# waiting to pounce, resulting in uncaught exceptions.
97
# Doing this here means getting SIGINT during a blocking
98
# libzmq call will raise a *catchable* KeyboardInterrupt
71
101
def __str__(self):
72
102
return self.strerror
105
return "ZMQError('%s')"%self.strerror
75
108
class ZMQBindError(ZMQBaseError):
76
"""An error for bind_to_random_port."""
109
"""An error for ``Socket.bind_to_random_port()``.
113
.Socket.bind_to_random_port
80
118
class NotDone(ZMQBaseError):
81
"""For raising in MessageTracker.wait"""
119
"""Raised when timeout is reached while waiting for 0MQ to finish with a Message
123
.MessageTracker.wait : object for tracking when ZeroMQ is done