You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-04 01:09:52 +08:00
Compare commits
42 Commits
release-2.
...
release-py
Author | SHA1 | Date | |
---|---|---|---|
|
5566b9ba6c | ||
|
e56ab2dcd5 | ||
|
d6c45979ba | ||
|
a06e9bf32e | ||
|
7e8f7ba674 | ||
|
09eb7f7f78 | ||
|
f7a910ec66 | ||
|
6d6a73eea7 | ||
|
e4a7641927 | ||
|
b24b46d48c | ||
|
a65d7dce5b | ||
|
718a0a5d34 | ||
|
ea9e3ab3f5 | ||
|
770e988ff8 | ||
|
0fa0641974 | ||
|
c13e23cdae | ||
|
fab4ebb768 | ||
|
89429339fa | ||
|
6ed129bd7a | ||
|
c4fde6b53e | ||
|
a7d93e88b4 | ||
|
9891494142 | ||
|
f8544dfbbe | ||
|
b00651d428 | ||
|
da8dccbaca | ||
|
37272ae827 | ||
|
7f2bee46b7 | ||
|
c8a4dcf72b | ||
|
012ff91cfb | ||
|
e690ddd50a | ||
|
45b7c1948c | ||
|
e2fb7ca3d2 | ||
|
b3bda76582 | ||
|
ab6d322eca | ||
|
1a8a0df107 | ||
|
0a37709b0a | ||
|
98cd1417df | ||
|
460069ceaa | ||
|
316aa44f23 | ||
|
7133540c23 | ||
|
590231741d | ||
|
a9349b8f3d |
10
.travis.yml
10
.travis.yml
@@ -3,16 +3,10 @@ language: python
|
||||
sudo: false
|
||||
|
||||
python:
|
||||
- '3.5'
|
||||
- '2.7.12'
|
||||
- '2.6'
|
||||
- '3.3'
|
||||
- '3.4'
|
||||
- '3.2'
|
||||
- '3.6'
|
||||
- '2.7' # this is a cheat here because travis doesn't do 2.4-2.6
|
||||
|
||||
install:
|
||||
- pip install -e .
|
||||
- pip install -r requirements.txt
|
||||
- pip install -r requirements-dev.txt
|
||||
|
||||
script:
|
||||
|
717
ChangeLog
717
ChangeLog
@@ -1,502 +1,17 @@
|
||||
2017-08-15 rocky <rb@dustyfeet.com>
|
||||
2017-05-06 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/version.py: Get ready for release 2.11.4
|
||||
|
||||
2017-08-15 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, pytest/validate.py, uncompyle6/parser.py,
|
||||
uncompyle6/scanner.py: Misc cleanups... remove code now in xdis require at least xdis 3.5.4 PyPy tolerance
|
||||
in validate testing
|
||||
|
||||
2017-08-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* pytest/test_basic.py, uncompyle6/parser.py, uncompyle6/scanner.py:
|
||||
Allow 3-part version string lookups, e.g 2.7.1 We allow a float here, but if passed a string like '2.7'. or
|
||||
'2.7.13', accept that in looking up either a scanner or a parser.
|
||||
|
||||
2017-08-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* README.rst: Link typo Name is trepan2 now not trepan
|
||||
|
||||
2017-08-09 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, README.rst, __pkginfo__.py,
|
||||
uncompyle6/semantics/consts.py, uncompyle6/version.py: Get ready for
|
||||
release 2.11.3 need xdis 3.5.1 for now. Adjust for xdis "is-not" which we need as
|
||||
"is not"
|
||||
|
||||
2017-08-02 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py: Revert commit to wrong branch
|
||||
|
||||
2017-08-02 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py: Remove six from Python-2.4/2.5 package
|
||||
|
||||
2017-07-17 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, uncompyle6/scanners/scanner2.py,
|
||||
uncompyle6/scanners/scanner3.py, uncompyle6/scanners/scanner30.py:
|
||||
xdis's "exception match" is now "exception-match"
|
||||
|
||||
2017-07-15 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py: xdis 3.5.1 is botched?
|
||||
|
||||
2017-07-14 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py: Use newer xdis
|
||||
|
||||
2017-07-14 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* README.rst: Fixes issue #124
|
||||
|
||||
2017-07-14 rocky <rb@dustyfeet.com>
|
||||
|
||||
* HISTORY.md: History updates
|
||||
|
||||
2017-07-09 rocky <rb@dustyfeet.com>
|
||||
|
||||
* README.rst: RsT doc formatting
|
||||
|
||||
2017-07-09 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, HOW-TO-REPORT-A-BUG.md, NEWS, uncompyle6/version.py:
|
||||
Get ready for release 2.11.2
|
||||
|
||||
2017-07-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, uncompyle6/scanner.py,
|
||||
uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner26.py,
|
||||
uncompyle6/scanners/scanner3.py, uncompyle6/scanners/scanner30.py,
|
||||
uncompyle6/scanners/tok.py: Use xdis 3.5.0's opcode sets
|
||||
|
||||
2017-07-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/test_pyenvlib.py, uncompyle6/scanners/pypy32.py,
|
||||
uncompyle6/scanners/pypy35.py, uncompyle6/scanners/scanner15.py,
|
||||
uncompyle6/scanners/scanner32.py, uncompyle6/scanners/scanner34.py,
|
||||
uncompyle6/scanners/scanner35.py, uncompyle6/scanners/scanner36.py:
|
||||
Start supporting Pypy 3.5 (5.7.1-beta)
|
||||
|
||||
2017-07-05 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/bug26/03_loop_if_cf.py,
|
||||
uncompyle6/parsers/parse26.py: Loops in Python 2.4-2.6 loop
|
||||
come_from Looks like Python 2.4-2.6 may have a COME_FROM(_LOOP) before the
|
||||
jump_back. Fixes Issue #123
|
||||
|
||||
2017-06-29 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : Work around not having real flow-control analysis
|
||||
|
||||
2017-06-28 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/make_function.py: A guard against badly
|
||||
formated bytecode
|
||||
|
||||
2017-06-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, test/simple_source/bug31/04_def_annotate.py,
|
||||
uncompyle6/semantics/make_function.py,
|
||||
uncompyle6/semantics/pysource.py: 3.x funciton and annotation bug
|
||||
fixes
|
||||
|
||||
2017-06-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/version.py: Get ready for release 2.11.1
|
||||
|
||||
2017-06-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, uncompyle6/scanner.py,
|
||||
uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner3.py,
|
||||
uncompyle6/scanners/scanner30.py, uncompyle6/semantics/pysource.py:
|
||||
Use xdis' instruction offset calculation fns.. next_offset, op_size, has_argument
|
||||
|
||||
2017-06-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Python 2 sometimes need
|
||||
str->uncode in writing?
|
||||
|
||||
2017-06-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Allow deparsed out to be str as
|
||||
well as unicode
|
||||
|
||||
2017-06-18 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, uncompyle6/version.py: Get ready for release
|
||||
2.11.0
|
||||
|
||||
2017-06-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Adjust nodeInfo if it is a
|
||||
Token
|
||||
|
||||
2017-06-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Add nonterminal node in
|
||||
extractInfo
|
||||
|
||||
2017-06-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py,
|
||||
uncompyle6/semantics/make_function.py: Fragment tag more expressions Revise make_function3 comment wrt args and kwargs
|
||||
|
||||
2017-06-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Fragment tag array subscripts
|
||||
|
||||
2017-06-10 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* README.rst: Create README.rst
|
||||
|
||||
2017-06-10 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* README.rst: Create README.rst
|
||||
|
||||
2017-06-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Set YIELD_VALUE offset in a
|
||||
<yield> expr
|
||||
|
||||
2017-06-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/make_function.py: Python 3.2 MAKE_FUNCTION
|
||||
again.. Was handling bug32/01_named_and_kwargs.py wrong again
|
||||
|
||||
2017-06-09 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* : Merge pull request #119 from rocky/scan-longconstant Simplify access to L65536 ...
|
||||
|
||||
2017-06-09 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/make_function.py: Attempt to document the
|
||||
MAKE_FUNCTION/MAKE_LAMBDA mess... in Python 3.0+
|
||||
|
||||
2017-06-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/make_function.py: Correct make_function3 for
|
||||
Pytohn 3.2
|
||||
|
||||
2017-06-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Disable "continue" removal in
|
||||
pysource.py "continue" could be the only statement and then removing it might
|
||||
lead to a dangling "else".
|
||||
|
||||
2017-06-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Mark "pass" offsets. Start routine to find previous node.
|
||||
|
||||
2017-06-06 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/semantics/fragments.py:
|
||||
Remove hacky fragments try fixup... hacky call_function code is also not needed or will be reinstated
|
||||
properly. Better grammar structure for Python 3.6 call_function.
|
||||
|
||||
2017-06-05 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/parsers/parse36.py,
|
||||
uncompyle6/scanners/scanner36.py: BUILD_{MAP,TUPLE}_UNPACK &
|
||||
CALL_FUNCTION_EX_KW... Bang on these in 3.6. Not totally succesfull right now. In fact a
|
||||
regression on one of the test cases
|
||||
|
||||
2017-06-05 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Important fragments bug fix... start, finish that had been adjusted wasn't getting reflected in
|
||||
final returned deparsed.offsets dictionary. Redo keeping API
|
||||
compatibility, i.e we still use namedtuple NodeInfo.
|
||||
|
||||
2017-06-04 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/semantics/pysource.py:
|
||||
Python 3.5 *args with kwargs handling. 3.5 is a snowflake here. Thank you, Python. Fully fixes Issue 95. 3.6 is broken on this source, but for a *different* reason. Sigh.
|
||||
|
||||
2017-06-03 rocky <rb@dustyfeet.com>
|
||||
|
||||
* README.rst, __pkginfo__.py,
|
||||
test/simple_source/bug35/04_CALL_FUNCTION_VAR_KW.py,
|
||||
uncompyle6/semantics/fragments.py: Small changes. fragment tag EXEC_STMT
|
||||
|
||||
2017-06-03 rocky <rb@dustyfeet.com>
|
||||
|
||||
* .travis.yml: Streamline .travis.yml a little bit
|
||||
|
||||
2017-06-03 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py: We need six
|
||||
|
||||
2017-06-03 rocky <rb@dustyfeet.com>
|
||||
|
||||
* README.rst, circle.yml, requirements-dev.txt: Go over
|
||||
administrivia
|
||||
|
||||
2017-06-03 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, uncompyle6/version.py: Get ready for release
|
||||
2.10.1
|
||||
|
||||
2017-06-03 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py,
|
||||
uncompyle6/semantics/pysource.py: Fragment bugs fragment.py: * deparse_code_aorund_offset: was sometimes returning the wrong type * capture function name offset * lint imports pysource.py: use a clearer variable name
|
||||
|
||||
2017-06-02 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Track changes in ifelstmtr.. in fragments from pysource
|
||||
|
||||
2017-05-30 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, uncompyle6/version.py: Get ready for release
|
||||
2.10.0
|
||||
|
||||
2017-05-30 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py: Python 3.6 makefunction
|
||||
handling for fragments
|
||||
|
||||
2017-05-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Fix up 3.6 unmapexpr
|
||||
|
||||
2017-05-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Fix up retreiving "async"
|
||||
property on 3.6
|
||||
|
||||
2017-05-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Fix bug in a 3.6 class name.
|
||||
|
||||
2017-05-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/fragments.py,
|
||||
uncompyle6/semantics/pysource.py: Add fuzzy offset deparse lookup
|
||||
|
||||
2017-05-21 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: Correct EXTENDED_ARG handling on
|
||||
Python 3.6... where it can appear several times and xdis may handle it as well.
|
||||
It possibly in other versions bug since EXTENDED_ARG is used so
|
||||
rarely there because it has such a high value 1<<16, it's hard to
|
||||
test and determine that.
|
||||
|
||||
2017-05-20 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Worse results. Revert some of
|
||||
the last changes
|
||||
|
||||
2017-05-20 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/semantics/pysource.py:
|
||||
More explicit about 3.5 UNMAP_PACK Have to reduce 3.5 bytecode testing for now, code is more solid.
|
||||
|
||||
2017-05-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/parsers/parse36.py,
|
||||
uncompyle6/scanners/scanner3.py: Simplify EXTENDED_ARG on 3.x We largely remove them and fold them itno the next op.
|
||||
MAKE_FUNCTION though before 3.6 is an exception as that indicates an
|
||||
annotated function
|
||||
|
||||
2017-05-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner26.py: EXTENDED_ARG is implemented in
|
||||
2.6
|
||||
|
||||
2017-05-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/expression/06_huge_list.py,
|
||||
uncompyle6/parsers/parse3.py, uncompyle6/semantics/pysource.py: Fix
|
||||
EXTENDED_ARG for long lists, sets, maps
|
||||
|
||||
2017-05-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: Another attempt at getting
|
||||
get_target() correct
|
||||
|
||||
2017-05-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py: Bug in pypy JUMP_IF_NOT_DEBUG
|
||||
handling
|
||||
|
||||
2017-05-19 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse36.py, uncompyle6/scanners/scanner3.py:
|
||||
EXTENDED_ARG handling... get_target() wasn't taking into account EXTENDED_ARG before opcode. This is mostly relevant in Python 3.6 where the max size before
|
||||
needing EXTENDED_ARG has been reduced to 256, but theoretically
|
||||
possible in earlier versions.
|
||||
|
||||
2017-05-18 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py: Enforce using xdis >=3.3.1 .. to pick up bug fixes to 3.6 in xdis
|
||||
|
||||
2017-05-17 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, uncompyle6/parsers/parse36.py,
|
||||
uncompyle6/scanners/scanner3.py: Small changes.... * __pkginfo__.py: Need spark parser 1.6.1 for corrected
|
||||
remove_rules() fn * parser36.py: remove replaced Python3 rules * scanner3.py: corrected comment. Thanks to moagstar here. *
|
||||
|
||||
2017-05-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse36.py: Fix broken CI on 3.6... Another grammar rule replacing SETUP_LOOP with setup_loop
|
||||
|
||||
2017-05-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse36.py: More EXTENDED_ARGS on 3.6
|
||||
|
||||
2017-05-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse36.py: extend use of EXTENDED_ARGS in 3.6 switching to a wordcode seems to have made opcode fields smaller so
|
||||
we need EXTENDED_ARG more?
|
||||
|
||||
2017-05-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse36.py, uncompyle6/semantics/pysource.py:
|
||||
Allow LOAD_CONST EXTENDED_ARG
|
||||
|
||||
2017-05-15 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py: Reinstate 3.6 listcomp rule
|
||||
|
||||
2017-05-15 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py: Bang on 3.6 MAKE_FUNCTION some more
|
||||
|
||||
2017-05-14 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: towards fixing a
|
||||
3.5.CALL_FUNCTONI_VAR bug
|
||||
|
||||
2017-05-14 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/bug35/04_CALL_FUNCTION_VAR_KW.py,
|
||||
uncompyle6/parsers/parse3.py: Python 3.5 kw arg can be an expr Fixes Issue #95
|
||||
|
||||
2017-05-14 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* : Merge pull request #117 from rocky/3.6-MAKE_FUNCTION 3.6 make function
|
||||
|
||||
2017-05-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: MAKE_FUNCTION_FLAGS can be a
|
||||
simpler tuple
|
||||
|
||||
2017-05-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py: Grammar rules for Python 3.6
|
||||
MAKE_FUNCTION
|
||||
|
||||
2017-05-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* README.rst, uncompyle6/parsers/parse3.py,
|
||||
uncompyle6/parsers/parse36.py, uncompyle6/semantics/pysource.py:
|
||||
Bang on 3.6 MAKE_FUNCTION a bit more parse3.py, parse36.py: adding return_closure rule tags what's going
|
||||
on with this rule pysource.py: start changing semantic rules to support code changed
|
||||
by new make_function semantics README.rst: typo
|
||||
|
||||
2017-05-13 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: Typo
|
||||
|
||||
2017-05-12 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse27.py: Bug in 2.7 decompiling ourself! Troublesome file was uncompyle6.semantics.pysource.engine()
|
||||
|
||||
2017-05-11 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* : Merge pull request #113 from grkov90/patch-1 Fixed out_base bug
|
||||
|
||||
2017-05-11 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/scanners/scanner3.py,
|
||||
uncompyle6/semantics/make_function.py: WIP: start 3.6 MAKE_FUNCTION
|
||||
handling
|
||||
|
||||
2017-05-11 Daniel Bradburn <moagstar@gmail.com>
|
||||
|
||||
* : Merge pull request #116 from moagstar/function_call_keyword_only Added support for Python 3.6 CALL_FUNCTION_KW
|
||||
|
||||
2017-05-10 Daniel Bradburn <moagstar@gmail.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: Fixed bug in compiling double
|
||||
star arg only function calls where the closing parenthesis would be
|
||||
missed
|
||||
|
||||
2017-05-10 Daniel Bradburn <moagstar@gmail.com>
|
||||
|
||||
* requirements-dev.txt: Adding requirement for pytest >= 3.0 to fix
|
||||
strange INTERNALERROR in combination with hypothesis when using
|
||||
pytest 2.6.4
|
||||
|
||||
2017-05-10 Daniel Bradburn <moagstar@gmail.com>
|
||||
|
||||
* pytest/test_CALL_FUNCTION_KW.sh, pytest/test_function_call.py,
|
||||
uncompyle6/parsers/parse3.py, uncompyle6/parsers/parse36.py,
|
||||
uncompyle6/scanners/scanner36.py, uncompyle6/semantics/pysource.py:
|
||||
Added support for support for Python 3.6 CALL_FUNCTION_KW
|
||||
|
||||
2017-05-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* appveyor.yml, test/test_pyenvlib.py,
|
||||
uncompyle6/semantics/pysource.py: pysource guard and another
|
||||
appveyor test
|
||||
|
||||
2017-05-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* appveyor.yml: appveyor take 2
|
||||
|
||||
2017-05-08 rocky <rb@dustyfeet.com>
|
||||
|
||||
* appveyor.yml, appveyor/install.ps1, appveyor/run_with_env.cmd: Try
|
||||
appveyor
|
||||
|
||||
2017-05-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/semantics/pysource.py: More guarded CONTINUE deletion
|
||||
|
||||
2017-05-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanner.py, uncompyle6/scanners/scanner3.py,
|
||||
uncompyle6/semantics/pysource.py: Reduce spurious "continue"
|
||||
statements
|
||||
|
||||
2017-05-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/Makefile: --weak-verify on 3.3 with inclusion of last commit Note that the result is sematically equivalent, so it is is correct.
|
||||
|
||||
2017-05-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/looping/12_if_while_true_pass.py,
|
||||
uncompyle6/scanners/scanner3.py: Python 3.x control-flow bug... "pass" statement inside "while True"
|
||||
|
||||
2017-05-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* HOW-TO-REPORT-A-BUG.md: Small typo
|
||||
|
||||
2017-05-07 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: Fix improper COME_FROM_EXCEPT in
|
||||
Python 3.3+
|
||||
* uncompyle6/version.py: Get ready for release 2.9.11
|
||||
|
||||
2017-05-06 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse33.py: python 3.3 while True parsing bug
|
||||
* test/Makefile, uncompyle6/scanners/scanner2.py,
|
||||
uncompyle6/scanners/scanner3.py, uncompyle6/semantics/fragments.py:
|
||||
Sync with master
|
||||
|
||||
2017-05-06 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, uncompyle6/version.py: Get ready for release
|
||||
2.9.11
|
||||
|
||||
2017-05-06 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/Makefile: fix PYTHON variable setting in test/Makefile
|
||||
|
||||
2017-05-06 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/bug32/01_try_except_raise.py,
|
||||
test/simple_source/bug32/03_if.py, uncompyle6/parsers/parse32.py,
|
||||
uncompyle6/parsers/parse33.py: Fix more Python3.2 parser errors
|
||||
* : commit 4a4782290490187ac2fcaaecd3ca808f933722b2 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sat May 6 05:25:56 2017 -0400
|
||||
|
||||
2017-05-05 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -507,14 +22,6 @@
|
||||
|
||||
* .travis.yml: Try CI testing on Python 3.6
|
||||
|
||||
2017-05-03 Gregory <grkov90@gmail.com>
|
||||
|
||||
* uncompyle6/main.py: Some fix
|
||||
|
||||
2017-05-03 Gregory <grkov90@gmail.com>
|
||||
|
||||
* uncompyle6/main.py: Fixed out_base bug Variable filename using in for tags uncompyle6 -o haven't worked argument -o haven't worked
|
||||
|
||||
2017-05-02 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/bug35/01_map_unpack.py, uncompyle6/parser.py,
|
||||
@@ -684,6 +191,11 @@
|
||||
haphazard way using real flow-control analysis. Hopefully that's on
|
||||
the way. In the meantime we have this hack.
|
||||
|
||||
2017-04-14 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit 7e8f7ba67431725fceec08344934c929a517efc5 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Fri Apr 14 05:42:44 2017 -0400
|
||||
|
||||
2017-04-14 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/simple_source/bug27+/03_if_1_else.py,
|
||||
@@ -748,9 +260,10 @@
|
||||
uncompyle6/parsers/parse2.py, uncompyle6/parsers/parse3.py,
|
||||
uncompyle6/parsers/parse35.py: Add more while1else grammar rules Towards addressing issue #93
|
||||
|
||||
2017-04-09 rocky <rb@dustyfeet.com>
|
||||
2017-04-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : One more FUNCTION_VAR test for 3.3
|
||||
* : commit b9703cf6b41138b717c282fc791c08d807692b07 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sun Apr 9 06:58:41 2017 -0400
|
||||
|
||||
2017-04-09 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -861,11 +374,8 @@
|
||||
|
||||
2017-03-01 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanner.py, uncompyle6/scanners/scanner2.py,
|
||||
uncompyle6/scanners/scanner3.py, uncompyle6/verify.py: COME_FROM for
|
||||
3.x POP_EXCEPT, DRY with op_name() ... Start adding COME_FROMs for POP_EXCEPT in preparation for getting
|
||||
tryelse blocks correct. Simpler opname access functions: - self.op_name(op) is self.opc.opname[op] - self.op_name_from_offset(offset) is
|
||||
self.opc.opname[self.code[offset]] verify.py: not all offsets are ints
|
||||
* : commit 160ec0d9cc5fe347f6e8bdb69515a28c76cfb368 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Wed Mar 1 05:50:31 2017 -0500
|
||||
|
||||
2017-02-28 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -889,13 +399,17 @@
|
||||
|
||||
2017-02-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, __pkginfo__.py, uncompyle6/version.py: Get ready
|
||||
for release 2.9.10
|
||||
* : commit 1e3ea60055027dfd3f098661ac4f5979c5c48f7e Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sat Feb 25 20:18:03 2017 -0500
|
||||
|
||||
2017-02-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parser.py, uncompyle6/parsers/parse26.py: Python 2.6
|
||||
parsing bugs .. and some parser list nonterminal cleanup
|
||||
* uncompyle6/parser.py: Python <= 2.6 grammar fixes
|
||||
|
||||
2017-02-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit 2fbbc728b10f0d3a754165708584bd80d33bc7f9 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sat Feb 25 04:45:10 2017 -0500
|
||||
|
||||
2017-02-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -909,9 +423,15 @@
|
||||
uncompyle6/parsers/parse25.py: Python 2.5 wasn't handling tryelse
|
||||
properly
|
||||
|
||||
2017-02-20 rocky <rb@dustyfeet.com>
|
||||
2017-02-22 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : New test doesn't --verify correctly. Sigh.
|
||||
* test/Makefile, test/simple_source/bug25/02_try_else.py,
|
||||
uncompyle6/parsers/parse25.py: Python 2.5 was missing try else stmt
|
||||
|
||||
2017-02-22 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit b043f6bafc9b9ae26e64dc0f1441d7abae894c37 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Mon Feb 20 09:22:01 2017 -0500
|
||||
|
||||
2017-02-20 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -950,6 +470,10 @@
|
||||
* test/simple_source/bug22/01_ops.py, test/test_pythonlib.py: Beef
|
||||
up grammar coverage
|
||||
|
||||
2017-02-10 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/Makefile: Group coverage Makefile targets
|
||||
|
||||
2017-01-29 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/Makefile, test/simple_source/bug22/01_ops.py,
|
||||
@@ -957,9 +481,24 @@
|
||||
uncompyle6/semantics/pysource.py: Changes based on grammar coverage
|
||||
info
|
||||
|
||||
2017-01-29 R. Bernstein <rocky@users.noreply.github.com>
|
||||
2017-01-29 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : Merge pull request #83 from rocky/coverage Coverage
|
||||
* test/Makefile, test/simple_source/bug22/01_ops.py,
|
||||
uncompyle6/parsers/parse25.py, uncompyle6/semantics/consts.py,
|
||||
uncompyle6/semantics/pysource.py: Changes based on coverage
|
||||
information
|
||||
|
||||
2017-01-29 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit 9348411056cbe809e07c4ef341effa17bca90e2f Merge: 3dc766d
|
||||
e71dd01 Author: R. Bernstein <rocky@users.noreply.github.com> Date:
|
||||
Sun Jan 29 21:54:45 2017 -0500
|
||||
|
||||
2017-01-29 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/Makefile, test/simple_source/bug22/01_ops.py,
|
||||
test/test_pyenvlib.py, test/test_pythonlib.py,
|
||||
uncompyle6/semantics/consts.py: Simplfy getting coverage consts.py: notes on versions use which ops
|
||||
|
||||
2017-01-29 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -1063,6 +602,10 @@
|
||||
* uncompyle6/__init__.py: sys.recursionlimit is optional, not
|
||||
essential
|
||||
|
||||
2017-01-11 rocky <rb@dustyfeet.com>
|
||||
|
||||
* NEWS, uncompyle6/version.py: Get ready for release 2.9.9
|
||||
|
||||
2017-01-11 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit b131c20e99514d3a969a51e841d3a823017f1beb Author: rocky
|
||||
@@ -1072,9 +615,22 @@
|
||||
|
||||
* ChangeLog, NEWS: Get ready for release 2.10.9
|
||||
|
||||
2017-01-11 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/scanner.py,
|
||||
uncompyle6/semantics/make_function.py, uncompyle6/version.py: Merge
|
||||
changes ... * str() in Python 2.4 doesn't detect unicode. * index() doesn't work on tuples * ifelse change
|
||||
|
||||
2017-01-11 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit 7ece296f7638e71fad1117b940f7ffddbe095b1f Merge: 78a5b62
|
||||
5035d54 Author: R. Bernstein <rocky@users.noreply.github.com> Date:
|
||||
Wed Jan 11 07:10:23 2017 -0500
|
||||
|
||||
2017-01-11 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* : Merge pull request #79 from rocky/revert-78-patch-1 Revert "fix bug : not generate all files when use "-ro""
|
||||
* uncompyle6/main.py: Revert "fix bug : not generate all files when
|
||||
use "-ro""
|
||||
|
||||
2017-01-11 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
@@ -1173,6 +729,16 @@
|
||||
* uncompyle6/parsers/parse35.py, uncompyle6/scanners/scanner3.py:
|
||||
Python 3.5 continue detection bug
|
||||
|
||||
2017-01-02 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/verify.py: 2.4 verify hacks
|
||||
|
||||
2017-01-02 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit a7d93e88b4e0dfd6876a7a31bd201a0e40f24bea Merge: 9891494
|
||||
136f42a Author: rocky <rb@dustyfeet.com> Date: Mon Jan 2 05:39:13
|
||||
2017 -0500
|
||||
|
||||
2017-01-01 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: add come_from for setup_finally
|
||||
@@ -1187,6 +753,14 @@
|
||||
|
||||
* README.rst: Note how to verify correctness ... with --verify, --weak-verify and cross checking with pycdc
|
||||
|
||||
2016-12-31 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/version.py: We are version 2.9.9
|
||||
|
||||
2016-12-31 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/main.py: 2.7->2.4 conversion
|
||||
|
||||
2016-12-31 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, uncompyle6/version.py: Get ready for release
|
||||
@@ -1196,6 +770,13 @@
|
||||
|
||||
* uncompyle6/parsers/parse26.py: 2.x list_if may have a THEN in it
|
||||
|
||||
2016-12-31 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/Makefile, uncompyle6/main.py, uncompyle6/parsers/parse26.py,
|
||||
uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner26.py,
|
||||
uncompyle6/scanners/scanner3.py, uncompyle6/semantics/pysource.py,
|
||||
uncompyle6/verify.py: Merge master branche Handle 2.2 list_if
|
||||
|
||||
2016-12-31 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner3.py: Towards fixing a Python 3.3
|
||||
@@ -1224,10 +805,9 @@
|
||||
|
||||
* : Merge pull request #73 from rocky/then-crap Add THEN token to improve Python 2.2-2.6 control flow detection
|
||||
|
||||
2016-12-28 rocky <rb@dustyfeet.com>
|
||||
2016-12-29 R. Bernstein <rocky@users.noreply.github.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/scanners/tok.py: Misc
|
||||
bugs
|
||||
* : Merge pull request #72 from rocky/master THEN psuedo-ops for Python 2.x
|
||||
|
||||
2016-12-28 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -1254,8 +834,7 @@
|
||||
|
||||
2016-12-27 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner2.py: Make 2.6 and 2.7 ingest more
|
||||
alike
|
||||
* : Merge commit '9b1dd0f' into python-2.4
|
||||
|
||||
2016-12-26 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -1275,6 +854,11 @@
|
||||
* uncompyle6/parsers/parse25.py: fix bug in using python2 AST rules
|
||||
in python 2.5
|
||||
|
||||
2016-12-26 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse25.py: Bug in using python2 ast checking
|
||||
in python 2.5
|
||||
|
||||
2016-12-26 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit f1a947f106b231fb1480ba301b15e3ceaf78c94f Author: rocky
|
||||
@@ -1287,15 +871,19 @@
|
||||
uncompyle6/verify.py: Scanner call fixes. NAME_MODULE removal for
|
||||
<=2.4
|
||||
|
||||
2016-12-24 rocky <rb@dustyfeet.com>
|
||||
2016-12-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/astnode.py, uncompyle6/parsers/parse2.py,
|
||||
uncompyle6/parsers/parse26.py, uncompyle6/parsers/parse3.py,
|
||||
uncompyle6/parsers/parse36.py, uncompyle6/scanners/scanner15.py,
|
||||
uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner21.py,
|
||||
uncompyle6/scanners/scanner22.py,
|
||||
uncompyle6/semantics/fragments.py, uncompyle6/semantics/pysource.py:
|
||||
Lint
|
||||
* uncompyle6/main.py, uncompyle6/scanners/scanner15.py,
|
||||
uncompyle6/scanners/scanner21.py, uncompyle6/scanners/scanner22.py,
|
||||
uncompyle6/scanners/scanner23.py, uncompyle6/scanners/scanner24.py,
|
||||
uncompyle6/semantics/pysource.py, uncompyle6/verify.py: Removing
|
||||
NAME_MODULE, lint and bug fixes scanner*.py: show_asm param is optional verify.py: call correct
|
||||
scanners main.py, verify.py: Use older Python print statements
|
||||
|
||||
2016-12-25 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit e3f4beeb74e33d5b404094765cc63040f62a0b41 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sat Dec 24 07:45:02 2016 -0500
|
||||
|
||||
2016-12-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -1316,22 +904,34 @@
|
||||
|
||||
2016-12-18 rocky <rb@dustyfeet.com>
|
||||
|
||||
* pytest/.gitignore, test/simple_source/bug25/02_try_else.py,
|
||||
uncompyle6/parsers/parse25.py, uncompyle6/parsers/parse26.py: Python
|
||||
2.5 mistaken try/else
|
||||
* : commit c7c0a989829a9a625333665516387c1177c611c2 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sun Dec 18 00:56:07 2016 -0500
|
||||
|
||||
2016-12-17 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner25.py:
|
||||
show-asm on python2.5 is optional make scanner2 look a little more like scanner3
|
||||
|
||||
2016-12-17 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner25.py:
|
||||
show-asm on python2.5 is optional Make scanner2 a little more like scanner3.
|
||||
|
||||
2016-12-17 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parser.py, uncompyle6/scanner.py,
|
||||
uncompyle6/scanners/scanner2.py, uncompyle6/scanners/scanner3.py,
|
||||
uncompyle6/semantics/fragments.py: Python 2.6/2.7 tolerance in
|
||||
Python 2.4 branch
|
||||
|
||||
2016-12-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
* NEWS: Release 2.9.8 news
|
||||
|
||||
2016-12-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, uncompyle6/version.py: Get ready for release 2.9.8
|
||||
* : commit 13d5cd1a588b7f4f2c233c436ce6b0b39db9950e Author: rocky
|
||||
<rb@dustyfeet.com> Date: Fri Dec 16 22:42:46 2016 -0500
|
||||
|
||||
2016-12-16 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -1399,15 +999,12 @@
|
||||
|
||||
2016-12-04 rocky <rb@dustyfeet.com>
|
||||
|
||||
* ChangeLog, NEWS, uncompyle6/main.py, uncompyle6/parser.py,
|
||||
uncompyle6/parsers/parse26.py, uncompyle6/parsers/parse3.py,
|
||||
uncompyle6/parsers/parse34.py, uncompyle6/parsers/parse35.py,
|
||||
uncompyle6/scanner.py, uncompyle6/scanners/scanner2.py,
|
||||
uncompyle6/scanners/scanner23.py, uncompyle6/scanners/scanner24.py,
|
||||
uncompyle6/scanners/scanner3.py, uncompyle6/scanners/tok.py,
|
||||
uncompyle6/semantics/make_function.py,
|
||||
uncompyle6/semantics/pysource.py, uncompyle6/verify.py,
|
||||
uncompyle6/version.py: Get ready for release 2.9.7 Some of the many lint things. Linting is kind of stupid though.
|
||||
* ChangeLog: Get ready for release 2.9.7
|
||||
|
||||
2016-12-04 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit d22931cb49f0e28a0fbe48a7c1526b1f170a5b52 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Sun Dec 4 07:31:34 2016 -0500
|
||||
|
||||
2016-11-28 rocky <rb@dustyfeet.com>
|
||||
|
||||
@@ -1458,11 +1055,34 @@
|
||||
* uncompyle6/semantics/pysource.py: Better line number tracking Indent Python 2 list comprehensions, albeit badly. DRY code a
|
||||
little via indent_if_source_nl
|
||||
|
||||
2016-11-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
* circle.yml: CircleCI build
|
||||
|
||||
2016-11-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py: Remove dup Python 3 grammar rule
|
||||
|
||||
2016-11-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
* uncompyle6/parsers/parse3.py, uncompyle6/scanners/scanner2.py:
|
||||
<2.7 "if" detection and dup Python 3 grammar rule
|
||||
|
||||
2016-11-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
* test/test_pyenvlib.py, uncompyle6/linenumbers.py,
|
||||
uncompyle6/main.py, uncompyle6/scanners/scanner2.py,
|
||||
uncompyle6/semantics/make_function.py,
|
||||
uncompyle6/semantics/pysource.py, uncompyle6/verify.py: Bug in 2.4
|
||||
"if" dectection and... Wrong language used in old-style exceptions: use "except Error,e"
|
||||
not "except Error(e)""
|
||||
|
||||
2016-11-24 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, pytest/test_grammar.py, uncompyle6/parser.py,
|
||||
uncompyle6/parsers/parse26.py: Python 2.6 grammary bug and.. __pkginfo.py__: Bump spark_parser
|
||||
version for parse_flags 'dups'
|
||||
|
||||
2016-11-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* __pkginfo__.py, pytest/test_grammar.py, uncompyle6/parser.py,
|
||||
@@ -1474,8 +1094,17 @@
|
||||
|
||||
2016-11-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit 6aa1531972de83ecab15b4c96b89c873ea5a7458 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Wed Nov 23 00:48:38 2016 -0500
|
||||
* : commit 7133540c235e16f02d2db62cb903b70aa311de20 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Wed Nov 23 08:26:12 2016 -0500
|
||||
|
||||
2016-11-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* : commit a9349b8f3d12b2aa0cd88286617c1af9cccad018 Author: rocky
|
||||
<rb@dustyfeet.com> Date: Tue Nov 22 17:49:47 2016 -0500
|
||||
|
||||
2016-11-23 rocky <rb@dustyfeet.com>
|
||||
|
||||
* circle.yml: Circle CI uses 2.7.10 and 2.7.12 is not available
|
||||
|
||||
2016-11-22 rocky <rb@dustyfeet.com>
|
||||
|
||||
|
15
HISTORY.md
15
HISTORY.md
@@ -44,8 +44,8 @@ it appears that Hartmut did most of the work to get this code to
|
||||
accept the full Python language. He added precedence to the table
|
||||
specifiers, support for multiple versions of Python, the
|
||||
pretty-printing of docstrings, lists, and hashes. He also wrote test and verification routines of
|
||||
deparsed bytecode, and used this in an extensive set of tests that he also wrote. He says he could verify against the
|
||||
entire Python library. However I have subsequently found small and relatively obscure bugs in the decompilation code.
|
||||
deparsed bytecode, and used this in an extensive set of tests that he also wrote. He says he could verify against the
|
||||
entire Python library. However I have subsequently found small and relatively obscure bugs in the decompilation code.
|
||||
|
||||
decompyle2.2 was packaged for Debian (sarge) by
|
||||
[Ben Burton around 2002](https://packages.qa.debian.org/d/decompyle.html). As
|
||||
@@ -66,7 +66,7 @@ code to handle first Python 2.3 and then 2.4 bytecodes. Because of
|
||||
jump optimization introduced in the CPython bytecode compiler at that
|
||||
time, various JUMP instructions were classifed as going backwards, and
|
||||
COME FROM instructions were reintroduced. See
|
||||
[RELEASE-2.4-CHANGELOG.txt](https://github.com/rocky/python-uncompyle6/blob/master/DECOMPYLE-2.4-CHANGELOG.txt)
|
||||
[RELEASE-2.4-CHANGELOG.txt](https://github.com/rocky/python-uncompyle6/blob/master/DECOMPYLE-2.4-CHANGELOG.txt)
|
||||
for more details here. There wasn't a public
|
||||
release of RELEASE-2.4 and bytecodes other than Python 2.4 weren't
|
||||
supported. Dan says the Python 2.3 version could verify the entire
|
||||
@@ -99,7 +99,7 @@ made a few commits later on. But mostly wibiti, and Guenther
|
||||
Starnberger got the code to where uncompyle2 was around 2012.
|
||||
|
||||
In `uncompyle`, decompilation of python bytecode 2.5 & 2.6 is done by
|
||||
transforming the byte code into a pseudo-2.7 Python bytecode and is
|
||||
transforming the byte code into a a pseudo 2.7 python bytecode and is
|
||||
based on code from Eloi Vanderbeken.
|
||||
|
||||
This project, `uncompyle6`, abandons that approach for various
|
||||
@@ -120,10 +120,10 @@ while, handling Python bytecodes from Python versions 2.5+ and
|
||||
3.2+. In doing so, it has been expedient to separate this into three
|
||||
projects:
|
||||
|
||||
* marshaling/unmarshaling, bytecode loading and disassembly ([xdis](https://pypi.python.org/pypi/xdis)),
|
||||
* bytecode loading and disassembly ([xdis](https://pypi.python.org/pypi/xdis)),
|
||||
* parsing and tree building ([spark_parser](https://pypi.python.org/pypi/spark_parser)),
|
||||
* this project - grammar and semantic actions for decompiling
|
||||
([uncompyle6](https://pypi.python.org/pypi/uncompyle6)).
|
||||
([uncompyle6](https://pypi.python.org/pypi/spark_parser)).
|
||||
|
||||
|
||||
Over the many years, code styles and Python features have
|
||||
@@ -162,8 +162,5 @@ support has been lagging.
|
||||
Tests for the project have been, or are being, culled from all of the
|
||||
projects mentioned.
|
||||
|
||||
For a little bit of the history of changes to the Early-algorithm parser,
|
||||
see the file [NEW-FEATURES.rst](https://github.com/rocky/python-spark/blob/master/NEW-FEATURES.rst) in the [python-spark github repository](https://github.com/rocky/python-spark).
|
||||
|
||||
NB. If you find mistakes, want corrections, or want your name added
|
||||
(or removed), please contact me.
|
||||
|
@@ -7,7 +7,7 @@ decompyle everything. This one probably does the
|
||||
best job of *any* Python decompiler. But it is a constant work in progress: Python keeps changing, and so does its code generation.
|
||||
|
||||
I have found bugs in *every* Python decompiler I have tried. Even
|
||||
those where authors/maintainers claim that they have used it on
|
||||
those where authors/maintainers claim that they have used it on
|
||||
the entire Python standard library. And I don't mean that
|
||||
the program doesn't come out with the same Python source instructions,
|
||||
but that the program is *semantically* not equivalent.
|
||||
@@ -19,7 +19,7 @@ So it is likely you'll find a mistranslation in decompiling.
|
||||
The basic requirement is pretty simple:
|
||||
|
||||
* Python bytecode
|
||||
* Python source text
|
||||
* Source text
|
||||
|
||||
## What to send (additional helpful information)
|
||||
|
||||
@@ -29,7 +29,7 @@ can figure out what OS you are running this on and what version of
|
||||
*uncomplye6* was used. Therefore, if you don't provide the input
|
||||
command and the output from that, please give:
|
||||
|
||||
* _uncompyle6_ version used
|
||||
* _uncompile6_ version used
|
||||
* OS that you used this on
|
||||
* Python interpreter version used
|
||||
|
||||
@@ -37,20 +37,15 @@ command and the output from that, please give:
|
||||
### But I don't *have* the source code!
|
||||
|
||||
Sure, I get it. No problem. There is Python assembly code on parse
|
||||
errors, so simply by hand decompile that. To get a full disassembly,
|
||||
use pydisasm from the [xdis](https://pypi.python.org/pypi/xdis)
|
||||
package. Opcodes are described in the documentation for
|
||||
the [dis](https://docs.python.org/3.6/library/dis.html) module.
|
||||
errors, so simply by hand decompile that. To get a full disassembly, use pydisasm from the [xdis](https://pypi.python.org/pypi/xdis) package. Opcodes are described in the documentation for the [dis](https://docs.python.org/3.6/library/dis.html) module.
|
||||
|
||||
### But I don't *have* the source code and am incapable of figuring how how to do a hand disassembly!
|
||||
|
||||
Well, you could learn. No one is born into this world knowing how to
|
||||
disassemble Python bytecode. And as Richard Feynman once said, "What
|
||||
one fool can learn, so can another."
|
||||
Well, you could learn. No one is born into this world knowing how to disassemble Python bytecode. And as Richard Feynman once said, "What one fool can learn, so can another."
|
||||
|
||||
## Narrowing the problem
|
||||
|
||||
I don't need or want the entire source code base for which one file or module
|
||||
I don't need the entire source code base for which one file or module
|
||||
can't be decompiled. I just need that one file or module only. If
|
||||
there are several files, file a bug report for each file.
|
||||
|
||||
|
4
Makefile
4
Makefile
@@ -37,7 +37,7 @@ check-3.0 check-3.1 check-3.2 check-3.5 check-3.6:
|
||||
$(MAKE) -C test $@
|
||||
|
||||
#:Tests for Python 2.6 (doesn't have pytest)
|
||||
check-2.6:
|
||||
check-2.4 check-2.5 check-2.6:
|
||||
$(MAKE) -C test $@
|
||||
|
||||
#:PyPy 2.6.1 or PyPy 5.0.1
|
||||
@@ -59,7 +59,7 @@ clean: clean_pyc
|
||||
|
||||
#: Create source (tarball) and wheel distribution
|
||||
dist:
|
||||
$(PYTHON) ./setup.py sdist bdist_wheel
|
||||
$(PYTHON) ./setup.py sdist bdist_egg
|
||||
|
||||
#: Remove .pyc files
|
||||
clean_pyc:
|
||||
|
95
NEWS
95
NEWS
@@ -1,81 +1,10 @@
|
||||
uncompyle6 2.11.4 2017-08-15
|
||||
|
||||
* scanner and parser now allow 3-part version string lookups,
|
||||
e.g. 2.7.1 We allow a float here, but if passed a string like '2.7'. or
|
||||
* unpin 3.5.1. xdis 3.5.4 has been releasd and fixes the problems we had. Use that.
|
||||
* some routnes here moved to xdis. Use the xdis version
|
||||
* README.rst: Link typo Name is trepan2 now not trepan
|
||||
* xdis-forched change adjust for COMPARE_OP "is-not" in
|
||||
semanatic routines. We need "is not".
|
||||
* Some PyPy tolerance in validate testing.
|
||||
* Some pyston tolerance
|
||||
|
||||
uncompyle6 2.11.3 2017-08-09
|
||||
|
||||
Very minor changes
|
||||
|
||||
- RsT doc fixes and updates
|
||||
- use newer xdis, but not too new; 3.5.2 breaks uncompyle6
|
||||
- use xdis opcode sets
|
||||
- xdis "exception match" is now "exception-match"
|
||||
|
||||
uncompyle6 2.11.2 2017-07-09
|
||||
|
||||
- Start supporting Pypy 3.5 (5.7.1-beta)
|
||||
- use xdis 3.5.0's opcode sets and require xdis 3.5.0
|
||||
- Correct some Python 2.4-2.6 loop detection
|
||||
- guard against badly formatted bytecode
|
||||
|
||||
uncompyle6 2.11.1 2017-06-25
|
||||
|
||||
- Python 3.x annotation and function signature fixes
|
||||
- Bump xdis version
|
||||
- Small pysource bug fixes
|
||||
|
||||
uncompyle6 2.11.0 2017-06-18 Fleetwood
|
||||
- Major improvements in fragment tracking
|
||||
* Add nonterminal node in extractInfo
|
||||
* tag more offsets in expressions
|
||||
* tag array subscripts
|
||||
* set YIELD value offset in a <yield> expr
|
||||
* fix a long-standing bug in not adjusting final AST when melding other deparse ASTs
|
||||
- Fixes yet again for make_function node handling; document what's up here
|
||||
- Fix bug in snowflake Python 3.5 *args kwargs
|
||||
|
||||
uncompyle6 2.10.1 2017-06-3 Marylin Frankel
|
||||
|
||||
- fix some fragments parsing bugs
|
||||
- was returning the wrong type sometimes in deparse_code_around_offset()
|
||||
- capture function name in offsets
|
||||
- track changes to ifelstrmtr node from pysource into fragments
|
||||
|
||||
uncompyle6 2.10.0 2017-05-30 Elaine Gordon
|
||||
|
||||
- Add fuzzy offset deparse look up
|
||||
- 3.6 bug fixes
|
||||
- fix EXTENDED_ARGS handling (and in 2.6 and others)
|
||||
- semantic routine make_function fragments.py
|
||||
- MAKE_FUNCTION handling
|
||||
- CALL_FUNCTION_EX handling
|
||||
- async property on defs
|
||||
- support for CALL_FUNCTION_KW (moagstar)
|
||||
- 3.5+ UNMAP_PACK and BUILD_UNMAP_PACK handling
|
||||
- 3.5 FUNCTION_VAR bug
|
||||
- 3.x pass statement insdie while True
|
||||
- Improve 3.2 decompilation
|
||||
- Fixed -o argument processing (grkov90)
|
||||
- Reduce scope of LOAD_ASSERT as expr to 3.4+
|
||||
- "await" statement fixes
|
||||
- 2.3, 2.4 "if 1 .." fixes
|
||||
- 3.x annotation fixes
|
||||
|
||||
uncompyle6 2.9.11 2017-04-06
|
||||
uncompyle6 2.9.11 2016-04-06
|
||||
|
||||
- Better support for Python 3.5+ BUILD_MAP_UNPACK
|
||||
- Start 3.6 CALL_FUNCTION_EX support
|
||||
- Many decompilation bug fixes. (Many more remain). See ChangeLog
|
||||
|
||||
uncompyle6 2.9.10 2017-02-25
|
||||
uncompyle6 2.9.10 2016-02-25
|
||||
|
||||
- Python grammar rule fixes
|
||||
- Add ability to get grammar coverage on runs
|
||||
@@ -142,7 +71,7 @@ uncompyle6 2.9.6 2016-11-20
|
||||
uncompyle6 2.9.5 2016-11-13
|
||||
|
||||
- Fix Python 3 bugs:
|
||||
* improper while 1 else
|
||||
* improprer while 1 else
|
||||
* docstring indent
|
||||
* 3.3 default values in lambda expressions
|
||||
* start 3.0 decompilation (needs newer xdis)
|
||||
@@ -152,12 +81,12 @@ uncompyle6 2.9.5 2016-11-13
|
||||
uncompyle6 2.9.4 2016-11-02
|
||||
|
||||
- Handle Python 3.x function annotations
|
||||
- track def keyword-parameter line-splitting in source code better
|
||||
- track def keywoard-parameter line-splitting in source code better
|
||||
- bump min xdis version to mask previous xdis bug
|
||||
|
||||
uncompyle6 2.9.3 2016-10-26
|
||||
|
||||
Release forced by incompatibility change in xdis 3.2.0.
|
||||
Release forced by incompatiblity change in xdis 3.2.0.
|
||||
|
||||
- Python 3.1 bugs:
|
||||
* handle "with ... as"
|
||||
@@ -189,7 +118,7 @@ uncompyle6 2.9.0 2016-10-09
|
||||
this Forces change in requirements.txt and _pkg_info_.py
|
||||
- Start Python 1.5 decompiling; another round of work is needed to
|
||||
remove bugs
|
||||
- Simplify python 2.1 grammar
|
||||
- Simpify python 2.1 grammar
|
||||
- Fix bug with -t ... Wasn't showing source text when -t option was given
|
||||
- Fix 2.1-2.6 bug in list comprehension
|
||||
|
||||
@@ -212,7 +141,7 @@ control-flow structure detection is done.
|
||||
. 3.0 .. 3.2 *args processing
|
||||
. 3.0 .. 3.2 call name and kwargs bug
|
||||
. 3.0 .. getting parameter of *
|
||||
. 3.0 .. handling variable number of args
|
||||
. 3.0 .. handling varible number of args
|
||||
. 3.0 .. "if" structure bugs
|
||||
* 3.5+ if/else bugs
|
||||
* 2.2-2.6 bugs
|
||||
@@ -263,7 +192,7 @@ uncompyle6 2.7.1 2016-07-26
|
||||
|
||||
uncompyle6 2.7.0 2016-07-15
|
||||
|
||||
- Many Syntax and verification bugs removed
|
||||
- Many Syntax and verifification bugs removed
|
||||
tested on standard libraries from 2.3.7 to 3.5.1
|
||||
and they all decompile and verify fine.
|
||||
I'm sure there are more bugs though.
|
||||
@@ -290,9 +219,9 @@ uncompyle6 2.6.0 2016-07-07
|
||||
- Better <2.6 vs. 2.7 grammar separation
|
||||
- Fix some 2.7 deparsing bugs
|
||||
- Fix bug in installing uncompyle6 script
|
||||
- Doc improvements
|
||||
- Doc improvments
|
||||
|
||||
uncompyle6 2.5.0 2016-06-22 Summer Solstice
|
||||
uncompyle6 2.5.0 2016-06-22 Summer Solstace
|
||||
|
||||
- Much better Python 3.2-3.5 coverage.
|
||||
3.4.6 is probably the best;3.2 and 3.5 are weaker
|
||||
@@ -304,7 +233,7 @@ uncompyle6 2.5.0 2016-06-22 Summer Solstice
|
||||
uncompyle6 2.4.0 2016-05-18 (in memory of Lewis Bernstein)
|
||||
|
||||
- Many Python 3 bugs fixed:
|
||||
* Python 3.2 to 3.5 libraries largely
|
||||
* Python 3.2 to 3.5 libaries largely
|
||||
uncompyle and most verify
|
||||
- pydisassembler:
|
||||
* disassembles all code objects in a file
|
||||
@@ -362,7 +291,7 @@ uncompyle6 2.2.0 2016-04-30
|
||||
|
||||
uncompyle6 2.2.0 2016-04-02
|
||||
|
||||
- Support single-mode (in addition to exec-mode) compilation
|
||||
- Support single-mode (in addtion to exec-mode) compilation
|
||||
- Start to DRY Python 2 and Python 3 grammars
|
||||
- Fix bug in if else ternary construct
|
||||
- Fix bug in uncomplye6 -d and -r options (via lelicopter)
|
||||
|
11
README.rst
11
README.rst
@@ -56,7 +56,7 @@ This uses setup.py, so it follows the standard Python routine:
|
||||
|
||||
::
|
||||
|
||||
pip install -e .
|
||||
pip install -r requirements.txt
|
||||
pip install -r requirements-dev.txt
|
||||
python setup.py install # may need sudo
|
||||
# or if you have pyenv:
|
||||
@@ -168,15 +168,12 @@ See Also
|
||||
--------
|
||||
|
||||
* https://github.com/zrax/pycdc : supports all versions of Python and is written in C++. Support for later Python 3 versions is a bit lacking though.
|
||||
* https://code.google.com/archive/p/unpyc3/ : supports Python 3.2 only. The above projects use a different decompiling technique than what is used here.
|
||||
* https://code.google.com/archive/p/unpyc3/ : supports Python 3.2 only. The above projects use a different decompiling technique what is used here.
|
||||
* https://github.com/figment/unpyc3/ : fork of above, but supports Python 3.3 only. Include some fixes like supporting function annotations
|
||||
* The HISTORY_ file.
|
||||
* `How to report a bug <https://github.com/rocky/python-uncompyle6/blob/master/HOW-TO-REPORT-A-BUG.md>`_
|
||||
* https://github.com/rocky/python-xdis : Cross Python version disassembler
|
||||
* https://github.com/rocky/python-xasm : Cross Python version assembler
|
||||
|
||||
|
||||
.. _trepan: https://pypi.python.org/pypi/trepan2
|
||||
.. |downloads| image:: https://img.shields.io/pypi/dd/uncompyle6.svg
|
||||
.. _trepan: https://pypi.python.org/pypi/trepan
|
||||
.. _HISTORY: https://github.com/rocky/python-uncompyle6/blob/master/HISTORY.md
|
||||
.. _debuggers: https://pypi.python.org/pypi/trepan3k
|
||||
.. _remake: https://bashdb.sf.net/remake
|
||||
|
@@ -33,14 +33,14 @@ classifiers = ['Development Status :: 5 - Production/Stable',
|
||||
# The rest in alphabetic order
|
||||
author = "Rocky Bernstein, Hartmut Goebel, John Aycock, and others"
|
||||
author_email = "rb@dustyfeet.com"
|
||||
entry_points = {
|
||||
entry_points={
|
||||
'console_scripts': [
|
||||
'uncompyle6=uncompyle6.bin.uncompile:main_bin',
|
||||
'pydisassemble=uncompyle6.bin.pydisassemble:main',
|
||||
]}
|
||||
ftp_url = None
|
||||
install_requires = ['spark-parser >= 1.6.1, < 1.7.0',
|
||||
'xdis >= 3.5.4, < 3.6.0', 'six']
|
||||
install_requires = ['spark-parser >= 1.6.0, < 1.7.0',
|
||||
'xdis >= 3.3.0, < 3.4.0']
|
||||
license = 'MIT'
|
||||
mailing_list = 'python-debugger@googlegroups.com'
|
||||
modname = 'uncompyle6'
|
||||
|
78
appveyor.yml
78
appveyor.yml
@@ -1,78 +0,0 @@
|
||||
environment:
|
||||
global:
|
||||
# SDK v7.0 MSVC Express 2008's SetEnv.cmd script will fail if the
|
||||
# /E:ON and /V:ON options are not enabled in the batch script intepreter
|
||||
# See: http://stackoverflow.com/a/13751649/163740
|
||||
CMD_IN_ENV: "cmd /E:ON /V:ON /C .\\appveyor\\run_with_env.cmd"
|
||||
|
||||
matrix:
|
||||
|
||||
# Pre-installed Python versions, which Appveyor may upgrade to
|
||||
# a later point release.
|
||||
# See: http://www.appveyor.com/docs/installed-software#python
|
||||
|
||||
# - PYTHON: "C:\\Python27"
|
||||
# PYTHON_VERSION: "2.7.x"
|
||||
# PYTHON_ARCH: "32"
|
||||
|
||||
- PYTHON: "C:\\Python27-x64"
|
||||
PYTHON_VERSION: "2.7.x"
|
||||
PYTHON_ARCH: "64"
|
||||
|
||||
# - PYTHON: "C:\\Python26"
|
||||
# PYTHON_VERSION: "2.6.x"
|
||||
# PYTHON_ARCH: "32"
|
||||
|
||||
# - PYTHON: "C:\\Python26-x64"
|
||||
# PYTHON_VERSION: "2.6.x"
|
||||
# PYTHON_ARCH: "64"
|
||||
|
||||
install:
|
||||
# We need wheel installed to build wheels
|
||||
- "%PYTHON%\\python.exe -m pip install wheel"
|
||||
|
||||
# Install Python (from the official .msi of http://python.org) and pip when
|
||||
# not already installed.
|
||||
- ps: if (-not(Test-Path($env:PYTHON))) { & appveyor\install.ps1 }
|
||||
|
||||
# Prepend newly installed Python to the PATH of this build (this cannot be
|
||||
# done from inside the powershell script as it would require to restart
|
||||
# the parent CMD process).
|
||||
- "SET PATH=%PYTHON%;%PYTHON%\\Scripts;%PATH%"
|
||||
- "SET HOME=."
|
||||
|
||||
# Check that we have the expected version and architecture for Python
|
||||
- "python --version"
|
||||
- "python -c \"import struct; print(struct.calcsize('P') * 8)\""
|
||||
|
||||
# Upgrade to the latest version of pip to avoid it displaying warnings
|
||||
# about it being out of date.
|
||||
- "pip install --disable-pip-version-check --user --upgrade pip"
|
||||
|
||||
# Install the build dependencies of the project. If some dependencies contain
|
||||
# compiled extensions and are not provided as pre-built wheel packages,
|
||||
# pip will build them from source using the MSVC compiler matching the
|
||||
# target Python version and architecture
|
||||
- "%CMD_IN_ENV% pip install -r requirements.txt"
|
||||
|
||||
build_script:
|
||||
# Build the compiled extension
|
||||
- "%CMD_IN_ENV% python setup.py build"
|
||||
|
||||
test_script:
|
||||
# Run the project tests
|
||||
- "%CMD_IN_ENV% python test/test_pyenvlib.py --native --weak-verify"
|
||||
|
||||
after_test:
|
||||
# If tests are successful, create binary packages for the project.
|
||||
- "%CMD_IN_ENV% python setup.py bdist_wininst"
|
||||
- "%CMD_IN_ENV% python setup.py bdist_msi"
|
||||
- ps: "ls dist"
|
||||
|
||||
artifacts:
|
||||
# Archive the generated packages in the ci.appveyor.com build report.
|
||||
- path: dist\*
|
||||
|
||||
#on_success:
|
||||
# - TODO: upload the content of dist/*.whl to a public wheelhouse
|
||||
#
|
@@ -1,229 +0,0 @@
|
||||
# Sample script to install Python and pip under Windows
|
||||
# Authors: Olivier Grisel, Jonathan Helmus, Kyle Kastner, and Alex Willmer
|
||||
# License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
|
||||
$MINICONDA_URL = "http://repo.continuum.io/miniconda/"
|
||||
$BASE_URL = "https://www.python.org/ftp/python/"
|
||||
$GET_PIP_URL = "https://bootstrap.pypa.io/get-pip.py"
|
||||
$GET_PIP_PATH = "C:\get-pip.py"
|
||||
|
||||
$PYTHON_PRERELEASE_REGEX = @"
|
||||
(?x)
|
||||
(?<major>\d+)
|
||||
\.
|
||||
(?<minor>\d+)
|
||||
\.
|
||||
(?<micro>\d+)
|
||||
(?<prerelease>[a-z]{1,2}\d+)
|
||||
"@
|
||||
|
||||
|
||||
function Download ($filename, $url) {
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
|
||||
$basedir = $pwd.Path + "\"
|
||||
$filepath = $basedir + $filename
|
||||
if (Test-Path $filename) {
|
||||
Write-Host "Reusing" $filepath
|
||||
return $filepath
|
||||
}
|
||||
|
||||
# Download and retry up to 3 times in case of network transient errors.
|
||||
Write-Host "Downloading" $filename "from" $url
|
||||
$retry_attempts = 2
|
||||
for ($i = 0; $i -lt $retry_attempts; $i++) {
|
||||
try {
|
||||
$webclient.DownloadFile($url, $filepath)
|
||||
break
|
||||
}
|
||||
Catch [Exception]{
|
||||
Start-Sleep 1
|
||||
}
|
||||
}
|
||||
if (Test-Path $filepath) {
|
||||
Write-Host "File saved at" $filepath
|
||||
} else {
|
||||
# Retry once to get the error message if any at the last try
|
||||
$webclient.DownloadFile($url, $filepath)
|
||||
}
|
||||
return $filepath
|
||||
}
|
||||
|
||||
|
||||
function ParsePythonVersion ($python_version) {
|
||||
if ($python_version -match $PYTHON_PRERELEASE_REGEX) {
|
||||
return ([int]$matches.major, [int]$matches.minor, [int]$matches.micro,
|
||||
$matches.prerelease)
|
||||
}
|
||||
$version_obj = [version]$python_version
|
||||
return ($version_obj.major, $version_obj.minor, $version_obj.build, "")
|
||||
}
|
||||
|
||||
|
||||
function DownloadPython ($python_version, $platform_suffix) {
|
||||
$major, $minor, $micro, $prerelease = ParsePythonVersion $python_version
|
||||
|
||||
if (($major -le 2 -and $micro -eq 0) `
|
||||
-or ($major -eq 3 -and $minor -le 2 -and $micro -eq 0) `
|
||||
) {
|
||||
$dir = "$major.$minor"
|
||||
$python_version = "$major.$minor$prerelease"
|
||||
} else {
|
||||
$dir = "$major.$minor.$micro"
|
||||
}
|
||||
|
||||
if ($prerelease) {
|
||||
if (($major -le 2) `
|
||||
-or ($major -eq 3 -and $minor -eq 1) `
|
||||
-or ($major -eq 3 -and $minor -eq 2) `
|
||||
-or ($major -eq 3 -and $minor -eq 3) `
|
||||
) {
|
||||
$dir = "$dir/prev"
|
||||
}
|
||||
}
|
||||
|
||||
if (($major -le 2) -or ($major -le 3 -and $minor -le 4)) {
|
||||
$ext = "msi"
|
||||
if ($platform_suffix) {
|
||||
$platform_suffix = ".$platform_suffix"
|
||||
}
|
||||
} else {
|
||||
$ext = "exe"
|
||||
if ($platform_suffix) {
|
||||
$platform_suffix = "-$platform_suffix"
|
||||
}
|
||||
}
|
||||
|
||||
$filename = "python-$python_version$platform_suffix.$ext"
|
||||
$url = "$BASE_URL$dir/$filename"
|
||||
$filepath = Download $filename $url
|
||||
return $filepath
|
||||
}
|
||||
|
||||
|
||||
function InstallPython ($python_version, $architecture, $python_home) {
|
||||
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host $python_home "already exists, skipping."
|
||||
return $false
|
||||
}
|
||||
if ($architecture -eq "32") {
|
||||
$platform_suffix = ""
|
||||
} else {
|
||||
$platform_suffix = "amd64"
|
||||
}
|
||||
$installer_path = DownloadPython $python_version $platform_suffix
|
||||
$installer_ext = [System.IO.Path]::GetExtension($installer_path)
|
||||
Write-Host "Installing $installer_path to $python_home"
|
||||
$install_log = $python_home + ".log"
|
||||
if ($installer_ext -eq '.msi') {
|
||||
InstallPythonMSI $installer_path $python_home $install_log
|
||||
} else {
|
||||
InstallPythonEXE $installer_path $python_home $install_log
|
||||
}
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host "Python $python_version ($architecture) installation complete"
|
||||
} else {
|
||||
Write-Host "Failed to install Python in $python_home"
|
||||
Get-Content -Path $install_log
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function InstallPythonEXE ($exepath, $python_home, $install_log) {
|
||||
$install_args = "/quiet InstallAllUsers=1 TargetDir=$python_home"
|
||||
RunCommand $exepath $install_args
|
||||
}
|
||||
|
||||
|
||||
function InstallPythonMSI ($msipath, $python_home, $install_log) {
|
||||
$install_args = "/qn /log $install_log /i $msipath TARGETDIR=$python_home"
|
||||
$uninstall_args = "/qn /x $msipath"
|
||||
RunCommand "msiexec.exe" $install_args
|
||||
if (-not(Test-Path $python_home)) {
|
||||
Write-Host "Python seems to be installed else-where, reinstalling."
|
||||
RunCommand "msiexec.exe" $uninstall_args
|
||||
RunCommand "msiexec.exe" $install_args
|
||||
}
|
||||
}
|
||||
|
||||
function RunCommand ($command, $command_args) {
|
||||
Write-Host $command $command_args
|
||||
Start-Process -FilePath $command -ArgumentList $command_args -Wait -Passthru
|
||||
}
|
||||
|
||||
|
||||
function InstallPip ($python_home) {
|
||||
$pip_path = $python_home + "\Scripts\pip.exe"
|
||||
$python_path = $python_home + "\python.exe"
|
||||
if (-not(Test-Path $pip_path)) {
|
||||
Write-Host "Installing pip..."
|
||||
$webclient = New-Object System.Net.WebClient
|
||||
$webclient.DownloadFile($GET_PIP_URL, $GET_PIP_PATH)
|
||||
Write-Host "Executing:" $python_path $GET_PIP_PATH
|
||||
& $python_path $GET_PIP_PATH
|
||||
} else {
|
||||
Write-Host "pip already installed."
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function DownloadMiniconda ($python_version, $platform_suffix) {
|
||||
if ($python_version -eq "3.4") {
|
||||
$filename = "Miniconda3-3.5.5-Windows-" + $platform_suffix + ".exe"
|
||||
} else {
|
||||
$filename = "Miniconda-3.5.5-Windows-" + $platform_suffix + ".exe"
|
||||
}
|
||||
$url = $MINICONDA_URL + $filename
|
||||
$filepath = Download $filename $url
|
||||
return $filepath
|
||||
}
|
||||
|
||||
|
||||
function InstallMiniconda ($python_version, $architecture, $python_home) {
|
||||
Write-Host "Installing Python" $python_version "for" $architecture "bit architecture to" $python_home
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host $python_home "already exists, skipping."
|
||||
return $false
|
||||
}
|
||||
if ($architecture -eq "32") {
|
||||
$platform_suffix = "x86"
|
||||
} else {
|
||||
$platform_suffix = "x86_64"
|
||||
}
|
||||
$filepath = DownloadMiniconda $python_version $platform_suffix
|
||||
Write-Host "Installing" $filepath "to" $python_home
|
||||
$install_log = $python_home + ".log"
|
||||
$args = "/S /D=$python_home"
|
||||
Write-Host $filepath $args
|
||||
Start-Process -FilePath $filepath -ArgumentList $args -Wait -Passthru
|
||||
if (Test-Path $python_home) {
|
||||
Write-Host "Python $python_version ($architecture) installation complete"
|
||||
} else {
|
||||
Write-Host "Failed to install Python in $python_home"
|
||||
Get-Content -Path $install_log
|
||||
Exit 1
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function InstallMinicondaPip ($python_home) {
|
||||
$pip_path = $python_home + "\Scripts\pip.exe"
|
||||
$conda_path = $python_home + "\Scripts\conda.exe"
|
||||
if (-not(Test-Path $pip_path)) {
|
||||
Write-Host "Installing pip..."
|
||||
$args = "install --yes pip"
|
||||
Write-Host $conda_path $args
|
||||
Start-Process -FilePath "$conda_path" -ArgumentList $args -Wait -Passthru
|
||||
} else {
|
||||
Write-Host "pip already installed."
|
||||
}
|
||||
}
|
||||
|
||||
function main () {
|
||||
InstallPython $env:PYTHON_VERSION $env:PYTHON_ARCH $env:PYTHON
|
||||
InstallPip $env:PYTHON
|
||||
}
|
||||
|
||||
main
|
@@ -1,87 +0,0 @@
|
||||
:: To build extensions for 64 bit Python 3, we need to configure environment
|
||||
:: variables to use the MSVC 2010 C++ compilers from GRMSDKX_EN_DVD.iso of:
|
||||
:: MS Windows SDK for Windows 7 and .NET Framework 4 (SDK v7.1)
|
||||
::
|
||||
:: To build extensions for 64 bit Python 2, we need to configure environment
|
||||
:: variables to use the MSVC 2008 C++ compilers from GRMSDKX_EN_DVD.iso of:
|
||||
:: MS Windows SDK for Windows 7 and .NET Framework 3.5 (SDK v7.0)
|
||||
::
|
||||
:: 32 bit builds, and 64-bit builds for 3.5 and beyond, do not require specific
|
||||
:: environment configurations.
|
||||
::
|
||||
:: Note: this script needs to be run with the /E:ON and /V:ON flags for the
|
||||
:: cmd interpreter, at least for (SDK v7.0)
|
||||
::
|
||||
:: More details at:
|
||||
:: https://github.com/cython/cython/wiki/64BitCythonExtensionsOnWindows
|
||||
:: http://stackoverflow.com/a/13751649/163740
|
||||
::
|
||||
:: Author: Olivier Grisel
|
||||
:: License: CC0 1.0 Universal: http://creativecommons.org/publicdomain/zero/1.0/
|
||||
::
|
||||
:: Notes about batch files for Python people:
|
||||
::
|
||||
:: Quotes in values are literally part of the values:
|
||||
:: SET FOO="bar"
|
||||
:: FOO is now five characters long: " b a r "
|
||||
:: If you don't want quotes, don't include them on the right-hand side.
|
||||
::
|
||||
:: The CALL lines at the end of this file look redundant, but if you move them
|
||||
:: outside of the IF clauses, they do not run properly in the SET_SDK_64==Y
|
||||
:: case, I don't know why.
|
||||
@ECHO OFF
|
||||
SET COMMAND_TO_RUN=%*
|
||||
SET WIN_SDK_ROOT=C:\Program Files\Microsoft SDKs\Windows
|
||||
SET WIN_WDK=c:\Program Files (x86)\Windows Kits\10\Include\wdf
|
||||
|
||||
:: Extract the major and minor versions, and allow for the minor version to be
|
||||
:: more than 9. This requires the version number to have two dots in it.
|
||||
SET MAJOR_PYTHON_VERSION=%PYTHON_VERSION:~0,1%
|
||||
IF "%PYTHON_VERSION:~3,1%" == "." (
|
||||
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,1%
|
||||
) ELSE (
|
||||
SET MINOR_PYTHON_VERSION=%PYTHON_VERSION:~2,2%
|
||||
)
|
||||
|
||||
:: Based on the Python version, determine what SDK version to use, and whether
|
||||
:: to set the SDK for 64-bit.
|
||||
IF %MAJOR_PYTHON_VERSION% == 2 (
|
||||
SET WINDOWS_SDK_VERSION="v7.0"
|
||||
SET SET_SDK_64=Y
|
||||
) ELSE (
|
||||
IF %MAJOR_PYTHON_VERSION% == 3 (
|
||||
SET WINDOWS_SDK_VERSION="v7.1"
|
||||
IF %MINOR_PYTHON_VERSION% LEQ 4 (
|
||||
SET SET_SDK_64=Y
|
||||
) ELSE (
|
||||
SET SET_SDK_64=N
|
||||
IF EXIST "%WIN_WDK%" (
|
||||
:: See: https://connect.microsoft.com/VisualStudio/feedback/details/1610302/
|
||||
REN "%WIN_WDK%" 0wdf
|
||||
)
|
||||
)
|
||||
) ELSE (
|
||||
ECHO Unsupported Python version: "%MAJOR_PYTHON_VERSION%"
|
||||
EXIT 1
|
||||
)
|
||||
)
|
||||
|
||||
IF %PYTHON_ARCH% == 64 (
|
||||
IF %SET_SDK_64% == Y (
|
||||
ECHO Configuring Windows SDK %WINDOWS_SDK_VERSION% for Python %MAJOR_PYTHON_VERSION% on a 64 bit architecture
|
||||
SET DISTUTILS_USE_SDK=1
|
||||
SET MSSdk=1
|
||||
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Setup\WindowsSdkVer.exe" -q -version:%WINDOWS_SDK_VERSION%
|
||||
"%WIN_SDK_ROOT%\%WINDOWS_SDK_VERSION%\Bin\SetEnv.cmd" /x64 /release
|
||||
ECHO Executing: %COMMAND_TO_RUN%
|
||||
call %COMMAND_TO_RUN% || EXIT 1
|
||||
) ELSE (
|
||||
ECHO Using default MSVC build environment for 64 bit architecture
|
||||
ECHO Executing: %COMMAND_TO_RUN%
|
||||
call %COMMAND_TO_RUN% || EXIT 1
|
||||
)
|
||||
) ELSE (
|
||||
ECHO Using default MSVC build environment for 32 bit architecture
|
||||
ECHO Executing: %COMMAND_TO_RUN%
|
||||
call %COMMAND_TO_RUN% || EXIT 1
|
||||
)
|
@@ -6,8 +6,8 @@ machine:
|
||||
|
||||
dependencies:
|
||||
override:
|
||||
- pip install -e .
|
||||
- pip install -r requirements.txt
|
||||
- pip install -r requirements-dev.txt
|
||||
test:
|
||||
override:
|
||||
- python ./setup.py develop && make check-2.7
|
||||
- python ./setup.py develop && make check-2.6
|
||||
|
@@ -1,6 +0,0 @@
|
||||
source ../.venv.3.6/bin/activate
|
||||
py.test -k test_CALL_FUNCTION_KW
|
||||
source ../.venv.3.5/bin/activate
|
||||
py.test -k test_CALL_FUNCTION_KW
|
||||
source ../.venv.2.7/bin/activate
|
||||
py.test -k test_CALL_FUNCTION_KW
|
@@ -1,11 +0,0 @@
|
||||
from uncompyle6.scanner import get_scanner
|
||||
from uncompyle6.parser import get_python_parser
|
||||
|
||||
def test_get_scanner():
|
||||
# See that we can retrieve a scanner using a full version number
|
||||
assert get_scanner('2.7.13')
|
||||
|
||||
|
||||
def test_get_parser():
|
||||
# See that we can retrieve a sparser using a full version number
|
||||
assert get_python_parser('2.7.13')
|
@@ -1,150 +0,0 @@
|
||||
# std
|
||||
import os
|
||||
# test
|
||||
import pytest
|
||||
import hypothesis
|
||||
from hypothesis import strategies as st
|
||||
# uncompyle6
|
||||
from uncompyle6 import PYTHON_VERSION, deparse_code
|
||||
|
||||
|
||||
@st.composite
|
||||
def expressions(draw):
|
||||
# todo : would be nice to generate expressions using hypothesis however
|
||||
# this is pretty involved so for now just use a corpus of expressions
|
||||
# from which to select.
|
||||
return draw(st.sampled_from((
|
||||
'abc',
|
||||
'len(items)',
|
||||
'x + 1',
|
||||
'lineno',
|
||||
'container',
|
||||
'self.attribute',
|
||||
'self.method()',
|
||||
# These expressions are failing, I think these are control
|
||||
# flow problems rather than problems with FORMAT_VALUE,
|
||||
# however I need to confirm this...
|
||||
#'sorted(items, key=lambda x: x.name)',
|
||||
#'func(*args, **kwargs)',
|
||||
#'text or default',
|
||||
#'43 if life_the_universe and everything else None'
|
||||
)))
|
||||
|
||||
|
||||
@st.composite
|
||||
def format_specifiers(draw):
|
||||
"""
|
||||
Generate a valid format specifier using the rules:
|
||||
|
||||
format_spec ::= [[fill]align][sign][#][0][width][,][.precision][type]
|
||||
fill ::= <any character>
|
||||
align ::= "<" | ">" | "=" | "^"
|
||||
sign ::= "+" | "-" | " "
|
||||
width ::= integer
|
||||
precision ::= integer
|
||||
type ::= "b" | "c" | "d" | "e" | "E" | "f" | "F" | "g" | "G" | "n" | "o" | "s" | "x" | "X" | "%"
|
||||
|
||||
See https://docs.python.org/2/library/string.html
|
||||
|
||||
:param draw: Let hypothesis draw from other strategies.
|
||||
|
||||
:return: An example format_specifier.
|
||||
"""
|
||||
alphabet_strategy = st.characters(min_codepoint=ord('a'), max_codepoint=ord('z'))
|
||||
fill = draw(st.one_of(alphabet_strategy, st.none()))
|
||||
align = draw(st.sampled_from(list('<>=^')))
|
||||
fill_align = (fill + align or '') if fill else ''
|
||||
|
||||
type_ = draw(st.sampled_from('bcdeEfFgGnosxX%'))
|
||||
can_have_sign = type_ in 'deEfFgGnoxX%'
|
||||
can_have_comma = type_ in 'deEfFgG%'
|
||||
can_have_precision = type_ in 'fFgG'
|
||||
can_have_pound = type_ in 'boxX%'
|
||||
can_have_zero = type_ in 'oxX'
|
||||
|
||||
sign = draw(st.sampled_from(list('+- ') + [''])) if can_have_sign else ''
|
||||
pound = draw(st.sampled_from(('#', '',))) if can_have_pound else ''
|
||||
zero = draw(st.sampled_from(('0', '',))) if can_have_zero else ''
|
||||
|
||||
int_strategy = st.integers(min_value=1, max_value=1000)
|
||||
|
||||
width = draw(st.one_of(int_strategy, st.none()))
|
||||
width = str(width) if width is not None else ''
|
||||
|
||||
comma = draw(st.sampled_from((',', '',))) if can_have_comma else ''
|
||||
if can_have_precision:
|
||||
precision = draw(st.one_of(int_strategy, st.none()))
|
||||
precision = '.' + str(precision) if precision else ''
|
||||
else:
|
||||
precision = ''
|
||||
|
||||
return ''.join((fill_align, sign, pound, zero, width, comma, precision, type_,))
|
||||
|
||||
|
||||
@st.composite
|
||||
def fstrings(draw):
|
||||
"""
|
||||
Generate a valid f-string.
|
||||
See https://www.python.org/dev/peps/pep-0498/#specification
|
||||
|
||||
:param draw: Let hypothsis draw from other strategies.
|
||||
|
||||
:return: A valid f-string.
|
||||
"""
|
||||
character_strategy = st.characters(
|
||||
blacklist_characters='\r\n\'\\s{}',
|
||||
min_codepoint=1,
|
||||
max_codepoint=1000,
|
||||
)
|
||||
is_raw = draw(st.booleans())
|
||||
integer_strategy = st.integers(min_value=0, max_value=3)
|
||||
expression_count = draw(integer_strategy)
|
||||
content = []
|
||||
for _ in range(expression_count):
|
||||
expression = draw(expressions())
|
||||
conversion = draw(st.sampled_from(('', '!s', '!r', '!a',)))
|
||||
has_specifier = draw(st.booleans())
|
||||
specifier = ':' + draw(format_specifiers()) if has_specifier else ''
|
||||
content.append('{{{}{}}}'.format(expression, conversion, specifier))
|
||||
content.append(draw(st.text(character_strategy)))
|
||||
content = ''.join(content)
|
||||
return "f{}'{}'".format('r' if is_raw else '', content)
|
||||
|
||||
|
||||
@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need at least python 3.6')
|
||||
@hypothesis.given(format_specifiers())
|
||||
def test_format_specifiers(format_specifier):
|
||||
"""Verify that format_specifiers generates valid specifiers"""
|
||||
try:
|
||||
exec('"{:' + format_specifier + '}".format(0)')
|
||||
except ValueError as e:
|
||||
if 'Unknown format code' not in str(e):
|
||||
raise
|
||||
|
||||
|
||||
def run_test(text):
|
||||
hypothesis.assume(len(text))
|
||||
hypothesis.assume("f'{" in text)
|
||||
expr = text + '\n'
|
||||
code = compile(expr, '<string>', 'single')
|
||||
deparsed = deparse_code(PYTHON_VERSION, code, compile_mode='single')
|
||||
recompiled = compile(deparsed.text, '<string>', 'single')
|
||||
if recompiled != code:
|
||||
assert 'dis(' + deparsed.text.strip('\n') + ')' == 'dis(' + expr.strip('\n') + ')'
|
||||
|
||||
|
||||
@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need at least python 3.6')
|
||||
@hypothesis.given(fstrings())
|
||||
def test_uncompyle_fstring(fstring):
|
||||
"""Verify uncompyling fstring bytecode"""
|
||||
run_test(fstring)
|
||||
|
||||
|
||||
@pytest.mark.skipif(PYTHON_VERSION < 3.6, reason='need at least python 3.6')
|
||||
@pytest.mark.parametrize('fstring', [
|
||||
"f'{abc}{abc!s}'",
|
||||
"f'{abc}0'",
|
||||
])
|
||||
def test_uncompyle_direct(fstring):
|
||||
"""useful for debugging"""
|
||||
run_test(fstring)
|
@@ -1,24 +1,20 @@
|
||||
# std
|
||||
import string
|
||||
# 3rd party
|
||||
from hypothesis import given, assume, example, settings, strategies as st
|
||||
from hypothesis import given, assume, strategies as st
|
||||
import pytest
|
||||
# uncompyle
|
||||
from validate import validate_uncompyle
|
||||
from test_fstring import expressions
|
||||
|
||||
|
||||
alpha = st.sampled_from(string.ascii_lowercase)
|
||||
numbers = st.sampled_from(string.digits)
|
||||
alphanum = st.sampled_from(string.ascii_lowercase + string.digits)
|
||||
expressions = st.sampled_from([x for x in string.ascii_lowercase + string.digits] + ['x+1'])
|
||||
|
||||
|
||||
@st.composite
|
||||
def function_calls(draw,
|
||||
min_keyword_args=0, max_keyword_args=5,
|
||||
min_positional_args=0, max_positional_args=5,
|
||||
min_star_args=0, max_star_args=1,
|
||||
min_double_star_args=0, max_double_star_args=1):
|
||||
def function_calls(draw):
|
||||
"""
|
||||
Strategy factory for generating function calls.
|
||||
|
||||
@@ -26,49 +22,21 @@ def function_calls(draw,
|
||||
|
||||
:return: The function call text.
|
||||
"""
|
||||
st_positional_args = st.lists(
|
||||
alpha,
|
||||
min_size=min_positional_args,
|
||||
max_size=max_positional_args
|
||||
)
|
||||
st_keyword_args = st.lists(
|
||||
alpha,
|
||||
min_size=min_keyword_args,
|
||||
max_size=max_keyword_args
|
||||
)
|
||||
st_star_args = st.lists(
|
||||
alpha,
|
||||
min_size=min_star_args,
|
||||
max_size=max_star_args
|
||||
)
|
||||
st_double_star_args = st.lists(
|
||||
alpha,
|
||||
min_size=min_double_star_args,
|
||||
max_size=max_double_star_args
|
||||
)
|
||||
list1 = st.lists(alpha, min_size=0, max_size=1)
|
||||
list3 = st.lists(alpha, min_size=0, max_size=3)
|
||||
|
||||
positional_args = draw(st_positional_args)
|
||||
keyword_args = draw(st_keyword_args)
|
||||
st_values = st.lists(
|
||||
expressions(),
|
||||
min_size=len(keyword_args),
|
||||
max_size=len(keyword_args)
|
||||
)
|
||||
keyword_args = [
|
||||
x + '=' + e
|
||||
for x, e in
|
||||
zip(keyword_args, draw(st_values))
|
||||
]
|
||||
star_args = ['*' + x for x in draw(st_star_args)]
|
||||
double_star_args = ['**' + x for x in draw(st_double_star_args)]
|
||||
positional_args = draw(list3)
|
||||
named_args = [x + '=0' for x in draw(list3)]
|
||||
star_args = ['*' + x for x in draw(list1)]
|
||||
double_star_args = ['**' + x for x in draw(list1)]
|
||||
|
||||
arguments = positional_args + keyword_args + star_args + double_star_args
|
||||
arguments = positional_args + named_args + star_args + double_star_args
|
||||
draw(st.randoms()).shuffle(arguments)
|
||||
arguments = ','.join(arguments)
|
||||
|
||||
function_call = 'fn({arguments})'.format(arguments=arguments)
|
||||
try:
|
||||
# TODO: Figure out the exact rules for ordering of positional, keyword,
|
||||
# TODO: Figure out the exact rules for ordering of positional, named,
|
||||
# star args, double star args and in which versions the various
|
||||
# types of arguments are supported so we don't need to check that the
|
||||
# expression compiles like this.
|
||||
@@ -78,55 +46,9 @@ def function_calls(draw,
|
||||
return function_call
|
||||
|
||||
|
||||
def test_function_no_args():
|
||||
validate_uncompyle("fn()")
|
||||
|
||||
|
||||
def isolated_function_calls(which):
|
||||
"""
|
||||
Returns a strategy for generating function calls, but isolated to
|
||||
particular types of arguments, for example only positional arguments.
|
||||
|
||||
This can help reason about debugging errors in specific types of function
|
||||
calls.
|
||||
|
||||
:param which: One of 'keyword', 'positional', 'star', 'double_star'
|
||||
|
||||
:return: Strategy for generating an function call isolated to specific
|
||||
argument types.
|
||||
"""
|
||||
kwargs = dict(
|
||||
max_keyword_args=0,
|
||||
max_positional_args=0,
|
||||
max_star_args=0,
|
||||
max_double_star_args=0,
|
||||
)
|
||||
kwargs['_'.join(('min', which, 'args'))] = 1
|
||||
kwargs['_'.join(('max', which, 'args'))] = 5 if 'star' not in which else 1
|
||||
return function_calls(**kwargs)
|
||||
|
||||
|
||||
with settings(max_examples=25):
|
||||
|
||||
@given(isolated_function_calls('positional'))
|
||||
@example("fn(0)")
|
||||
def test_function_positional_only(expr):
|
||||
validate_uncompyle(expr)
|
||||
|
||||
@given(isolated_function_calls('keyword'))
|
||||
@example("fn(a=0)")
|
||||
def test_function_call_keyword_only(expr):
|
||||
validate_uncompyle(expr)
|
||||
|
||||
@given(isolated_function_calls('star'))
|
||||
@example("fn(*items)")
|
||||
def test_function_call_star_only(expr):
|
||||
validate_uncompyle(expr)
|
||||
|
||||
@given(isolated_function_calls('double_star'))
|
||||
@example("fn(**{})")
|
||||
def test_function_call_double_star_only(expr):
|
||||
validate_uncompyle(expr)
|
||||
@pytest.mark.xfail()
|
||||
def test_CALL_FUNCTION():
|
||||
validate_uncompyle("fn(w,m,f)")
|
||||
|
||||
|
||||
@pytest.mark.xfail()
|
||||
@@ -139,6 +61,11 @@ def test_BUILD_MAP_BUILD_MAP_UNPACK_WITH_CALL_BUILD_TUPLE_CALL_FUNCTION_EX():
|
||||
validate_uncompyle("fn(a=0,**g)")
|
||||
|
||||
|
||||
@pytest.mark.xfail()
|
||||
def test_CALL_FUNCTION_KW():
|
||||
validate_uncompyle("fn(j=0)")
|
||||
|
||||
|
||||
@pytest.mark.xfail()
|
||||
def test_CALL_FUNCTION_EX():
|
||||
validate_uncompyle("fn(*g,**j)")
|
||||
@@ -173,3 +100,29 @@ def test_BUILD_CONST_KEY_MAP_CALL_FUNCTION_EX():
|
||||
@given(function_calls())
|
||||
def test_function_call(function_call):
|
||||
validate_uncompyle(function_call)
|
||||
|
||||
|
||||
examples = set()
|
||||
generate_examples = False
|
||||
|
||||
|
||||
@pytest.mark.skipif(not generate_examples, reason='not generating examples')
|
||||
@given(function_calls())
|
||||
def test_generate_hypothesis(function_call):
|
||||
examples.add(function_call)
|
||||
|
||||
|
||||
@pytest.mark.skipif(not generate_examples, reason='not generating examples')
|
||||
def test_generate_examples():
|
||||
import dis
|
||||
example_opcodes = {}
|
||||
for example in examples:
|
||||
opcodes = tuple(sorted(set(
|
||||
instruction.opname
|
||||
for instruction in dis.Bytecode(example)
|
||||
if instruction.opname not in ('LOAD_CONST', 'LOAD_NAME', 'RETURN_VALUE')
|
||||
)))
|
||||
example_opcodes[opcodes] = example
|
||||
for k, v in example_opcodes.items():
|
||||
print('def test_' + '_'.join(k) + '():\n validate_uncompyle("' + v + '")\n\n')
|
||||
return
|
||||
|
@@ -123,9 +123,7 @@ def validate_uncompyle(text, mode='exec'):
|
||||
original_text = text
|
||||
|
||||
deparsed = deparse_code(PYTHON_VERSION, original_code,
|
||||
compile_mode=mode,
|
||||
out=six.StringIO(),
|
||||
is_pypy=IS_PYPY)
|
||||
compile_mode=mode, out=six.StringIO())
|
||||
uncompyled_text = deparsed.text
|
||||
uncompyled_code = compile(uncompyled_text, '<string>', 'exec')
|
||||
|
||||
|
@@ -1,3 +1,4 @@
|
||||
pytest>=3.0.0
|
||||
pytest
|
||||
flake8
|
||||
hypothesis
|
||||
six
|
@@ -16,10 +16,11 @@ check-short:
|
||||
|
||||
# Run all tests
|
||||
check:
|
||||
$(MAKE) check-$(PYTHON_VERSION)
|
||||
@$(PYTHON) -V && PYTHON_VERSION=`$(PYTHON) -V 2>&1 | cut -d ' ' -f 2 | cut -d'.' -f1,2`; \
|
||||
$(MAKE) check-$$PYTHON_VERSION
|
||||
|
||||
#: Run working tests from Python 2.6 or 2.7
|
||||
check-2.6 check-2.7: check-bytecode-2 check-bytecode-3 check-bytecode-1 check-native-short
|
||||
check-2.4 check-2.5 check-2.6 check-2.7: check-bytecode-2 check-bytecode-3 check-bytecode-1 check-native-short
|
||||
|
||||
#: Run working tests from Python 3.0
|
||||
check-3.0: check-bytecode
|
||||
@@ -35,7 +36,7 @@ check-3.2: check-bytecode
|
||||
|
||||
#: Run working tests from Python 3.3
|
||||
check-3.3: check-bytecode
|
||||
$(PYTHON) test_pythonlib.py --bytecode-3.3 --weak-verify $(COMPILE)
|
||||
$(PYTHON) test_pythonlib.py --bytecode-3.3 --verify $(COMPILE)
|
||||
|
||||
#: Run working tests from Python 3.4
|
||||
check-3.4: check-bytecode check-3.4-ok check-2.7-ok
|
||||
@@ -67,7 +68,7 @@ check-bytecode-2:
|
||||
check-bytecode-3:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-3.0 \
|
||||
--bytecode-3.1 --bytecode-3.2 --bytecode-3.3 \
|
||||
--bytecode-3.4 --bytecode-3.5 --bytecode-pypy3.2
|
||||
--bytecode-3.4 --bytecode-3.5 --bytecode-3.6 --bytecode-pypy3.2
|
||||
|
||||
#: Check deparsing bytecode that works running Python 2 and Python 3
|
||||
check-bytecode: check-bytecode-3
|
||||
@@ -97,29 +98,6 @@ check-bytecode-2.4:
|
||||
check-bytecode-2.5:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-2.5
|
||||
|
||||
#: Get grammar coverage for Python 2.5
|
||||
grammar-coverage-2.5:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pythonlib.py --bytecode-2.5
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pyenvlib.py --2.5.6
|
||||
|
||||
#: Get grammar coverage for Python 2.6
|
||||
grammar-coverage-2.6:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pythonlib.py --bytecode-2.6
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pyenvlib.py --2.6.9
|
||||
|
||||
#: Get grammar coverage for Python 2.7
|
||||
grammar-coverage-2.7:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pythonlib.py --bytecode-2.7
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pyenvlib.py --2.7.13
|
||||
|
||||
#: Check deparsing Python 2.6
|
||||
check-bytecode-2.6:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-2.6 --weak-verify
|
||||
|
||||
#: Check deparsing Python 2.7
|
||||
check-bytecode-2.7:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-2.7 --verify
|
||||
|
||||
#: Check deparsing Python 3.0
|
||||
check-bytecode-3.0:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-3.0
|
||||
@@ -148,9 +126,33 @@ check-bytecode-3.5:
|
||||
check-bytecode-3.6:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-3.6
|
||||
|
||||
#: Get grammar coverage for Python 2.4
|
||||
grammar-coverage-2.4:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-24.cover $(PYTHON) test_pythonlib.py --bytecode-2.4
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-24.cover $(PYTHON) test_pyenvlib.py --2.4.6
|
||||
|
||||
#: Get grammar coverage for Python 2.5
|
||||
grammar-coverage-2.5:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pythonlib.py --bytecode-2.5
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-25.cover $(PYTHON) test_pyenvlib.py --2.5.6
|
||||
|
||||
#: Get grammar coverage for Python 2.6
|
||||
grammar-coverage-2.6:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pythonlib.py --bytecode-2.6
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-26.cover $(PYTHON) test_pyenvlib.py --2.6.9
|
||||
|
||||
#: Get grammar coverage for Python 2.7
|
||||
grammar-coverage-2.7:
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pythonlib.py --bytecode-2.7
|
||||
SPARK_PARSER_COVERAGE=/tmp/spark-grammar-27.cover $(PYTHON) test_pyenvlib.py --2.7.13
|
||||
|
||||
#: short tests for bytecodes only for this version of Python
|
||||
check-native-short:
|
||||
$(PYTHON) test_pythonlib.py --bytecode-$(PYTHON_VERSION) --verify $(COMPILE)
|
||||
$(PYTHON) test_pythonlib.py --bytecode-$(PYTHON_VERSION) --weak-verify $(COMPILE)
|
||||
|
||||
#: Run longer Python 2.6's lib files known to be okay
|
||||
check-2.4-ok:
|
||||
$(PYTHON) test_pythonlib.py --ok-2.4 --verify $(COMPILE)
|
||||
|
||||
#: Run longer Python 2.6's lib files known to be okay
|
||||
check-2.6-ok:
|
||||
|
BIN
test/bytecode_2.4/01_ops.pyc
Normal file
BIN
test/bytecode_2.4/01_ops.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_2.5/01_ops.pyc
Normal file
BIN
test/bytecode_2.5/01_ops.pyc
Normal file
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,19 +0,0 @@
|
||||
# Bug in < 2.6 is having a COME_FROM_LOOP (but we
|
||||
# don't tag that so it is just COME_FROM *before*
|
||||
# a jump back to the loop.
|
||||
def pickup(self, open_players, open_buf, wrap_buf):
|
||||
for aplayer in self._game.active_players:
|
||||
|
||||
if aplayer in open_players:
|
||||
aplayer.send(open_players)
|
||||
|
||||
if self == aplayer:
|
||||
for awatcher in self._watchers:
|
||||
if awatcher._can_see_detail:
|
||||
awatcher.send(open_buf)
|
||||
else:
|
||||
awatcher.send(wrap_buf)
|
||||
else:
|
||||
self._game.send(aplayer.side)
|
||||
else:
|
||||
self._game.send(aplayer.side, wrap_buf)
|
@@ -9,7 +9,7 @@ def open(file, mode = "r", buffering = None,
|
||||
newline = None, closefd = True) -> "IOBase":
|
||||
return text
|
||||
|
||||
def foo1(x: 'an argument that defaults to 5' = 5):
|
||||
def foo(x: 'an argument that defaults to 5' = 5):
|
||||
print(x)
|
||||
|
||||
def div(a: dict(type=float, help='the dividend'),
|
||||
|
@@ -1,8 +0,0 @@
|
||||
# sql/schema.py
|
||||
# Note that kwargs comes before "positional" args
|
||||
def tometadata(self, metadata, schema, Table, args, name=None):
|
||||
table = Table(
|
||||
name, metadata, schema=schema,
|
||||
*args, **self.kwargs
|
||||
)
|
||||
return table
|
File diff suppressed because it is too large
Load Diff
@@ -1,14 +0,0 @@
|
||||
# Python 3.3 pyclbr.py
|
||||
# Note that Python 3 adds a lot of unecessary "continues"
|
||||
# and puts that in for "pass"
|
||||
def _readmodule(g, token, path):
|
||||
for tokentype in g:
|
||||
if g:
|
||||
while True:
|
||||
if token:
|
||||
token = 1
|
||||
elif token:
|
||||
pass
|
||||
elif tokentype:
|
||||
token = 7
|
||||
token = 10
|
@@ -19,21 +19,19 @@ Step 2: Run the test:
|
||||
test_pyenvlib --mylib --verify # decompile verify 'mylib'
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6 import main, PYTHON3
|
||||
import os, time, shutil, sys
|
||||
import os, time, shutil
|
||||
from fnmatch import fnmatch
|
||||
|
||||
#----- configure this for your needs
|
||||
|
||||
TEST_VERSIONS=('2.3.7', '2.4.6', '2.5.6', '2.6.9',
|
||||
'pypy-2.4.0', 'pypy-2.6.1',
|
||||
'pypy-5.0.1', 'pypy-5.3.1', 'pypy3.5-5.7.1-beta',
|
||||
'pypy-5.0.1', 'pypy-5.3.1',
|
||||
'2.7.10', '2.7.11', '2.7.12', '2.7.13',
|
||||
'3.0.1', '3.1.5', '3.2.6',
|
||||
'3.3.5', '3.3.6',
|
||||
'3.4.2', '3.5.1', '3.6.0', 'native')
|
||||
'3.4.2', '3.5.1', '3.6.0')
|
||||
|
||||
target_base = '/tmp/py-dis/'
|
||||
lib_prefix = os.path.join(os.environ['HOME'], '.pyenv/versions')
|
||||
@@ -54,11 +52,6 @@ for vers in TEST_VERSIONS:
|
||||
short_vers = vers[0:-2]
|
||||
test_options[vers] = (os.path.join(lib_prefix, vers, 'lib_pypy'),
|
||||
PYC, 'python-lib'+short_vers)
|
||||
if vers == 'native':
|
||||
short_vers = os.path.basename(sys.path[-1])
|
||||
test_options[vers] = (sys.path[-1],
|
||||
PYC, short_vers)
|
||||
|
||||
else:
|
||||
short_vers = vers[:3]
|
||||
test_options[vers] = (os.path.join(lib_prefix, vers, 'lib', 'python'+short_vers),
|
||||
|
@@ -27,8 +27,6 @@ Step 2: Run the test:
|
||||
test_pythonlib.py --mylib --verify # decompile verify 'mylib'
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import getopt, os, py_compile, sys, shutil, tempfile, time
|
||||
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
@@ -127,8 +125,10 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
||||
if opts['do_compile']:
|
||||
compiled_version = opts['compiled_version']
|
||||
if compiled_version and PYTHON_VERSION != compiled_version:
|
||||
print("Not compiling: desired Python version is %s but we are running %s" %
|
||||
(compiled_version, PYTHON_VERSION), file=sys.stderr)
|
||||
sys.stderr.write("Not compiling: "
|
||||
"desired Python version is %s "
|
||||
"but we are running %s" %
|
||||
(compiled_version, PYTHON_VERSION))
|
||||
else:
|
||||
for root, dirs, basenames in os.walk(src_dir):
|
||||
file_matches(files, root, basenames, PY)
|
||||
@@ -146,8 +146,8 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
||||
file_matches(files, dirname, basenames, obj_patterns)
|
||||
|
||||
if not files:
|
||||
print("Didn't come up with any files to test! Try with --compile?",
|
||||
file=sys.stderr)
|
||||
sys.stderr.write("Didn't come up with any files to test! "
|
||||
"Try with --compile?")
|
||||
exit(1)
|
||||
|
||||
os.chdir(cwd)
|
||||
@@ -161,9 +161,9 @@ def do_tests(src_dir, obj_patterns, target_dir, opts):
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
print(time.ctime())
|
||||
print('Source directory: ', src_dir)
|
||||
print('Output directory: ', target_dir)
|
||||
print time.ctime()
|
||||
print 'Source directory: ', src_dir
|
||||
print 'Output directory: ', target_dir
|
||||
try:
|
||||
_, _, failed_files, failed_verify = \
|
||||
main(src_dir, target_dir, files, [],
|
||||
@@ -236,14 +236,13 @@ if __name__ == '__main__':
|
||||
if os.path.isdir(src_dir):
|
||||
checked_dirs.append([src_dir, pattern, target_dir])
|
||||
else:
|
||||
print("Can't find directory %s. Skipping" % src_dir,
|
||||
file=sys.stderr)
|
||||
sys.stderr.write("Can't find directory %s. Skipping" % src_dir)
|
||||
continue
|
||||
last_compile_version = compiled_version
|
||||
pass
|
||||
|
||||
if not checked_dirs:
|
||||
print("No directories found to check", file=sys.stderr)
|
||||
sys.stderr.write("No directories found to check\n")
|
||||
sys.exit(1)
|
||||
|
||||
test_opts['compiled_version'] = last_compile_version
|
||||
|
@@ -3,7 +3,6 @@
|
||||
#
|
||||
# Copyright (c) 2015-2016 by Rocky Bernstein <rb@dustyfeet.com>
|
||||
#
|
||||
from __future__ import print_function
|
||||
import sys, os, getopt
|
||||
|
||||
from uncompyle6.disas import disassemble_file
|
||||
@@ -26,7 +25,7 @@ Options:
|
||||
-V | --version show version and stop
|
||||
-h | --help show this message
|
||||
|
||||
""".format(program)
|
||||
""" % (program, program)
|
||||
|
||||
PATTERNS = ('*.pyc', '*.pyo')
|
||||
|
||||
@@ -37,15 +36,15 @@ Type -h for for full help.""" % program
|
||||
native = True
|
||||
|
||||
if len(sys.argv) == 1:
|
||||
print("No file(s) given", file=sys.stderr)
|
||||
print(Usage_short, file=sys.stderr)
|
||||
sys.stderr.write("No file(s) given\n")
|
||||
sys.stderr.write(Usage_short)
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
opts, files = getopt.getopt(sys.argv[1:], 'hVU',
|
||||
['help', 'version', 'uncompyle6'])
|
||||
except getopt.GetoptError as e:
|
||||
print('%s: %s' % (os.path.basename(sys.argv[0]), e), file=sys.stderr)
|
||||
except getopt.GetoptError(e):
|
||||
sys.stderr.write('%s: %s' % (os.path.basename(sys.argv[0]), e))
|
||||
sys.exit(-1)
|
||||
|
||||
for opt, val in opts:
|
||||
@@ -59,15 +58,14 @@ Type -h for for full help.""" % program
|
||||
native = False
|
||||
else:
|
||||
print(opt)
|
||||
print(Usage_short, file=sys.stderr)
|
||||
sys.stderr.write(Usage_short)
|
||||
sys.exit(1)
|
||||
|
||||
for file in files:
|
||||
if os.path.exists(files[0]):
|
||||
disassemble_file(file, sys.stdout, native)
|
||||
else:
|
||||
print("Can't read %s - skipping" % files[0],
|
||||
file=sys.stderr)
|
||||
sys.stderr.write("Can't read %s - skipping\n" % files[0])
|
||||
pass
|
||||
pass
|
||||
return
|
||||
|
@@ -4,7 +4,6 @@
|
||||
# Copyright (c) 2015-2016 by Rocky Bernstein
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
#
|
||||
from __future__ import print_function
|
||||
import sys, os, getopt, time
|
||||
|
||||
program, ext = os.path.splitext(os.path.basename(__file__))
|
||||
@@ -65,11 +64,11 @@ def usage():
|
||||
|
||||
|
||||
def main_bin():
|
||||
if not (sys.version_info[0:2] in ((2, 6), (2, 7),
|
||||
(3, 1), (3, 2), (3, 3),
|
||||
if not (sys.version_info[0:2] in ((2, 4), (2, 5), (2, 6), (2, 7),
|
||||
(3, 2), (3, 3),
|
||||
(3, 4), (3, 5), (3, 6))):
|
||||
print('Error: %s requires Python 2.6-2.7, or 3.1-3.6' % program,
|
||||
file=sys.stderr)
|
||||
sys.stderr.write('Error: %s requires Python 2.4 2.5 2.6, 2.7, '
|
||||
'3.2, 3.3, 3.4, 3.5, or 3.6' % program)
|
||||
sys.exit(-1)
|
||||
|
||||
do_verify = recurse_dirs = False
|
||||
@@ -84,8 +83,8 @@ def main_bin():
|
||||
opts, files = getopt.getopt(sys.argv[1:], 'hagtdrVo:c:p:',
|
||||
'help asm grammar linemaps recurse timestamp tree '
|
||||
'verify version showgrammar'.split(' '))
|
||||
except getopt.GetoptError as e:
|
||||
print('%s: %s' % (os.path.basename(sys.argv[0]), e), file=sys.stderr)
|
||||
except getopt.GetoptError(e):
|
||||
sys.stderr.write('%s: %s\n' % (os.path.basename(sys.argv[0]), e))
|
||||
sys.exit(-1)
|
||||
|
||||
options = {}
|
||||
@@ -119,7 +118,7 @@ def main_bin():
|
||||
elif opt in ('--recurse', '-r'):
|
||||
recurse_dirs = True
|
||||
else:
|
||||
print(opt, file=sys.stderr)
|
||||
sys.stderr.write(opt)
|
||||
usage()
|
||||
|
||||
# expand directory if specified
|
||||
@@ -144,7 +143,7 @@ def main_bin():
|
||||
files = [f[sb_len:] for f in files]
|
||||
|
||||
if not files:
|
||||
print("No files given", file=sys.stderr)
|
||||
sys.stderr.write("No files given\n")
|
||||
usage()
|
||||
|
||||
if outfile == '-':
|
||||
|
@@ -16,8 +16,6 @@ Second, we need structured instruction information for the
|
||||
want to run on Python 2.7.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
from collections import deque
|
||||
|
||||
@@ -37,10 +35,9 @@ def disco(version, co, out=None, is_pypy=False):
|
||||
|
||||
# store final output stream for case of error
|
||||
real_out = out or sys.stdout
|
||||
print('# Python %s' % version, file=real_out)
|
||||
real_out.write('# Python %s\n' % version)
|
||||
if co.co_filename:
|
||||
print('# Embedded file name: %s' % co.co_filename,
|
||||
file=real_out)
|
||||
real_out.write('# Embedded file name: %s\n' % co.co_filename)
|
||||
|
||||
scanner = get_scanner(version, is_pypy=is_pypy)
|
||||
|
||||
@@ -52,16 +49,15 @@ def disco_loop(disasm, queue, real_out):
|
||||
while len(queue) > 0:
|
||||
co = queue.popleft()
|
||||
if co.co_name != '<module>':
|
||||
print('\n# %s line %d of %s' %
|
||||
(co.co_name, co.co_firstlineno, co.co_filename),
|
||||
file=real_out)
|
||||
real_out.write('\n# %s line %d of %s\n' %
|
||||
(co.co_name, co.co_firstlineno, co.co_filename))
|
||||
tokens, customize = disasm(co)
|
||||
for t in tokens:
|
||||
if iscode(t.pattr):
|
||||
queue.append(t.pattr)
|
||||
elif iscode(t.attr):
|
||||
queue.append(t.attr)
|
||||
print(t, file=real_out)
|
||||
real_out.write(t)
|
||||
pass
|
||||
pass
|
||||
|
||||
|
@@ -10,7 +10,7 @@ def line_number_mapping(pyc_filename, src_filename):
|
||||
source_size) = load_module(pyc_filename)
|
||||
try:
|
||||
code2 = load_file(src_filename)
|
||||
except SyntaxError as e:
|
||||
except SyntaxError, e:
|
||||
return str(e)
|
||||
|
||||
queue = deque([code1, code2])
|
||||
|
@@ -1,4 +1,3 @@
|
||||
from __future__ import print_function
|
||||
import datetime, os, subprocess, sys, tempfile
|
||||
|
||||
from uncompyle6 import verify, IS_PYPY
|
||||
@@ -22,31 +21,36 @@ def decompile(
|
||||
|
||||
# store final output stream for case of error
|
||||
real_out = out or sys.stdout
|
||||
co_pypy_str = 'PyPy ' if is_pypy else ''
|
||||
run_pypy_str = 'PyPy ' if IS_PYPY else ''
|
||||
print('# uncompyle6 version %s\n'
|
||||
'# %sPython bytecode %s%s\n# Decompiled from: %sPython %s' %
|
||||
(VERSION, co_pypy_str, bytecode_version,
|
||||
" (%d)" % magic_int if magic_int else "",
|
||||
run_pypy_str, '\n# '.join(sys.version.split('\n'))),
|
||||
file=real_out)
|
||||
if co.co_filename:
|
||||
print('# Embedded file name: %s' % co.co_filename,
|
||||
file=real_out)
|
||||
if timestamp:
|
||||
print('# Compiled at: %s' % datetime.datetime.fromtimestamp(timestamp),
|
||||
file=real_out)
|
||||
if source_size:
|
||||
print('# Size of source mod 2**32: %d bytes' % source_size,
|
||||
file=real_out)
|
||||
if is_pypy:
|
||||
co_pypy_str = 'PyPy '
|
||||
else:
|
||||
co_pypy_str = ''
|
||||
|
||||
try:
|
||||
pysource.deparse_code(bytecode_version, co, out, showasm, showast,
|
||||
showgrammar, code_objects=code_objects,
|
||||
is_pypy=is_pypy)
|
||||
except pysource.SourceWalkerError as e:
|
||||
# deparsing failed
|
||||
raise pysource.SourceWalkerError(str(e))
|
||||
if IS_PYPY:
|
||||
run_pypy_str = 'PyPy '
|
||||
else:
|
||||
run_pypy_str = ''
|
||||
|
||||
if magic_int:
|
||||
m = str(magic_int)
|
||||
else:
|
||||
m = ""
|
||||
real_out.write('# uncompyle6 version %s\n'
|
||||
'# %sPython bytecode %s%s\n# Decompiled from: %sPython %s\n' %
|
||||
(VERSION, co_pypy_str, bytecode_version,
|
||||
" (%s)" % m, run_pypy_str,
|
||||
'\n# '.join(sys.version.split('\n'))))
|
||||
if co.co_filename:
|
||||
real_out.write('# Embedded file name: %s\n' % co.co_filename)
|
||||
if timestamp:
|
||||
real_out.write('# Compiled at: %s\n' %
|
||||
datetime.datetime.fromtimestamp(timestamp))
|
||||
if source_size:
|
||||
real_out.write('# Size of source mod 2**32: %d bytes\n' % source_size)
|
||||
|
||||
pysource.deparse_code(bytecode_version, co, out, showasm, showast,
|
||||
showgrammar, code_objects=code_objects,
|
||||
is_pypy=is_pypy)
|
||||
|
||||
# For compatiblity
|
||||
uncompyle = decompile
|
||||
@@ -106,7 +110,6 @@ def main(in_base, out_base, files, codes, outfile=None,
|
||||
return open(outfile, 'w')
|
||||
|
||||
tot_files = okay_files = failed_files = verify_failed_files = 0
|
||||
current_outfile = outfile
|
||||
|
||||
for filename in files:
|
||||
infile = os.path.join(in_base, filename)
|
||||
@@ -128,26 +131,29 @@ def main(in_base, out_base, files, codes, outfile=None,
|
||||
junk, outfile = tempfile.mkstemp(suffix=".py",
|
||||
prefix=prefix)
|
||||
# Unbuffer output if possible
|
||||
buffering = -1 if sys.stdout.isatty() else 0
|
||||
if sys.stdout.isatty():
|
||||
buffering = -1
|
||||
else:
|
||||
buffering = 0
|
||||
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', buffering)
|
||||
tee = subprocess.Popen(["tee", outfile], stdin=subprocess.PIPE)
|
||||
os.dup2(tee.stdin.fileno(), sys.stdout.fileno())
|
||||
os.dup2(tee.stdin.fileno(), sys.stderr.fileno())
|
||||
else:
|
||||
if filename.endswith('.pyc'):
|
||||
current_outfile = os.path.join(out_base, filename[0:-1])
|
||||
outfile = os.path.join(out_base, filename[0:-1])
|
||||
else:
|
||||
current_outfile = os.path.join(out_base, filename) + '_dis'
|
||||
outstream = _get_outstream(current_outfile)
|
||||
# print(current_outfile, file=sys.stderr)
|
||||
outfile = os.path.join(out_base, filename) + '_dis'
|
||||
outstream = _get_outstream(outfile)
|
||||
# print(outfile, file=sys.stderr)
|
||||
|
||||
# Try to uncompile the input file
|
||||
try:
|
||||
decompile_file(infile, outstream, showasm, showast, showgrammar)
|
||||
tot_files += 1
|
||||
except (ValueError, SyntaxError, ParserError, pysource.SourceWalkerError) as e:
|
||||
except (ValueError, SyntaxError, ParserError, pysource.SourceWalkerError):
|
||||
sys.stdout.write("\n")
|
||||
sys.stderr.write("\n# file %s\n# %s\n" % (infile, e))
|
||||
sys.stderr.write("# file %s\n" % (infile))
|
||||
failed_files += 1
|
||||
except KeyboardInterrupt:
|
||||
if outfile:
|
||||
@@ -158,16 +164,16 @@ def main(in_base, out_base, files, codes, outfile=None,
|
||||
raise
|
||||
# except:
|
||||
# failed_files += 1
|
||||
# if current_outfile:
|
||||
# if outfile:
|
||||
# outstream.close()
|
||||
# os.rename(current_outfile, current_outfile + '_failed')
|
||||
# os.rename(outfile, outfile + '_failed')
|
||||
# else:
|
||||
# sys.stderr.write("\n# %s" % sys.exc_info()[1])
|
||||
# sys.stderr.write("\n# Can't uncompile %s\n" % infile)
|
||||
else: # uncompile successful
|
||||
if current_outfile:
|
||||
if outfile:
|
||||
if do_linemaps:
|
||||
mapping = line_number_mapping(infile, current_outfile)
|
||||
mapping = line_number_mapping(infile, outfile)
|
||||
outstream.write("\n\n## Line number correspondences\n")
|
||||
import pprint
|
||||
s = pprint.pformat(mapping, indent=2, width=80)
|
||||
@@ -178,39 +184,43 @@ def main(in_base, out_base, files, codes, outfile=None,
|
||||
if do_verify:
|
||||
weak_verify = do_verify == 'weak'
|
||||
try:
|
||||
msg = verify.compare_code_with_srcfile(infile, current_outfile, weak_verify=weak_verify)
|
||||
if not current_outfile:
|
||||
msg = verify.compare_code_with_srcfile(infile, outfile, weak_verify=weak_verify)
|
||||
if not outfile:
|
||||
if not msg:
|
||||
print('\n# okay decompiling %s' % infile)
|
||||
print '\n# okay decompiling %s' % infile
|
||||
okay_files += 1
|
||||
else:
|
||||
print('\n# %s\n\t%s', infile, msg)
|
||||
except verify.VerifyCmpError as e:
|
||||
print '\n# %s\n\t%s', infile, msg
|
||||
except verify.VerifyCmpError, e:
|
||||
print(e)
|
||||
verify_failed_files += 1
|
||||
os.rename(current_outfile, current_outfile + '_unverified')
|
||||
os.rename(outfile, outfile + '_unverified')
|
||||
sys.stderr.write("### Error Verifying %s\n" % filename)
|
||||
sys.stderr.write(str(e) + "\n")
|
||||
if not outfile:
|
||||
sys.stder.write("### Error Verifiying %s" %
|
||||
filename)
|
||||
sys.stderr.write(e)
|
||||
if raise_on_error:
|
||||
raise
|
||||
pass
|
||||
pass
|
||||
pass
|
||||
elif do_verify:
|
||||
sys.stderr.write("\n### uncompile successful, but no file to compare against\n")
|
||||
sys.stderr.write("\n### uncompile successful, "
|
||||
"but no file to compare against")
|
||||
pass
|
||||
else:
|
||||
okay_files += 1
|
||||
if not current_outfile:
|
||||
if not outfile:
|
||||
mess = '\n# okay decompiling'
|
||||
# mem_usage = __memUsage()
|
||||
print(mess, infile)
|
||||
if current_outfile:
|
||||
print mess, infile
|
||||
if outfile:
|
||||
sys.stdout.write("%s\r" %
|
||||
status_msg(do_verify, tot_files, okay_files, failed_files, verify_failed_files))
|
||||
sys.stdout.flush()
|
||||
if current_outfile:
|
||||
if outfile:
|
||||
sys.stdout.write("\n")
|
||||
sys.stdout.flush()
|
||||
return (tot_files, okay_files, failed_files, verify_failed_files)
|
||||
|
@@ -6,15 +6,13 @@
|
||||
Common uncompyle parser routines.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
from xdis.code import iscode
|
||||
from xdis.magics import py_str2float
|
||||
from spark_parser import GenericASTBuilder, DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
from uncompyle6.show import maybe_show_asm
|
||||
|
||||
|
||||
class ParserError(Exception):
|
||||
def __init__(self, token, offset):
|
||||
self.token = token
|
||||
@@ -30,13 +28,13 @@ class PythonParser(GenericASTBuilder):
|
||||
|
||||
def __init__(self, AST, start, debug):
|
||||
super(PythonParser, self).__init__(AST, start, debug)
|
||||
self.collect = frozenset(
|
||||
['stmts', 'except_stmts', '_stmts', 'load_attrs',
|
||||
'exprlist', 'kvlist', 'kwargs', 'come_froms', '_come_from',
|
||||
# Python < 3
|
||||
'print_items',
|
||||
# PyPy:
|
||||
'kvlist_n'])
|
||||
self.collect = [
|
||||
'stmts', 'except_stmts', '_stmts', 'load_attrs',
|
||||
'exprlist', 'kvlist', 'kwargs', 'come_froms', '_come_from',
|
||||
# Python < 3
|
||||
'print_items',
|
||||
# PyPy:
|
||||
'kvlist_n']
|
||||
|
||||
def ast_first_offset(self, ast):
|
||||
if hasattr(ast, 'offset'):
|
||||
@@ -92,7 +90,10 @@ class PythonParser(GenericASTBuilder):
|
||||
def fix(c):
|
||||
s = str(c)
|
||||
i = s.find('_')
|
||||
return s if i == -1 else s[:i]
|
||||
if i == -1:
|
||||
return s
|
||||
else:
|
||||
return s[:i]
|
||||
|
||||
prefix = ''
|
||||
if parent and tokens:
|
||||
@@ -123,7 +124,10 @@ class PythonParser(GenericASTBuilder):
|
||||
err_token = instructions[index]
|
||||
print("Instruction context:")
|
||||
for i in range(start, finish):
|
||||
indent = ' ' if i != index else '-> '
|
||||
if i != index:
|
||||
indent = ' '
|
||||
else:
|
||||
indent = '-> '
|
||||
print("%s%s" % (indent, instructions[i]))
|
||||
raise ParserError(err_token, err_token.offset)
|
||||
|
||||
@@ -605,15 +609,7 @@ def get_python_parser(
|
||||
explanation of the different modes.
|
||||
"""
|
||||
|
||||
# If version is a string, turn that into the corresponding float.
|
||||
if isinstance(version, str):
|
||||
version = py_str2float(version)
|
||||
|
||||
# FIXME: there has to be a better way...
|
||||
# We could do this as a table lookup, but that would force us
|
||||
# in import all of the parsers all of the time. Perhaps there is
|
||||
# a lazy way of doing the import?
|
||||
|
||||
if version < 3.0:
|
||||
if version == 1.5:
|
||||
import uncompyle6.parsers.parse15 as parse15
|
||||
@@ -766,7 +762,6 @@ def python_parser(version, co, out=sys.stdout, showasm=False,
|
||||
if __name__ == '__main__':
|
||||
def parse_test(co):
|
||||
from uncompyle6 import PYTHON_VERSION, IS_PYPY
|
||||
ast = python_parser('2.7.13', co, showasm=True, is_pypy=True)
|
||||
ast = python_parser(PYTHON_VERSION, co, showasm=True, is_pypy=IS_PYPY)
|
||||
print(ast)
|
||||
return
|
||||
|
@@ -12,8 +12,6 @@ If we succeed in creating a parse tree, then we have a Python program
|
||||
that a later phase can turn into a sequence of ASCII text.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
||||
from uncompyle6.parsers.astnode import AST
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
|
@@ -84,12 +84,6 @@ class Python26Parser(Python2Parser):
|
||||
ja_cf_pop ::= JUMP_ABSOLUTE come_froms POP_TOP
|
||||
jf_cf_pop ::= JUMP_FORWARD come_froms POP_TOP
|
||||
|
||||
# The first optional COME_FROM when it appears is really
|
||||
# COME_FROM_LOOP, but in <= 2.6 we don't distinguish
|
||||
# this
|
||||
|
||||
cf_jb_cf_pop ::= _come_from JUMP_BACK come_froms POP_TOP
|
||||
|
||||
bp_come_from ::= POP_BLOCK COME_FROM
|
||||
jb_bp_come_from ::= JUMP_BACK bp_come_from
|
||||
|
||||
@@ -117,8 +111,7 @@ class Python26Parser(Python2Parser):
|
||||
break_stmt ::= BREAK_LOOP JUMP_BACK
|
||||
|
||||
# Semantic actions want else_suitel to be at index 3
|
||||
ifelsestmtl ::= testexpr c_stmts_opt cf_jb_cf_pop else_suitel
|
||||
|
||||
ifelsestmtl ::= testexpr c_stmts_opt jb_cf_pop else_suitel
|
||||
ifelsestmtc ::= testexpr c_stmts_opt ja_cf_pop else_suitec
|
||||
|
||||
# Semantic actions want suite_stmts_opt to be at index 3
|
||||
|
@@ -52,8 +52,6 @@ class Python27Parser(Python2Parser):
|
||||
come_froms ::= come_froms COME_FROM
|
||||
come_froms ::= COME_FROM
|
||||
|
||||
iflaststmtl ::= testexpr c_stmts_opt
|
||||
|
||||
_ifstmts_jump ::= c_stmts_opt JUMP_FORWARD come_froms
|
||||
bp_come_from ::= POP_BLOCK COME_FROM
|
||||
|
||||
|
@@ -15,8 +15,6 @@ If we succeed in creating a parse tree, then we have a Python program
|
||||
that a later phase can turn into a sequence of ASCII text.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParser, PythonParserSingle, nop_func
|
||||
from uncompyle6.parsers.astnode import AST
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
@@ -334,9 +332,7 @@ class Python3Parser(PythonParser):
|
||||
|
||||
def p_stmt3(self, args):
|
||||
"""
|
||||
stmt ::= return_closure
|
||||
return_closure ::= LOAD_CLOSURE RETURN_VALUE RETURN_LAST
|
||||
|
||||
stmt ::= LOAD_CLOSURE RETURN_VALUE RETURN_LAST
|
||||
stmt ::= whileTruestmt
|
||||
ifelsestmt ::= testexpr c_stmts_opt JUMP_FORWARD else_suite _come_from
|
||||
"""
|
||||
@@ -483,8 +479,6 @@ class Python3Parser(PythonParser):
|
||||
# high byte number of positional parameters
|
||||
args_pos = token.attr & 0xff
|
||||
args_kw = (token.attr >> 8) & 0xff
|
||||
args_kw = (token.attr >> 8) & 0xff
|
||||
# args_ann = (token.attr >> 16) & 0x7FFF
|
||||
|
||||
# Additional exprs for * and ** args:
|
||||
# 0 if neither
|
||||
@@ -496,28 +490,22 @@ class Python3Parser(PythonParser):
|
||||
token.type = self.call_fn_name(token)
|
||||
uniq_param = args_kw + args_pos
|
||||
if self.version == 3.5 and opname.startswith('CALL_FUNCTION_VAR'):
|
||||
# Python 3.5 changes the stack position of *args. KW args come
|
||||
# after *args.
|
||||
# Python 3.5 changes the stack position of where * args, the
|
||||
# first LOAD_FAST, below are located.
|
||||
# Python 3.6+ replaces CALL_FUNCTION_VAR_KW with CALL_FUNCTION_EX
|
||||
if opname.endswith('KW'):
|
||||
kw = 'expr '
|
||||
kw = 'LOAD_FAST '
|
||||
else:
|
||||
kw = ''
|
||||
rule = ('call_function ::= expr expr ' +
|
||||
('pos_arg ' * args_pos) +
|
||||
('kwarg ' * args_kw) + kw + token.type)
|
||||
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
||||
if self.version >= 3.6 and opname == 'CALL_FUNCTION_EX_KW':
|
||||
rule = ('call_function36 ::= '
|
||||
'expr build_tuple_unpack_with_call build_map_unpack_with_call '
|
||||
'CALL_FUNCTION_EX_KW_1')
|
||||
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
||||
rule = 'call_function ::= call_function36'
|
||||
else:
|
||||
rule = ('call_function ::= expr ' +
|
||||
('pos_arg ' * args_pos) +
|
||||
('kwarg ' * args_kw) +
|
||||
'expr ' * nak + token.type)
|
||||
|
||||
rule = ('call_function ::= expr ' +
|
||||
('pos_arg ' * args_pos) +
|
||||
('kwarg ' * args_kw) +
|
||||
'expr ' * nak + token.type)
|
||||
|
||||
self.add_unique_rule(rule, token.type, uniq_param, customize)
|
||||
if self.version >= 3.5:
|
||||
@@ -537,7 +525,10 @@ class Python3Parser(PythonParser):
|
||||
"""Python 3.3 added a an addtional LOAD_CONST before MAKE_FUNCTION and
|
||||
this has an effect on many rules.
|
||||
"""
|
||||
new_rule = rule % (('LOAD_CONST ') * (1 if self.version >= 3.3 else 0))
|
||||
if self.version >= 3.3:
|
||||
new_rule = rule % (('LOAD_CONST ') * 1)
|
||||
else:
|
||||
new_rule = rule % (('LOAD_CONST ') * 0)
|
||||
self.add_unique_rule(new_rule, opname, attr, customize)
|
||||
|
||||
def add_custom_rules(self, tokens, customize):
|
||||
@@ -616,9 +607,8 @@ class Python3Parser(PythonParser):
|
||||
assign2_pypy ::= expr expr designator designator
|
||||
""", nop_func)
|
||||
continue
|
||||
elif (opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_EX_KW')
|
||||
or opname.startswith('CALL_FUNCTION_KW')):
|
||||
elif opname in ('CALL_FUNCTION', 'CALL_FUNCTION_VAR',
|
||||
'CALL_FUNCTION_VAR_KW', 'CALL_FUNCTION_KW'):
|
||||
self.custom_classfunc_rule(opname, token, customize)
|
||||
elif opname == 'LOAD_DICTCOMP':
|
||||
rule_pat = ("dictcomp ::= LOAD_DICTCOMP %sMAKE_FUNCTION_0 expr "
|
||||
@@ -631,26 +621,6 @@ class Python3Parser(PythonParser):
|
||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||
elif opname == 'LOAD_BUILD_CLASS':
|
||||
self.custom_build_class_rule(opname, i, token, tokens, customize)
|
||||
elif opname.startswith('BUILD_LIST_UNPACK'):
|
||||
v = token.attr
|
||||
rule = ('build_list_unpack ::= ' + 'expr1024 ' * int(v//1024) +
|
||||
'expr32 ' * int((v//32) % 32) +
|
||||
'expr ' * (v % 32) + opname)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = 'expr ::= build_list_unpack'
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
elif opname.startswith('BUILD_TUPLE_UNPACK_WITH_CALL'):
|
||||
v = token.attr
|
||||
rule = ('build_tuple_unpack_with_call ::= ' + 'expr1024 ' * int(v//1024) +
|
||||
'expr32 ' * int((v//32) % 32) +
|
||||
'expr ' * (v % 32) + opname)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
elif opname.startswith('BUILD_MAP_UNPACK_WITH_CALL'):
|
||||
v = token.attr
|
||||
rule = ('build_map_unpack_with_call ::= ' + 'expr1024 ' * int(v//1024) +
|
||||
'expr32 ' * int((v//32) % 32) +
|
||||
'expr ' * (v % 32) + opname)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
elif opname_base in ('BUILD_LIST', 'BUILD_TUPLE', 'BUILD_SET'):
|
||||
v = token.attr
|
||||
rule = ('build_list ::= ' + 'expr1024 ' * int(v//1024) +
|
||||
@@ -660,17 +630,13 @@ class Python3Parser(PythonParser):
|
||||
if opname_base == 'BUILD_TUPLE':
|
||||
rule = ('load_closure ::= %s%s' % (('LOAD_CLOSURE ' * v), opname))
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = ('build_tuple ::= ' + 'expr1024 ' * int(v//1024) +
|
||||
'expr32 ' * int((v//32) % 32) +
|
||||
'expr ' * (v % 32) + opname)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
|
||||
elif opname == 'LOOKUP_METHOD':
|
||||
# A PyPy speciality - DRY with parse2
|
||||
self.add_unique_rule("load_attr ::= expr LOOKUP_METHOD",
|
||||
opname, token.attr, customize)
|
||||
continue
|
||||
elif opname == 'JUMP_IF_NOT_DEBUG':
|
||||
v = token.attr
|
||||
self.add_unique_rule(
|
||||
"stmt ::= assert_pypy", opname, v, customize)
|
||||
self.add_unique_rule(
|
||||
@@ -709,7 +675,7 @@ class Python3Parser(PythonParser):
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = ('unmap_dict ::= ' +
|
||||
('mapexpr ' * token.attr) +
|
||||
'BUILD_MAP_UNPACK')
|
||||
' BUILD_MAP_UNPACK')
|
||||
else:
|
||||
rule = kvlist_n + ' ::= ' + 'expr ' * (token.attr*2)
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
@@ -735,30 +701,7 @@ class Python3Parser(PythonParser):
|
||||
rule = 'unpack_list ::= ' + opname + ' designator' * token.attr
|
||||
elif opname_base.startswith('MAKE_FUNCTION'):
|
||||
# DRY with MAKE_CLOSURE
|
||||
if self.version >= 3.6:
|
||||
# The semantics of MAKE_FUNCTION in 3.6 are totally different from
|
||||
# before.
|
||||
args_pos, args_kw, annotate_args, closure = token.attr
|
||||
stack_count = args_pos + args_kw + annotate_args
|
||||
rule = ('mkfunc ::= %s%s%s%s' %
|
||||
('expr ' * stack_count,
|
||||
'load_closure ' * closure,
|
||||
'LOAD_CONST ' * 2,
|
||||
opname))
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule_pat = ('mklambda ::= %s%sLOAD_LAMBDA %%s%s' %
|
||||
(('pos_arg '* args_pos),
|
||||
('kwarg '* args_kw),
|
||||
opname))
|
||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||
rule_pat = ("listcomp ::= %sLOAD_LISTCOMP %%s%s expr "
|
||||
"GET_ITER CALL_FUNCTION_1" % ('expr ' * args_pos, opname))
|
||||
self.add_make_function_rule(rule_pat, opname, token.attr, customize)
|
||||
continue
|
||||
if self.version < 3.6:
|
||||
args_pos, args_kw, annotate_args = token.attr
|
||||
else:
|
||||
args_pos, args_kw, annotate_args, closure = token.attr
|
||||
args_pos, args_kw, annotate_args = token.attr
|
||||
|
||||
rule_pat = ("genexpr ::= %sload_genexpr %%s%s expr "
|
||||
"GET_ITER CALL_FUNCTION_1" % ('pos_arg '* args_pos, opname))
|
||||
@@ -787,18 +730,7 @@ class Python3Parser(PythonParser):
|
||||
('pos_arg ' * args_pos, opname))
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
if opname.startswith('MAKE_FUNCTION_A'):
|
||||
if self.version >= 3.6:
|
||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
|
||||
(('pos_arg ' * (args_pos)),
|
||||
('call_function ' * (annotate_args-1)), opname))
|
||||
self.add_unique_rule(rule, opname, token.attr, customize)
|
||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST %s' %
|
||||
(('pos_arg ' * (args_pos)),
|
||||
('annotate_arg ' * (annotate_args-1)), opname))
|
||||
if self.version >= 3.3:
|
||||
# Normally we remove EXTENDED_ARG from the opcodes, but in the case of
|
||||
# annotated functions can use the EXTENDED_ARG tuple to signal we have an annotated function.
|
||||
# Yes this is a little hacky
|
||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST LOAD_CONST EXTENDED_ARG %s' %
|
||||
(('pos_arg ' * (args_pos)),
|
||||
('call_function ' * (annotate_args-1)), opname))
|
||||
@@ -807,7 +739,6 @@ class Python3Parser(PythonParser):
|
||||
(('pos_arg ' * (args_pos)),
|
||||
('annotate_arg ' * (annotate_args-1)), opname))
|
||||
else:
|
||||
# See above comment about use of EXTENDED_ARG
|
||||
rule = ('mkfunc_annotate ::= %s%sannotate_tuple LOAD_CONST EXTENDED_ARG %s' %
|
||||
(('pos_arg ' * (args_pos)),
|
||||
('annotate_arg ' * (annotate_args-1)), opname))
|
||||
@@ -889,7 +820,8 @@ class Python3Parser(PythonParser):
|
||||
elif lhs == 'annotate_tuple':
|
||||
return not isinstance(tokens[first].attr, tuple)
|
||||
elif lhs == 'kwarg':
|
||||
return not isinstance(tokens[first].attr, str)
|
||||
return not (isinstance(tokens[first].attr, unicode) or
|
||||
isinstance(tokens[first].attr, str))
|
||||
elif lhs == 'while1elsestmt':
|
||||
# if SETUP_LOOP target spans the else part, then this is
|
||||
# not while1else. Also do for whileTrue?
|
||||
|
@@ -2,7 +2,6 @@
|
||||
"""
|
||||
spark grammar differences over Python 3.1 for Python 3.0.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from uncompyle6.parsers.parse31 import Python31Parser
|
||||
|
@@ -2,7 +2,6 @@
|
||||
"""
|
||||
spark grammar differences over Python 3.2 for Python 3.1.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from uncompyle6.parsers.parse32 import Python32Parser
|
||||
|
@@ -2,8 +2,6 @@
|
||||
"""
|
||||
spark grammar differences over Python 3 for Python 3.2.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from uncompyle6.parsers.parse3 import Python3Parser
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
"""
|
||||
spark grammar differences over Python 3.2 for Python 3.3.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from uncompyle6.parsers.parse32 import Python32Parser
|
||||
@@ -21,9 +20,6 @@ class Python33Parser(Python32Parser):
|
||||
iflaststmt ::= testexpr c_stmts_opt33
|
||||
c_stmts_opt33 ::= JUMP_BACK JUMP_ABSOLUTE c_stmts_opt
|
||||
|
||||
whileTruestmt ::= SETUP_LOOP l_stmts JUMP_ABSOLUTE
|
||||
JUMP_BACK COME_FROM_LOOP
|
||||
|
||||
# Python 3.5+ has jump optimization to remove the redundant
|
||||
# jump_excepts. But in 3.3 we need them added
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
"""
|
||||
spark grammar differences over Python 3.4 for Python 3.5.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
|
@@ -2,7 +2,6 @@
|
||||
"""
|
||||
spark grammar differences over Python 3.5 for Python 3.6.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.parser import PythonParserSingle
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
@@ -14,24 +13,21 @@ class Python36Parser(Python35Parser):
|
||||
super(Python36Parser, self).__init__(debug_parser)
|
||||
self.customized = {}
|
||||
|
||||
|
||||
def p_36misc(self, args):
|
||||
"""
|
||||
# 3.6 redoes how return_closure works
|
||||
return_closure ::= LOAD_CLOSURE DUP_TOP STORE_NAME RETURN_VALUE RETURN_LAST
|
||||
expr ::= LOAD_NAME EXTENDED_ARG
|
||||
|
||||
fstring_multi ::= fstring_expr_or_strs BUILD_STRING
|
||||
fstring_expr_or_strs ::= fstring_expr_or_str+
|
||||
|
||||
func_args36 ::= expr BUILD_TUPLE_0
|
||||
call_function ::= func_args36 unmapexpr CALL_FUNCTION_EX
|
||||
call_function ::= func_args36 build_map_unpack_with_call CALL_FUNCTION_EX_KW_1
|
||||
|
||||
withstmt ::= expr SETUP_WITH POP_TOP suite_stmts_opt POP_BLOCK LOAD_CONST
|
||||
WITH_CLEANUP_START WITH_CLEANUP_FINISH END_FINALLY
|
||||
|
||||
call_function ::= expr expr CALL_FUNCTION_EX
|
||||
call_function ::= expr expr expr CALL_FUNCTION_EX_KW_1
|
||||
call_function ::= expr expr expr CALL_FUNCTION_EX_KW
|
||||
"""
|
||||
|
||||
def add_custom_rules(self, tokens, customize):
|
||||
@@ -61,17 +57,6 @@ class Python36Parser(Python35Parser):
|
||||
""" % (fstring_expr_or_str_n, fstring_expr_or_str_n, "fstring_expr_or_str " * v)
|
||||
self.add_unique_doc_rules(rules_str, customize)
|
||||
|
||||
def custom_classfunc_rule(self, opname, token, customize):
|
||||
|
||||
if opname.startswith('CALL_FUNCTION_KW'):
|
||||
values = 'expr ' * token.attr
|
||||
rule = 'call_function ::= expr kwargs_only_36 {token.type}'.format(**locals())
|
||||
self.add_unique_rule(rule, token.type, token.attr, customize)
|
||||
rule = 'kwargs_only_36 ::= {values} LOAD_CONST'.format(**locals())
|
||||
self.add_unique_rule(rule, token.type, token.attr, customize)
|
||||
else:
|
||||
super(Python36Parser, self).custom_classfunc_rule(opname, token, customize)
|
||||
|
||||
|
||||
class Python36ParserSingle(Python36Parser, PythonParserSingle):
|
||||
pass
|
||||
|
@@ -10,14 +10,10 @@ scanner/ingestion module. From here we call various version-specific
|
||||
scanners, e.g. for Python 2.7 or 3.4.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
from uncompyle6 import PYTHON3, IS_PYPY
|
||||
from uncompyle6.scanners.tok import Token
|
||||
from xdis.bytecode import op_size
|
||||
from xdis.magics import py_str2float
|
||||
|
||||
# The byte code versions we support
|
||||
PYTHON_VERSIONS = (1.5,
|
||||
@@ -90,7 +86,7 @@ class Scanner(object):
|
||||
if op is None:
|
||||
op = self.code[pos]
|
||||
target = self.get_argument(pos)
|
||||
if op in self.opc.JREL_OPS:
|
||||
if op in self.opc.hasjrel:
|
||||
target += pos + 3
|
||||
return target
|
||||
|
||||
@@ -101,7 +97,7 @@ class Scanner(object):
|
||||
def print_bytecode(self):
|
||||
for i in self.op_range(0, len(self.code)):
|
||||
op = self.code[i]
|
||||
if op in self.JUMP_OPs:
|
||||
if op in self.opc.hasjabs+self.opc.hasjrel:
|
||||
dest = self.get_target(i, op)
|
||||
print('%i\t%s\t%i' % (i, self.opname[op], dest))
|
||||
else:
|
||||
@@ -216,6 +212,9 @@ class Scanner(object):
|
||||
result.append(offset)
|
||||
return result
|
||||
|
||||
def op_hasArgument(self, op):
|
||||
return self.op_size(op) > 1
|
||||
|
||||
def op_range(self, start, end):
|
||||
"""
|
||||
Iterate through positions of opcodes, skipping
|
||||
@@ -223,7 +222,23 @@ class Scanner(object):
|
||||
"""
|
||||
while start < end:
|
||||
yield start
|
||||
start += op_size(self.code[start], self.opc)
|
||||
start += self.op_size(self.code[start])
|
||||
|
||||
def op_size(self, op):
|
||||
"""
|
||||
Return size of operator with its arguments
|
||||
for given opcode <op>.
|
||||
"""
|
||||
if op < self.opc.HAVE_ARGUMENT:
|
||||
if self.version >= 3.6:
|
||||
return 2
|
||||
else:
|
||||
return 1
|
||||
else:
|
||||
if self.version >= 3.6:
|
||||
return 2
|
||||
else:
|
||||
return 3
|
||||
|
||||
def remove_mid_line_ifs(self, ifs):
|
||||
"""
|
||||
@@ -255,16 +270,13 @@ class Scanner(object):
|
||||
self.Token = tokenClass
|
||||
return self.Token
|
||||
|
||||
def op_has_argument(op, opc):
|
||||
return op >= opc.HAVE_ARGUMENT
|
||||
|
||||
def parse_fn_counts(argc):
|
||||
return ((argc & 0xFF), (argc >> 8) & 0xFF, (argc >> 16) & 0x7FFF)
|
||||
|
||||
|
||||
def get_scanner(version, is_pypy=False, show_asm=None):
|
||||
|
||||
# If version is a string, turn that into the corresponding float.
|
||||
if isinstance(version, str):
|
||||
version = py_str2float(version)
|
||||
|
||||
# Pick up appropriate scanner
|
||||
if version in PYTHON_VERSIONS:
|
||||
v_str = "%s" % (int(version * 10))
|
||||
@@ -291,6 +303,5 @@ def get_scanner(version, is_pypy=False, show_asm=None):
|
||||
if __name__ == "__main__":
|
||||
import inspect, uncompyle6
|
||||
co = inspect.currentframe().f_code
|
||||
scanner = get_scanner('2.7.13', True)
|
||||
scanner = get_scanner(uncompyle6.PYTHON_VERSION, IS_PYPY, True)
|
||||
tokens, customize = scanner.ingest(co, {})
|
||||
|
@@ -1,18 +1,22 @@
|
||||
# Copyright (c) 2017 by Rocky Bernstein
|
||||
# Copyright (c) 2016 by Rocky Bernstein
|
||||
"""
|
||||
Python PyPy 3.2 decompiler scanner.
|
||||
Python PyPy 3.2 bytecode scanner/deparser
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
This overlaps Python's 3.2's dis module, but it can be run from
|
||||
Python 3 and other versions of Python. Also, we save token
|
||||
information for later use in deparsing.
|
||||
"""
|
||||
|
||||
import uncompyle6.scanners.scanner32 as scan
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_32 as opc # is this right?
|
||||
from xdis.opcodes import opcode_32 as opc # is this rgith?
|
||||
JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
||||
# We base this off of 3.2
|
||||
# We base this off of 2.6 instead of the other way around
|
||||
# because we cleaned things up this way.
|
||||
# The history is that 2.7 support is the cleanest,
|
||||
# then from that we got 2.6 and so on.
|
||||
class ScannerPyPy32(scan.Scanner32):
|
||||
def __init__(self, show_asm):
|
||||
# There are no differences in initialization between
|
||||
|
@@ -1,22 +0,0 @@
|
||||
# Copyright (c) 2017 by Rocky Bernstein
|
||||
"""
|
||||
Python PyPy 3.2 decompiler scanner.
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
"""
|
||||
|
||||
import uncompyle6.scanners.scanner35 as scan
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_35 as opc # is this right?
|
||||
JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
||||
# We base this off of 3.5
|
||||
class ScannerPyPy35(scan.Scanner35):
|
||||
def __init__(self, show_asm):
|
||||
# There are no differences in initialization between
|
||||
# pypy 3.5 and 3.5
|
||||
scan.Scanner35.__init__(self, show_asm, is_pypy=True)
|
||||
self.version = 3.5
|
||||
return
|
@@ -1,6 +1,6 @@
|
||||
# Copyright (c) 2016-2017 by Rocky Bernstein
|
||||
# Copyright (c) 2016 by Rocky Bernstein
|
||||
"""
|
||||
Python 1.5 bytecode decompiler scanner.
|
||||
Python 1.5 bytecode scanner/deparser
|
||||
|
||||
This massages tokenized 1.5 bytecode to make it more amenable for
|
||||
grammar parsing.
|
||||
@@ -13,13 +13,13 @@ import uncompyle6.scanners.scanner21 as scan
|
||||
from xdis.opcodes import opcode_15
|
||||
JUMP_OPs = opcode_15.JUMP_OPs
|
||||
|
||||
# We base this off of 2.2 instead of the other way around
|
||||
# We base this off of 2.1 instead of the other way around
|
||||
# because we cleaned things up this way.
|
||||
# The history is that 2.7 support is the cleanest,
|
||||
# then from that we got 2.6 and so on.
|
||||
class Scanner15(scan.Scanner21):
|
||||
def __init__(self, show_asm=False):
|
||||
scan.Scanner21.__init__(self, show_asm)
|
||||
scan.Scanner21.__init__(self, show_asm=False)
|
||||
self.opc = opcode_15
|
||||
self.opname = opcode_15.opname
|
||||
self.version = 1.5
|
||||
|
@@ -20,20 +20,23 @@ For example:
|
||||
Finally we save token information.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
|
||||
if PYTHON_VERSION < 2.6:
|
||||
from xdis.namedtuple25 import namedtuple
|
||||
else:
|
||||
from collections import namedtuple
|
||||
|
||||
from collections import namedtuple
|
||||
from array import array
|
||||
|
||||
from uncompyle6.scanner import L65536
|
||||
from uncompyle6.scanner import op_has_argument
|
||||
from xdis.code import iscode
|
||||
from xdis.bytecode import op_has_argument, op_size
|
||||
|
||||
from uncompyle6.scanner import Scanner
|
||||
import uncompyle6.scanner as scan
|
||||
|
||||
class Scanner2(Scanner):
|
||||
class Scanner2(scan.Scanner):
|
||||
def __init__(self, version, show_asm=None, is_pypy=False):
|
||||
Scanner.__init__(self, version, show_asm, is_pypy)
|
||||
scan.Scanner.__init__(self, version, show_asm, is_pypy)
|
||||
self.pop_jump_if = frozenset([self.opc.PJIF, self.opc.PJIT])
|
||||
self.jump_forward = frozenset([self.opc.JUMP_ABSOLUTE, self.opc.JUMP_FORWARD])
|
||||
# This is the 2.5+ default
|
||||
@@ -85,7 +88,9 @@ class Scanner2(Scanner):
|
||||
cause specific rules for the specific number of arguments they take.
|
||||
"""
|
||||
|
||||
show_asm = self.show_asm if not show_asm else show_asm
|
||||
if not show_asm:
|
||||
show_asm = self.show_asm
|
||||
|
||||
# show_asm = 'after'
|
||||
if show_asm in ('both', 'before'):
|
||||
from xdis.bytecode import Bytecode
|
||||
@@ -187,9 +192,9 @@ class Scanner2(Scanner):
|
||||
oparg = self.get_argument(offset) + extended_arg
|
||||
extended_arg = 0
|
||||
if op == self.opc.EXTENDED_ARG:
|
||||
extended_arg = oparg * L65536
|
||||
extended_arg = oparg * scan.L65536
|
||||
continue
|
||||
if op in self.opc.CONST_OPS:
|
||||
if op in self.opc.hasconst:
|
||||
const = co.co_consts[oparg]
|
||||
if iscode(const):
|
||||
oparg = const
|
||||
@@ -210,23 +215,23 @@ class Scanner2(Scanner):
|
||||
pattr = '<code_object ' + const.co_name + '>'
|
||||
else:
|
||||
pattr = const
|
||||
elif op in self.opc.NAME_OPS:
|
||||
elif op in self.opc.hasname:
|
||||
pattr = names[oparg]
|
||||
elif op in self.opc.JREL_OPS:
|
||||
elif op in self.opc.hasjrel:
|
||||
# use instead: hasattr(self, 'patch_continue'): ?
|
||||
if self.version == 2.7:
|
||||
self.patch_continue(tokens, offset, op)
|
||||
pattr = repr(offset + 3 + oparg)
|
||||
elif op in self.opc.JABS_OPS:
|
||||
elif op in self.opc.hasjabs:
|
||||
# use instead: hasattr(self, 'patch_continue'): ?
|
||||
if self.version == 2.7:
|
||||
self.patch_continue(tokens, offset, op)
|
||||
pattr = repr(oparg)
|
||||
elif op in self.opc.LOCAL_OPS:
|
||||
elif op in self.opc.haslocal:
|
||||
pattr = varnames[oparg]
|
||||
elif op in self.opc.COMPARE_OPS:
|
||||
elif op in self.opc.hascompare:
|
||||
pattr = self.opc.cmp_op[oparg]
|
||||
elif op in self.opc.FREE_OPS:
|
||||
elif op in self.opc.hasfree:
|
||||
pattr = free[oparg]
|
||||
|
||||
if op in self.varargs_ops:
|
||||
@@ -328,7 +333,7 @@ class Scanner2(Scanner):
|
||||
for i in self.op_range(0, n):
|
||||
op = self.code[i]
|
||||
self.prev.append(i)
|
||||
if op_has_argument(op, self.opc):
|
||||
if self.op_hasArgument(op):
|
||||
self.prev.append(i)
|
||||
self.prev.append(i)
|
||||
pass
|
||||
@@ -381,7 +386,7 @@ class Scanner2(Scanner):
|
||||
if elem != code[i]:
|
||||
match = False
|
||||
break
|
||||
i += op_size(code[i], self.opc)
|
||||
i += self.op_size(code[i])
|
||||
|
||||
if match:
|
||||
i = self.prev[i]
|
||||
@@ -452,7 +457,7 @@ class Scanner2(Scanner):
|
||||
self.not_continue.add(jmp)
|
||||
jmp = self.get_target(jmp)
|
||||
prev_offset = self.prev[except_match]
|
||||
# COMPARE_OP argument should be "exception-match" or 10
|
||||
# COMPARE_OP argument should be "exception match" or 10
|
||||
if (self.code[prev_offset] == self.opc.COMPARE_OP and
|
||||
self.code[prev_offset+1] != 10):
|
||||
return None
|
||||
@@ -603,7 +608,7 @@ class Scanner2(Scanner):
|
||||
|
||||
if test == offset:
|
||||
loop_type = 'while 1'
|
||||
elif self.code[test] in self.opc.JUMP_OPs:
|
||||
elif self.code[test] in self.opc.hasjabs + self.opc.hasjrel:
|
||||
self.ignore_if.add(test)
|
||||
test_target = self.get_target(test)
|
||||
if test_target > (jump_back+3):
|
||||
@@ -618,7 +623,7 @@ class Scanner2(Scanner):
|
||||
'start': jump_back+3,
|
||||
'end': end})
|
||||
elif op == self.opc.SETUP_EXCEPT:
|
||||
start = offset + op_size(op, self.opc)
|
||||
start = offset + self.op_size(op)
|
||||
target = self.get_target(offset, op)
|
||||
end = self.restrict_to_parent(target, parent)
|
||||
if target != end:
|
||||
@@ -642,7 +647,7 @@ class Scanner2(Scanner):
|
||||
setup_except_nest -= 1
|
||||
elif self.code[end_finally_offset] == self.opc.SETUP_EXCEPT:
|
||||
setup_except_nest += 1
|
||||
end_finally_offset += op_size(code[end_finally_offset], self.opc)
|
||||
end_finally_offset += self.op_size(code[end_finally_offset])
|
||||
pass
|
||||
|
||||
# Add the except blocks
|
||||
@@ -843,7 +848,7 @@ class Scanner2(Scanner):
|
||||
else:
|
||||
# We still have the case in 2.7 that the next instruction
|
||||
# is a jump to a SETUP_LOOP target.
|
||||
next_offset = target + op_size(self.code[target], self.opc)
|
||||
next_offset = target + self.op_size(self.code[target])
|
||||
next_op = self.code[next_offset]
|
||||
if self.op_name(next_op) == 'JUMP_FORWARD':
|
||||
jump_target = self.get_target(next_offset, next_op)
|
||||
@@ -905,9 +910,7 @@ class Scanner2(Scanner):
|
||||
'start': start-3,
|
||||
'end': pre_rtarget})
|
||||
|
||||
# FIXME: this is yet another case were we need dominators.
|
||||
if pre_rtarget not in self.linestartoffsets or self.version < 2.7:
|
||||
self.not_continue.add(pre_rtarget)
|
||||
self.not_continue.add(pre_rtarget)
|
||||
|
||||
if rtarget < end:
|
||||
# We have an "else" block of some kind.
|
||||
@@ -994,11 +997,11 @@ class Scanner2(Scanner):
|
||||
oparg = self.get_argument(offset)
|
||||
|
||||
if label is None:
|
||||
if op in self.opc.JREL_OPS and self.op_name(op) != 'FOR_ITER':
|
||||
# if (op in self.opc.JREL_OPS and
|
||||
if op in self.opc.hasjrel and self.op_name(op) != 'FOR_ITER':
|
||||
# if (op in self.opc.hasjrel and
|
||||
# (self.version < 2.0 or op != self.opc.FOR_ITER)):
|
||||
label = offset + 3 + oparg
|
||||
elif self.version == 2.7 and op in self.opc.JABS_OPS:
|
||||
elif self.version == 2.7 and op in self.opc.hasjabs:
|
||||
if op in (self.opc.JUMP_IF_FALSE_OR_POP,
|
||||
self.opc.JUMP_IF_TRUE_OR_POP):
|
||||
if (oparg > offset):
|
||||
@@ -1026,8 +1029,10 @@ class Scanner2(Scanner):
|
||||
|
||||
# FIXME: rocky: I think we need something like this...
|
||||
if offset not in set(self.ignore_if) or self.version == 2.7:
|
||||
source = (self.setup_loops[label]
|
||||
if label in self.setup_loops else offset)
|
||||
if label in self.setup_loops:
|
||||
source = self.setup_loops[label]
|
||||
else:
|
||||
source = offset
|
||||
targets[label] = targets.get(label, []) + [source]
|
||||
pass
|
||||
|
||||
|
@@ -19,7 +19,7 @@ JUMP_OPs = opcode_21.JUMP_OPs
|
||||
# then from that we got 2.6 and so on.
|
||||
class Scanner21(scan.Scanner22):
|
||||
def __init__(self, show_asm=False):
|
||||
scan.Scanner22.__init__(self, show_asm)
|
||||
scan.Scanner22.__init__(self, show_asm=False)
|
||||
self.opc = opcode_21
|
||||
self.opname = opcode_21.opname
|
||||
self.version = 2.1
|
||||
|
@@ -19,7 +19,7 @@ JUMP_OPs = opcode_22.JUMP_OPs
|
||||
# then from that we got 2.6 and so on.
|
||||
class Scanner22(scan.Scanner23):
|
||||
def __init__(self, show_asm=False):
|
||||
scan.Scanner23.__init__(self, show_asm)
|
||||
scan.Scanner23.__init__(self, show_asm=False)
|
||||
self.opc = opcode_22
|
||||
self.opname = opcode_22.opname
|
||||
self.version = 2.2
|
||||
|
@@ -1,4 +1,4 @@
|
||||
# Copyright (c) 2015-2017 by Rocky Bernstein
|
||||
# Copyright (c) 2015, 2016 by Rocky Bernstein
|
||||
# Copyright (c) 2005 by Dan Pascu <dan@windowmaker.org>
|
||||
# Copyright (c) 2000-2002 by hartmut Goebel <h.goebel@crazy-compilers.com>
|
||||
"""
|
||||
@@ -15,7 +15,6 @@ if PYTHON3:
|
||||
intern = sys.intern
|
||||
|
||||
import uncompyle6.scanners.scanner2 as scan
|
||||
from uncompyle6.scanner import L65536
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_26
|
||||
@@ -87,7 +86,9 @@ class Scanner26(scan.Scanner2):
|
||||
cause specific rules for the specific number of arguments they take.
|
||||
"""
|
||||
|
||||
show_asm = self.show_asm if not show_asm else show_asm
|
||||
if not show_asm:
|
||||
show_asm = self.show_asm
|
||||
|
||||
# show_asm = 'after'
|
||||
if show_asm in ('both', 'before'):
|
||||
from xdis.bytecode import Bytecode
|
||||
@@ -179,9 +180,10 @@ class Scanner26(scan.Scanner2):
|
||||
oparg = self.get_argument(offset) + extended_arg
|
||||
extended_arg = 0
|
||||
if op == self.opc.EXTENDED_ARG:
|
||||
extended_arg = oparg * L65536
|
||||
raise NotImplementedError
|
||||
extended_arg = oparg * scan.L65536
|
||||
continue
|
||||
if op in self.opc.CONST_OPS:
|
||||
if op in self.opc.hasconst:
|
||||
const = co.co_consts[oparg]
|
||||
# We can't use inspect.iscode() because we may be
|
||||
# using a different version of Python than the
|
||||
@@ -206,9 +208,9 @@ class Scanner26(scan.Scanner2):
|
||||
pattr = '<code_object ' + const.co_name + '>'
|
||||
else:
|
||||
pattr = const
|
||||
elif op in self.opc.NAME_OPS:
|
||||
elif op in self.opc.hasname:
|
||||
pattr = names[oparg]
|
||||
elif op in self.opc.JREL_OPS:
|
||||
elif op in self.opc.hasjrel:
|
||||
pattr = repr(offset + 3 + oparg)
|
||||
if op == self.opc.JUMP_FORWARD:
|
||||
target = self.get_target(offset)
|
||||
@@ -218,13 +220,13 @@ class Scanner26(scan.Scanner2):
|
||||
if len(tokens) and tokens[-1].type == 'JUMP_BACK':
|
||||
tokens[-1].type = intern('CONTINUE')
|
||||
|
||||
elif op in self.opc.JABS_OPS:
|
||||
elif op in self.opc.hasjabs:
|
||||
pattr = repr(oparg)
|
||||
elif op in self.opc.LOCAL_OPS:
|
||||
elif op in self.opc.haslocal:
|
||||
pattr = varnames[oparg]
|
||||
elif op in self.opc.COMPARE_OPS:
|
||||
elif op in self.opc.hascompare:
|
||||
pattr = self.opc.cmp_op[oparg]
|
||||
elif op in self.opc.FREE_OPS:
|
||||
elif op in self.opc.hasfree:
|
||||
pattr = free[oparg]
|
||||
if op in self.varargs_ops:
|
||||
# CE - Hack for >= 2.5
|
||||
|
@@ -7,8 +7,6 @@ grammar parsing.
|
||||
"""
|
||||
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.scanners.scanner2 import Scanner2
|
||||
|
||||
from uncompyle6 import PYTHON3
|
||||
|
@@ -20,16 +20,19 @@ For example:
|
||||
Finally we save token information.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
from uncompyle6 import PYTHON_VERSION
|
||||
|
||||
if PYTHON_VERSION < 2.6:
|
||||
from xdis.namedtuple25 import namedtuple
|
||||
else:
|
||||
from collections import namedtuple
|
||||
|
||||
from collections import namedtuple
|
||||
from array import array
|
||||
|
||||
from uncompyle6.scanner import Scanner
|
||||
from uncompyle6.scanner import Scanner, op_has_argument
|
||||
from xdis.code import iscode
|
||||
from xdis.bytecode import Bytecode, op_has_argument, op_size
|
||||
from xdis.bytecode import Bytecode
|
||||
from uncompyle6.scanner import Token, parse_fn_counts
|
||||
import xdis
|
||||
|
||||
# Get all the opcodes into globals
|
||||
import xdis.opcodes.opcode_33 as op3
|
||||
@@ -131,21 +134,11 @@ class Scanner3(Scanner):
|
||||
varargs_ops.add(self.opc.CALL_METHOD)
|
||||
if self.version >= 3.6:
|
||||
varargs_ops.add(self.opc.BUILD_CONST_KEY_MAP)
|
||||
# Below is in bit order, "default = bit 0, closure = bit 3
|
||||
self.MAKE_FUNCTION_FLAGS = tuple("""
|
||||
default keyword-only annotation closure""".split())
|
||||
|
||||
self.varargs_ops = frozenset(varargs_ops)
|
||||
# FIXME: remove the above in favor of:
|
||||
# self.varargs_ops = frozenset(self.opc.hasvargs)
|
||||
|
||||
def extended_arg_val(self, val):
|
||||
if self.version < 3.6:
|
||||
return val * (1<<16)
|
||||
else:
|
||||
return val * (1<<8)
|
||||
|
||||
|
||||
def ingest(self, co, classname=None, code_objects={}, show_asm=None):
|
||||
"""
|
||||
Pick out tokens from an uncompyle6 code object, and transform them,
|
||||
@@ -162,8 +155,10 @@ class Scanner3(Scanner):
|
||||
cause specific rules for the specific number of arguments they take.
|
||||
"""
|
||||
|
||||
show_asm = self.show_asm if not show_asm else show_asm
|
||||
# show_asm = 'both'
|
||||
if not show_asm:
|
||||
show_asm = self.show_asm
|
||||
|
||||
# show_asm = 'after'
|
||||
if show_asm in ('both', 'before'):
|
||||
bytecode = Bytecode(co, self.opc)
|
||||
for instr in bytecode.get_instructions(co):
|
||||
@@ -216,29 +211,9 @@ class Scanner3(Scanner):
|
||||
jump_targets = self.find_jump_targets(show_asm)
|
||||
last_op_was_break = False
|
||||
|
||||
extended_arg = 0
|
||||
for i, inst in enumerate(bytecode):
|
||||
for inst in bytecode:
|
||||
|
||||
argval = inst.argval
|
||||
op = inst.opcode
|
||||
has_arg = op_has_argument(op, self.opc)
|
||||
if has_arg:
|
||||
if op == self.opc.EXTENDED_ARG:
|
||||
extended_arg += self.extended_arg_val(argval)
|
||||
|
||||
# Normally we remove EXTENDED_ARG from the
|
||||
# opcodes, but in the case of annotated functions
|
||||
# can use the EXTENDED_ARG tuple to signal we have
|
||||
# an annotated function.
|
||||
if not bs[i+1].opname.startswith("MAKE_FUNCTION"):
|
||||
continue
|
||||
|
||||
if isinstance(argval, int) and extended_arg:
|
||||
min_extended= self.extended_arg_val(1)
|
||||
if argval < min_extended:
|
||||
argval += extended_arg
|
||||
extended_arg = 0
|
||||
|
||||
if inst.offset in jump_targets:
|
||||
jump_idx = 0
|
||||
# We want to process COME_FROMs to the same offset to be in *descending*
|
||||
@@ -275,11 +250,12 @@ class Scanner3(Scanner):
|
||||
|
||||
pass
|
||||
|
||||
pattr = inst.argrepr
|
||||
pattr = inst.argrepr
|
||||
opname = inst.opname
|
||||
op = inst.opcode
|
||||
|
||||
if opname in ['LOAD_CONST']:
|
||||
const = argval
|
||||
const = inst.argval
|
||||
if iscode(const):
|
||||
if const.co_name == '<lambda>':
|
||||
opname = 'LOAD_LAMBDA'
|
||||
@@ -301,37 +277,20 @@ class Scanner3(Scanner):
|
||||
pattr = const
|
||||
pass
|
||||
elif opname in ('MAKE_FUNCTION', 'MAKE_CLOSURE'):
|
||||
if self.version >= 3.6:
|
||||
# 3.6+ doesn't have MAKE_CLOSURE, so opname == 'MAKE_FUNCTION'
|
||||
flags = argval
|
||||
opname = 'MAKE_FUNCTION_%d' % (flags)
|
||||
attr = []
|
||||
for flag in self.MAKE_FUNCTION_FLAGS:
|
||||
bit = flags & 1
|
||||
if bit:
|
||||
if pattr:
|
||||
pattr += ", " + flag
|
||||
else:
|
||||
pattr += flag
|
||||
attr.append(bit)
|
||||
flags >>= 1
|
||||
attr = attr[:4] # remove last value: attr[5] == False
|
||||
else:
|
||||
pos_args, name_pair_args, annotate_args = parse_fn_counts(inst.argval)
|
||||
pattr = ("%d positional, %d keyword pair, %d annotated" %
|
||||
(pos_args, name_pair_args, annotate_args))
|
||||
if name_pair_args > 0:
|
||||
opname = '%s_N%d' % (opname, name_pair_args)
|
||||
pass
|
||||
if annotate_args > 0:
|
||||
opname = '%s_A_%d' % (opname, annotate_args)
|
||||
pass
|
||||
opname = '%s_%d' % (opname, pos_args)
|
||||
attr = (pos_args, name_pair_args, annotate_args)
|
||||
pos_args, name_pair_args, annotate_args = parse_fn_counts(inst.argval)
|
||||
if name_pair_args > 0:
|
||||
opname = '%s_N%d' % (opname, name_pair_args)
|
||||
pass
|
||||
if annotate_args > 0:
|
||||
opname = '%s_A_%d' % (opname, annotate_args)
|
||||
pass
|
||||
opname = '%s_%d' % (opname, pos_args)
|
||||
pattr = ("%d positional, %d keyword pair, %d annotated" %
|
||||
(pos_args, name_pair_args, annotate_args))
|
||||
tokens.append(
|
||||
Token(
|
||||
type_ = opname,
|
||||
attr = attr,
|
||||
attr = (pos_args, name_pair_args, annotate_args),
|
||||
pattr = pattr,
|
||||
offset = inst.offset,
|
||||
linestart = inst.starts_line,
|
||||
@@ -342,7 +301,7 @@ class Scanner3(Scanner):
|
||||
)
|
||||
continue
|
||||
elif op in self.varargs_ops:
|
||||
pos_args = argval
|
||||
pos_args = inst.argval
|
||||
if self.is_pypy and not pos_args and opname == 'BUILD_MAP':
|
||||
opname = 'BUILD_MAP_n'
|
||||
else:
|
||||
@@ -354,9 +313,9 @@ class Scanner3(Scanner):
|
||||
customize[opname] = 0
|
||||
elif opname == 'UNPACK_EX':
|
||||
# FIXME: try with scanner and parser by
|
||||
# changing argval
|
||||
before_args = argval & 0xFF
|
||||
after_args = (argval >> 8) & 0xff
|
||||
# changing inst.argval
|
||||
before_args = inst.argval & 0xFF
|
||||
after_args = (inst.argval >> 8) & 0xff
|
||||
pattr = "%d before vararg, %d after" % (before_args, after_args)
|
||||
argval = (before_args, after_args)
|
||||
opname = '%s_%d+%d' % (opname, before_args, after_args)
|
||||
@@ -373,7 +332,7 @@ class Scanner3(Scanner):
|
||||
# comprehensions we might sometimes classify JUMP_BACK
|
||||
# as CONTINUE, but that's okay since we add a grammar
|
||||
# rule for that.
|
||||
pattr = argval
|
||||
pattr = inst.argval
|
||||
target = self.get_target(inst.offset)
|
||||
if target <= inst.offset:
|
||||
next_opname = self.opname[self.code[inst.offset+3]]
|
||||
@@ -382,7 +341,11 @@ class Scanner3(Scanner):
|
||||
(next_opname not in ('END_FINALLY', 'POP_BLOCK',
|
||||
# Python 3.0 only uses POP_TOP
|
||||
'POP_TOP'))):
|
||||
opname = 'CONTINUE'
|
||||
if (self.version >= 3.4 or
|
||||
(inst.offset not in self.not_continue) or
|
||||
(tokens[-1].type == 'RETURN_VALUE')):
|
||||
opname = 'CONTINUE'
|
||||
pass
|
||||
else:
|
||||
opname = 'JUMP_BACK'
|
||||
# FIXME: this is a hack to catch stuff like:
|
||||
@@ -469,7 +432,7 @@ class Scanner3(Scanner):
|
||||
self.prev = self.prev_op = [0]
|
||||
for offset in self.op_range(0, codelen):
|
||||
op = code[offset]
|
||||
for _ in range(op_size(op, self.opc)):
|
||||
for _ in range(self.op_size(op)):
|
||||
self.prev_op.append(offset)
|
||||
|
||||
def find_jump_targets(self, debug):
|
||||
@@ -519,7 +482,7 @@ class Scanner3(Scanner):
|
||||
oparg = code[offset+1]
|
||||
else:
|
||||
oparg = code[offset+1] + code[offset+2] * 256
|
||||
next_offset = xdis.next_offset(op, self.opc, offset)
|
||||
next_offset = offset + self.op_size(op)
|
||||
|
||||
if label is None:
|
||||
if op in op3.hasjrel and op != self.opc.FOR_ITER:
|
||||
@@ -565,7 +528,7 @@ class Scanner3(Scanner):
|
||||
if elem != code[i]:
|
||||
match = False
|
||||
break
|
||||
i += op_size(code[i], self.opc)
|
||||
i += self.op_size(code[i])
|
||||
|
||||
if match is True:
|
||||
i = self.prev_op[i]
|
||||
@@ -630,18 +593,14 @@ class Scanner3(Scanner):
|
||||
Get target offset for op located at given <offset>.
|
||||
"""
|
||||
op = self.code[offset]
|
||||
rel_offset = 0
|
||||
if self.version >= 3.6:
|
||||
target = self.code[offset+1]
|
||||
if op in self.opc.JREL_OPS:
|
||||
rel_offset = offset + 2
|
||||
if op in self.opc.hasjrel:
|
||||
target += offset + 2
|
||||
else:
|
||||
target = self.code[offset+1] + self.code[offset+2] * 256
|
||||
if op in self.opc.JREL_OPS:
|
||||
rel_offset = offset + 3
|
||||
pass
|
||||
pass
|
||||
target += rel_offset
|
||||
if op in self.opc.hasjrel:
|
||||
target += offset + 3
|
||||
|
||||
return target
|
||||
|
||||
@@ -758,7 +717,7 @@ class Scanner3(Scanner):
|
||||
'start': jump_back+3,
|
||||
'end': end})
|
||||
elif op in self.pop_jump_tf:
|
||||
start = offset + op_size(op, self.opc)
|
||||
start = offset + self.op_size(op)
|
||||
target = self.get_target(offset)
|
||||
rtarget = self.restrict_to_parent(target, parent)
|
||||
prev_op = self.prev_op
|
||||
@@ -786,7 +745,7 @@ class Scanner3(Scanner):
|
||||
pre_rtarget = prev_op[rtarget]
|
||||
|
||||
# Is it an "and" inside an "if" or "while" block
|
||||
if op == self.opc.POP_JUMP_IF_FALSE and self.version < 3.6:
|
||||
if op == self.opc.POP_JUMP_IF_FALSE:
|
||||
|
||||
# Search for another POP_JUMP_IF_FALSE targetting the same op,
|
||||
# in current statement, starting from current offset, and filter
|
||||
@@ -921,7 +880,7 @@ class Scanner3(Scanner):
|
||||
# except block return
|
||||
jump_prev = prev_op[offset]
|
||||
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
|
||||
if self.version >= 3.5:
|
||||
# Python 3.5 may remove as dead code a JUMP
|
||||
@@ -933,9 +892,9 @@ class Scanner3(Scanner):
|
||||
# not from SETUP_EXCEPT
|
||||
next_op = rtarget
|
||||
if code[next_op] == self.opc.POP_BLOCK:
|
||||
next_op += op_size(self.code[next_op], self.opc)
|
||||
next_op += self.op_size(self.code[next_op])
|
||||
if code[next_op] == self.opc.JUMP_ABSOLUTE:
|
||||
next_op += op_size(self.code[next_op], self.opc)
|
||||
next_op += self.op_size(self.code[next_op])
|
||||
if next_op in targets:
|
||||
for try_op in targets[next_op]:
|
||||
come_from_op = code[try_op]
|
||||
@@ -958,14 +917,14 @@ class Scanner3(Scanner):
|
||||
end = self.restrict_to_parent(target, parent)
|
||||
self.fixed_jumps[offset] = end
|
||||
elif op == self.opc.POP_EXCEPT:
|
||||
next_offset = xdis.next_offset(op, self.opc, offset)
|
||||
if self.version <= 3.5:
|
||||
next_offset = offset+1
|
||||
else:
|
||||
next_offset = offset+2
|
||||
target = self.get_target(next_offset)
|
||||
if target > next_offset:
|
||||
next_op = code[next_offset]
|
||||
if (self.opc.JUMP_ABSOLUTE == next_op and
|
||||
END_FINALLY != code[xdis.next_offset(next_op, self.opc, next_offset)]):
|
||||
self.fixed_jumps[next_offset] = target
|
||||
self.except_targets[target] = next_offset
|
||||
self.fixed_jumps[next_offset] = target
|
||||
self.except_targets[target] = next_offset
|
||||
|
||||
elif op == self.opc.SETUP_FINALLY:
|
||||
target = self.get_target(offset)
|
||||
|
@@ -6,12 +6,8 @@ This sets up opcodes Python's 3.0 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_30 as opc
|
||||
from xdis.bytecode import op_size
|
||||
|
||||
JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
||||
JUMP_TF = frozenset([opc.JUMP_IF_FALSE, opc.JUMP_IF_TRUE])
|
||||
@@ -120,7 +116,7 @@ class Scanner30(Scanner3):
|
||||
|
||||
if test == offset:
|
||||
loop_type = 'while 1'
|
||||
elif self.code[test] in opc.JUMP_OPs:
|
||||
elif self.code[test] in opc.hasjabs+opc.hasjrel:
|
||||
self.ignore_if.add(test)
|
||||
test_target = self.get_target(test)
|
||||
if test_target > (jump_back+3):
|
||||
@@ -135,7 +131,7 @@ class Scanner30(Scanner3):
|
||||
'start': jump_back+3,
|
||||
'end': end})
|
||||
elif op in JUMP_TF:
|
||||
start = offset + op_size(op, self.opc)
|
||||
start = offset + self.op_size(op)
|
||||
target = self.get_target(offset)
|
||||
rtarget = self.restrict_to_parent(target, parent)
|
||||
prev_op = self.prev_op
|
||||
@@ -295,7 +291,7 @@ class Scanner30(Scanner3):
|
||||
# except block return
|
||||
jump_prev = prev_op[offset]
|
||||
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
|
||||
if self.version >= 3.5:
|
||||
# Python 3.5 may remove as dead code a JUMP
|
||||
@@ -307,9 +303,9 @@ class Scanner30(Scanner3):
|
||||
# not from SETUP_EXCEPT
|
||||
next_op = rtarget
|
||||
if code[next_op] == self.opc.POP_BLOCK:
|
||||
next_op += op_size(self.code[next_op], self.opc)
|
||||
next_op += self.op_size(self.code[next_op])
|
||||
if code[next_op] == self.opc.JUMP_ABSOLUTE:
|
||||
next_op += op_size(self.code[next_op], self.opc)
|
||||
next_op += self.op_size(self.code[next_op])
|
||||
if next_op in targets:
|
||||
for try_op in targets[next_op]:
|
||||
come_from_op = code[try_op]
|
||||
|
@@ -6,8 +6,6 @@ This sets up opcodes Python's 3.1 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_31 as opc
|
||||
JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
@@ -1,16 +1,11 @@
|
||||
# Copyright (c) 2015-2017 by Rocky Bernstein
|
||||
# Copyright (c) 2015-2016 by Rocky Bernstein
|
||||
"""
|
||||
Python 3.2 bytecode decompiler scanner.
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
Python 3.2 bytecode scanner/deparser
|
||||
|
||||
This sets up opcodes Python's 3.2 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_32 as opc
|
||||
JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
@@ -6,8 +6,6 @@ This sets up opcodes Python's 3.3 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
from xdis.opcodes import opcode_33 as opc
|
||||
JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
@@ -1,16 +1,11 @@
|
||||
# Copyright (c) 2015-2017 by Rocky Bernstein
|
||||
# Copyright (c) 2015-2016 by Rocky Bernstein
|
||||
"""
|
||||
Python 3.4 bytecode decompiler scanner
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
Python 3.4 bytecode scanner/deparser
|
||||
|
||||
This sets up opcodes Python's 3.4 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from xdis.opcodes import opcode_34 as opc
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
|
@@ -1,16 +1,11 @@
|
||||
# Copyright (c) 2017 by Rocky Bernstein
|
||||
# Copyright (c) 2016 by Rocky Bernstein
|
||||
"""
|
||||
Python 3.5 bytecode decompiler scanner
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
Python 3.5 bytecode scanner/deparser
|
||||
|
||||
This sets up opcodes Python's 3.5 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.scanners.scanner3 import Scanner3
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
@@ -19,8 +14,8 @@ JUMP_OPs = map(lambda op: opc.opname[op], opc.hasjrel + opc.hasjabs)
|
||||
|
||||
class Scanner35(Scanner3):
|
||||
|
||||
def __init__(self, show_asm=None, is_pypy=False):
|
||||
Scanner3.__init__(self, 3.5, show_asm, is_pypy)
|
||||
def __init__(self, show_asm=None):
|
||||
Scanner3.__init__(self, 3.5, show_asm)
|
||||
return
|
||||
pass
|
||||
|
||||
|
@@ -1,16 +1,11 @@
|
||||
# Copyright (c) 2016-2017 by Rocky Bernstein
|
||||
# Copyright (c) 2016 by Rocky Bernstein
|
||||
"""
|
||||
Python 3.6 bytecode decompiler scanner
|
||||
|
||||
Does some additional massaging of xdis-disassembled instructions to
|
||||
make things easier for decompilation.
|
||||
Python 3.6 bytecode scanner/deparser
|
||||
|
||||
This sets up opcodes Python's 3.6 and calls a generalized
|
||||
scanner routine for Python 3.
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
from uncompyle6.scanners.scanner3 import Scanner3
|
||||
|
||||
# bytecode verification, verify(), uses JUMP_OPs from here
|
||||
@@ -31,12 +26,6 @@ class Scanner36(Scanner3):
|
||||
if t.op == self.opc.CALL_FUNCTION_EX and t.attr & 1:
|
||||
t.type = 'CALL_FUNCTION_EX_KW'
|
||||
pass
|
||||
elif t.op == self.opc.CALL_FUNCTION_KW:
|
||||
t.type = 'CALL_FUNCTION_KW_{t.attr}'.format(**locals())
|
||||
elif t.op == self.opc.BUILD_TUPLE_UNPACK_WITH_CALL:
|
||||
t.type = 'BUILD_TUPLE_UNPACK_WITH_CALL_%d' % t.attr
|
||||
elif t.op == self.opc.BUILD_MAP_UNPACK_WITH_CALL:
|
||||
t.type = 'BUILD_MAP_UNPACK_WITH_CALL_%d' % t.attr
|
||||
pass
|
||||
return tokens, customize
|
||||
|
||||
|
@@ -56,19 +56,25 @@ class Token:
|
||||
return self.format(line_prefix='')
|
||||
|
||||
def format(self, line_prefix=''):
|
||||
prefix = ('\n%s%4d ' % (line_prefix, self.linestart)
|
||||
if self.linestart else (' ' * (6 + len(line_prefix))))
|
||||
if self.linestart:
|
||||
prefix = '\n%s%4d ' % (line_prefix, self.linestart)
|
||||
else:
|
||||
prefix = ' ' * (6 + len(line_prefix))
|
||||
offset_opname = '%6s %-17s' % (self.offset, self.type)
|
||||
if not self.has_arg:
|
||||
return "%s%s" % (prefix, offset_opname)
|
||||
argstr = "%6d " % self.attr if isinstance(self.attr, int) else (' '*7)
|
||||
|
||||
if isinstance(self.attr, int):
|
||||
argstr = "%6d " % self.attr
|
||||
else:
|
||||
argstr = ' '*7
|
||||
if self.pattr:
|
||||
pattr = self.pattr
|
||||
if self.opc:
|
||||
if self.op in self.opc.JREL_OPS:
|
||||
if self.op in self.opc.hasjrel:
|
||||
if not self.pattr.startswith('to '):
|
||||
pattr = "to " + self.pattr
|
||||
elif self.op in self.opc.JABS_OPS:
|
||||
elif self.op in self.opc.hasjabs:
|
||||
self.pattr= str(self.pattr)
|
||||
if not self.pattr.startswith('to '):
|
||||
pattr = "to " + str(self.pattr)
|
||||
|
@@ -176,7 +176,7 @@ TABLE_DIRECT = {
|
||||
'ret_cond_not': ( '%p if not %p else %p', (2, 27), (0, 22), (-1, 27)),
|
||||
'conditional_lambda': ( '(%c if %c else %c)', 2, 0, 3),
|
||||
'return_lambda': ('%c', 0),
|
||||
'compare': ( '%p %[-1]{pattr.replace("-", " ")} %p', (0, 19), (1, 19) ),
|
||||
'compare': ( '%p %[-1]{pattr} %p', (0, 19), (1, 19) ),
|
||||
'cmp_list': ( '%p %p', (0, 29), (1, 30)),
|
||||
'cmp_list1': ( '%[3]{pattr} %p %p', (0, 19), (-2, 19)),
|
||||
'cmp_list2': ( '%[1]{pattr} %p', (0, 19)),
|
||||
|
@@ -44,45 +44,53 @@ do it recursively which is where offsets are probably located.
|
||||
|
||||
For example in:
|
||||
'importmultiple': ( '%|import%b %c%c\n', 0, 2, 3 ),
|
||||
n
|
||||
|
||||
The node position 0 will be associated with "import".
|
||||
|
||||
"""
|
||||
|
||||
# FIXME: DRY code with pysource
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import re, sys
|
||||
|
||||
from uncompyle6 import PYTHON3, IS_PYPY, PYTHON_VERSION
|
||||
from xdis.code import iscode
|
||||
from uncompyle6.semantics import pysource
|
||||
from uncompyle6 import parser
|
||||
from uncompyle6.scanner import Token, Code, get_scanner
|
||||
from uncompyle6.semantics.check_ast import checker
|
||||
from uncompyle6.semantics.helper import print_docstring
|
||||
|
||||
from uncompyle6.show import (
|
||||
maybe_show_asm,
|
||||
maybe_show_ast,
|
||||
maybe_show_ast_param_default,
|
||||
)
|
||||
|
||||
from uncompyle6.parsers.astnode import AST
|
||||
|
||||
from uncompyle6.semantics.pysource import (
|
||||
ParserError, StringIO)
|
||||
ParserError, find_globals, StringIO)
|
||||
|
||||
from uncompyle6.semantics.consts import (
|
||||
INDENT_PER_LEVEL, NONE, PRECEDENCE,
|
||||
TABLE_DIRECT, escape, minint, MAP
|
||||
)
|
||||
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
from spark_parser.ast import GenericASTTraversalPruningException
|
||||
from uncompyle6.semantics.make_function import (
|
||||
find_all_globals, find_none, code_has_star_arg, code_has_star_star_arg
|
||||
)
|
||||
|
||||
from spark_parser import DEFAULT_DEBUG as PARSER_DEFAULT_DEBUG
|
||||
|
||||
if PYTHON_VERSION < 2.6:
|
||||
from xdis.namedtuple25 import namedtuple
|
||||
else:
|
||||
from collections import namedtuple
|
||||
|
||||
from collections import namedtuple
|
||||
NodeInfo = namedtuple("NodeInfo", "node start finish")
|
||||
ExtractInfo = namedtuple("ExtractInfo",
|
||||
"lineNo lineStartOffset markerLine selectedLine selectedText nonterminal")
|
||||
"lineNo lineStartOffset markerLine selectedLine selectedText")
|
||||
|
||||
TABLE_DIRECT_FRAGMENT = {
|
||||
'break_stmt': ( '%|%rbreak\n', ),
|
||||
@@ -160,9 +168,8 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
def set_pos_info(self, node, start, finish, name=None):
|
||||
if name is None: name = self.name
|
||||
if hasattr(node, 'offset'):
|
||||
node.start = start
|
||||
node.finish = finish
|
||||
self.offsets[name, node.offset] = node
|
||||
self.offsets[name, node.offset] = \
|
||||
NodeInfo(node = node, start = start, finish = finish)
|
||||
|
||||
if hasattr(node, 'parent'):
|
||||
assert node.parent != node
|
||||
@@ -178,34 +185,6 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
|
||||
return
|
||||
|
||||
def table_r_node(self, node):
|
||||
"""General pattern where the last node should should
|
||||
get the text span attributes of the entire tree"""
|
||||
start = len(self.f.getvalue())
|
||||
try:
|
||||
self.default(node)
|
||||
except GenericASTTraversalPruningException:
|
||||
final = len(self.f.getvalue())
|
||||
self.set_pos_info(node, start, final)
|
||||
self.set_pos_info(node[-1], start, final)
|
||||
raise GenericASTTraversalPruningException
|
||||
|
||||
n_slice0 = n_slice1 = n_slice2 = n_slice3 = n_binary_subscr = table_r_node
|
||||
n_augassign_1 = n_print_item = exec_stmt = print_to_item = del_stmt = table_r_node
|
||||
n_classdefco1 = n_classdefco2 = except_cond1 = except_cond2 = table_r_node
|
||||
|
||||
def n_passtmt(self, node):
|
||||
start = len(self.f.getvalue()) + len(self.indent)
|
||||
self.set_pos_info(node, start, start+len("pass"))
|
||||
self.default(node)
|
||||
|
||||
def n_trystmt(self, node):
|
||||
start = len(self.f.getvalue()) + len(self.indent)
|
||||
self.set_pos_info(node[0], start, start+len("try:"))
|
||||
self.default(node)
|
||||
|
||||
n_tryelsestmt = n_tryelsestmtc = n_tryelsestmtl = n_tryfinallystmt = n_trystmt
|
||||
|
||||
def n_return_stmt(self, node):
|
||||
start = len(self.f.getvalue()) + len(self.indent)
|
||||
if self.params['isLambda']:
|
||||
@@ -259,7 +238,6 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.write(' ')
|
||||
node[0].parent = node
|
||||
self.preorder(node[0])
|
||||
self.set_pos_info(node[-1], start, len(self.f.getvalue()))
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
self.prune() # stop recursing
|
||||
|
||||
@@ -397,23 +375,15 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.write(sep); sep = ", "
|
||||
self.preorder(subnode)
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
self.set_pos_info(node[-1], start, len(self.f.getvalue()))
|
||||
self.println()
|
||||
self.prune() # stop recursing
|
||||
|
||||
def n_ifelsestmtr(self, node):
|
||||
if node[2] == 'COME_FROM':
|
||||
return_stmts_node = node[3]
|
||||
node.type = 'ifelsestmtr2'
|
||||
else:
|
||||
return_stmts_node = node[2]
|
||||
if len(return_stmts_node) != 2:
|
||||
if len(node[2]) != 2:
|
||||
self.default(node)
|
||||
|
||||
if (not (return_stmts_node[0][0][0] == 'ifstmt'
|
||||
and return_stmts_node[0][0][0][1][0] == 'return_if_stmts')
|
||||
and not (return_stmts_node[0][-1][0] == 'ifstmt'
|
||||
and return_stmts_node[0][-1][0][1][0] == 'return_if_stmts')):
|
||||
if not (node[2][0][0][0] == 'ifstmt' and node[2][0][0][0][1][0] == 'return_if_stmts') \
|
||||
and not (node[2][0][-1][0] == 'ifstmt' and node[2][0][-1][0][1][0] == 'return_if_stmts'):
|
||||
self.default(node)
|
||||
return
|
||||
|
||||
@@ -434,7 +404,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
|
||||
past_else = False
|
||||
prev_stmt_is_if_ret = True
|
||||
for n in return_stmts_node[0]:
|
||||
for n in node[2][0]:
|
||||
if (n[0] == 'ifstmt' and n[0][1][0] == 'return_if_stmts'):
|
||||
if prev_stmt_is_if_ret:
|
||||
n[0].type = 'elifstmt'
|
||||
@@ -516,20 +486,17 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
# LOAD_CONST code object ..
|
||||
# LOAD_CONST 'x0' if >= 3.3
|
||||
# MAKE_FUNCTION ..
|
||||
code_node = node[-3]
|
||||
elif node[-2] == 'expr':
|
||||
code_node = node[-2][0]
|
||||
code_index = -3
|
||||
else:
|
||||
# LOAD_CONST code object ..
|
||||
# MAKE_FUNCTION ..
|
||||
code_node = node[-2]
|
||||
func_name = code_node.attr.co_name
|
||||
code_index = -2
|
||||
code = node[code_index]
|
||||
func_name = code.attr.co_name
|
||||
self.write(func_name)
|
||||
self.set_pos_info(code_node, start, len(self.f.getvalue()))
|
||||
|
||||
self.indentMore()
|
||||
start = len(self.f.getvalue())
|
||||
self.make_function(node, isLambda=False, codeNode=code_node)
|
||||
self.make_function(node, isLambda=False, code=code)
|
||||
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
|
||||
@@ -772,7 +739,10 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
def n_genexpr(self, node):
|
||||
start = len(self.f.getvalue())
|
||||
self.write('(')
|
||||
code_index = -6 if self.version > 3.2 else -5
|
||||
if self.version > 3.2:
|
||||
code_index = -6
|
||||
else:
|
||||
code_index = -5
|
||||
self.comprehension_walk(node, iter_index=3, code_index=code_index)
|
||||
self.write(')')
|
||||
self.set_pos_info(node, start, len(self.f.getvalue()))
|
||||
@@ -926,7 +896,10 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
subclass = n.attr
|
||||
break
|
||||
pass
|
||||
subclass_info = node if node == 'classdefdeco2' else node[0]
|
||||
if node == 'classdefdeco2':
|
||||
subclass_info = node
|
||||
else:
|
||||
subclass_info = node[0]
|
||||
elif buildclass[1][0] == 'load_closure':
|
||||
# Python 3 with closures not functions
|
||||
load_closure = buildclass[1]
|
||||
@@ -950,7 +923,10 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
subclass = buildclass[1][0].attr
|
||||
subclass_info = node[0]
|
||||
else:
|
||||
buildclass = node if (node == 'classdefdeco2') else node[0]
|
||||
if node == 'classdefdeco2':
|
||||
buildclass = node
|
||||
else:
|
||||
buildclass = node[0]
|
||||
build_list = buildclass[1][0]
|
||||
if hasattr(buildclass[-3][0], 'attr'):
|
||||
subclass = buildclass[-3][0].attr
|
||||
@@ -1016,7 +992,9 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
tokens.append(Token('LAMBDA_MARKER'))
|
||||
try:
|
||||
ast = parser.parse(self.p, tokens, customize)
|
||||
except (parser.ParserError, AssertionError) as e:
|
||||
except parser.ParserError(e):
|
||||
raise ParserError(e, tokens)
|
||||
except AssertionError(e):
|
||||
raise ParserError(e, tokens)
|
||||
maybe_show_ast(self.showast, ast)
|
||||
return ast
|
||||
@@ -1041,7 +1019,9 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
# Build AST from disassembly.
|
||||
try:
|
||||
ast = parser.parse(self.p, tokens, customize)
|
||||
except (parser.ParserError, AssertionError) as e:
|
||||
except parser.ParserError(e):
|
||||
raise ParserError(e, tokens)
|
||||
except AssertionError(e):
|
||||
raise ParserError(e, tokens)
|
||||
|
||||
maybe_show_ast(self.showast, ast)
|
||||
@@ -1121,6 +1101,7 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
def traverse(self, node, indent=None, isLambda=False):
|
||||
'''Buulds up fragment which can be used inside a larger
|
||||
block of code'''
|
||||
|
||||
self.param_stack.append(self.params)
|
||||
if indent is None: indent = self.indent
|
||||
p = self.pending_newlines
|
||||
@@ -1215,38 +1196,16 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
|
||||
if elided: selectedLine += ' ...'
|
||||
|
||||
if isinstance(nodeInfo, Token):
|
||||
nodeInfo = nodeInfo.parent
|
||||
else:
|
||||
nodeInfo = nodeInfo
|
||||
|
||||
if isinstance(nodeInfo, AST):
|
||||
nonterminal = nodeInfo[0]
|
||||
else:
|
||||
nonterminal = nodeInfo.node
|
||||
|
||||
return ExtractInfo(lineNo = len(lines), lineStartOffset = lineStart,
|
||||
markerLine = markerLine,
|
||||
selectedLine = selectedLine,
|
||||
selectedText = selectedText,
|
||||
nonterminal = nonterminal)
|
||||
selectedText = selectedText)
|
||||
|
||||
def extract_line_info(self, name, offset):
|
||||
if (name, offset) not in list(self.offsets.keys()):
|
||||
return None
|
||||
return self.extract_node_info(self.offsets[name, offset])
|
||||
|
||||
def prev_node(self, node):
|
||||
prev = None
|
||||
if not hasattr(node, 'parent'):
|
||||
return prev
|
||||
p = node.parent
|
||||
for n in p:
|
||||
if node == n:
|
||||
return prev
|
||||
prev = n
|
||||
return prev
|
||||
|
||||
def extract_parent_info(self, node):
|
||||
if not hasattr(node, 'parent'):
|
||||
return None, None
|
||||
@@ -1610,16 +1569,155 @@ class FragmentsWalker(pysource.SourceWalker, object):
|
||||
self.set_pos_info(startnode, startnode_start, fin)
|
||||
|
||||
# FIXME rocky: figure out how to get these casess to be table driven.
|
||||
#
|
||||
# 1. for loops. For loops have two positions that correspond to a single text
|
||||
# location. In "for i in ..." there is the initialization "i" code as well
|
||||
# as the iteration code with "i". A "copy" spec like %X3,3 - copy parame
|
||||
# 3 to param 2 would work
|
||||
#
|
||||
# 2. subroutine calls. It the last op is the call and for purposes of printing
|
||||
# we don't need to print anything special there. However it encompases the
|
||||
# entire string of the node fn(...)
|
||||
match = re.search(r'^call_function', startnode.type)
|
||||
match = re.search(r'^try', startnode.type)
|
||||
if match:
|
||||
last_node = startnode[-1]
|
||||
# import traceback; traceback.print_stack()
|
||||
self.set_pos_info(last_node, startnode_start, self.last_finish)
|
||||
self.set_pos_info(node[0], startnode_start, startnode_start+len("try:"))
|
||||
self.set_pos_info(node[2], node[3].finish, node[3].finish)
|
||||
else:
|
||||
match = re.search(r'^call_function', startnode.type)
|
||||
if match:
|
||||
last_node = startnode[-1]
|
||||
# import traceback; traceback.print_stack()
|
||||
self.set_pos_info(last_node, startnode_start, self.last_finish)
|
||||
return
|
||||
|
||||
def make_function(self, node, isLambda, nested=1, code=None):
|
||||
"""Dump function defintion, doc string, and function body."""
|
||||
|
||||
def build_param(ast, name, default):
|
||||
"""build parameters:
|
||||
- handle defaults
|
||||
- handle format tuple parameters
|
||||
"""
|
||||
if self.version < 3.0:
|
||||
# if formal parameter is a tuple, the paramater name
|
||||
# starts with a dot (eg. '.1', '.2')
|
||||
if name.startswith('.'):
|
||||
# replace the name with the tuple-string
|
||||
name = self.get_tuple_parameter(ast, name)
|
||||
pass
|
||||
pass
|
||||
|
||||
if default:
|
||||
maybe_show_ast_param_default(self.showast, name, default)
|
||||
result = '%s=' % name
|
||||
old_last_finish = self.last_finish
|
||||
self.last_finish = len(result)
|
||||
value = self.traverse(default, indent='')
|
||||
self.last_finish = old_last_finish
|
||||
result += value
|
||||
if result[-2:] == '= ': # default was 'LOAD_CONST None'
|
||||
result += 'None'
|
||||
return result
|
||||
else:
|
||||
return name
|
||||
|
||||
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
|
||||
assert node[-1].type.startswith('MAKE_')
|
||||
|
||||
args_node = node[-1]
|
||||
if isinstance(args_node.attr, tuple):
|
||||
if self.version <= 3.3 and len(node) > 2 and node[-3] != 'LOAD_LAMBDA':
|
||||
# positional args are after kwargs
|
||||
defparams = node[1:args_node.attr[0]+1]
|
||||
else:
|
||||
# positional args are before kwargs
|
||||
defparams = node[:args_node.attr[0]]
|
||||
pos_args, kw_args, annotate_argc = args_node.attr
|
||||
else:
|
||||
defparams = node[:args_node.attr]
|
||||
kw_args, annotate_argc = (0, 0)
|
||||
pass
|
||||
|
||||
if self.version > 3.0 and isLambda and iscode(node[-3].attr):
|
||||
code = node[-3].attr
|
||||
else:
|
||||
code = code.attr
|
||||
|
||||
assert iscode(code)
|
||||
code = Code(code, self.scanner, self.currentclass)
|
||||
|
||||
# add defaults values to parameter names
|
||||
argc = code.co_argcount
|
||||
paramnames = list(code.co_varnames[:argc])
|
||||
|
||||
# defaults are for last n parameters, thus reverse
|
||||
paramnames.reverse(); defparams.reverse()
|
||||
|
||||
try:
|
||||
ast = self.build_ast(code._tokens,
|
||||
code._customize,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError(p):
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
return
|
||||
|
||||
# build parameters
|
||||
|
||||
tup = [paramnames, defparams]
|
||||
params = [build_param(ast, name, default) for
|
||||
name, default in map(lambda *tup:tup, *tup)]
|
||||
params.reverse() # back to correct order
|
||||
|
||||
if code_has_star_arg(code):
|
||||
params.append('*%s' % code.co_varnames[argc])
|
||||
argc += 1
|
||||
if code_has_star_star_arg(code):
|
||||
params.append('**%s' % code.co_varnames[argc])
|
||||
argc += 1
|
||||
|
||||
# dump parameter list (with default values)
|
||||
indent = self.indent
|
||||
if isLambda:
|
||||
self.write("lambda ", ", ".join(params))
|
||||
else:
|
||||
self.write("(", ", ".join(params))
|
||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||
|
||||
if kw_args > 0:
|
||||
if argc > 0:
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write("*, ")
|
||||
for n in node:
|
||||
if n == 'pos_arg':
|
||||
continue
|
||||
self.preorder(n)
|
||||
break
|
||||
pass
|
||||
|
||||
if isLambda:
|
||||
self.write(": ")
|
||||
else:
|
||||
self.println("):")
|
||||
|
||||
if len(code.co_consts)>0 and code.co_consts[0] is not None and not isLambda: # ugly
|
||||
# docstring exists, dump it
|
||||
print_docstring(self, indent, code.co_consts[0])
|
||||
|
||||
code._tokens = None # save memory
|
||||
assert ast == 'stmts'
|
||||
|
||||
all_globals = find_all_globals(ast, set())
|
||||
for g in ((all_globals & self.mod_globs) | find_globals(ast, set())):
|
||||
self.println(self.indent, 'global ', g)
|
||||
self.mod_globs -= all_globals
|
||||
rn = ('None' in code.co_names) and not find_none(ast)
|
||||
self.gen_source(ast, code.co_name, code._customize, isLambda=isLambda,
|
||||
returnNone=rn)
|
||||
code._tokens = None; code._customize = None # save memory
|
||||
|
||||
@classmethod
|
||||
def _get_mapping(cls, node):
|
||||
return MAP.get(node, MAP_DIRECT_FRAGMENT)
|
||||
@@ -1699,48 +1797,10 @@ def deparse_code(version, co, out=StringIO(), showasm=False, showast=False,
|
||||
if deparsed.ERROR:
|
||||
raise deparsed.ERROR
|
||||
|
||||
# To keep the API consistent with previous releases, convert
|
||||
# deparse.offset values into NodeInfo items
|
||||
for tup, node in deparsed.offsets.items():
|
||||
deparsed.offsets[tup] = NodeInfo(node = node, start = node.start,
|
||||
finish = node.finish)
|
||||
|
||||
deparsed.scanner = scanner
|
||||
return deparsed
|
||||
|
||||
from bisect import bisect_right
|
||||
def find_gt(a, x):
|
||||
'Find leftmost value greater than x'
|
||||
i = bisect_right(a, x)
|
||||
if i != len(a):
|
||||
return a[i]
|
||||
raise ValueError
|
||||
|
||||
def deparse_code_around_offset(name, offset, version, co, out=StringIO(),
|
||||
showasm=False, showast=False,
|
||||
showgrammar=False, is_pypy=False):
|
||||
"""
|
||||
Like deparse_code(), but given a function/module name and
|
||||
offset, finds the node closest to offset. If offset is not an instruction boundary,
|
||||
we raise an IndexError.
|
||||
"""
|
||||
deparsed = deparse_code(version, co, out, showasm, showast, showgrammar, is_pypy)
|
||||
if (name, offset) in deparsed.offsets.keys():
|
||||
# This is the easy case
|
||||
return deparsed
|
||||
|
||||
valid_offsets = [t for t in deparsed.offsets if isinstance(t[1], int)]
|
||||
offset_list = sorted([t[1] for t in valid_offsets if t[0] == name])
|
||||
|
||||
# FIXME: should check for branching?
|
||||
found_offset = find_gt(offset_list, offset)
|
||||
deparsed.offsets[name, offset] = deparsed.offsets[name, found_offset]
|
||||
return deparsed
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
from uncompyle6 import IS_PYPY
|
||||
def deparse_test(co, is_pypy=IS_PYPY):
|
||||
sys_version = sys.version_info.major + (sys.version_info.minor / 10.0)
|
||||
walk = deparse_code(sys_version, co, showasm=False, showast=False,
|
||||
@@ -1770,35 +1830,6 @@ if __name__ == '__main__':
|
||||
pass
|
||||
return
|
||||
|
||||
def deparse_test_around(offset, name, co, is_pypy=IS_PYPY):
|
||||
sys_version = sys.version_info.major + (sys.version_info.minor / 10.0)
|
||||
walk = deparse_code_around_offset(name, offset, sys_version, co, showasm=False, showast=False,
|
||||
showgrammar=False, is_pypy=IS_PYPY)
|
||||
print("deparsed source")
|
||||
print(walk.text, "\n")
|
||||
print('------------------------')
|
||||
for name, offset in sorted(walk.offsets.keys(),
|
||||
key=lambda x: str(x[0])):
|
||||
print("name %s, offset %s" % (name, offset))
|
||||
nodeInfo = walk.offsets[name, offset]
|
||||
node = nodeInfo.node
|
||||
extractInfo = walk.extract_node_info(node)
|
||||
print("code: %s" % node.type)
|
||||
# print extractInfo
|
||||
print(extractInfo.selectedText)
|
||||
print(extractInfo.selectedLine)
|
||||
print(extractInfo.markerLine)
|
||||
extractInfo, p = walk.extract_parent_info(node)
|
||||
if extractInfo:
|
||||
print("Contained in...")
|
||||
print(extractInfo.selectedLine)
|
||||
print(extractInfo.markerLine)
|
||||
print("code: %s" % p.type)
|
||||
print('=' * 40)
|
||||
pass
|
||||
pass
|
||||
return
|
||||
|
||||
def get_code_for_fn(fn):
|
||||
return fn.__code__
|
||||
|
||||
@@ -1818,9 +1849,6 @@ if __name__ == '__main__':
|
||||
|
||||
# check_args(['3', '5'])
|
||||
# deparse_test(get_code_for_fn(gcd))
|
||||
# deparse_test(get_code_for_fn(test))
|
||||
deparse_test(get_code_for_fn(test))
|
||||
# deparse_test(get_code_for_fn(FragmentsWalker.fixup_offsets))
|
||||
# deparse_test(get_code_for_fn(FragmentsWalker.n_build_list))
|
||||
print('=' * 30)
|
||||
deparse_test_around(408, 'n_build_list', get_code_for_fn(FragmentsWalker.n_build_list))
|
||||
# deparse_test(inspect.currentframe().f_code)
|
||||
|
@@ -6,14 +6,9 @@ All the crazy things we have to do to handle Python functions
|
||||
from xdis.code import iscode
|
||||
from uncompyle6.scanner import Code
|
||||
from uncompyle6.parsers.astnode import AST
|
||||
from uncompyle6 import PYTHON3
|
||||
from uncompyle6.semantics.parser_error import ParserError
|
||||
from uncompyle6.semantics.helper import print_docstring
|
||||
|
||||
if PYTHON3:
|
||||
from itertools import zip_longest
|
||||
else:
|
||||
from itertools import izip_longest as zip_longest
|
||||
|
||||
from uncompyle6.show import maybe_show_ast_param_default
|
||||
|
||||
@@ -139,7 +134,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
||||
code._customize,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError as p:
|
||||
except ParserError, p:
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
return
|
||||
@@ -163,14 +158,11 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
||||
|
||||
i = len(paramnames) - len(defparams)
|
||||
suffix = ''
|
||||
|
||||
no_paramnames = len(paramnames[:i]) == 0
|
||||
|
||||
for param in paramnames[:i]:
|
||||
self.write(suffix, param)
|
||||
suffix = ', '
|
||||
if param in annotate_tuple[0].attr:
|
||||
p = annotate_tuple[0].attr.index(param)
|
||||
p = [x for x in annotate_tuple[0].attr].index(param)
|
||||
self.write(': ')
|
||||
self.preorder(node[p])
|
||||
if (line_number != self.line_number):
|
||||
@@ -182,10 +174,12 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
||||
# else:
|
||||
# self.write(': %s' % value)
|
||||
|
||||
suffix = ', ' if i > 0 else ''
|
||||
if i > 0:
|
||||
suffix = ', '
|
||||
else:
|
||||
suffix = ''
|
||||
for n in node:
|
||||
if n == 'pos_arg':
|
||||
no_paramnames = False
|
||||
self.write(suffix)
|
||||
param = paramnames[i]
|
||||
self.write(param)
|
||||
@@ -193,11 +187,7 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
||||
aa = annotate_args[param]
|
||||
if isinstance(aa, tuple):
|
||||
aa = aa[0]
|
||||
self.write(': "%s"' % aa)
|
||||
elif isinstance(aa, AST):
|
||||
self.write(': ')
|
||||
self.preorder(aa)
|
||||
|
||||
self.write(': "%s"' % aa)
|
||||
self.write('=')
|
||||
i += 1
|
||||
self.preorder(n)
|
||||
@@ -210,65 +200,64 @@ def make_function3_annotate(self, node, isLambda, nested=1,
|
||||
|
||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||
if kw_args + annotate_argc > 0:
|
||||
if no_paramnames:
|
||||
if not code_has_star_arg(code):
|
||||
if argc > 0:
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write("*, ")
|
||||
pass
|
||||
else:
|
||||
self.write(", ")
|
||||
if not code_has_star_arg(code):
|
||||
if argc > 0:
|
||||
|
||||
kwargs = node[0]
|
||||
last = len(kwargs)-1
|
||||
i = 0
|
||||
for n in node[0]:
|
||||
if n == 'kwarg':
|
||||
if (line_number != self.line_number):
|
||||
self.write("\n" + indent)
|
||||
line_number = self.line_number
|
||||
self.write('%s=' % n[0].pattr)
|
||||
self.preorder(n[1])
|
||||
if i < last:
|
||||
self.write(', ')
|
||||
i += 1
|
||||
pass
|
||||
pass
|
||||
annotate_args = []
|
||||
for n in node:
|
||||
if n == 'annotate_arg':
|
||||
annotate_args.append(n[0])
|
||||
elif n == 'annotate_tuple':
|
||||
t = n[0].attr
|
||||
if t[-1] == 'return':
|
||||
t = t[0:-1]
|
||||
annotate_args = annotate_args[:-1]
|
||||
pass
|
||||
last = len(annotate_args) - 1
|
||||
for i in range(len(annotate_args)):
|
||||
self.write("%s: " % (t[i]))
|
||||
self.preorder(annotate_args[i])
|
||||
if i < last:
|
||||
self.write(', ')
|
||||
pass
|
||||
pass
|
||||
break
|
||||
self.write(", *, ")
|
||||
else:
|
||||
self.write("*, ")
|
||||
pass
|
||||
else:
|
||||
self.write(", ")
|
||||
|
||||
kwargs = node[0]
|
||||
last = len(kwargs)-1
|
||||
i = 0
|
||||
for n in node[0]:
|
||||
if n == 'kwarg':
|
||||
if (line_number != self.line_number):
|
||||
self.write("\n" + indent)
|
||||
line_number = self.line_number
|
||||
self.write('%s=' % n[0].pattr)
|
||||
self.preorder(n[1])
|
||||
if i < last:
|
||||
self.write(', ')
|
||||
i += 1
|
||||
pass
|
||||
pass
|
||||
annotate_args = []
|
||||
for n in node:
|
||||
if n == 'annotate_arg':
|
||||
annotate_args.append(n[0])
|
||||
elif n == 'annotate_tuple':
|
||||
t = n[0].attr
|
||||
if t[-1] == 'return':
|
||||
t = t[0:-1]
|
||||
annotate_args = annotate_args[:-1]
|
||||
pass
|
||||
last = len(annotate_args) - 1
|
||||
for i in range(len(annotate_args)):
|
||||
self.write("%s: " % (t[i]))
|
||||
self.preorder(annotate_args[i])
|
||||
if i < last:
|
||||
self.write(', ')
|
||||
pass
|
||||
pass
|
||||
break
|
||||
pass
|
||||
pass
|
||||
|
||||
|
||||
if code_has_star_star_arg(code):
|
||||
if argc > 0:
|
||||
self.write(', ')
|
||||
self.write('**%s' % code.co_varnames[argc + kw_pairs])
|
||||
if code_has_star_star_arg(code):
|
||||
if argc > 0:
|
||||
self.write(', ')
|
||||
self.write('**%s' % code.co_varnames[argc + kw_pairs])
|
||||
|
||||
if isLambda:
|
||||
self.write(": ")
|
||||
else:
|
||||
self.write(')')
|
||||
if 'return' in annotate_tuple[0].attr:
|
||||
if (line_number != self.line_number) and not no_paramnames:
|
||||
if (line_number != self.line_number):
|
||||
self.write("\n" + indent)
|
||||
line_number = self.line_number
|
||||
self.write(' -> ')
|
||||
@@ -367,17 +356,21 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
|
||||
code._customize,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError as p:
|
||||
except ParserError, p:
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
return
|
||||
|
||||
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
|
||||
if self.version >= 3.0:
|
||||
kw_pairs = args_node.attr[1]
|
||||
else:
|
||||
kw_pairs = 0
|
||||
indent = self.indent
|
||||
|
||||
# build parameters
|
||||
tup = [paramnames, defparams]
|
||||
params = [build_param(ast, name, default) for
|
||||
name, default in zip_longest(paramnames, defparams, fillvalue=None)]
|
||||
name, default in map(lambda *tup:tup, *tup)]
|
||||
params.reverse() # back to correct order
|
||||
|
||||
if code_has_star_arg(code):
|
||||
@@ -411,8 +404,7 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
|
||||
if code_has_star_star_arg(code):
|
||||
if argc > 0:
|
||||
self.write(', ')
|
||||
if argc + kw_pairs > 0:
|
||||
self.write('**%s' % code.co_varnames[argc + kw_pairs])
|
||||
self.write('**%s' % code.co_varnames[argc + kw_pairs])
|
||||
|
||||
if isLambda:
|
||||
self.write(": ")
|
||||
@@ -438,34 +430,10 @@ def make_function2(self, node, isLambda, nested=1, codeNode=None):
|
||||
|
||||
|
||||
def make_function3(self, node, isLambda, nested=1, codeNode=None):
|
||||
"""Dump function definition, doc string, and function body in
|
||||
Python version 3.0 and above
|
||||
"""
|
||||
"""Dump function definition, doc string, and function body."""
|
||||
|
||||
# For Python 3.3, the evaluation stack in MAKE_FUNCTION is:
|
||||
|
||||
# * default argument objects in positional order
|
||||
# * pairs of name and default argument, with the name just below
|
||||
# the object on the stack, for keyword-only parameters
|
||||
# * parameter annotation objects
|
||||
# * a tuple listing the parameter names for the annotations
|
||||
# (only if there are ony annotation objects)
|
||||
# * the code associated with the function (at TOS1)
|
||||
# * the qualified name of the function (at TOS)
|
||||
|
||||
# For Python 3.0 .. 3.2 the evaluation stack is:
|
||||
# The function object is defined to have argc default parameters,
|
||||
# which are found below TOS.
|
||||
# * first come positional args in the order they are given in the source,
|
||||
# * next come the keyword args in the order they given in the source,
|
||||
# * finally is the code associated with the function (at TOS)
|
||||
#
|
||||
# Note: There is no qualified name at TOS
|
||||
|
||||
# MAKE_CLOSURE adds an additional closure slot
|
||||
|
||||
# Thank you, Python, for a such a well-thought out system that has
|
||||
# changed 4 or so times.
|
||||
# FIXME: call make_function3 if we are self.version >= 3.0
|
||||
# and then simplify the below.
|
||||
|
||||
def build_param(ast, name, default):
|
||||
"""build parameters:
|
||||
@@ -485,9 +453,20 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
|
||||
# MAKE_FUNCTION_... or MAKE_CLOSURE_...
|
||||
assert node[-1].type.startswith('MAKE_')
|
||||
|
||||
args_node = node[-1]
|
||||
if isinstance(args_node.attr, tuple):
|
||||
if self.version <= 3.3 and len(node) > 2 and node[-3] != 'LOAD_LAMBDA':
|
||||
# positional args are after kwargs
|
||||
defparams = node[1:args_node.attr[0]+1]
|
||||
else:
|
||||
# positional args are before kwargs
|
||||
defparams = node[:args_node.attr[0]]
|
||||
pos_args, kw_args, annotate_argc = args_node.attr
|
||||
else:
|
||||
defparams = node[:args_node.attr]
|
||||
kw_args = 0
|
||||
pass
|
||||
|
||||
# Python 3.3+ adds a qualified name at TOS (-1)
|
||||
# moving down the LOAD_LAMBDA instruction
|
||||
if 3.0 <= self.version <= 3.2:
|
||||
lambda_index = -2
|
||||
elif 3.03 <= self.version:
|
||||
@@ -495,31 +474,6 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
|
||||
else:
|
||||
lambda_index = None
|
||||
|
||||
args_node = node[-1]
|
||||
if isinstance(args_node.attr, tuple):
|
||||
pos_args, kw_args, annotate_argc = args_node.attr
|
||||
if self.version <= 3.3 and len(node) > 2 and node[lambda_index] != 'LOAD_LAMBDA':
|
||||
# args are after kwargs; kwargs are bundled as one node
|
||||
defparams = node[1:args_node.attr[0]+1]
|
||||
else:
|
||||
# args are before kwargs; kwags as bundled as one node
|
||||
defparams = node[:args_node.attr[0]]
|
||||
else:
|
||||
if self.version < 3.6:
|
||||
defparams = node[:args_node.attr]
|
||||
else:
|
||||
default, kw, annotate, closure = args_node.attr
|
||||
# FIXME: start here for Python 3.6 and above:
|
||||
defparams = []
|
||||
# if default:
|
||||
# defparams = node[-(2 + kw + annotate + closure)]
|
||||
# else:
|
||||
# defparams = []
|
||||
|
||||
kw_args = 0
|
||||
pass
|
||||
|
||||
|
||||
if lambda_index and isLambda and iscode(node[lambda_index].attr):
|
||||
assert node[lambda_index].type == 'LOAD_LAMBDA'
|
||||
code = node[lambda_index].attr
|
||||
@@ -534,7 +488,7 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
|
||||
paramnames = list(code.co_varnames[:argc])
|
||||
|
||||
# defaults are for last n parameters, thus reverse
|
||||
if not 3.0 <= self.version <= 3.1:
|
||||
if not 3.0 <= self.version <= 3.2:
|
||||
paramnames.reverse(); defparams.reverse()
|
||||
|
||||
try:
|
||||
@@ -542,33 +496,71 @@ def make_function3(self, node, isLambda, nested=1, codeNode=None):
|
||||
code._customize,
|
||||
isLambda = isLambda,
|
||||
noneInNames = ('None' in code.co_names))
|
||||
except ParserError as p:
|
||||
except ParserError, p:
|
||||
self.write(str(p))
|
||||
self.ERROR = p
|
||||
return
|
||||
|
||||
kw_pairs = args_node.attr[1] if self.version >= 3.0 else 0
|
||||
if self.version >= 3.0:
|
||||
kw_pairs = args_node.attr[1]
|
||||
else:
|
||||
kw_pairs = 0
|
||||
indent = self.indent
|
||||
|
||||
# build parameters
|
||||
params = [build_param(ast, name, d) for
|
||||
name, d in zip_longest(paramnames, defparams, fillvalue=None)]
|
||||
|
||||
if not 3.0 <= self.version <= 3.1:
|
||||
if self.version != 3.2:
|
||||
tup = [paramnames, defparams]
|
||||
params = [build_param(ast, name, default) for
|
||||
name, default in map(lambda *tup:tup, *tup)]
|
||||
params.reverse() # back to correct order
|
||||
|
||||
if code_has_star_arg(code):
|
||||
if self.version > 3.0:
|
||||
params.append('*%s' % code.co_varnames[argc + kw_pairs])
|
||||
else:
|
||||
params.append('*%s' % code.co_varnames[argc])
|
||||
argc += 1
|
||||
if code_has_star_arg(code):
|
||||
if self.version > 3.0:
|
||||
params.append('*%s' % code.co_varnames[argc + kw_pairs])
|
||||
else:
|
||||
params.append('*%s' % code.co_varnames[argc])
|
||||
argc += 1
|
||||
|
||||
# dump parameter list (with default values)
|
||||
if isLambda:
|
||||
self.write("lambda ", ", ".join(params))
|
||||
else:
|
||||
self.write("(", ", ".join(params))
|
||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||
|
||||
# dump parameter list (with default values)
|
||||
if isLambda:
|
||||
self.write("lambda ", ", ".join(params))
|
||||
else:
|
||||
self.write("(", ", ".join(params))
|
||||
# self.println(indent, '#flags:\t', int(code.co_flags))
|
||||
if isLambda:
|
||||
self.write("lambda ")
|
||||
else:
|
||||
self.write("(")
|
||||
pass
|
||||
|
||||
last_line = self.f.getvalue().split("\n")[-1]
|
||||
l = len(last_line)
|
||||
indent = ' ' * l
|
||||
line_number = self.line_number
|
||||
|
||||
if code_has_star_arg(code):
|
||||
self.write('*%s' % code.co_varnames[argc + kw_pairs])
|
||||
argc += 1
|
||||
|
||||
i = len(paramnames) - len(defparams)
|
||||
self.write(", ".join(paramnames[:i]))
|
||||
if i > 0:
|
||||
suffix = ', '
|
||||
else:
|
||||
suffix = ''
|
||||
for n in node:
|
||||
if n == 'pos_arg':
|
||||
self.write(suffix)
|
||||
self.write(paramnames[i] + '=')
|
||||
i += 1
|
||||
self.preorder(n)
|
||||
if (line_number != self.line_number):
|
||||
suffix = ",\n" + indent
|
||||
line_number = self.line_number
|
||||
else:
|
||||
suffix = ', '
|
||||
|
||||
if kw_args > 0:
|
||||
if not (4 & code.co_flags):
|
||||
|
@@ -67,8 +67,6 @@ methods implement most of the below.
|
||||
The '%' may optionally be followed by a number (C) in square brackets, which
|
||||
makes the engine walk down to N[C] before evaluating the escape code.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
import sys
|
||||
|
||||
from uncompyle6 import PYTHON3
|
||||
@@ -311,13 +309,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
if node[annotate_last] == 'annotate_tuple':
|
||||
break
|
||||
|
||||
# FIXME: the real situation is that when derived from
|
||||
# funcdef_annotate we the name has been filled in.
|
||||
# But when derived from funcdefdeco it hasn't Would like a better
|
||||
# way to distinquish.
|
||||
if self.f.getvalue()[-4:] == 'def ':
|
||||
self.write(code.attr.co_name)
|
||||
|
||||
# FIXME: handle and pass full annotate args
|
||||
make_function3_annotate(self, node, isLambda=False,
|
||||
codeNode=code, annotate_last=annotate_last)
|
||||
@@ -353,7 +344,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
'async_with_as_stmt': (
|
||||
'%|async with %c as %c:\n%+%c%-', 0, 6, 7),
|
||||
'unmap_dict': ( '{**%C}', (0, -1, ', **') ),
|
||||
# 'unmapexpr': ( '{**%c}', 0), # done by n_unmapexpr
|
||||
'unmapexpr': ( '{**%c}', 0),
|
||||
|
||||
})
|
||||
def n_async_call_function(node):
|
||||
@@ -365,43 +356,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.prec = p
|
||||
self.prune()
|
||||
self.n_async_call_function = n_async_call_function
|
||||
self.n_build_list_unpack = self.n_build_list
|
||||
|
||||
if version == 3.5:
|
||||
def n_call_function(node):
|
||||
mapping = self._get_mapping(node)
|
||||
table = mapping[0]
|
||||
key = node
|
||||
for i in mapping[1:]:
|
||||
key = key[i]
|
||||
pass
|
||||
if key.type.startswith('CALL_FUNCTION_VAR_KW'):
|
||||
# Python 3.5 changes the stack position of *args. kwargs come
|
||||
# after *args whereas in earlier Pythons, *args is at the end
|
||||
# which simpilfiies things from our perspective.
|
||||
# Python 3.6+ replaces CALL_FUNCTION_VAR_KW with CALL_FUNCTION_EX
|
||||
# We will just swap the order to make it look like earlier Python 3.
|
||||
entry = table[key.type]
|
||||
kwarg_pos = entry[2][1]
|
||||
args_pos = kwarg_pos - 1
|
||||
# Put last node[args_pos] after subsequent kwargs
|
||||
while node[kwarg_pos] == 'kwarg' and kwarg_pos < len(node):
|
||||
# swap node[args_pos] with node[kwargs_pos]
|
||||
node[kwarg_pos], node[args_pos] = node[args_pos], node[kwarg_pos]
|
||||
args_pos = kwarg_pos
|
||||
kwarg_pos += 1
|
||||
self.default(node)
|
||||
self.n_call_function = n_call_function
|
||||
|
||||
def n_funcdef(node):
|
||||
if self.version == 3.6:
|
||||
code_node = node[0][0]
|
||||
else:
|
||||
code_node = node[0][1]
|
||||
|
||||
is_code = hasattr(code_node, 'attr') and iscode(code_node.attr)
|
||||
if (is_code and
|
||||
(code_node.attr.co_flags & COMPILER_FLAG_BIT['COROUTINE'])):
|
||||
code_node = node[0][1]
|
||||
if (code_node == 'LOAD_CONST' and iscode(code_node.attr)
|
||||
and code_node.attr.co_flags & COMPILER_FLAG_BIT['COROUTINE']):
|
||||
self.engine(('\n\n%|async def %c\n', -2), node)
|
||||
else:
|
||||
self.engine(('\n\n%|def %c\n', -2), node)
|
||||
@@ -416,6 +375,8 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.f.write(', **')
|
||||
pass
|
||||
pass
|
||||
if version >= 3.6:
|
||||
self.f.write(')')
|
||||
self.prune()
|
||||
pass
|
||||
self.n_unmapexpr = n_unmapexpr
|
||||
@@ -429,12 +390,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
'fstring_single': ( "f'{%c%{conversion}}'", 0),
|
||||
'fstring_multi': ( "f'%c'", 0),
|
||||
'func_args36': ( "%c(**", 0),
|
||||
#'kwargs_only_36': ( "%c(**", 0),
|
||||
})
|
||||
TABLE_R.update({
|
||||
'CALL_FUNCTION_EX': ('%c(*%P)', 0, (1, 2, ', ', 100)),
|
||||
# Not quite right
|
||||
'CALL_FUNCTION_EX_KW': ('%c(**%C)', 0, (2,3, ',')),
|
||||
'CALL_FUNCTION_EX_KW': ('%c(**%C', 0, (2,3, ',')),
|
||||
})
|
||||
FSTRING_CONVERSION_MAP = {1: '!s', 2: '!r', 3: '!a'}
|
||||
|
||||
@@ -451,27 +411,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.default(node)
|
||||
self.n_fstring_single = n_fstring_single
|
||||
|
||||
def n_kwargs_only_36(node):
|
||||
keys = node[-1].attr
|
||||
num_kwargs = len(keys)
|
||||
values = node[:num_kwargs]
|
||||
for i, (key, value) in enumerate(zip(keys, values)):
|
||||
self.write(key + '=')
|
||||
self.preorder(value)
|
||||
if i < num_kwargs:
|
||||
self.write(',')
|
||||
self.prune()
|
||||
return
|
||||
self.n_kwargs_only_36 = n_kwargs_only_36
|
||||
|
||||
def n_return_closure(node):
|
||||
# Nothing should be output here
|
||||
self.prune()
|
||||
return
|
||||
self.n_return_closure = n_return_closure
|
||||
pass # version > 3.6
|
||||
pass # version > 3.4
|
||||
pass # version > 3.0
|
||||
return
|
||||
|
||||
f = property(lambda s: s.params['f'],
|
||||
@@ -556,8 +495,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
if self.pending_newlines:
|
||||
out = out[:-self.pending_newlines]
|
||||
if isinstance(out, str) and not PYTHON3:
|
||||
out = unicode(out, 'utf-8')
|
||||
self.f.write(out)
|
||||
|
||||
def println(self, *data):
|
||||
@@ -913,19 +850,19 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# LOAD_CONST code object ..
|
||||
# LOAD_CONST 'x0' if >= 3.3
|
||||
# MAKE_FUNCTION ..
|
||||
code_node = node[-3]
|
||||
code = node[-3]
|
||||
elif node[-2] == 'expr':
|
||||
code_node = node[-2][0]
|
||||
code = node[-2][0]
|
||||
else:
|
||||
# LOAD_CONST code object ..
|
||||
# MAKE_FUNCTION ..
|
||||
code_node = node[-2]
|
||||
code = node[-2]
|
||||
|
||||
func_name = code_node.attr.co_name
|
||||
func_name = code.attr.co_name
|
||||
self.write(func_name)
|
||||
|
||||
self.indentMore()
|
||||
self.make_function(node, isLambda=False, codeNode=code_node)
|
||||
self.make_function(node, isLambda=False, codeNode=code)
|
||||
|
||||
if len(self.param_stack) > 1:
|
||||
self.write('\n\n')
|
||||
@@ -956,7 +893,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
return
|
||||
n = node[-1]
|
||||
elif node[-1] == 'del_stmt':
|
||||
n = node[-3] if node[-2] == 'JUMP_BACK' else node[-2]
|
||||
if node[-2] == 'JUMP_BACK':
|
||||
n = node[-3]
|
||||
else:
|
||||
n = node[-2]
|
||||
|
||||
assert n == 'list_iter'
|
||||
|
||||
@@ -974,7 +914,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
list_iter = node[-1]
|
||||
else:
|
||||
expr = n[1]
|
||||
list_iter = node[-3] if node[-2] == 'JUMP_BACK' else node[-2]
|
||||
if node[-2] == 'JUMP_BACK':
|
||||
list_iter = node[-3]
|
||||
else:
|
||||
list_iter = node[-2]
|
||||
|
||||
assert expr == 'expr'
|
||||
assert list_iter == 'list_iter'
|
||||
@@ -1026,7 +969,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.write( '[ ')
|
||||
|
||||
expr = n[0]
|
||||
list_iter = node[-2] if self.is_pypy and node[-1] == 'JUMP_BACK' else node[-1]
|
||||
if self.is_pypy and node[-1] == 'JUMP_BACK':
|
||||
list_iter = node[-2]
|
||||
else:
|
||||
list_iter = node[-1]
|
||||
|
||||
assert expr == 'expr'
|
||||
assert list_iter == 'list_iter'
|
||||
@@ -1100,7 +1046,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
self.write(' for ')
|
||||
self.preorder(ast[iter_index-1])
|
||||
self.write(' in ')
|
||||
iter_expr = node[2] if node[2] == 'expr' else node[-3]
|
||||
if node[2] == 'expr':
|
||||
iter_expr = node[2]
|
||||
else:
|
||||
iter_expr = node[-3]
|
||||
assert iter_expr == 'expr'
|
||||
self.preorder(iter_expr)
|
||||
self.preorder(ast[iter_index])
|
||||
@@ -1108,7 +1057,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
def n_genexpr(self, node):
|
||||
self.write('(')
|
||||
code_index = -6 if self.version > 3.2 else -5
|
||||
if self.version > 3.2:
|
||||
code_index = -6
|
||||
else:
|
||||
code_index = -5
|
||||
self.comprehension_walk(node, iter_index=3, code_index=code_index)
|
||||
self.write(')')
|
||||
self.prune()
|
||||
@@ -1317,18 +1269,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
if self.version > 3.0:
|
||||
if node == 'classdefdeco2':
|
||||
if self.version >= 3.6:
|
||||
class_name = node[1][1].pattr
|
||||
else:
|
||||
class_name = node[1][2].pattr
|
||||
currentclass = node[1][2].pattr
|
||||
buildclass = node
|
||||
else:
|
||||
if self.version >= 3.6:
|
||||
class_name = node[0][1][0].attr.co_name
|
||||
buildclass = node[0]
|
||||
else:
|
||||
class_name = node[1][0].pattr
|
||||
buildclass = node[0]
|
||||
currentclass = node[1][0].pattr
|
||||
buildclass = node[0]
|
||||
|
||||
assert 'mkfunc' == buildclass[1]
|
||||
mkfunc = buildclass[1]
|
||||
@@ -1336,20 +1281,23 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
if 3.0 <= self.version <= 3.2:
|
||||
for n in mkfunc:
|
||||
if hasattr(n, 'attr') and iscode(n.attr):
|
||||
subclass_code = n.attr
|
||||
subclass = n.attr
|
||||
break
|
||||
elif n == 'expr':
|
||||
subclass_code = n[0].attr
|
||||
subclass = n[0].attr
|
||||
pass
|
||||
pass
|
||||
else:
|
||||
for n in mkfunc:
|
||||
if hasattr(n, 'attr') and iscode(n.attr):
|
||||
subclass_code = n.attr
|
||||
subclass = n.attr
|
||||
break
|
||||
pass
|
||||
pass
|
||||
subclass_info = node if node == 'classdefdeco2' else node[0]
|
||||
if node == 'classdefdeco2':
|
||||
subclass_info = node
|
||||
else:
|
||||
subclass_info = node[0]
|
||||
elif buildclass[1][0] == 'load_closure':
|
||||
# Python 3 with closures not functions
|
||||
load_closure = buildclass[1]
|
||||
@@ -1357,10 +1305,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# Python 3.3 classes with closures work like this.
|
||||
# Note have to test before 3.2 case because
|
||||
# index -2 also has an attr.
|
||||
subclass_code = load_closure[-3].attr
|
||||
subclass = load_closure[-3].attr
|
||||
elif hasattr(load_closure[-2], 'attr'):
|
||||
# Python 3.2 works like this
|
||||
subclass_code = load_closure[-2].attr
|
||||
subclass = load_closure[-2].attr
|
||||
else:
|
||||
raise 'Internal Error n_classdef: cannot find class body'
|
||||
if hasattr(buildclass[3], '__len__'):
|
||||
@@ -1369,21 +1317,21 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
subclass_info = buildclass[2]
|
||||
else:
|
||||
raise 'Internal Error n_classdef: cannot superclass name'
|
||||
elif self.version >= 3.6 and node == 'classdefdeco2':
|
||||
subclass_info = node
|
||||
subclass_code = buildclass[1][0].attr
|
||||
else:
|
||||
subclass_code = buildclass[1][0].attr
|
||||
subclass = buildclass[1][0].attr
|
||||
subclass_info = node[0]
|
||||
else:
|
||||
buildclass = node if (node == 'classdefdeco2') else node[0]
|
||||
if node == 'classdefdeco2':
|
||||
buildclass = node
|
||||
else:
|
||||
buildclass = node[0]
|
||||
build_list = buildclass[1][0]
|
||||
if hasattr(buildclass[-3][0], 'attr'):
|
||||
subclass_code = buildclass[-3][0].attr
|
||||
class_name = buildclass[0].pattr
|
||||
subclass = buildclass[-3][0].attr
|
||||
currentclass = buildclass[0].pattr
|
||||
elif hasattr(node[0][0], 'pattr'):
|
||||
subclass_code = buildclass[-3][1].attr
|
||||
class_name = node[0][0].pattr
|
||||
subclass = buildclass[-3][1].attr
|
||||
currentclass = node[0][0].pattr
|
||||
else:
|
||||
raise 'Internal Error n_classdef: cannot find class name'
|
||||
|
||||
@@ -1392,7 +1340,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
else:
|
||||
self.write('\n\n')
|
||||
|
||||
self.currentclass = str(class_name)
|
||||
self.currentclass = str(currentclass)
|
||||
self.write(self.indent, 'class ', self.currentclass)
|
||||
|
||||
if self.version > 3.0:
|
||||
@@ -1403,7 +1351,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
# class body
|
||||
self.indentMore()
|
||||
self.build_class(subclass_code)
|
||||
self.build_class(subclass)
|
||||
self.indentLess()
|
||||
|
||||
self.currentclass = cclass
|
||||
@@ -1539,21 +1487,10 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
values = node[:-2]
|
||||
# FIXME: Line numbers?
|
||||
for key, value in zip(keys, values):
|
||||
self.write(sep)
|
||||
self.write(repr(key))
|
||||
line_number = self.line_number
|
||||
self.write(':')
|
||||
self.write(self.traverse(value[0]))
|
||||
sep = ","
|
||||
if line_number != self.line_number:
|
||||
sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
|
||||
line_number = self.line_number
|
||||
else:
|
||||
sep += " "
|
||||
pass
|
||||
pass
|
||||
if sep.startswith(",\n"):
|
||||
self.write(sep[1:])
|
||||
self.write(',')
|
||||
pass
|
||||
pass
|
||||
else:
|
||||
@@ -1607,9 +1544,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
if line_number != self.line_number:
|
||||
sep += "\n" + self.indent + " "
|
||||
line_number = self.line_number
|
||||
pass
|
||||
pass
|
||||
pass
|
||||
if sep.startswith(",\n"):
|
||||
self.write(sep[1:])
|
||||
self.write('}')
|
||||
@@ -1632,13 +1566,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# will assume that if the text ends in *.
|
||||
last_was_star = self.f.getvalue().endswith('*')
|
||||
|
||||
if lastnodetype.endswith('UNPACK'):
|
||||
# FIXME: need to handle range of BUILD_LIST_UNPACK
|
||||
have_star = True
|
||||
# endchar = ''
|
||||
else:
|
||||
have_star = False
|
||||
|
||||
if lastnodetype.startswith('BUILD_LIST'):
|
||||
self.write('['); endchar = ']'
|
||||
elif lastnodetype.startswith('BUILD_TUPLE'):
|
||||
@@ -1650,7 +1577,11 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
elif lastnodetype.startswith('ROT_TWO'):
|
||||
self.write('('); endchar = ')'
|
||||
else:
|
||||
raise TypeError('Internal Error: n_build_list expects list, tuple, set, or unpack')
|
||||
raise 'Internal Error: n_build_list expects list, tuple, set, or unpack'
|
||||
have_star = False
|
||||
if lastnodetype.endswith('UNPACK'):
|
||||
# FIXME: need to handle range of BUILD_LIST_UNPACK
|
||||
have_star = True
|
||||
|
||||
flat_elems = []
|
||||
for elem in node:
|
||||
@@ -1668,7 +1599,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
sep = ''
|
||||
|
||||
for elem in flat_elems:
|
||||
if elem in ('ROT_THREE', 'EXTENDED_ARG'):
|
||||
if elem == 'ROT_THREE':
|
||||
continue
|
||||
assert elem == 'expr'
|
||||
line_number = self.line_number
|
||||
@@ -1757,8 +1688,12 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
typ = m.group('type') or '{'
|
||||
node = startnode
|
||||
if m.group('child'):
|
||||
node = node[int(m.group('child'))]
|
||||
try:
|
||||
if m.group('child'):
|
||||
node = node[int(m.group('child'))]
|
||||
except:
|
||||
print(node.__dict__)
|
||||
raise
|
||||
|
||||
if typ == '%': self.write('%')
|
||||
elif typ == '+':
|
||||
@@ -1833,6 +1768,7 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
try:
|
||||
self.write(eval(expr, d, d))
|
||||
except:
|
||||
print(node)
|
||||
raise
|
||||
m = escape.search(fmt, i)
|
||||
self.write(fmt[i:])
|
||||
@@ -1863,8 +1799,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
if k.startswith('CALL_METHOD'):
|
||||
# This happens in PyPy only
|
||||
TABLE_R[k] = ('%c(%P)', 0, (1, -1, ', ', 100))
|
||||
elif self.version >= 3.6 and k.startswith('CALL_FUNCTION_KW'):
|
||||
TABLE_R[k] = ('%c(%P)', 0, (1, -1, ', ', 100))
|
||||
elif op == 'CALL_FUNCTION':
|
||||
TABLE_R[k] = ('%c(%P)', 0, (1, -1, ', ', 100))
|
||||
elif op in ('CALL_FUNCTION_VAR',
|
||||
@@ -1881,9 +1815,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
if self.version == 3.5:
|
||||
if str == '%c(%C, ':
|
||||
str = '%c(*%C, %c)'
|
||||
elif str == '%c(%C':
|
||||
str = '%c(*%C)'
|
||||
# p2 = (1, -1, 100)
|
||||
else:
|
||||
str += '*%c)'
|
||||
entry = (str, 0, p2, -2)
|
||||
@@ -2069,7 +2000,9 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
tokens.append(Token('LAMBDA_MARKER'))
|
||||
try:
|
||||
ast = python_parser.parse(self.p, tokens, customize)
|
||||
except (python_parser.ParserError, AssertionError) as e:
|
||||
except python_parser.ParserError, e:
|
||||
raise ParserError(e, tokens)
|
||||
except AssertionError, e:
|
||||
raise ParserError(e, tokens)
|
||||
maybe_show_ast(self.showast, ast)
|
||||
return ast
|
||||
@@ -2096,7 +2029,9 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
# Build AST from disassembly.
|
||||
try:
|
||||
ast = python_parser.parse(self.p, tokens, customize)
|
||||
except (python_parser.ParserError, AssertionError) as e:
|
||||
except python_parser.ParserError, e:
|
||||
raise ParserError(e, tokens)
|
||||
except AssertionError, e:
|
||||
raise ParserError(e, tokens)
|
||||
|
||||
maybe_show_ast(self.showast, ast)
|
||||
@@ -2174,10 +2109,10 @@ def deparse_code(version, co, out=sys.stdout, showasm=None, showast=False,
|
||||
if __name__ == '__main__':
|
||||
def deparse_test(co):
|
||||
"This is a docstring"
|
||||
sys_version = sys.version_info.major + (sys.version_info.minor / 10.0)
|
||||
sys_version = float(sys.version[0:3])
|
||||
deparsed = deparse_code(sys_version, co, showasm='after', showast=True)
|
||||
# deparsed = deparse_code(sys_version, co, showasm=None, showast=False,
|
||||
# showgrammar=True)
|
||||
print(deparsed.text)
|
||||
return
|
||||
deparse_test(deparse_test.__code__)
|
||||
deparse_test(deparse_test.func_code)
|
||||
|
@@ -12,7 +12,10 @@ def maybe_show_asm(showasm, tokens):
|
||||
:param tokens: The asm tokens to show.
|
||||
"""
|
||||
if showasm:
|
||||
stream = showasm if hasattr(showasm, 'write') else sys.stdout
|
||||
if hasattr(showasm, 'write'):
|
||||
stream = showasm
|
||||
else:
|
||||
stream = sys.stdout
|
||||
for t in tokens:
|
||||
stream.write(str(t))
|
||||
stream.write('\n')
|
||||
@@ -29,7 +32,10 @@ def maybe_show_ast(showast, ast):
|
||||
:param ast: The ast to show.
|
||||
"""
|
||||
if showast:
|
||||
stream = showast if hasattr(showast, 'write') else sys.stdout
|
||||
if hasattr(showast, 'write'):
|
||||
stream = showast
|
||||
else:
|
||||
stream = sys.stdout
|
||||
stream.write(str(ast))
|
||||
stream.write('\n')
|
||||
|
||||
@@ -48,7 +54,10 @@ def maybe_show_ast_param_default(showast, name, default):
|
||||
:param default: The function parameter default.
|
||||
"""
|
||||
if showast:
|
||||
stream = showast if hasattr(showast, 'write') else sys.stdout
|
||||
if hasattr(showast, 'write'):
|
||||
stream = showast
|
||||
else:
|
||||
stream = sys.stdout
|
||||
stream.write('\n')
|
||||
stream.write('--' + name)
|
||||
stream.write('\n')
|
||||
|
@@ -6,8 +6,6 @@
|
||||
byte-code verification
|
||||
"""
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
import dis, operator
|
||||
|
||||
import uncompyle6
|
||||
@@ -365,8 +363,10 @@ def cmp_code_objects(version, is_pypy, code_obj1, code_obj2,
|
||||
elif member == 'co_flags':
|
||||
flags1 = code_obj1.co_flags
|
||||
flags2 = code_obj2.co_flags
|
||||
if is_pypy:
|
||||
if is_pypy or version == 2.4:
|
||||
# For PYPY for now we don't care about PYPY_SOURCE_IS_UTF8:
|
||||
# Python 2.4 also sets this flag and I am not sure
|
||||
# where or why
|
||||
flags2 &= ~0x0100 # PYPY_SOURCE_IS_UTF8
|
||||
# We also don't care about COROUTINE or GENERATOR for now
|
||||
flags1 &= ~0x000000a0
|
||||
@@ -375,6 +375,8 @@ def cmp_code_objects(version, is_pypy, code_obj1, code_obj2,
|
||||
raise CmpErrorMember(name, 'co_flags',
|
||||
pretty_flags(flags1),
|
||||
pretty_flags(flags2))
|
||||
|
||||
|
||||
else:
|
||||
# all other members must be equal
|
||||
if getattr(code_obj1, member) != getattr(code_obj2, member):
|
||||
@@ -418,8 +420,10 @@ def compare_code_with_srcfile(pyc_filename, src_filename, weak_verify=False):
|
||||
return msg
|
||||
try:
|
||||
code_obj2 = load_file(src_filename)
|
||||
except SyntaxError as e:
|
||||
except SyntaxError, e:
|
||||
# src_filename can be the first of a group sometimes
|
||||
if version == 2.4:
|
||||
print(pyc_filename)
|
||||
return str(e).replace(src_filename, pyc_filename)
|
||||
cmp_code_objects(version, is_pypy, code_obj1, code_obj2, ignore_code=weak_verify)
|
||||
return None
|
||||
|
@@ -1,3 +1,3 @@
|
||||
# This file is suitable for sourcing inside bash as
|
||||
# well as importing into Python
|
||||
VERSION='2.11.4'
|
||||
VERSION='2.9.11'
|
||||
|
Reference in New Issue
Block a user