~ubuntu-branches/ubuntu/utopic/pyzmq/utopic-proposed

« back to all changes in this revision

Viewing changes to zmq/core/error.pyx

  • Committer: Package Import Robot
  • Author(s): Julian Taylor
  • Date: 2013-05-12 13:59:20 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20130512135920-1d2md9w425iq3sb6
Tags: 13.1.0-1
* New upstream release built with zeromq3 (Closes: #698830)
  - drop all patches
* workaround-gevent.patch: workaround issue with gevent < 1.0
* noncopysend-test.patch: avoid uninitialized values in tests
* update copyright

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
cdef extern from *:
28
28
    ctypedef char* const_char_ptr "const char*"
29
29
 
30
 
from cpython cimport PyErr_CheckSignals
31
 
 
32
 
from libzmq cimport zmq_strerror, zmq_errno
 
30
from libzmq cimport zmq_strerror, zmq_errno as zmq_errno_c
33
31
 
34
32
from zmq.utils.strtypes import bytes
35
33
 
48
46
        # Python 3: decode bytes to unicode str
49
47
        return str_e.decode()
50
48
 
51
 
 
52
 
class ZMQBaseError(Exception):
53
 
    """Base exception class for 0MQ errors in Python."""
54
 
    pass
55
 
 
56
 
 
57
 
class ZMQError(ZMQBaseError):
58
 
    """Wrap an errno style error.
59
 
 
60
 
    Parameters
61
 
    ----------
62
 
    errno : int
63
 
        The ZMQ errno or None.  If None, then ``zmq_errno()`` is called and
64
 
        used.
65
 
    msg : string
66
 
        Description of the error or None.
67
 
    """
68
 
    errno = None
69
 
 
70
 
    def __init__(self, errno=None, msg=None):
71
 
        """Wrap an errno style error.
72
 
 
73
 
        Parameters
74
 
        ----------
75
 
        errno : int
76
 
            The ZMQ errno or None.  If None, then ``zmq_errno()`` is called and
77
 
            used.
78
 
        msg : string
79
 
            Description of the error or None.
80
 
        """
81
 
        if errno is None:
82
 
            errno = zmq_errno()
83
 
            error = errno
84
 
        if type(errno) == int:
85
 
            self.errno = errno
86
 
            if msg is None:
87
 
                self.strerror = strerror(errno)
88
 
            else:
89
 
                self.strerror = msg
90
 
        else:
91
 
            if msg is None:
92
 
                self.strerror = str(errno)
93
 
            else:
94
 
                self.strerror = msg
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
99
 
        PyErr_CheckSignals()
100
 
 
101
 
    def __str__(self):
102
 
        return self.strerror
103
 
    
104
 
    def __repr__(self):
105
 
        return "ZMQError('%s')"%self.strerror
106
 
 
107
 
 
108
 
class ZMQBindError(ZMQBaseError):
109
 
    """An error for ``Socket.bind_to_random_port()``.
110
 
    
111
 
    See Also
112
 
    --------
113
 
    .Socket.bind_to_random_port
114
 
    """
115
 
    pass
116
 
 
117
 
 
118
 
class NotDone(ZMQBaseError):
119
 
    """Raised when timeout is reached while waiting for 0MQ to finish with a Message
120
 
    
121
 
    See Also
122
 
    --------
123
 
    .MessageTracker.wait : object for tracking when ZeroMQ is done
124
 
    """
125
 
    pass
126
 
 
127
 
 
128
 
__all__ = ['strerror', 'ZMQBaseError', 'ZMQBindError', 'ZMQError', 'NotDone']
 
49
def zmq_errno():
 
50
    """zmq_errno()
 
51
    
 
52
    Return the integer errno of the most recent zmq error.
 
53
    """
 
54
    return zmq_errno_c()
 
55
 
 
56
__all__ = ['strerror', 'zmq_errno']