Skip to content

Commit 1e1f04a

Browse files
committed
add py2 compat for export_svg.py
1 parent e776b33 commit 1e1f04a

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

python/examples/export_svg.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import webbrowser
44
import time
5+
import sys
56
try:
67
from urllib import pathname2url # Python 2.x
78
except:
@@ -27,7 +28,10 @@ def escape(toescape):
2728
# handle extended unicode
2829
toescape = toescape.encode('ascii', 'xmlcharrefreplace')
2930
# still escape the basics
30-
return ''.join(escape_table.get(chr(i), chr(i)) for i in toescape)
31+
if sys.version_info[0] == 3:
32+
return ''.join(escape_table.get(chr(i), chr(i)) for i in toescape)
33+
else:
34+
return ''.join(escape_table.get(i, i) for i in toescape)
3135

3236

3337
def save_svg(bv, function):
@@ -47,15 +51,18 @@ def save_svg(bv, function):
4751
result = show_message_box("Open SVG", "Would you like to view the exported SVG?",
4852
buttons=MessageBoxButtonSet.YesNoButtonSet, icon=MessageBoxIcon.QuestionIcon)
4953
if result == MessageBoxButtonResult.YesButton:
50-
url = 'file:{}'.format(pathname2url(outputfile))
54+
url = 'file:{}'.format(pathname2url(bytes(outputfile)))
5155
webbrowser.open(url)
5256

5357

5458
def instruction_data_flow(function, address):
5559
''' TODO: Extract data flow information '''
5660
length = function.view.get_instruction_length(address)
5761
func_bytes = function.view.read(address, length)
58-
hex = func_bytes.hex()
62+
if sys.version_info[0] == 3:
63+
hex = func_bytes.hex()
64+
else:
65+
hex = func_bytes.encode('hex')
5966
padded = ' '.join([hex[i:i + 2] for i in range(0, len(hex), 2)])
6067
return 'Opcode: {bytes}'.format(bytes=padded)
6168

0 commit comments

Comments
 (0)