@@ -149,6 +149,15 @@ def arguments_parse():
149
149
return args
150
150
151
151
152
+ if sys .version_info .major >= 3 :
153
+ def safe_ord (c ):
154
+ if isinstance (c , int ):
155
+ return c
156
+ return ord (c )
157
+ else :
158
+ safe_ord = ord
159
+
160
+
152
161
class JerryBreakpoint (object ):
153
162
154
163
def __init__ (self , line , offset , function ):
@@ -307,12 +316,12 @@ def __init__(self, channel):
307
316
# cpointer_size [1]
308
317
result = self .channel .connect (config_size )
309
318
310
- if len (result ) != config_size or ord (result [0 ]) != JERRY_DEBUGGER_CONFIGURATION :
319
+ if len (result ) != config_size or safe_ord (result [0 ]) != JERRY_DEBUGGER_CONFIGURATION :
311
320
raise Exception ("Unexpected configuration" )
312
321
313
- self .little_endian = ord (result [1 ]) & JERRY_DEBUGGER_LITTLE_ENDIAN
314
- self .max_message_size = ord (result [6 ])
315
- self .cp_size = ord (result [7 ])
322
+ self .little_endian = safe_ord (result [1 ]) & JERRY_DEBUGGER_LITTLE_ENDIAN
323
+ self .max_message_size = safe_ord (result [6 ])
324
+ self .cp_size = safe_ord (result [7 ])
316
325
317
326
if self .little_endian :
318
327
self .byte_order = "<"
@@ -400,7 +409,7 @@ def delete(self, args):
400
409
"to clear all the given breakpoints\n "
401
410
elif args in ['all' , 'pending' , 'active' ]:
402
411
if args != "pending" :
403
- for i in self .active_breakpoint_list .values ():
412
+ for i in list ( self .active_breakpoint_list .values () ):
404
413
breakpoint = self .active_breakpoint_list [i .active_index ]
405
414
del self .active_breakpoint_list [i .active_index ]
406
415
breakpoint .active_index = - 1
@@ -561,6 +570,7 @@ def memstats(self):
561
570
self ._exec_command (JERRY_DEBUGGER_MEMSTATS )
562
571
563
572
def _send_string (self , args , message_type , index = 0 ):
573
+ args = args .encode ("utf8" )
564
574
565
575
# 1: length of type byte
566
576
# 4: length of an uint32 value
@@ -684,7 +694,7 @@ def process_messages(self):
684
694
if not data : # Break the while loop if there is no more data.
685
695
return DebuggerAction (DebuggerAction .END , "" )
686
696
687
- buffer_type = ord (data [0 ])
697
+ buffer_type = safe_ord (data [0 ])
688
698
buffer_size = len (data ) - 1
689
699
690
700
logging .debug ("Main buffer type: %d, message size: %d" , buffer_type , buffer_size )
@@ -738,10 +748,10 @@ def process_messages(self):
738
748
return DebuggerAction (DebuggerAction .TEXT , result )
739
749
740
750
elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR :
741
- self .exception_string += data [1 :]
751
+ self .exception_string += data [1 :]. decode ( "utf8" )
742
752
743
753
elif buffer_type == JERRY_DEBUGGER_EXCEPTION_STR_END :
744
- self .exception_string += data [1 :]
754
+ self .exception_string += data [1 :]. decode ( "utf8" )
745
755
746
756
elif buffer_type == JERRY_DEBUGGER_BACKTRACE_TOTAL :
747
757
total = struct .unpack (self .byte_order + self .idx_format , data [1 :])[0 ]
@@ -808,7 +818,7 @@ def process_messages(self):
808
818
return DebuggerAction (DebuggerAction .TEXT , result )
809
819
810
820
elif buffer_type in [JERRY_DEBUGGER_SCOPE_VARIABLES , JERRY_DEBUGGER_SCOPE_VARIABLES_END ]:
811
- self .scope_vars += "" .join (data [1 :])
821
+ self .scope_vars += "" .join (data [1 :]. decode ( "utf8" ) )
812
822
813
823
if buffer_type == JERRY_DEBUGGER_SCOPE_VARIABLES_END :
814
824
result = self ._process_scope_variables ()
@@ -864,9 +874,9 @@ def print_source(self, line_num, offset):
864
874
865
875
# pylint: disable=too-many-branches,too-many-locals,too-many-statements
866
876
def _parse_source (self , data ):
867
- source_code = ""
868
- source_code_name = ""
869
- function_name = ""
877
+ source_code = b ""
878
+ source_code_name = b ""
879
+ function_name = b ""
870
880
stack = [{"line" : 1 ,
871
881
"column" : 1 ,
872
882
"name" : "" ,
@@ -879,7 +889,7 @@ def _parse_source(self, data):
879
889
if data is None :
880
890
return "Error: connection lost during source code receiving"
881
891
882
- buffer_type = ord (data [0 ])
892
+ buffer_type = safe_ord (data [0 ])
883
893
buffer_size = len (data ) - 1
884
894
885
895
logging .debug ("Parser buffer type: %d, message size: %d" , buffer_type , buffer_size )
@@ -903,14 +913,14 @@ def _parse_source(self, data):
903
913
position = struct .unpack (self .byte_order + self .idx_format + self .idx_format ,
904
914
data [1 : 1 + 4 + 4 ])
905
915
906
- stack .append ({"source" : source_code ,
907
- "source_name" : source_code_name ,
916
+ stack .append ({"source" : source_code . decode ( "utf8" ) ,
917
+ "source_name" : source_code_name . decode ( "utf8" ) ,
908
918
"line" : position [0 ],
909
919
"column" : position [1 ],
910
- "name" : function_name ,
920
+ "name" : function_name . decode ( "utf8" ) ,
911
921
"lines" : [],
912
922
"offsets" : []})
913
- function_name = ""
923
+ function_name = b ""
914
924
915
925
elif buffer_type in [JERRY_DEBUGGER_BREAKPOINT_LIST , JERRY_DEBUGGER_BREAKPOINT_OFFSET_LIST ]:
916
926
name = "lines"
@@ -937,8 +947,8 @@ def _parse_source(self, data):
937
947
938
948
# We know the last item in the list is the general byte code.
939
949
if not stack :
940
- func_desc ["source" ] = source_code
941
- func_desc ["source_name" ] = source_code_name
950
+ func_desc ["source" ] = source_code . decode ( "utf8" )
951
+ func_desc ["source_name" ] = source_code_name . decode ( "utf8" )
942
952
943
953
function = JerryFunction (stack ,
944
954
byte_code_cp ,
@@ -989,7 +999,7 @@ def _parse_source(self, data):
989
999
logging .debug ("Pending breakpoints available" )
990
1000
bp_list = self .pending_breakpoint_list
991
1001
992
- for breakpoint_index , breakpoint in bp_list .items ():
1002
+ for breakpoint_index , breakpoint in list ( bp_list .items () ):
993
1003
source_lines = 0
994
1004
for src in new_function_list .values ():
995
1005
if (src .source_name == breakpoint .source_name or
@@ -1132,14 +1142,14 @@ def _process_incoming_text(self, buffer_type, data):
1132
1142
while True :
1133
1143
if buffer_type in [JERRY_DEBUGGER_EVAL_RESULT_END ,
1134
1144
JERRY_DEBUGGER_OUTPUT_RESULT_END ]:
1135
- subtype = ord (data [- 1 ])
1145
+ subtype = safe_ord (data [- 1 ])
1136
1146
message += data [1 :- 1 ]
1137
1147
break
1138
1148
else :
1139
1149
message += data [1 :]
1140
1150
1141
1151
data = self .channel .get_message (True )
1142
- buffer_type = ord (data [0 ])
1152
+ buffer_type = safe_ord (data [0 ])
1143
1153
# Checks if the next frame would be an invalid data frame.
1144
1154
# If it is not the message type, or the end type of it, an exception is thrown.
1145
1155
if buffer_type not in [msg_type , msg_type + 1 ]:
@@ -1151,20 +1161,21 @@ def _process_incoming_text(self, buffer_type, data):
1151
1161
log_type = "%sout:%s " % (self .blue , self .nocolor )
1152
1162
1153
1163
message = self .current_out + message
1154
- lines = message .split ("\n " )
1155
- self .current_out = lines .pop ()
1164
+ lines = message .decode ( "utf8" ). split ("\n " )
1165
+ self .current_out = lines .pop (). encode ( "utf8" )
1156
1166
1157
1167
return "" .join (["%s%s\n " % (log_type , line ) for line in lines ])
1158
1168
1159
1169
if subtype == JERRY_DEBUGGER_OUTPUT_DEBUG :
1160
1170
log_type = "%slog:%s " % (self .yellow , self .nocolor )
1161
1171
1162
1172
message = self .current_log + message
1163
- lines = message .split ("\n " )
1164
- self .current_log = lines .pop ()
1173
+ lines = message .decode ( "utf8" ). split ("\n " )
1174
+ self .current_log = lines .pop (). encode ( "utf8" )
1165
1175
1166
1176
return "" .join (["%s%s\n " % (log_type , line ) for line in lines ])
1167
1177
1178
+ message = message .decode ("utf8" )
1168
1179
if not message .endswith ("\n " ):
1169
1180
message += "\n "
1170
1181
@@ -1174,6 +1185,9 @@ def _process_incoming_text(self, buffer_type, data):
1174
1185
return "%serr: %s%s" % (self .red , self .nocolor , message )
1175
1186
elif subtype == JERRY_DEBUGGER_OUTPUT_TRACE :
1176
1187
return "%strace: %s%s" % (self .blue , self .nocolor , message )
1188
+ else :
1189
+ message = message .decode ("utf8" )
1190
+
1177
1191
1178
1192
# Subtypes of eval
1179
1193
self .prompt = True
@@ -1193,17 +1207,17 @@ def _process_scope_variables(self):
1193
1207
1194
1208
while buff_pos != buff_size :
1195
1209
# Process name
1196
- name_length = ord (self .scope_vars [buff_pos :buff_pos + 1 ])
1210
+ name_length = safe_ord (self .scope_vars [buff_pos :buff_pos + 1 ])
1197
1211
buff_pos += 1
1198
1212
name = self .scope_vars [buff_pos :buff_pos + name_length ]
1199
1213
buff_pos += name_length
1200
1214
1201
1215
# Process type
1202
- value_type = ord (self .scope_vars [buff_pos :buff_pos + 1 ])
1216
+ value_type = safe_ord (self .scope_vars [buff_pos :buff_pos + 1 ])
1203
1217
1204
1218
buff_pos += 1
1205
1219
1206
- value_length = ord (self .scope_vars [buff_pos :buff_pos + 1 ])
1220
+ value_length = safe_ord (self .scope_vars [buff_pos :buff_pos + 1 ])
1207
1221
buff_pos += 1
1208
1222
value = self .scope_vars [buff_pos : buff_pos + value_length ]
1209
1223
buff_pos += value_length
@@ -1234,16 +1248,16 @@ def _process_scope(self):
1234
1248
table = [['level' , 'type' ]]
1235
1249
1236
1250
for i , level in enumerate (self .scope_data ):
1237
- if ord (level ) == JERRY_DEBUGGER_SCOPE_WITH :
1251
+ if safe_ord (level ) == JERRY_DEBUGGER_SCOPE_WITH :
1238
1252
table .append ([str (i ), 'with' ])
1239
- elif ord (level ) == JERRY_DEBUGGER_SCOPE_GLOBAL :
1253
+ elif safe_ord (level ) == JERRY_DEBUGGER_SCOPE_GLOBAL :
1240
1254
table .append ([str (i ), 'global' ])
1241
- elif ord (level ) == JERRY_DEBUGGER_SCOPE_NON_CLOSURE :
1255
+ elif safe_ord (level ) == JERRY_DEBUGGER_SCOPE_NON_CLOSURE :
1242
1256
# Currently it is only marks the catch closure.
1243
1257
table .append ([str (i ), 'catch' ])
1244
- elif ord (level ) == JERRY_DEBUGGER_SCOPE_LOCAL :
1258
+ elif safe_ord (level ) == JERRY_DEBUGGER_SCOPE_LOCAL :
1245
1259
table .append ([str (i ), 'local' ])
1246
- elif ord (level ) == JERRY_DEBUGGER_SCOPE_CLOSURE :
1260
+ elif safe_ord (level ) == JERRY_DEBUGGER_SCOPE_CLOSURE :
1247
1261
table .append ([str (i ), 'closure' ])
1248
1262
else :
1249
1263
raise Exception ("Unexpected scope chain element" )
0 commit comments