ZIO
Python and C++ interface to ZeroMQ and Zyre
util.py
Go to the documentation of this file.
1 #!/usr/bin/env python3
2 '''
3 Utilities
4 '''
5 
6 import zmq
7 
8 socket_names = [
9  "PAIR",
10  "PUB",
11  "SUB",
12  "REQ",
13  "REP",
14  "DEALER",
15  "ROUTER",
16  "PULL",
17  "PUSH",
18  "XPUB",
19  "XSUB",
20  "STREAM",
21  "SERVER",
22  "CLIENT",
23  "RADIO",
24  "DISH",
25  "GATHER",
26  "SCATTER",
27  "DGRAM",
28  0
29 ]
30 
31 
32 def needs_codec(stype):
33  """Determine if socket needs codec
34 
35  :param stype: a ZeroMQ socket type number
36  :returns: True if socket type stype requires single-part messages
37  :rtype: bool
38 
39  """
40  return \
41  stype == zmq.SERVER or \
42  stype == zmq.CLIENT or \
43  stype == zmq.RADIO or \
44  stype == zmq.DISH
45 
47  """Guess the local hostname
48 
49  :returns: host name
50  :rtype: string
51 
52  """
53  import socket
54  return socket.getfqdn()
55 
56 def byteify_list(lst):
57  """Encode to bytes elements of a list
58 
59  :param lst: list of things that can be converted to bytes
60  :returns: list of bytes
61  :rtype: list
62 
63  """
64  ret = list()
65  for el in lst:
66  if type(el) is str:
67  el = bytes(el, encoding='utf-8')
68  ret.append(el)
69  return ret
def byteify_list(lst)
Definition: util.py:56
def needs_codec(stype)
Definition: util.py:32
def guess_hostname()
Definition: util.py:46