|
18 | 18 |
|
19 | 19 | import zprocess
|
20 | 20 | import zprocess.process_tree
|
21 |
| -from zprocess.security import SecureContext |
| 21 | +from zprocess.security import SecureContext, SecureSocket |
22 | 22 | from labscript_utils.labconfig import LabConfig
|
23 | 23 | from labscript_utils import dedent
|
24 | 24 | import zprocess.zlog
|
@@ -248,10 +248,19 @@ def instance(cls):
|
248 | 248 | # Super required to call unbound class method of parent class:
|
249 | 249 | return super(Context, cls).instance(shared_secret=config['shared_secret'])
|
250 | 250 |
|
251 |
| - def socket(self, *args, **kwargs): |
252 |
| - config = get_config() |
253 |
| - kwargs['allow_insecure'] = config['allow_insecure'] |
254 |
| - return SecureContext.socket(self, *args, **kwargs) |
| 251 | + def socket(self, socket_type, socket_class=None, **kwargs): |
| 252 | + # socket_class kwarg introduced in pyzmq 25. Pass it through if it was given, |
| 253 | + # otherwise don't. |
| 254 | + if socket_class is not None: |
| 255 | + kwargs['socket_class'] = socket_class |
| 256 | + # Only insert our security-related args to the socket if we know it's going to |
| 257 | + # be a SecureSocket. If caller has explicitly requested a different socket type |
| 258 | + # (e.g since pyzmq 25, ThreadAuthenticator sets up an internal socket by calling |
| 259 | + # `Context.socket(..., socket_class=zmq.Socket)), then don't.` |
| 260 | + if socket_class is None or issubclass(socket_class, SecureContext): |
| 261 | + config = get_config() |
| 262 | + kwargs['allow_insecure'] = config['allow_insecure'] |
| 263 | + return SecureContext.socket(self, socket_type=socket_type, **kwargs) |
255 | 264 |
|
256 | 265 |
|
257 | 266 | def Lock(*args, **kwargs):
|
|
0 commit comments