1"""0MQ Error classes and functions."""
2
3#
4#    Copyright (c) 2010-2011 Brian E. Granger & Min Ragan-Kelley
5#
6#    This file is part of pyzmq.
7#
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.
12#
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.
17#
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/>.
20#
21
22#-----------------------------------------------------------------------------
23# Imports
24#-----------------------------------------------------------------------------
25
26# allow const char*
27cdef extern from *:
28    ctypedef char* const_char_ptr "const char*"
29
30from libzmq cimport zmq_strerror, zmq_errno as zmq_errno_c
31
32from zmq.utils.strtypes import bytes
33
34def strerror(int errno):
35    """strerror(errno)
36
37    Return the error string given the error number.
38    """
39    cdef const_char_ptr str_e
40    # char * will be a bytes object:
41    str_e = zmq_strerror(errno)
42    if str is bytes:
43        # Python 2: str is bytes, so we already have the right type
44        return str_e
45    else:
46        # Python 3: decode bytes to unicode str
47        return str_e.decode()
48
49def 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']
57