mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2024-11-27 15:10:55 +00:00
disas.py: Do better for finding/turning a .py file into a .pyc file
across supported versions of Python. Add for else list comprehension test
This commit is contained in:
parent
78847fe454
commit
e5f58e8ecb
BIN
test/bytecode_2.7/forelse.pyc
Normal file
BIN
test/bytecode_2.7/forelse.pyc
Normal file
Binary file not shown.
5
test/simple-source/comprehension/forelse.py
Normal file
5
test/simple-source/comprehension/forelse.py
Normal file
@ -0,0 +1,5 @@
|
||||
# Tests:
|
||||
# list_compr ::= BUILD_LIST_0 list_iter
|
||||
# list_iter ::= list_for
|
||||
# list_for ::= expr _for designator list_iter JUMP_BACK
|
||||
[b for b in (0,1,2,3)] if True else 5
|
@ -18,17 +18,31 @@ want to run on Python 2.7.
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import inspect, os, sys
|
||||
import inspect, os, py_compile, sys, tempfile
|
||||
|
||||
import uncompyle6
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.scanner import get_scanner
|
||||
|
||||
def check_object_path(path):
|
||||
if path.endswith(".py"):
|
||||
if uncompyle6.PYTHON3:
|
||||
try:
|
||||
import importlib
|
||||
path = importlib.util.cache_from_source(path)
|
||||
return path
|
||||
return importlib.util.cache_from_source(path,
|
||||
optimization='')
|
||||
except:
|
||||
try:
|
||||
import imp
|
||||
imp.cache_from_source(path, debug_override=False)
|
||||
except:
|
||||
pass
|
||||
pass
|
||||
basename = os.path.basename(path)[0:-3]
|
||||
spath = path if PYTHON3 else path.decude('utf-8')
|
||||
path = tempfile.mkstemp(prefix=basename + '-',
|
||||
suffix='.pyc', text=False)[1]
|
||||
py_compile.compile(spath, cfile=path)
|
||||
|
||||
if not path.endswith(".pyc") and not path.endswith(".pyo"):
|
||||
raise ValueError("path %s must point to a .py or .pyc file" %
|
||||
path)
|
||||
|
Loading…
Reference in New Issue
Block a user