Skip to content

Commit 085b54d

Browse files
committed
remove some dead code checks for unsupported libzmq
1 parent 5deb7d7 commit 085b54d

File tree

5 files changed

+25
-56
lines changed

5 files changed

+25
-56
lines changed

zmq/backend/cffi/socket.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import zmq
99
from zmq.constants import SocketOption, _OptType
10-
from zmq.error import ZMQError, _check_rc, _check_version
10+
from zmq.error import ZMQError, _check_rc
1111

1212
from ._cffi import ffi
1313
from ._cffi import lib as C
@@ -184,7 +184,6 @@ def bind(self, address):
184184
_check_rc(rc)
185185

186186
def unbind(self, address):
187-
_check_version((3, 2), "unbind")
188187
if isinstance(address, str):
189188
address = address.encode('utf8')
190189
rc = C.zmq_unbind(self._zmq_socket, address)
@@ -197,7 +196,6 @@ def connect(self, address):
197196
_check_rc(rc)
198197

199198
def disconnect(self, address):
200-
_check_version((3, 2), "disconnect")
201199
if isinstance(address, str):
202200
address = address.encode('utf8')
203201
rc = C.zmq_disconnect(self._zmq_socket, address)
@@ -372,8 +370,6 @@ def monitor(self, addr, events=-1):
372370
events : int [default: zmq.EVENT_ALL]
373371
The zmq event bitmask for which events will be sent to the monitor.
374372
"""
375-
376-
_check_version((3, 2), "monitor")
377373
if events < 0:
378374
events = zmq.EVENT_ALL
379375
if addr is None:

zmq/backend/cffi/utils.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ def curve_keypair():
3131
(public, secret) : two bytestrings
3232
The public and private key pair as 40 byte z85-encoded bytestrings.
3333
"""
34-
_check_version((3, 2), "curve_keypair")
3534
public = ffi.new('char[64]')
3635
private = ffi.new('char[64]')
3736
rc = C.zmq_curve_keypair(public, private)

zmq/backend/cython/_zmq.py

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
ZMQ_ROUTER,
9393
ZMQ_SNDMORE,
9494
ZMQ_TYPE,
95-
ZMQ_VERSION_MAJOR,
9695
_zmq_version,
9796
fd_t,
9897
int64_t,
@@ -109,7 +108,6 @@
109108
zmq_free_fn,
110109
zmq_getsockopt,
111110
zmq_has,
112-
zmq_init,
113111
zmq_join,
114112
zmq_leave,
115113
zmq_msg_close,
@@ -534,16 +532,13 @@ def __init__(self, io_threads: C.int = 1, shadow: size_t = 0):
534532
self._shadow = True
535533
else:
536534
self._shadow = False
537-
if ZMQ_VERSION_MAJOR >= 3:
538-
self.handle = zmq_ctx_new()
539-
else:
540-
self.handle = zmq_init(io_threads)
535+
self.handle = zmq_ctx_new()
541536

542537
if self.handle == NULL:
543538
raise ZMQError()
544539

545540
rc: C.int = 0
546-
if ZMQ_VERSION_MAJOR >= 3 and not self._shadow:
541+
if not self._shadow:
547542
rc = zmq_ctx_set(self.handle, ZMQ_IO_THREADS, io_threads)
548543
_check_rc(rc)
549544

@@ -984,7 +979,6 @@ def unbind(self, addr):
984979
rc: C.int
985980
c_addr: p_char
986981

987-
_check_version((3, 2), "unbind")
988982
_check_closed(self)
989983
if isinstance(addr, str):
990984
addr = addr.encode('utf-8')
@@ -1014,7 +1008,6 @@ def disconnect(self, addr):
10141008
rc: C.int
10151009
c_addr: p_char
10161010

