You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 00:45:53 +08:00
Prefer using double quote for strings
This commit is contained in:
@@ -597,25 +597,14 @@ class Scanner:
|
|||||||
return self.Token
|
return self.Token
|
||||||
|
|
||||||
|
|
||||||
# TODO: after the next xdis release, use from there instead.
|
def prefer_double_quote(string: str) -> str:
|
||||||
def parse_fn_counts_30_35(argc: int) -> Tuple[int, int, int]:
|
|
||||||
"""
|
"""
|
||||||
In Python 3.0 to 3.5 MAKE_CLOSURE and MAKE_FUNCTION encode
|
Prefer a double quoted string over a
|
||||||
arguments counts of positional, default + named, and annotation
|
single quoted string when possible
|
||||||
arguments a particular kind of encoding where each of
|
|
||||||
the entry a a packed byted value of the lower 24 bits
|
|
||||||
of ``argc``. The high bits of argc may have come from
|
|
||||||
an EXTENDED_ARG instruction. Here, we unpack the values
|
|
||||||
from the ``argc`` int and return a triple of the
|
|
||||||
positional args, named_args, and annotation args.
|
|
||||||
"""
|
"""
|
||||||
annotate_count = (argc >> 16) & 0x7FFF
|
if string.find("'") == -1:
|
||||||
# For some reason that I don't understand, annotate_args is off by one
|
return f'"{string}"'
|
||||||
# when there is an EXENDED_ARG instruction from what is documented in
|
return str(string)
|
||||||
# https://docs.python.org/3.4/library/dis.html#opcode-MAKE_CLOSURE
|
|
||||||
if annotate_count > 1:
|
|
||||||
annotate_count -= 1
|
|
||||||
return ((argc & 0xFF), (argc >> 8) & 0xFF, annotate_count)
|
|
||||||
|
|
||||||
|
|
||||||
def get_scanner(version: Union[str, tuple], is_pypy=False, show_asm=None) -> Scanner:
|
def get_scanner(version: Union[str, tuple], is_pypy=False, show_asm=None) -> Scanner:
|
||||||
|
@@ -44,8 +44,9 @@ import xdis
|
|||||||
import xdis.opcodes.opcode_33 as op3
|
import xdis.opcodes.opcode_33 as op3
|
||||||
from xdis import Instruction, instruction_size, iscode
|
from xdis import Instruction, instruction_size, iscode
|
||||||
from xdis.bytecode import _get_const_info
|
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, parse_fn_counts_30_35
|
from uncompyle6.scanner import CONST_COLLECTIONS, Scanner, prefer_double_quote
|
||||||
from uncompyle6.scanners.tok import Token
|
from uncompyle6.scanners.tok import Token
|
||||||
from uncompyle6.util import get_code_name
|
from uncompyle6.util import get_code_name
|
||||||
|
|
||||||
@@ -611,6 +612,7 @@ class Scanner3(Scanner):
|
|||||||
pattr = "<code_object " + co_name + ">"
|
pattr = "<code_object " + co_name + ">"
|
||||||
elif isinstance(const, str):
|
elif isinstance(const, str):
|
||||||
opname = "LOAD_STR"
|
opname = "LOAD_STR"
|
||||||
|
pattr = prefer_double_quote(inst.argval)
|
||||||
else:
|
else:
|
||||||
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
||||||
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
||||||
|
@@ -39,7 +39,7 @@ import xdis.opcodes.opcode_37 as op3
|
|||||||
from xdis import Instruction, instruction_size, iscode
|
from xdis import Instruction, instruction_size, iscode
|
||||||
from xdis.bytecode import _get_const_info
|
from xdis.bytecode import _get_const_info
|
||||||
|
|
||||||
from uncompyle6.scanner import Scanner, Token
|
from uncompyle6.scanner import Scanner, Token, prefer_double_quote
|
||||||
|
|
||||||
globals().update(op3.opmap)
|
globals().update(op3.opmap)
|
||||||
|
|
||||||
@@ -386,6 +386,7 @@ class Scanner37Base(Scanner):
|
|||||||
pattr = "<code_object " + const.co_name + ">"
|
pattr = "<code_object " + const.co_name + ">"
|
||||||
elif isinstance(const, str):
|
elif isinstance(const, str):
|
||||||
opname = "LOAD_STR"
|
opname = "LOAD_STR"
|
||||||
|
pattr = prefer_double_quote(inst.argval)
|
||||||
else:
|
else:
|
||||||
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
if isinstance(inst.arg, int) and inst.arg < len(co.co_consts):
|
||||||
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
argval, _ = _get_const_info(inst.arg, co.co_consts)
|
||||||
|
@@ -39,6 +39,7 @@ class NonterminalActions:
|
|||||||
# parenthesis surrounding it. A high value indicates no
|
# parenthesis surrounding it. A high value indicates no
|
||||||
# parenthesis are needed.
|
# parenthesis are needed.
|
||||||
self.prec = 1000
|
self.prec = 1000
|
||||||
|
self.in_format_string = False
|
||||||
|
|
||||||
def n_alias(self, node):
|
def n_alias(self, node):
|
||||||
if self.version <= (2, 1):
|
if self.version <= (2, 1):
|
||||||
|
Reference in New Issue
Block a user