Make string handling in debugger more pythonic (#1757)

* `to_string` is unpythonic, let's use `__str__` instead.
* `\"%s\"` for strings is also unpythonic, let's use `%r`.

JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
This commit is contained in:
Akos Kiss
2017-04-21 02:52:06 +02:00
committed by yichoi
parent 4cff7a3f2c
commit d93bc3a849
+9 -17
View File
@@ -93,20 +93,13 @@ class JerryBreakpoint(object):
self.function = function self.function = function
self.active_index = -1 self.active_index = -1
def to_string(self): def __str__(self):
result = self.function.source_name result = self.function.source_name or "<unknown>"
if result == "":
result = "<unknown>"
result += ":%d" % (self.line) result += ":%d" % (self.line)
if self.function.is_func: if self.function.is_func:
result += " (in " result += " (in "
if self.function.name: result += self.function.name or "function"
result += self.function.name
else:
result += "function"
result += "() at line:%d, col:%d)" % (self.function.line, self.function.column) result += "() at line:%d, col:%d)" % (self.function.line, self.function.column)
return result return result
@@ -138,7 +131,7 @@ class JerryFunction(object):
self.offsets[offset] = breakpoint self.offsets[offset] = breakpoint
def __repr__(self): def __repr__(self):
result = ("Function(byte_code_cp:0x%x, source_name:\"%s\", name:\"%s\", line:%d, column: %d { " result = ("Function(byte_code_cp:0x%x, source_name:%r, name:%r, line:%d, column:%d { "
% (self.byte_code_cp, self.source_name, self.name, self.line, self.column)) % (self.byte_code_cp, self.source_name, self.name, self.line, self.column))
result += ','.join([str(breakpoint) for breakpoint in self.lines.values()]) result += ','.join([str(breakpoint) for breakpoint in self.lines.values()])
@@ -229,7 +222,7 @@ class DebuggerPrompt(Cmd):
return return
for breakpoint in self.debugger.active_breakpoint_list.values(): for breakpoint in self.debugger.active_breakpoint_list.values():
print("%d: %s" % (breakpoint.active_index, breakpoint.to_string())) print("%d: %s" % (breakpoint.active_index, breakpoint))
def do_delete(self, args): def do_delete(self, args):
""" Delete the given breakpoint, use 'delete all' to clear the breakpoints in the whole program""" """ Delete the given breakpoint, use 'delete all' to clear the breakpoints in the whole program"""
@@ -394,7 +387,7 @@ class Multimap(object):
del items[items.index(value)] del items[items.index(value)]
def __repr__(self): def __repr__(self):
return "Multimap(%s)" % (self.map) return "Multimap(%r)" % (self.map)
class JerryDebugger(object): class JerryDebugger(object):
@@ -712,8 +705,7 @@ def enable_breakpoint(debugger, breakpoint):
breakpoint.active_index = debugger.next_breakpoint_index breakpoint.active_index = debugger.next_breakpoint_index
debugger.send_breakpoint(breakpoint) debugger.send_breakpoint(breakpoint)
print ("Breakpoint %d at %s" print ("Breakpoint %d at %s" % (breakpoint.active_index, breakpoint))
% (breakpoint.active_index, breakpoint.to_string()))
def set_breakpoint(debugger, string): def set_breakpoint(debugger, string):
@@ -828,7 +820,7 @@ def main():
if breakpoint[0].active_index >= 0: if breakpoint[0].active_index >= 0:
breakpoint_info += " breakpoint:%d" % (breakpoint[0].active_index) breakpoint_info += " breakpoint:%d" % (breakpoint[0].active_index)
print("Stopped %s %s" % (breakpoint_info, breakpoint[0].to_string())) print("Stopped %s %s" % (breakpoint_info, breakpoint[0]))
prompt.cmdloop() prompt.cmdloop()
if prompt.quit: if prompt.quit:
@@ -846,7 +838,7 @@ def main():
breakpoint = get_breakpoint(debugger, breakpoint_data) breakpoint = get_breakpoint(debugger, breakpoint_data)
print("Frame %d: %s" % (frame_index, breakpoint[0].to_string())) print("Frame %d: %s" % (frame_index, breakpoint[0]))
frame_index += 1 frame_index += 1
buffer_pos += 6 buffer_pos += 6