Skip to content

Commit

Permalink
better packet dump format
Browse files Browse the repository at this point in the history
  • Loading branch information
methane committed Sep 3, 2016
1 parent 7d97090 commit c09ba86
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions pymysql/connections.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,20 +117,18 @@ def is_ascii(data):

try:
print("packet length:", len(data))
print("method call[1]:", sys._getframe(1).f_code.co_name)
print("method call[2]:", sys._getframe(2).f_code.co_name)
print("method call[3]:", sys._getframe(3).f_code.co_name)
print("method call[4]:", sys._getframe(4).f_code.co_name)
print("method call[5]:", sys._getframe(5).f_code.co_name)
print("-" * 88)
for i in range(1, 6):
f = sys._getframe(i)
print("call[%d]: %s (line %d)" % (i, f.f_code.co_name, f.f_lineno))
print("-" * 66)
except ValueError:
pass
dump_data = [data[i:i+16] for i in range_type(0, min(len(data), 256), 16)]
for d in dump_data:
print(' '.join(map(lambda x: "{:02X}".format(byte2int(x)), d)) +
' ' * (16 - len(d)) + ' ' * 2 +
' '.join(map(lambda x: "{}".format(is_ascii(x)), d)))
print("-" * 88)
''.join(map(lambda x: "{}".format(is_ascii(x)), d)))
print("-" * 66)
print()


Expand Down

0 comments on commit c09ba86

Please sign in to comment.