{ "info": { "author": "kai zhu", "author_email": "kaizhu256@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 3 - Alpha", "Intended Audience :: Developers", "Intended Audience :: End Users/Desktop", "Intended Audience :: Science/Research", "License :: OSI Approved :: GNU General Public License (GPL)", "Natural Language :: English", "Operating System :: POSIX", "Operating System :: POSIX :: Linux", "Programming Language :: C", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.1", "Topic :: Multimedia", "Topic :: Multimedia :: Graphics", "Topic :: Scientific/Engineering", "Topic :: Scientific/Engineering :: Mathematics", "Topic :: Scientific/Engineering :: Visualization", "Topic :: Software Development", "Topic :: Software Development :: Code Generators", "Topic :: Software Development :: Libraries", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "codetree - directly hack compiled python code object\n\n REQUIRES PYTHON3.1\n\n QUICK TEST: $ python3.1 setup.py build dev --quicktest\n\n DESCRIPTION: codetree - directly hack compiled python code object\n\nSUMMARY:\ncodetree converts compiled python code objects into trees, which can be edited and recompiled\n\nRECENT CHANGELOG:\n20091224 - modularized package - fix install issues - added sdist check\n20091205 - moved source code to c++\n20091116 - package integrated\n\n DEMO USAGE:\n\n>>> from codetree import *\n>>> ## source code\n>>> src = 'def foo(aa):\\n def closure():\\n nonlocal aa\\n aa += \"!\"\\n print(aa)\\n return closure()\\nfoo(\"hello\")'; print( src )\ndef foo(aa):\n def closure():\n nonlocal aa\n aa += \"!\"\n print(aa)\n return closure()\nfoo(\"hello\")\n\n>>> ## compile source code\n>>> codeobj = compile(src, '', 'exec')\n>>> exec( codeobj )\nhello!\n\n>>> ## convert code object into editable codetree\n>>> tree = codetree(codeobj)\n>>> for item in vars(tree).items(): print( item )\n('co_firstlineno', 1)\n('co_code', b'd\\x00\\x00\\x84\\x00\\x00Z\\x00\\x00e\\x00\\x00d\\x01\\x00\\x83\\x01\\x00\\x01d\\x02\\x00S')\n('co_freevars', [])\n('co_name', '')\n('co_filename', '')\n('co_lnotab', b'\\t\\x06')\n('co_flags', 64)\n('co_nlocals', 0)\n('co_stacksize', 2)\n('co_argcount', 0)\n('co_cellvars', [])\n('co_kwonlyargcount', 0)\n('co_varnames', [])\n('co_names', ['foo'])\n\n>>> ## edit / compile / exec codetree\n>>> element, depth, index, subtree = tree.find('hello')\n>>> subtree[index] = 'goodbye'\n>>> exec( tree.compile() )\ngoodbye!\n\n>>> ## codetree structure\n>>> print( tree )\ncodetree(\n co_argcount 0\n co_kwonlyargcount 0\n co_nlocals 0\n co_stacksize 2\n co_flags 64\n co_code b'd\\x00\\x00\\x84\\x00\\x00Z\\x00\\x00e\\x00\\x00d\\x01\\x00\\x83\\x01\\x00\\x01d\\x02\\x00S'\n co_consts \n codetree(\n co_argcount 1\n co_kwonlyargcount 0\n co_nlocals 2\n co_stacksize 2\n co_flags 3\n co_code b'\\x87\\x00\\x00f\\x01\\x00d\\x01\\x00\\x86\\x00\\x00}\\x01\\x00|\\x01\\x00\\x83\\x00\\x00S'\n co_consts \n None\n codetree(\n co_argcount 0\n co_kwonlyargcount 0\n co_nlocals 0\n co_stacksize 2\n co_flags 19\n co_code b'\\x88\\x00\\x00d\\x01\\x007\\x89\\x00\\x00t\\x00\\x00\\x88\\x00\\x00\\x83\\x01\\x00\\x01d\\x00\\x00S'\n co_consts \n None\n !\n co_names ['print']\n co_varnames []\n co_filename ''\n co_name 'closure'\n co_firstlineno 2\n co_lnotab b'\\x00\\x02\\n\\x01'\n co_freevars ['aa']\n co_cellvars [])\n co_names []\n co_varnames ['aa', 'closure']\n co_filename ''\n co_name 'foo'\n co_firstlineno 1\n co_lnotab b'\\x00\\x01\\x0f\\x04'\n co_freevars []\n co_cellvars ['aa'])\n goodbye\n None\n co_names ['foo']\n co_varnames []\n co_filename ''\n co_name ''\n co_firstlineno 1\n co_lnotab b'\\t\\x06'\n co_freevars []\n co_cellvars [])\n\n>>> ## disassemble codetree\n>>> print( tree.dis() )\n 1 0 LOAD_CONST 0 () \n 3 MAKE_FUNCTION 0 \n 6 STORE_NAME 0 (foo) \n\n 7 9 LOAD_NAME 0 (foo) \n 12 LOAD_CONST 1 ('goodbye') \n 15 CALL_FUNCTION 1 \n 18 POP_TOP \n 19 LOAD_CONST 2 (None) \n 22 RETURN_VALUE \n\n 2 0 LOAD_CLOSURE 0 (aa) \n 3 BUILD_TUPLE 1 \n 6 LOAD_CONST 1 () \n 9 MAKE_CLOSURE 0 \n 12 STORE_FAST 1 (closure) \n \n 6 15 LOAD_FAST 1 (closure) \n 18 CALL_FUNCTION 0 \n 21 RETURN_VALUE \n \n 4 0 LOAD_DEREF 0 (aa) \n 3 LOAD_CONST 1 ('!') \n 6 INPLACE_ADD \n 7 STORE_DEREF 0 (aa) \n \n 5 10 LOAD_GLOBAL 0 (print) \n 13 LOAD_DEREF 0 (aa) \n 16 CALL_FUNCTION 1 \n 19 POP_TOP \n 20 LOAD_CONST 0 (None) \n 23 RETURN_VALUE", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://pypi.python.org/pypi/codetree", "keywords": null, "license": "gpl", "maintainer": null, "maintainer_email": null, "name": "codetree", "package_url": "https://pypi.org/project/codetree/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/codetree/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://pypi.python.org/pypi/codetree" }, "release_url": "https://pypi.org/project/codetree/2009.12.24.py3k.cpp/", "requires_dist": null, "requires_python": null, "summary": "codetree - directly hack compiled python code object", "version": "2009.12.24.py3k.cpp" }, "last_serial": 787611, "releases": { "2009.12.06.py3k.cpp.static": [ { "comment_text": "", "digests": { "md5": "67c644dc52063f5fd051219bd312e4d9", "sha256": "26876125b17957123925e9adc8b0268acec7b0ad67953b361eb5836f8c9570c2" }, "downloads": -1, "filename": "codetree-2009.12.06.py3k.cpp.static.tar.gz", "has_sig": false, "md5_digest": "67c644dc52063f5fd051219bd312e4d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 83069, "upload_time": "2009-12-09T13:53:31", "url": "https://files.pythonhosted.org/packages/14/1c/fd8155eefe420083250ed7173fdd64b7828dd4ac35726b6b939305400df2/codetree-2009.12.06.py3k.cpp.static.tar.gz" } ], "2009.12.24.py3k.cpp": [ { "comment_text": "", "digests": { "md5": "a5d3a42814505785a92810c243957a2f", "sha256": "a09876da783fa56f4705830672700fb4439d778add84171dcf3693f6861a94fc" }, "downloads": -1, "filename": "codetree-2009.12.24.py3k.cpp.tar.gz", "has_sig": false, "md5_digest": "a5d3a42814505785a92810c243957a2f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 80224, "upload_time": "2009-12-29T16:49:05", "url": "https://files.pythonhosted.org/packages/e0/32/c66578759a018edde64e5f67e813daad117cc3128369fa73a78004361226/codetree-2009.12.24.py3k.cpp.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "a5d3a42814505785a92810c243957a2f", "sha256": "a09876da783fa56f4705830672700fb4439d778add84171dcf3693f6861a94fc" }, "downloads": -1, "filename": "codetree-2009.12.24.py3k.cpp.tar.gz", "has_sig": false, "md5_digest": "a5d3a42814505785a92810c243957a2f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 80224, "upload_time": "2009-12-29T16:49:05", "url": "https://files.pythonhosted.org/packages/e0/32/c66578759a018edde64e5f67e813daad117cc3128369fa73a78004361226/codetree-2009.12.24.py3k.cpp.tar.gz" } ] }