You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Merge branch 'master' into python-3.3-to-3.5
This commit is contained in:
@@ -656,16 +656,6 @@ def get_scanner(version, is_pypy=False, show_asm=None):
|
||||
return scanner
|
||||
|
||||
|
||||
def prefer_double_quote(string: str) -> str:
|
||||
"""
|
||||
Prefer a double quoted string over a
|
||||
single quoted string when possible
|
||||
"""
|
||||
if string.find("'") == -1:
|
||||
return '"%s"' % string
|
||||
return repr(string)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import inspect
|
||||
|
||||
|
@@ -45,7 +45,7 @@ from xdis import Instruction, instruction_size, iscode
|
||||
from xdis.bytecode import _get_const_info
|
||||
from xdis.opcodes.opcode_3x import parse_fn_counts_30_35
|
||||
|
||||
from uncompyle6.scanner import CONST_COLLECTIONS, Scanner, prefer_double_quote
|
||||
from uncompyle6.scanner import CONST_COLLECTIONS, Scanner
|
||||
from uncompyle6.scanners.tok import Token
|
||||
from uncompyle6.util import get_code_name
|
||||
|
||||
@@ -609,7 +609,6 @@ class Scanner3(Scanner):
|
||||
pattr = "<code_object " + co_name + ">"
|
||||
elif isinstance(const, str):
|
||||
opname = "LOAD_STR"
|
||||
pattr = prefer_double_quote(inst.argval)
|
||||
else:
|
||||
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
||||
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
||||
|
@@ -38,7 +38,7 @@ import xdis.opcodes.opcode_37 as op3
|
||||
from xdis import Instruction, instruction_size, iscode
|
||||
from xdis.bytecode import _get_const_info
|
||||
|
||||
from uncompyle6.scanner import Scanner, Token, prefer_double_quote
|
||||
from uncompyle6.scanner import Scanner, Token
|
||||
|
||||
globals().update(op3.opmap)
|
||||
|
||||
@@ -290,20 +290,21 @@ class Scanner37Base(Scanner):
|
||||
# but the operator and operand properties come from the other
|
||||
# instruction
|
||||
self.insts[i] = Instruction(
|
||||
jump_inst.opname,
|
||||
jump_inst.opcode,
|
||||
jump_inst.optype,
|
||||
jump_inst.inst_size,
|
||||
jump_inst.arg,
|
||||
jump_inst.argval,
|
||||
jump_inst.argrepr,
|
||||
jump_inst.has_arg,
|
||||
inst.offset,
|
||||
inst.starts_line,
|
||||
inst.is_jump_target,
|
||||
inst.has_extended_arg,
|
||||
None,
|
||||
None,
|
||||
opcode=jump_inst.opcode,
|
||||
opname=jump_inst.opname,
|
||||
arg=jump_inst.arg,
|
||||
argval=jump_inst.argval,
|
||||
argrepr=jump_inst.argrepr,
|
||||
offset=inst.offset,
|
||||
starts_line=inst.starts_line,
|
||||
is_jump_target=inst.is_jump_target,
|
||||
positions=None,
|
||||
optype=jump_inst.optype,
|
||||
has_arg=jump_inst.has_arg,
|
||||
inst_size=jump_inst.inst_size,
|
||||
has_extended_arg=inst.has_extended_arg,
|
||||
tos_str=None,
|
||||
start_offset=None,
|
||||
)
|
||||
|
||||
# Get jump targets
|
||||
@@ -383,7 +384,6 @@ class Scanner37Base(Scanner):
|
||||
pattr = "<code_object " + const.co_name + ">"
|
||||
elif isinstance(const, str):
|
||||
opname = "LOAD_STR"
|
||||
pattr = prefer_double_quote(inst.argval)
|
||||
else:
|
||||
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
||||
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
||||
@@ -935,7 +935,7 @@ class Scanner37Base(Scanner):
|
||||
if __name__ == "__main__":
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE, version_tuple_to_str
|
||||
|
||||
if PYTHON_VERSION_TRIPLE[:2] == (3, 7):
|
||||
if (3, 7) <= PYTHON_VERSION_TRIPLE[:2] < (3, 9):
|
||||
import inspect
|
||||
|
||||
co = inspect.currentframe().f_code # type: ignore
|
||||
|
@@ -133,7 +133,7 @@ import sys
|
||||
from io import StringIO
|
||||
|
||||
from spark_parser import GenericASTTraversal
|
||||
from xdis import COMPILER_FLAG_BIT, iscode
|
||||
from xdis import COMPILER_FLAG_BIT, IS_PYPY, iscode
|
||||
from xdis.version_info import PYTHON_VERSION_TRIPLE
|
||||
|
||||
from uncompyle6.parser import get_python_parser, parse
|
||||
@@ -148,6 +148,7 @@ from uncompyle6.semantics.consts import (
|
||||
MAP,
|
||||
MAP_DIRECT,
|
||||
NAME_MODULE,
|
||||
NO_PARENTHESIS_EVER,
|
||||
NONE,
|
||||
PASS,
|
||||
PRECEDENCE,
|
||||
@@ -188,8 +189,6 @@ PARSER_DEFAULT_DEBUG = {
|
||||
"dups": False,
|
||||
}
|
||||
|
||||
IS_PYPY = "__pypy__" in sys.builtin_module_names
|
||||
|
||||
TREE_DEFAULT_DEBUG = {"before": False, "after": False}
|
||||
|
||||
DEFAULT_DEBUG_OPTS = {
|
||||
@@ -209,7 +208,7 @@ class SourceWalkerError(Exception):
|
||||
|
||||
class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
"""
|
||||
Class to traverses a Parse Tree of the bytecode instruction built from parsing to
|
||||
Class to traverse a Parse Tree of the bytecode instruction built from parsing to
|
||||
produce some sort of source text.
|
||||
The Parse tree may be turned an Abstract Syntax tree as an intermediate step.
|
||||
"""
|
||||
@@ -266,27 +265,32 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
is_pypy=is_pypy,
|
||||
)
|
||||
|
||||
self.ast_errors = []
|
||||
self.currentclass = None
|
||||
self.classes = []
|
||||
self.debug_parser = dict(debug_parser)
|
||||
self.line_number = 1
|
||||
self.linemap = {}
|
||||
self.params = params
|
||||
self.param_stack = []
|
||||
self.ERROR = None
|
||||
self.prec = 100
|
||||
self.return_none = False
|
||||
self.mod_globs = set()
|
||||
self.showast = showast
|
||||
self.pending_newlines = 0
|
||||
self.ast_errors = []
|
||||
self.classes = []
|
||||
self.compile_mode = compile_mode
|
||||
self.currentclass = None
|
||||
self.debug_parser = dict(debug_parser)
|
||||
self.is_pypy = is_pypy
|
||||
self.linemap = {}
|
||||
self.line_number = 1
|
||||
self.linestarts = linestarts
|
||||
self.mod_globs = set()
|
||||
self.name = None
|
||||
self.offset2inst_index = scanner.offset2inst_index
|
||||
self.param_stack = []
|
||||
self.params = params
|
||||
self.pending_newlines = 0
|
||||
self.prec = NO_PARENTHESIS_EVER
|
||||
self.return_none = False
|
||||
self.showast = showast
|
||||
self.version = version
|
||||
|
||||
self.treeTransform = TreeTransform(version=self.version, show_ast=showast)
|
||||
|
||||
# FIXME: have p.insts update in a better way
|
||||
# modularity is broken here
|
||||
self.insts = scanner.insts
|
||||
self.offset2inst_index = scanner.offset2inst_index
|
||||
|
||||
# Initialize p_lambda on demand
|
||||
self.p_lambda = None
|
||||
@@ -311,10 +315,6 @@ class SourceWalker(GenericASTTraversal, NonterminalActions, ComprehensionMixin):
|
||||
# An example is:
|
||||
# __module__ = __name__
|
||||
self.hide_internal = True
|
||||
self.compile_mode = compile_mode
|
||||
self.name = None
|
||||
self.version = version
|
||||
self.is_pypy = is_pypy
|
||||
customize_for_version(self, is_pypy, version)
|
||||
return
|
||||
|
||||
|
Reference in New Issue
Block a user