{ "info": { "author": "David Cortesi, Noam Yorav-Raphael", "author_email": "davecortesi@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 4 - Beta" ], "description": "byteplay lets you convert Python code objects into equivalent objects which are easy to play with, and lets you convert those objects back into Python code objects. It's useful for applying transformations on Python functions, and is also useful in learning Python byte code intricacies. This version works with Python 3.4 and 3.5.\r\n\r\nFor the full documentation see the \"about\" file located at\r\nhttps://github.com/tallforasmurf/byteplay/blob/master/about.md\r\n\r\nAbout byteplay\r\n--------------------\r\n\r\nbyteplay3 is a module which lets you easily play with Python bytecode.\r\nThe basic idea is simple: define a new type named Code which is equivalent\r\nto Python code objects, but Code objects, unlike Python code objects,\r\nare easy to play with. Any Python code object can be converted to\r\na Code object, and vice-versa, without losing any important information.\r\nWithin a Code object, the bytecode instructions are represented in a\r\nway that is easy to examine and modify.\r\n\r\nCompatibility\r\n----------------\r\n\r\nThis module, byteplay3, is based on the original by Noam Raph, which\r\nis still available from pypi. If you have code that used byteplay under\r\nPython 2, you can migrate to Python 3 just by changing your import line\r\nto read \"from byteplay3 import *\". For minor incompatibilities, see the\r\n\"about\" file linked above. Of course you will find more than minor\r\nincompatibilities in Python 3's bytecode, which is considerably changed.\r\n\r\nA Quick Example\r\n---------------\r\n\r\nStart with a silly function, convert its code to a Code object and display it::\r\n\r\n\t>>> def f(a, b):\r\n\t... print(a, b)\r\n\t...\r\n\t>>> f(3, 5)\r\n\t\t3 5\r\n\t>>> from byteplay3 import *\r\n\t>>> # convert the code object of function f to a Code object\r\n\t>>> c = Code.from_code(f.__code__)\r\n\t>>> c\r\n\t\t\r\n\t>>> # display the bytecode tuples in the Code object\r\n\t>>> print( c.code )\r\n\t2 1 LOAD_GLOBAL print\r\n\t\t\t 2 LOAD_FAST a\r\n\t\t\t 3 LOAD_FAST b\r\n\t\t\t 4 CALL_FUNCTION 2\r\n\t\t\t 5 POP_TOP \r\n\t\t\t 6 LOAD_CONST None\r\n\t\t\t 7 RETURN_VALUE \r\n\t\t\t \r\nOk, now let's play! Say we want to change the function so it prints its\r\narguments in reverse order. To do this, we will insert a ROT_TWO opcode\r\nafter the two arguments were loaded to the stack. (That is, after\r\nLOAD_FAST b and before CALL_FUNCTION 2.)::\r\n\r\n >>> c.code[4:4] = [(ROT_TWO,None)]\r\n \r\nThen replace the code object in function f with a new one::\r\n\r\n\t>>> f.__code__ = c.to_code()\r\n\t>>> f(3,5)\r\n\t\t5 3", "description_content_type": null, "docs_url": null, "download_url": "https://github.com/tallforasmurf/byteplay/archive/master.zip", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/tallforasmurf/byteplay", "keywords": "", "license": "LGPL", "maintainer": "", "maintainer_email": "", "name": "byteplay3", "package_url": "https://pypi.org/project/byteplay3/", "platform": "Any supporting Python 3.4+ with the array, itertools, and opcode standard modules", "project_url": "https://pypi.org/project/byteplay3/", "project_urls": { "Download": "https://github.com/tallforasmurf/byteplay/archive/master.zip", "Homepage": "https://github.com/tallforasmurf/byteplay" }, "release_url": "https://pypi.org/project/byteplay3/3.5.0/", "requires_dist": null, "requires_python": null, "summary": "bytecode manipulation (byteplay) library for Python 3", "version": "3.5.0" }, "last_serial": 1940829, "releases": { "3.5.0": [ { "comment_text": "", "digests": { "md5": "048c2612d5038d4c8d94fe5fd2e0eff9", "sha256": "d2b40e641a96ac484d969a9a7c6ff8dbb1f2b42ac8db35adb68ea78559173ba5" }, "downloads": -1, "filename": "byteplay3-3.5.0.tar.gz", "has_sig": false, "md5_digest": "048c2612d5038d4c8d94fe5fd2e0eff9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23368, "upload_time": "2016-02-05T00:23:27", "url": "https://files.pythonhosted.org/packages/b8/34/5b31eed1b05c4599d59870676de50060de382e7c161ccfbf767a61e0e8d0/byteplay3-3.5.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "048c2612d5038d4c8d94fe5fd2e0eff9", "sha256": "d2b40e641a96ac484d969a9a7c6ff8dbb1f2b42ac8db35adb68ea78559173ba5" }, "downloads": -1, "filename": "byteplay3-3.5.0.tar.gz", "has_sig": false, "md5_digest": "048c2612d5038d4c8d94fe5fd2e0eff9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 23368, "upload_time": "2016-02-05T00:23:27", "url": "https://files.pythonhosted.org/packages/b8/34/5b31eed1b05c4599d59870676de50060de382e7c161ccfbf767a61e0e8d0/byteplay3-3.5.0.tar.gz" } ] }