Try and display a pretty html line difference between the original and uncompyled code and bytecode if elinks and BeautifulSoup are installed otherwise just show the diff. :param original: Text describing the original code object. :param uncompyled: Text describing the uncompyl
(original, uncompyled)
| 24 | |
| 25 | |
| 26 | def print_diff(original, uncompyled): |
| 27 | """ |
| 28 | Try and display a pretty html line difference between the original and |
| 29 | uncompyled code and bytecode if elinks and BeautifulSoup are installed |
| 30 | otherwise just show the diff. |
| 31 | |
| 32 | :param original: Text describing the original code object. |
| 33 | :param uncompyled: Text describing the uncompyled code object. |
| 34 | """ |
| 35 | original_lines = original.split("\n") |
| 36 | uncompyled_lines = uncompyled.split("\n") |
| 37 | args = original_lines, uncompyled_lines, "original", "uncompyled" |
| 38 | try: |
| 39 | from bs4 import BeautifulSoup |
| 40 | |
| 41 | diff = difflib.HtmlDiff().make_file(*args) |
| 42 | diff = BeautifulSoup(diff, "html.parser") |
| 43 | diff.select_one('table[summary="Legends"]').extract() |
| 44 | except ImportError: |
| 45 | print("\nTo display diff highlighting run:\n pip install BeautifulSoup4") |
| 46 | diff = difflib.HtmlDiff().make_table(*args) |
| 47 | |
| 48 | with tempfile.NamedTemporaryFile(delete=False) as f: |
| 49 | f.write(str(diff).encode("utf-8")) |
| 50 | |
| 51 | try: |
| 52 | print() |
| 53 | html = subprocess.check_output( |
| 54 | ["elinks", "-dump", "-no-references", "-dump-color-mode", "1", f.name] |
| 55 | ).decode("utf-8") |
| 56 | print(html) |
| 57 | except: |
| 58 | print("\nFor side by side diff install elinks") |
| 59 | diff = difflib.Differ().compare(original_lines, uncompyled_lines) |
| 60 | print("\n".join(diff)) |
| 61 | finally: |
| 62 | os.unlink(f.name) |
| 63 | |
| 64 | |
| 65 | def are_instructions_equal(i1, i2): |
no test coverage detected