Metadata-Version: 1.0
Name: ast2src
Version: 2010.01.21.ast2src
Summary: DESCRIPTION: ast2src - convert compiled ast tree back to legal python source code
Home-page: http://pypi.python.org/pypi/ast2src
Author: kai zhu
Author-email: kaizhu256@gmail.com
License: gpl
Description: DESCRIPTION: ast2src - convert compiled ast tree back to legal python source code
        
        REQUIRES: LINUX OS AND PYTHON3.1
        
        QUICK TEST: $ python3.1 setup.py build dev --quicktest
        
        SUMMARY:
        ast2src is a pure python module.
        ast2src is a python ast tree hack.
        
        RECENT CHANGELOG:
        20100121 - added ast2src
        20091231 - added <<<< and >>>> sugar
        20091224 - added pseudomethod interactive console - revamped pseudomethod import hook
        20091224 - modularized package - fix install issues - added sdist check
        20091209 - improved documentation
        20091205 - moved source code to c++
        20091116 - package integrated
        
        DEMO USAGE:
        
        PseudoSugar - adding hook <ast2src.PseudoSugar object at 0xb7ba656c> to sys.meta_path
        >>> from ast2src import *
        
        >>> ## let's use ast2src's source code as example
        >>> import ast2src, ast
        >>> source_code1 = open(ast2src.__file__).read()
        >>> print( '\n' + re.sub('\n+', '\n', source_code1[:1024]) + '...' )
        
        ## import ast2src; reload(ast2src); from ast2src import *
        import os, sys
        if os.name != 'posix': sys.stderr.write('\nast2src requires linux os\n\n'); exit()
        if sys.version_info[:2] != (3, 1): sys.stderr.write('\nast2src requires python3.1\n\n'); exit()
        if 1: ###### INIT
        import ast2src as _MODULE
        if '_SETUP' not in globals(): _SETUP = sys.modules.get('ast2src.setup', None)
        def closure(*args, **kwds): return lambda fnc: fnc(*args, **kwds)
        def identity(aa): return aa
        def _import(ss, globals = globals()):
        for aa in ss.split(' '): globals[aa] = __import__(aa)
        return identity
        class Namespace(object):
        def __init__(self, **kwds): vars(self).update(kwds)
        @_import('ast builtins collections re ' #### pseudosugar compiler
        'imp importlib importlib.abc importlib.util ' #### import hook
        'locale') ## PYTHON BUG
        class PseudoSugar(ast.NodeVisitor, importlib.abc.Finder, importlib.abc.PyLoader):
        ## convenience function
        @staticmethod
        def exec(ss, globa...
        
        >>> ## compile source to ast
        >>> ast_tree1 = compile(source_code1, '', 'exec', ast.PyCF_ONLY_AST)
        >>> print( Ast2Src.debugnode(ast_tree1)[:1024], '...' )
        <class '_ast.Module'>	body [<_ast.Import object at 0x8841a2c>, <_ast.If object at 0x88417cc>, <_ast.If object at 0x87d9b0c>, <_ast.If object at 0x87d9fec>]
        <class '_ast.Import'>	col_offset 0	lineno 2	names [<_ast.alias object at 0x88412ec>, <_ast.alias object at 0x88419ac>]
        <class '_ast.alias'>	asname None	name 'os'
        <class '_ast.alias'>	asname None	name 'sys'
        <class '_ast.If'>	body [<_ast.Expr object at 0x889f92c>, <_ast.Expr object at 0x87d9acc>]	col_offset 0	lineno 3	orelse []	test <_ast.Compare object at 0x8841ccc>
        <class '_ast.Compare'>	col_offset 3	comparators [<_ast.Str object at 0x889f9ec>]	left <_ast.Attribute object at 0x88678cc>	lineno 3	ops [<_ast.NotEq object at 0xb7b3482c>]
        <class '_ast.Attribute'>	attr 'name'	col_offset 3	ctx <_ast.Load object at 0xb7bb0ccc>	lineno 3	value <_ast.Name object at 0x889f46c>
        <class '_ast.Name'>	col_offset 3	ctx <_ast.Load object at 0xb7bb0ccc>	id 'os'	lineno 3
        <class '_ast.Load'>
        <class '_ast.Load'>
        <class '_ast.NotEq'>
        <class '_ast. ...
        
        >>> ## reverse compile ast back to source
        >>> source_code2 = Ast2Src.unparse(ast_tree1)
        >>> print( '\n' + re.sub('\n+', '\n', source_code1[:1024]) + '...' )
        
        ## import ast2src; reload(ast2src); from ast2src import *
        import os, sys
        if os.name != 'posix': sys.stderr.write('\nast2src requires linux os\n\n'); exit()
        if sys.version_info[:2] != (3, 1): sys.stderr.write('\nast2src requires python3.1\n\n'); exit()
        if 1: ###### INIT
        import ast2src as _MODULE
        if '_SETUP' not in globals(): _SETUP = sys.modules.get('ast2src.setup', None)
        def closure(*args, **kwds): return lambda fnc: fnc(*args, **kwds)
        def identity(aa): return aa
        def _import(ss, globals = globals()):
        for aa in ss.split(' '): globals[aa] = __import__(aa)
        return identity
        class Namespace(object):
        def __init__(self, **kwds): vars(self).update(kwds)
        @_import('ast builtins collections re ' #### pseudosugar compiler
        'imp importlib importlib.abc importlib.util ' #### import hook
        'locale') ## PYTHON BUG
        class PseudoSugar(ast.NodeVisitor, importlib.abc.Finder, importlib.abc.PyLoader):
        ## convenience function
        @staticmethod
        def exec(ss, globa...
        
        >>> ## recompile reverse-compiled source
        >>> ast_tree2 = compile(source_code2, '', 'exec', ast.PyCF_ONLY_AST)
        >>> print( Ast2Src.debugnode(ast_tree2)[:1024], '...' )
        <class '_ast.Module'>	body [<_ast.Import object at 0x87ffecc>, <_ast.If object at 0x870416c>, <_ast.If object at 0x870abcc>, <_ast.If object at 0x870ae6c>]
        <class '_ast.Import'>	col_offset 0	lineno 2	names [<_ast.alias object at 0x869d1ec>, <_ast.alias object at 0x86bbacc>]
        <class '_ast.alias'>	asname None	name 'os'
        <class '_ast.alias'>	asname None	name 'sys'
        <class '_ast.If'>	body [<_ast.Expr object at 0x870aaac>, <_ast.Expr object at 0x870ab6c>]	col_offset 0	lineno 3	orelse []	test <_ast.Compare object at 0x87042ac>
        <class '_ast.Compare'>	col_offset 4	comparators [<_ast.Str object at 0x870a80c>]	left <_ast.Attribute object at 0x870590c>	lineno 3	ops [<_ast.NotEq object at 0xb7b3482c>]
        <class '_ast.Attribute'>	attr 'name'	col_offset 4	ctx <_ast.Load object at 0xb7bb0ccc>	lineno 3	value <_ast.Name object at 0x870a10c>
        <class '_ast.Name'>	col_offset 4	ctx <_ast.Load object at 0xb7bb0ccc>	id 'os'	lineno 3
        <class '_ast.Load'>
        <class '_ast.Load'>
        <class '_ast.NotEq'>
        <class '_ast. ...
        
Platform: UNKNOWN
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: End Users/Desktop
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: GNU General Public License (GPL)
Classifier: Natural Language :: English
Classifier: Operating System :: POSIX
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: C
Classifier: Programming Language :: C++
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.1
Classifier: Topic :: Multimedia
Classifier: Topic :: Multimedia :: Graphics
Classifier: Topic :: Scientific/Engineering
Classifier: Topic :: Scientific/Engineering :: Mathematics
Classifier: Topic :: Scientific/Engineering :: Visualization
Classifier: Topic :: Software Development
Classifier: Topic :: Software Development :: Code Generators
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
