Skip to main content

Byte-code and ast programming tools

Project description

Meta

A Pure Python module containing a framework to manipulate and analyze python ast’s and bytecode.

Example

This shows how to take python source to a code object and back again from within python:

import meta, ast
source = '''
a = 1
b = 2
c = (a ** b)
'''

mod = ast.parse(source, '<nofile>', 'exec')
code = compile(mod, '<nofile>', 'exec')

mod2 = meta.decompile(code)
source2 = meta.dump_python_source(mod2)

assert source == source2

This shows the depyc script. The script compiles itself, and then the compiled script extracts itself:

DEPYC_FILE=`python -c"import meta.scripts.depyc; print meta.scripts.depyc.__file__"`
depyc $DEPYC_FILE --pyc > depycX.pyc
python -m depycX depycX.pyc --python > depycX.py
echo depycX.py

Notes

  • Meta is python3 compliant (mostly)

Bugs

  • The decompliler does not yet support complex list/set/dict - comprehensions

Testing

python -m unittest discover meta

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

meta-0.2.0.tar.gz (38.2 kB view details)

Uploaded Source

File details

Details for the file meta-0.2.0.tar.gz.

File metadata

  • Download URL: meta-0.2.0.tar.gz
  • Upload date:
  • Size: 38.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for meta-0.2.0.tar.gz
Algorithm Hash digest
SHA256 c5cef55dd1d2f9ad18bbdcc0e5f0d46b387f592807f3434eaf1de1e0fec8b0cf
MD5 ca5905cc4697d089f20b94f639fa00b9
BLAKE2b-256 12ac6e75cfcffdc9257fc7693dd8ea9ff8345565d60d36b2f6f0413abe502c9f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page