1################################################################################
2#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
3#  Read the zproject/README.md for information about making permanent changes. #
4################################################################################
5
6from __future__ import print_function
7import os, sys
8from ctypes import *
9from ctypes.util import find_library
10
11# load libc to access free, etc.
12libcpath = find_library("c")
13if not libcpath:
14    raise ImportError("Unable to find libc")
15libc = cdll.LoadLibrary(libcpath)
16libc.free.argtypes = [c_void_p]
17libc.free.restype = None
18
19def return_fresh_string(char_p):
20    s = string_at(char_p)
21    libc.free(char_p)
22    return s
23
24# czmq
25lib = None
26# check to see if the shared object was embedded locally, attempt to load it
27# if not, try to load it using the default system paths...
28# we need to use os.chdir instead of trying to modify $LD_LIBRARY_PATH and reloading the interpreter
29t = os.getcwd()
30p = os.path.join(os.path.dirname(__file__), '..')  # find the path to our $project_ctypes.py
31os.chdir(p)  # change directories briefly
32
33try:
34    from czmq import libczmq                        # attempt to import the shared lib if it exists
35    lib = CDLL(libczmq.__file__)             # if it exists try to load the shared lib
36except ImportError:
37    pass
38finally:
39    os.chdir(t)  # switch back to orig dir
40
41if not lib:
42    try:
43        # If LD_LIBRARY_PATH or your OSs equivalent is set, this is the only way to
44        # load the library.  If we use find_library below, we get the wrong result.
45        if os.name == 'posix':
46            if sys.platform == 'darwin':
47                lib = cdll.LoadLibrary('libczmq.4.dylib')
48            else:
49                lib = cdll.LoadLibrary("libczmq.so.4")
50        elif os.name == 'nt':
51            lib = cdll.LoadLibrary('libczmq.dll')
52    except OSError:
53        libpath = find_library("czmq")
54        if not libpath:
55            raise ImportError("Unable to find libczmq")
56        lib = cdll.LoadLibrary(libpath)
57
58class zsock_t(Structure):
59    pass # Empty - only for type checking
60zsock_p = POINTER(zsock_t)
61
62class zactor_t(Structure):
63    pass # Empty - only for type checking
64zactor_p = POINTER(zactor_t)
65
66class zmsg_t(Structure):
67    pass # Empty - only for type checking
68zmsg_p = POINTER(zmsg_t)
69
70class zargs_t(Structure):
71    pass # Empty - only for type checking
72zargs_p = POINTER(zargs_t)
73
74class zarmour_t(Structure):
75    pass # Empty - only for type checking
76zarmour_p = POINTER(zarmour_t)
77
78class zchunk_t(Structure):
79    pass # Empty - only for type checking
80zchunk_p = POINTER(zchunk_t)
81
82class char_t(Structure):
83    pass # Empty - only for type checking
84char_p = POINTER(char_t)
85
86class zcert_t(Structure):
87    pass # Empty - only for type checking
88zcert_p = POINTER(zcert_t)
89
90class zlist_t(Structure):
91    pass # Empty - only for type checking
92zlist_p = POINTER(zlist_t)
93
94class zcertstore_t(Structure):
95    pass # Empty - only for type checking
96zcertstore_p = POINTER(zcertstore_t)
97
98class zlistx_t(Structure):
99    pass # Empty - only for type checking
100zlistx_p = POINTER(zlistx_t)
101
102class FILE(Structure):
103    pass # Empty - only for type checking
104FILE_p = POINTER(FILE)
105
106class zframe_t(Structure):
107    pass # Empty - only for type checking
108zframe_p = POINTER(zframe_t)
109
110class msecs_t(Structure):
111    pass # Empty - only for type checking
112msecs_p = POINTER(msecs_t)
113
114class zconfig_t(Structure):
115    pass # Empty - only for type checking
116zconfig_p = POINTER(zconfig_t)
117
118class zdigest_t(Structure):
119    pass # Empty - only for type checking
120zdigest_p = POINTER(zdigest_t)
121
122class zdir_t(Structure):
123    pass # Empty - only for type checking
124zdir_p = POINTER(zdir_t)
125
126class zhash_t(Structure):
127    pass # Empty - only for type checking
128zhash_p = POINTER(zhash_t)
129
130class zfile_t(Structure):
131    pass # Empty - only for type checking
132zfile_p = POINTER(zfile_t)
133
134class zdir_patch_t(Structure):
135    pass # Empty - only for type checking
136zdir_patch_p = POINTER(zdir_patch_t)
137
138class zhashx_t(Structure):
139    pass # Empty - only for type checking
140zhashx_p = POINTER(zhashx_t)
141
142class ziflist_t(Structure):
143    pass # Empty - only for type checking
144ziflist_p = POINTER(ziflist_t)
145
146class zloop_t(Structure):
147    pass # Empty - only for type checking
148zloop_p = POINTER(zloop_t)
149
150class zmq_pollitem_t(Structure):
151    pass # Empty - only for type checking
152zmq_pollitem_p = POINTER(zmq_pollitem_t)
153
154class zpoller_t(Structure):
155    pass # Empty - only for type checking
156zpoller_p = POINTER(zpoller_t)
157
158class zproc_t(Structure):
159    pass # Empty - only for type checking
160zproc_p = POINTER(zproc_t)
161
162class va_list_t(Structure):
163    pass # Empty - only for type checking
164va_list_p = POINTER(va_list_t)
165
166class socket_t(Structure):
167    pass # Empty - only for type checking
168socket_p = POINTER(socket_t)
169
170class ztimerset_t(Structure):
171    pass # Empty - only for type checking
172ztimerset_p = POINTER(ztimerset_t)
173
174class ztrie_t(Structure):
175    pass # Empty - only for type checking
176ztrie_p = POINTER(ztrie_t)
177
178class zuuid_t(Structure):
179    pass # Empty - only for type checking
180zuuid_p = POINTER(zuuid_t)
181
182def return_py_file(c_file):
183    if not sys.version_info > (3,):
184        PyFile_FromFile_close_cb = CFUNCTYPE(c_int, FILE_p)
185        PyFile_FromFile = pythonapi.PyFile_FromFile
186        PyFile_FromFile.restype = py_object
187        PyFile_FromFile.argtypes = [FILE_p,
188                                    c_char_p,
189                                    c_char_p,
190                                    PyFile_FromFile_close_cb]
191        return PyFile_FromFile(c_file, "", "r+", PyFile_FromFile_close_cb())
192
193    else:
194        fileno = libc.fileno
195        fileno.restype = c_int
196        fileno.argtypes = [c_void_p]
197
198        return os.fdopen(fileno(c_file), r'r+b')
199
200def coerce_py_file(obj):
201    if not sys.version_info > (3,):
202        PyFile_AsFile = pythonapi.PyFile_AsFile
203        PyFile_AsFile.restype = FILE_p
204        PyFile_AsFile.argtypes = [py_object]
205
206        if isinstance(obj, FILE_p):
207            return obj
208        else:
209            return PyFile_AsFile(obj)
210
211    # Python 3 does not provide a low level buffered I/O (FILE*) API. Had to
212    # resort to direct Standard C library calls.
213    #
214    #   https://docs.python.org/3/c-api/file.html.
215    #
216    else:
217        fdopen = libc.fdopen
218        fdopen.restype = FILE_p
219        fdopen.argtypes = [c_int, c_char_p]
220
221        setbuf = libc.setbuf
222        setbuf.restype = None
223        setbuf.argtypes = [FILE_p, c_char_p]
224
225        if isinstance(obj, FILE_p):
226            return obj
227        else:
228            fd = obj.fileno()
229            fp = fdopen(fd, obj.mode.encode())
230
231            # Make sure the file is opened in unbuffered mode. The test case
232            # "test_zmsg" of the CZMQ Python fails if this mode is not set.
233            setbuf(fp, None)
234
235            return fp
236
237
238# zactor
239zactor_fn = CFUNCTYPE(None, zsock_p, c_void_p)
240zactor_destructor_fn = CFUNCTYPE(None, zactor_p)
241lib.zactor_new.restype = zactor_p
242lib.zactor_new.argtypes = [zactor_fn, c_void_p]
243lib.zactor_destroy.restype = None
244lib.zactor_destroy.argtypes = [POINTER(zactor_p)]
245lib.zactor_send.restype = c_int
246lib.zactor_send.argtypes = [zactor_p, POINTER(zmsg_p)]
247lib.zactor_recv.restype = zmsg_p
248lib.zactor_recv.argtypes = [zactor_p]
249lib.zactor_is.restype = c_bool
250lib.zactor_is.argtypes = [c_void_p]
251lib.zactor_resolve.restype = c_void_p
252lib.zactor_resolve.argtypes = [c_void_p]
253lib.zactor_sock.restype = zsock_p
254lib.zactor_sock.argtypes = [zactor_p]
255lib.zactor_set_destructor.restype = None
256lib.zactor_set_destructor.argtypes = [zactor_p, zactor_destructor_fn]
257lib.zactor_test.restype = None
258lib.zactor_test.argtypes = [c_bool]
259
260class Zactor(object):
261    """
262    provides a simple actor framework
263    """
264
265    allow_destruct = False
266    def __init__(self, *args):
267        """
268        Create a new actor passing arbitrary arguments reference.
269        """
270        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
271            self._as_parameter_ = cast(args[0], zactor_p) # Conversion from raw type to binding
272            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
273        elif len(args) == 2 and type(args[0]) is zactor_p and isinstance(args[1], bool):
274            self._as_parameter_ = args[0] # Conversion from raw type to binding
275            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
276        else:
277            assert(len(args) == 2)
278            self._as_parameter_ = lib.zactor_new(args[0], args[1]) # Creation of new raw type
279            self.allow_destruct = True
280
281    def __del__(self):
282        """
283        Destroy an actor.
284        """
285        if self.allow_destruct:
286            lib.zactor_destroy(byref(self._as_parameter_))
287
288    def __eq__(self, other):
289        if type(other) == type(self):
290            return other.c_address() == self.c_address()
291        elif type(other) == c_void_p:
292            return other.value == self.c_address()
293
294    def c_address(self):
295        """
296        Return the address of the object pointer in c.  Useful for comparison.
297        """
298        return addressof(self._as_parameter_.contents)
299
300    def __bool__(self):
301        "Determine whether the object is valid by converting to boolean" # Python 3
302        return self._as_parameter_.__bool__()
303
304    def __nonzero__(self):
305        "Determine whether the object is valid by converting to boolean" # Python 2
306        return self._as_parameter_.__nonzero__()
307
308    def send(self, msg_p):
309        """
310        Send a zmsg message to the actor, take ownership of the message
311and destroy when it has been sent.
312        """
313        return lib.zactor_send(self._as_parameter_, byref(zmsg_p.from_param(msg_p)))
314
315    def recv(self):
316        """
317        Receive a zmsg message from the actor. Returns NULL if the actor
318was interrupted before the message could be received, or if there
319was a timeout on the actor.
320        """
321        return Zmsg(lib.zactor_recv(self._as_parameter_), True)
322
323    @staticmethod
324    def is_(self):
325        """
326        Probe the supplied object, and report if it looks like a zactor_t.
327        """
328        return lib.zactor_is(self)
329
330    @staticmethod
331    def resolve(self):
332        """
333        Probe the supplied reference. If it looks like a zactor_t instance,
334return the underlying libzmq actor handle; else if it looks like
335a libzmq actor handle, return the supplied value.
336        """
337        return c_void_p(lib.zactor_resolve(self))
338
339    def sock(self):
340        """
341        Return the actor's zsock handle. Use this when you absolutely need
342to work with the zsock instance rather than the actor.
343        """
344        return Zsock(lib.zactor_sock(self._as_parameter_), False)
345
346    def set_destructor(self, destructor):
347        """
348        Change default destructor by custom function. Actor MUST be able to handle new message instead of default $TERM.
349        """
350        return lib.zactor_set_destructor(self._as_parameter_, destructor)
351
352    @staticmethod
353    def test(verbose):
354        """
355        Self test of this class.
356        """
357        return lib.zactor_test(verbose)
358
359
360# zargs
361lib.zargs_new.restype = zargs_p
362lib.zargs_new.argtypes = [c_int, POINTER(c_char_p)]
363lib.zargs_destroy.restype = None
364lib.zargs_destroy.argtypes = [POINTER(zargs_p)]
365lib.zargs_progname.restype = c_char_p
366lib.zargs_progname.argtypes = [zargs_p]
367lib.zargs_arguments.restype = c_size_t
368lib.zargs_arguments.argtypes = [zargs_p]
369lib.zargs_first.restype = c_char_p
370lib.zargs_first.argtypes = [zargs_p]
371lib.zargs_next.restype = c_char_p
372lib.zargs_next.argtypes = [zargs_p]
373lib.zargs_param_first.restype = c_char_p
374lib.zargs_param_first.argtypes = [zargs_p]
375lib.zargs_param_next.restype = c_char_p
376lib.zargs_param_next.argtypes = [zargs_p]
377lib.zargs_param_name.restype = c_char_p
378lib.zargs_param_name.argtypes = [zargs_p]
379lib.zargs_param_lookup.restype = c_char_p
380lib.zargs_param_lookup.argtypes = [zargs_p, c_char_p]
381lib.zargs_param_lookupx.restype = c_char_p
382lib.zargs_param_lookupx.argtypes = [zargs_p, c_char_p]
383lib.zargs_has_help.restype = c_bool
384lib.zargs_has_help.argtypes = [zargs_p]
385lib.zargs_param_empty.restype = c_bool
386lib.zargs_param_empty.argtypes = [c_char_p]
387lib.zargs_print.restype = None
388lib.zargs_print.argtypes = [zargs_p]
389lib.zargs_test.restype = None
390lib.zargs_test.argtypes = [c_bool]
391
392class Zargs(object):
393    """
394    Platform independent command line argument parsing helpers
395
396There are two kind of elements provided by this class
397foo --named-parameter --parameter with_value positional arguments -a gain-parameter
398zargs keeps poision only for arguments, parameters are to be accessed like hash.
399
400It DOES:
401* provide easy to use CLASS compatible API for accessing argv
402* is platform independent
403* provide getopt_long style -- argument, which delimits parameters from arguments
404* makes parameters positon independent
405
406It does NOT
407* change argv
408* provide a "declarative" way to define command line interface
409
410In future it SHALL
411* hide several formats of command line to one (-Idir, --include=dir,
412  --include dir are the same from API pov)
413    """
414
415    allow_destruct = False
416    def __init__(self, *args):
417        """
418        Create a new zargs from command line arguments.
419        """
420        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
421            self._as_parameter_ = cast(args[0], zargs_p) # Conversion from raw type to binding
422            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
423        elif len(args) == 2 and type(args[0]) is zargs_p and isinstance(args[1], bool):
424            self._as_parameter_ = args[0] # Conversion from raw type to binding
425            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
426        else:
427            assert(len(args) == 2)
428            self._as_parameter_ = lib.zargs_new(args[0], byref(c_char_p.from_param(args[1]))) # Creation of new raw type
429            self.allow_destruct = True
430
431    def __del__(self):
432        """
433        Destroy zargs instance.
434        """
435        if self.allow_destruct:
436            lib.zargs_destroy(byref(self._as_parameter_))
437
438    def __eq__(self, other):
439        if type(other) == type(self):
440            return other.c_address() == self.c_address()
441        elif type(other) == c_void_p:
442            return other.value == self.c_address()
443
444    def c_address(self):
445        """
446        Return the address of the object pointer in c.  Useful for comparison.
447        """
448        return addressof(self._as_parameter_.contents)
449
450    def __bool__(self):
451        "Determine whether the object is valid by converting to boolean" # Python 3
452        return self._as_parameter_.__bool__()
453
454    def __nonzero__(self):
455        "Determine whether the object is valid by converting to boolean" # Python 2
456        return self._as_parameter_.__nonzero__()
457
458    def progname(self):
459        """
460        Return program name (argv[0])
461        """
462        return lib.zargs_progname(self._as_parameter_)
463
464    def arguments(self):
465        """
466        Return number of positional arguments
467        """
468        return lib.zargs_arguments(self._as_parameter_)
469
470    def first(self):
471        """
472        Return first positional argument or NULL
473        """
474        return lib.zargs_first(self._as_parameter_)
475
476    def next(self):
477        """
478        Return next positional argument or NULL
479        """
480        return lib.zargs_next(self._as_parameter_)
481
482    def param_first(self):
483        """
484        Return first named parameter value, or NULL if there are no named
485parameters, or value for which zargs_param_empty (arg) returns true.
486        """
487        return lib.zargs_param_first(self._as_parameter_)
488
489    def param_next(self):
490        """
491        Return next named parameter value, or NULL if there are no named
492parameters, or value for which zargs_param_empty (arg) returns true.
493        """
494        return lib.zargs_param_next(self._as_parameter_)
495
496    def param_name(self):
497        """
498        Return current parameter name, or NULL if there are no named
499parameters.
500        """
501        return lib.zargs_param_name(self._as_parameter_)
502
503    def param_lookup(self, keys):
504        """
505        Return value of named parameter, NULL if no given parameter has
506been specified, or special value for wich zargs_param_empty ()
507returns true.
508        """
509        return lib.zargs_param_lookup(self._as_parameter_, keys)
510
511    def param_lookupx(self, keys, *args):
512        """
513        Return value of named parameter(s), NULL if no given parameter has
514been specified, or special value for wich zargs_param_empty ()
515returns true.
516        """
517        return lib.zargs_param_lookupx(self._as_parameter_, keys, *args)
518
519    def has_help(self):
520        """
521        Returns true if there are --help -h arguments
522        """
523        return lib.zargs_has_help(self._as_parameter_)
524
525    @staticmethod
526    def param_empty(arg):
527        """
528        Returns true if parameter did not have a value
529        """
530        return lib.zargs_param_empty(arg)
531
532    def print(self):
533        """
534        Print an instance of zargs.
535        """
536        return lib.zargs_print(self._as_parameter_)
537
538    @staticmethod
539    def test(verbose):
540        """
541        Self test of this class.
542        """
543        return lib.zargs_test(verbose)
544
545
546# zarmour
547lib.zarmour_new.restype = zarmour_p
548lib.zarmour_new.argtypes = []
549lib.zarmour_destroy.restype = None
550lib.zarmour_destroy.argtypes = [POINTER(zarmour_p)]
551lib.zarmour_encode.restype = POINTER(c_char)
552lib.zarmour_encode.argtypes = [zarmour_p, c_void_p, c_size_t]
553lib.zarmour_decode.restype = zchunk_p
554lib.zarmour_decode.argtypes = [zarmour_p, c_char_p]
555lib.zarmour_mode.restype = c_int
556lib.zarmour_mode.argtypes = [zarmour_p]
557lib.zarmour_mode_str.restype = c_char_p
558lib.zarmour_mode_str.argtypes = [zarmour_p]
559lib.zarmour_set_mode.restype = None
560lib.zarmour_set_mode.argtypes = [zarmour_p, c_int]
561lib.zarmour_pad.restype = c_bool
562lib.zarmour_pad.argtypes = [zarmour_p]
563lib.zarmour_set_pad.restype = None
564lib.zarmour_set_pad.argtypes = [zarmour_p, c_bool]
565lib.zarmour_pad_char.restype = char_p
566lib.zarmour_pad_char.argtypes = [zarmour_p]
567lib.zarmour_set_pad_char.restype = None
568lib.zarmour_set_pad_char.argtypes = [zarmour_p, char_p]
569lib.zarmour_line_breaks.restype = c_bool
570lib.zarmour_line_breaks.argtypes = [zarmour_p]
571lib.zarmour_set_line_breaks.restype = None
572lib.zarmour_set_line_breaks.argtypes = [zarmour_p, c_bool]
573lib.zarmour_line_length.restype = c_size_t
574lib.zarmour_line_length.argtypes = [zarmour_p]
575lib.zarmour_set_line_length.restype = None
576lib.zarmour_set_line_length.argtypes = [zarmour_p, c_size_t]
577lib.zarmour_print.restype = None
578lib.zarmour_print.argtypes = [zarmour_p]
579lib.zarmour_test.restype = None
580lib.zarmour_test.argtypes = [c_bool]
581
582class Zarmour(object):
583    """
584    armoured text encoding and decoding
585    """
586
587    MODE_BASE64_STD = 0 # Standard base 64
588    MODE_BASE64_URL = 1 # URL and filename friendly base 64
589    MODE_BASE32_STD = 2 # Standard base 32
590    MODE_BASE32_HEX = 3 # Extended hex base 32
591    MODE_BASE16 = 4 # Standard base 16
592    MODE_Z85 = 5 # Z85 from ZeroMQ RFC 32
593    allow_destruct = False
594    def __init__(self, *args):
595        """
596        Create a new zarmour
597        """
598        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
599            self._as_parameter_ = cast(args[0], zarmour_p) # Conversion from raw type to binding
600            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
601        elif len(args) == 2 and type(args[0]) is zarmour_p and isinstance(args[1], bool):
602            self._as_parameter_ = args[0] # Conversion from raw type to binding
603            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
604        else:
605            assert(len(args) == 0)
606            self._as_parameter_ = lib.zarmour_new() # Creation of new raw type
607            self.allow_destruct = True
608
609    def __del__(self):
610        """
611        Destroy the zarmour
612        """
613        if self.allow_destruct:
614            lib.zarmour_destroy(byref(self._as_parameter_))
615
616    def __eq__(self, other):
617        if type(other) == type(self):
618            return other.c_address() == self.c_address()
619        elif type(other) == c_void_p:
620            return other.value == self.c_address()
621
622    def c_address(self):
623        """
624        Return the address of the object pointer in c.  Useful for comparison.
625        """
626        return addressof(self._as_parameter_.contents)
627
628    def __bool__(self):
629        "Determine whether the object is valid by converting to boolean" # Python 3
630        return self._as_parameter_.__bool__()
631
632    def __nonzero__(self):
633        "Determine whether the object is valid by converting to boolean" # Python 2
634        return self._as_parameter_.__nonzero__()
635
636    def encode(self, data, size):
637        """
638        Encode a stream of bytes into an armoured string. Returns the armoured
639string, or NULL if there was insufficient memory available to allocate
640a new string.
641        """
642        return return_fresh_string(lib.zarmour_encode(self._as_parameter_, data, size))
643
644    def decode(self, data):
645        """
646        Decode an armoured string into a chunk. The decoded output is
647null-terminated, so it may be treated as a string, if that's what
648it was prior to encoding.
649        """
650        return Zchunk(lib.zarmour_decode(self._as_parameter_, data), True)
651
652    def mode(self):
653        """
654        Get the mode property.
655        """
656        return lib.zarmour_mode(self._as_parameter_)
657
658    def mode_str(self):
659        """
660        Get printable string for mode.
661        """
662        return lib.zarmour_mode_str(self._as_parameter_)
663
664    def set_mode(self, mode):
665        """
666        Set the mode property.
667        """
668        return lib.zarmour_set_mode(self._as_parameter_, mode)
669
670    def pad(self):
671        """
672        Return true if padding is turned on.
673        """
674        return lib.zarmour_pad(self._as_parameter_)
675
676    def set_pad(self, pad):
677        """
678        Turn padding on or off. Default is on.
679        """
680        return lib.zarmour_set_pad(self._as_parameter_, pad)
681
682    def pad_char(self):
683        """
684        Get the padding character.
685        """
686        return lib.zarmour_pad_char(self._as_parameter_)
687
688    def set_pad_char(self, pad_char):
689        """
690        Set the padding character.
691        """
692        return lib.zarmour_set_pad_char(self._as_parameter_, pad_char)
693
694    def line_breaks(self):
695        """
696        Return if splitting output into lines is turned on. Default is off.
697        """
698        return lib.zarmour_line_breaks(self._as_parameter_)
699
700    def set_line_breaks(self, line_breaks):
701        """
702        Turn splitting output into lines on or off.
703        """
704        return lib.zarmour_set_line_breaks(self._as_parameter_, line_breaks)
705
706    def line_length(self):
707        """
708        Get the line length used for splitting lines.
709        """
710        return lib.zarmour_line_length(self._as_parameter_)
711
712    def set_line_length(self, line_length):
713        """
714        Set the line length used for splitting lines.
715        """
716        return lib.zarmour_set_line_length(self._as_parameter_, line_length)
717
718    def print(self):
719        """
720        Print properties of object
721        """
722        return lib.zarmour_print(self._as_parameter_)
723
724    @staticmethod
725    def test(verbose):
726        """
727        Self test of this class.
728        """
729        return lib.zarmour_test(verbose)
730
731
732# zcert
733lib.zcert_new.restype = zcert_p
734lib.zcert_new.argtypes = []
735lib.zcert_destroy.restype = None
736lib.zcert_destroy.argtypes = [POINTER(zcert_p)]
737lib.zcert_new_from.restype = zcert_p
738lib.zcert_new_from.argtypes = [c_void_p, c_void_p]
739lib.zcert_new_from_txt.restype = zcert_p
740lib.zcert_new_from_txt.argtypes = [c_char_p, c_char_p]
741lib.zcert_load.restype = zcert_p
742lib.zcert_load.argtypes = [c_char_p]
743lib.zcert_public_key.restype = c_void_p
744lib.zcert_public_key.argtypes = [zcert_p]
745lib.zcert_secret_key.restype = c_void_p
746lib.zcert_secret_key.argtypes = [zcert_p]
747lib.zcert_public_txt.restype = c_char_p
748lib.zcert_public_txt.argtypes = [zcert_p]
749lib.zcert_secret_txt.restype = c_char_p
750lib.zcert_secret_txt.argtypes = [zcert_p]
751lib.zcert_set_meta.restype = None
752lib.zcert_set_meta.argtypes = [zcert_p, c_char_p, c_char_p]
753lib.zcert_unset_meta.restype = None
754lib.zcert_unset_meta.argtypes = [zcert_p, c_char_p]
755lib.zcert_meta.restype = c_char_p
756lib.zcert_meta.argtypes = [zcert_p, c_char_p]
757lib.zcert_meta_keys.restype = zlist_p
758lib.zcert_meta_keys.argtypes = [zcert_p]
759lib.zcert_save.restype = c_int
760lib.zcert_save.argtypes = [zcert_p, c_char_p]
761lib.zcert_save_public.restype = c_int
762lib.zcert_save_public.argtypes = [zcert_p, c_char_p]
763lib.zcert_save_secret.restype = c_int
764lib.zcert_save_secret.argtypes = [zcert_p, c_char_p]
765lib.zcert_apply.restype = None
766lib.zcert_apply.argtypes = [zcert_p, c_void_p]
767lib.zcert_dup.restype = zcert_p
768lib.zcert_dup.argtypes = [zcert_p]
769lib.zcert_eq.restype = c_bool
770lib.zcert_eq.argtypes = [zcert_p, zcert_p]
771lib.zcert_print.restype = None
772lib.zcert_print.argtypes = [zcert_p]
773lib.zcert_test.restype = None
774lib.zcert_test.argtypes = [c_bool]
775
776class Zcert(object):
777    """
778    work with CURVE security certificates
779    """
780
781    allow_destruct = False
782    def __init__(self, *args):
783        """
784        Create and initialize a new certificate in memory
785        """
786        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
787            self._as_parameter_ = cast(args[0], zcert_p) # Conversion from raw type to binding
788            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
789        elif len(args) == 2 and type(args[0]) is zcert_p and isinstance(args[1], bool):
790            self._as_parameter_ = args[0] # Conversion from raw type to binding
791            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
792        else:
793            assert(len(args) == 0)
794            self._as_parameter_ = lib.zcert_new() # Creation of new raw type
795            self.allow_destruct = True
796
797    def __del__(self):
798        """
799        Destroy a certificate in memory
800        """
801        if self.allow_destruct:
802            lib.zcert_destroy(byref(self._as_parameter_))
803
804    def __eq__(self, other):
805        if type(other) == type(self):
806            return other.c_address() == self.c_address()
807        elif type(other) == c_void_p:
808            return other.value == self.c_address()
809
810    def c_address(self):
811        """
812        Return the address of the object pointer in c.  Useful for comparison.
813        """
814        return addressof(self._as_parameter_.contents)
815
816    def __bool__(self):
817        "Determine whether the object is valid by converting to boolean" # Python 3
818        return self._as_parameter_.__bool__()
819
820    def __nonzero__(self):
821        "Determine whether the object is valid by converting to boolean" # Python 2
822        return self._as_parameter_.__nonzero__()
823
824    @staticmethod
825    def new_from(public_key, secret_key):
826        """
827        Accepts public/secret key pair from caller
828        """
829        return Zcert(lib.zcert_new_from(public_key, secret_key), True)
830
831    @staticmethod
832    def new_from_txt(public_txt, secret_txt):
833        """
834        Accepts public/secret key text pair from caller
835        """
836        return Zcert(lib.zcert_new_from_txt(public_txt, secret_txt), True)
837
838    @staticmethod
839    def load(filename):
840        """
841        Load certificate from file
842        """
843        return Zcert(lib.zcert_load(filename), True)
844
845    def public_key(self):
846        """
847        Return public part of key pair as 32-byte binary string
848        """
849        return lib.zcert_public_key(self._as_parameter_)
850
851    def secret_key(self):
852        """
853        Return secret part of key pair as 32-byte binary string
854        """
855        return lib.zcert_secret_key(self._as_parameter_)
856
857    def public_txt(self):
858        """
859        Return public part of key pair as Z85 armored string
860        """
861        return lib.zcert_public_txt(self._as_parameter_)
862
863    def secret_txt(self):
864        """
865        Return secret part of key pair as Z85 armored string
866        """
867        return lib.zcert_secret_txt(self._as_parameter_)
868
869    def set_meta(self, name, format, *args):
870        """
871        Set certificate metadata from formatted string.
872        """
873        return lib.zcert_set_meta(self._as_parameter_, name, format, *args)
874
875    def unset_meta(self, name):
876        """
877        Unset certificate metadata.
878        """
879        return lib.zcert_unset_meta(self._as_parameter_, name)
880
881    def meta(self, name):
882        """
883        Get metadata value from certificate; if the metadata value doesn't
884exist, returns NULL.
885        """
886        return lib.zcert_meta(self._as_parameter_, name)
887
888    def meta_keys(self):
889        """
890        Get list of metadata fields from certificate. Caller is responsible for
891destroying list. Caller should not modify the values of list items.
892        """
893        return Zlist(lib.zcert_meta_keys(self._as_parameter_), False)
894
895    def save(self, filename):
896        """
897        Save full certificate (public + secret) to file for persistent storage
898This creates one public file and one secret file (filename + "_secret").
899        """
900        return lib.zcert_save(self._as_parameter_, filename)
901
902    def save_public(self, filename):
903        """
904        Save public certificate only to file for persistent storage
905        """
906        return lib.zcert_save_public(self._as_parameter_, filename)
907
908    def save_secret(self, filename):
909        """
910        Save secret certificate only to file for persistent storage
911        """
912        return lib.zcert_save_secret(self._as_parameter_, filename)
913
914    def apply(self, socket):
915        """
916        Apply certificate to socket, i.e. use for CURVE security on socket.
917If certificate was loaded from public file, the secret key will be
918undefined, and this certificate will not work successfully.
919        """
920        return lib.zcert_apply(self._as_parameter_, socket)
921
922    def dup(self):
923        """
924        Return copy of certificate; if certificate is NULL or we exhausted
925heap memory, returns NULL.
926        """
927        return Zcert(lib.zcert_dup(self._as_parameter_), True)
928
929    def eq(self, compare):
930        """
931        Return true if two certificates have the same keys
932        """
933        return lib.zcert_eq(self._as_parameter_, compare)
934
935    def print(self):
936        """
937        Print certificate contents to stdout
938        """
939        return lib.zcert_print(self._as_parameter_)
940
941    @staticmethod
942    def test(verbose):
943        """
944        Self test of this class
945        """
946        return lib.zcert_test(verbose)
947
948
949# zcertstore
950zcertstore_loader = CFUNCTYPE(None, zcertstore_p)
951zcertstore_destructor = CFUNCTYPE(None, c_void_p)
952lib.zcertstore_new.restype = zcertstore_p
953lib.zcertstore_new.argtypes = [c_char_p]
954lib.zcertstore_destroy.restype = None
955lib.zcertstore_destroy.argtypes = [POINTER(zcertstore_p)]
956lib.zcertstore_set_loader.restype = None
957lib.zcertstore_set_loader.argtypes = [zcertstore_p, zcertstore_loader, zcertstore_destructor, c_void_p]
958lib.zcertstore_lookup.restype = zcert_p
959lib.zcertstore_lookup.argtypes = [zcertstore_p, c_char_p]
960lib.zcertstore_insert.restype = None
961lib.zcertstore_insert.argtypes = [zcertstore_p, POINTER(zcert_p)]
962lib.zcertstore_empty.restype = None
963lib.zcertstore_empty.argtypes = [zcertstore_p]
964lib.zcertstore_print.restype = None
965lib.zcertstore_print.argtypes = [zcertstore_p]
966lib.zcertstore_certs.restype = zlistx_p
967lib.zcertstore_certs.argtypes = [zcertstore_p]
968lib.zcertstore_test.restype = None
969lib.zcertstore_test.argtypes = [c_bool]
970
971class Zcertstore(object):
972    """
973    work with CURVE security certificate stores
974    """
975
976    allow_destruct = False
977    def __init__(self, *args):
978        """
979        Create a new certificate store from a disk directory, loading and
980indexing all certificates in that location. The directory itself may be
981absent, and created later, or modified at any time. The certificate store
982is automatically refreshed on any zcertstore_lookup() call. If the
983location is specified as NULL, creates a pure-memory store, which you
984can work with by inserting certificates at runtime.
985        """
986        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
987            self._as_parameter_ = cast(args[0], zcertstore_p) # Conversion from raw type to binding
988            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
989        elif len(args) == 2 and type(args[0]) is zcertstore_p and isinstance(args[1], bool):
990            self._as_parameter_ = args[0] # Conversion from raw type to binding
991            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
992        else:
993            assert(len(args) == 1)
994            self._as_parameter_ = lib.zcertstore_new(args[0]) # Creation of new raw type
995            self.allow_destruct = True
996
997    def __del__(self):
998        """
999        Destroy a certificate store object in memory. Does not affect anything
1000stored on disk.
1001        """
1002        if self.allow_destruct:
1003            lib.zcertstore_destroy(byref(self._as_parameter_))
1004
1005    def __eq__(self, other):
1006        if type(other) == type(self):
1007            return other.c_address() == self.c_address()
1008        elif type(other) == c_void_p:
1009            return other.value == self.c_address()
1010
1011    def c_address(self):
1012        """
1013        Return the address of the object pointer in c.  Useful for comparison.
1014        """
1015        return addressof(self._as_parameter_.contents)
1016
1017    def __bool__(self):
1018        "Determine whether the object is valid by converting to boolean" # Python 3
1019        return self._as_parameter_.__bool__()
1020
1021    def __nonzero__(self):
1022        "Determine whether the object is valid by converting to boolean" # Python 2
1023        return self._as_parameter_.__nonzero__()
1024
1025    def set_loader(self, loader, destructor, state):
1026        """
1027        Override the default disk loader with a custom loader fn.
1028        """
1029        return lib.zcertstore_set_loader(self._as_parameter_, loader, destructor, state)
1030
1031    def lookup(self, public_key):
1032        """
1033        Look up certificate by public key, returns zcert_t object if found,
1034else returns NULL. The public key is provided in Z85 text format.
1035        """
1036        return Zcert(lib.zcertstore_lookup(self._as_parameter_, public_key), False)
1037
1038    def insert(self, cert_p):
1039        """
1040        Insert certificate into certificate store in memory. Note that this
1041does not save the certificate to disk. To do that, use zcert_save()
1042directly on the certificate. Takes ownership of zcert_t object.
1043        """
1044        return lib.zcertstore_insert(self._as_parameter_, byref(zcert_p.from_param(cert_p)))
1045
1046    def empty(self):
1047        """
1048        Empty certificate hashtable. This wrapper exists to be friendly to bindings,
1049which don't usually have access to struct internals.
1050        """
1051        return lib.zcertstore_empty(self._as_parameter_)
1052
1053    def print(self):
1054        """
1055        Print list of certificates in store to logging facility
1056        """
1057        return lib.zcertstore_print(self._as_parameter_)
1058
1059    def certs(self):
1060        """
1061        Return a list of all the certificates in the store.
1062The caller takes ownership of the zlistx_t object and is responsible
1063for destroying it.  The caller does not take ownership of the zcert_t
1064objects.
1065        """
1066        return Zlistx(lib.zcertstore_certs(self._as_parameter_), True)
1067
1068    @staticmethod
1069    def test(verbose):
1070        """
1071        Self test of this class
1072        """
1073        return lib.zcertstore_test(verbose)
1074
1075
1076# zchunk
1077lib.zchunk_new.restype = zchunk_p
1078lib.zchunk_new.argtypes = [c_void_p, c_size_t]
1079lib.zchunk_destroy.restype = None
1080lib.zchunk_destroy.argtypes = [POINTER(zchunk_p)]
1081lib.zchunk_resize.restype = None
1082lib.zchunk_resize.argtypes = [zchunk_p, c_size_t]
1083lib.zchunk_size.restype = c_size_t
1084lib.zchunk_size.argtypes = [zchunk_p]
1085lib.zchunk_max_size.restype = c_size_t
1086lib.zchunk_max_size.argtypes = [zchunk_p]
1087lib.zchunk_data.restype = c_void_p
1088lib.zchunk_data.argtypes = [zchunk_p]
1089lib.zchunk_set.restype = c_size_t
1090lib.zchunk_set.argtypes = [zchunk_p, c_void_p, c_size_t]
1091lib.zchunk_fill.restype = c_size_t
1092lib.zchunk_fill.argtypes = [zchunk_p, c_ubyte, c_size_t]
1093lib.zchunk_append.restype = c_size_t
1094lib.zchunk_append.argtypes = [zchunk_p, c_void_p, c_size_t]
1095lib.zchunk_extend.restype = c_size_t
1096lib.zchunk_extend.argtypes = [zchunk_p, c_void_p, c_size_t]
1097lib.zchunk_consume.restype = c_size_t
1098lib.zchunk_consume.argtypes = [zchunk_p, zchunk_p]
1099lib.zchunk_exhausted.restype = c_bool
1100lib.zchunk_exhausted.argtypes = [zchunk_p]
1101lib.zchunk_read.restype = zchunk_p
1102lib.zchunk_read.argtypes = [FILE_p, c_size_t]
1103lib.zchunk_write.restype = c_int
1104lib.zchunk_write.argtypes = [zchunk_p, FILE_p]
1105lib.zchunk_slurp.restype = zchunk_p
1106lib.zchunk_slurp.argtypes = [c_char_p, c_size_t]
1107lib.zchunk_dup.restype = zchunk_p
1108lib.zchunk_dup.argtypes = [zchunk_p]
1109lib.zchunk_strhex.restype = POINTER(c_char)
1110lib.zchunk_strhex.argtypes = [zchunk_p]
1111lib.zchunk_strdup.restype = POINTER(c_char)
1112lib.zchunk_strdup.argtypes = [zchunk_p]
1113lib.zchunk_streq.restype = c_bool
1114lib.zchunk_streq.argtypes = [zchunk_p, c_char_p]
1115lib.zchunk_pack.restype = zframe_p
1116lib.zchunk_pack.argtypes = [zchunk_p]
1117lib.zchunk_unpack.restype = zchunk_p
1118lib.zchunk_unpack.argtypes = [zframe_p]
1119lib.zchunk_digest.restype = c_char_p
1120lib.zchunk_digest.argtypes = [zchunk_p]
1121lib.zchunk_fprint.restype = None
1122lib.zchunk_fprint.argtypes = [zchunk_p, FILE_p]
1123lib.zchunk_print.restype = None
1124lib.zchunk_print.argtypes = [zchunk_p]
1125lib.zchunk_is.restype = c_bool
1126lib.zchunk_is.argtypes = [c_void_p]
1127lib.zchunk_test.restype = None
1128lib.zchunk_test.argtypes = [c_bool]
1129
1130class Zchunk(object):
1131    """
1132    work with memory chunks
1133    """
1134
1135    allow_destruct = False
1136    def __init__(self, *args):
1137        """
1138        Create a new chunk of the specified size. If you specify the data, it
1139is copied into the chunk. If you do not specify the data, the chunk is
1140allocated and left empty, and you can then add data using zchunk_append.
1141        """
1142        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
1143            self._as_parameter_ = cast(args[0], zchunk_p) # Conversion from raw type to binding
1144            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1145        elif len(args) == 2 and type(args[0]) is zchunk_p and isinstance(args[1], bool):
1146            self._as_parameter_ = args[0] # Conversion from raw type to binding
1147            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1148        else:
1149            assert(len(args) == 2)
1150            self._as_parameter_ = lib.zchunk_new(args[0], args[1]) # Creation of new raw type
1151            self.allow_destruct = True
1152
1153    def __del__(self):
1154        """
1155        Destroy a chunk
1156        """
1157        if self.allow_destruct:
1158            lib.zchunk_destroy(byref(self._as_parameter_))
1159
1160    def __eq__(self, other):
1161        if type(other) == type(self):
1162            return other.c_address() == self.c_address()
1163        elif type(other) == c_void_p:
1164            return other.value == self.c_address()
1165
1166    def c_address(self):
1167        """
1168        Return the address of the object pointer in c.  Useful for comparison.
1169        """
1170        return addressof(self._as_parameter_.contents)
1171
1172    def __bool__(self):
1173        "Determine whether the object is valid by converting to boolean" # Python 3
1174        return self._as_parameter_.__bool__()
1175
1176    def __nonzero__(self):
1177        "Determine whether the object is valid by converting to boolean" # Python 2
1178        return self._as_parameter_.__nonzero__()
1179
1180    def resize(self, size):
1181        """
1182        Resizes chunk max_size as requested; chunk_cur size is set to zero
1183        """
1184        return lib.zchunk_resize(self._as_parameter_, size)
1185
1186    def size(self):
1187        """
1188        Return chunk cur size
1189        """
1190        return lib.zchunk_size(self._as_parameter_)
1191
1192    def max_size(self):
1193        """
1194        Return chunk max size
1195        """
1196        return lib.zchunk_max_size(self._as_parameter_)
1197
1198    def data(self):
1199        """
1200        Return chunk data
1201        """
1202        return lib.zchunk_data(self._as_parameter_)
1203
1204    def set(self, data, size):
1205        """
1206        Set chunk data from user-supplied data; truncate if too large. Data may
1207be null. Returns actual size of chunk
1208        """
1209        return lib.zchunk_set(self._as_parameter_, data, size)
1210
1211    def fill(self, filler, size):
1212        """
1213        Fill chunk data from user-supplied octet
1214        """
1215        return lib.zchunk_fill(self._as_parameter_, filler, size)
1216
1217    def append(self, data, size):
1218        """
1219        Append user-supplied data to chunk, return resulting chunk size. If the
1220data would exceeded the available space, it is truncated. If you want to
1221grow the chunk to accommodate new data, use the zchunk_extend method.
1222        """
1223        return lib.zchunk_append(self._as_parameter_, data, size)
1224
1225    def extend(self, data, size):
1226        """
1227        Append user-supplied data to chunk, return resulting chunk size. If the
1228data would exceeded the available space, the chunk grows in size.
1229        """
1230        return lib.zchunk_extend(self._as_parameter_, data, size)
1231
1232    def consume(self, source):
1233        """
1234        Copy as much data from 'source' into the chunk as possible; returns the
1235new size of chunk. If all data from 'source' is used, returns exhausted
1236on the source chunk. Source can be consumed as many times as needed until
1237it is exhausted. If source was already exhausted, does not change chunk.
1238        """
1239        return lib.zchunk_consume(self._as_parameter_, source)
1240
1241    def exhausted(self):
1242        """
1243        Returns true if the chunk was exhausted by consume methods, or if the
1244chunk has a size of zero.
1245        """
1246        return lib.zchunk_exhausted(self._as_parameter_)
1247
1248    @staticmethod
1249    def read(handle, bytes):
1250        """
1251        Read chunk from an open file descriptor
1252        """
1253        return Zchunk(lib.zchunk_read(coerce_py_file(handle), bytes), True)
1254
1255    def write(self, handle):
1256        """
1257        Write chunk to an open file descriptor
1258        """
1259        return lib.zchunk_write(self._as_parameter_, coerce_py_file(handle))
1260
1261    @staticmethod
1262    def slurp(filename, maxsize):
1263        """
1264        Try to slurp an entire file into a chunk. Will read up to maxsize of
1265the file. If maxsize is 0, will attempt to read the entire file and
1266fail with an assertion if that cannot fit into memory. Returns a new
1267chunk containing the file data, or NULL if the file could not be read.
1268        """
1269        return Zchunk(lib.zchunk_slurp(filename, maxsize), True)
1270
1271    def dup(self):
1272        """
1273        Create copy of chunk, as new chunk object. Returns a fresh zchunk_t
1274object, or null if there was not enough heap memory. If chunk is null,
1275returns null.
1276        """
1277        return Zchunk(lib.zchunk_dup(self._as_parameter_), True)
1278
1279    def strhex(self):
1280        """
1281        Return chunk data encoded as printable hex string. Caller must free
1282string when finished with it.
1283        """
1284        return return_fresh_string(lib.zchunk_strhex(self._as_parameter_))
1285
1286    def strdup(self):
1287        """
1288        Return chunk data copied into freshly allocated string
1289Caller must free string when finished with it.
1290        """
1291        return return_fresh_string(lib.zchunk_strdup(self._as_parameter_))
1292
1293    def streq(self, string):
1294        """
1295        Return TRUE if chunk body is equal to string, excluding terminator
1296        """
1297        return lib.zchunk_streq(self._as_parameter_, string)
1298
1299    def pack(self):
1300        """
1301        Transform zchunk into a zframe that can be sent in a message.
1302        """
1303        return Zframe(lib.zchunk_pack(self._as_parameter_), True)
1304
1305    @staticmethod
1306    def unpack(frame):
1307        """
1308        Transform a zframe into a zchunk.
1309        """
1310        return Zchunk(lib.zchunk_unpack(frame), True)
1311
1312    def digest(self):
1313        """
1314        Calculate SHA1 digest for chunk, using zdigest class.
1315        """
1316        return lib.zchunk_digest(self._as_parameter_)
1317
1318    def fprint(self, file):
1319        """
1320        Dump chunk to FILE stream, for debugging and tracing.
1321        """
1322        return lib.zchunk_fprint(self._as_parameter_, coerce_py_file(file))
1323
1324    def print(self):
1325        """
1326        Dump message to stderr, for debugging and tracing.
1327See zchunk_fprint for details
1328        """
1329        return lib.zchunk_print(self._as_parameter_)
1330
1331    @staticmethod
1332    def is_(self):
1333        """
1334        Probe the supplied object, and report if it looks like a zchunk_t.
1335        """
1336        return lib.zchunk_is(self)
1337
1338    @staticmethod
1339    def test(verbose):
1340        """
1341        Self test of this class.
1342        """
1343        return lib.zchunk_test(verbose)
1344
1345
1346# zclock
1347lib.zclock_sleep.restype = None
1348lib.zclock_sleep.argtypes = [c_int]
1349lib.zclock_time.restype = msecs_p
1350lib.zclock_time.argtypes = []
1351lib.zclock_mono.restype = msecs_p
1352lib.zclock_mono.argtypes = []
1353lib.zclock_usecs.restype = msecs_p
1354lib.zclock_usecs.argtypes = []
1355lib.zclock_timestr.restype = POINTER(c_char)
1356lib.zclock_timestr.argtypes = []
1357lib.zclock_test.restype = None
1358lib.zclock_test.argtypes = [c_bool]
1359
1360class Zclock(object):
1361    """
1362    millisecond clocks and delays
1363    """
1364
1365    allow_destruct = False
1366    def __eq__(self, other):
1367        if type(other) == type(self):
1368            return other.c_address() == self.c_address()
1369        elif type(other) == c_void_p:
1370            return other.value == self.c_address()
1371
1372    def c_address(self):
1373        """
1374        Return the address of the object pointer in c.  Useful for comparison.
1375        """
1376        return addressof(self._as_parameter_.contents)
1377
1378    def __bool__(self):
1379        "Determine whether the object is valid by converting to boolean" # Python 3
1380        return self._as_parameter_.__bool__()
1381
1382    def __nonzero__(self):
1383        "Determine whether the object is valid by converting to boolean" # Python 2
1384        return self._as_parameter_.__nonzero__()
1385
1386    @staticmethod
1387    def sleep(msecs):
1388        """
1389        Sleep for a number of milliseconds
1390        """
1391        return lib.zclock_sleep(msecs)
1392
1393    @staticmethod
1394    def time():
1395        """
1396        Return current system clock as milliseconds. Note that this clock can
1397jump backwards (if the system clock is changed) so is unsafe to use for
1398timers and time offsets. Use zclock_mono for that instead.
1399        """
1400        return lib.zclock_time()
1401
1402    @staticmethod
1403    def mono():
1404        """
1405        Return current monotonic clock in milliseconds. Use this when you compute
1406time offsets. The monotonic clock is not affected by system changes and
1407so will never be reset backwards, unlike a system clock.
1408        """
1409        return lib.zclock_mono()
1410
1411    @staticmethod
1412    def usecs():
1413        """
1414        Return current monotonic clock in microseconds. Use this when you compute
1415time offsets. The monotonic clock is not affected by system changes and
1416so will never be reset backwards, unlike a system clock.
1417        """
1418        return lib.zclock_usecs()
1419
1420    @staticmethod
1421    def timestr():
1422        """
1423        Return formatted date/time as fresh string. Free using zstr_free().
1424        """
1425        return return_fresh_string(lib.zclock_timestr())
1426
1427    @staticmethod
1428    def test(verbose):
1429        """
1430        Self test of this class.
1431        """
1432        return lib.zclock_test(verbose)
1433
1434
1435# zconfig
1436zconfig_fct = CFUNCTYPE(c_int, zconfig_p, c_void_p, c_int)
1437lib.zconfig_new.restype = zconfig_p
1438lib.zconfig_new.argtypes = [c_char_p, zconfig_p]
1439lib.zconfig_destroy.restype = None
1440lib.zconfig_destroy.argtypes = [POINTER(zconfig_p)]
1441lib.zconfig_load.restype = zconfig_p
1442lib.zconfig_load.argtypes = [c_char_p]
1443lib.zconfig_loadf.restype = zconfig_p
1444lib.zconfig_loadf.argtypes = [c_char_p]
1445lib.zconfig_name.restype = c_char_p
1446lib.zconfig_name.argtypes = [zconfig_p]
1447lib.zconfig_value.restype = c_char_p
1448lib.zconfig_value.argtypes = [zconfig_p]
1449lib.zconfig_put.restype = None
1450lib.zconfig_put.argtypes = [zconfig_p, c_char_p, c_char_p]
1451lib.zconfig_putf.restype = None
1452lib.zconfig_putf.argtypes = [zconfig_p, c_char_p, c_char_p]
1453lib.zconfig_get.restype = c_char_p
1454lib.zconfig_get.argtypes = [zconfig_p, c_char_p, c_char_p]
1455lib.zconfig_set_name.restype = None
1456lib.zconfig_set_name.argtypes = [zconfig_p, c_char_p]
1457lib.zconfig_set_value.restype = None
1458lib.zconfig_set_value.argtypes = [zconfig_p, c_char_p]
1459lib.zconfig_child.restype = zconfig_p
1460lib.zconfig_child.argtypes = [zconfig_p]
1461lib.zconfig_next.restype = zconfig_p
1462lib.zconfig_next.argtypes = [zconfig_p]
1463lib.zconfig_locate.restype = zconfig_p
1464lib.zconfig_locate.argtypes = [zconfig_p, c_char_p]
1465lib.zconfig_at_depth.restype = zconfig_p
1466lib.zconfig_at_depth.argtypes = [zconfig_p, c_int]
1467lib.zconfig_execute.restype = c_int
1468lib.zconfig_execute.argtypes = [zconfig_p, zconfig_fct, c_void_p]
1469lib.zconfig_set_comment.restype = None
1470lib.zconfig_set_comment.argtypes = [zconfig_p, c_char_p]
1471lib.zconfig_comments.restype = zlist_p
1472lib.zconfig_comments.argtypes = [zconfig_p]
1473lib.zconfig_save.restype = c_int
1474lib.zconfig_save.argtypes = [zconfig_p, c_char_p]
1475lib.zconfig_savef.restype = c_int
1476lib.zconfig_savef.argtypes = [zconfig_p, c_char_p]
1477lib.zconfig_filename.restype = c_char_p
1478lib.zconfig_filename.argtypes = [zconfig_p]
1479lib.zconfig_reload.restype = c_int
1480lib.zconfig_reload.argtypes = [POINTER(zconfig_p)]
1481lib.zconfig_chunk_load.restype = zconfig_p
1482lib.zconfig_chunk_load.argtypes = [zchunk_p]
1483lib.zconfig_chunk_save.restype = zchunk_p
1484lib.zconfig_chunk_save.argtypes = [zconfig_p]
1485lib.zconfig_str_load.restype = zconfig_p
1486lib.zconfig_str_load.argtypes = [c_char_p]
1487lib.zconfig_str_save.restype = POINTER(c_char)
1488lib.zconfig_str_save.argtypes = [zconfig_p]
1489lib.zconfig_has_changed.restype = c_bool
1490lib.zconfig_has_changed.argtypes = [zconfig_p]
1491lib.zconfig_remove_subtree.restype = None
1492lib.zconfig_remove_subtree.argtypes = [zconfig_p]
1493lib.zconfig_remove.restype = None
1494lib.zconfig_remove.argtypes = [POINTER(zconfig_p)]
1495lib.zconfig_fprint.restype = None
1496lib.zconfig_fprint.argtypes = [zconfig_p, FILE_p]
1497lib.zconfig_print.restype = None
1498lib.zconfig_print.argtypes = [zconfig_p]
1499lib.zconfig_test.restype = None
1500lib.zconfig_test.argtypes = [c_bool]
1501
1502class Zconfig(object):
1503    """
1504    work with config files written in rfc.zeromq.org/spec:4/ZPL.
1505    """
1506
1507    allow_destruct = False
1508    def __init__(self, *args):
1509        """
1510        Create new config item
1511        """
1512        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
1513            self._as_parameter_ = cast(args[0], zconfig_p) # Conversion from raw type to binding
1514            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1515        elif len(args) == 2 and type(args[0]) is zconfig_p and isinstance(args[1], bool):
1516            self._as_parameter_ = args[0] # Conversion from raw type to binding
1517            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1518        else:
1519            assert(len(args) == 2)
1520            self._as_parameter_ = lib.zconfig_new(args[0], args[1]) # Creation of new raw type
1521            self.allow_destruct = True
1522
1523    def __del__(self):
1524        """
1525        Destroy a config item and all its children
1526        """
1527        if self.allow_destruct:
1528            lib.zconfig_destroy(byref(self._as_parameter_))
1529
1530    def __eq__(self, other):
1531        if type(other) == type(self):
1532            return other.c_address() == self.c_address()
1533        elif type(other) == c_void_p:
1534            return other.value == self.c_address()
1535
1536    def c_address(self):
1537        """
1538        Return the address of the object pointer in c.  Useful for comparison.
1539        """
1540        return addressof(self._as_parameter_.contents)
1541
1542    def __bool__(self):
1543        "Determine whether the object is valid by converting to boolean" # Python 3
1544        return self._as_parameter_.__bool__()
1545
1546    def __nonzero__(self):
1547        "Determine whether the object is valid by converting to boolean" # Python 2
1548        return self._as_parameter_.__nonzero__()
1549
1550    @staticmethod
1551    def load(filename):
1552        """
1553        Load a config tree from a specified ZPL text file; returns a zconfig_t
1554reference for the root, if the file exists and is readable. Returns NULL
1555if the file does not exist.
1556        """
1557        return Zconfig(lib.zconfig_load(filename), True)
1558
1559    @staticmethod
1560    def loadf(format, *args):
1561        """
1562        Equivalent to zconfig_load, taking a format string instead of a fixed
1563filename.
1564        """
1565        return Zconfig(lib.zconfig_loadf(format, *args), True)
1566
1567    def name(self):
1568        """
1569        Return name of config item
1570        """
1571        return lib.zconfig_name(self._as_parameter_)
1572
1573    def value(self):
1574        """
1575        Return value of config item
1576        """
1577        return lib.zconfig_value(self._as_parameter_)
1578
1579    def put(self, path, value):
1580        """
1581        Insert or update configuration key with value
1582        """
1583        return lib.zconfig_put(self._as_parameter_, path, value)
1584
1585    def putf(self, path, format, *args):
1586        """
1587        Equivalent to zconfig_put, accepting a format specifier and variable
1588argument list, instead of a single string value.
1589        """
1590        return lib.zconfig_putf(self._as_parameter_, path, format, *args)
1591
1592    def get(self, path, default_value):
1593        """
1594        Get value for config item into a string value; leading slash is optional
1595and ignored.
1596        """
1597        return lib.zconfig_get(self._as_parameter_, path, default_value)
1598
1599    def set_name(self, name):
1600        """
1601        Set config item name, name may be NULL
1602        """
1603        return lib.zconfig_set_name(self._as_parameter_, name)
1604
1605    def set_value(self, format, *args):
1606        """
1607        Set new value for config item. The new value may be a string, a printf
1608format, or NULL. Note that if string may possibly contain '%', or if it
1609comes from an insecure source, you must use '%s' as the format, followed
1610by the string.
1611        """
1612        return lib.zconfig_set_value(self._as_parameter_, format, *args)
1613
1614    def child(self):
1615        """
1616        Find our first child, if any
1617        """
1618        return Zconfig(lib.zconfig_child(self._as_parameter_), False)
1619
1620    def next(self):
1621        """
1622        Find our first sibling, if any
1623        """
1624        return Zconfig(lib.zconfig_next(self._as_parameter_), False)
1625
1626    def locate(self, path):
1627        """
1628        Find a config item along a path; leading slash is optional and ignored.
1629        """
1630        return Zconfig(lib.zconfig_locate(self._as_parameter_, path), False)
1631
1632    def at_depth(self, level):
1633        """
1634        Locate the last config item at a specified depth
1635        """
1636        return Zconfig(lib.zconfig_at_depth(self._as_parameter_, level), False)
1637
1638    def execute(self, handler, arg):
1639        """
1640        Execute a callback for each config item in the tree; returns zero if
1641successful, else -1.
1642        """
1643        return lib.zconfig_execute(self._as_parameter_, handler, arg)
1644
1645    def set_comment(self, format, *args):
1646        """
1647        Add comment to config item before saving to disk. You can add as many
1648comment lines as you like. If you use a null format, all comments are
1649deleted.
1650        """
1651        return lib.zconfig_set_comment(self._as_parameter_, format, *args)
1652
1653    def comments(self):
1654        """
1655        Return comments of config item, as zlist.
1656        """
1657        return Zlist(lib.zconfig_comments(self._as_parameter_), False)
1658
1659    def save(self, filename):
1660        """
1661        Save a config tree to a specified ZPL text file, where a filename
1662"-" means dump to standard output.
1663        """
1664        return lib.zconfig_save(self._as_parameter_, filename)
1665
1666    def savef(self, format, *args):
1667        """
1668        Equivalent to zconfig_save, taking a format string instead of a fixed
1669filename.
1670        """
1671        return lib.zconfig_savef(self._as_parameter_, format, *args)
1672
1673    def filename(self):
1674        """
1675        Report filename used during zconfig_load, or NULL if none
1676        """
1677        return lib.zconfig_filename(self._as_parameter_)
1678
1679    @staticmethod
1680    def reload(self_p):
1681        """
1682        Reload config tree from same file that it was previously loaded from.
1683Returns 0 if OK, -1 if there was an error (and then does not change
1684existing data).
1685        """
1686        return lib.zconfig_reload(byref(zconfig_p.from_param(self_p)))
1687
1688    @staticmethod
1689    def chunk_load(chunk):
1690        """
1691        Load a config tree from a memory chunk
1692        """
1693        return Zconfig(lib.zconfig_chunk_load(chunk), False)
1694
1695    def chunk_save(self):
1696        """
1697        Save a config tree to a new memory chunk
1698        """
1699        return Zchunk(lib.zconfig_chunk_save(self._as_parameter_), False)
1700
1701    @staticmethod
1702    def str_load(string):
1703        """
1704        Load a config tree from a null-terminated string
1705        """
1706        return Zconfig(lib.zconfig_str_load(string), True)
1707
1708    def str_save(self):
1709        """
1710        Save a config tree to a new null terminated string
1711        """
1712        return return_fresh_string(lib.zconfig_str_save(self._as_parameter_))
1713
1714    def has_changed(self):
1715        """
1716        Return true if a configuration tree was loaded from a file and that
1717file has changed in since the tree was loaded.
1718        """
1719        return lib.zconfig_has_changed(self._as_parameter_)
1720
1721    def remove_subtree(self):
1722        """
1723        Destroy subtree (all children)
1724        """
1725        return lib.zconfig_remove_subtree(self._as_parameter_)
1726
1727    @staticmethod
1728    def remove(self_p):
1729        """
1730        Destroy node and subtree (all children)
1731        """
1732        return lib.zconfig_remove(byref(zconfig_p.from_param(self_p)))
1733
1734    def fprint(self, file):
1735        """
1736        Print the config file to open stream
1737        """
1738        return lib.zconfig_fprint(self._as_parameter_, coerce_py_file(file))
1739
1740    def print(self):
1741        """
1742        Print properties of object
1743        """
1744        return lib.zconfig_print(self._as_parameter_)
1745
1746    @staticmethod
1747    def test(verbose):
1748        """
1749        Self test of this class
1750        """
1751        return lib.zconfig_test(verbose)
1752
1753
1754# zdigest
1755lib.zdigest_new.restype = zdigest_p
1756lib.zdigest_new.argtypes = []
1757lib.zdigest_destroy.restype = None
1758lib.zdigest_destroy.argtypes = [POINTER(zdigest_p)]
1759lib.zdigest_update.restype = None
1760lib.zdigest_update.argtypes = [zdigest_p, c_void_p, c_size_t]
1761lib.zdigest_data.restype = c_void_p
1762lib.zdigest_data.argtypes = [zdigest_p]
1763lib.zdigest_size.restype = c_size_t
1764lib.zdigest_size.argtypes = [zdigest_p]
1765lib.zdigest_string.restype = c_char_p
1766lib.zdigest_string.argtypes = [zdigest_p]
1767lib.zdigest_test.restype = None
1768lib.zdigest_test.argtypes = [c_bool]
1769
1770class Zdigest(object):
1771    """
1772    provides hashing functions (SHA-1 at present)
1773    """
1774
1775    allow_destruct = False
1776    def __init__(self, *args):
1777        """
1778        Constructor - creates new digest object, which you use to build up a
1779digest by repeatedly calling zdigest_update() on chunks of data.
1780        """
1781        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
1782            self._as_parameter_ = cast(args[0], zdigest_p) # Conversion from raw type to binding
1783            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1784        elif len(args) == 2 and type(args[0]) is zdigest_p and isinstance(args[1], bool):
1785            self._as_parameter_ = args[0] # Conversion from raw type to binding
1786            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1787        else:
1788            assert(len(args) == 0)
1789            self._as_parameter_ = lib.zdigest_new() # Creation of new raw type
1790            self.allow_destruct = True
1791
1792    def __del__(self):
1793        """
1794        Destroy a digest object
1795        """
1796        if self.allow_destruct:
1797            lib.zdigest_destroy(byref(self._as_parameter_))
1798
1799    def __eq__(self, other):
1800        if type(other) == type(self):
1801            return other.c_address() == self.c_address()
1802        elif type(other) == c_void_p:
1803            return other.value == self.c_address()
1804
1805    def c_address(self):
1806        """
1807        Return the address of the object pointer in c.  Useful for comparison.
1808        """
1809        return addressof(self._as_parameter_.contents)
1810
1811    def __bool__(self):
1812        "Determine whether the object is valid by converting to boolean" # Python 3
1813        return self._as_parameter_.__bool__()
1814
1815    def __nonzero__(self):
1816        "Determine whether the object is valid by converting to boolean" # Python 2
1817        return self._as_parameter_.__nonzero__()
1818
1819    def update(self, buffer, length):
1820        """
1821        Add buffer into digest calculation
1822        """
1823        return lib.zdigest_update(self._as_parameter_, buffer, length)
1824
1825    def data(self):
1826        """
1827        Return final digest hash data. If built without crypto support,
1828returns NULL.
1829        """
1830        return lib.zdigest_data(self._as_parameter_)
1831
1832    def size(self):
1833        """
1834        Return final digest hash size
1835        """
1836        return lib.zdigest_size(self._as_parameter_)
1837
1838    def string(self):
1839        """
1840        Return digest as printable hex string; caller should not modify nor
1841free this string. After calling this, you may not use zdigest_update()
1842on the same digest. If built without crypto support, returns NULL.
1843        """
1844        return lib.zdigest_string(self._as_parameter_)
1845
1846    @staticmethod
1847    def test(verbose):
1848        """
1849        Self test of this class.
1850        """
1851        return lib.zdigest_test(verbose)
1852
1853
1854# zdir
1855lib.zdir_new.restype = zdir_p
1856lib.zdir_new.argtypes = [c_char_p, c_char_p]
1857lib.zdir_destroy.restype = None
1858lib.zdir_destroy.argtypes = [POINTER(zdir_p)]
1859lib.zdir_path.restype = c_char_p
1860lib.zdir_path.argtypes = [zdir_p]
1861lib.zdir_modified.restype = c_int
1862lib.zdir_modified.argtypes = [zdir_p]
1863lib.zdir_cursize.restype = c_int
1864lib.zdir_cursize.argtypes = [zdir_p]
1865lib.zdir_count.restype = c_size_t
1866lib.zdir_count.argtypes = [zdir_p]
1867lib.zdir_list.restype = zlist_p
1868lib.zdir_list.argtypes = [zdir_p]
1869lib.zdir_remove.restype = None
1870lib.zdir_remove.argtypes = [zdir_p, c_bool]
1871lib.zdir_diff.restype = zlist_p
1872lib.zdir_diff.argtypes = [zdir_p, zdir_p, c_char_p]
1873lib.zdir_resync.restype = zlist_p
1874lib.zdir_resync.argtypes = [zdir_p, c_char_p]
1875lib.zdir_cache.restype = zhash_p
1876lib.zdir_cache.argtypes = [zdir_p]
1877lib.zdir_fprint.restype = None
1878lib.zdir_fprint.argtypes = [zdir_p, FILE_p, c_int]
1879lib.zdir_print.restype = None
1880lib.zdir_print.argtypes = [zdir_p, c_int]
1881lib.zdir_watch.restype = None
1882lib.zdir_watch.argtypes = [zsock_p, c_void_p]
1883lib.zdir_test.restype = None
1884lib.zdir_test.argtypes = [c_bool]
1885
1886class Zdir(object):
1887    """
1888    work with file-system directories
1889    """
1890
1891    allow_destruct = False
1892    def __init__(self, *args):
1893        """
1894        Create a new directory item that loads in the full tree of the specified
1895path, optionally located under some parent path. If parent is "-", then
1896loads only the top-level directory, and does not use parent as a path.
1897        """
1898        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
1899            self._as_parameter_ = cast(args[0], zdir_p) # Conversion from raw type to binding
1900            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1901        elif len(args) == 2 and type(args[0]) is zdir_p and isinstance(args[1], bool):
1902            self._as_parameter_ = args[0] # Conversion from raw type to binding
1903            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
1904        else:
1905            assert(len(args) == 2)
1906            self._as_parameter_ = lib.zdir_new(args[0], args[1]) # Creation of new raw type
1907            self.allow_destruct = True
1908
1909    def __del__(self):
1910        """
1911        Destroy a directory tree and all children it contains.
1912        """
1913        if self.allow_destruct:
1914            lib.zdir_destroy(byref(self._as_parameter_))
1915
1916    def __eq__(self, other):
1917        if type(other) == type(self):
1918            return other.c_address() == self.c_address()
1919        elif type(other) == c_void_p:
1920            return other.value == self.c_address()
1921
1922    def c_address(self):
1923        """
1924        Return the address of the object pointer in c.  Useful for comparison.
1925        """
1926        return addressof(self._as_parameter_.contents)
1927
1928    def __bool__(self):
1929        "Determine whether the object is valid by converting to boolean" # Python 3
1930        return self._as_parameter_.__bool__()
1931
1932    def __nonzero__(self):
1933        "Determine whether the object is valid by converting to boolean" # Python 2
1934        return self._as_parameter_.__nonzero__()
1935
1936    def path(self):
1937        """
1938        Return directory path
1939        """
1940        return lib.zdir_path(self._as_parameter_)
1941
1942    def modified(self):
1943        """
1944        Return last modification time for directory.
1945        """
1946        return lib.zdir_modified(self._as_parameter_)
1947
1948    def cursize(self):
1949        """
1950        Return total hierarchy size, in bytes of data contained in all files
1951in the directory tree.
1952        """
1953        return lib.zdir_cursize(self._as_parameter_)
1954
1955    def count(self):
1956        """
1957        Return directory count
1958        """
1959        return lib.zdir_count(self._as_parameter_)
1960
1961    def list(self):
1962        """
1963        Returns a sorted list of zfile objects; Each entry in the list is a pointer
1964to a zfile_t item already allocated in the zdir tree. Do not destroy the
1965original zdir tree until you are done with this list.
1966        """
1967        return Zlist(lib.zdir_list(self._as_parameter_), True)
1968
1969    def remove(self, force):
1970        """
1971        Remove directory, optionally including all files that it contains, at
1972all levels. If force is false, will only remove the directory if empty.
1973If force is true, will remove all files and all subdirectories.
1974        """
1975        return lib.zdir_remove(self._as_parameter_, force)
1976
1977    @staticmethod
1978    def diff(older, newer, alias):
1979        """
1980        Calculate differences between two versions of a directory tree.
1981Returns a list of zdir_patch_t patches. Either older or newer may
1982be null, indicating the directory is empty/absent. If alias is set,
1983generates virtual filename (minus path, plus alias).
1984        """
1985        return Zlist(lib.zdir_diff(older, newer, alias), True)
1986
1987    def resync(self, alias):
1988        """
1989        Return full contents of directory as a zdir_patch list.
1990        """
1991        return Zlist(lib.zdir_resync(self._as_parameter_, alias), True)
1992
1993    def cache(self):
1994        """
1995        Load directory cache; returns a hash table containing the SHA-1 digests
1996of every file in the tree. The cache is saved between runs in .cache.
1997        """
1998        return Zhash(lib.zdir_cache(self._as_parameter_), True)
1999
2000    def fprint(self, file, indent):
2001        """
2002        Print contents of directory to open stream
2003        """
2004        return lib.zdir_fprint(self._as_parameter_, coerce_py_file(file), indent)
2005
2006    def print(self, indent):
2007        """
2008        Print contents of directory to stdout
2009        """
2010        return lib.zdir_print(self._as_parameter_, indent)
2011
2012    @staticmethod
2013    def watch(pipe, unused):
2014        """
2015        Create a new zdir_watch actor instance:
2016
2017    zactor_t *watch = zactor_new (zdir_watch, NULL);
2018
2019Destroy zdir_watch instance:
2020
2021    zactor_destroy (&watch);
2022
2023Enable verbose logging of commands and activity:
2024
2025    zstr_send (watch, "VERBOSE");
2026
2027Subscribe to changes to a directory path:
2028
2029    zsock_send (watch, "ss", "SUBSCRIBE", "directory_path");
2030
2031Unsubscribe from changes to a directory path:
2032
2033    zsock_send (watch, "ss", "UNSUBSCRIBE", "directory_path");
2034
2035Receive directory changes:
2036    zsock_recv (watch, "sp", &path, &patches);
2037
2038    // Delete the received data.
2039    free (path);
2040    zlist_destroy (&patches);
2041        """
2042        return lib.zdir_watch(pipe, unused)
2043
2044    @staticmethod
2045    def test(verbose):
2046        """
2047        Self test of this class.
2048        """
2049        return lib.zdir_test(verbose)
2050
2051
2052# zdir_patch
2053lib.zdir_patch_new.restype = zdir_patch_p
2054lib.zdir_patch_new.argtypes = [c_char_p, zfile_p, c_int, c_char_p]
2055lib.zdir_patch_destroy.restype = None
2056lib.zdir_patch_destroy.argtypes = [POINTER(zdir_patch_p)]
2057lib.zdir_patch_dup.restype = zdir_patch_p
2058lib.zdir_patch_dup.argtypes = [zdir_patch_p]
2059lib.zdir_patch_path.restype = c_char_p
2060lib.zdir_patch_path.argtypes = [zdir_patch_p]
2061lib.zdir_patch_file.restype = zfile_p
2062lib.zdir_patch_file.argtypes = [zdir_patch_p]
2063lib.zdir_patch_op.restype = c_int
2064lib.zdir_patch_op.argtypes = [zdir_patch_p]
2065lib.zdir_patch_vpath.restype = c_char_p
2066lib.zdir_patch_vpath.argtypes = [zdir_patch_p]
2067lib.zdir_patch_digest_set.restype = None
2068lib.zdir_patch_digest_set.argtypes = [zdir_patch_p]
2069lib.zdir_patch_digest.restype = c_char_p
2070lib.zdir_patch_digest.argtypes = [zdir_patch_p]
2071lib.zdir_patch_test.restype = None
2072lib.zdir_patch_test.argtypes = [c_bool]
2073
2074class ZdirPatch(object):
2075    """
2076    work with directory patches
2077    """
2078
2079    CREATE = 1 # Creates a new file
2080    DELETE = 2 # Delete a file
2081    allow_destruct = False
2082    def __init__(self, *args):
2083        """
2084        Create new patch
2085        """
2086        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
2087            self._as_parameter_ = cast(args[0], zdir_patch_p) # Conversion from raw type to binding
2088            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2089        elif len(args) == 2 and type(args[0]) is zdir_patch_p and isinstance(args[1], bool):
2090            self._as_parameter_ = args[0] # Conversion from raw type to binding
2091            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2092        else:
2093            assert(len(args) == 4)
2094            self._as_parameter_ = lib.zdir_patch_new(args[0], args[1], args[2], args[3]) # Creation of new raw type
2095            self.allow_destruct = True
2096
2097    def __del__(self):
2098        """
2099        Destroy a patch
2100        """
2101        if self.allow_destruct:
2102            lib.zdir_patch_destroy(byref(self._as_parameter_))
2103
2104    def __eq__(self, other):
2105        if type(other) == type(self):
2106            return other.c_address() == self.c_address()
2107        elif type(other) == c_void_p:
2108            return other.value == self.c_address()
2109
2110    def c_address(self):
2111        """
2112        Return the address of the object pointer in c.  Useful for comparison.
2113        """
2114        return addressof(self._as_parameter_.contents)
2115
2116    def __bool__(self):
2117        "Determine whether the object is valid by converting to boolean" # Python 3
2118        return self._as_parameter_.__bool__()
2119
2120    def __nonzero__(self):
2121        "Determine whether the object is valid by converting to boolean" # Python 2
2122        return self._as_parameter_.__nonzero__()
2123
2124    def dup(self):
2125        """
2126        Create copy of a patch. If the patch is null, or memory was exhausted,
2127returns null.
2128        """
2129        return ZdirPatch(lib.zdir_patch_dup(self._as_parameter_), True)
2130
2131    def path(self):
2132        """
2133        Return patch file directory path
2134        """
2135        return lib.zdir_patch_path(self._as_parameter_)
2136
2137    def file(self):
2138        """
2139        Return patch file item
2140        """
2141        return Zfile(lib.zdir_patch_file(self._as_parameter_), False)
2142
2143    def op(self):
2144        """
2145        Return operation
2146        """
2147        return lib.zdir_patch_op(self._as_parameter_)
2148
2149    def vpath(self):
2150        """
2151        Return patch virtual file path
2152        """
2153        return lib.zdir_patch_vpath(self._as_parameter_)
2154
2155    def digest_set(self):
2156        """
2157        Calculate hash digest for file (create only)
2158        """
2159        return lib.zdir_patch_digest_set(self._as_parameter_)
2160
2161    def digest(self):
2162        """
2163        Return hash digest for patch file
2164        """
2165        return lib.zdir_patch_digest(self._as_parameter_)
2166
2167    @staticmethod
2168    def test(verbose):
2169        """
2170        Self test of this class.
2171        """
2172        return lib.zdir_patch_test(verbose)
2173
2174
2175# zfile
2176lib.zfile_new.restype = zfile_p
2177lib.zfile_new.argtypes = [c_char_p, c_char_p]
2178lib.zfile_destroy.restype = None
2179lib.zfile_destroy.argtypes = [POINTER(zfile_p)]
2180lib.zfile_tmp.restype = zfile_p
2181lib.zfile_tmp.argtypes = []
2182lib.zfile_dup.restype = zfile_p
2183lib.zfile_dup.argtypes = [zfile_p]
2184lib.zfile_filename.restype = c_char_p
2185lib.zfile_filename.argtypes = [zfile_p, c_char_p]
2186lib.zfile_restat.restype = None
2187lib.zfile_restat.argtypes = [zfile_p]
2188lib.zfile_modified.restype = c_int
2189lib.zfile_modified.argtypes = [zfile_p]
2190lib.zfile_cursize.restype = c_int
2191lib.zfile_cursize.argtypes = [zfile_p]
2192lib.zfile_is_directory.restype = c_bool
2193lib.zfile_is_directory.argtypes = [zfile_p]
2194lib.zfile_is_regular.restype = c_bool
2195lib.zfile_is_regular.argtypes = [zfile_p]
2196lib.zfile_is_readable.restype = c_bool
2197lib.zfile_is_readable.argtypes = [zfile_p]
2198lib.zfile_is_writeable.restype = c_bool
2199lib.zfile_is_writeable.argtypes = [zfile_p]
2200lib.zfile_is_stable.restype = c_bool
2201lib.zfile_is_stable.argtypes = [zfile_p]
2202lib.zfile_has_changed.restype = c_bool
2203lib.zfile_has_changed.argtypes = [zfile_p]
2204lib.zfile_remove.restype = None
2205lib.zfile_remove.argtypes = [zfile_p]
2206lib.zfile_input.restype = c_int
2207lib.zfile_input.argtypes = [zfile_p]
2208lib.zfile_output.restype = c_int
2209lib.zfile_output.argtypes = [zfile_p]
2210lib.zfile_read.restype = zchunk_p
2211lib.zfile_read.argtypes = [zfile_p, c_size_t, c_int]
2212lib.zfile_eof.restype = c_bool
2213lib.zfile_eof.argtypes = [zfile_p]
2214lib.zfile_write.restype = c_int
2215lib.zfile_write.argtypes = [zfile_p, zchunk_p, c_int]
2216lib.zfile_readln.restype = c_char_p
2217lib.zfile_readln.argtypes = [zfile_p]
2218lib.zfile_close.restype = None
2219lib.zfile_close.argtypes = [zfile_p]
2220lib.zfile_handle.restype = FILE_p
2221lib.zfile_handle.argtypes = [zfile_p]
2222lib.zfile_digest.restype = c_char_p
2223lib.zfile_digest.argtypes = [zfile_p]
2224lib.zfile_test.restype = None
2225lib.zfile_test.argtypes = [c_bool]
2226
2227class Zfile(object):
2228    """
2229    helper functions for working with files.
2230    """
2231
2232    allow_destruct = False
2233    def __init__(self, *args):
2234        """
2235        If file exists, populates properties. CZMQ supports portable symbolic
2236links, which are files with the extension ".ln". A symbolic link is a
2237text file containing one line, the filename of a target file. Reading
2238data from the symbolic link actually reads from the target file. Path
2239may be NULL, in which case it is not used.
2240        """
2241        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
2242            self._as_parameter_ = cast(args[0], zfile_p) # Conversion from raw type to binding
2243            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2244        elif len(args) == 2 and type(args[0]) is zfile_p and isinstance(args[1], bool):
2245            self._as_parameter_ = args[0] # Conversion from raw type to binding
2246            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2247        else:
2248            assert(len(args) == 2)
2249            self._as_parameter_ = lib.zfile_new(args[0], args[1]) # Creation of new raw type
2250            self.allow_destruct = True
2251
2252    def __del__(self):
2253        """
2254        Destroy a file item
2255        """
2256        if self.allow_destruct:
2257            lib.zfile_destroy(byref(self._as_parameter_))
2258
2259    def __eq__(self, other):
2260        if type(other) == type(self):
2261            return other.c_address() == self.c_address()
2262        elif type(other) == c_void_p:
2263            return other.value == self.c_address()
2264
2265    def c_address(self):
2266        """
2267        Return the address of the object pointer in c.  Useful for comparison.
2268        """
2269        return addressof(self._as_parameter_.contents)
2270
2271    def __bool__(self):
2272        "Determine whether the object is valid by converting to boolean" # Python 3
2273        return self._as_parameter_.__bool__()
2274
2275    def __nonzero__(self):
2276        "Determine whether the object is valid by converting to boolean" # Python 2
2277        return self._as_parameter_.__nonzero__()
2278
2279    @staticmethod
2280    def tmp():
2281        """
2282        Create new temporary file for writing via tmpfile. File is automaticaly
2283deleted on destroy
2284        """
2285        return Zfile(lib.zfile_tmp(), True)
2286
2287    def dup(self):
2288        """
2289        Duplicate a file item, returns a newly constructed item. If the file
2290is null, or memory was exhausted, returns null.
2291        """
2292        return Zfile(lib.zfile_dup(self._as_parameter_), True)
2293
2294    def filename(self, path):
2295        """
2296        Return file name, remove path if provided
2297        """
2298        return lib.zfile_filename(self._as_parameter_, path)
2299
2300    def restat(self):
2301        """
2302        Refresh file properties from disk; this is not done automatically
2303on access methods, otherwise it is not possible to compare directory
2304snapshots.
2305        """
2306        return lib.zfile_restat(self._as_parameter_)
2307
2308    def modified(self):
2309        """
2310        Return when the file was last modified. If you want this to reflect the
2311current situation, call zfile_restat before checking this property.
2312        """
2313        return lib.zfile_modified(self._as_parameter_)
2314
2315    def cursize(self):
2316        """
2317        Return the last-known size of the file. If you want this to reflect the
2318current situation, call zfile_restat before checking this property.
2319        """
2320        return lib.zfile_cursize(self._as_parameter_)
2321
2322    def is_directory(self):
2323        """
2324        Return true if the file is a directory. If you want this to reflect
2325any external changes, call zfile_restat before checking this property.
2326        """
2327        return lib.zfile_is_directory(self._as_parameter_)
2328
2329    def is_regular(self):
2330        """
2331        Return true if the file is a regular file. If you want this to reflect
2332any external changes, call zfile_restat before checking this property.
2333        """
2334        return lib.zfile_is_regular(self._as_parameter_)
2335
2336    def is_readable(self):
2337        """
2338        Return true if the file is readable by this process. If you want this to
2339reflect any external changes, call zfile_restat before checking this
2340property.
2341        """
2342        return lib.zfile_is_readable(self._as_parameter_)
2343
2344    def is_writeable(self):
2345        """
2346        Return true if the file is writeable by this process. If you want this
2347to reflect any external changes, call zfile_restat before checking this
2348property.
2349        """
2350        return lib.zfile_is_writeable(self._as_parameter_)
2351
2352    def is_stable(self):
2353        """
2354        Check if file has stopped changing and can be safely processed.
2355Updates the file statistics from disk at every call.
2356        """
2357        return lib.zfile_is_stable(self._as_parameter_)
2358
2359    def has_changed(self):
2360        """
2361        Return true if the file was changed on disk since the zfile_t object
2362was created, or the last zfile_restat() call made on it.
2363        """
2364        return lib.zfile_has_changed(self._as_parameter_)
2365
2366    def remove(self):
2367        """
2368        Remove the file from disk
2369        """
2370        return lib.zfile_remove(self._as_parameter_)
2371
2372    def input(self):
2373        """
2374        Open file for reading
2375Returns 0 if OK, -1 if not found or not accessible
2376        """
2377        return lib.zfile_input(self._as_parameter_)
2378
2379    def output(self):
2380        """
2381        Open file for writing, creating directory if needed
2382File is created if necessary; chunks can be written to file at any
2383location. Returns 0 if OK, -1 if error.
2384        """
2385        return lib.zfile_output(self._as_parameter_)
2386
2387    def read(self, bytes, offset):
2388        """
2389        Read chunk from file at specified position. If this was the last chunk,
2390sets the eof property. Returns a null chunk in case of error.
2391        """
2392        return Zchunk(lib.zfile_read(self._as_parameter_, bytes, offset), True)
2393
2394    def eof(self):
2395        """
2396        Returns true if zfile_read() just read the last chunk in the file.
2397        """
2398        return lib.zfile_eof(self._as_parameter_)
2399
2400    def write(self, chunk, offset):
2401        """
2402        Write chunk to file at specified position
2403Return 0 if OK, else -1
2404        """
2405        return lib.zfile_write(self._as_parameter_, chunk, offset)
2406
2407    def readln(self):
2408        """
2409        Read next line of text from file. Returns a pointer to the text line,
2410or NULL if there was nothing more to read from the file.
2411        """
2412        return lib.zfile_readln(self._as_parameter_)
2413
2414    def close(self):
2415        """
2416        Close file, if open
2417        """
2418        return lib.zfile_close(self._as_parameter_)
2419
2420    def handle(self):
2421        """
2422        Return file handle, if opened
2423        """
2424        return return_py_file(lib.zfile_handle(self._as_parameter_))
2425
2426    def digest(self):
2427        """
2428        Calculate SHA1 digest for file, using zdigest class.
2429        """
2430        return lib.zfile_digest(self._as_parameter_)
2431
2432    @staticmethod
2433    def test(verbose):
2434        """
2435        Self test of this class.
2436        """
2437        return lib.zfile_test(verbose)
2438
2439
2440# zframe
2441lib.zframe_new.restype = zframe_p
2442lib.zframe_new.argtypes = [c_void_p, c_size_t]
2443lib.zframe_destroy.restype = None
2444lib.zframe_destroy.argtypes = [POINTER(zframe_p)]
2445lib.zframe_new_empty.restype = zframe_p
2446lib.zframe_new_empty.argtypes = []
2447lib.zframe_from.restype = zframe_p
2448lib.zframe_from.argtypes = [c_char_p]
2449lib.zframe_recv.restype = zframe_p
2450lib.zframe_recv.argtypes = [c_void_p]
2451lib.zframe_send.restype = c_int
2452lib.zframe_send.argtypes = [POINTER(zframe_p), c_void_p, c_int]
2453lib.zframe_size.restype = c_size_t
2454lib.zframe_size.argtypes = [zframe_p]
2455lib.zframe_data.restype = c_void_p
2456lib.zframe_data.argtypes = [zframe_p]
2457lib.zframe_meta.restype = c_char_p
2458lib.zframe_meta.argtypes = [zframe_p, c_char_p]
2459lib.zframe_dup.restype = zframe_p
2460lib.zframe_dup.argtypes = [zframe_p]
2461lib.zframe_strhex.restype = POINTER(c_char)
2462lib.zframe_strhex.argtypes = [zframe_p]
2463lib.zframe_strdup.restype = POINTER(c_char)
2464lib.zframe_strdup.argtypes = [zframe_p]
2465lib.zframe_streq.restype = c_bool
2466lib.zframe_streq.argtypes = [zframe_p, c_char_p]
2467lib.zframe_more.restype = c_int
2468lib.zframe_more.argtypes = [zframe_p]
2469lib.zframe_set_more.restype = None
2470lib.zframe_set_more.argtypes = [zframe_p, c_int]
2471lib.zframe_routing_id.restype = c_int
2472lib.zframe_routing_id.argtypes = [zframe_p]
2473lib.zframe_set_routing_id.restype = None
2474lib.zframe_set_routing_id.argtypes = [zframe_p, c_int]
2475lib.zframe_group.restype = c_char_p
2476lib.zframe_group.argtypes = [zframe_p]
2477lib.zframe_set_group.restype = c_int
2478lib.zframe_set_group.argtypes = [zframe_p, c_char_p]
2479lib.zframe_eq.restype = c_bool
2480lib.zframe_eq.argtypes = [zframe_p, zframe_p]
2481lib.zframe_reset.restype = None
2482lib.zframe_reset.argtypes = [zframe_p, c_void_p, c_size_t]
2483lib.zframe_print.restype = None
2484lib.zframe_print.argtypes = [zframe_p, c_char_p]
2485lib.zframe_is.restype = c_bool
2486lib.zframe_is.argtypes = [c_void_p]
2487lib.zframe_test.restype = None
2488lib.zframe_test.argtypes = [c_bool]
2489
2490class Zframe(object):
2491    """
2492    working with single message frames
2493    """
2494
2495    MORE = 1 #
2496    REUSE = 2 #
2497    DONTWAIT = 4 #
2498    allow_destruct = False
2499    def __init__(self, *args):
2500        """
2501        Create a new frame. If size is not null, allocates the frame data
2502to the specified size. If additionally, data is not null, copies
2503size octets from the specified data into the frame body.
2504        """
2505        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
2506            self._as_parameter_ = cast(args[0], zframe_p) # Conversion from raw type to binding
2507            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2508        elif len(args) == 2 and type(args[0]) is zframe_p and isinstance(args[1], bool):
2509            self._as_parameter_ = args[0] # Conversion from raw type to binding
2510            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2511        else:
2512            assert(len(args) == 2)
2513            self._as_parameter_ = lib.zframe_new(args[0], args[1]) # Creation of new raw type
2514            self.allow_destruct = True
2515
2516    def __del__(self):
2517        """
2518        Destroy a frame
2519        """
2520        if self.allow_destruct:
2521            lib.zframe_destroy(byref(self._as_parameter_))
2522
2523    def __eq__(self, other):
2524        if type(other) == type(self):
2525            return other.c_address() == self.c_address()
2526        elif type(other) == c_void_p:
2527            return other.value == self.c_address()
2528
2529    def c_address(self):
2530        """
2531        Return the address of the object pointer in c.  Useful for comparison.
2532        """
2533        return addressof(self._as_parameter_.contents)
2534
2535    def __bool__(self):
2536        "Determine whether the object is valid by converting to boolean" # Python 3
2537        return self._as_parameter_.__bool__()
2538
2539    def __nonzero__(self):
2540        "Determine whether the object is valid by converting to boolean" # Python 2
2541        return self._as_parameter_.__nonzero__()
2542
2543    @staticmethod
2544    def new_empty():
2545        """
2546        Create an empty (zero-sized) frame
2547        """
2548        return Zframe(lib.zframe_new_empty(), True)
2549
2550    @staticmethod
2551    def from_(string):
2552        """
2553        Create a frame with a specified string content.
2554        """
2555        return Zframe(lib.zframe_from(string), True)
2556
2557    @staticmethod
2558    def recv(source):
2559        """
2560        Receive frame from socket, returns zframe_t object or NULL if the recv
2561was interrupted. Does a blocking recv, if you want to not block then use
2562zpoller or zloop.
2563        """
2564        return Zframe(lib.zframe_recv(source), True)
2565
2566    @staticmethod
2567    def send(self_p, dest, flags):
2568        """
2569        Send a frame to a socket, destroy frame after sending.
2570Return -1 on error, 0 on success.
2571        """
2572        return lib.zframe_send(byref(zframe_p.from_param(self_p)), dest, flags)
2573
2574    def size(self):
2575        """
2576        Return number of bytes in frame data
2577        """
2578        return lib.zframe_size(self._as_parameter_)
2579
2580    def data(self):
2581        """
2582        Return address of frame data
2583        """
2584        return lib.zframe_data(self._as_parameter_)
2585
2586    def meta(self, property):
2587        """
2588        Return meta data property for frame
2589The caller shall not modify or free the returned value, which shall be
2590owned by the message.
2591        """
2592        return lib.zframe_meta(self._as_parameter_, property)
2593
2594    def dup(self):
2595        """
2596        Create a new frame that duplicates an existing frame. If frame is null,
2597or memory was exhausted, returns null.
2598        """
2599        return Zframe(lib.zframe_dup(self._as_parameter_), True)
2600
2601    def strhex(self):
2602        """
2603        Return frame data encoded as printable hex string, useful for 0MQ UUIDs.
2604Caller must free string when finished with it.
2605        """
2606        return return_fresh_string(lib.zframe_strhex(self._as_parameter_))
2607
2608    def strdup(self):
2609        """
2610        Return frame data copied into freshly allocated string
2611Caller must free string when finished with it.
2612        """
2613        return return_fresh_string(lib.zframe_strdup(self._as_parameter_))
2614
2615    def streq(self, string):
2616        """
2617        Return TRUE if frame body is equal to string, excluding terminator
2618        """
2619        return lib.zframe_streq(self._as_parameter_, string)
2620
2621    def more(self):
2622        """
2623        Return frame MORE indicator (1 or 0), set when reading frame from socket
2624or by the zframe_set_more() method
2625        """
2626        return lib.zframe_more(self._as_parameter_)
2627
2628    def set_more(self, more):
2629        """
2630        Set frame MORE indicator (1 or 0). Note this is NOT used when sending
2631frame to socket, you have to specify flag explicitly.
2632        """
2633        return lib.zframe_set_more(self._as_parameter_, more)
2634
2635    def routing_id(self):
2636        """
2637        Return frame routing ID, if the frame came from a ZMQ_SERVER socket.
2638Else returns zero.
2639        """
2640        return lib.zframe_routing_id(self._as_parameter_)
2641
2642    def set_routing_id(self, routing_id):
2643        """
2644        Set routing ID on frame. This is used if/when the frame is sent to a
2645ZMQ_SERVER socket.
2646        """
2647        return lib.zframe_set_routing_id(self._as_parameter_, routing_id)
2648
2649    def group(self):
2650        """
2651        Return frame group of radio-dish pattern.
2652        """
2653        return lib.zframe_group(self._as_parameter_)
2654
2655    def set_group(self, group):
2656        """
2657        Set group on frame. This is used if/when the frame is sent to a
2658ZMQ_RADIO socket.
2659Return -1 on error, 0 on success.
2660        """
2661        return lib.zframe_set_group(self._as_parameter_, group)
2662
2663    def eq(self, other):
2664        """
2665        Return TRUE if two frames have identical size and data
2666If either frame is NULL, equality is always false.
2667        """
2668        return lib.zframe_eq(self._as_parameter_, other)
2669
2670    def reset(self, data, size):
2671        """
2672        Set new contents for frame
2673        """
2674        return lib.zframe_reset(self._as_parameter_, data, size)
2675
2676    def print(self, prefix):
2677        """
2678        Send message to zsys log sink (may be stdout, or system facility as
2679configured by zsys_set_logstream). Prefix shows before frame, if not null.
2680        """
2681        return lib.zframe_print(self._as_parameter_, prefix)
2682
2683    @staticmethod
2684    def is_(self):
2685        """
2686        Probe the supplied object, and report if it looks like a zframe_t.
2687        """
2688        return lib.zframe_is(self)
2689
2690    @staticmethod
2691    def test(verbose):
2692        """
2693        Self test of this class.
2694        """
2695        return lib.zframe_test(verbose)
2696
2697
2698# zhash
2699zhash_free_fn = CFUNCTYPE(None, c_void_p)
2700lib.zhash_new.restype = zhash_p
2701lib.zhash_new.argtypes = []
2702lib.zhash_destroy.restype = None
2703lib.zhash_destroy.argtypes = [POINTER(zhash_p)]
2704lib.zhash_unpack.restype = zhash_p
2705lib.zhash_unpack.argtypes = [zframe_p]
2706lib.zhash_insert.restype = c_int
2707lib.zhash_insert.argtypes = [zhash_p, c_char_p, c_void_p]
2708lib.zhash_update.restype = None
2709lib.zhash_update.argtypes = [zhash_p, c_char_p, c_void_p]
2710lib.zhash_delete.restype = None
2711lib.zhash_delete.argtypes = [zhash_p, c_char_p]
2712lib.zhash_lookup.restype = c_void_p
2713lib.zhash_lookup.argtypes = [zhash_p, c_char_p]
2714lib.zhash_rename.restype = c_int
2715lib.zhash_rename.argtypes = [zhash_p, c_char_p, c_char_p]
2716lib.zhash_freefn.restype = c_void_p
2717lib.zhash_freefn.argtypes = [zhash_p, c_char_p, zhash_free_fn]
2718lib.zhash_size.restype = c_size_t
2719lib.zhash_size.argtypes = [zhash_p]
2720lib.zhash_dup.restype = zhash_p
2721lib.zhash_dup.argtypes = [zhash_p]
2722lib.zhash_keys.restype = zlist_p
2723lib.zhash_keys.argtypes = [zhash_p]
2724lib.zhash_first.restype = c_void_p
2725lib.zhash_first.argtypes = [zhash_p]
2726lib.zhash_next.restype = c_void_p
2727lib.zhash_next.argtypes = [zhash_p]
2728lib.zhash_cursor.restype = c_char_p
2729lib.zhash_cursor.argtypes = [zhash_p]
2730lib.zhash_comment.restype = None
2731lib.zhash_comment.argtypes = [zhash_p, c_char_p]
2732lib.zhash_pack.restype = zframe_p
2733lib.zhash_pack.argtypes = [zhash_p]
2734lib.zhash_save.restype = c_int
2735lib.zhash_save.argtypes = [zhash_p, c_char_p]
2736lib.zhash_load.restype = c_int
2737lib.zhash_load.argtypes = [zhash_p, c_char_p]
2738lib.zhash_refresh.restype = c_int
2739lib.zhash_refresh.argtypes = [zhash_p]
2740lib.zhash_autofree.restype = None
2741lib.zhash_autofree.argtypes = [zhash_p]
2742lib.zhash_test.restype = None
2743lib.zhash_test.argtypes = [c_bool]
2744
2745class Zhash(object):
2746    """
2747    generic type-free hash container (simple)
2748    """
2749
2750    allow_destruct = False
2751    def __init__(self, *args):
2752        """
2753        Create a new, empty hash container
2754        """
2755        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
2756            self._as_parameter_ = cast(args[0], zhash_p) # Conversion from raw type to binding
2757            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2758        elif len(args) == 2 and type(args[0]) is zhash_p and isinstance(args[1], bool):
2759            self._as_parameter_ = args[0] # Conversion from raw type to binding
2760            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
2761        else:
2762            assert(len(args) == 0)
2763            self._as_parameter_ = lib.zhash_new() # Creation of new raw type
2764            self.allow_destruct = True
2765
2766    def __del__(self):
2767        """
2768        Destroy a hash container and all items in it
2769        """
2770        if self.allow_destruct:
2771            lib.zhash_destroy(byref(self._as_parameter_))
2772
2773    def __eq__(self, other):
2774        if type(other) == type(self):
2775            return other.c_address() == self.c_address()
2776        elif type(other) == c_void_p:
2777            return other.value == self.c_address()
2778
2779    def c_address(self):
2780        """
2781        Return the address of the object pointer in c.  Useful for comparison.
2782        """
2783        return addressof(self._as_parameter_.contents)
2784
2785    def __bool__(self):
2786        "Determine whether the object is valid by converting to boolean" # Python 3
2787        return self._as_parameter_.__bool__()
2788
2789    def __nonzero__(self):
2790        "Determine whether the object is valid by converting to boolean" # Python 2
2791        return self._as_parameter_.__nonzero__()
2792
2793    @staticmethod
2794    def unpack(frame):
2795        """
2796        Unpack binary frame into a new hash table. Packed data must follow format
2797defined by zhash_pack. Hash table is set to autofree. An empty frame
2798unpacks to an empty hash table.
2799        """
2800        return Zhash(lib.zhash_unpack(frame), True)
2801
2802    def insert(self, key, item):
2803        """
2804        Insert item into hash table with specified key and item.
2805If key is already present returns -1 and leaves existing item unchanged
2806Returns 0 on success.
2807        """
2808        return lib.zhash_insert(self._as_parameter_, key, item)
2809
2810    def update(self, key, item):
2811        """
2812        Update item into hash table with specified key and item.
2813If key is already present, destroys old item and inserts new one.
2814Use free_fn method to ensure deallocator is properly called on item.
2815        """
2816        return lib.zhash_update(self._as_parameter_, key, item)
2817
2818    def delete(self, key):
2819        """
2820        Remove an item specified by key from the hash table. If there was no such
2821item, this function does nothing.
2822        """
2823        return lib.zhash_delete(self._as_parameter_, key)
2824
2825    def lookup(self, key):
2826        """
2827        Return the item at the specified key, or null
2828        """
2829        return c_void_p(lib.zhash_lookup(self._as_parameter_, key))
2830
2831    def rename(self, old_key, new_key):
2832        """
2833        Reindexes an item from an old key to a new key. If there was no such
2834item, does nothing. Returns 0 if successful, else -1.
2835        """
2836        return lib.zhash_rename(self._as_parameter_, old_key, new_key)
2837
2838    def freefn(self, key, free_fn):
2839        """
2840        Set a free function for the specified hash table item. When the item is
2841destroyed, the free function, if any, is called on that item.
2842Use this when hash items are dynamically allocated, to ensure that
2843you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
2844Returns the item, or NULL if there is no such item.
2845        """
2846        return c_void_p(lib.zhash_freefn(self._as_parameter_, key, free_fn))
2847
2848    def size(self):
2849        """
2850        Return the number of keys/items in the hash table
2851        """
2852        return lib.zhash_size(self._as_parameter_)
2853
2854    def dup(self):
2855        """
2856        Make copy of hash table; if supplied table is null, returns null.
2857Does not copy items themselves. Rebuilds new table so may be slow on
2858very large tables. NOTE: only works with item values that are strings
2859since there's no other way to know how to duplicate the item value.
2860        """
2861        return Zhash(lib.zhash_dup(self._as_parameter_), True)
2862
2863    def keys(self):
2864        """
2865        Return keys for items in table
2866        """
2867        return Zlist(lib.zhash_keys(self._as_parameter_), True)
2868
2869    def first(self):
2870        """
2871        Simple iterator; returns first item in hash table, in no given order,
2872or NULL if the table is empty. This method is simpler to use than the
2873foreach() method, which is deprecated. To access the key for this item
2874use zhash_cursor(). NOTE: do NOT modify the table while iterating.
2875        """
2876        return c_void_p(lib.zhash_first(self._as_parameter_))
2877
2878    def next(self):
2879        """
2880        Simple iterator; returns next item in hash table, in no given order,
2881or NULL if the last item was already returned. Use this together with
2882zhash_first() to process all items in a hash table. If you need the
2883items in sorted order, use zhash_keys() and then zlist_sort(). To
2884access the key for this item use zhash_cursor(). NOTE: do NOT modify
2885the table while iterating.
2886        """
2887        return c_void_p(lib.zhash_next(self._as_parameter_))
2888
2889    def cursor(self):
2890        """
2891        After a successful first/next method, returns the key for the item that
2892was returned. This is a constant string that you may not modify or
2893deallocate, and which lasts as long as the item in the hash. After an
2894unsuccessful first/next, returns NULL.
2895        """
2896        return lib.zhash_cursor(self._as_parameter_)
2897
2898    def comment(self, format, *args):
2899        """
2900        Add a comment to hash table before saving to disk. You can add as many
2901comment lines as you like. These comment lines are discarded when loading
2902the file. If you use a null format, all comments are deleted.
2903        """
2904        return lib.zhash_comment(self._as_parameter_, format, *args)
2905
2906    def pack(self):
2907        """
2908        Serialize hash table to a binary frame that can be sent in a message.
2909The packed format is compatible with the 'dictionary' type defined in
2910http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
2911
2912   ; A list of name/value pairs
2913   dictionary      = dict-count *( dict-name dict-value )
2914   dict-count      = number-4
2915   dict-value      = longstr
2916   dict-name       = string
2917
2918   ; Strings are always length + text contents
2919   longstr         = number-4 *VCHAR
2920   string          = number-1 *VCHAR
2921
2922   ; Numbers are unsigned integers in network byte order
2923   number-1        = 1OCTET
2924   number-4        = 4OCTET
2925
2926Comments are not included in the packed data. Item values MUST be
2927strings.
2928        """
2929        return Zframe(lib.zhash_pack(self._as_parameter_), True)
2930
2931    def save(self, filename):
2932        """
2933        Save hash table to a text file in name=value format. Hash values must be
2934printable strings; keys may not contain '=' character. Returns 0 if OK,
2935else -1 if a file error occurred.
2936        """
2937        return lib.zhash_save(self._as_parameter_, filename)
2938
2939    def load(self, filename):
2940        """
2941        Load hash table from a text file in name=value format; hash table must
2942already exist. Hash values must printable strings; keys may not contain
2943'=' character. Returns 0 if OK, else -1 if a file was not readable.
2944        """
2945        return lib.zhash_load(self._as_parameter_, filename)
2946
2947    def refresh(self):
2948        """
2949        When a hash table was loaded from a file by zhash_load, this method will
2950reload the file if it has been modified since, and is "stable", i.e. not
2951still changing. Returns 0 if OK, -1 if there was an error reloading the
2952file.
2953        """
2954        return lib.zhash_refresh(self._as_parameter_)
2955
2956    def autofree(self):
2957        """
2958        Set hash for automatic value destruction. Note that this assumes that
2959values are NULL-terminated strings. Do not use with different types.
2960        """
2961        return lib.zhash_autofree(self._as_parameter_)
2962
2963    @staticmethod
2964    def test(verbose):
2965        """
2966        Self test of this class.
2967        """
2968        return lib.zhash_test(verbose)
2969
2970
2971# zhashx
2972zhashx_destructor_fn = CFUNCTYPE(None, POINTER(c_void_p))
2973zhashx_duplicator_fn = CFUNCTYPE(c_void_p, c_void_p)
2974zhashx_comparator_fn = CFUNCTYPE(c_int, c_void_p, c_void_p)
2975zhashx_free_fn = CFUNCTYPE(None, c_void_p)
2976zhashx_hash_fn = CFUNCTYPE(c_size_t, c_void_p)
2977zhashx_serializer_fn = CFUNCTYPE(POINTER(c_char), c_void_p)
2978zhashx_deserializer_fn = CFUNCTYPE(c_void_p, c_char_p)
2979lib.zhashx_new.restype = zhashx_p
2980lib.zhashx_new.argtypes = []
2981lib.zhashx_destroy.restype = None
2982lib.zhashx_destroy.argtypes = [POINTER(zhashx_p)]
2983lib.zhashx_unpack.restype = zhashx_p
2984lib.zhashx_unpack.argtypes = [zframe_p]
2985lib.zhashx_unpack_own.restype = zhashx_p
2986lib.zhashx_unpack_own.argtypes = [zframe_p, zhashx_deserializer_fn]
2987lib.zhashx_insert.restype = c_int
2988lib.zhashx_insert.argtypes = [zhashx_p, c_void_p, c_void_p]
2989lib.zhashx_update.restype = None
2990lib.zhashx_update.argtypes = [zhashx_p, c_void_p, c_void_p]
2991lib.zhashx_delete.restype = None
2992lib.zhashx_delete.argtypes = [zhashx_p, c_void_p]
2993lib.zhashx_purge.restype = None
2994lib.zhashx_purge.argtypes = [zhashx_p]
2995lib.zhashx_lookup.restype = c_void_p
2996lib.zhashx_lookup.argtypes = [zhashx_p, c_void_p]
2997lib.zhashx_rename.restype = c_int
2998lib.zhashx_rename.argtypes = [zhashx_p, c_void_p, c_void_p]
2999lib.zhashx_freefn.restype = c_void_p
3000lib.zhashx_freefn.argtypes = [zhashx_p, c_void_p, zhashx_free_fn]
3001lib.zhashx_size.restype = c_size_t
3002lib.zhashx_size.argtypes = [zhashx_p]
3003lib.zhashx_keys.restype = zlistx_p
3004lib.zhashx_keys.argtypes = [zhashx_p]
3005lib.zhashx_values.restype = zlistx_p
3006lib.zhashx_values.argtypes = [zhashx_p]
3007lib.zhashx_first.restype = c_void_p
3008lib.zhashx_first.argtypes = [zhashx_p]
3009lib.zhashx_next.restype = c_void_p
3010lib.zhashx_next.argtypes = [zhashx_p]
3011lib.zhashx_cursor.restype = c_void_p
3012lib.zhashx_cursor.argtypes = [zhashx_p]
3013lib.zhashx_comment.restype = None
3014lib.zhashx_comment.argtypes = [zhashx_p, c_char_p]
3015lib.zhashx_save.restype = c_int
3016lib.zhashx_save.argtypes = [zhashx_p, c_char_p]
3017lib.zhashx_load.restype = c_int
3018lib.zhashx_load.argtypes = [zhashx_p, c_char_p]
3019lib.zhashx_refresh.restype = c_int
3020lib.zhashx_refresh.argtypes = [zhashx_p]
3021lib.zhashx_pack.restype = zframe_p
3022lib.zhashx_pack.argtypes = [zhashx_p]
3023lib.zhashx_pack_own.restype = zframe_p
3024lib.zhashx_pack_own.argtypes = [zhashx_p, zhashx_serializer_fn]
3025lib.zhashx_dup.restype = zhashx_p
3026lib.zhashx_dup.argtypes = [zhashx_p]
3027lib.zhashx_set_destructor.restype = None
3028lib.zhashx_set_destructor.argtypes = [zhashx_p, zhashx_destructor_fn]
3029lib.zhashx_set_duplicator.restype = None
3030lib.zhashx_set_duplicator.argtypes = [zhashx_p, zhashx_duplicator_fn]
3031lib.zhashx_set_key_destructor.restype = None
3032lib.zhashx_set_key_destructor.argtypes = [zhashx_p, zhashx_destructor_fn]
3033lib.zhashx_set_key_duplicator.restype = None
3034lib.zhashx_set_key_duplicator.argtypes = [zhashx_p, zhashx_duplicator_fn]
3035lib.zhashx_set_key_comparator.restype = None
3036lib.zhashx_set_key_comparator.argtypes = [zhashx_p, zhashx_comparator_fn]
3037lib.zhashx_set_key_hasher.restype = None
3038lib.zhashx_set_key_hasher.argtypes = [zhashx_p, zhashx_hash_fn]
3039lib.zhashx_dup_v2.restype = zhashx_p
3040lib.zhashx_dup_v2.argtypes = [zhashx_p]
3041lib.zhashx_test.restype = None
3042lib.zhashx_test.argtypes = [c_bool]
3043
3044class Zhashx(object):
3045    """
3046    extended generic type-free hash container
3047    """
3048
3049    allow_destruct = False
3050    def __init__(self, *args):
3051        """
3052        Create a new, empty hash container
3053        """
3054        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
3055            self._as_parameter_ = cast(args[0], zhashx_p) # Conversion from raw type to binding
3056            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3057        elif len(args) == 2 and type(args[0]) is zhashx_p and isinstance(args[1], bool):
3058            self._as_parameter_ = args[0] # Conversion from raw type to binding
3059            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3060        else:
3061            assert(len(args) == 0)
3062            self._as_parameter_ = lib.zhashx_new() # Creation of new raw type
3063            self.allow_destruct = True
3064
3065    def __del__(self):
3066        """
3067        Destroy a hash container and all items in it
3068        """
3069        if self.allow_destruct:
3070            lib.zhashx_destroy(byref(self._as_parameter_))
3071
3072    def __eq__(self, other):
3073        if type(other) == type(self):
3074            return other.c_address() == self.c_address()
3075        elif type(other) == c_void_p:
3076            return other.value == self.c_address()
3077
3078    def c_address(self):
3079        """
3080        Return the address of the object pointer in c.  Useful for comparison.
3081        """
3082        return addressof(self._as_parameter_.contents)
3083
3084    def __bool__(self):
3085        "Determine whether the object is valid by converting to boolean" # Python 3
3086        return self._as_parameter_.__bool__()
3087
3088    def __nonzero__(self):
3089        "Determine whether the object is valid by converting to boolean" # Python 2
3090        return self._as_parameter_.__nonzero__()
3091
3092    @staticmethod
3093    def unpack(frame):
3094        """
3095        Unpack binary frame into a new hash table. Packed data must follow format
3096defined by zhashx_pack. Hash table is set to autofree. An empty frame
3097unpacks to an empty hash table.
3098        """
3099        return Zhashx(lib.zhashx_unpack(frame), True)
3100
3101    @staticmethod
3102    def unpack_own(frame, deserializer):
3103        """
3104        Same as unpack but uses a user-defined deserializer function to convert
3105a longstr back into item format.
3106        """
3107        return Zhashx(lib.zhashx_unpack_own(frame, deserializer), True)
3108
3109    def insert(self, key, item):
3110        """
3111        Insert item into hash table with specified key and item.
3112If key is already present returns -1 and leaves existing item unchanged
3113Returns 0 on success.
3114        """
3115        return lib.zhashx_insert(self._as_parameter_, key, item)
3116
3117    def update(self, key, item):
3118        """
3119        Update or insert item into hash table with specified key and item. If the
3120key is already present, destroys old item and inserts new one. If you set
3121a container item destructor, this is called on the old value. If the key
3122was not already present, inserts a new item. Sets the hash cursor to the
3123new item.
3124        """
3125        return lib.zhashx_update(self._as_parameter_, key, item)
3126
3127    def delete(self, key):
3128        """
3129        Remove an item specified by key from the hash table. If there was no such
3130item, this function does nothing.
3131        """
3132        return lib.zhashx_delete(self._as_parameter_, key)
3133
3134    def purge(self):
3135        """
3136        Delete all items from the hash table. If the key destructor is
3137set, calls it on every key. If the item destructor is set, calls
3138it on every item.
3139        """
3140        return lib.zhashx_purge(self._as_parameter_)
3141
3142    def lookup(self, key):
3143        """
3144        Return the item at the specified key, or null
3145        """
3146        return c_void_p(lib.zhashx_lookup(self._as_parameter_, key))
3147
3148    def rename(self, old_key, new_key):
3149        """
3150        Reindexes an item from an old key to a new key. If there was no such
3151item, does nothing. Returns 0 if successful, else -1.
3152        """
3153        return lib.zhashx_rename(self._as_parameter_, old_key, new_key)
3154
3155    def freefn(self, key, free_fn):
3156        """
3157        Set a free function for the specified hash table item. When the item is
3158destroyed, the free function, if any, is called on that item.
3159Use this when hash items are dynamically allocated, to ensure that
3160you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3161Returns the item, or NULL if there is no such item.
3162        """
3163        return c_void_p(lib.zhashx_freefn(self._as_parameter_, key, free_fn))
3164
3165    def size(self):
3166        """
3167        Return the number of keys/items in the hash table
3168        """
3169        return lib.zhashx_size(self._as_parameter_)
3170
3171    def keys(self):
3172        """
3173        Return a zlistx_t containing the keys for the items in the
3174table. Uses the key_duplicator to duplicate all keys and sets the
3175key_destructor as destructor for the list.
3176        """
3177        return Zlistx(lib.zhashx_keys(self._as_parameter_), True)
3178
3179    def values(self):
3180        """
3181        Return a zlistx_t containing the values for the items in the
3182table. Uses the duplicator to duplicate all items and sets the
3183destructor as destructor for the list.
3184        """
3185        return Zlistx(lib.zhashx_values(self._as_parameter_), True)
3186
3187    def first(self):
3188        """
3189        Simple iterator; returns first item in hash table, in no given order,
3190or NULL if the table is empty. This method is simpler to use than the
3191foreach() method, which is deprecated. To access the key for this item
3192use zhashx_cursor(). NOTE: do NOT modify the table while iterating.
3193        """
3194        return c_void_p(lib.zhashx_first(self._as_parameter_))
3195
3196    def next(self):
3197        """
3198        Simple iterator; returns next item in hash table, in no given order,
3199or NULL if the last item was already returned. Use this together with
3200zhashx_first() to process all items in a hash table. If you need the
3201items in sorted order, use zhashx_keys() and then zlistx_sort(). To
3202access the key for this item use zhashx_cursor(). NOTE: do NOT modify
3203the table while iterating.
3204        """
3205        return c_void_p(lib.zhashx_next(self._as_parameter_))
3206
3207    def cursor(self):
3208        """
3209        After a successful first/next method, returns the key for the item that
3210was returned. This is a constant string that you may not modify or
3211deallocate, and which lasts as long as the item in the hash. After an
3212unsuccessful first/next, returns NULL.
3213        """
3214        return c_void_p(lib.zhashx_cursor(self._as_parameter_))
3215
3216    def comment(self, format, *args):
3217        """
3218        Add a comment to hash table before saving to disk. You can add as many
3219comment lines as you like. These comment lines are discarded when loading
3220the file. If you use a null format, all comments are deleted.
3221        """
3222        return lib.zhashx_comment(self._as_parameter_, format, *args)
3223
3224    def save(self, filename):
3225        """
3226        Save hash table to a text file in name=value format. Hash values must be
3227printable strings; keys may not contain '=' character. Returns 0 if OK,
3228else -1 if a file error occurred.
3229        """
3230        return lib.zhashx_save(self._as_parameter_, filename)
3231
3232    def load(self, filename):
3233        """
3234        Load hash table from a text file in name=value format; hash table must
3235already exist. Hash values must printable strings; keys may not contain
3236'=' character. Returns 0 if OK, else -1 if a file was not readable.
3237        """
3238        return lib.zhashx_load(self._as_parameter_, filename)
3239
3240    def refresh(self):
3241        """
3242        When a hash table was loaded from a file by zhashx_load, this method will
3243reload the file if it has been modified since, and is "stable", i.e. not
3244still changing. Returns 0 if OK, -1 if there was an error reloading the
3245file.
3246        """
3247        return lib.zhashx_refresh(self._as_parameter_)
3248
3249    def pack(self):
3250        """
3251        Serialize hash table to a binary frame that can be sent in a message.
3252The packed format is compatible with the 'dictionary' type defined in
3253http://rfc.zeromq.org/spec:35/FILEMQ, and implemented by zproto:
3254
3255   ; A list of name/value pairs
3256   dictionary      = dict-count *( dict-name dict-value )
3257   dict-count      = number-4
3258   dict-value      = longstr
3259   dict-name       = string
3260
3261   ; Strings are always length + text contents
3262   longstr         = number-4 *VCHAR
3263   string          = number-1 *VCHAR
3264
3265   ; Numbers are unsigned integers in network byte order
3266   number-1        = 1OCTET
3267   number-4        = 4OCTET
3268
3269Comments are not included in the packed data. Item values MUST be
3270strings.
3271        """
3272        return Zframe(lib.zhashx_pack(self._as_parameter_), True)
3273
3274    def pack_own(self, serializer):
3275        """
3276        Same as pack but uses a user-defined serializer function to convert items
3277into longstr.
3278        """
3279        return Zframe(lib.zhashx_pack_own(self._as_parameter_, serializer), True)
3280
3281    def dup(self):
3282        """
3283        Make a copy of the list; items are duplicated if you set a duplicator
3284for the list, otherwise not. Copying a null reference returns a null
3285reference. Note that this method's behavior changed slightly for CZMQ
3286v3.x, as it does not set nor respect autofree. It does however let you
3287duplicate any hash table safely. The old behavior is in zhashx_dup_v2.
3288        """
3289        return Zhashx(lib.zhashx_dup(self._as_parameter_), True)
3290
3291    def set_destructor(self, destructor):
3292        """
3293        Set a user-defined deallocator for hash items; by default items are not
3294freed when the hash is destroyed.
3295        """
3296        return lib.zhashx_set_destructor(self._as_parameter_, destructor)
3297
3298    def set_duplicator(self, duplicator):
3299        """
3300        Set a user-defined duplicator for hash items; by default items are not
3301copied when the hash is duplicated.
3302        """
3303        return lib.zhashx_set_duplicator(self._as_parameter_, duplicator)
3304
3305    def set_key_destructor(self, destructor):
3306        """
3307        Set a user-defined deallocator for keys; by default keys are freed
3308when the hash is destroyed using free().
3309        """
3310        return lib.zhashx_set_key_destructor(self._as_parameter_, destructor)
3311
3312    def set_key_duplicator(self, duplicator):
3313        """
3314        Set a user-defined duplicator for keys; by default keys are duplicated
3315using strdup.
3316        """
3317        return lib.zhashx_set_key_duplicator(self._as_parameter_, duplicator)
3318
3319    def set_key_comparator(self, comparator):
3320        """
3321        Set a user-defined comparator for keys; by default keys are
3322compared using strcmp.
3323The callback function should return zero (0) on matching
3324items.
3325        """
3326        return lib.zhashx_set_key_comparator(self._as_parameter_, comparator)
3327
3328    def set_key_hasher(self, hasher):
3329        """
3330        Set a user-defined hash function for keys; by default keys are
3331hashed by a modified Bernstein hashing function.
3332        """
3333        return lib.zhashx_set_key_hasher(self._as_parameter_, hasher)
3334
3335    def dup_v2(self):
3336        """
3337        Make copy of hash table; if supplied table is null, returns null.
3338Does not copy items themselves. Rebuilds new table so may be slow on
3339very large tables. NOTE: only works with item values that are strings
3340since there's no other way to know how to duplicate the item value.
3341        """
3342        return Zhashx(lib.zhashx_dup_v2(self._as_parameter_), False)
3343
3344    @staticmethod
3345    def test(verbose):
3346        """
3347        Self test of this class.
3348        """
3349        return lib.zhashx_test(verbose)
3350
3351
3352# ziflist
3353lib.ziflist_new.restype = ziflist_p
3354lib.ziflist_new.argtypes = []
3355lib.ziflist_destroy.restype = None
3356lib.ziflist_destroy.argtypes = [POINTER(ziflist_p)]
3357lib.ziflist_reload.restype = None
3358lib.ziflist_reload.argtypes = [ziflist_p]
3359lib.ziflist_size.restype = c_size_t
3360lib.ziflist_size.argtypes = [ziflist_p]
3361lib.ziflist_first.restype = c_char_p
3362lib.ziflist_first.argtypes = [ziflist_p]
3363lib.ziflist_next.restype = c_char_p
3364lib.ziflist_next.argtypes = [ziflist_p]
3365lib.ziflist_address.restype = c_char_p
3366lib.ziflist_address.argtypes = [ziflist_p]
3367lib.ziflist_broadcast.restype = c_char_p
3368lib.ziflist_broadcast.argtypes = [ziflist_p]
3369lib.ziflist_netmask.restype = c_char_p
3370lib.ziflist_netmask.argtypes = [ziflist_p]
3371lib.ziflist_print.restype = None
3372lib.ziflist_print.argtypes = [ziflist_p]
3373lib.ziflist_new_ipv6.restype = ziflist_p
3374lib.ziflist_new_ipv6.argtypes = []
3375lib.ziflist_reload_ipv6.restype = None
3376lib.ziflist_reload_ipv6.argtypes = [ziflist_p]
3377lib.ziflist_is_ipv6.restype = c_bool
3378lib.ziflist_is_ipv6.argtypes = [ziflist_p]
3379lib.ziflist_test.restype = None
3380lib.ziflist_test.argtypes = [c_bool]
3381
3382class Ziflist(object):
3383    """
3384    List of network interfaces available on system
3385    """
3386
3387    allow_destruct = False
3388    def __init__(self, *args):
3389        """
3390        Get a list of network interfaces currently defined on the system
3391        """
3392        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
3393            self._as_parameter_ = cast(args[0], ziflist_p) # Conversion from raw type to binding
3394            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3395        elif len(args) == 2 and type(args[0]) is ziflist_p and isinstance(args[1], bool):
3396            self._as_parameter_ = args[0] # Conversion from raw type to binding
3397            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3398        else:
3399            assert(len(args) == 0)
3400            self._as_parameter_ = lib.ziflist_new() # Creation of new raw type
3401            self.allow_destruct = True
3402
3403    def __del__(self):
3404        """
3405        Destroy a ziflist instance
3406        """
3407        if self.allow_destruct:
3408            lib.ziflist_destroy(byref(self._as_parameter_))
3409
3410    def __eq__(self, other):
3411        if type(other) == type(self):
3412            return other.c_address() == self.c_address()
3413        elif type(other) == c_void_p:
3414            return other.value == self.c_address()
3415
3416    def c_address(self):
3417        """
3418        Return the address of the object pointer in c.  Useful for comparison.
3419        """
3420        return addressof(self._as_parameter_.contents)
3421
3422    def __bool__(self):
3423        "Determine whether the object is valid by converting to boolean" # Python 3
3424        return self._as_parameter_.__bool__()
3425
3426    def __nonzero__(self):
3427        "Determine whether the object is valid by converting to boolean" # Python 2
3428        return self._as_parameter_.__nonzero__()
3429
3430    def reload(self):
3431        """
3432        Reload network interfaces from system
3433        """
3434        return lib.ziflist_reload(self._as_parameter_)
3435
3436    def size(self):
3437        """
3438        Return the number of network interfaces on system
3439        """
3440        return lib.ziflist_size(self._as_parameter_)
3441
3442    def first(self):
3443        """
3444        Get first network interface, return NULL if there are none
3445        """
3446        return lib.ziflist_first(self._as_parameter_)
3447
3448    def next(self):
3449        """
3450        Get next network interface, return NULL if we hit the last one
3451        """
3452        return lib.ziflist_next(self._as_parameter_)
3453
3454    def address(self):
3455        """
3456        Return the current interface IP address as a printable string
3457        """
3458        return lib.ziflist_address(self._as_parameter_)
3459
3460    def broadcast(self):
3461        """
3462        Return the current interface broadcast address as a printable string
3463        """
3464        return lib.ziflist_broadcast(self._as_parameter_)
3465
3466    def netmask(self):
3467        """
3468        Return the current interface network mask as a printable string
3469        """
3470        return lib.ziflist_netmask(self._as_parameter_)
3471
3472    def print(self):
3473        """
3474        Return the list of interfaces.
3475        """
3476        return lib.ziflist_print(self._as_parameter_)
3477
3478    @staticmethod
3479    def new_ipv6():
3480        """
3481        Get a list of network interfaces currently defined on the system
3482Includes IPv6 interfaces
3483        """
3484        return Ziflist(lib.ziflist_new_ipv6(), True)
3485
3486    def reload_ipv6(self):
3487        """
3488        Reload network interfaces from system, including IPv6
3489        """
3490        return lib.ziflist_reload_ipv6(self._as_parameter_)
3491
3492    def is_ipv6(self):
3493        """
3494        Return true if the current interface uses IPv6
3495        """
3496        return lib.ziflist_is_ipv6(self._as_parameter_)
3497
3498    @staticmethod
3499    def test(verbose):
3500        """
3501        Self test of this class.
3502        """
3503        return lib.ziflist_test(verbose)
3504
3505
3506# zlist
3507zlist_compare_fn = CFUNCTYPE(c_int, c_void_p, c_void_p)
3508zlist_free_fn = CFUNCTYPE(None, c_void_p)
3509lib.zlist_new.restype = zlist_p
3510lib.zlist_new.argtypes = []
3511lib.zlist_destroy.restype = None
3512lib.zlist_destroy.argtypes = [POINTER(zlist_p)]
3513lib.zlist_first.restype = c_void_p
3514lib.zlist_first.argtypes = [zlist_p]
3515lib.zlist_next.restype = c_void_p
3516lib.zlist_next.argtypes = [zlist_p]
3517lib.zlist_last.restype = c_void_p
3518lib.zlist_last.argtypes = [zlist_p]
3519lib.zlist_head.restype = c_void_p
3520lib.zlist_head.argtypes = [zlist_p]
3521lib.zlist_tail.restype = c_void_p
3522lib.zlist_tail.argtypes = [zlist_p]
3523lib.zlist_item.restype = c_void_p
3524lib.zlist_item.argtypes = [zlist_p]
3525lib.zlist_append.restype = c_int
3526lib.zlist_append.argtypes = [zlist_p, c_void_p]
3527lib.zlist_push.restype = c_int
3528lib.zlist_push.argtypes = [zlist_p, c_void_p]
3529lib.zlist_pop.restype = c_void_p
3530lib.zlist_pop.argtypes = [zlist_p]
3531lib.zlist_exists.restype = c_bool
3532lib.zlist_exists.argtypes = [zlist_p, c_void_p]
3533lib.zlist_remove.restype = None
3534lib.zlist_remove.argtypes = [zlist_p, c_void_p]
3535lib.zlist_dup.restype = zlist_p
3536lib.zlist_dup.argtypes = [zlist_p]
3537lib.zlist_purge.restype = None
3538lib.zlist_purge.argtypes = [zlist_p]
3539lib.zlist_size.restype = c_size_t
3540lib.zlist_size.argtypes = [zlist_p]
3541lib.zlist_sort.restype = None
3542lib.zlist_sort.argtypes = [zlist_p, zlist_compare_fn]
3543lib.zlist_autofree.restype = None
3544lib.zlist_autofree.argtypes = [zlist_p]
3545lib.zlist_comparefn.restype = None
3546lib.zlist_comparefn.argtypes = [zlist_p, zlist_compare_fn]
3547lib.zlist_freefn.restype = c_void_p
3548lib.zlist_freefn.argtypes = [zlist_p, c_void_p, zlist_free_fn, c_bool]
3549lib.zlist_test.restype = None
3550lib.zlist_test.argtypes = [c_bool]
3551
3552class Zlist(object):
3553    """
3554    simple generic list container
3555    """
3556
3557    allow_destruct = False
3558    def __init__(self, *args):
3559        """
3560        Create a new list container
3561        """
3562        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
3563            self._as_parameter_ = cast(args[0], zlist_p) # Conversion from raw type to binding
3564            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3565        elif len(args) == 2 and type(args[0]) is zlist_p and isinstance(args[1], bool):
3566            self._as_parameter_ = args[0] # Conversion from raw type to binding
3567            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3568        else:
3569            assert(len(args) == 0)
3570            self._as_parameter_ = lib.zlist_new() # Creation of new raw type
3571            self.allow_destruct = True
3572
3573    def __del__(self):
3574        """
3575        Destroy a list container
3576        """
3577        if self.allow_destruct:
3578            lib.zlist_destroy(byref(self._as_parameter_))
3579
3580    def __eq__(self, other):
3581        if type(other) == type(self):
3582            return other.c_address() == self.c_address()
3583        elif type(other) == c_void_p:
3584            return other.value == self.c_address()
3585
3586    def c_address(self):
3587        """
3588        Return the address of the object pointer in c.  Useful for comparison.
3589        """
3590        return addressof(self._as_parameter_.contents)
3591
3592    def __bool__(self):
3593        "Determine whether the object is valid by converting to boolean" # Python 3
3594        return self._as_parameter_.__bool__()
3595
3596    def __nonzero__(self):
3597        "Determine whether the object is valid by converting to boolean" # Python 2
3598        return self._as_parameter_.__nonzero__()
3599
3600    def first(self):
3601        """
3602        Return the item at the head of list. If the list is empty, returns NULL.
3603Leaves cursor pointing at the head item, or NULL if the list is empty.
3604        """
3605        return c_void_p(lib.zlist_first(self._as_parameter_))
3606
3607    def next(self):
3608        """
3609        Return the next item. If the list is empty, returns NULL. To move to
3610the start of the list call zlist_first (). Advances the cursor.
3611        """
3612        return c_void_p(lib.zlist_next(self._as_parameter_))
3613
3614    def last(self):
3615        """
3616        Return the item at the tail of list. If the list is empty, returns NULL.
3617Leaves cursor pointing at the tail item, or NULL if the list is empty.
3618        """
3619        return c_void_p(lib.zlist_last(self._as_parameter_))
3620
3621    def head(self):
3622        """
3623        Return first item in the list, or null, leaves the cursor
3624        """
3625        return c_void_p(lib.zlist_head(self._as_parameter_))
3626
3627    def tail(self):
3628        """
3629        Return last item in the list, or null, leaves the cursor
3630        """
3631        return c_void_p(lib.zlist_tail(self._as_parameter_))
3632
3633    def item(self):
3634        """
3635        Return the current item of list. If the list is empty, returns NULL.
3636Leaves cursor pointing at the current item, or NULL if the list is empty.
3637        """
3638        return c_void_p(lib.zlist_item(self._as_parameter_))
3639
3640    def append(self, item):
3641        """
3642        Append an item to the end of the list, return 0 if OK or -1 if this
3643failed for some reason (out of memory). Note that if a duplicator has
3644been set, this method will also duplicate the item.
3645        """
3646        return lib.zlist_append(self._as_parameter_, item)
3647
3648    def push(self, item):
3649        """
3650        Push an item to the start of the list, return 0 if OK or -1 if this
3651failed for some reason (out of memory). Note that if a duplicator has
3652been set, this method will also duplicate the item.
3653        """
3654        return lib.zlist_push(self._as_parameter_, item)
3655
3656    def pop(self):
3657        """
3658        Pop the item off the start of the list, if any
3659        """
3660        return c_void_p(lib.zlist_pop(self._as_parameter_))
3661
3662    def exists(self, item):
3663        """
3664        Checks if an item already is present. Uses compare method to determine if
3665items are equal. If the compare method is NULL the check will only compare
3666pointers. Returns true if item is present else false.
3667        """
3668        return lib.zlist_exists(self._as_parameter_, item)
3669
3670    def remove(self, item):
3671        """
3672        Remove the specified item from the list if present
3673        """
3674        return lib.zlist_remove(self._as_parameter_, item)
3675
3676    def dup(self):
3677        """
3678        Make a copy of list. If the list has autofree set, the copied list will
3679duplicate all items, which must be strings. Otherwise, the list will hold
3680pointers back to the items in the original list. If list is null, returns
3681NULL.
3682        """
3683        return Zlist(lib.zlist_dup(self._as_parameter_), True)
3684
3685    def purge(self):
3686        """
3687        Purge all items from list
3688        """
3689        return lib.zlist_purge(self._as_parameter_)
3690
3691    def size(self):
3692        """
3693        Return number of items in the list
3694        """
3695        return lib.zlist_size(self._as_parameter_)
3696
3697    def sort(self, compare):
3698        """
3699        Sort the list. If the compare function is null, sorts the list by
3700ascending key value using a straight ASCII comparison. If you specify
3701a compare function, this decides how items are sorted. The sort is not
3702stable, so may reorder items with the same keys. The algorithm used is
3703combsort, a compromise between performance and simplicity.
3704        """
3705        return lib.zlist_sort(self._as_parameter_, compare)
3706
3707    def autofree(self):
3708        """
3709        Set list for automatic item destruction; item values MUST be strings.
3710By default a list item refers to a value held elsewhere. When you set
3711this, each time you append or push a list item, zlist will take a copy
3712of the string value. Then, when you destroy the list, it will free all
3713item values automatically. If you use any other technique to allocate
3714list values, you must free them explicitly before destroying the list.
3715The usual technique is to pop list items and destroy them, until the
3716list is empty.
3717        """
3718        return lib.zlist_autofree(self._as_parameter_)
3719
3720    def comparefn(self, fn):
3721        """
3722        Sets a compare function for this list. The function compares two items.
3723It returns an integer less than, equal to, or greater than zero if the
3724first item is found, respectively, to be less than, to match, or be
3725greater than the second item.
3726This function is used for sorting, removal and exists checking.
3727        """
3728        return lib.zlist_comparefn(self._as_parameter_, fn)
3729
3730    def freefn(self, item, fn, at_tail):
3731        """
3732        Set a free function for the specified list item. When the item is
3733destroyed, the free function, if any, is called on that item.
3734Use this when list items are dynamically allocated, to ensure that
3735you don't have memory leaks. You can pass 'free' or NULL as a free_fn.
3736Returns the item, or NULL if there is no such item.
3737        """
3738        return c_void_p(lib.zlist_freefn(self._as_parameter_, item, fn, at_tail))
3739
3740    @staticmethod
3741    def test(verbose):
3742        """
3743        Self test of this class.
3744        """
3745        return lib.zlist_test(verbose)
3746
3747
3748# zlistx
3749zlistx_destructor_fn = CFUNCTYPE(None, POINTER(c_void_p))
3750zlistx_duplicator_fn = CFUNCTYPE(c_void_p, c_void_p)
3751zlistx_comparator_fn = CFUNCTYPE(c_int, c_void_p, c_void_p)
3752lib.zlistx_new.restype = zlistx_p
3753lib.zlistx_new.argtypes = []
3754lib.zlistx_destroy.restype = None
3755lib.zlistx_destroy.argtypes = [POINTER(zlistx_p)]
3756lib.zlistx_add_start.restype = c_void_p
3757lib.zlistx_add_start.argtypes = [zlistx_p, c_void_p]
3758lib.zlistx_add_end.restype = c_void_p
3759lib.zlistx_add_end.argtypes = [zlistx_p, c_void_p]
3760lib.zlistx_size.restype = c_size_t
3761lib.zlistx_size.argtypes = [zlistx_p]
3762lib.zlistx_head.restype = c_void_p
3763lib.zlistx_head.argtypes = [zlistx_p]
3764lib.zlistx_tail.restype = c_void_p
3765lib.zlistx_tail.argtypes = [zlistx_p]
3766lib.zlistx_first.restype = c_void_p
3767lib.zlistx_first.argtypes = [zlistx_p]
3768lib.zlistx_next.restype = c_void_p
3769lib.zlistx_next.argtypes = [zlistx_p]
3770lib.zlistx_prev.restype = c_void_p
3771lib.zlistx_prev.argtypes = [zlistx_p]
3772lib.zlistx_last.restype = c_void_p
3773lib.zlistx_last.argtypes = [zlistx_p]
3774lib.zlistx_item.restype = c_void_p
3775lib.zlistx_item.argtypes = [zlistx_p]
3776lib.zlistx_cursor.restype = c_void_p
3777lib.zlistx_cursor.argtypes = [zlistx_p]
3778lib.zlistx_handle_item.restype = c_void_p
3779lib.zlistx_handle_item.argtypes = [c_void_p]
3780lib.zlistx_find.restype = c_void_p
3781lib.zlistx_find.argtypes = [zlistx_p, c_void_p]
3782lib.zlistx_detach.restype = c_void_p
3783lib.zlistx_detach.argtypes = [zlistx_p, c_void_p]
3784lib.zlistx_detach_cur.restype = c_void_p
3785lib.zlistx_detach_cur.argtypes = [zlistx_p]
3786lib.zlistx_delete.restype = c_int
3787lib.zlistx_delete.argtypes = [zlistx_p, c_void_p]
3788lib.zlistx_move_start.restype = None
3789lib.zlistx_move_start.argtypes = [zlistx_p, c_void_p]
3790lib.zlistx_move_end.restype = None
3791lib.zlistx_move_end.argtypes = [zlistx_p, c_void_p]
3792lib.zlistx_purge.restype = None
3793lib.zlistx_purge.argtypes = [zlistx_p]
3794lib.zlistx_sort.restype = None
3795lib.zlistx_sort.argtypes = [zlistx_p]
3796lib.zlistx_insert.restype = c_void_p
3797lib.zlistx_insert.argtypes = [zlistx_p, c_void_p, c_bool]
3798lib.zlistx_reorder.restype = None
3799lib.zlistx_reorder.argtypes = [zlistx_p, c_void_p, c_bool]
3800lib.zlistx_dup.restype = zlistx_p
3801lib.zlistx_dup.argtypes = [zlistx_p]
3802lib.zlistx_set_destructor.restype = None
3803lib.zlistx_set_destructor.argtypes = [zlistx_p, zlistx_destructor_fn]
3804lib.zlistx_set_duplicator.restype = None
3805lib.zlistx_set_duplicator.argtypes = [zlistx_p, zlistx_duplicator_fn]
3806lib.zlistx_set_comparator.restype = None
3807lib.zlistx_set_comparator.argtypes = [zlistx_p, zlistx_comparator_fn]
3808lib.zlistx_test.restype = None
3809lib.zlistx_test.argtypes = [c_bool]
3810
3811class Zlistx(object):
3812    """
3813    extended generic list container
3814    """
3815
3816    allow_destruct = False
3817    def __init__(self, *args):
3818        """
3819        Create a new, empty list.
3820        """
3821        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
3822            self._as_parameter_ = cast(args[0], zlistx_p) # Conversion from raw type to binding
3823            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3824        elif len(args) == 2 and type(args[0]) is zlistx_p and isinstance(args[1], bool):
3825            self._as_parameter_ = args[0] # Conversion from raw type to binding
3826            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
3827        else:
3828            assert(len(args) == 0)
3829            self._as_parameter_ = lib.zlistx_new() # Creation of new raw type
3830            self.allow_destruct = True
3831
3832    def __del__(self):
3833        """
3834        Destroy a list. If an item destructor was specified, all items in the
3835list are automatically destroyed as well.
3836        """
3837        if self.allow_destruct:
3838            lib.zlistx_destroy(byref(self._as_parameter_))
3839
3840    def __eq__(self, other):
3841        if type(other) == type(self):
3842            return other.c_address() == self.c_address()
3843        elif type(other) == c_void_p:
3844            return other.value == self.c_address()
3845
3846    def c_address(self):
3847        """
3848        Return the address of the object pointer in c.  Useful for comparison.
3849        """
3850        return addressof(self._as_parameter_.contents)
3851
3852    def __bool__(self):
3853        "Determine whether the object is valid by converting to boolean" # Python 3
3854        return self._as_parameter_.__bool__()
3855
3856    def __nonzero__(self):
3857        "Determine whether the object is valid by converting to boolean" # Python 2
3858        return self._as_parameter_.__nonzero__()
3859
3860    def add_start(self, item):
3861        """
3862        Add an item to the head of the list. Calls the item duplicator, if any,
3863on the item. Resets cursor to list head. Returns an item handle on
3864success, NULL if memory was exhausted.
3865        """
3866        return c_void_p(lib.zlistx_add_start(self._as_parameter_, item))
3867
3868    def add_end(self, item):
3869        """
3870        Add an item to the tail of the list. Calls the item duplicator, if any,
3871on the item. Resets cursor to list head. Returns an item handle on
3872success, NULL if memory was exhausted.
3873        """
3874        return c_void_p(lib.zlistx_add_end(self._as_parameter_, item))
3875
3876    def size(self):
3877        """
3878        Return the number of items in the list
3879        """
3880        return lib.zlistx_size(self._as_parameter_)
3881
3882    def head(self):
3883        """
3884        Return first item in the list, or null, leaves the cursor
3885        """
3886        return c_void_p(lib.zlistx_head(self._as_parameter_))
3887
3888    def tail(self):
3889        """
3890        Return last item in the list, or null, leaves the cursor
3891        """
3892        return c_void_p(lib.zlistx_tail(self._as_parameter_))
3893
3894    def first(self):
3895        """
3896        Return the item at the head of list. If the list is empty, returns NULL.
3897Leaves cursor pointing at the head item, or NULL if the list is empty.
3898        """
3899        return c_void_p(lib.zlistx_first(self._as_parameter_))
3900
3901    def next(self):
3902        """
3903        Return the next item. At the end of the list (or in an empty list),
3904returns NULL. Use repeated zlistx_next () calls to work through the list
3905from zlistx_first (). First time, acts as zlistx_first().
3906        """
3907        return c_void_p(lib.zlistx_next(self._as_parameter_))
3908
3909    def prev(self):
3910        """
3911        Return the previous item. At the start of the list (or in an empty list),
3912returns NULL. Use repeated zlistx_prev () calls to work through the list
3913backwards from zlistx_last (). First time, acts as zlistx_last().
3914        """
3915        return c_void_p(lib.zlistx_prev(self._as_parameter_))
3916
3917    def last(self):
3918        """
3919        Return the item at the tail of list. If the list is empty, returns NULL.
3920Leaves cursor pointing at the tail item, or NULL if the list is empty.
3921        """
3922        return c_void_p(lib.zlistx_last(self._as_parameter_))
3923
3924    def item(self):
3925        """
3926        Returns the value of the item at the cursor, or NULL if the cursor is
3927not pointing to an item.
3928        """
3929        return c_void_p(lib.zlistx_item(self._as_parameter_))
3930
3931    def cursor(self):
3932        """
3933        Returns the handle of the item at the cursor, or NULL if the cursor is
3934not pointing to an item.
3935        """
3936        return c_void_p(lib.zlistx_cursor(self._as_parameter_))
3937
3938    @staticmethod
3939    def handle_item(handle):
3940        """
3941        Returns the item associated with the given list handle, or NULL if passed
3942in handle is NULL. Asserts that the passed in handle points to a list element.
3943        """
3944        return c_void_p(lib.zlistx_handle_item(handle))
3945
3946    def find(self, item):
3947        """
3948        Find an item in the list, searching from the start. Uses the item
3949comparator, if any, else compares item values directly. Returns the
3950item handle found, or NULL. Sets the cursor to the found item, if any.
3951        """
3952        return c_void_p(lib.zlistx_find(self._as_parameter_, item))
3953
3954    def detach(self, handle):
3955        """
3956        Detach an item from the list, using its handle. The item is not modified,
3957and the caller is responsible for destroying it if necessary. If handle is
3958null, detaches the first item on the list. Returns item that was detached,
3959or null if none was. If cursor was at item, moves cursor to previous item,
3960so you can detach items while iterating forwards through a list.
3961        """
3962        return c_void_p(lib.zlistx_detach(self._as_parameter_, handle))
3963
3964    def detach_cur(self):
3965        """
3966        Detach item at the cursor, if any, from the list. The item is not modified,
3967and the caller is responsible for destroying it as necessary. Returns item
3968that was detached, or null if none was. Moves cursor to previous item, so
3969you can detach items while iterating forwards through a list.
3970        """
3971        return c_void_p(lib.zlistx_detach_cur(self._as_parameter_))
3972
3973    def delete(self, handle):
3974        """
3975        Delete an item, using its handle. Calls the item destructor is any is
3976set. If handle is null, deletes the first item on the list. Returns 0
3977if an item was deleted, -1 if not. If cursor was at item, moves cursor
3978to previous item, so you can delete items while iterating forwards
3979through a list.
3980        """
3981        return lib.zlistx_delete(self._as_parameter_, handle)
3982
3983    def move_start(self, handle):
3984        """
3985        Move an item to the start of the list, via its handle.
3986        """
3987        return lib.zlistx_move_start(self._as_parameter_, handle)
3988
3989    def move_end(self, handle):
3990        """
3991        Move an item to the end of the list, via its handle.
3992        """
3993        return lib.zlistx_move_end(self._as_parameter_, handle)
3994
3995    def purge(self):
3996        """
3997        Remove all items from the list, and destroy them if the item destructor
3998is set.
3999        """
4000        return lib.zlistx_purge(self._as_parameter_)
4001
4002    def sort(self):
4003        """
4004        Sort the list. If an item comparator was set, calls that to compare
4005items, otherwise compares on item value. The sort is not stable, so may
4006reorder equal items.
4007        """
4008        return lib.zlistx_sort(self._as_parameter_)
4009
4010    def insert(self, item, low_value):
4011        """
4012        Create a new node and insert it into a sorted list. Calls the item
4013duplicator, if any, on the item. If low_value is true, starts searching
4014from the start of the list, otherwise searches from the end. Use the item
4015comparator, if any, to find where to place the new node. Returns a handle
4016to the new node, or NULL if memory was exhausted. Resets the cursor to the
4017list head.
4018        """
4019        return c_void_p(lib.zlistx_insert(self._as_parameter_, item, low_value))
4020
4021    def reorder(self, handle, low_value):
4022        """
4023        Move an item, specified by handle, into position in a sorted list. Uses
4024the item comparator, if any, to determine the new location. If low_value
4025is true, starts searching from the start of the list, otherwise searches
4026from the end.
4027        """
4028        return lib.zlistx_reorder(self._as_parameter_, handle, low_value)
4029
4030    def dup(self):
4031        """
4032        Make a copy of the list; items are duplicated if you set a duplicator
4033for the list, otherwise not. Copying a null reference returns a null
4034reference.
4035        """
4036        return Zlistx(lib.zlistx_dup(self._as_parameter_), False)
4037
4038    def set_destructor(self, destructor):
4039        """
4040        Set a user-defined deallocator for list items; by default items are not
4041freed when the list is destroyed.
4042        """
4043        return lib.zlistx_set_destructor(self._as_parameter_, destructor)
4044
4045    def set_duplicator(self, duplicator):
4046        """
4047        Set a user-defined duplicator for list items; by default items are not
4048copied when the list is duplicated.
4049        """
4050        return lib.zlistx_set_duplicator(self._as_parameter_, duplicator)
4051
4052    def set_comparator(self, comparator):
4053        """
4054        Set a user-defined comparator for zlistx_find and zlistx_sort; the method
4055must return -1, 0, or 1 depending on whether item1 is less than, equal to,
4056or greater than, item2.
4057        """
4058        return lib.zlistx_set_comparator(self._as_parameter_, comparator)
4059
4060    @staticmethod
4061    def test(verbose):
4062        """
4063        Self test of this class.
4064        """
4065        return lib.zlistx_test(verbose)
4066
4067
4068# zloop
4069zloop_reader_fn = CFUNCTYPE(c_int, zloop_p, zsock_p, c_void_p)
4070zloop_fn = CFUNCTYPE(c_int, zloop_p, zmq_pollitem_p, c_void_p)
4071zloop_timer_fn = CFUNCTYPE(c_int, zloop_p, c_int, c_void_p)
4072lib.zloop_new.restype = zloop_p
4073lib.zloop_new.argtypes = []
4074lib.zloop_destroy.restype = None
4075lib.zloop_destroy.argtypes = [POINTER(zloop_p)]
4076lib.zloop_reader.restype = c_int
4077lib.zloop_reader.argtypes = [zloop_p, zsock_p, zloop_reader_fn, c_void_p]
4078lib.zloop_reader_end.restype = None
4079lib.zloop_reader_end.argtypes = [zloop_p, zsock_p]
4080lib.zloop_reader_set_tolerant.restype = None
4081lib.zloop_reader_set_tolerant.argtypes = [zloop_p, zsock_p]
4082lib.zloop_poller.restype = c_int
4083lib.zloop_poller.argtypes = [zloop_p, zmq_pollitem_p, zloop_fn, c_void_p]
4084lib.zloop_poller_end.restype = None
4085lib.zloop_poller_end.argtypes = [zloop_p, zmq_pollitem_p]
4086lib.zloop_poller_set_tolerant.restype = None
4087lib.zloop_poller_set_tolerant.argtypes = [zloop_p, zmq_pollitem_p]
4088lib.zloop_timer.restype = c_int
4089lib.zloop_timer.argtypes = [zloop_p, c_size_t, c_size_t, zloop_timer_fn, c_void_p]
4090lib.zloop_timer_end.restype = c_int
4091lib.zloop_timer_end.argtypes = [zloop_p, c_int]
4092lib.zloop_ticket.restype = c_void_p
4093lib.zloop_ticket.argtypes = [zloop_p, zloop_timer_fn, c_void_p]
4094lib.zloop_ticket_reset.restype = None
4095lib.zloop_ticket_reset.argtypes = [zloop_p, c_void_p]
4096lib.zloop_ticket_delete.restype = None
4097lib.zloop_ticket_delete.argtypes = [zloop_p, c_void_p]
4098lib.zloop_set_ticket_delay.restype = None
4099lib.zloop_set_ticket_delay.argtypes = [zloop_p, c_size_t]
4100lib.zloop_set_max_timers.restype = None
4101lib.zloop_set_max_timers.argtypes = [zloop_p, c_size_t]
4102lib.zloop_set_verbose.restype = None
4103lib.zloop_set_verbose.argtypes = [zloop_p, c_bool]
4104lib.zloop_set_nonstop.restype = None
4105lib.zloop_set_nonstop.argtypes = [zloop_p, c_bool]
4106lib.zloop_start.restype = c_int
4107lib.zloop_start.argtypes = [zloop_p]
4108lib.zloop_test.restype = None
4109lib.zloop_test.argtypes = [c_bool]
4110
4111class Zloop(object):
4112    """
4113    event-driven reactor
4114    """
4115
4116    allow_destruct = False
4117    def __init__(self, *args):
4118        """
4119        Create a new zloop reactor
4120        """
4121        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
4122            self._as_parameter_ = cast(args[0], zloop_p) # Conversion from raw type to binding
4123            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4124        elif len(args) == 2 and type(args[0]) is zloop_p and isinstance(args[1], bool):
4125            self._as_parameter_ = args[0] # Conversion from raw type to binding
4126            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4127        else:
4128            assert(len(args) == 0)
4129            self._as_parameter_ = lib.zloop_new() # Creation of new raw type
4130            self.allow_destruct = True
4131
4132    def __del__(self):
4133        """
4134        Destroy a reactor
4135        """
4136        if self.allow_destruct:
4137            lib.zloop_destroy(byref(self._as_parameter_))
4138
4139    def __eq__(self, other):
4140        if type(other) == type(self):
4141            return other.c_address() == self.c_address()
4142        elif type(other) == c_void_p:
4143            return other.value == self.c_address()
4144
4145    def c_address(self):
4146        """
4147        Return the address of the object pointer in c.  Useful for comparison.
4148        """
4149        return addressof(self._as_parameter_.contents)
4150
4151    def __bool__(self):
4152        "Determine whether the object is valid by converting to boolean" # Python 3
4153        return self._as_parameter_.__bool__()
4154
4155    def __nonzero__(self):
4156        "Determine whether the object is valid by converting to boolean" # Python 2
4157        return self._as_parameter_.__nonzero__()
4158
4159    def reader(self, sock, handler, arg):
4160        """
4161        Register socket reader with the reactor. When the reader has messages,
4162the reactor will call the handler, passing the arg. Returns 0 if OK, -1
4163if there was an error. If you register the same socket more than once,
4164each instance will invoke its corresponding handler.
4165        """
4166        return lib.zloop_reader(self._as_parameter_, sock, handler, arg)
4167
4168    def reader_end(self, sock):
4169        """
4170        Cancel a socket reader from the reactor. If multiple readers exist for
4171same socket, cancels ALL of them.
4172        """
4173        return lib.zloop_reader_end(self._as_parameter_, sock)
4174
4175    def reader_set_tolerant(self, sock):
4176        """
4177        Configure a registered reader to ignore errors. If you do not set this,
4178then readers that have errors are removed from the reactor silently.
4179        """
4180        return lib.zloop_reader_set_tolerant(self._as_parameter_, sock)
4181
4182    def poller(self, item, handler, arg):
4183        """
4184        Register low-level libzmq pollitem with the reactor. When the pollitem
4185is ready, will call the handler, passing the arg. Returns 0 if OK, -1
4186if there was an error. If you register the pollitem more than once, each
4187instance will invoke its corresponding handler. A pollitem with
4188socket=NULL and fd=0 means 'poll on FD zero'.
4189        """
4190        return lib.zloop_poller(self._as_parameter_, item, handler, arg)
4191
4192    def poller_end(self, item):
4193        """
4194        Cancel a pollitem from the reactor, specified by socket or FD. If both
4195are specified, uses only socket. If multiple poll items exist for same
4196socket/FD, cancels ALL of them.
4197        """
4198        return lib.zloop_poller_end(self._as_parameter_, item)
4199
4200    def poller_set_tolerant(self, item):
4201        """
4202        Configure a registered poller to ignore errors. If you do not set this,
4203then poller that have errors are removed from the reactor silently.
4204        """
4205        return lib.zloop_poller_set_tolerant(self._as_parameter_, item)
4206
4207    def timer(self, delay, times, handler, arg):
4208        """
4209        Register a timer that expires after some delay and repeats some number of
4210times. At each expiry, will call the handler, passing the arg. To run a
4211timer forever, use 0 times. Returns a timer_id that is used to cancel the
4212timer in the future. Returns -1 if there was an error.
4213        """
4214        return lib.zloop_timer(self._as_parameter_, delay, times, handler, arg)
4215
4216    def timer_end(self, timer_id):
4217        """
4218        Cancel a specific timer identified by a specific timer_id (as returned by
4219zloop_timer).
4220        """
4221        return lib.zloop_timer_end(self._as_parameter_, timer_id)
4222
4223    def ticket(self, handler, arg):
4224        """
4225        Register a ticket timer. Ticket timers are very fast in the case where
4226you use a lot of timers (thousands), and frequently remove and add them.
4227The main use case is expiry timers for servers that handle many clients,
4228and which reset the expiry timer for each message received from a client.
4229Whereas normal timers perform poorly as the number of clients grows, the
4230cost of ticket timers is constant, no matter the number of clients. You
4231must set the ticket delay using zloop_set_ticket_delay before creating a
4232ticket. Returns a handle to the timer that you should use in
4233zloop_ticket_reset and zloop_ticket_delete.
4234        """
4235        return c_void_p(lib.zloop_ticket(self._as_parameter_, handler, arg))
4236
4237    def ticket_reset(self, handle):
4238        """
4239        Reset a ticket timer, which moves it to the end of the ticket list and
4240resets its execution time. This is a very fast operation.
4241        """
4242        return lib.zloop_ticket_reset(self._as_parameter_, handle)
4243
4244    def ticket_delete(self, handle):
4245        """
4246        Delete a ticket timer. We do not actually delete the ticket here, as
4247other code may still refer to the ticket. We mark as deleted, and remove
4248later and safely.
4249        """
4250        return lib.zloop_ticket_delete(self._as_parameter_, handle)
4251
4252    def set_ticket_delay(self, ticket_delay):
4253        """
4254        Set the ticket delay, which applies to all tickets. If you lower the
4255delay and there are already tickets created, the results are undefined.
4256        """
4257        return lib.zloop_set_ticket_delay(self._as_parameter_, ticket_delay)
4258
4259    def set_max_timers(self, max_timers):
4260        """
4261        Set hard limit on number of timers allowed. Setting more than a small
4262number of timers (10-100) can have a dramatic impact on the performance
4263of the reactor. For high-volume cases, use ticket timers. If the hard
4264limit is reached, the reactor stops creating new timers and logs an
4265error.
4266        """
4267        return lib.zloop_set_max_timers(self._as_parameter_, max_timers)
4268
4269    def set_verbose(self, verbose):
4270        """
4271        Set verbose tracing of reactor on/off. The default verbose setting is
4272off (false).
4273        """
4274        return lib.zloop_set_verbose(self._as_parameter_, verbose)
4275
4276    def set_nonstop(self, nonstop):
4277        """
4278        By default the reactor stops if the process receives a SIGINT or SIGTERM
4279signal. This makes it impossible to shut-down message based architectures
4280like zactors. This method lets you switch off break handling. The default
4281nonstop setting is off (false).
4282        """
4283        return lib.zloop_set_nonstop(self._as_parameter_, nonstop)
4284
4285    def start(self):
4286        """
4287        Start the reactor. Takes control of the thread and returns when the 0MQ
4288context is terminated or the process is interrupted, or any event handler
4289returns -1. Event handlers may register new sockets and timers, and
4290cancel sockets. Returns 0 if interrupted, -1 if canceled by a handler.
4291        """
4292        return lib.zloop_start(self._as_parameter_)
4293
4294    @staticmethod
4295    def test(verbose):
4296        """
4297        Self test of this class.
4298        """
4299        return lib.zloop_test(verbose)
4300
4301
4302# zmsg
4303lib.zmsg_new.restype = zmsg_p
4304lib.zmsg_new.argtypes = []
4305lib.zmsg_destroy.restype = None
4306lib.zmsg_destroy.argtypes = [POINTER(zmsg_p)]
4307lib.zmsg_recv.restype = zmsg_p
4308lib.zmsg_recv.argtypes = [c_void_p]
4309lib.zmsg_load.restype = zmsg_p
4310lib.zmsg_load.argtypes = [FILE_p]
4311lib.zmsg_decode.restype = zmsg_p
4312lib.zmsg_decode.argtypes = [zframe_p]
4313lib.zmsg_new_signal.restype = zmsg_p
4314lib.zmsg_new_signal.argtypes = [c_ubyte]
4315lib.zmsg_send.restype = c_int
4316lib.zmsg_send.argtypes = [POINTER(zmsg_p), c_void_p]
4317lib.zmsg_sendm.restype = c_int
4318lib.zmsg_sendm.argtypes = [POINTER(zmsg_p), c_void_p]
4319lib.zmsg_size.restype = c_size_t
4320lib.zmsg_size.argtypes = [zmsg_p]
4321lib.zmsg_content_size.restype = c_size_t
4322lib.zmsg_content_size.argtypes = [zmsg_p]
4323lib.zmsg_routing_id.restype = c_int
4324lib.zmsg_routing_id.argtypes = [zmsg_p]
4325lib.zmsg_set_routing_id.restype = None
4326lib.zmsg_set_routing_id.argtypes = [zmsg_p, c_int]
4327lib.zmsg_prepend.restype = c_int
4328lib.zmsg_prepend.argtypes = [zmsg_p, POINTER(zframe_p)]
4329lib.zmsg_append.restype = c_int
4330lib.zmsg_append.argtypes = [zmsg_p, POINTER(zframe_p)]
4331lib.zmsg_pop.restype = zframe_p
4332lib.zmsg_pop.argtypes = [zmsg_p]
4333lib.zmsg_pushmem.restype = c_int
4334lib.zmsg_pushmem.argtypes = [zmsg_p, c_void_p, c_size_t]
4335lib.zmsg_addmem.restype = c_int
4336lib.zmsg_addmem.argtypes = [zmsg_p, c_void_p, c_size_t]
4337lib.zmsg_pushstr.restype = c_int
4338lib.zmsg_pushstr.argtypes = [zmsg_p, c_char_p]
4339lib.zmsg_addstr.restype = c_int
4340lib.zmsg_addstr.argtypes = [zmsg_p, c_char_p]
4341lib.zmsg_pushstrf.restype = c_int
4342lib.zmsg_pushstrf.argtypes = [zmsg_p, c_char_p]
4343lib.zmsg_addstrf.restype = c_int
4344lib.zmsg_addstrf.argtypes = [zmsg_p, c_char_p]
4345lib.zmsg_popstr.restype = POINTER(c_char)
4346lib.zmsg_popstr.argtypes = [zmsg_p]
4347lib.zmsg_addmsg.restype = c_int
4348lib.zmsg_addmsg.argtypes = [zmsg_p, POINTER(zmsg_p)]
4349lib.zmsg_popmsg.restype = zmsg_p
4350lib.zmsg_popmsg.argtypes = [zmsg_p]
4351lib.zmsg_remove.restype = None
4352lib.zmsg_remove.argtypes = [zmsg_p, zframe_p]
4353lib.zmsg_first.restype = zframe_p
4354lib.zmsg_first.argtypes = [zmsg_p]
4355lib.zmsg_next.restype = zframe_p
4356lib.zmsg_next.argtypes = [zmsg_p]
4357lib.zmsg_last.restype = zframe_p
4358lib.zmsg_last.argtypes = [zmsg_p]
4359lib.zmsg_save.restype = c_int
4360lib.zmsg_save.argtypes = [zmsg_p, FILE_p]
4361lib.zmsg_encode.restype = zframe_p
4362lib.zmsg_encode.argtypes = [zmsg_p]
4363lib.zmsg_dup.restype = zmsg_p
4364lib.zmsg_dup.argtypes = [zmsg_p]
4365lib.zmsg_print.restype = None
4366lib.zmsg_print.argtypes = [zmsg_p]
4367lib.zmsg_eq.restype = c_bool
4368lib.zmsg_eq.argtypes = [zmsg_p, zmsg_p]
4369lib.zmsg_signal.restype = c_int
4370lib.zmsg_signal.argtypes = [zmsg_p]
4371lib.zmsg_is.restype = c_bool
4372lib.zmsg_is.argtypes = [c_void_p]
4373lib.zmsg_test.restype = None
4374lib.zmsg_test.argtypes = [c_bool]
4375
4376class Zmsg(object):
4377    """
4378    working with multipart messages
4379    """
4380
4381    allow_destruct = False
4382    def __init__(self, *args):
4383        """
4384        Create a new empty message object
4385        """
4386        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
4387            self._as_parameter_ = cast(args[0], zmsg_p) # Conversion from raw type to binding
4388            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4389        elif len(args) == 2 and type(args[0]) is zmsg_p and isinstance(args[1], bool):
4390            self._as_parameter_ = args[0] # Conversion from raw type to binding
4391            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4392        else:
4393            assert(len(args) == 0)
4394            self._as_parameter_ = lib.zmsg_new() # Creation of new raw type
4395            self.allow_destruct = True
4396
4397    def __del__(self):
4398        """
4399        Destroy a message object and all frames it contains
4400        """
4401        if self.allow_destruct:
4402            lib.zmsg_destroy(byref(self._as_parameter_))
4403
4404    def __eq__(self, other):
4405        if type(other) == type(self):
4406            return other.c_address() == self.c_address()
4407        elif type(other) == c_void_p:
4408            return other.value == self.c_address()
4409
4410    def c_address(self):
4411        """
4412        Return the address of the object pointer in c.  Useful for comparison.
4413        """
4414        return addressof(self._as_parameter_.contents)
4415
4416    def __bool__(self):
4417        "Determine whether the object is valid by converting to boolean" # Python 3
4418        return self._as_parameter_.__bool__()
4419
4420    def __nonzero__(self):
4421        "Determine whether the object is valid by converting to boolean" # Python 2
4422        return self._as_parameter_.__nonzero__()
4423
4424    @staticmethod
4425    def recv(source):
4426        """
4427        Receive message from socket, returns zmsg_t object or NULL if the recv
4428was interrupted. Does a blocking recv. If you want to not block then use
4429the zloop class or zmsg_recv_nowait or zmq_poll to check for socket input
4430before receiving.
4431        """
4432        return Zmsg(lib.zmsg_recv(source), True)
4433
4434    @staticmethod
4435    def load(file):
4436        """
4437        Load/append an open file into new message, return the message.
4438Returns NULL if the message could not be loaded.
4439        """
4440        return Zmsg(lib.zmsg_load(coerce_py_file(file)), True)
4441
4442    @staticmethod
4443    def decode(frame):
4444        """
4445        Decodes a serialized message frame created by zmsg_encode () and returns
4446a new zmsg_t object. Returns NULL if the frame was badly formatted or
4447there was insufficient memory to work.
4448        """
4449        return Zmsg(lib.zmsg_decode(frame), True)
4450
4451    @staticmethod
4452    def new_signal(status):
4453        """
4454        Generate a signal message encoding the given status. A signal is a short
4455message carrying a 1-byte success/failure code (by convention, 0 means
4456OK). Signals are encoded to be distinguishable from "normal" messages.
4457        """
4458        return Zmsg(lib.zmsg_new_signal(status), True)
4459
4460    @staticmethod
4461    def send(self_p, dest):
4462        """
4463        Send message to destination socket, and destroy the message after sending
4464it successfully. If the message has no frames, sends nothing but destroys
4465the message anyhow. Nullifies the caller's reference to the message (as
4466it is a destructor).
4467        """
4468        return lib.zmsg_send(byref(zmsg_p.from_param(self_p)), dest)
4469
4470    @staticmethod
4471    def sendm(self_p, dest):
4472        """
4473        Send message to destination socket as part of a multipart sequence, and
4474destroy the message after sending it successfully. Note that after a
4475zmsg_sendm, you must call zmsg_send or another method that sends a final
4476message part. If the message has no frames, sends nothing but destroys
4477the message anyhow. Nullifies the caller's reference to the message (as
4478it is a destructor).
4479        """
4480        return lib.zmsg_sendm(byref(zmsg_p.from_param(self_p)), dest)
4481
4482    def size(self):
4483        """
4484        Return size of message, i.e. number of frames (0 or more).
4485        """
4486        return lib.zmsg_size(self._as_parameter_)
4487
4488    def content_size(self):
4489        """
4490        Return total size of all frames in message.
4491        """
4492        return lib.zmsg_content_size(self._as_parameter_)
4493
4494    def routing_id(self):
4495        """
4496        Return message routing ID, if the message came from a ZMQ_SERVER socket.
4497Else returns zero.
4498        """
4499        return lib.zmsg_routing_id(self._as_parameter_)
4500
4501    def set_routing_id(self, routing_id):
4502        """
4503        Set routing ID on message. This is used if/when the message is sent to a
4504ZMQ_SERVER socket.
4505        """
4506        return lib.zmsg_set_routing_id(self._as_parameter_, routing_id)
4507
4508    def prepend(self, frame_p):
4509        """
4510        Push frame to the front of the message, i.e. before all other frames.
4511Message takes ownership of frame, will destroy it when message is sent.
4512Returns 0 on success, -1 on error. Deprecates zmsg_push, which did not
4513nullify the caller's frame reference.
4514        """
4515        return lib.zmsg_prepend(self._as_parameter_, byref(zframe_p.from_param(frame_p)))
4516
4517    def append(self, frame_p):
4518        """
4519        Add frame to the end of the message, i.e. after all other frames.
4520Message takes ownership of frame, will destroy it when message is sent.
4521Returns 0 on success. Deprecates zmsg_add, which did not nullify the
4522caller's frame reference.
4523        """
4524        return lib.zmsg_append(self._as_parameter_, byref(zframe_p.from_param(frame_p)))
4525
4526    def pop(self):
4527        """
4528        Remove first frame from message, if any. Returns frame, or NULL.
4529        """
4530        return Zframe(lib.zmsg_pop(self._as_parameter_), True)
4531
4532    def pushmem(self, data, size):
4533        """
4534        Push block of memory to front of message, as a new frame.
4535Returns 0 on success, -1 on error.
4536        """
4537        return lib.zmsg_pushmem(self._as_parameter_, data, size)
4538
4539    def addmem(self, data, size):
4540        """
4541        Add block of memory to the end of the message, as a new frame.
4542Returns 0 on success, -1 on error.
4543        """
4544        return lib.zmsg_addmem(self._as_parameter_, data, size)
4545
4546    def pushstr(self, string):
4547        """
4548        Push string as new frame to front of message.
4549Returns 0 on success, -1 on error.
4550        """
4551        return lib.zmsg_pushstr(self._as_parameter_, string)
4552
4553    def addstr(self, string):
4554        """
4555        Push string as new frame to end of message.
4556Returns 0 on success, -1 on error.
4557        """
4558        return lib.zmsg_addstr(self._as_parameter_, string)
4559
4560    def pushstrf(self, format, *args):
4561        """
4562        Push formatted string as new frame to front of message.
4563Returns 0 on success, -1 on error.
4564        """
4565        return lib.zmsg_pushstrf(self._as_parameter_, format, *args)
4566
4567    def addstrf(self, format, *args):
4568        """
4569        Push formatted string as new frame to end of message.
4570Returns 0 on success, -1 on error.
4571        """
4572        return lib.zmsg_addstrf(self._as_parameter_, format, *args)
4573
4574    def popstr(self):
4575        """
4576        Pop frame off front of message, return as fresh string. If there were
4577no more frames in the message, returns NULL.
4578        """
4579        return return_fresh_string(lib.zmsg_popstr(self._as_parameter_))
4580
4581    def addmsg(self, msg_p):
4582        """
4583        Push encoded message as a new frame. Message takes ownership of
4584submessage, so the original is destroyed in this call. Returns 0 on
4585success, -1 on error.
4586        """
4587        return lib.zmsg_addmsg(self._as_parameter_, byref(zmsg_p.from_param(msg_p)))
4588
4589    def popmsg(self):
4590        """
4591        Remove first submessage from message, if any. Returns zmsg_t, or NULL if
4592decoding was not successful.
4593        """
4594        return Zmsg(lib.zmsg_popmsg(self._as_parameter_), True)
4595
4596    def remove(self, frame):
4597        """
4598        Remove specified frame from list, if present. Does not destroy frame.
4599        """
4600        return lib.zmsg_remove(self._as_parameter_, frame)
4601
4602    def first(self):
4603        """
4604        Set cursor to first frame in message. Returns frame, or NULL, if the
4605message is empty. Use this to navigate the frames as a list.
4606        """
4607        return Zframe(lib.zmsg_first(self._as_parameter_), False)
4608
4609    def next(self):
4610        """
4611        Return the next frame. If there are no more frames, returns NULL. To move
4612to the first frame call zmsg_first(). Advances the cursor.
4613        """
4614        return Zframe(lib.zmsg_next(self._as_parameter_), False)
4615
4616    def last(self):
4617        """
4618        Return the last frame. If there are no frames, returns NULL.
4619        """
4620        return Zframe(lib.zmsg_last(self._as_parameter_), False)
4621
4622    def save(self, file):
4623        """
4624        Save message to an open file, return 0 if OK, else -1. The message is
4625saved as a series of frames, each with length and data. Note that the
4626file is NOT guaranteed to be portable between operating systems, not
4627versions of CZMQ. The file format is at present undocumented and liable
4628to arbitrary change.
4629        """
4630        return lib.zmsg_save(self._as_parameter_, coerce_py_file(file))
4631
4632    def encode(self):
4633        """
4634        Serialize multipart message to a single message frame. Use this method
4635to send structured messages across transports that do not support
4636multipart data. Allocates and returns a new frame containing the
4637serialized message. To decode a serialized message frame, use
4638zmsg_decode ().
4639        """
4640        return Zframe(lib.zmsg_encode(self._as_parameter_), True)
4641
4642    def dup(self):
4643        """
4644        Create copy of message, as new message object. Returns a fresh zmsg_t
4645object. If message is null, or memory was exhausted, returns null.
4646        """
4647        return Zmsg(lib.zmsg_dup(self._as_parameter_), True)
4648
4649    def print(self):
4650        """
4651        Send message to zsys log sink (may be stdout, or system facility as
4652configured by zsys_set_logstream).
4653        """
4654        return lib.zmsg_print(self._as_parameter_)
4655
4656    def eq(self, other):
4657        """
4658        Return true if the two messages have the same number of frames and each
4659frame in the first message is identical to the corresponding frame in the
4660other message. As with zframe_eq, return false if either message is NULL.
4661        """
4662        return lib.zmsg_eq(self._as_parameter_, other)
4663
4664    def signal(self):
4665        """
4666        Return signal value, 0 or greater, if message is a signal, -1 if not.
4667        """
4668        return lib.zmsg_signal(self._as_parameter_)
4669
4670    @staticmethod
4671    def is_(self):
4672        """
4673        Probe the supplied object, and report if it looks like a zmsg_t.
4674        """
4675        return lib.zmsg_is(self)
4676
4677    @staticmethod
4678    def test(verbose):
4679        """
4680        Self test of this class.
4681        """
4682        return lib.zmsg_test(verbose)
4683
4684
4685# zpoller
4686lib.zpoller_new.restype = zpoller_p
4687lib.zpoller_new.argtypes = [c_void_p]
4688lib.zpoller_destroy.restype = None
4689lib.zpoller_destroy.argtypes = [POINTER(zpoller_p)]
4690lib.zpoller_add.restype = c_int
4691lib.zpoller_add.argtypes = [zpoller_p, c_void_p]
4692lib.zpoller_remove.restype = c_int
4693lib.zpoller_remove.argtypes = [zpoller_p, c_void_p]
4694lib.zpoller_set_nonstop.restype = None
4695lib.zpoller_set_nonstop.argtypes = [zpoller_p, c_bool]
4696lib.zpoller_wait.restype = c_void_p
4697lib.zpoller_wait.argtypes = [zpoller_p, c_int]
4698lib.zpoller_expired.restype = c_bool
4699lib.zpoller_expired.argtypes = [zpoller_p]
4700lib.zpoller_terminated.restype = c_bool
4701lib.zpoller_terminated.argtypes = [zpoller_p]
4702lib.zpoller_test.restype = None
4703lib.zpoller_test.argtypes = [c_bool]
4704
4705class Zpoller(object):
4706    """
4707    event-driven reactor
4708    """
4709
4710    allow_destruct = False
4711    def __init__(self, *args):
4712        """
4713        Create new poller, specifying zero or more readers. The list of
4714readers ends in a NULL. Each reader can be a zsock_t instance, a
4715zactor_t instance, a libzmq socket (void *), or a file handle.
4716        """
4717        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
4718            self._as_parameter_ = cast(args[0], zpoller_p) # Conversion from raw type to binding
4719            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4720        elif len(args) == 2 and type(args[0]) is zpoller_p and isinstance(args[1], bool):
4721            self._as_parameter_ = args[0] # Conversion from raw type to binding
4722            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4723        else:
4724            assert(len(args) >= 1)
4725            self._as_parameter_ = lib.zpoller_new(args[0], *args[1:]) # Creation of new raw type
4726            self.allow_destruct = True
4727
4728    def __del__(self):
4729        """
4730        Destroy a poller
4731        """
4732        if self.allow_destruct:
4733            lib.zpoller_destroy(byref(self._as_parameter_))
4734
4735    def __eq__(self, other):
4736        if type(other) == type(self):
4737            return other.c_address() == self.c_address()
4738        elif type(other) == c_void_p:
4739            return other.value == self.c_address()
4740
4741    def c_address(self):
4742        """
4743        Return the address of the object pointer in c.  Useful for comparison.
4744        """
4745        return addressof(self._as_parameter_.contents)
4746
4747    def __bool__(self):
4748        "Determine whether the object is valid by converting to boolean" # Python 3
4749        return self._as_parameter_.__bool__()
4750
4751    def __nonzero__(self):
4752        "Determine whether the object is valid by converting to boolean" # Python 2
4753        return self._as_parameter_.__nonzero__()
4754
4755    def add(self, reader):
4756        """
4757        Add a reader to be polled. Returns 0 if OK, -1 on failure. The reader may
4758be a libzmq void * socket, a zsock_t instance, or a zactor_t instance.
4759        """
4760        return lib.zpoller_add(self._as_parameter_, reader)
4761
4762    def remove(self, reader):
4763        """
4764        Remove a reader from the poller; returns 0 if OK, -1 on failure. The reader
4765must have been passed during construction, or in an zpoller_add () call.
4766        """
4767        return lib.zpoller_remove(self._as_parameter_, reader)
4768
4769    def set_nonstop(self, nonstop):
4770        """
4771        By default the poller stops if the process receives a SIGINT or SIGTERM
4772signal. This makes it impossible to shut-down message based architectures
4773like zactors. This method lets you switch off break handling. The default
4774nonstop setting is off (false).
4775        """
4776        return lib.zpoller_set_nonstop(self._as_parameter_, nonstop)
4777
4778    def wait(self, timeout):
4779        """
4780        Poll the registered readers for I/O, return first reader that has input.
4781The reader will be a libzmq void * socket, or a zsock_t or zactor_t
4782instance as specified in zpoller_new/zpoller_add. The timeout should be
4783zero or greater, or -1 to wait indefinitely. Socket priority is defined
4784by their order in the poll list. If you need a balanced poll, use the low
4785level zmq_poll method directly. If the poll call was interrupted (SIGINT),
4786or the ZMQ context was destroyed, or the timeout expired, returns NULL.
4787You can test the actual exit condition by calling zpoller_expired () and
4788zpoller_terminated (). The timeout is in msec.
4789        """
4790        return c_void_p(lib.zpoller_wait(self._as_parameter_, timeout))
4791
4792    def expired(self):
4793        """
4794        Return true if the last zpoller_wait () call ended because the timeout
4795expired, without any error.
4796        """
4797        return lib.zpoller_expired(self._as_parameter_)
4798
4799    def terminated(self):
4800        """
4801        Return true if the last zpoller_wait () call ended because the process
4802was interrupted, or the parent context was destroyed.
4803        """
4804        return lib.zpoller_terminated(self._as_parameter_)
4805
4806    @staticmethod
4807    def test(verbose):
4808        """
4809        Self test of this class.
4810        """
4811        return lib.zpoller_test(verbose)
4812
4813
4814# zproc
4815lib.zproc_new.restype = zproc_p
4816lib.zproc_new.argtypes = []
4817lib.zproc_destroy.restype = None
4818lib.zproc_destroy.argtypes = [POINTER(zproc_p)]
4819lib.zproc_args.restype = zlist_p
4820lib.zproc_args.argtypes = [zproc_p]
4821lib.zproc_set_args.restype = None
4822lib.zproc_set_args.argtypes = [zproc_p, POINTER(zlist_p)]
4823lib.zproc_set_argsx.restype = None
4824lib.zproc_set_argsx.argtypes = [zproc_p, c_char_p]
4825lib.zproc_set_env.restype = None
4826lib.zproc_set_env.argtypes = [zproc_p, POINTER(zhash_p)]
4827lib.zproc_set_stdin.restype = None
4828lib.zproc_set_stdin.argtypes = [zproc_p, c_void_p]
4829lib.zproc_set_stdout.restype = None
4830lib.zproc_set_stdout.argtypes = [zproc_p, c_void_p]
4831lib.zproc_set_stderr.restype = None
4832lib.zproc_set_stderr.argtypes = [zproc_p, c_void_p]
4833lib.zproc_stdin.restype = c_void_p
4834lib.zproc_stdin.argtypes = [zproc_p]
4835lib.zproc_stdout.restype = c_void_p
4836lib.zproc_stdout.argtypes = [zproc_p]
4837lib.zproc_stderr.restype = c_void_p
4838lib.zproc_stderr.argtypes = [zproc_p]
4839lib.zproc_run.restype = c_int
4840lib.zproc_run.argtypes = [zproc_p]
4841lib.zproc_returncode.restype = c_int
4842lib.zproc_returncode.argtypes = [zproc_p]
4843lib.zproc_pid.restype = c_int
4844lib.zproc_pid.argtypes = [zproc_p]
4845lib.zproc_running.restype = c_bool
4846lib.zproc_running.argtypes = [zproc_p]
4847lib.zproc_wait.restype = c_int
4848lib.zproc_wait.argtypes = [zproc_p, c_bool]
4849lib.zproc_actor.restype = c_void_p
4850lib.zproc_actor.argtypes = [zproc_p]
4851lib.zproc_kill.restype = None
4852lib.zproc_kill.argtypes = [zproc_p, c_int]
4853lib.zproc_set_verbose.restype = None
4854lib.zproc_set_verbose.argtypes = [zproc_p, c_bool]
4855lib.zproc_test.restype = None
4856lib.zproc_test.argtypes = [c_bool]
4857
4858class Zproc(object):
4859    """
4860    process configuration and status
4861    """
4862
4863    allow_destruct = False
4864    def __init__(self, *args):
4865        """
4866        Create a new zproc.
4867NOTE: On Windows and with libzmq3 and libzmq2 this function
4868returns NULL. Code needs to be ported there.
4869        """
4870        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
4871            self._as_parameter_ = cast(args[0], zproc_p) # Conversion from raw type to binding
4872            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4873        elif len(args) == 2 and type(args[0]) is zproc_p and isinstance(args[1], bool):
4874            self._as_parameter_ = args[0] # Conversion from raw type to binding
4875            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
4876        else:
4877            assert(len(args) == 0)
4878            self._as_parameter_ = lib.zproc_new() # Creation of new raw type
4879            self.allow_destruct = True
4880
4881    def __del__(self):
4882        """
4883        Destroy zproc, wait until process ends.
4884        """
4885        if self.allow_destruct:
4886            lib.zproc_destroy(byref(self._as_parameter_))
4887
4888    def __eq__(self, other):
4889        if type(other) == type(self):
4890            return other.c_address() == self.c_address()
4891        elif type(other) == c_void_p:
4892            return other.value == self.c_address()
4893
4894    def c_address(self):
4895        """
4896        Return the address of the object pointer in c.  Useful for comparison.
4897        """
4898        return addressof(self._as_parameter_.contents)
4899
4900    def __bool__(self):
4901        "Determine whether the object is valid by converting to boolean" # Python 3
4902        return self._as_parameter_.__bool__()
4903
4904    def __nonzero__(self):
4905        "Determine whether the object is valid by converting to boolean" # Python 2
4906        return self._as_parameter_.__nonzero__()
4907
4908    def args(self):
4909        """
4910        Return command line arguments (the first item is the executable) or
4911NULL if not set.
4912        """
4913        return Zlist(lib.zproc_args(self._as_parameter_), True)
4914
4915    def set_args(self, arguments):
4916        """
4917        Setup the command line arguments, the first item must be an (absolute) filename
4918to run.
4919        """
4920        return lib.zproc_set_args(self._as_parameter_, byref(zlist_p.from_param(arguments)))
4921
4922    def set_argsx(self, arguments, *args):
4923        """
4924        Setup the command line arguments, the first item must be an (absolute) filename
4925to run. Variadic function, must be NULL terminated.
4926        """
4927        return lib.zproc_set_argsx(self._as_parameter_, arguments, *args)
4928
4929    def set_env(self, arguments):
4930        """
4931        Setup the environment variables for the process.
4932        """
4933        return lib.zproc_set_env(self._as_parameter_, byref(zhash_p.from_param(arguments)))
4934
4935    def set_stdin(self, socket):
4936        """
4937        Connects process stdin with a readable ('>', connect) zeromq socket. If
4938socket argument is NULL, zproc creates own managed pair of inproc
4939sockets.  The writable one is then accessbile via zproc_stdin method.
4940        """
4941        return lib.zproc_set_stdin(self._as_parameter_, socket)
4942
4943    def set_stdout(self, socket):
4944        """
4945        Connects process stdout with a writable ('@', bind) zeromq socket. If
4946socket argument is NULL, zproc creates own managed pair of inproc
4947sockets.  The readable one is then accessbile via zproc_stdout method.
4948        """
4949        return lib.zproc_set_stdout(self._as_parameter_, socket)
4950
4951    def set_stderr(self, socket):
4952        """
4953        Connects process stderr with a writable ('@', bind) zeromq socket. If
4954socket argument is NULL, zproc creates own managed pair of inproc
4955sockets.  The readable one is then accessbile via zproc_stderr method.
4956        """
4957        return lib.zproc_set_stderr(self._as_parameter_, socket)
4958
4959    def stdin(self):
4960        """
4961        Return subprocess stdin writable socket. NULL for
4962not initialized or external sockets.
4963        """
4964        return c_void_p(lib.zproc_stdin(self._as_parameter_))
4965
4966    def stdout(self):
4967        """
4968        Return subprocess stdout readable socket. NULL for
4969not initialized or external sockets.
4970        """
4971        return c_void_p(lib.zproc_stdout(self._as_parameter_))
4972
4973    def stderr(self):
4974        """
4975        Return subprocess stderr readable socket. NULL for
4976not initialized or external sockets.
4977        """
4978        return c_void_p(lib.zproc_stderr(self._as_parameter_))
4979
4980    def run(self):
4981        """
4982        Starts the process, return just before execve/CreateProcess.
4983        """
4984        return lib.zproc_run(self._as_parameter_)
4985
4986    def returncode(self):
4987        """
4988        process exit code
4989        """
4990        return lib.zproc_returncode(self._as_parameter_)
4991
4992    def pid(self):
4993        """
4994        PID of the process
4995        """
4996        return lib.zproc_pid(self._as_parameter_)
4997
4998    def running(self):
4999        """
5000        return true if process is running, false if not yet started or finished
5001        """
5002        return lib.zproc_running(self._as_parameter_)
5003
5004    def wait(self, hang):
5005        """
5006        wait or poll process status, return return code
5007        """
5008        return lib.zproc_wait(self._as_parameter_, hang)
5009
5010    def actor(self):
5011        """
5012        return internal actor, usefull for the polling if process died
5013        """
5014        return c_void_p(lib.zproc_actor(self._as_parameter_))
5015
5016    def kill(self, signal):
5017        """
5018        send a signal to the subprocess
5019        """
5020        return lib.zproc_kill(self._as_parameter_, signal)
5021
5022    def set_verbose(self, verbose):
5023        """
5024        set verbose mode
5025        """
5026        return lib.zproc_set_verbose(self._as_parameter_, verbose)
5027
5028    @staticmethod
5029    def test(verbose):
5030        """
5031        Self test of this class.
5032        """
5033        return lib.zproc_test(verbose)
5034
5035
5036# zsock
5037lib.zsock_new.restype = zsock_p
5038lib.zsock_new.argtypes = [c_int]
5039lib.zsock_destroy.restype = None
5040lib.zsock_destroy.argtypes = [POINTER(zsock_p)]
5041lib.zsock_new_pub.restype = zsock_p
5042lib.zsock_new_pub.argtypes = [c_char_p]
5043lib.zsock_new_sub.restype = zsock_p
5044lib.zsock_new_sub.argtypes = [c_char_p, c_char_p]
5045lib.zsock_new_req.restype = zsock_p
5046lib.zsock_new_req.argtypes = [c_char_p]
5047lib.zsock_new_rep.restype = zsock_p
5048lib.zsock_new_rep.argtypes = [c_char_p]
5049lib.zsock_new_dealer.restype = zsock_p
5050lib.zsock_new_dealer.argtypes = [c_char_p]
5051lib.zsock_new_router.restype = zsock_p
5052lib.zsock_new_router.argtypes = [c_char_p]
5053lib.zsock_new_push.restype = zsock_p
5054lib.zsock_new_push.argtypes = [c_char_p]
5055lib.zsock_new_pull.restype = zsock_p
5056lib.zsock_new_pull.argtypes = [c_char_p]
5057lib.zsock_new_xpub.restype = zsock_p
5058lib.zsock_new_xpub.argtypes = [c_char_p]
5059lib.zsock_new_xsub.restype = zsock_p
5060lib.zsock_new_xsub.argtypes = [c_char_p]
5061lib.zsock_new_pair.restype = zsock_p
5062lib.zsock_new_pair.argtypes = [c_char_p]
5063lib.zsock_new_stream.restype = zsock_p
5064lib.zsock_new_stream.argtypes = [c_char_p]
5065lib.zsock_new_server.restype = zsock_p
5066lib.zsock_new_server.argtypes = [c_char_p]
5067lib.zsock_new_client.restype = zsock_p
5068lib.zsock_new_client.argtypes = [c_char_p]
5069lib.zsock_new_radio.restype = zsock_p
5070lib.zsock_new_radio.argtypes = [c_char_p]
5071lib.zsock_new_dish.restype = zsock_p
5072lib.zsock_new_dish.argtypes = [c_char_p]
5073lib.zsock_new_gather.restype = zsock_p
5074lib.zsock_new_gather.argtypes = [c_char_p]
5075lib.zsock_new_scatter.restype = zsock_p
5076lib.zsock_new_scatter.argtypes = [c_char_p]
5077lib.zsock_bind.restype = c_int
5078lib.zsock_bind.argtypes = [zsock_p, c_char_p]
5079lib.zsock_endpoint.restype = c_char_p
5080lib.zsock_endpoint.argtypes = [zsock_p]
5081lib.zsock_unbind.restype = c_int
5082lib.zsock_unbind.argtypes = [zsock_p, c_char_p]
5083lib.zsock_connect.restype = c_int
5084lib.zsock_connect.argtypes = [zsock_p, c_char_p]
5085lib.zsock_disconnect.restype = c_int
5086lib.zsock_disconnect.argtypes = [zsock_p, c_char_p]
5087lib.zsock_attach.restype = c_int
5088lib.zsock_attach.argtypes = [zsock_p, c_char_p, c_bool]
5089lib.zsock_type_str.restype = c_char_p
5090lib.zsock_type_str.argtypes = [zsock_p]
5091lib.zsock_send.restype = c_int
5092lib.zsock_send.argtypes = [zsock_p, c_char_p]
5093lib.zsock_vsend.restype = c_int
5094lib.zsock_vsend.argtypes = [zsock_p, c_char_p, va_list_p]
5095lib.zsock_recv.restype = c_int
5096lib.zsock_recv.argtypes = [zsock_p, c_char_p]
5097lib.zsock_vrecv.restype = c_int
5098lib.zsock_vrecv.argtypes = [zsock_p, c_char_p, va_list_p]
5099lib.zsock_bsend.restype = c_int
5100lib.zsock_bsend.argtypes = [zsock_p, c_char_p]
5101lib.zsock_brecv.restype = c_int
5102lib.zsock_brecv.argtypes = [zsock_p, c_char_p]
5103lib.zsock_routing_id.restype = c_int
5104lib.zsock_routing_id.argtypes = [zsock_p]
5105lib.zsock_set_routing_id.restype = None
5106lib.zsock_set_routing_id.argtypes = [zsock_p, c_int]
5107lib.zsock_set_unbounded.restype = None
5108lib.zsock_set_unbounded.argtypes = [zsock_p]
5109lib.zsock_signal.restype = c_int
5110lib.zsock_signal.argtypes = [zsock_p, c_ubyte]
5111lib.zsock_wait.restype = c_int
5112lib.zsock_wait.argtypes = [zsock_p]
5113lib.zsock_flush.restype = None
5114lib.zsock_flush.argtypes = [zsock_p]
5115lib.zsock_join.restype = c_int
5116lib.zsock_join.argtypes = [zsock_p, c_char_p]
5117lib.zsock_leave.restype = c_int
5118lib.zsock_leave.argtypes = [zsock_p, c_char_p]
5119lib.zsock_is.restype = c_bool
5120lib.zsock_is.argtypes = [c_void_p]
5121lib.zsock_resolve.restype = c_void_p
5122lib.zsock_resolve.argtypes = [c_void_p]
5123lib.zsock_heartbeat_ivl.restype = c_int
5124lib.zsock_heartbeat_ivl.argtypes = [zsock_p]
5125lib.zsock_set_heartbeat_ivl.restype = None
5126lib.zsock_set_heartbeat_ivl.argtypes = [zsock_p, c_int]
5127lib.zsock_heartbeat_ttl.restype = c_int
5128lib.zsock_heartbeat_ttl.argtypes = [zsock_p]
5129lib.zsock_set_heartbeat_ttl.restype = None
5130lib.zsock_set_heartbeat_ttl.argtypes = [zsock_p, c_int]
5131lib.zsock_heartbeat_timeout.restype = c_int
5132lib.zsock_heartbeat_timeout.argtypes = [zsock_p]
5133lib.zsock_set_heartbeat_timeout.restype = None
5134lib.zsock_set_heartbeat_timeout.argtypes = [zsock_p, c_int]
5135lib.zsock_use_fd.restype = c_int
5136lib.zsock_use_fd.argtypes = [zsock_p]
5137lib.zsock_set_use_fd.restype = None
5138lib.zsock_set_use_fd.argtypes = [zsock_p, c_int]
5139lib.zsock_set_xpub_manual.restype = None
5140lib.zsock_set_xpub_manual.argtypes = [zsock_p, c_int]
5141lib.zsock_set_xpub_welcome_msg.restype = None
5142lib.zsock_set_xpub_welcome_msg.argtypes = [zsock_p, c_char_p]
5143lib.zsock_set_stream_notify.restype = None
5144lib.zsock_set_stream_notify.argtypes = [zsock_p, c_int]
5145lib.zsock_invert_matching.restype = c_int
5146lib.zsock_invert_matching.argtypes = [zsock_p]
5147lib.zsock_set_invert_matching.restype = None
5148lib.zsock_set_invert_matching.argtypes = [zsock_p, c_int]
5149lib.zsock_set_xpub_verboser.restype = None
5150lib.zsock_set_xpub_verboser.argtypes = [zsock_p, c_int]
5151lib.zsock_connect_timeout.restype = c_int
5152lib.zsock_connect_timeout.argtypes = [zsock_p]
5153lib.zsock_set_connect_timeout.restype = None
5154lib.zsock_set_connect_timeout.argtypes = [zsock_p, c_int]
5155lib.zsock_tcp_maxrt.restype = c_int
5156lib.zsock_tcp_maxrt.argtypes = [zsock_p]
5157lib.zsock_set_tcp_maxrt.restype = None
5158lib.zsock_set_tcp_maxrt.argtypes = [zsock_p, c_int]
5159lib.zsock_thread_safe.restype = c_int
5160lib.zsock_thread_safe.argtypes = [zsock_p]
5161lib.zsock_multicast_maxtpdu.restype = c_int
5162lib.zsock_multicast_maxtpdu.argtypes = [zsock_p]
5163lib.zsock_set_multicast_maxtpdu.restype = None
5164lib.zsock_set_multicast_maxtpdu.argtypes = [zsock_p, c_int]
5165lib.zsock_vmci_buffer_size.restype = c_int
5166lib.zsock_vmci_buffer_size.argtypes = [zsock_p]
5167lib.zsock_set_vmci_buffer_size.restype = None
5168lib.zsock_set_vmci_buffer_size.argtypes = [zsock_p, c_int]
5169lib.zsock_vmci_buffer_min_size.restype = c_int
5170lib.zsock_vmci_buffer_min_size.argtypes = [zsock_p]
5171lib.zsock_set_vmci_buffer_min_size.restype = None
5172lib.zsock_set_vmci_buffer_min_size.argtypes = [zsock_p, c_int]
5173lib.zsock_vmci_buffer_max_size.restype = c_int
5174lib.zsock_vmci_buffer_max_size.argtypes = [zsock_p]
5175lib.zsock_set_vmci_buffer_max_size.restype = None
5176lib.zsock_set_vmci_buffer_max_size.argtypes = [zsock_p, c_int]
5177lib.zsock_vmci_connect_timeout.restype = c_int
5178lib.zsock_vmci_connect_timeout.argtypes = [zsock_p]
5179lib.zsock_set_vmci_connect_timeout.restype = None
5180lib.zsock_set_vmci_connect_timeout.argtypes = [zsock_p, c_int]
5181lib.zsock_tos.restype = c_int
5182lib.zsock_tos.argtypes = [zsock_p]
5183lib.zsock_set_tos.restype = None
5184lib.zsock_set_tos.argtypes = [zsock_p, c_int]
5185lib.zsock_set_router_handover.restype = None
5186lib.zsock_set_router_handover.argtypes = [zsock_p, c_int]
5187lib.zsock_set_connect_rid.restype = None
5188lib.zsock_set_connect_rid.argtypes = [zsock_p, c_char_p]
5189lib.zsock_set_connect_rid_bin.restype = None
5190lib.zsock_set_connect_rid_bin.argtypes = [zsock_p, c_void_p]
5191lib.zsock_handshake_ivl.restype = c_int
5192lib.zsock_handshake_ivl.argtypes = [zsock_p]
5193lib.zsock_set_handshake_ivl.restype = None
5194lib.zsock_set_handshake_ivl.argtypes = [zsock_p, c_int]
5195lib.zsock_socks_proxy.restype = POINTER(c_char)
5196lib.zsock_socks_proxy.argtypes = [zsock_p]
5197lib.zsock_set_socks_proxy.restype = None
5198lib.zsock_set_socks_proxy.argtypes = [zsock_p, c_char_p]
5199lib.zsock_set_xpub_nodrop.restype = None
5200lib.zsock_set_xpub_nodrop.argtypes = [zsock_p, c_int]
5201lib.zsock_set_router_mandatory.restype = None
5202lib.zsock_set_router_mandatory.argtypes = [zsock_p, c_int]
5203lib.zsock_set_probe_router.restype = None
5204lib.zsock_set_probe_router.argtypes = [zsock_p, c_int]
5205lib.zsock_set_req_relaxed.restype = None
5206lib.zsock_set_req_relaxed.argtypes = [zsock_p, c_int]
5207lib.zsock_set_req_correlate.restype = None
5208lib.zsock_set_req_correlate.argtypes = [zsock_p, c_int]
5209lib.zsock_set_conflate.restype = None
5210lib.zsock_set_conflate.argtypes = [zsock_p, c_int]
5211lib.zsock_zap_domain.restype = POINTER(c_char)
5212lib.zsock_zap_domain.argtypes = [zsock_p]
5213lib.zsock_set_zap_domain.restype = None
5214lib.zsock_set_zap_domain.argtypes = [zsock_p, c_char_p]
5215lib.zsock_mechanism.restype = c_int
5216lib.zsock_mechanism.argtypes = [zsock_p]
5217lib.zsock_plain_server.restype = c_int
5218lib.zsock_plain_server.argtypes = [zsock_p]
5219lib.zsock_set_plain_server.restype = None
5220lib.zsock_set_plain_server.argtypes = [zsock_p, c_int]
5221lib.zsock_plain_username.restype = POINTER(c_char)
5222lib.zsock_plain_username.argtypes = [zsock_p]
5223lib.zsock_set_plain_username.restype = None
5224lib.zsock_set_plain_username.argtypes = [zsock_p, c_char_p]
5225lib.zsock_plain_password.restype = POINTER(c_char)
5226lib.zsock_plain_password.argtypes = [zsock_p]
5227lib.zsock_set_plain_password.restype = None
5228lib.zsock_set_plain_password.argtypes = [zsock_p, c_char_p]
5229lib.zsock_curve_server.restype = c_int
5230lib.zsock_curve_server.argtypes = [zsock_p]
5231lib.zsock_set_curve_server.restype = None
5232lib.zsock_set_curve_server.argtypes = [zsock_p, c_int]
5233lib.zsock_curve_publickey.restype = POINTER(c_char)
5234lib.zsock_curve_publickey.argtypes = [zsock_p]
5235lib.zsock_set_curve_publickey.restype = None
5236lib.zsock_set_curve_publickey.argtypes = [zsock_p, c_char_p]
5237lib.zsock_set_curve_publickey_bin.restype = None
5238lib.zsock_set_curve_publickey_bin.argtypes = [zsock_p, c_void_p]
5239lib.zsock_curve_secretkey.restype = POINTER(c_char)
5240lib.zsock_curve_secretkey.argtypes = [zsock_p]
5241lib.zsock_set_curve_secretkey.restype = None
5242lib.zsock_set_curve_secretkey.argtypes = [zsock_p, c_char_p]
5243lib.zsock_set_curve_secretkey_bin.restype = None
5244lib.zsock_set_curve_secretkey_bin.argtypes = [zsock_p, c_void_p]
5245lib.zsock_curve_serverkey.restype = POINTER(c_char)
5246lib.zsock_curve_serverkey.argtypes = [zsock_p]
5247lib.zsock_set_curve_serverkey.restype = None
5248lib.zsock_set_curve_serverkey.argtypes = [zsock_p, c_char_p]
5249lib.zsock_set_curve_serverkey_bin.restype = None
5250lib.zsock_set_curve_serverkey_bin.argtypes = [zsock_p, c_void_p]
5251lib.zsock_gssapi_server.restype = c_int
5252lib.zsock_gssapi_server.argtypes = [zsock_p]
5253lib.zsock_set_gssapi_server.restype = None
5254lib.zsock_set_gssapi_server.argtypes = [zsock_p, c_int]
5255lib.zsock_gssapi_plaintext.restype = c_int
5256lib.zsock_gssapi_plaintext.argtypes = [zsock_p]
5257lib.zsock_set_gssapi_plaintext.restype = None
5258lib.zsock_set_gssapi_plaintext.argtypes = [zsock_p, c_int]
5259lib.zsock_gssapi_principal.restype = POINTER(c_char)
5260lib.zsock_gssapi_principal.argtypes = [zsock_p]
5261lib.zsock_set_gssapi_principal.restype = None
5262lib.zsock_set_gssapi_principal.argtypes = [zsock_p, c_char_p]
5263lib.zsock_gssapi_service_principal.restype = POINTER(c_char)
5264lib.zsock_gssapi_service_principal.argtypes = [zsock_p]
5265lib.zsock_set_gssapi_service_principal.restype = None
5266lib.zsock_set_gssapi_service_principal.argtypes = [zsock_p, c_char_p]
5267lib.zsock_ipv6.restype = c_int
5268lib.zsock_ipv6.argtypes = [zsock_p]
5269lib.zsock_set_ipv6.restype = None
5270lib.zsock_set_ipv6.argtypes = [zsock_p, c_int]
5271lib.zsock_immediate.restype = c_int
5272lib.zsock_immediate.argtypes = [zsock_p]
5273lib.zsock_set_immediate.restype = None
5274lib.zsock_set_immediate.argtypes = [zsock_p, c_int]
5275lib.zsock_sndhwm.restype = c_int
5276lib.zsock_sndhwm.argtypes = [zsock_p]
5277lib.zsock_set_sndhwm.restype = None
5278lib.zsock_set_sndhwm.argtypes = [zsock_p, c_int]
5279lib.zsock_rcvhwm.restype = c_int
5280lib.zsock_rcvhwm.argtypes = [zsock_p]
5281lib.zsock_set_rcvhwm.restype = None
5282lib.zsock_set_rcvhwm.argtypes = [zsock_p, c_int]
5283lib.zsock_maxmsgsize.restype = c_int
5284lib.zsock_maxmsgsize.argtypes = [zsock_p]
5285lib.zsock_set_maxmsgsize.restype = None
5286lib.zsock_set_maxmsgsize.argtypes = [zsock_p, c_int]
5287lib.zsock_multicast_hops.restype = c_int
5288lib.zsock_multicast_hops.argtypes = [zsock_p]
5289lib.zsock_set_multicast_hops.restype = None
5290lib.zsock_set_multicast_hops.argtypes = [zsock_p, c_int]
5291lib.zsock_set_xpub_verbose.restype = None
5292lib.zsock_set_xpub_verbose.argtypes = [zsock_p, c_int]
5293lib.zsock_tcp_keepalive.restype = c_int
5294lib.zsock_tcp_keepalive.argtypes = [zsock_p]
5295lib.zsock_set_tcp_keepalive.restype = None
5296lib.zsock_set_tcp_keepalive.argtypes = [zsock_p, c_int]
5297lib.zsock_tcp_keepalive_idle.restype = c_int
5298lib.zsock_tcp_keepalive_idle.argtypes = [zsock_p]
5299lib.zsock_set_tcp_keepalive_idle.restype = None
5300lib.zsock_set_tcp_keepalive_idle.argtypes = [zsock_p, c_int]
5301lib.zsock_tcp_keepalive_cnt.restype = c_int
5302lib.zsock_tcp_keepalive_cnt.argtypes = [zsock_p]
5303lib.zsock_set_tcp_keepalive_cnt.restype = None
5304lib.zsock_set_tcp_keepalive_cnt.argtypes = [zsock_p, c_int]
5305lib.zsock_tcp_keepalive_intvl.restype = c_int
5306lib.zsock_tcp_keepalive_intvl.argtypes = [zsock_p]
5307lib.zsock_set_tcp_keepalive_intvl.restype = None
5308lib.zsock_set_tcp_keepalive_intvl.argtypes = [zsock_p, c_int]
5309lib.zsock_tcp_accept_filter.restype = POINTER(c_char)
5310lib.zsock_tcp_accept_filter.argtypes = [zsock_p]
5311lib.zsock_set_tcp_accept_filter.restype = None
5312lib.zsock_set_tcp_accept_filter.argtypes = [zsock_p, c_char_p]
5313lib.zsock_last_endpoint.restype = POINTER(c_char)
5314lib.zsock_last_endpoint.argtypes = [zsock_p]
5315lib.zsock_set_router_raw.restype = None
5316lib.zsock_set_router_raw.argtypes = [zsock_p, c_int]
5317lib.zsock_ipv4only.restype = c_int
5318lib.zsock_ipv4only.argtypes = [zsock_p]
5319lib.zsock_set_ipv4only.restype = None
5320lib.zsock_set_ipv4only.argtypes = [zsock_p, c_int]
5321lib.zsock_set_delay_attach_on_connect.restype = None
5322lib.zsock_set_delay_attach_on_connect.argtypes = [zsock_p, c_int]
5323lib.zsock_hwm.restype = c_int
5324lib.zsock_hwm.argtypes = [zsock_p]
5325lib.zsock_set_hwm.restype = None
5326lib.zsock_set_hwm.argtypes = [zsock_p, c_int]
5327lib.zsock_swap.restype = c_int
5328lib.zsock_swap.argtypes = [zsock_p]
5329lib.zsock_set_swap.restype = None
5330lib.zsock_set_swap.argtypes = [zsock_p, c_int]
5331lib.zsock_affinity.restype = c_int
5332lib.zsock_affinity.argtypes = [zsock_p]
5333lib.zsock_set_affinity.restype = None
5334lib.zsock_set_affinity.argtypes = [zsock_p, c_int]
5335lib.zsock_identity.restype = POINTER(c_char)
5336lib.zsock_identity.argtypes = [zsock_p]
5337lib.zsock_set_identity.restype = None
5338lib.zsock_set_identity.argtypes = [zsock_p, c_char_p]
5339lib.zsock_rate.restype = c_int
5340lib.zsock_rate.argtypes = [zsock_p]
5341lib.zsock_set_rate.restype = None
5342lib.zsock_set_rate.argtypes = [zsock_p, c_int]
5343lib.zsock_recovery_ivl.restype = c_int
5344lib.zsock_recovery_ivl.argtypes = [zsock_p]
5345lib.zsock_set_recovery_ivl.restype = None
5346lib.zsock_set_recovery_ivl.argtypes = [zsock_p, c_int]
5347lib.zsock_recovery_ivl_msec.restype = c_int
5348lib.zsock_recovery_ivl_msec.argtypes = [zsock_p]
5349lib.zsock_set_recovery_ivl_msec.restype = None
5350lib.zsock_set_recovery_ivl_msec.argtypes = [zsock_p, c_int]
5351lib.zsock_mcast_loop.restype = c_int
5352lib.zsock_mcast_loop.argtypes = [zsock_p]
5353lib.zsock_set_mcast_loop.restype = None
5354lib.zsock_set_mcast_loop.argtypes = [zsock_p, c_int]
5355lib.zsock_rcvtimeo.restype = c_int
5356lib.zsock_rcvtimeo.argtypes = [zsock_p]
5357lib.zsock_set_rcvtimeo.restype = None
5358lib.zsock_set_rcvtimeo.argtypes = [zsock_p, c_int]
5359lib.zsock_sndtimeo.restype = c_int
5360lib.zsock_sndtimeo.argtypes = [zsock_p]
5361lib.zsock_set_sndtimeo.restype = None
5362lib.zsock_set_sndtimeo.argtypes = [zsock_p, c_int]
5363lib.zsock_sndbuf.restype = c_int
5364lib.zsock_sndbuf.argtypes = [zsock_p]
5365lib.zsock_set_sndbuf.restype = None
5366lib.zsock_set_sndbuf.argtypes = [zsock_p, c_int]
5367lib.zsock_rcvbuf.restype = c_int
5368lib.zsock_rcvbuf.argtypes = [zsock_p]
5369lib.zsock_set_rcvbuf.restype = None
5370lib.zsock_set_rcvbuf.argtypes = [zsock_p, c_int]
5371lib.zsock_linger.restype = c_int
5372lib.zsock_linger.argtypes = [zsock_p]
5373lib.zsock_set_linger.restype = None
5374lib.zsock_set_linger.argtypes = [zsock_p, c_int]
5375lib.zsock_reconnect_ivl.restype = c_int
5376lib.zsock_reconnect_ivl.argtypes = [zsock_p]
5377lib.zsock_set_reconnect_ivl.restype = None
5378lib.zsock_set_reconnect_ivl.argtypes = [zsock_p, c_int]
5379lib.zsock_reconnect_ivl_max.restype = c_int
5380lib.zsock_reconnect_ivl_max.argtypes = [zsock_p]
5381lib.zsock_set_reconnect_ivl_max.restype = None
5382lib.zsock_set_reconnect_ivl_max.argtypes = [zsock_p, c_int]
5383lib.zsock_backlog.restype = c_int
5384lib.zsock_backlog.argtypes = [zsock_p]
5385lib.zsock_set_backlog.restype = None
5386lib.zsock_set_backlog.argtypes = [zsock_p, c_int]
5387lib.zsock_set_subscribe.restype = None
5388lib.zsock_set_subscribe.argtypes = [zsock_p, c_char_p]
5389lib.zsock_set_unsubscribe.restype = None
5390lib.zsock_set_unsubscribe.argtypes = [zsock_p, c_char_p]
5391lib.zsock_type.restype = c_int
5392lib.zsock_type.argtypes = [zsock_p]
5393lib.zsock_rcvmore.restype = c_int
5394lib.zsock_rcvmore.argtypes = [zsock_p]
5395lib.zsock_fd.restype = socket_p
5396lib.zsock_fd.argtypes = [zsock_p]
5397lib.zsock_events.restype = c_int
5398lib.zsock_events.argtypes = [zsock_p]
5399lib.zsock_test.restype = None
5400lib.zsock_test.argtypes = [c_bool]
5401
5402class Zsock(object):
5403    """
5404    high-level socket API that hides libzmq contexts and sockets
5405    """
5406
5407    allow_destruct = False
5408    def __init__(self, *args):
5409        """
5410        Create a new socket. Returns the new socket, or NULL if the new socket
5411could not be created. Note that the symbol zsock_new (and other
5412constructors/destructors for zsock) are redirected to the *_checked
5413variant, enabling intelligent socket leak detection. This can have
5414performance implications if you use a LOT of sockets. To turn off this
5415redirection behaviour, define ZSOCK_NOCHECK.
5416        """
5417        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
5418            self._as_parameter_ = cast(args[0], zsock_p) # Conversion from raw type to binding
5419            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
5420        elif len(args) == 2 and type(args[0]) is zsock_p and isinstance(args[1], bool):
5421            self._as_parameter_ = args[0] # Conversion from raw type to binding
5422            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
5423        else:
5424            assert(len(args) == 1)
5425            self._as_parameter_ = lib.zsock_new(args[0]) # Creation of new raw type
5426            self.allow_destruct = True
5427
5428    def __del__(self):
5429        """
5430        Destroy the socket. You must use this for any socket created via the
5431zsock_new method.
5432        """
5433        if self.allow_destruct:
5434            lib.zsock_destroy(byref(self._as_parameter_))
5435
5436    def __eq__(self, other):
5437        if type(other) == type(self):
5438            return other.c_address() == self.c_address()
5439        elif type(other) == c_void_p:
5440            return other.value == self.c_address()
5441
5442    def c_address(self):
5443        """
5444        Return the address of the object pointer in c.  Useful for comparison.
5445        """
5446        return addressof(self._as_parameter_.contents)
5447
5448    def __bool__(self):
5449        "Determine whether the object is valid by converting to boolean" # Python 3
5450        return self._as_parameter_.__bool__()
5451
5452    def __nonzero__(self):
5453        "Determine whether the object is valid by converting to boolean" # Python 2
5454        return self._as_parameter_.__nonzero__()
5455
5456    @staticmethod
5457    def new_pub(endpoint):
5458        """
5459        Create a PUB socket. Default action is bind.
5460        """
5461        return Zsock(lib.zsock_new_pub(endpoint), True)
5462
5463    @staticmethod
5464    def new_sub(endpoint, subscribe):
5465        """
5466        Create a SUB socket, and optionally subscribe to some prefix string. Default
5467action is connect.
5468        """
5469        return Zsock(lib.zsock_new_sub(endpoint, subscribe), True)
5470
5471    @staticmethod
5472    def new_req(endpoint):
5473        """
5474        Create a REQ socket. Default action is connect.
5475        """
5476        return Zsock(lib.zsock_new_req(endpoint), True)
5477
5478    @staticmethod
5479    def new_rep(endpoint):
5480        """
5481        Create a REP socket. Default action is bind.
5482        """
5483        return Zsock(lib.zsock_new_rep(endpoint), True)
5484
5485    @staticmethod
5486    def new_dealer(endpoint):
5487        """
5488        Create a DEALER socket. Default action is connect.
5489        """
5490        return Zsock(lib.zsock_new_dealer(endpoint), True)
5491
5492    @staticmethod
5493    def new_router(endpoint):
5494        """
5495        Create a ROUTER socket. Default action is bind.
5496        """
5497        return Zsock(lib.zsock_new_router(endpoint), True)
5498
5499    @staticmethod
5500    def new_push(endpoint):
5501        """
5502        Create a PUSH socket. Default action is connect.
5503        """
5504        return Zsock(lib.zsock_new_push(endpoint), True)
5505
5506    @staticmethod
5507    def new_pull(endpoint):
5508        """
5509        Create a PULL socket. Default action is bind.
5510        """
5511        return Zsock(lib.zsock_new_pull(endpoint), True)
5512
5513    @staticmethod
5514    def new_xpub(endpoint):
5515        """
5516        Create an XPUB socket. Default action is bind.
5517        """
5518        return Zsock(lib.zsock_new_xpub(endpoint), True)
5519
5520    @staticmethod
5521    def new_xsub(endpoint):
5522        """
5523        Create an XSUB socket. Default action is connect.
5524        """
5525        return Zsock(lib.zsock_new_xsub(endpoint), True)
5526
5527    @staticmethod
5528    def new_pair(endpoint):
5529        """
5530        Create a PAIR socket. Default action is connect.
5531        """
5532        return Zsock(lib.zsock_new_pair(endpoint), True)
5533
5534    @staticmethod
5535    def new_stream(endpoint):
5536        """
5537        Create a STREAM socket. Default action is connect.
5538        """
5539        return Zsock(lib.zsock_new_stream(endpoint), True)
5540
5541    @staticmethod
5542    def new_server(endpoint):
5543        """
5544        Create a SERVER socket. Default action is bind.
5545        """
5546        return Zsock(lib.zsock_new_server(endpoint), True)
5547
5548    @staticmethod
5549    def new_client(endpoint):
5550        """
5551        Create a CLIENT socket. Default action is connect.
5552        """
5553        return Zsock(lib.zsock_new_client(endpoint), True)
5554
5555    @staticmethod
5556    def new_radio(endpoint):
5557        """
5558        Create a RADIO socket. Default action is bind.
5559        """
5560        return Zsock(lib.zsock_new_radio(endpoint), True)
5561
5562    @staticmethod
5563    def new_dish(endpoint):
5564        """
5565        Create a DISH socket. Default action is connect.
5566        """
5567        return Zsock(lib.zsock_new_dish(endpoint), True)
5568
5569    @staticmethod
5570    def new_gather(endpoint):
5571        """
5572        Create a GATHER socket. Default action is bind.
5573        """
5574        return Zsock(lib.zsock_new_gather(endpoint), True)
5575
5576    @staticmethod
5577    def new_scatter(endpoint):
5578        """
5579        Create a SCATTER socket. Default action is connect.
5580        """
5581        return Zsock(lib.zsock_new_scatter(endpoint), True)
5582
5583    def bind(self, format, *args):
5584        """
5585        Bind a socket to a formatted endpoint. For tcp:// endpoints, supports
5586ephemeral ports, if you specify the port number as "*". By default
5587zsock uses the IANA designated range from C000 (49152) to FFFF (65535).
5588To override this range, follow the "*" with "[first-last]". Either or
5589both first and last may be empty. To bind to a random port within the
5590range, use "!" in place of "*".
5591
5592Examples:
5593    tcp://127.0.0.1:*           bind to first free port from C000 up
5594    tcp://127.0.0.1:!           bind to random port from C000 to FFFF
5595    tcp://127.0.0.1:*[60000-]   bind to first free port from 60000 up
5596    tcp://127.0.0.1:![-60000]   bind to random port from C000 to 60000
5597    tcp://127.0.0.1:![55000-55999]
5598                                bind to random port from 55000 to 55999
5599
5600On success, returns the actual port number used, for tcp:// endpoints,
5601and 0 for other transports. On failure, returns -1. Note that when using
5602ephemeral ports, a port may be reused by different services without
5603clients being aware. Protocols that run on ephemeral ports should take
5604this into account.
5605        """
5606        return lib.zsock_bind(self._as_parameter_, format, *args)
5607
5608    def endpoint(self):
5609        """
5610        Returns last bound endpoint, if any.
5611        """
5612        return lib.zsock_endpoint(self._as_parameter_)
5613
5614    def unbind(self, format, *args):
5615        """
5616        Unbind a socket from a formatted endpoint.
5617Returns 0 if OK, -1 if the endpoint was invalid or the function
5618isn't supported.
5619        """
5620        return lib.zsock_unbind(self._as_parameter_, format, *args)
5621
5622    def connect(self, format, *args):
5623        """
5624        Connect a socket to a formatted endpoint
5625Returns 0 if OK, -1 if the endpoint was invalid.
5626        """
5627        return lib.zsock_connect(self._as_parameter_, format, *args)
5628
5629    def disconnect(self, format, *args):
5630        """
5631        Disconnect a socket from a formatted endpoint
5632Returns 0 if OK, -1 if the endpoint was invalid or the function
5633isn't supported.
5634        """
5635        return lib.zsock_disconnect(self._as_parameter_, format, *args)
5636
5637    def attach(self, endpoints, serverish):
5638        """
5639        Attach a socket to zero or more endpoints. If endpoints is not null,
5640parses as list of ZeroMQ endpoints, separated by commas, and prefixed by
5641'@' (to bind the socket) or '>' (to connect the socket). Returns 0 if all
5642endpoints were valid, or -1 if there was a syntax error. If the endpoint
5643does not start with '@' or '>', the serverish argument defines whether
5644it is used to bind (serverish = true) or connect (serverish = false).
5645        """
5646        return lib.zsock_attach(self._as_parameter_, endpoints, serverish)
5647
5648    def type_str(self):
5649        """
5650        Returns socket type as printable constant string.
5651        """
5652        return lib.zsock_type_str(self._as_parameter_)
5653
5654    def send(self, picture, *args):
5655        """
5656        Send a 'picture' message to the socket (or actor). The picture is a
5657string that defines the type of each frame. This makes it easy to send
5658a complex multiframe message in one call. The picture can contain any
5659of these characters, each corresponding to one or two arguments:
5660
5661    i = int (signed)
5662    1 = uint8_t
5663    2 = uint16_t
5664    4 = uint32_t
5665    8 = uint64_t
5666    s = char *
5667    b = byte *, size_t (2 arguments)
5668    c = zchunk_t *
5669    f = zframe_t *
5670    h = zhashx_t *
5671    U = zuuid_t *
5672    p = void * (sends the pointer value, only meaningful over inproc)
5673    m = zmsg_t * (sends all frames in the zmsg)
5674    z = sends zero-sized frame (0 arguments)
5675    u = uint (deprecated)
5676
5677Note that s, b, c, and f are encoded the same way and the choice is
5678offered as a convenience to the sender, which may or may not already
5679have data in a zchunk or zframe. Does not change or take ownership of
5680any arguments. Returns 0 if successful, -1 if sending failed for any
5681reason.
5682        """
5683        return lib.zsock_send(self._as_parameter_, picture, *args)
5684
5685    def vsend(self, picture, argptr):
5686        """
5687        Send a 'picture' message to the socket (or actor). This is a va_list
5688version of zsock_send (), so please consult its documentation for the
5689details.
5690        """
5691        return lib.zsock_vsend(self._as_parameter_, picture, argptr)
5692
5693    def recv(self, picture, *args):
5694        """
5695        Receive a 'picture' message to the socket (or actor). See zsock_send for
5696the format and meaning of the picture. Returns the picture elements into
5697a series of pointers as provided by the caller:
5698
5699    i = int * (stores signed integer)
5700    4 = uint32_t * (stores 32-bit unsigned integer)
5701    8 = uint64_t * (stores 64-bit unsigned integer)
5702    s = char ** (allocates new string)
5703    b = byte **, size_t * (2 arguments) (allocates memory)
5704    c = zchunk_t ** (creates zchunk)
5705    f = zframe_t ** (creates zframe)
5706    U = zuuid_t * (creates a zuuid with the data)
5707    h = zhashx_t ** (creates zhashx)
5708    p = void ** (stores pointer)
5709    m = zmsg_t ** (creates a zmsg with the remaing frames)
5710    z = null, asserts empty frame (0 arguments)
5711    u = uint * (stores unsigned integer, deprecated)
5712
5713Note that zsock_recv creates the returned objects, and the caller must
5714destroy them when finished with them. The supplied pointers do not need
5715to be initialized. Returns 0 if successful, or -1 if it failed to recv
5716a message, in which case the pointers are not modified. When message
5717frames are truncated (a short message), sets return values to zero/null.
5718If an argument pointer is NULL, does not store any value (skips it).
5719An 'n' picture matches an empty frame; if the message does not match,
5720the method will return -1.
5721        """
5722        return lib.zsock_recv(self._as_parameter_, picture, *args)
5723
5724    def vrecv(self, picture, argptr):
5725        """
5726        Receive a 'picture' message from the socket (or actor). This is a
5727va_list version of zsock_recv (), so please consult its documentation
5728for the details.
5729        """
5730        return lib.zsock_vrecv(self._as_parameter_, picture, argptr)
5731
5732    def bsend(self, picture, *args):
5733        """
5734        Send a binary encoded 'picture' message to the socket (or actor). This
5735method is similar to zsock_send, except the arguments are encoded in a
5736binary format that is compatible with zproto, and is designed to reduce
5737memory allocations. The pattern argument is a string that defines the
5738type of each argument. Supports these argument types:
5739
5740 pattern    C type                  zproto type:
5741    1       uint8_t                 type = "number" size = "1"
5742    2       uint16_t                type = "number" size = "2"
5743    4       uint32_t                type = "number" size = "3"
5744    8       uint64_t                type = "number" size = "4"
5745    s       char *, 0-255 chars     type = "string"
5746    S       char *, 0-2^32-1 chars  type = "longstr"
5747    c       zchunk_t *              type = "chunk"
5748    f       zframe_t *              type = "frame"
5749    u       zuuid_t *               type = "uuid"
5750    m       zmsg_t *                type = "msg"
5751    p       void *, sends pointer value, only over inproc
5752
5753Does not change or take ownership of any arguments. Returns 0 if
5754successful, -1 if sending failed for any reason.
5755        """
5756        return lib.zsock_bsend(self._as_parameter_, picture, *args)
5757
5758    def brecv(self, picture, *args):
5759        """
5760        Receive a binary encoded 'picture' message from the socket (or actor).
5761This method is similar to zsock_recv, except the arguments are encoded
5762in a binary format that is compatible with zproto, and is designed to
5763reduce memory allocations. The pattern argument is a string that defines
5764the type of each argument. See zsock_bsend for the supported argument
5765types. All arguments must be pointers; this call sets them to point to
5766values held on a per-socket basis.
5767For types 1, 2, 4 and 8 the caller must allocate the memory itself before
5768calling zsock_brecv.
5769For types S, the caller must free the value once finished with it, as
5770zsock_brecv will allocate the buffer.
5771For type s, the caller must not free the value as it is stored in a
5772local cache for performance purposes.
5773For types c, f, u and m the caller must call the appropriate destructor
5774depending on the object as zsock_brecv will create new objects.
5775For type p the caller must coordinate with the sender, as it is just a
5776pointer value being passed.
5777        """
5778        return lib.zsock_brecv(self._as_parameter_, picture, *args)
5779
5780    def routing_id(self):
5781        """
5782        Return socket routing ID if any. This returns 0 if the socket is not
5783of type ZMQ_SERVER or if no request was already received on it.
5784        """
5785        return lib.zsock_routing_id(self._as_parameter_)
5786
5787    def set_routing_id(self, routing_id):
5788        """
5789        Set routing ID on socket. The socket MUST be of type ZMQ_SERVER.
5790This will be used when sending messages on the socket via the zsock API.
5791        """
5792        return lib.zsock_set_routing_id(self._as_parameter_, routing_id)
5793
5794    def set_unbounded(self):
5795        """
5796        Set socket to use unbounded pipes (HWM=0); use this in cases when you are
5797totally certain the message volume can fit in memory. This method works
5798across all versions of ZeroMQ. Takes a polymorphic socket reference.
5799        """
5800        return lib.zsock_set_unbounded(self._as_parameter_)
5801
5802    def signal(self, status):
5803        """
5804        Send a signal over a socket. A signal is a short message carrying a
5805success/failure code (by convention, 0 means OK). Signals are encoded
5806to be distinguishable from "normal" messages. Accepts a zsock_t or a
5807zactor_t argument, and returns 0 if successful, -1 if the signal could
5808not be sent. Takes a polymorphic socket reference.
5809        """
5810        return lib.zsock_signal(self._as_parameter_, status)
5811
5812    def wait(self):
5813        """
5814        Wait on a signal. Use this to coordinate between threads, over pipe
5815pairs. Blocks until the signal is received. Returns -1 on error, 0 or
5816greater on success. Accepts a zsock_t or a zactor_t as argument.
5817Takes a polymorphic socket reference.
5818        """
5819        return lib.zsock_wait(self._as_parameter_)
5820
5821    def flush(self):
5822        """
5823        If there is a partial message still waiting on the socket, remove and
5824discard it. This is useful when reading partial messages, to get specific
5825message types.
5826        """
5827        return lib.zsock_flush(self._as_parameter_)
5828
5829    def join(self, group):
5830        """
5831        Join a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
5832Returns 0 if OK, -1 if failed.
5833        """
5834        return lib.zsock_join(self._as_parameter_, group)
5835
5836    def leave(self, group):
5837        """
5838        Leave a group for the RADIO-DISH pattern. Call only on ZMQ_DISH.
5839Returns 0 if OK, -1 if failed.
5840        """
5841        return lib.zsock_leave(self._as_parameter_, group)
5842
5843    @staticmethod
5844    def is_(self):
5845        """
5846        Probe the supplied object, and report if it looks like a zsock_t.
5847Takes a polymorphic socket reference.
5848        """
5849        return lib.zsock_is(self)
5850
5851    @staticmethod
5852    def resolve(self):
5853        """
5854        Probe the supplied reference. If it looks like a zsock_t instance, return
5855the underlying libzmq socket handle; else if it looks like a file
5856descriptor, return NULL; else if it looks like a libzmq socket handle,
5857return the supplied value. Takes a polymorphic socket reference.
5858        """
5859        return c_void_p(lib.zsock_resolve(self))
5860
5861    def heartbeat_ivl(self):
5862        """
5863        Get socket option `heartbeat_ivl`.
5864Available from libzmq 4.2.0.
5865        """
5866        return lib.zsock_heartbeat_ivl(self._as_parameter_)
5867
5868    def set_heartbeat_ivl(self, heartbeat_ivl):
5869        """
5870        Set socket option `heartbeat_ivl`.
5871Available from libzmq 4.2.0.
5872        """
5873        return lib.zsock_set_heartbeat_ivl(self._as_parameter_, heartbeat_ivl)
5874
5875    def heartbeat_ttl(self):
5876        """
5877        Get socket option `heartbeat_ttl`.
5878Available from libzmq 4.2.0.
5879        """
5880        return lib.zsock_heartbeat_ttl(self._as_parameter_)
5881
5882    def set_heartbeat_ttl(self, heartbeat_ttl):
5883        """
5884        Set socket option `heartbeat_ttl`.
5885Available from libzmq 4.2.0.
5886        """
5887        return lib.zsock_set_heartbeat_ttl(self._as_parameter_, heartbeat_ttl)
5888
5889    def heartbeat_timeout(self):
5890        """
5891        Get socket option `heartbeat_timeout`.
5892Available from libzmq 4.2.0.
5893        """
5894        return lib.zsock_heartbeat_timeout(self._as_parameter_)
5895
5896    def set_heartbeat_timeout(self, heartbeat_timeout):
5897        """
5898        Set socket option `heartbeat_timeout`.
5899Available from libzmq 4.2.0.
5900        """
5901        return lib.zsock_set_heartbeat_timeout(self._as_parameter_, heartbeat_timeout)
5902
5903    def use_fd(self):
5904        """
5905        Get socket option `use_fd`.
5906Available from libzmq 4.2.0.
5907        """
5908        return lib.zsock_use_fd(self._as_parameter_)
5909
5910    def set_use_fd(self, use_fd):
5911        """
5912        Set socket option `use_fd`.
5913Available from libzmq 4.2.0.
5914        """
5915        return lib.zsock_set_use_fd(self._as_parameter_, use_fd)
5916
5917    def set_xpub_manual(self, xpub_manual):
5918        """
5919        Set socket option `xpub_manual`.
5920Available from libzmq 4.2.0.
5921        """
5922        return lib.zsock_set_xpub_manual(self._as_parameter_, xpub_manual)
5923
5924    def set_xpub_welcome_msg(self, xpub_welcome_msg):
5925        """
5926        Set socket option `xpub_welcome_msg`.
5927Available from libzmq 4.2.0.
5928        """
5929        return lib.zsock_set_xpub_welcome_msg(self._as_parameter_, xpub_welcome_msg)
5930
5931    def set_stream_notify(self, stream_notify):
5932        """
5933        Set socket option `stream_notify`.
5934Available from libzmq 4.2.0.
5935        """
5936        return lib.zsock_set_stream_notify(self._as_parameter_, stream_notify)
5937
5938    def invert_matching(self):
5939        """
5940        Get socket option `invert_matching`.
5941Available from libzmq 4.2.0.
5942        """
5943        return lib.zsock_invert_matching(self._as_parameter_)
5944
5945    def set_invert_matching(self, invert_matching):
5946        """
5947        Set socket option `invert_matching`.
5948Available from libzmq 4.2.0.
5949        """
5950        return lib.zsock_set_invert_matching(self._as_parameter_, invert_matching)
5951
5952    def set_xpub_verboser(self, xpub_verboser):
5953        """
5954        Set socket option `xpub_verboser`.
5955Available from libzmq 4.2.0.
5956        """
5957        return lib.zsock_set_xpub_verboser(self._as_parameter_, xpub_verboser)
5958
5959    def connect_timeout(self):
5960        """
5961        Get socket option `connect_timeout`.
5962Available from libzmq 4.2.0.
5963        """
5964        return lib.zsock_connect_timeout(self._as_parameter_)
5965
5966    def set_connect_timeout(self, connect_timeout):
5967        """
5968        Set socket option `connect_timeout`.
5969Available from libzmq 4.2.0.
5970        """
5971        return lib.zsock_set_connect_timeout(self._as_parameter_, connect_timeout)
5972
5973    def tcp_maxrt(self):
5974        """
5975        Get socket option `tcp_maxrt`.
5976Available from libzmq 4.2.0.
5977        """
5978        return lib.zsock_tcp_maxrt(self._as_parameter_)
5979
5980    def set_tcp_maxrt(self, tcp_maxrt):
5981        """
5982        Set socket option `tcp_maxrt`.
5983Available from libzmq 4.2.0.
5984        """
5985        return lib.zsock_set_tcp_maxrt(self._as_parameter_, tcp_maxrt)
5986
5987    def thread_safe(self):
5988        """
5989        Get socket option `thread_safe`.
5990Available from libzmq 4.2.0.
5991        """
5992        return lib.zsock_thread_safe(self._as_parameter_)
5993
5994    def multicast_maxtpdu(self):
5995        """
5996        Get socket option `multicast_maxtpdu`.
5997Available from libzmq 4.2.0.
5998        """
5999        return lib.zsock_multicast_maxtpdu(self._as_parameter_)
6000
6001    def set_multicast_maxtpdu(self, multicast_maxtpdu):
6002        """
6003        Set socket option `multicast_maxtpdu`.
6004Available from libzmq 4.2.0.
6005        """
6006        return lib.zsock_set_multicast_maxtpdu(self._as_parameter_, multicast_maxtpdu)
6007
6008    def vmci_buffer_size(self):
6009        """
6010        Get socket option `vmci_buffer_size`.
6011Available from libzmq 4.2.0.
6012        """
6013        return lib.zsock_vmci_buffer_size(self._as_parameter_)
6014
6015    def set_vmci_buffer_size(self, vmci_buffer_size):
6016        """
6017        Set socket option `vmci_buffer_size`.
6018Available from libzmq 4.2.0.
6019        """
6020        return lib.zsock_set_vmci_buffer_size(self._as_parameter_, vmci_buffer_size)
6021
6022    def vmci_buffer_min_size(self):
6023        """
6024        Get socket option `vmci_buffer_min_size`.
6025Available from libzmq 4.2.0.
6026        """
6027        return lib.zsock_vmci_buffer_min_size(self._as_parameter_)
6028
6029    def set_vmci_buffer_min_size(self, vmci_buffer_min_size):
6030        """
6031        Set socket option `vmci_buffer_min_size`.
6032Available from libzmq 4.2.0.
6033        """
6034        return lib.zsock_set_vmci_buffer_min_size(self._as_parameter_, vmci_buffer_min_size)
6035
6036    def vmci_buffer_max_size(self):
6037        """
6038        Get socket option `vmci_buffer_max_size`.
6039Available from libzmq 4.2.0.
6040        """
6041        return lib.zsock_vmci_buffer_max_size(self._as_parameter_)
6042
6043    def set_vmci_buffer_max_size(self, vmci_buffer_max_size):
6044        """
6045        Set socket option `vmci_buffer_max_size`.
6046Available from libzmq 4.2.0.
6047        """
6048        return lib.zsock_set_vmci_buffer_max_size(self._as_parameter_, vmci_buffer_max_size)
6049
6050    def vmci_connect_timeout(self):
6051        """
6052        Get socket option `vmci_connect_timeout`.
6053Available from libzmq 4.2.0.
6054        """
6055        return lib.zsock_vmci_connect_timeout(self._as_parameter_)
6056
6057    def set_vmci_connect_timeout(self, vmci_connect_timeout):
6058        """
6059        Set socket option `vmci_connect_timeout`.
6060Available from libzmq 4.2.0.
6061        """
6062        return lib.zsock_set_vmci_connect_timeout(self._as_parameter_, vmci_connect_timeout)
6063
6064    def tos(self):
6065        """
6066        Get socket option `tos`.
6067Available from libzmq 4.1.0.
6068        """
6069        return lib.zsock_tos(self._as_parameter_)
6070
6071    def set_tos(self, tos):
6072        """
6073        Set socket option `tos`.
6074Available from libzmq 4.1.0.
6075        """
6076        return lib.zsock_set_tos(self._as_parameter_, tos)
6077
6078    def set_router_handover(self, router_handover):
6079        """
6080        Set socket option `router_handover`.
6081Available from libzmq 4.1.0.
6082        """
6083        return lib.zsock_set_router_handover(self._as_parameter_, router_handover)
6084
6085    def set_connect_rid(self, connect_rid):
6086        """
6087        Set socket option `connect_rid`.
6088Available from libzmq 4.1.0.
6089        """
6090        return lib.zsock_set_connect_rid(self._as_parameter_, connect_rid)
6091
6092    def set_connect_rid_bin(self, connect_rid):
6093        """
6094        Set socket option `connect_rid` from 32-octet binary
6095Available from libzmq 4.1.0.
6096        """
6097        return lib.zsock_set_connect_rid_bin(self._as_parameter_, connect_rid)
6098
6099    def handshake_ivl(self):
6100        """
6101        Get socket option `handshake_ivl`.
6102Available from libzmq 4.1.0.
6103        """
6104        return lib.zsock_handshake_ivl(self._as_parameter_)
6105
6106    def set_handshake_ivl(self, handshake_ivl):
6107        """
6108        Set socket option `handshake_ivl`.
6109Available from libzmq 4.1.0.
6110        """
6111        return lib.zsock_set_handshake_ivl(self._as_parameter_, handshake_ivl)
6112
6113    def socks_proxy(self):
6114        """
6115        Get socket option `socks_proxy`.
6116Available from libzmq 4.1.0.
6117        """
6118        return return_fresh_string(lib.zsock_socks_proxy(self._as_parameter_))
6119
6120    def set_socks_proxy(self, socks_proxy):
6121        """
6122        Set socket option `socks_proxy`.
6123Available from libzmq 4.1.0.
6124        """
6125        return lib.zsock_set_socks_proxy(self._as_parameter_, socks_proxy)
6126
6127    def set_xpub_nodrop(self, xpub_nodrop):
6128        """
6129        Set socket option `xpub_nodrop`.
6130Available from libzmq 4.1.0.
6131        """
6132        return lib.zsock_set_xpub_nodrop(self._as_parameter_, xpub_nodrop)
6133
6134    def set_router_mandatory(self, router_mandatory):
6135        """
6136        Set socket option `router_mandatory`.
6137Available from libzmq 4.0.0.
6138        """
6139        return lib.zsock_set_router_mandatory(self._as_parameter_, router_mandatory)
6140
6141    def set_probe_router(self, probe_router):
6142        """
6143        Set socket option `probe_router`.
6144Available from libzmq 4.0.0.
6145        """
6146        return lib.zsock_set_probe_router(self._as_parameter_, probe_router)
6147
6148    def set_req_relaxed(self, req_relaxed):
6149        """
6150        Set socket option `req_relaxed`.
6151Available from libzmq 4.0.0.
6152        """
6153        return lib.zsock_set_req_relaxed(self._as_parameter_, req_relaxed)
6154
6155    def set_req_correlate(self, req_correlate):
6156        """
6157        Set socket option `req_correlate`.
6158Available from libzmq 4.0.0.
6159        """
6160        return lib.zsock_set_req_correlate(self._as_parameter_, req_correlate)
6161
6162    def set_conflate(self, conflate):
6163        """
6164        Set socket option `conflate`.
6165Available from libzmq 4.0.0.
6166        """
6167        return lib.zsock_set_conflate(self._as_parameter_, conflate)
6168
6169    def zap_domain(self):
6170        """
6171        Get socket option `zap_domain`.
6172Available from libzmq 4.0.0.
6173        """
6174        return return_fresh_string(lib.zsock_zap_domain(self._as_parameter_))
6175
6176    def set_zap_domain(self, zap_domain):
6177        """
6178        Set socket option `zap_domain`.
6179Available from libzmq 4.0.0.
6180        """
6181        return lib.zsock_set_zap_domain(self._as_parameter_, zap_domain)
6182
6183    def mechanism(self):
6184        """
6185        Get socket option `mechanism`.
6186Available from libzmq 4.0.0.
6187        """
6188        return lib.zsock_mechanism(self._as_parameter_)
6189
6190    def plain_server(self):
6191        """
6192        Get socket option `plain_server`.
6193Available from libzmq 4.0.0.
6194        """
6195        return lib.zsock_plain_server(self._as_parameter_)
6196
6197    def set_plain_server(self, plain_server):
6198        """
6199        Set socket option `plain_server`.
6200Available from libzmq 4.0.0.
6201        """
6202        return lib.zsock_set_plain_server(self._as_parameter_, plain_server)
6203
6204    def plain_username(self):
6205        """
6206        Get socket option `plain_username`.
6207Available from libzmq 4.0.0.
6208        """
6209        return return_fresh_string(lib.zsock_plain_username(self._as_parameter_))
6210
6211    def set_plain_username(self, plain_username):
6212        """
6213        Set socket option `plain_username`.
6214Available from libzmq 4.0.0.
6215        """
6216        return lib.zsock_set_plain_username(self._as_parameter_, plain_username)
6217
6218    def plain_password(self):
6219        """
6220        Get socket option `plain_password`.
6221Available from libzmq 4.0.0.
6222        """
6223        return return_fresh_string(lib.zsock_plain_password(self._as_parameter_))
6224
6225    def set_plain_password(self, plain_password):
6226        """
6227        Set socket option `plain_password`.
6228Available from libzmq 4.0.0.
6229        """
6230        return lib.zsock_set_plain_password(self._as_parameter_, plain_password)
6231
6232    def curve_server(self):
6233        """
6234        Get socket option `curve_server`.
6235Available from libzmq 4.0.0.
6236        """
6237        return lib.zsock_curve_server(self._as_parameter_)
6238
6239    def set_curve_server(self, curve_server):
6240        """
6241        Set socket option `curve_server`.
6242Available from libzmq 4.0.0.
6243        """
6244        return lib.zsock_set_curve_server(self._as_parameter_, curve_server)
6245
6246    def curve_publickey(self):
6247        """
6248        Get socket option `curve_publickey`.
6249Available from libzmq 4.0.0.
6250        """
6251        return return_fresh_string(lib.zsock_curve_publickey(self._as_parameter_))
6252
6253    def set_curve_publickey(self, curve_publickey):
6254        """
6255        Set socket option `curve_publickey`.
6256Available from libzmq 4.0.0.
6257        """
6258        return lib.zsock_set_curve_publickey(self._as_parameter_, curve_publickey)
6259
6260    def set_curve_publickey_bin(self, curve_publickey):
6261        """
6262        Set socket option `curve_publickey` from 32-octet binary
6263Available from libzmq 4.0.0.
6264        """
6265        return lib.zsock_set_curve_publickey_bin(self._as_parameter_, curve_publickey)
6266
6267    def curve_secretkey(self):
6268        """
6269        Get socket option `curve_secretkey`.
6270Available from libzmq 4.0.0.
6271        """
6272        return return_fresh_string(lib.zsock_curve_secretkey(self._as_parameter_))
6273
6274    def set_curve_secretkey(self, curve_secretkey):
6275        """
6276        Set socket option `curve_secretkey`.
6277Available from libzmq 4.0.0.
6278        """
6279        return lib.zsock_set_curve_secretkey(self._as_parameter_, curve_secretkey)
6280
6281    def set_curve_secretkey_bin(self, curve_secretkey):
6282        """
6283        Set socket option `curve_secretkey` from 32-octet binary
6284Available from libzmq 4.0.0.
6285        """
6286        return lib.zsock_set_curve_secretkey_bin(self._as_parameter_, curve_secretkey)
6287
6288    def curve_serverkey(self):
6289        """
6290        Get socket option `curve_serverkey`.
6291Available from libzmq 4.0.0.
6292        """
6293        return return_fresh_string(lib.zsock_curve_serverkey(self._as_parameter_))
6294
6295    def set_curve_serverkey(self, curve_serverkey):
6296        """
6297        Set socket option `curve_serverkey`.
6298Available from libzmq 4.0.0.
6299        """
6300        return lib.zsock_set_curve_serverkey(self._as_parameter_, curve_serverkey)
6301
6302    def set_curve_serverkey_bin(self, curve_serverkey):
6303        """
6304        Set socket option `curve_serverkey` from 32-octet binary
6305Available from libzmq 4.0.0.
6306        """
6307        return lib.zsock_set_curve_serverkey_bin(self._as_parameter_, curve_serverkey)
6308
6309    def gssapi_server(self):
6310        """
6311        Get socket option `gssapi_server`.
6312Available from libzmq 4.0.0.
6313        """
6314        return lib.zsock_gssapi_server(self._as_parameter_)
6315
6316    def set_gssapi_server(self, gssapi_server):
6317        """
6318        Set socket option `gssapi_server`.
6319Available from libzmq 4.0.0.
6320        """
6321        return lib.zsock_set_gssapi_server(self._as_parameter_, gssapi_server)
6322
6323    def gssapi_plaintext(self):
6324        """
6325        Get socket option `gssapi_plaintext`.
6326Available from libzmq 4.0.0.
6327        """
6328        return lib.zsock_gssapi_plaintext(self._as_parameter_)
6329
6330    def set_gssapi_plaintext(self, gssapi_plaintext):
6331        """
6332        Set socket option `gssapi_plaintext`.
6333Available from libzmq 4.0.0.
6334        """
6335        return lib.zsock_set_gssapi_plaintext(self._as_parameter_, gssapi_plaintext)
6336
6337    def gssapi_principal(self):
6338        """
6339        Get socket option `gssapi_principal`.
6340Available from libzmq 4.0.0.
6341        """
6342        return return_fresh_string(lib.zsock_gssapi_principal(self._as_parameter_))
6343
6344    def set_gssapi_principal(self, gssapi_principal):
6345        """
6346        Set socket option `gssapi_principal`.
6347Available from libzmq 4.0.0.
6348        """
6349        return lib.zsock_set_gssapi_principal(self._as_parameter_, gssapi_principal)
6350
6351    def gssapi_service_principal(self):
6352        """
6353        Get socket option `gssapi_service_principal`.
6354Available from libzmq 4.0.0.
6355        """
6356        return return_fresh_string(lib.zsock_gssapi_service_principal(self._as_parameter_))
6357
6358    def set_gssapi_service_principal(self, gssapi_service_principal):
6359        """
6360        Set socket option `gssapi_service_principal`.
6361Available from libzmq 4.0.0.
6362        """
6363        return lib.zsock_set_gssapi_service_principal(self._as_parameter_, gssapi_service_principal)
6364
6365    def ipv6(self):
6366        """
6367        Get socket option `ipv6`.
6368Available from libzmq 4.0.0.
6369        """
6370        return lib.zsock_ipv6(self._as_parameter_)
6371
6372    def set_ipv6(self, ipv6):
6373        """
6374        Set socket option `ipv6`.
6375Available from libzmq 4.0.0.
6376        """
6377        return lib.zsock_set_ipv6(self._as_parameter_, ipv6)
6378
6379    def immediate(self):
6380        """
6381        Get socket option `immediate`.
6382Available from libzmq 4.0.0.
6383        """
6384        return lib.zsock_immediate(self._as_parameter_)
6385
6386    def set_immediate(self, immediate):
6387        """
6388        Set socket option `immediate`.
6389Available from libzmq 4.0.0.
6390        """
6391        return lib.zsock_set_immediate(self._as_parameter_, immediate)
6392
6393    def sndhwm(self):
6394        """
6395        Get socket option `sndhwm`.
6396Available from libzmq 3.0.0.
6397        """
6398        return lib.zsock_sndhwm(self._as_parameter_)
6399
6400    def set_sndhwm(self, sndhwm):
6401        """
6402        Set socket option `sndhwm`.
6403Available from libzmq 3.0.0.
6404        """
6405        return lib.zsock_set_sndhwm(self._as_parameter_, sndhwm)
6406
6407    def rcvhwm(self):
6408        """
6409        Get socket option `rcvhwm`.
6410Available from libzmq 3.0.0.
6411        """
6412        return lib.zsock_rcvhwm(self._as_parameter_)
6413
6414    def set_rcvhwm(self, rcvhwm):
6415        """
6416        Set socket option `rcvhwm`.
6417Available from libzmq 3.0.0.
6418        """
6419        return lib.zsock_set_rcvhwm(self._as_parameter_, rcvhwm)
6420
6421    def maxmsgsize(self):
6422        """
6423        Get socket option `maxmsgsize`.
6424Available from libzmq 3.0.0.
6425        """
6426        return lib.zsock_maxmsgsize(self._as_parameter_)
6427
6428    def set_maxmsgsize(self, maxmsgsize):
6429        """
6430        Set socket option `maxmsgsize`.
6431Available from libzmq 3.0.0.
6432        """
6433        return lib.zsock_set_maxmsgsize(self._as_parameter_, maxmsgsize)
6434
6435    def multicast_hops(self):
6436        """
6437        Get socket option `multicast_hops`.
6438Available from libzmq 3.0.0.
6439        """
6440        return lib.zsock_multicast_hops(self._as_parameter_)
6441
6442    def set_multicast_hops(self, multicast_hops):
6443        """
6444        Set socket option `multicast_hops`.
6445Available from libzmq 3.0.0.
6446        """
6447        return lib.zsock_set_multicast_hops(self._as_parameter_, multicast_hops)
6448
6449    def set_xpub_verbose(self, xpub_verbose):
6450        """
6451        Set socket option `xpub_verbose`.
6452Available from libzmq 3.0.0.
6453        """
6454        return lib.zsock_set_xpub_verbose(self._as_parameter_, xpub_verbose)
6455
6456    def tcp_keepalive(self):
6457        """
6458        Get socket option `tcp_keepalive`.
6459Available from libzmq 3.0.0.
6460        """
6461        return lib.zsock_tcp_keepalive(self._as_parameter_)
6462
6463    def set_tcp_keepalive(self, tcp_keepalive):
6464        """
6465        Set socket option `tcp_keepalive`.
6466Available from libzmq 3.0.0.
6467        """
6468        return lib.zsock_set_tcp_keepalive(self._as_parameter_, tcp_keepalive)
6469
6470    def tcp_keepalive_idle(self):
6471        """
6472        Get socket option `tcp_keepalive_idle`.
6473Available from libzmq 3.0.0.
6474        """
6475        return lib.zsock_tcp_keepalive_idle(self._as_parameter_)
6476
6477    def set_tcp_keepalive_idle(self, tcp_keepalive_idle):
6478        """
6479        Set socket option `tcp_keepalive_idle`.
6480Available from libzmq 3.0.0.
6481        """
6482        return lib.zsock_set_tcp_keepalive_idle(self._as_parameter_, tcp_keepalive_idle)
6483
6484    def tcp_keepalive_cnt(self):
6485        """
6486        Get socket option `tcp_keepalive_cnt`.
6487Available from libzmq 3.0.0.
6488        """
6489        return lib.zsock_tcp_keepalive_cnt(self._as_parameter_)
6490
6491    def set_tcp_keepalive_cnt(self, tcp_keepalive_cnt):
6492        """
6493        Set socket option `tcp_keepalive_cnt`.
6494Available from libzmq 3.0.0.
6495        """
6496        return lib.zsock_set_tcp_keepalive_cnt(self._as_parameter_, tcp_keepalive_cnt)
6497
6498    def tcp_keepalive_intvl(self):
6499        """
6500        Get socket option `tcp_keepalive_intvl`.
6501Available from libzmq 3.0.0.
6502        """
6503        return lib.zsock_tcp_keepalive_intvl(self._as_parameter_)
6504
6505    def set_tcp_keepalive_intvl(self, tcp_keepalive_intvl):
6506        """
6507        Set socket option `tcp_keepalive_intvl`.
6508Available from libzmq 3.0.0.
6509        """
6510        return lib.zsock_set_tcp_keepalive_intvl(self._as_parameter_, tcp_keepalive_intvl)
6511
6512    def tcp_accept_filter(self):
6513        """
6514        Get socket option `tcp_accept_filter`.
6515Available from libzmq 3.0.0.
6516        """
6517        return return_fresh_string(lib.zsock_tcp_accept_filter(self._as_parameter_))
6518
6519    def set_tcp_accept_filter(self, tcp_accept_filter):
6520        """
6521        Set socket option `tcp_accept_filter`.
6522Available from libzmq 3.0.0.
6523        """
6524        return lib.zsock_set_tcp_accept_filter(self._as_parameter_, tcp_accept_filter)
6525
6526    def last_endpoint(self):
6527        """
6528        Get socket option `last_endpoint`.
6529Available from libzmq 3.0.0.
6530        """
6531        return return_fresh_string(lib.zsock_last_endpoint(self._as_parameter_))
6532
6533    def set_router_raw(self, router_raw):
6534        """
6535        Set socket option `router_raw`.
6536Available from libzmq 3.0.0.
6537        """
6538        return lib.zsock_set_router_raw(self._as_parameter_, router_raw)
6539
6540    def ipv4only(self):
6541        """
6542        Get socket option `ipv4only`.
6543Available from libzmq 3.0.0.
6544        """
6545        return lib.zsock_ipv4only(self._as_parameter_)
6546
6547    def set_ipv4only(self, ipv4only):
6548        """
6549        Set socket option `ipv4only`.
6550Available from libzmq 3.0.0.
6551        """
6552        return lib.zsock_set_ipv4only(self._as_parameter_, ipv4only)
6553
6554    def set_delay_attach_on_connect(self, delay_attach_on_connect):
6555        """
6556        Set socket option `delay_attach_on_connect`.
6557Available from libzmq 3.0.0.
6558        """
6559        return lib.zsock_set_delay_attach_on_connect(self._as_parameter_, delay_attach_on_connect)
6560
6561    def hwm(self):
6562        """
6563        Get socket option `hwm`.
6564Available from libzmq 2.0.0 to 3.0.0.
6565        """
6566        return lib.zsock_hwm(self._as_parameter_)
6567
6568    def set_hwm(self, hwm):
6569        """
6570        Set socket option `hwm`.
6571Available from libzmq 2.0.0 to 3.0.0.
6572        """
6573        return lib.zsock_set_hwm(self._as_parameter_, hwm)
6574
6575    def swap(self):
6576        """
6577        Get socket option `swap`.
6578Available from libzmq 2.0.0 to 3.0.0.
6579        """
6580        return lib.zsock_swap(self._as_parameter_)
6581
6582    def set_swap(self, swap):
6583        """
6584        Set socket option `swap`.
6585Available from libzmq 2.0.0 to 3.0.0.
6586        """
6587        return lib.zsock_set_swap(self._as_parameter_, swap)
6588
6589    def affinity(self):
6590        """
6591        Get socket option `affinity`.
6592Available from libzmq 2.0.0.
6593        """
6594        return lib.zsock_affinity(self._as_parameter_)
6595
6596    def set_affinity(self, affinity):
6597        """
6598        Set socket option `affinity`.
6599Available from libzmq 2.0.0.
6600        """
6601        return lib.zsock_set_affinity(self._as_parameter_, affinity)
6602
6603    def identity(self):
6604        """
6605        Get socket option `identity`.
6606Available from libzmq 2.0.0.
6607        """
6608        return return_fresh_string(lib.zsock_identity(self._as_parameter_))
6609
6610    def set_identity(self, identity):
6611        """
6612        Set socket option `identity`.
6613Available from libzmq 2.0.0.
6614        """
6615        return lib.zsock_set_identity(self._as_parameter_, identity)
6616
6617    def rate(self):
6618        """
6619        Get socket option `rate`.
6620Available from libzmq 2.0.0.
6621        """
6622        return lib.zsock_rate(self._as_parameter_)
6623
6624    def set_rate(self, rate):
6625        """
6626        Set socket option `rate`.
6627Available from libzmq 2.0.0.
6628        """
6629        return lib.zsock_set_rate(self._as_parameter_, rate)
6630
6631    def recovery_ivl(self):
6632        """
6633        Get socket option `recovery_ivl`.
6634Available from libzmq 2.0.0.
6635        """
6636        return lib.zsock_recovery_ivl(self._as_parameter_)
6637
6638    def set_recovery_ivl(self, recovery_ivl):
6639        """
6640        Set socket option `recovery_ivl`.
6641Available from libzmq 2.0.0.
6642        """
6643        return lib.zsock_set_recovery_ivl(self._as_parameter_, recovery_ivl)
6644
6645    def recovery_ivl_msec(self):
6646        """
6647        Get socket option `recovery_ivl_msec`.
6648Available from libzmq 2.0.0 to 3.0.0.
6649        """
6650        return lib.zsock_recovery_ivl_msec(self._as_parameter_)
6651
6652    def set_recovery_ivl_msec(self, recovery_ivl_msec):
6653        """
6654        Set socket option `recovery_ivl_msec`.
6655Available from libzmq 2.0.0 to 3.0.0.
6656        """
6657        return lib.zsock_set_recovery_ivl_msec(self._as_parameter_, recovery_ivl_msec)
6658
6659    def mcast_loop(self):
6660        """
6661        Get socket option `mcast_loop`.
6662Available from libzmq 2.0.0 to 3.0.0.
6663        """
6664        return lib.zsock_mcast_loop(self._as_parameter_)
6665
6666    def set_mcast_loop(self, mcast_loop):
6667        """
6668        Set socket option `mcast_loop`.
6669Available from libzmq 2.0.0 to 3.0.0.
6670        """
6671        return lib.zsock_set_mcast_loop(self._as_parameter_, mcast_loop)
6672
6673    def rcvtimeo(self):
6674        """
6675        Get socket option `rcvtimeo`.
6676Available from libzmq 2.2.0.
6677        """
6678        return lib.zsock_rcvtimeo(self._as_parameter_)
6679
6680    def set_rcvtimeo(self, rcvtimeo):
6681        """
6682        Set socket option `rcvtimeo`.
6683Available from libzmq 2.2.0.
6684        """
6685        return lib.zsock_set_rcvtimeo(self._as_parameter_, rcvtimeo)
6686
6687    def sndtimeo(self):
6688        """
6689        Get socket option `sndtimeo`.
6690Available from libzmq 2.2.0.
6691        """
6692        return lib.zsock_sndtimeo(self._as_parameter_)
6693
6694    def set_sndtimeo(self, sndtimeo):
6695        """
6696        Set socket option `sndtimeo`.
6697Available from libzmq 2.2.0.
6698        """
6699        return lib.zsock_set_sndtimeo(self._as_parameter_, sndtimeo)
6700
6701    def sndbuf(self):
6702        """
6703        Get socket option `sndbuf`.
6704Available from libzmq 2.0.0.
6705        """
6706        return lib.zsock_sndbuf(self._as_parameter_)
6707
6708    def set_sndbuf(self, sndbuf):
6709        """
6710        Set socket option `sndbuf`.
6711Available from libzmq 2.0.0.
6712        """
6713        return lib.zsock_set_sndbuf(self._as_parameter_, sndbuf)
6714
6715    def rcvbuf(self):
6716        """
6717        Get socket option `rcvbuf`.
6718Available from libzmq 2.0.0.
6719        """
6720        return lib.zsock_rcvbuf(self._as_parameter_)
6721
6722    def set_rcvbuf(self, rcvbuf):
6723        """
6724        Set socket option `rcvbuf`.
6725Available from libzmq 2.0.0.
6726        """
6727        return lib.zsock_set_rcvbuf(self._as_parameter_, rcvbuf)
6728
6729    def linger(self):
6730        """
6731        Get socket option `linger`.
6732Available from libzmq 2.0.0.
6733        """
6734        return lib.zsock_linger(self._as_parameter_)
6735
6736    def set_linger(self, linger):
6737        """
6738        Set socket option `linger`.
6739Available from libzmq 2.0.0.
6740        """
6741        return lib.zsock_set_linger(self._as_parameter_, linger)
6742
6743    def reconnect_ivl(self):
6744        """
6745        Get socket option `reconnect_ivl`.
6746Available from libzmq 2.0.0.
6747        """
6748        return lib.zsock_reconnect_ivl(self._as_parameter_)
6749
6750    def set_reconnect_ivl(self, reconnect_ivl):
6751        """
6752        Set socket option `reconnect_ivl`.
6753Available from libzmq 2.0.0.
6754        """
6755        return lib.zsock_set_reconnect_ivl(self._as_parameter_, reconnect_ivl)
6756
6757    def reconnect_ivl_max(self):
6758        """
6759        Get socket option `reconnect_ivl_max`.
6760Available from libzmq 2.0.0.
6761        """
6762        return lib.zsock_reconnect_ivl_max(self._as_parameter_)
6763
6764    def set_reconnect_ivl_max(self, reconnect_ivl_max):
6765        """
6766        Set socket option `reconnect_ivl_max`.
6767Available from libzmq 2.0.0.
6768        """
6769        return lib.zsock_set_reconnect_ivl_max(self._as_parameter_, reconnect_ivl_max)
6770
6771    def backlog(self):
6772        """
6773        Get socket option `backlog`.
6774Available from libzmq 2.0.0.
6775        """
6776        return lib.zsock_backlog(self._as_parameter_)
6777
6778    def set_backlog(self, backlog):
6779        """
6780        Set socket option `backlog`.
6781Available from libzmq 2.0.0.
6782        """
6783        return lib.zsock_set_backlog(self._as_parameter_, backlog)
6784
6785    def set_subscribe(self, subscribe):
6786        """
6787        Set socket option `subscribe`.
6788Available from libzmq 2.0.0.
6789        """
6790        return lib.zsock_set_subscribe(self._as_parameter_, subscribe)
6791
6792    def set_unsubscribe(self, unsubscribe):
6793        """
6794        Set socket option `unsubscribe`.
6795Available from libzmq 2.0.0.
6796        """
6797        return lib.zsock_set_unsubscribe(self._as_parameter_, unsubscribe)
6798
6799    def type(self):
6800        """
6801        Get socket option `type`.
6802Available from libzmq 2.0.0.
6803        """
6804        return lib.zsock_type(self._as_parameter_)
6805
6806    def rcvmore(self):
6807        """
6808        Get socket option `rcvmore`.
6809Available from libzmq 2.0.0.
6810        """
6811        return lib.zsock_rcvmore(self._as_parameter_)
6812
6813    def fd(self):
6814        """
6815        Get socket option `fd`.
6816Available from libzmq 2.0.0.
6817        """
6818        return lib.zsock_fd(self._as_parameter_)
6819
6820    def events(self):
6821        """
6822        Get socket option `events`.
6823Available from libzmq 2.0.0.
6824        """
6825        return lib.zsock_events(self._as_parameter_)
6826
6827    @staticmethod
6828    def test(verbose):
6829        """
6830        Self test of this class.
6831        """
6832        return lib.zsock_test(verbose)
6833
6834
6835# zstr
6836lib.zstr_recv.restype = POINTER(c_char)
6837lib.zstr_recv.argtypes = [c_void_p]
6838lib.zstr_recvx.restype = c_int
6839lib.zstr_recvx.argtypes = [c_void_p, POINTER(c_char_p)]
6840lib.zstr_recv_compress.restype = POINTER(c_char)
6841lib.zstr_recv_compress.argtypes = [c_void_p]
6842lib.zstr_send.restype = c_int
6843lib.zstr_send.argtypes = [c_void_p, c_char_p]
6844lib.zstr_sendm.restype = c_int
6845lib.zstr_sendm.argtypes = [c_void_p, c_char_p]
6846lib.zstr_sendf.restype = c_int
6847lib.zstr_sendf.argtypes = [c_void_p, c_char_p]
6848lib.zstr_sendfm.restype = c_int
6849lib.zstr_sendfm.argtypes = [c_void_p, c_char_p]
6850lib.zstr_sendx.restype = c_int
6851lib.zstr_sendx.argtypes = [c_void_p, c_char_p]
6852lib.zstr_send_compress.restype = c_int
6853lib.zstr_send_compress.argtypes = [c_void_p, c_char_p]
6854lib.zstr_sendm_compress.restype = c_int
6855lib.zstr_sendm_compress.argtypes = [c_void_p, c_char_p]
6856lib.zstr_str.restype = POINTER(c_char)
6857lib.zstr_str.argtypes = [c_void_p]
6858lib.zstr_free.restype = None
6859lib.zstr_free.argtypes = [POINTER(c_char_p)]
6860lib.zstr_test.restype = None
6861lib.zstr_test.argtypes = [c_bool]
6862
6863class Zstr(object):
6864    """
6865    sending and receiving strings
6866    """
6867
6868    allow_destruct = False
6869    def __eq__(self, other):
6870        if type(other) == type(self):
6871            return other.c_address() == self.c_address()
6872        elif type(other) == c_void_p:
6873            return other.value == self.c_address()
6874
6875    def c_address(self):
6876        """
6877        Return the address of the object pointer in c.  Useful for comparison.
6878        """
6879        return addressof(self._as_parameter_.contents)
6880
6881    def __bool__(self):
6882        "Determine whether the object is valid by converting to boolean" # Python 3
6883        return self._as_parameter_.__bool__()
6884
6885    def __nonzero__(self):
6886        "Determine whether the object is valid by converting to boolean" # Python 2
6887        return self._as_parameter_.__nonzero__()
6888
6889    @staticmethod
6890    def recv(source):
6891        """
6892        Receive C string from socket. Caller must free returned string using
6893zstr_free(). Returns NULL if the context is being terminated or the
6894process was interrupted.
6895        """
6896        return return_fresh_string(lib.zstr_recv(source))
6897
6898    @staticmethod
6899    def recvx(source, string_p, *args):
6900        """
6901        Receive a series of strings (until NULL) from multipart data.
6902Each string is allocated and filled with string data; if there
6903are not enough frames, unallocated strings are set to NULL.
6904Returns -1 if the message could not be read, else returns the
6905number of strings filled, zero or more. Free each returned string
6906using zstr_free(). If not enough strings are provided, remaining
6907multipart frames in the message are dropped.
6908        """
6909        return lib.zstr_recvx(source, byref(c_char_p.from_param(string_p)), *args)
6910
6911    @staticmethod
6912    def recv_compress(source):
6913        """
6914        De-compress and receive C string from socket, received as a message
6915with two frames: size of the uncompressed string, and the string itself.
6916Caller must free returned string using zstr_free(). Returns NULL if the
6917context is being terminated or the process was interrupted.
6918        """
6919        return return_fresh_string(lib.zstr_recv_compress(source))
6920
6921    @staticmethod
6922    def send(dest, string):
6923        """
6924        Send a C string to a socket, as a frame. The string is sent without
6925trailing null byte; to read this you can use zstr_recv, or a similar
6926method that adds a null terminator on the received string. String
6927may be NULL, which is sent as "".
6928        """
6929        return lib.zstr_send(dest, string)
6930
6931    @staticmethod
6932    def sendm(dest, string):
6933        """
6934        Send a C string to a socket, as zstr_send(), with a MORE flag, so that
6935you can send further strings in the same multi-part message.
6936        """
6937        return lib.zstr_sendm(dest, string)
6938
6939    @staticmethod
6940    def sendf(dest, format, *args):
6941        """
6942        Send a formatted string to a socket. Note that you should NOT use
6943user-supplied strings in the format (they may contain '%' which
6944will create security holes).
6945        """
6946        return lib.zstr_sendf(dest, format, *args)
6947
6948    @staticmethod
6949    def sendfm(dest, format, *args):
6950        """
6951        Send a formatted string to a socket, as for zstr_sendf(), with a
6952MORE flag, so that you can send further strings in the same multi-part
6953message.
6954        """
6955        return lib.zstr_sendfm(dest, format, *args)
6956
6957    @staticmethod
6958    def sendx(dest, string, *args):
6959        """
6960        Send a series of strings (until NULL) as multipart data
6961Returns 0 if the strings could be sent OK, or -1 on error.
6962        """
6963        return lib.zstr_sendx(dest, string, *args)
6964
6965    @staticmethod
6966    def send_compress(dest, string):
6967        """
6968        Compress and send a C string to a socket, as a message with two frames:
6969size of the uncompressed string, and the string itself. The string is
6970sent without trailing null byte; to read this you can use
6971zstr_recv_compress, or a similar method that de-compresses and adds a
6972null terminator on the received string.
6973        """
6974        return lib.zstr_send_compress(dest, string)
6975
6976    @staticmethod
6977    def sendm_compress(dest, string):
6978        """
6979        Compress and send a C string to a socket, as zstr_send_compress(),
6980with a MORE flag, so that you can send further strings in the same
6981multi-part message.
6982        """
6983        return lib.zstr_sendm_compress(dest, string)
6984
6985    @staticmethod
6986    def str(source):
6987        """
6988        Accepts a void pointer and returns a fresh character string. If source
6989is null, returns an empty string.
6990        """
6991        return return_fresh_string(lib.zstr_str(source))
6992
6993    @staticmethod
6994    def free(string_p):
6995        """
6996        Free a provided string, and nullify the parent pointer. Safe to call on
6997a null pointer.
6998        """
6999        return lib.zstr_free(byref(c_char_p.from_param(string_p)))
7000
7001    @staticmethod
7002    def test(verbose):
7003        """
7004        Self test of this class.
7005        """
7006        return lib.zstr_test(verbose)
7007
7008
7009# zsys
7010zsys_handler_fn = CFUNCTYPE(None, c_int)
7011lib.zsys_init.restype = c_void_p
7012lib.zsys_init.argtypes = []
7013lib.zsys_shutdown.restype = None
7014lib.zsys_shutdown.argtypes = []
7015lib.zsys_socket.restype = c_void_p
7016lib.zsys_socket.argtypes = [c_int, c_char_p, c_size_t]
7017lib.zsys_close.restype = c_int
7018lib.zsys_close.argtypes = [c_void_p, c_char_p, c_size_t]
7019lib.zsys_sockname.restype = c_char_p
7020lib.zsys_sockname.argtypes = [c_int]
7021lib.zsys_create_pipe.restype = zsock_p
7022lib.zsys_create_pipe.argtypes = [POINTER(zsock_p)]
7023lib.zsys_handler_set.restype = None
7024lib.zsys_handler_set.argtypes = [POINTER(zsys_handler_fn)]
7025lib.zsys_handler_reset.restype = None
7026lib.zsys_handler_reset.argtypes = []
7027lib.zsys_catch_interrupts.restype = None
7028lib.zsys_catch_interrupts.argtypes = []
7029lib.zsys_is_interrupted.restype = c_bool
7030lib.zsys_is_interrupted.argtypes = []
7031lib.zsys_set_interrupted.restype = None
7032lib.zsys_set_interrupted.argtypes = []
7033lib.zsys_file_exists.restype = c_bool
7034lib.zsys_file_exists.argtypes = [c_char_p]
7035lib.zsys_file_modified.restype = c_int
7036lib.zsys_file_modified.argtypes = [c_char_p]
7037lib.zsys_file_mode.restype = c_int
7038lib.zsys_file_mode.argtypes = [c_char_p]
7039lib.zsys_file_delete.restype = c_int
7040lib.zsys_file_delete.argtypes = [c_char_p]
7041lib.zsys_file_stable.restype = c_bool
7042lib.zsys_file_stable.argtypes = [c_char_p]
7043lib.zsys_dir_create.restype = c_int
7044lib.zsys_dir_create.argtypes = [c_char_p]
7045lib.zsys_dir_delete.restype = c_int
7046lib.zsys_dir_delete.argtypes = [c_char_p]
7047lib.zsys_dir_change.restype = c_int
7048lib.zsys_dir_change.argtypes = [c_char_p]
7049lib.zsys_file_mode_private.restype = None
7050lib.zsys_file_mode_private.argtypes = []
7051lib.zsys_file_mode_default.restype = None
7052lib.zsys_file_mode_default.argtypes = []
7053lib.zsys_version.restype = None
7054lib.zsys_version.argtypes = [POINTER(c_int), POINTER(c_int), POINTER(c_int)]
7055lib.zsys_sprintf.restype = c_char_p
7056lib.zsys_sprintf.argtypes = [c_char_p]
7057lib.zsys_vprintf.restype = c_char_p
7058lib.zsys_vprintf.argtypes = [c_char_p, va_list_p]
7059lib.zsys_udp_new.restype = socket_p
7060lib.zsys_udp_new.argtypes = [c_bool]
7061lib.zsys_udp_close.restype = c_int
7062lib.zsys_udp_close.argtypes = [socket_p]
7063lib.zsys_udp_send.restype = c_int
7064lib.zsys_udp_send.argtypes = [socket_p, zframe_p, c_void_p, c_int]
7065lib.zsys_udp_recv.restype = zframe_p
7066lib.zsys_udp_recv.argtypes = [socket_p, c_char_p, c_int]
7067lib.zsys_socket_error.restype = None
7068lib.zsys_socket_error.argtypes = [c_char_p]
7069lib.zsys_hostname.restype = c_char_p
7070lib.zsys_hostname.argtypes = []
7071lib.zsys_daemonize.restype = c_int
7072lib.zsys_daemonize.argtypes = [c_char_p]
7073lib.zsys_run_as.restype = c_int
7074lib.zsys_run_as.argtypes = [c_char_p, c_char_p, c_char_p]
7075lib.zsys_has_curve.restype = c_bool
7076lib.zsys_has_curve.argtypes = []
7077lib.zsys_set_io_threads.restype = None
7078lib.zsys_set_io_threads.argtypes = [c_size_t]
7079lib.zsys_set_thread_sched_policy.restype = None
7080lib.zsys_set_thread_sched_policy.argtypes = [c_int]
7081lib.zsys_set_thread_priority.restype = None
7082lib.zsys_set_thread_priority.argtypes = [c_int]
7083lib.zsys_set_max_sockets.restype = None
7084lib.zsys_set_max_sockets.argtypes = [c_size_t]
7085lib.zsys_socket_limit.restype = c_size_t
7086lib.zsys_socket_limit.argtypes = []
7087lib.zsys_set_max_msgsz.restype = None
7088lib.zsys_set_max_msgsz.argtypes = [c_int]
7089lib.zsys_max_msgsz.restype = c_int
7090lib.zsys_max_msgsz.argtypes = []
7091lib.zsys_set_zero_copy_recv.restype = None
7092lib.zsys_set_zero_copy_recv.argtypes = [c_int]
7093lib.zsys_zero_copy_recv.restype = c_int
7094lib.zsys_zero_copy_recv.argtypes = []
7095lib.zsys_set_file_stable_age_msec.restype = None
7096lib.zsys_set_file_stable_age_msec.argtypes = [msecs_p]
7097lib.zsys_file_stable_age_msec.restype = msecs_p
7098lib.zsys_file_stable_age_msec.argtypes = []
7099lib.zsys_set_linger.restype = None
7100lib.zsys_set_linger.argtypes = [c_size_t]
7101lib.zsys_set_sndhwm.restype = None
7102lib.zsys_set_sndhwm.argtypes = [c_size_t]
7103lib.zsys_set_rcvhwm.restype = None
7104lib.zsys_set_rcvhwm.argtypes = [c_size_t]
7105lib.zsys_set_pipehwm.restype = None
7106lib.zsys_set_pipehwm.argtypes = [c_size_t]
7107lib.zsys_pipehwm.restype = c_size_t
7108lib.zsys_pipehwm.argtypes = []
7109lib.zsys_set_ipv6.restype = None
7110lib.zsys_set_ipv6.argtypes = [c_int]
7111lib.zsys_ipv6.restype = c_int
7112lib.zsys_ipv6.argtypes = []
7113lib.zsys_set_interface.restype = None
7114lib.zsys_set_interface.argtypes = [c_char_p]
7115lib.zsys_interface.restype = c_char_p
7116lib.zsys_interface.argtypes = []
7117lib.zsys_set_ipv6_address.restype = None
7118lib.zsys_set_ipv6_address.argtypes = [c_char_p]
7119lib.zsys_ipv6_address.restype = c_char_p
7120lib.zsys_ipv6_address.argtypes = []
7121lib.zsys_set_ipv6_mcast_address.restype = None
7122lib.zsys_set_ipv6_mcast_address.argtypes = [c_char_p]
7123lib.zsys_ipv6_mcast_address.restype = c_char_p
7124lib.zsys_ipv6_mcast_address.argtypes = []
7125lib.zsys_set_auto_use_fd.restype = None
7126lib.zsys_set_auto_use_fd.argtypes = [c_int]
7127lib.zsys_auto_use_fd.restype = c_int
7128lib.zsys_auto_use_fd.argtypes = []
7129lib.zsys_set_logident.restype = None
7130lib.zsys_set_logident.argtypes = [c_char_p]
7131lib.zsys_set_logstream.restype = None
7132lib.zsys_set_logstream.argtypes = [FILE_p]
7133lib.zsys_set_logsender.restype = None
7134lib.zsys_set_logsender.argtypes = [c_char_p]
7135lib.zsys_set_logsystem.restype = None
7136lib.zsys_set_logsystem.argtypes = [c_bool]
7137lib.zsys_error.restype = None
7138lib.zsys_error.argtypes = [c_char_p]
7139lib.zsys_warning.restype = None
7140lib.zsys_warning.argtypes = [c_char_p]
7141lib.zsys_notice.restype = None
7142lib.zsys_notice.argtypes = [c_char_p]
7143lib.zsys_info.restype = None
7144lib.zsys_info.argtypes = [c_char_p]
7145lib.zsys_debug.restype = None
7146lib.zsys_debug.argtypes = [c_char_p]
7147lib.zsys_test.restype = None
7148lib.zsys_test.argtypes = [c_bool]
7149
7150class Zsys(object):
7151    """
7152
7153    """
7154
7155    allow_destruct = False
7156    def __eq__(self, other):
7157        if type(other) == type(self):
7158            return other.c_address() == self.c_address()
7159        elif type(other) == c_void_p:
7160            return other.value == self.c_address()
7161
7162    def c_address(self):
7163        """
7164        Return the address of the object pointer in c.  Useful for comparison.
7165        """
7166        return addressof(self._as_parameter_.contents)
7167
7168    def __bool__(self):
7169        "Determine whether the object is valid by converting to boolean" # Python 3
7170        return self._as_parameter_.__bool__()
7171
7172    def __nonzero__(self):
7173        "Determine whether the object is valid by converting to boolean" # Python 2
7174        return self._as_parameter_.__nonzero__()
7175
7176    @staticmethod
7177    def init():
7178        """
7179        Initialize CZMQ zsys layer; this happens automatically when you create
7180a socket or an actor; however this call lets you force initialization
7181earlier, so e.g. logging is properly set-up before you start working.
7182Not threadsafe, so call only from main thread. Safe to call multiple
7183times. Returns global CZMQ context.
7184        """
7185        return c_void_p(lib.zsys_init())
7186
7187    @staticmethod
7188    def shutdown():
7189        """
7190        Optionally shut down the CZMQ zsys layer; this normally happens automatically
7191when the process exits; however this call lets you force a shutdown
7192earlier, avoiding any potential problems with atexit() ordering, especially
7193with Windows dlls.
7194        """
7195        return lib.zsys_shutdown()
7196
7197    @staticmethod
7198    def socket(type, filename, line_nbr):
7199        """
7200        Get a new ZMQ socket, automagically creating a ZMQ context if this is
7201the first time. Caller is responsible for destroying the ZMQ socket
7202before process exits, to avoid a ZMQ deadlock. Note: you should not use
7203this method in CZMQ apps, use zsock_new() instead.
7204*** This is for CZMQ internal use only and may change arbitrarily ***
7205        """
7206        return c_void_p(lib.zsys_socket(type, filename, line_nbr))
7207
7208    @staticmethod
7209    def close(handle, filename, line_nbr):
7210        """
7211        Destroy/close a ZMQ socket. You should call this for every socket you
7212create using zsys_socket().
7213*** This is for CZMQ internal use only and may change arbitrarily ***
7214        """
7215        return lib.zsys_close(handle, filename, line_nbr)
7216
7217    @staticmethod
7218    def sockname(socktype):
7219        """
7220        Return ZMQ socket name for socket type
7221*** This is for CZMQ internal use only and may change arbitrarily ***
7222        """
7223        return lib.zsys_sockname(socktype)
7224
7225    @staticmethod
7226    def create_pipe(backend_p):
7227        """
7228        Create a pipe, which consists of two PAIR sockets connected over inproc.
7229The pipe is configured to use the zsys_pipehwm setting. Returns the
7230frontend socket successful, NULL if failed.
7231        """
7232        return Zsock(lib.zsys_create_pipe(byref(zsock_p.from_param(backend_p))), False)
7233
7234    @staticmethod
7235    def handler_set(handler_fn):
7236        """
7237        Set interrupt handler; this saves the default handlers so that a
7238zsys_handler_reset () can restore them. If you call this multiple times
7239then the last handler will take affect. If handler_fn is NULL, disables
7240default SIGINT/SIGTERM handling in CZMQ.
7241        """
7242        return lib.zsys_handler_set(byref(zsys_handler_fn.from_param(handler_fn)))
7243
7244    @staticmethod
7245    def handler_reset():
7246        """
7247        Reset interrupt handler, call this at exit if needed
7248        """
7249        return lib.zsys_handler_reset()
7250
7251    @staticmethod
7252    def catch_interrupts():
7253        """
7254        Set default interrupt handler, so Ctrl-C or SIGTERM will set
7255zsys_interrupted. Idempotent; safe to call multiple times.
7256Can be supressed by ZSYS_SIGHANDLER=false
7257*** This is for CZMQ internal use only and may change arbitrarily ***
7258        """
7259        return lib.zsys_catch_interrupts()
7260
7261    @staticmethod
7262    def is_interrupted():
7263        """
7264        Check if default interrupt handler of Ctrl-C or SIGTERM was called.
7265Does not work if ZSYS_SIGHANDLER is false and code does not call
7266set interrupted on signal.
7267        """
7268        return lib.zsys_is_interrupted()
7269
7270    @staticmethod
7271    def set_interrupted():
7272        """
7273        Set interrupted flag. This is done by default signal handler, however
7274this can be handy for language bindings or cases without default
7275signal handler.
7276        """
7277        return lib.zsys_set_interrupted()
7278
7279    @staticmethod
7280    def file_exists(filename):
7281        """
7282        Return 1 if file exists, else zero
7283        """
7284        return lib.zsys_file_exists(filename)
7285
7286    @staticmethod
7287    def file_modified(filename):
7288        """
7289        Return file modification time. Returns 0 if the file does not exist.
7290        """
7291        return lib.zsys_file_modified(filename)
7292
7293    @staticmethod
7294    def file_mode(filename):
7295        """
7296        Return file mode; provides at least support for the POSIX S_ISREG(m)
7297and S_ISDIR(m) macros and the S_IRUSR and S_IWUSR bits, on all boxes.
7298Returns a mode_t cast to int, or -1 in case of error.
7299        """
7300        return lib.zsys_file_mode(filename)
7301
7302    @staticmethod
7303    def file_delete(filename):
7304        """
7305        Delete file. Does not complain if the file is absent
7306        """
7307        return lib.zsys_file_delete(filename)
7308
7309    @staticmethod
7310    def file_stable(filename):
7311        """
7312        Check if file is 'stable'
7313        """
7314        return lib.zsys_file_stable(filename)
7315
7316    @staticmethod
7317    def dir_create(pathname, *args):
7318        """
7319        Create a file path if it doesn't exist. The file path is treated as
7320printf format.
7321        """
7322        return lib.zsys_dir_create(pathname, *args)
7323
7324    @staticmethod
7325    def dir_delete(pathname, *args):
7326        """
7327        Remove a file path if empty; the pathname is treated as printf format.
7328        """
7329        return lib.zsys_dir_delete(pathname, *args)
7330
7331    @staticmethod
7332    def dir_change(pathname):
7333        """
7334        Move to a specified working directory. Returns 0 if OK, -1 if this failed.
7335        """
7336        return lib.zsys_dir_change(pathname)
7337
7338    @staticmethod
7339    def file_mode_private():
7340        """
7341        Set private file creation mode; all files created from here will be
7342readable/writable by the owner only.
7343        """
7344        return lib.zsys_file_mode_private()
7345
7346    @staticmethod
7347    def file_mode_default():
7348        """
7349        Reset default file creation mode; all files created from here will use
7350process file mode defaults.
7351        """
7352        return lib.zsys_file_mode_default()
7353
7354    @staticmethod
7355    def version(major, minor, patch):
7356        """
7357        Return the CZMQ version for run-time API detection; returns version
7358number into provided fields, providing reference isn't null in each case.
7359        """
7360        return lib.zsys_version(byref(c_int.from_param(major)), byref(c_int.from_param(minor)), byref(c_int.from_param(patch)))
7361
7362    @staticmethod
7363    def sprintf(format, *args):
7364        """
7365        Format a string using printf formatting, returning a freshly allocated
7366buffer. If there was insufficient memory, returns NULL. Free the returned
7367string using zstr_free().
7368        """
7369        return lib.zsys_sprintf(format, *args)
7370
7371    @staticmethod
7372    def vprintf(format, argptr):
7373        """
7374        Format a string with a va_list argument, returning a freshly allocated
7375buffer. If there was insufficient memory, returns NULL. Free the returned
7376string using zstr_free().
7377        """
7378        return lib.zsys_vprintf(format, argptr)
7379
7380    @staticmethod
7381    def udp_new(routable):
7382        """
7383        Create UDP beacon socket; if the routable option is true, uses
7384multicast (not yet implemented), else uses broadcast. This method
7385and related ones might _eventually_ be moved to a zudp class.
7386*** This is for CZMQ internal use only and may change arbitrarily ***
7387        """
7388        return lib.zsys_udp_new(routable)
7389
7390    @staticmethod
7391    def udp_close(handle):
7392        """
7393        Close a UDP socket
7394*** This is for CZMQ internal use only and may change arbitrarily ***
7395        """
7396        return lib.zsys_udp_close(handle)
7397
7398    @staticmethod
7399    def udp_send(udpsock, frame, address, addrlen):
7400        """
7401        Send zframe to UDP socket, return -1 if sending failed due to
7402interface having disappeared (happens easily with WiFi)
7403*** This is for CZMQ internal use only and may change arbitrarily ***
7404        """
7405        return lib.zsys_udp_send(udpsock, frame, address, addrlen)
7406
7407    @staticmethod
7408    def udp_recv(udpsock, peername, peerlen):
7409        """
7410        Receive zframe from UDP socket, and set address of peer that sent it
7411The peername must be a char [INET_ADDRSTRLEN] array if IPv6 is disabled or
7412NI_MAXHOST if it's enabled. Returns NULL when failing to get peer address.
7413*** This is for CZMQ internal use only and may change arbitrarily ***
7414        """
7415        return Zframe(lib.zsys_udp_recv(udpsock, peername, peerlen), False)
7416
7417    @staticmethod
7418    def socket_error(reason):
7419        """
7420        Handle an I/O error on some socket operation; will report and die on
7421fatal errors, and continue silently on "try again" errors.
7422*** This is for CZMQ internal use only and may change arbitrarily ***
7423        """
7424        return lib.zsys_socket_error(reason)
7425
7426    @staticmethod
7427    def hostname():
7428        """
7429        Return current host name, for use in public tcp:// endpoints. Caller gets
7430a freshly allocated string, should free it using zstr_free(). If the host
7431name is not resolvable, returns NULL.
7432        """
7433        return lib.zsys_hostname()
7434
7435    @staticmethod
7436    def daemonize(workdir):
7437        """
7438        Move the current process into the background. The precise effect depends
7439on the operating system. On POSIX boxes, moves to a specified working
7440directory (if specified), closes all file handles, reopens stdin, stdout,
7441and stderr to the null device, and sets the process to ignore SIGHUP. On
7442Windows, does nothing. Returns 0 if OK, -1 if there was an error.
7443        """
7444        return lib.zsys_daemonize(workdir)
7445
7446    @staticmethod
7447    def run_as(lockfile, group, user):
7448        """
7449        Drop the process ID into the lockfile, with exclusive lock, and switch
7450the process to the specified group and/or user. Any of the arguments
7451may be null, indicating a no-op. Returns 0 on success, -1 on failure.
7452Note if you combine this with zsys_daemonize, run after, not before
7453that method, or the lockfile will hold the wrong process ID.
7454        """
7455        return lib.zsys_run_as(lockfile, group, user)
7456
7457    @staticmethod
7458    def has_curve():
7459        """
7460        Returns true if the underlying libzmq supports CURVE security.
7461Uses a heuristic probe according to the version of libzmq being used.
7462        """
7463        return lib.zsys_has_curve()
7464
7465    @staticmethod
7466    def set_io_threads(io_threads):
7467        """
7468        Configure the number of I/O threads that ZeroMQ will use. A good
7469rule of thumb is one thread per gigabit of traffic in or out. The
7470default is 1, sufficient for most applications. If the environment
7471variable ZSYS_IO_THREADS is defined, that provides the default.
7472Note that this method is valid only before any socket is created.
7473        """
7474        return lib.zsys_set_io_threads(io_threads)
7475
7476    @staticmethod
7477    def set_thread_sched_policy(policy):
7478        """
7479        Configure the scheduling policy of the ZMQ context thread pool.
7480Not available on Windows. See the sched_setscheduler man page or sched.h
7481for more information. If the environment variable ZSYS_THREAD_SCHED_POLICY
7482is defined, that provides the default.
7483Note that this method is valid only before any socket is created.
7484        """
7485        return lib.zsys_set_thread_sched_policy(policy)
7486
7487    @staticmethod
7488    def set_thread_priority(priority):
7489        """
7490        Configure the scheduling priority of the ZMQ context thread pool.
7491Not available on Windows. See the sched_setscheduler man page or sched.h
7492for more information. If the environment variable ZSYS_THREAD_PRIORITY is
7493defined, that provides the default.
7494Note that this method is valid only before any socket is created.
7495        """
7496        return lib.zsys_set_thread_priority(priority)
7497
7498    @staticmethod
7499    def set_max_sockets(max_sockets):
7500        """
7501        Configure the number of sockets that ZeroMQ will allow. The default
7502is 1024. The actual limit depends on the system, and you can query it
7503by using zsys_socket_limit (). A value of zero means "maximum".
7504Note that this method is valid only before any socket is created.
7505        """
7506        return lib.zsys_set_max_sockets(max_sockets)
7507
7508    @staticmethod
7509    def socket_limit():
7510        """
7511        Return maximum number of ZeroMQ sockets that the system will support.
7512        """
7513        return lib.zsys_socket_limit()
7514
7515    @staticmethod
7516    def set_max_msgsz(max_msgsz):
7517        """
7518        Configure the maximum allowed size of a message sent.
7519The default is INT_MAX.
7520        """
7521        return lib.zsys_set_max_msgsz(max_msgsz)
7522
7523    @staticmethod
7524    def max_msgsz():
7525        """
7526        Return maximum message size.
7527        """
7528        return lib.zsys_max_msgsz()
7529
7530    @staticmethod
7531    def set_zero_copy_recv(zero_copy):
7532        """
7533        Configure whether to use zero copy strategy in libzmq. If the environment
7534variable ZSYS_ZERO_COPY_RECV is defined, that provides the default.
7535Otherwise the default is 1.
7536        """
7537        return lib.zsys_set_zero_copy_recv(zero_copy)
7538
7539    @staticmethod
7540    def zero_copy_recv():
7541        """
7542        Return ZMQ_ZERO_COPY_RECV option.
7543        """
7544        return lib.zsys_zero_copy_recv()
7545
7546    @staticmethod
7547    def set_file_stable_age_msec(file_stable_age_msec):
7548        """
7549        Configure the threshold value of filesystem object age per st_mtime
7550that should elapse until we consider that object "stable" at the
7551current zclock_time() moment.
7552The default is S_DEFAULT_ZSYS_FILE_STABLE_AGE_MSEC defined in zsys.c
7553which generally depends on host OS, with fallback value of 5000.
7554        """
7555        return lib.zsys_set_file_stable_age_msec(file_stable_age_msec)
7556
7557    @staticmethod
7558    def file_stable_age_msec():
7559        """
7560        Return current threshold value of file stable age in msec.
7561This can be used in code that chooses to wait for this timeout
7562before testing if a filesystem object is "stable" or not.
7563        """
7564        return lib.zsys_file_stable_age_msec()
7565
7566    @staticmethod
7567    def set_linger(linger):
7568        """
7569        Configure the default linger timeout in msecs for new zsock instances.
7570You can also set this separately on each zsock_t instance. The default
7571linger time is zero, i.e. any pending messages will be dropped. If the
7572environment variable ZSYS_LINGER is defined, that provides the default.
7573Note that process exit will typically be delayed by the linger time.
7574        """
7575        return lib.zsys_set_linger(linger)
7576
7577    @staticmethod
7578    def set_sndhwm(sndhwm):
7579        """
7580        Configure the default outgoing pipe limit (HWM) for new zsock instances.
7581You can also set this separately on each zsock_t instance. The default
7582HWM is 1,000, on all versions of ZeroMQ. If the environment variable
7583ZSYS_SNDHWM is defined, that provides the default. Note that a value of
7584zero means no limit, i.e. infinite memory consumption.
7585        """
7586        return lib.zsys_set_sndhwm(sndhwm)
7587
7588    @staticmethod
7589    def set_rcvhwm(rcvhwm):
7590        """
7591        Configure the default incoming pipe limit (HWM) for new zsock instances.
7592You can also set this separately on each zsock_t instance. The default
7593HWM is 1,000, on all versions of ZeroMQ. If the environment variable
7594ZSYS_RCVHWM is defined, that provides the default. Note that a value of
7595zero means no limit, i.e. infinite memory consumption.
7596        """
7597        return lib.zsys_set_rcvhwm(rcvhwm)
7598
7599    @staticmethod
7600    def set_pipehwm(pipehwm):
7601        """
7602        Configure the default HWM for zactor internal pipes; this is set on both
7603ends of the pipe, for outgoing messages only (sndhwm). The default HWM is
76041,000, on all versions of ZeroMQ. If the environment var ZSYS_ACTORHWM is
7605defined, that provides the default. Note that a value of zero means no
7606limit, i.e. infinite memory consumption.
7607        """
7608        return lib.zsys_set_pipehwm(pipehwm)
7609
7610    @staticmethod
7611    def pipehwm():
7612        """
7613        Return the HWM for zactor internal pipes.
7614        """
7615        return lib.zsys_pipehwm()
7616
7617    @staticmethod
7618    def set_ipv6(ipv6):
7619        """
7620        Configure use of IPv6 for new zsock instances. By default sockets accept
7621and make only IPv4 connections. When you enable IPv6, sockets will accept
7622and connect to both IPv4 and IPv6 peers. You can override the setting on
7623each zsock_t instance. The default is IPv4 only (ipv6 set to 0). If the
7624environment variable ZSYS_IPV6 is defined (as 1 or 0), this provides the
7625default. Note: has no effect on ZMQ v2.
7626        """
7627        return lib.zsys_set_ipv6(ipv6)
7628
7629    @staticmethod
7630    def ipv6():
7631        """
7632        Return use of IPv6 for zsock instances.
7633        """
7634        return lib.zsys_ipv6()
7635
7636    @staticmethod
7637    def set_interface(value):
7638        """
7639        Set network interface name to use for broadcasts, particularly zbeacon.
7640This lets the interface be configured for test environments where required.
7641For example, on Mac OS X, zbeacon cannot bind to 255.255.255.255 which is
7642the default when there is no specified interface. If the environment
7643variable ZSYS_INTERFACE is set, use that as the default interface name.
7644Setting the interface to "*" means "use all available interfaces".
7645        """
7646        return lib.zsys_set_interface(value)
7647
7648    @staticmethod
7649    def interface():
7650        """
7651        Return network interface to use for broadcasts, or "" if none was set.
7652        """
7653        return lib.zsys_interface()
7654
7655    @staticmethod
7656    def set_ipv6_address(value):
7657        """
7658        Set IPv6 address to use zbeacon socket, particularly for receiving zbeacon.
7659This needs to be set IPv6 is enabled as IPv6 can have multiple addresses
7660on a given interface. If the environment variable ZSYS_IPV6_ADDRESS is set,
7661use that as the default IPv6 address.
7662        """
7663        return lib.zsys_set_ipv6_address(value)
7664
7665    @staticmethod
7666    def ipv6_address():
7667        """
7668        Return IPv6 address to use for zbeacon reception, or "" if none was set.
7669        """
7670        return lib.zsys_ipv6_address()
7671
7672    @staticmethod
7673    def set_ipv6_mcast_address(value):
7674        """
7675        Set IPv6 milticast address to use for sending zbeacon messages. This needs
7676to be set if IPv6 is enabled. If the environment variable
7677ZSYS_IPV6_MCAST_ADDRESS is set, use that as the default IPv6 multicast
7678address.
7679        """
7680        return lib.zsys_set_ipv6_mcast_address(value)
7681
7682    @staticmethod
7683    def ipv6_mcast_address():
7684        """
7685        Return IPv6 multicast address to use for sending zbeacon, or "" if none was
7686set.
7687        """
7688        return lib.zsys_ipv6_mcast_address()
7689
7690    @staticmethod
7691    def set_auto_use_fd(auto_use_fd):
7692        """
7693        Configure the automatic use of pre-allocated FDs when creating new sockets.
7694If 0 (default), nothing will happen. Else, when a new socket is bound, the
7695system API will be used to check if an existing pre-allocated FD with a
7696matching port (if TCP) or path (if IPC) exists, and if it does it will be
7697set via the ZMQ_USE_FD socket option so that the library will use it
7698instead of creating a new socket.
7699        """
7700        return lib.zsys_set_auto_use_fd(auto_use_fd)
7701
7702    @staticmethod
7703    def auto_use_fd():
7704        """
7705        Return use of automatic pre-allocated FDs for zsock instances.
7706        """
7707        return lib.zsys_auto_use_fd()
7708
7709    @staticmethod
7710    def set_logident(value):
7711        """
7712        Set log identity, which is a string that prefixes all log messages sent
7713by this process. The log identity defaults to the environment variable
7714ZSYS_LOGIDENT, if that is set.
7715        """
7716        return lib.zsys_set_logident(value)
7717
7718    @staticmethod
7719    def set_logstream(stream):
7720        """
7721        Set stream to receive log traffic. By default, log traffic is sent to
7722stdout. If you set the stream to NULL, no stream will receive the log
7723traffic (it may still be sent to the system facility).
7724        """
7725        return lib.zsys_set_logstream(coerce_py_file(stream))
7726
7727    @staticmethod
7728    def set_logsender(endpoint):
7729        """
7730        Sends log output to a PUB socket bound to the specified endpoint. To
7731collect such log output, create a SUB socket, subscribe to the traffic
7732you care about, and connect to the endpoint. Log traffic is sent as a
7733single string frame, in the same format as when sent to stdout. The
7734log system supports a single sender; multiple calls to this method will
7735bind the same sender to multiple endpoints. To disable the sender, call
7736this method with a null argument.
7737        """
7738        return lib.zsys_set_logsender(endpoint)
7739
7740    @staticmethod
7741    def set_logsystem(logsystem):
7742        """
7743        Enable or disable logging to the system facility (syslog on POSIX boxes,
7744event log on Windows). By default this is disabled.
7745        """
7746        return lib.zsys_set_logsystem(logsystem)
7747
7748    @staticmethod
7749    def error(format, *args):
7750        """
7751        Log error condition - highest priority
7752        """
7753        return lib.zsys_error(format, *args)
7754
7755    @staticmethod
7756    def warning(format, *args):
7757        """
7758        Log warning condition - high priority
7759        """
7760        return lib.zsys_warning(format, *args)
7761
7762    @staticmethod
7763    def notice(format, *args):
7764        """
7765        Log normal, but significant, condition - normal priority
7766        """
7767        return lib.zsys_notice(format, *args)
7768
7769    @staticmethod
7770    def info(format, *args):
7771        """
7772        Log informational message - low priority
7773        """
7774        return lib.zsys_info(format, *args)
7775
7776    @staticmethod
7777    def debug(format, *args):
7778        """
7779        Log debug-level message - lowest priority
7780        """
7781        return lib.zsys_debug(format, *args)
7782
7783    @staticmethod
7784    def test(verbose):
7785        """
7786        Self test of this class.
7787        """
7788        return lib.zsys_test(verbose)
7789
7790
7791# ztimerset
7792ztimerset_fn = CFUNCTYPE(None, c_int, c_void_p)
7793lib.ztimerset_new.restype = ztimerset_p
7794lib.ztimerset_new.argtypes = []
7795lib.ztimerset_destroy.restype = None
7796lib.ztimerset_destroy.argtypes = [POINTER(ztimerset_p)]
7797lib.ztimerset_add.restype = c_int
7798lib.ztimerset_add.argtypes = [ztimerset_p, c_size_t, ztimerset_fn, c_void_p]
7799lib.ztimerset_cancel.restype = c_int
7800lib.ztimerset_cancel.argtypes = [ztimerset_p, c_int]
7801lib.ztimerset_set_interval.restype = c_int
7802lib.ztimerset_set_interval.argtypes = [ztimerset_p, c_int, c_size_t]
7803lib.ztimerset_reset.restype = c_int
7804lib.ztimerset_reset.argtypes = [ztimerset_p, c_int]
7805lib.ztimerset_timeout.restype = c_int
7806lib.ztimerset_timeout.argtypes = [ztimerset_p]
7807lib.ztimerset_execute.restype = c_int
7808lib.ztimerset_execute.argtypes = [ztimerset_p]
7809lib.ztimerset_test.restype = None
7810lib.ztimerset_test.argtypes = [c_bool]
7811
7812class Ztimerset(object):
7813    """
7814    timer set
7815    """
7816
7817    allow_destruct = False
7818    def __init__(self, *args):
7819        """
7820        Create new timer set.
7821        """
7822        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
7823            self._as_parameter_ = cast(args[0], ztimerset_p) # Conversion from raw type to binding
7824            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
7825        elif len(args) == 2 and type(args[0]) is ztimerset_p and isinstance(args[1], bool):
7826            self._as_parameter_ = args[0] # Conversion from raw type to binding
7827            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
7828        else:
7829            assert(len(args) == 0)
7830            self._as_parameter_ = lib.ztimerset_new() # Creation of new raw type
7831            self.allow_destruct = True
7832
7833    def __del__(self):
7834        """
7835        Destroy a timer set
7836        """
7837        if self.allow_destruct:
7838            lib.ztimerset_destroy(byref(self._as_parameter_))
7839
7840    def __eq__(self, other):
7841        if type(other) == type(self):
7842            return other.c_address() == self.c_address()
7843        elif type(other) == c_void_p:
7844            return other.value == self.c_address()
7845
7846    def c_address(self):
7847        """
7848        Return the address of the object pointer in c.  Useful for comparison.
7849        """
7850        return addressof(self._as_parameter_.contents)
7851
7852    def __bool__(self):
7853        "Determine whether the object is valid by converting to boolean" # Python 3
7854        return self._as_parameter_.__bool__()
7855
7856    def __nonzero__(self):
7857        "Determine whether the object is valid by converting to boolean" # Python 2
7858        return self._as_parameter_.__nonzero__()
7859
7860    def add(self, interval, handler, arg):
7861        """
7862        Add a timer to the set. Returns timer id if OK, -1 on failure.
7863        """
7864        return lib.ztimerset_add(self._as_parameter_, interval, handler, arg)
7865
7866    def cancel(self, timer_id):
7867        """
7868        Cancel a timer. Returns 0 if OK, -1 on failure.
7869        """
7870        return lib.ztimerset_cancel(self._as_parameter_, timer_id)
7871
7872    def set_interval(self, timer_id, interval):
7873        """
7874        Set timer interval. Returns 0 if OK, -1 on failure.
7875This method is slow, canceling the timer and adding a new one yield better performance.
7876        """
7877        return lib.ztimerset_set_interval(self._as_parameter_, timer_id, interval)
7878
7879    def reset(self, timer_id):
7880        """
7881        Reset timer to start interval counting from current time. Returns 0 if OK, -1 on failure.
7882This method is slow, canceling the timer and adding a new one yield better performance.
7883        """
7884        return lib.ztimerset_reset(self._as_parameter_, timer_id)
7885
7886    def timeout(self):
7887        """
7888        Return the time until the next interval.
7889Should be used as timeout parameter for the zpoller wait method.
7890The timeout is in msec.
7891        """
7892        return lib.ztimerset_timeout(self._as_parameter_)
7893
7894    def execute(self):
7895        """
7896        Invoke callback function of all timers which their interval has elapsed.
7897Should be call after zpoller wait method.
7898Returns 0 if OK, -1 on failure.
7899        """
7900        return lib.ztimerset_execute(self._as_parameter_)
7901
7902    @staticmethod
7903    def test(verbose):
7904        """
7905        Self test of this class.
7906        """
7907        return lib.ztimerset_test(verbose)
7908
7909
7910# ztrie
7911ztrie_destroy_data_fn = CFUNCTYPE(None, POINTER(c_void_p))
7912lib.ztrie_new.restype = ztrie_p
7913lib.ztrie_new.argtypes = [char_p]
7914lib.ztrie_destroy.restype = None
7915lib.ztrie_destroy.argtypes = [POINTER(ztrie_p)]
7916lib.ztrie_insert_route.restype = c_int
7917lib.ztrie_insert_route.argtypes = [ztrie_p, c_char_p, c_void_p, ztrie_destroy_data_fn]
7918lib.ztrie_remove_route.restype = c_int
7919lib.ztrie_remove_route.argtypes = [ztrie_p, c_char_p]
7920lib.ztrie_matches.restype = c_bool
7921lib.ztrie_matches.argtypes = [ztrie_p, c_char_p]
7922lib.ztrie_hit_data.restype = c_void_p
7923lib.ztrie_hit_data.argtypes = [ztrie_p]
7924lib.ztrie_hit_parameter_count.restype = c_size_t
7925lib.ztrie_hit_parameter_count.argtypes = [ztrie_p]
7926lib.ztrie_hit_parameters.restype = zhashx_p
7927lib.ztrie_hit_parameters.argtypes = [ztrie_p]
7928lib.ztrie_hit_asterisk_match.restype = c_char_p
7929lib.ztrie_hit_asterisk_match.argtypes = [ztrie_p]
7930lib.ztrie_print.restype = None
7931lib.ztrie_print.argtypes = [ztrie_p]
7932lib.ztrie_test.restype = None
7933lib.ztrie_test.argtypes = [c_bool]
7934
7935class Ztrie(object):
7936    """
7937    simple trie for tokenizable strings
7938    """
7939
7940    allow_destruct = False
7941    def __init__(self, *args):
7942        """
7943        Creates a new ztrie.
7944        """
7945        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
7946            self._as_parameter_ = cast(args[0], ztrie_p) # Conversion from raw type to binding
7947            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
7948        elif len(args) == 2 and type(args[0]) is ztrie_p and isinstance(args[1], bool):
7949            self._as_parameter_ = args[0] # Conversion from raw type to binding
7950            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
7951        else:
7952            assert(len(args) == 1)
7953            self._as_parameter_ = lib.ztrie_new(args[0]) # Creation of new raw type
7954            self.allow_destruct = True
7955
7956    def __del__(self):
7957        """
7958        Destroy the ztrie.
7959        """
7960        if self.allow_destruct:
7961            lib.ztrie_destroy(byref(self._as_parameter_))
7962
7963    def __eq__(self, other):
7964        if type(other) == type(self):
7965            return other.c_address() == self.c_address()
7966        elif type(other) == c_void_p:
7967            return other.value == self.c_address()
7968
7969    def c_address(self):
7970        """
7971        Return the address of the object pointer in c.  Useful for comparison.
7972        """
7973        return addressof(self._as_parameter_.contents)
7974
7975    def __bool__(self):
7976        "Determine whether the object is valid by converting to boolean" # Python 3
7977        return self._as_parameter_.__bool__()
7978
7979    def __nonzero__(self):
7980        "Determine whether the object is valid by converting to boolean" # Python 2
7981        return self._as_parameter_.__nonzero__()
7982
7983    def insert_route(self, path, data, destroy_data_fn):
7984        """
7985        Inserts a new route into the tree and attaches the data. Returns -1
7986if the route already exists, otherwise 0. This method takes ownership of
7987the provided data if a destroy_data_fn is provided.
7988        """
7989        return lib.ztrie_insert_route(self._as_parameter_, path, data, destroy_data_fn)
7990
7991    def remove_route(self, path):
7992        """
7993        Removes a route from the trie and destroys its data. Returns -1 if the
7994route does not exists, otherwise 0.
7995the start of the list call zlist_first (). Advances the cursor.
7996        """
7997        return lib.ztrie_remove_route(self._as_parameter_, path)
7998
7999    def matches(self, path):
8000        """
8001        Returns true if the path matches a route in the tree, otherwise false.
8002        """
8003        return lib.ztrie_matches(self._as_parameter_, path)
8004
8005    def hit_data(self):
8006        """
8007        Returns the data of a matched route from last ztrie_matches. If the path
8008did not match, returns NULL. Do not delete the data as it's owned by
8009ztrie.
8010        """
8011        return c_void_p(lib.ztrie_hit_data(self._as_parameter_))
8012
8013    def hit_parameter_count(self):
8014        """
8015        Returns the count of parameters that a matched route has.
8016        """
8017        return lib.ztrie_hit_parameter_count(self._as_parameter_)
8018
8019    def hit_parameters(self):
8020        """
8021        Returns the parameters of a matched route with named regexes from last
8022ztrie_matches. If the path did not match or the route did not contain any
8023named regexes, returns NULL.
8024        """
8025        return Zhashx(lib.ztrie_hit_parameters(self._as_parameter_), False)
8026
8027    def hit_asterisk_match(self):
8028        """
8029        Returns the asterisk matched part of a route, if there has been no match
8030or no asterisk match, returns NULL.
8031        """
8032        return lib.ztrie_hit_asterisk_match(self._as_parameter_)
8033
8034    def print(self):
8035        """
8036        Print the trie
8037        """
8038        return lib.ztrie_print(self._as_parameter_)
8039
8040    @staticmethod
8041    def test(verbose):
8042        """
8043        Self test of this class.
8044        """
8045        return lib.ztrie_test(verbose)
8046
8047
8048# zuuid
8049lib.zuuid_new.restype = zuuid_p
8050lib.zuuid_new.argtypes = []
8051lib.zuuid_destroy.restype = None
8052lib.zuuid_destroy.argtypes = [POINTER(zuuid_p)]
8053lib.zuuid_new_from.restype = zuuid_p
8054lib.zuuid_new_from.argtypes = [c_void_p]
8055lib.zuuid_set.restype = None
8056lib.zuuid_set.argtypes = [zuuid_p, c_void_p]
8057lib.zuuid_set_str.restype = c_int
8058lib.zuuid_set_str.argtypes = [zuuid_p, c_char_p]
8059lib.zuuid_data.restype = c_void_p
8060lib.zuuid_data.argtypes = [zuuid_p]
8061lib.zuuid_size.restype = c_size_t
8062lib.zuuid_size.argtypes = [zuuid_p]
8063lib.zuuid_str.restype = c_char_p
8064lib.zuuid_str.argtypes = [zuuid_p]
8065lib.zuuid_str_canonical.restype = c_char_p
8066lib.zuuid_str_canonical.argtypes = [zuuid_p]
8067lib.zuuid_export.restype = None
8068lib.zuuid_export.argtypes = [zuuid_p, c_void_p]
8069lib.zuuid_eq.restype = c_bool
8070lib.zuuid_eq.argtypes = [zuuid_p, c_void_p]
8071lib.zuuid_neq.restype = c_bool
8072lib.zuuid_neq.argtypes = [zuuid_p, c_void_p]
8073lib.zuuid_dup.restype = zuuid_p
8074lib.zuuid_dup.argtypes = [zuuid_p]
8075lib.zuuid_test.restype = None
8076lib.zuuid_test.argtypes = [c_bool]
8077
8078class Zuuid(object):
8079    """
8080    UUID support class
8081    """
8082
8083    allow_destruct = False
8084    def __init__(self, *args):
8085        """
8086        Create a new UUID object.
8087        """
8088        if len(args) == 2 and type(args[0]) is c_void_p and isinstance(args[1], bool):
8089            self._as_parameter_ = cast(args[0], zuuid_p) # Conversion from raw type to binding
8090            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8091        elif len(args) == 2 and type(args[0]) is zuuid_p and isinstance(args[1], bool):
8092            self._as_parameter_ = args[0] # Conversion from raw type to binding
8093            self.allow_destruct = args[1] # This is a 'fresh' value, owned by us
8094        else:
8095            assert(len(args) == 0)
8096            self._as_parameter_ = lib.zuuid_new() # Creation of new raw type
8097            self.allow_destruct = True
8098
8099    def __del__(self):
8100        """
8101        Destroy a specified UUID object.
8102        """
8103        if self.allow_destruct:
8104            lib.zuuid_destroy(byref(self._as_parameter_))
8105
8106    def __eq__(self, other):
8107        if type(other) == type(self):
8108            return other.c_address() == self.c_address()
8109        elif type(other) == c_void_p:
8110            return other.value == self.c_address()
8111
8112    def c_address(self):
8113        """
8114        Return the address of the object pointer in c.  Useful for comparison.
8115        """
8116        return addressof(self._as_parameter_.contents)
8117
8118    def __bool__(self):
8119        "Determine whether the object is valid by converting to boolean" # Python 3
8120        return self._as_parameter_.__bool__()
8121
8122    def __nonzero__(self):
8123        "Determine whether the object is valid by converting to boolean" # Python 2
8124        return self._as_parameter_.__nonzero__()
8125
8126    @staticmethod
8127    def new_from(source):
8128        """
8129        Create UUID object from supplied ZUUID_LEN-octet value.
8130        """
8131        return Zuuid(lib.zuuid_new_from(source), True)
8132
8133    def set(self, source):
8134        """
8135        Set UUID to new supplied ZUUID_LEN-octet value.
8136        """
8137        return lib.zuuid_set(self._as_parameter_, source)
8138
8139    def set_str(self, source):
8140        """
8141        Set UUID to new supplied string value skipping '-' and '{' '}'
8142optional delimiters. Return 0 if OK, else returns -1.
8143        """
8144        return lib.zuuid_set_str(self._as_parameter_, source)
8145
8146    def data(self):
8147        """
8148        Return UUID binary data.
8149        """
8150        return lib.zuuid_data(self._as_parameter_)
8151
8152    def size(self):
8153        """
8154        Return UUID binary size
8155        """
8156        return lib.zuuid_size(self._as_parameter_)
8157
8158    def str(self):
8159        """
8160        Returns UUID as string
8161        """
8162        return lib.zuuid_str(self._as_parameter_)
8163
8164    def str_canonical(self):
8165        """
8166        Return UUID in the canonical string format: 8-4-4-4-12, in lower
8167case. Caller does not modify or free returned value. See
8168http://en.wikipedia.org/wiki/Universally_unique_identifier
8169        """
8170        return lib.zuuid_str_canonical(self._as_parameter_)
8171
8172    def export(self, target):
8173        """
8174        Store UUID blob in target array
8175        """
8176        return lib.zuuid_export(self._as_parameter_, target)
8177
8178    def eq(self, compare):
8179        """
8180        Check if UUID is same as supplied value
8181        """
8182        return lib.zuuid_eq(self._as_parameter_, compare)
8183
8184    def neq(self, compare):
8185        """
8186        Check if UUID is different from supplied value
8187        """
8188        return lib.zuuid_neq(self._as_parameter_, compare)
8189
8190    def dup(self):
8191        """
8192        Make copy of UUID object; if uuid is null, or memory was exhausted,
8193returns null.
8194        """
8195        return Zuuid(lib.zuuid_dup(self._as_parameter_), False)
8196
8197    @staticmethod
8198    def test(verbose):
8199        """
8200        Self test of this class.
8201        """
8202        return lib.zuuid_test(verbose)
8203
8204################################################################################
8205#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
8206#  Read the zproject/README.md for information about making permanent changes. #
8207################################################################################
8208