-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathdiffdis.py
More file actions
executable file
·31 lines (25 loc) · 886 Bytes
/
diffdis.py
File metadata and controls
executable file
·31 lines (25 loc) · 886 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env python3.4
# Copyright 2018 The go-python Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
# Diff two bytecode strings
import sys
import io
import os
from dis import dis
from difflib import unified_diff
from tempfile import NamedTemporaryFile
def disassemble(code):
"""Disassemble code into string"""
out = io.StringIO()
dis(code, file=out)
return out.getvalue()
def main():
assert len(sys.argv) == 3, "Need two arguments"
a, b = (bytes(x, "latin1").decode("unicode_escape").encode("latin1") for x in sys.argv[1:])
a_dissasembly = disassemble(a)
b_dissasembly = disassemble(b)
for line in unified_diff(a_dissasembly.split("\n"), b_dissasembly.split("\n"), fromfile="want", tofile="got"):
print(line)
if __name__ == "__main__":
main()