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