This release is a pre-release and may not be stable for production use.
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 0xb7ba856c> 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 0x9c6ea2c>, <_ast.If object at 0x9c6e7cc>, <_ast.If object at 0x9ab2b0c>, <_ast.If object at 0x9ab2fec>]
<class '_ast.Import'> col_offset 0 lineno 2 names [<_ast.alias object at 0x9c6e2ec>, <_ast.alias object at 0x9c6e9ac>]
<class '_ast.alias'> asname None name 'os'
<class '_ast.alias'> asname None name 'sys'
<class '_ast.If'> body [<_ast.Expr object at 0x9ccc92c>, <_ast.Expr object at 0x9ab2acc>] col_offset 0 lineno 3 orelse [] test <_ast.Compare object at 0x9c6eccc>
<class '_ast.Compare'> col_offset 3 comparators [<_ast.Str object at 0x9ccc9ec>] left <_ast.Attribute object at 0x9c948cc> lineno 3 ops [<_ast.NotEq object at 0xb7b3682c>]
<class '_ast.Attribute'> attr 'name' col_offset 3 ctx <_ast.Load object at 0xb7bb2ccc> lineno 3 value <_ast.Name object at 0x9ccc46c>
<class '_ast.Name'> col_offset 3 ctx <_ast.Load object at 0xb7bb2ccc> 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 0x9ad7ecc>, <_ast.If object at 0x9b3316c>, <_ast.If object at 0x9b3abcc>, <_ast.If object at 0x9b3ae6c>]
<class '_ast.Import'> col_offset 0 lineno 2 names [<_ast.alias object at 0x9c2966c>, <_ast.alias object at 0x9c022ec>]
<class '_ast.alias'> asname None name 'os'
<class '_ast.alias'> asname None name 'sys'
<class '_ast.If'> body [<_ast.Expr object at 0x9b3aaac>, <_ast.Expr object at 0x9b3ab6c>] col_offset 0 lineno 3 orelse [] test <_ast.Compare object at 0x9b332ac>
<class '_ast.Compare'> col_offset 4 comparators [<_ast.Str object at 0x9b3a80c>] left <_ast.Attribute object at 0x9b3490c> lineno 3 ops [<_ast.NotEq object at 0xb7b3682c>]
<class '_ast.Attribute'> attr 'name' col_offset 4 ctx <_ast.Load object at 0xb7bb2ccc> lineno 3 value <_ast.Name object at 0x9b3a10c>
<class '_ast.Name'> col_offset 4 ctx <_ast.Load object at 0xb7bb2ccc> id 'os' lineno 3
<class '_ast.Load'>
<class '_ast.Load'>
<class '_ast.NotEq'>
<class '_ast. ...
Metadata
Release files for ast2src 2010.01.21.ast2src
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| ast2src-2010.01.21.ast2src.tar.gz | 93.5 kB | Without provenance | Details |
Release files / ast2src-2010.01.21.ast2src.tar.gz
| Download URL | ast2src-2010.01.21.ast2src.tar.gz |
|---|---|
| Size | 93.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e1108ce558b89dce5ffc2aad84c1fbbbee541f04682dbf938ded96af1534a35a
|
|
BLAKE2b-256 checksum How to use checksums |
46ed2442689c6649daafe0f23e909f58f707f214a704ce7e855be60460bee168
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for ast2src 2010.01.21.ast2src
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.