Merge branch 'master' into python-2.4

This commit is contained in:
rocky
2017-12-13 17:43:44 -05:00
18 changed files with 36 additions and 35 deletions

View File

@@ -189,11 +189,9 @@ Deobfuscator_ to unscramble the bytecode to get valid bytecode before
trying this tool. This program can't decompile Microsoft Windows EXE
files created by Py2EXE_, although we can probably decompile the code
after you extract the bytecode properly. For situations like this, you
might want to consider a decompilation service like [Crazy
Compilers](http://www.crazy-compilers.com/decompyle/).
Handling pathologically long lists of expressions or statements is
slow.
might want to consider a decompilation service like `Crazy Compilers
<http://www.crazy-compilers.com/decompyle/>`_. Handling
pathologically long lists of expressions or statements is slow.
There is lots to do, so please dig in and help.

View File

@@ -6,6 +6,9 @@ FULLVERSION=$(pyenv local)
PYVERSION=${FULLVERSION%.*}
MINOR=${FULLVERSION##?.?.}
# DECOMPILER=uncompyle2
DECOMPILER="$fulldir/../../bin/uncompyle6"
typeset -i STOP_ONERROR=1
typeset -A SKIP_TESTS
@@ -169,7 +172,7 @@ for file in $files; do
$fulldir/compile-file.py $file && \
mv $file{,.orig} && \
echo ========== $(date +%X) Decompiling $file ===========
$fulldir/../../bin/uncompyle6 $decompiled_file > $file
$DECOMPILER $decompiled_file > $file
rc=$?
if (( rc == 0 )) ; then
echo ========== $(date +%X) Running $file ===========

View File

@@ -549,7 +549,7 @@ class PythonParser(GenericASTBuilder):
def parse(p, tokens, customize):
p.add_custom_rules(tokens, customize)
p.customize_grammar_rules(tokens, customize)
ast = p.parse(tokens)
# p.cleanup()
return ast

View File

@@ -216,7 +216,7 @@ class Python2Parser(PythonParser):
binary_op ::= BINARY_DIVIDE
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
"""The base grammar we start out for a Python version even with the
subclassing is, well, is pretty base. And we want it that way: lean and
mean so that parsing will go faster.

View File

@@ -20,8 +20,8 @@ class Python22Parser(Python23Parser):
COME_FROM POP_TOP COME_FROM
'''
def add_custom_rules(self, tokens, customize):
super(Python22Parser, self).add_custom_rules(tokens, customize)
def customize_grammar_rules(self, tokens, customize):
super(Python22Parser, self).customize_grammar_rules(tokens, customize)
self.remove_rules("""
kvlist ::= kvlist kv2
""")

View File

@@ -52,8 +52,8 @@ class Python23Parser(Python24Parser):
conditional ::= expr jmp_false expr JUMP_FORWARD expr COME_FROM
'''
def add_custom_rules(self, tokens, customize):
super(Python23Parser, self).add_custom_rules(tokens, customize)
def customize_grammar_rules(self, tokens, customize):
super(Python23Parser, self).customize_grammar_rules(tokens, customize)
def reduce_is_invalid(self, rule, ast, tokens, first, last):
invalid = super(Python24Parser,

View File

@@ -52,7 +52,7 @@ class Python24Parser(Python25Parser):
kv2 ::= DUP_TOP expr expr ROT_THREE STORE_SUBSCR
'''
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
self.remove_rules("""
gen_comp_body ::= expr YIELD_VALUE POP_TOP
kvlist ::= kvlist kv3
@@ -67,7 +67,7 @@ class Python24Parser(Python25Parser):
stmt ::= withstmt
stmt ::= withasstmt
""")
super(Python24Parser, self).add_custom_rules(tokens, customize)
super(Python24Parser, self).customize_grammar_rules(tokens, customize)
if self.version == 2.4:
self.check_reduce['nop_stmt'] = 'tokens'

View File

@@ -48,7 +48,7 @@ class Python25Parser(Python26Parser):
kv ::= DUP_TOP expr ROT_TWO expr STORE_SUBSCR
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
# Remove grammar rules inherited from Python 2.6 or Python 2
self.remove_rules("""
setupwith ::= DUP_TOP LOAD_ATTR ROT_TWO LOAD_ATTR CALL_FUNCTION_0 POP_TOP
@@ -77,7 +77,7 @@ class Python25Parser(Python26Parser):
conditional_lambda ::= expr jmp_false_then expr return_if_lambda
return_stmt_lambda LAMBDA_MARKER
""")
super(Python25Parser, self).add_custom_rules(tokens, customize)
super(Python25Parser, self).customize_grammar_rules(tokens, customize)
if self.version == 2.5:
self.check_reduce['tryelsestmt'] = 'tokens'

View File

@@ -298,13 +298,13 @@ class Python26Parser(Python2Parser):
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
self.remove_rules("""
withasstmt ::= expr SETUP_WITH store suite_stmts_opt
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
""")
super(Python26Parser, self).add_custom_rules(tokens, customize)
super(Python26Parser, self).customize_grammar_rules(tokens, customize)
self.check_reduce['and'] = 'AST'
self.check_reduce['list_for'] = 'AST'

View File

@@ -138,14 +138,14 @@ class Python27Parser(Python2Parser):
kv3 ::= expr expr STORE_MAP
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
# 2.7 changes COME_FROM to COME_FROM_FINALLY
self.remove_rules("""
while1stmt ::= SETUP_LOOP l_stmts JUMP_BACK COME_FROM
while1elsestmt ::= SETUP_LOOP l_stmts JUMP_BACK else_suite COME_FROM
tryfinallystmt ::= SETUP_FINALLY suite_stmts_opt POP_BLOCK LOAD_CONST COME_FROM suite_stmts_opt END_FINALLY
""")
super(Python27Parser, self).add_custom_rules(tokens, customize)
super(Python27Parser, self).customize_grammar_rules(tokens, customize)
self.check_reduce['and'] = 'AST'
return

View File

@@ -529,7 +529,7 @@ class Python3Parser(PythonParser):
return args_pos, args_kw
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
"""The base grammar we start out for a Python version even with the
subclassing is, well, is pretty base. And we want it that way: lean and
mean so that parsing will go faster.

View File

@@ -43,8 +43,8 @@ class Python30Parser(Python31Parser):
setup_finally ::= STORE_FAST SETUP_FINALLY LOAD_FAST DELETE_FAST
"""
def add_custom_rules(self, tokens, customize):
super(Python30Parser, self).add_custom_rules(tokens, customize)
def customize_grammar_rules(self, tokens, customize):
super(Python30Parser, self).customize_grammar_rules(tokens, customize)
return
pass

View File

@@ -32,8 +32,8 @@ class Python31Parser(Python32Parser):
load ::= LOAD_NAME
"""
def add_custom_rules(self, tokens, customize):
super(Python31Parser, self).add_custom_rules(tokens, customize)
def customize_grammar_rules(self, tokens, customize):
super(Python31Parser, self).customize_grammar_rules(tokens, customize)
return
pass

View File

@@ -56,7 +56,7 @@ class Python32Parser(Python3Parser):
"""
pass
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
self.remove_rules("""
except_handler ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY COME_FROM
except_handler ::= JUMP_FORWARD COME_FROM except_stmts END_FINALLY COME_FROM_EXCEPT
@@ -66,7 +66,7 @@ class Python32Parser(Python3Parser):
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP
""")
super(Python32Parser, self).add_custom_rules(tokens, customize)
super(Python32Parser, self).customize_grammar_rules(tokens, customize)
for i, token in enumerate(tokens):
opname = token.kind
if opname.startswith('MAKE_FUNCTION_A'):

View File

@@ -25,13 +25,13 @@ class Python33Parser(Python32Parser):
jump_excepts come_from_except_clauses
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
self.remove_rules("""
# 3.3+ adds POP_BLOCKS
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK NOP COME_FROM_LOOP
whileTruestmt ::= SETUP_LOOP l_stmts_opt JUMP_BACK POP_BLOCK NOP COME_FROM_LOOP
""")
super(Python33Parser, self).add_custom_rules(tokens, customize)
super(Python33Parser, self).customize_grammar_rules(tokens, customize)
return
class Python33ParserSingle(Python33Parser, PythonParserSingle):

View File

@@ -29,10 +29,10 @@ class Python34Parser(Python33Parser):
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
# self.remove_rules("""
# """)
super(Python34Parser, self).add_custom_rules(tokens, customize)
super(Python34Parser, self).customize_grammar_rules(tokens, customize)
return
class Python34ParserSingle(Python34Parser, PythonParserSingle):

View File

@@ -113,7 +113,7 @@ class Python35Parser(Python34Parser):
yield_from ::= expr GET_YIELD_FROM_ITER LOAD_CONST YIELD_FROM
"""
def add_custom_rules(self, tokens, customize):
def customize_grammar_rules(self, tokens, customize):
self.remove_rules("""
yield_from ::= expr GET_ITER LOAD_CONST YIELD_FROM
yield_from ::= expr expr YIELD_FROM
@@ -124,7 +124,7 @@ class Python35Parser(Python34Parser):
POP_BLOCK LOAD_CONST COME_FROM_WITH
WITH_CLEANUP END_FINALLY
""")
super(Python35Parser, self).add_custom_rules(tokens, customize)
super(Python35Parser, self).customize_grammar_rules(tokens, customize)
for i, token in enumerate(tokens):
opname = token.kind
if opname == 'BUILD_MAP_UNPACK_WITH_CALL':

View File

@@ -51,8 +51,8 @@ class Python36Parser(Python35Parser):
try_except36 ::= SETUP_EXCEPT return_stmts except_handler36 opt_come_from_except
"""
def add_custom_rules(self, tokens, customize):
super(Python36Parser, self).add_custom_rules(tokens, customize)
def customize_grammar_rules(self, tokens, customize):
super(Python36Parser, self).customize_grammar_rules(tokens, customize)
for i, token in enumerate(tokens):
opname = token.kind