Reconstructing a module from a Python bytecode cache file
So, sometimes you lose your configuration files and they happen to have a .pyc version that still exists.
>>> import marshal >>> f = open("imgapi/conf.pyc") >>> f.seek(8) >>> o = marshal.load(f) >>> o <code object <module> at 0x7f84ff7f8c60, file ".../imgapi/conf.py", line 1> >>> dis.dis(o) 1 0 LOAD_CONST 0 (-1) 3 LOAD_CONST 1 (('*',)) 6 IMPORT_NAME 0 (imgapi.conf_defaults) 9 IMPORT_STAR 2 10 LOAD_CONST 2 ('gevent') 13 STORE_NAME 1 (url_fetcher) 3 16 LOAD_CONST 6 (('.yo-toad.se:8000', '.yo-dev.se')) 19 STORE_NAME 2 (rewrite_host) 22 LOAD_CONST 5 (None) 25 RETURN_VALUE >>>
And from this, one can see what this (rather short) configuration file used to say:
from imgapi.conf_defaults import * url_fetcher = "gevent" rewrite_host = (".yo-toad.se:8000", ".yo-dev.se")
Now for some delicious food.
Comments
Posted by: Marius Gedminas ยง
There's also a tool that does that for you: decompyle.
