77from tornado .queues import Queue
88from tornado .locks import Event
99
10+ from IPython .core .getipython import get_ipython
11+
12+ try :
13+ from jupyter_client .jsonutil import json_default
14+ except ImportError :
15+ from jupyter_client .jsonutil import date_default as json_default
16+
1017from .compiler import (get_file_name , get_tmp_directory , get_tmp_hash_seed )
1118
12- from IPython .core .getipython import get_ipython
1319
14- from .jsonutil import json_clean
1520
1621# Required for backwards compatiblity
1722ROUTING_ID = getattr (zmq , 'ROUTING_ID' , None ) or zmq .IDENTITY
1823
24+
1925class DebugpyMessageQueue :
2026
2127 HEADER = 'Content-Length: '
@@ -58,7 +64,7 @@ def put_tcp_frame(self, frame):
5864 self .header_pos = self .tcp_buffer .find (DebugpyMessageQueue .HEADER )
5965 if self .header_pos == - 1 :
6066 return
61-
67+
6268 self .log .debug ('QUEUE - found header at pos %i' , self .header_pos )
6369
6470 #Finds separator
@@ -94,7 +100,7 @@ def put_tcp_frame(self, frame):
94100
95101 async def get_message (self ):
96102 return await self .message_queue .get ()
97-
103+
98104
99105class DebugpyClient :
100106
@@ -123,15 +129,20 @@ def _forward_event(self, msg):
123129 def _send_request (self , msg ):
124130 if self .routing_id is None :
125131 self .routing_id = self .debugpy_stream .socket .getsockopt (ROUTING_ID )
126- content = jsonapi .dumps (msg )
132+ content = jsonapi .dumps (
133+ msg ,
134+ default = json_default ,
135+ ensure_ascii = False ,
136+ allow_nan = False ,
137+ )
127138 content_length = str (len (content ))
128139 buf = (DebugpyMessageQueue .HEADER + content_length + DebugpyMessageQueue .SEPARATOR ).encode ('ascii' )
129140 buf += content
130141 self .log .debug ("DEBUGPYCLIENT:" )
131142 self .log .debug (self .routing_id )
132143 self .log .debug (buf )
133144 self .debugpy_stream .send_multipart ((self .routing_id , buf ))
134-
145+
135146 async def _wait_for_response (self ):
136147 # Since events are never pushed to the message_queue
137148 # we can safely assume the next message in queue
@@ -141,7 +152,7 @@ async def _wait_for_response(self):
141152 async def _handle_init_sequence (self ):
142153 # 1] Waits for initialized event
143154 await self .init_event .wait ()
144-
155+
145156 # 2] Sends configurationDone request
146157 configurationDone = {
147158 'type' : 'request' ,
@@ -193,6 +204,7 @@ async def send_dap_request(self, msg):
193204 self .log .debug (rep )
194205 return rep
195206
207+
196208class Debugger :
197209
198210 # Requests that requires that the debugger has started
@@ -202,7 +214,7 @@ class Debugger:
202214 'variables' , 'attach' ,
203215 'configurationDone'
204216 ]
205-
217+
206218 # Requests that can be handled even if the debugger is not running
207219 static_debug_msg_types = [
208220 'debugInfo' , 'inspectVariables' , 'richInspectVariables'
@@ -215,7 +227,7 @@ def __init__(self, log, debugpy_stream, event_callback, shell_socket, session):
215227 self .session = session
216228 self .is_started = False
217229 self .event_callback = event_callback
218-
230+
219231 self .started_debug_handlers = {}
220232 for msg_type in Debugger .started_debug_msg_types :
221233 self .started_debug_handlers [msg_type ] = getattr (self , msg_type )
@@ -264,7 +276,7 @@ def start(self):
264276 }
265277 self .session .send (self .shell_socket , 'execute_request' , content ,
266278 None , (self .shell_socket .getsockopt (ROUTING_ID )))
267-
279+
268280 ident , msg = self .session .recv (self .shell_socket , mode = 0 )
269281 self .debugpy_initialized = msg ['content' ]['status' ] == 'ok'
270282 self .debugpy_client .connect_tcp_socket ()
@@ -424,8 +436,12 @@ async def inspectVariables(self, message):
424436 for k , v in get_ipython ().user_ns .items ():
425437 if self .accept_variable (k ):
426438 try :
427- val = json_clean (v )
428-
439+ val = jsonapi .dumps (
440+ v ,
441+ default = json_default ,
442+ ensure_ascii = False ,
443+ allow_nan = False ,
444+ )
429445 except ValueError :
430446 val = str (v )
431447 var_list .append ({
@@ -486,7 +502,7 @@ async def richInspectVariables(self, message):
486502 'data' : {},
487503 'metadata' : {}
488504 }
489-
505+
490506 for key , value in repr_data .items ():
491507 body ['data' ]['key' ] = value
492508 if repr_metadata .has_key (key ):
0 commit comments