You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 09:22:40 +08:00
Python 2.4 comptiability and ...
exception match -> exception-match
This commit is contained in:
@@ -29,7 +29,7 @@ def list_comp():
|
|||||||
[y for y in range(3)]
|
[y for y in range(3)]
|
||||||
|
|
||||||
def get_parsed_for_fn(fn):
|
def get_parsed_for_fn(fn):
|
||||||
code = fn.__code__ if PYTHON3 else fn.func_code
|
code = fn.func_code
|
||||||
return deparse(PYTHON_VERSION, code)
|
return deparse(PYTHON_VERSION, code)
|
||||||
|
|
||||||
def check_expect(expect, parsed):
|
def check_expect(expect, parsed):
|
||||||
|
@@ -10,7 +10,7 @@ else:
|
|||||||
maxint = sys.maxint
|
maxint = sys.maxint
|
||||||
from uncompyle6.semantics.helper import print_docstring
|
from uncompyle6.semantics.helper import print_docstring
|
||||||
|
|
||||||
class PrintFake():
|
class PrintFake:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.pending_newlines = 0
|
self.pending_newlines = 0
|
||||||
self.f = StringIO()
|
self.f = StringIO()
|
||||||
|
@@ -21,9 +21,8 @@ def bug_loop(disassemble, tb=None):
|
|||||||
disassemble(tb)
|
disassemble(tb)
|
||||||
|
|
||||||
def test_if_in_for():
|
def test_if_in_for():
|
||||||
code = bug.__code__
|
code = bug.func_code
|
||||||
scan = get_scanner(PYTHON_VERSION)
|
scan = get_scanner(PYTHON_VERSION)
|
||||||
print(PYTHON_VERSION)
|
|
||||||
if 2.7 <= PYTHON_VERSION <= 3.0 and not IS_PYPY:
|
if 2.7 <= PYTHON_VERSION <= 3.0 and not IS_PYPY:
|
||||||
n = scan.setup_code(code)
|
n = scan.setup_code(code)
|
||||||
scan.build_lines_data(code, n)
|
scan.build_lines_data(code, n)
|
||||||
|
@@ -1,7 +1,7 @@
|
|||||||
import pytest
|
from uncompyle6 import PYTHON_VERSION, deparse_code
|
||||||
from uncompyle6 import PYTHON_VERSION, PYTHON3, deparse_code
|
|
||||||
|
|
||||||
def test_single_mode():
|
if PYTHON_VERSION >= 2.5:
|
||||||
|
def test_single_mode():
|
||||||
single_expressions = (
|
single_expressions = (
|
||||||
'i = 1',
|
'i = 1',
|
||||||
'i and (j or k)',
|
'i and (j or k)',
|
||||||
|
@@ -3,7 +3,7 @@ import os
|
|||||||
import difflib
|
import difflib
|
||||||
import subprocess
|
import subprocess
|
||||||
import tempfile
|
import tempfile
|
||||||
import functools
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
# uncompyle6 / xdis
|
# uncompyle6 / xdis
|
||||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY, deparse_code
|
from uncompyle6 import PYTHON_VERSION, IS_PYPY, deparse_code
|
||||||
@@ -11,11 +11,15 @@ from uncompyle6 import PYTHON_VERSION, IS_PYPY, deparse_code
|
|||||||
from xdis.bytecode import Bytecode
|
from xdis.bytecode import Bytecode
|
||||||
from xdis.main import get_opcode
|
from xdis.main import get_opcode
|
||||||
opc = get_opcode(PYTHON_VERSION, IS_PYPY)
|
opc = get_opcode(PYTHON_VERSION, IS_PYPY)
|
||||||
Bytecode = functools.partial(Bytecode, opc=opc)
|
|
||||||
|
|
||||||
|
try:
|
||||||
def _dis_to_text(co):
|
import functools
|
||||||
|
Bytecode = functools.partial(Bytecode, opc=opc)
|
||||||
|
def _dis_to_text(co):
|
||||||
return Bytecode(co).dis()
|
return Bytecode(co).dis()
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def print_diff(original, uncompyled):
|
def print_diff(original, uncompyled):
|
||||||
@@ -39,8 +43,11 @@ def print_diff(original, uncompyled):
|
|||||||
print('\nTo display diff highlighting run:\n pip install BeautifulSoup4')
|
print('\nTo display diff highlighting run:\n pip install BeautifulSoup4')
|
||||||
diff = difflib.HtmlDiff().make_table(*args)
|
diff = difflib.HtmlDiff().make_table(*args)
|
||||||
|
|
||||||
with tempfile.NamedTemporaryFile(delete=False) as f:
|
f = tempfile.NamedTemporaryFile(delete=False)
|
||||||
|
try:
|
||||||
f.write(str(diff).encode('utf-8'))
|
f.write(str(diff).encode('utf-8'))
|
||||||
|
finally:
|
||||||
|
f.close()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print()
|
print()
|
||||||
@@ -57,7 +64,6 @@ def print_diff(original, uncompyled):
|
|||||||
print('\nFor side by side diff install elinks')
|
print('\nFor side by side diff install elinks')
|
||||||
diff = difflib.Differ().compare(original_lines, uncompyled_lines)
|
diff = difflib.Differ().compare(original_lines, uncompyled_lines)
|
||||||
print('\n'.join(diff))
|
print('\n'.join(diff))
|
||||||
finally:
|
|
||||||
os.unlink(f.name)
|
os.unlink(f.name)
|
||||||
|
|
||||||
|
|
||||||
|
@@ -927,7 +927,7 @@ class Scanner3(Scanner):
|
|||||||
# except block return
|
# except block return
|
||||||
jump_prev = prev_op[offset]
|
jump_prev = prev_op[offset]
|
||||||
if self.is_pypy and code[jump_prev] == self.opc.COMPARE_OP:
|
if self.is_pypy and code[jump_prev] == self.opc.COMPARE_OP:
|
||||||
if self.opc.cmp_op[code[jump_prev+1]] == 'exception match':
|
if self.opc.cmp_op[code[jump_prev+1]] == 'exception-match':
|
||||||
return
|
return
|
||||||
if self.version >= 3.5:
|
if self.version >= 3.5:
|
||||||
# Python 3.5 may remove as dead code a JUMP
|
# Python 3.5 may remove as dead code a JUMP
|
||||||
|
@@ -293,7 +293,7 @@ class Scanner30(Scanner3):
|
|||||||
# except block return
|
# except block return
|
||||||
jump_prev = prev_op[offset]
|
jump_prev = prev_op[offset]
|
||||||
if self.is_pypy and code[jump_prev] == self.opc.COMPARE_OP:
|
if self.is_pypy and code[jump_prev] == self.opc.COMPARE_OP:
|
||||||
if self.opc.cmp_op[code[jump_prev+1]] == 'exception match':
|
if self.opc.cmp_op[code[jump_prev+1]] == 'exception-match':
|
||||||
return
|
return
|
||||||
if self.version >= 3.5:
|
if self.version >= 3.5:
|
||||||
# Python 3.5 may remove as dead code a JUMP
|
# Python 3.5 may remove as dead code a JUMP
|
||||||
|
Reference in New Issue
Block a user