Python cross-version byte-code disassembler and marshal routines
Cross-Python bytecode Disassembler, Bytecode, and Magic Number Manipulation package
The Python dis module allows you to disassemble bytecode from the same version of Python that you are running on. But what about bytecode from different versions?
That’s what this package is for. It can “marshal load” Python bytecodes from different versions of Python. The command-line routine pydisasm will show disassembly output using Python 3.6 disassembly conventions.
Also, if you need to modify and write bytecode, the routines here can be of help. There are routines to pack and unpack the read-only tuples in Python’s Code type. For interoperability between Python 2 and 3 we provide our own versions of the Code type, and we provide routines to reduce the tedium in writing a bytecode file.
This package also has an extensive knowledge of Python bytecode magic numbers, including Pypy and others, and how to translate from sys.sys_info major, minor, and release numbers to the corresponding magic value.
So If you want to write a cross-version assembler, or a bytecode-level optimizer this package may also be useful. In addition to the kinds of instruction categorization that dis offers, we have additional categories for things that would be useful in such a bytecode optimizer.
The programs here accept bytecodes from Python version 1.3 to 3.7 or so. The code requires Python 2.4 or later and has been tested on Python running lots of Python versions.
To install versions for Python before 2.6 install via eggs or use the python-2.4 branch of git in github.
This uses setup.py, so it follows the standard Python routine:
pip install -r requirements.txt pip install -r requirements-dev.txt python setup.py install # may need sudo # or if you have pyenv: python setup.py develop
A GNU makefile is also provided so
make install (possibly as root or
sudo) will do the steps above.
A GNU makefile has been added to smooth over setting running the right command, and running tests from fastest to slowest.
If you have remake installed, you can see the list of all tasks
including tests via
for usage help.
As a drop-in replacement for dis
xdis also provides some support as a drop in replacement for the the Python library dis module. This is may be desirable when you want to use the improved API from Python 3.4 or later from an earlier Python version.
>>> # works in Python 2 and 3 >>> import xdis.std as dis >>> [x.opname for x in dis.Bytecode('a = 10')] ['LOAD_CONST', 'STORE_NAME', 'LOAD_CONST', 'RETURN_VALUE']
There may some small differences in output produced for formatted disassembly or how we show compiler flags. We expect you’ll find the xdis output more informative though.
Release history Release notifications
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size & hash||File type||Python version||Upload date|
|xdis-4.0.3-py26-none-any.whl (90.6 kB) View hashes||Wheel||py26|
|xdis-4.0.3-py27-none-any.whl (94.8 kB) View hashes||Wheel||py27|
|xdis-4.0.3-py33-none-any.whl (90.6 kB) View hashes||Wheel||py33|
|xdis-4.0.3-py34-none-any.whl (94.9 kB) View hashes||Wheel||py34|
|xdis-4.0.3-py35-none-any.whl (94.8 kB) View hashes||Wheel||py35|
|xdis-4.0.3-py36-none-any.whl (94.8 kB) View hashes||Wheel||py36|
|xdis-4.0.3-py37-none-any.whl (94.8 kB) View hashes||Wheel||py37|
|xdis-4.0.3.tar.gz (185.9 kB) View hashes||Source||None|