2020from typing import Any
2121
2222import zmq
23- from jupyter_client .session import extract_header , Session
23+ from jupyter_client .session import extract_header
2424from tornado .ioloop import IOLoop
2525from zmq .eventloop .zmqstream import ZMQStream
2626
@@ -84,7 +84,7 @@ def _setup_xpub_listener(self):
8484 """Setup listener for XPUB subscription events"""
8585
8686 # Checks the socket is not a DummySocket
87- if not hasattr (self .socket , ' getsockopt' ):
87+ if not hasattr (self .socket , " getsockopt" ):
8888 return
8989
9090 socket_type = self .socket .getsockopt (zmq .TYPE )
@@ -95,17 +95,17 @@ def _setup_xpub_listener(self):
9595 def _handle_subscription (self , frames ):
9696 """Handle subscription/unsubscription events from XPUB socket
9797
98- XPUB sockets receive:
98+ XPUB sockets receive:
9999 - subscribe: single frame with b'\\ x01' + topic
100100 - unsubscribe: single frame with b'\\ x00' + topic
101101 """
102102
103103 for frame in frames :
104104 event_type = frame [0 ]
105105 if event_type == 1 :
106- subscription = frame [1 :] if len (frame ) > 1 else b''
106+ subscription = frame [1 :] if len (frame ) > 1 else b""
107107 try :
108- subscription_str = subscription .decode (' utf-8' )
108+ subscription_str = subscription .decode (" utf-8" )
109109 except UnicodeDecodeError :
110110 continue
111111 self ._send_welcome_message (subscription_str )
@@ -119,23 +119,21 @@ def _send_welcome_message(self, subscription):
119119 The subscription topic (UTF-8 decoded)
120120 """
121121
122- content = {
123- 'subscription' : subscription
124- }
122+ content = {"subscription" : subscription }
125123
126- header = self .session .msg_header (' iopub_welcome' )
124+ header = self .session .msg_header (" iopub_welcome" )
127125 msg = {
128- ' header' : header ,
129- ' parent_header' : {},
130- ' metadata' : {},
131- ' content' : content ,
132- ' buffers' : [],
126+ " header" : header ,
127+ " parent_header" : {},
128+ " metadata" : {},
129+ " content" : content ,
130+ " buffers" : [],
133131 }
134132
135133 msg_list = self .session .serialize (msg )
136134
137135 if subscription :
138- identity = subscription .encode (' utf-8' )
136+ identity = subscription .encode (" utf-8" )
139137 full_msg = [identity ] + msg_list
140138 else :
141139 full_msg = msg_list
0 commit comments