1
"""0MQ Error classes and functions."""
4
# Copyright (c) 2010 Brian E. Granger
6
# This file is part of pyzmq.
8
# pyzmq is free software; you can redistribute it and/or modify it under
9
# the terms of the Lesser GNU General Public License as published by
10
# the Free Software Foundation; either version 3 of the License, or
11
# (at your option) any later version.
13
# pyzmq is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
# Lesser GNU General Public License for more details.
18
# You should have received a copy of the Lesser GNU General Public License
19
# along with this program. If not, see <http://www.gnu.org/licenses/>.
22
#-----------------------------------------------------------------------------
24
#-----------------------------------------------------------------------------
26
from czmq cimport zmq_strerror, zmq_errno
28
from zmq.utils.strtypes import bytes
33
Return the error string given the error number.
36
# char * will be a bytes object:
37
str_e = zmq_strerror(errnum)
39
# Python 2: str is bytes, so we already have the right type
42
# Python 3: decode bytes to unicode str
46
class ZMQBaseError(Exception):
50
class ZMQError(ZMQBaseError):
51
"""Base exception class for 0MQ errors in Python."""
53
def __init__(self, error=None):
54
"""Wrap an errno style error.
59
The ZMQ errno or None. If None, then zmq_errno() is called and
64
if type(error) == int:
65
self.strerror = strerror(error)
68
self.strerror = str(error)
75
class ZMQBindError(ZMQBaseError):
76
"""An error for bind_to_random_port."""
80
class NotDone(ZMQBaseError):
81
"""For raising in MessageTracker.wait"""
85
__all__ = ['strerror', 'ZMQBaseError', 'ZMQBindError', 'ZMQError', 'NotDone']