1017-
_check_version((3, 2), "disconnect")
10181011
_check_closed(self)
10191012
if isinstance(addr, str):
10201013
addr = addr.encode('utf-8')
@@ -1047,7 +1040,6 @@ def monitor(self, addr, events: C.int = ZMQ_EVENT_ALL):
10471040
default: zmq.EVENT_ALL
10481041
The zmq event bitmask for which events will be sent to the monitor.
10491042
"""
1050-
_check_version((3, 2), "monitor")
10511043

10521044
if isinstance(addr, str):
10531045
# cast str to utf8 bytes
@@ -1595,11 +1587,6 @@ def zmq_poll(sockets, timeout: C.int = -1):
15951587
if pollitems == NULL:
15961588
raise MemoryError("Could not allocate poll items")
15971589

1598-
if ZMQ_VERSION_MAJOR < 3:
1599-
# timeout is us in 2.x, ms in 3.x
1600-
# expected input is ms (matches 3.x)
1601-
timeout = 1000 * timeout
1602-
16031590
for i in range(nsockets):
16041591
s, events = sockets[i]
16051592
if isinstance(s, Socket):

zmq/sugar/socket.py

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,7 @@ def bind_to_random_port(
498498
ZMQBindError
499499
if `max_tries` reached before successful bind
500500
"""
501-
if (
502-
(zmq.zmq_version_info() >= (3, 2))
503-
and min_port == 49152
504-
and max_port == 65536
505-
):
501+
if min_port == 49152 and max_port == 65536:
506502
# if LAST_ENDPOINT is supported, and min_port / max_port weren't specified,
507503
# we can bind to port 0 and let the OS do the work
508504
self.bind(f"{addr}:*")
@@ -531,17 +527,13 @@ def get_hwm(self) -> int:
531527
532528
On libzmq ≥ 3, this gets SNDHWM if available, otherwise RCVHWM
533529
"""
534-
major = zmq.zmq_version_info()[0]
535-
if major >= 3:
536-
# return sndhwm, fallback on rcvhwm
537-
try:
538-
return cast(int, self.get(zmq.SNDHWM))
539-
except zmq.ZMQError:
540-
pass
530+
# return sndhwm, fallback on rcvhwm
531+
try:
532+
return cast(int, self.get(zmq.SNDHWM))
533+
except zmq.ZMQError:
534+
pass
541535

542-
return cast(int, self.get(zmq.RCVHWM))
543-
else:
544-
return cast(int, self.get(zmq.HWM))
536+
return cast(int, self.get(zmq.RCVHWM))
545537

546538
def set_hwm(self, value: int) -> None:
547539
"""Set the High Water Mark.
@@ -554,22 +546,18 @@ def set_hwm(self, value: int) -> None:
554546
New values only take effect for subsequent socket
555547
bind/connects.
556548
"""
557-
major = zmq.zmq_version_info()[0]
558-
if major >= 3:
559-
raised = None
560-
try:
561-
self.sndhwm = value
562-
except Exception as e:
563-
raised = e
564-
try:
565-
self.rcvhwm = value
566-
except Exception as e:
567-
raised = e
549+
raised = None
550+
try:
551+
self.sndhwm = value
552+
except Exception as e:
553+
raised = e
554+
try:
555+
self.rcvhwm = value
556+
except Exception as e:
557+
raised = e
568558

569-
if raised:
570-
raise raised
571-
else:
572-
self.set(zmq.HWM, value)
559+
if raised:
560+
raise raised
573561

574562
hwm = property(
575563
get_hwm,

zmq/tests/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -181,11 +181,10 @@ def assertRaisesErrno(self, errno, func, *args, **kwargs):
181181

182182
def _select_recv(self, multipart, socket, **kwargs):
183183
"""call recv[_multipart] in a way that raises if there is nothing to receive"""
184-
if zmq.zmq_version_info() >= (3, 1, 0):
185-
# zmq 3.1 has a bug, where poll can return false positives,
186-
# so we wait a little bit just in case
187-
# See LIBZMQ-280 on JIRA
188-
time.sleep(0.1)
184+
# zmq 3.1 has a bug, where poll can return false positives,
185+
# so we wait a little bit just in case
186+
# See LIBZMQ-280 on JIRA
187+
time.sleep(0.1)
189188

190189
r, w, x = zmq.select([socket], [], [], timeout=kwargs.pop('timeout', 5))
191190
assert len(r) > 0, "Should have received a message"

0 commit comments

Comments
 (0)