{ "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 :: 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", "Topic :: Utilities" ], "description": "DESCRIPTION: ast2src - reverse compile ast tree back to legal python source code\n\n REQUIRES: LINUX OS AND PYTHON3.1\n\n QUICK TEST: $ python3.1 setup.py build dev --quicktest\n\n SUMMARY:\n ast2src is a pure python module.\n ast2src is a python ast tree hack.\n \nRECENT CHANGELOG:\n 20100121 - added ast2src\n 20091231 - added <<<< and >>>> sugar\n 20091224 - added pseudomethod interactive console - revamped pseudomethod import hook\n 20091224 - modularized package - fix install issues - added sdist check\n 20091209 - improved documentation\n 20091205 - moved source code to c++\n 20091116 - package integrated\n\nDEMO USAGE:\n\n PseudoSugar - adding hook to sys.meta_path\n>>> from ast2src import *\n\n>>> ## let's use ast2src's source code as example\n>>> import ast2src, ast\n>>> source_code1 = open(ast2src.__file__).read()\n>>> print( '\\n' + re.sub('\\n+', '\\n', source_code1[:1024]) + '...' )\n\n## import ast2src; reload(ast2src); from ast2src import *\nimport os, sys\nif os.name != 'posix': sys.stderr.write('\\nast2src requires linux os\\n\\n'); exit()\nif sys.version_info[:2] != (3, 1): sys.stderr.write('\\nast2src requires python3.1\\n\\n'); exit()\nif 1: ###### INIT\n import ast2src as _MODULE\n if '_SETUP' not in globals(): _SETUP = sys.modules.get('ast2src.setup', None)\n def closure(*args, **kwds): return lambda fnc: fnc(*args, **kwds)\n def identity(aa): return aa\n def _import(ss, globals = globals()):\n for aa in ss.split(' '): globals[aa] = __import__(aa)\n return identity\n class Namespace(object):\n def __init__(self, **kwds): vars(self).update(kwds)\n @_import('ast builtins collections re ' #### pseudosugar compiler\n 'imp importlib importlib.abc importlib.util ' #### import hook\n 'locale') ## PYTHON BUG\n class PseudoSugar(ast.NodeVisitor, importlib.abc.Finder, importlib.abc.PyLoader):\n ## convenience function\n @staticmethod\n def exec(ss, globa...\n\n>>> ## compile source to ast\n>>> ast_tree1 = compile(source_code1, '', 'exec', ast.PyCF_ONLY_AST)\n>>> print( Ast2Src.debugnode(ast_tree1)[:1024], '...' )\n\tbody [<_ast.Import object at 0x9c6ea2c>, <_ast.If object at 0x9c6e7cc>, <_ast.If object at 0x9ab2b0c>, <_ast.If object at 0x9ab2fec>]\n \tcol_offset 0\tlineno 2\tnames [<_ast.alias object at 0x9c6e2ec>, <_ast.alias object at 0x9c6e9ac>]\n \tasname None\tname 'os'\n \tasname None\tname 'sys'\n \tbody [<_ast.Expr object at 0x9ccc92c>, <_ast.Expr object at 0x9ab2acc>]\tcol_offset 0\tlineno 3\torelse []\ttest <_ast.Compare object at 0x9c6eccc>\n \tcol_offset 3\tcomparators [<_ast.Str object at 0x9ccc9ec>]\tleft <_ast.Attribute object at 0x9c948cc>\tlineno 3\tops [<_ast.NotEq object at 0xb7b3682c>]\n \tattr 'name'\tcol_offset 3\tctx <_ast.Load object at 0xb7bb2ccc>\tlineno 3\tvalue <_ast.Name object at 0x9ccc46c>\n \tcol_offset 3\tctx <_ast.Load object at 0xb7bb2ccc>\tid 'os'\tlineno 3\n \t\n \t\n \t\n >> ## reverse compile ast back to source\n>>> source_code2 = Ast2Src.unparse(ast_tree1)\n>>> print( '\\n' + re.sub('\\n+', '\\n', source_code1[:1024]) + '...' )\n\n## import ast2src; reload(ast2src); from ast2src import *\nimport os, sys\nif os.name != 'posix': sys.stderr.write('\\nast2src requires linux os\\n\\n'); exit()\nif sys.version_info[:2] != (3, 1): sys.stderr.write('\\nast2src requires python3.1\\n\\n'); exit()\nif 1: ###### INIT\n import ast2src as _MODULE\n if '_SETUP' not in globals(): _SETUP = sys.modules.get('ast2src.setup', None)\n def closure(*args, **kwds): return lambda fnc: fnc(*args, **kwds)\n def identity(aa): return aa\n def _import(ss, globals = globals()):\n for aa in ss.split(' '): globals[aa] = __import__(aa)\n return identity\n class Namespace(object):\n def __init__(self, **kwds): vars(self).update(kwds)\n @_import('ast builtins collections re ' #### pseudosugar compiler\n 'imp importlib importlib.abc importlib.util ' #### import hook\n 'locale') ## PYTHON BUG\n class PseudoSugar(ast.NodeVisitor, importlib.abc.Finder, importlib.abc.PyLoader):\n ## convenience function\n @staticmethod\n def exec(ss, globa...\n\n>>> ## recompile reverse-compiled source\n>>> ast_tree2 = compile(source_code2, '', 'exec', ast.PyCF_ONLY_AST)\n>>> print( Ast2Src.debugnode(ast_tree2)[:1024], '...' )\n\tbody [<_ast.Import object at 0x9ad7ecc>, <_ast.If object at 0x9b3316c>, <_ast.If object at 0x9b3abcc>, <_ast.If object at 0x9b3ae6c>]\n \tcol_offset 0\tlineno 2\tnames [<_ast.alias object at 0x9c2966c>, <_ast.alias object at 0x9c022ec>]\n \tasname None\tname 'os'\n \tasname None\tname 'sys'\n \tbody [<_ast.Expr object at 0x9b3aaac>, <_ast.Expr object at 0x9b3ab6c>]\tcol_offset 0\tlineno 3\torelse []\ttest <_ast.Compare object at 0x9b332ac>\n \tcol_offset 4\tcomparators [<_ast.Str object at 0x9b3a80c>]\tleft <_ast.Attribute object at 0x9b3490c>\tlineno 3\tops [<_ast.NotEq object at 0xb7b3682c>]\n \tattr 'name'\tcol_offset 4\tctx <_ast.Load object at 0xb7bb2ccc>\tlineno 3\tvalue <_ast.Name object at 0x9b3a10c>\n \tcol_offset 4\tctx <_ast.Load object at 0xb7bb2ccc>\tid 'os'\tlineno 3\n \t\n \t\n \t\n