Skip to main content

extension module backporting opcodes from python3k

Project description

################################################################################
REVISION DATE: 20081023

AUTHOR: kai zhu - kaizhu@hpc.usc.edu

HOMEPAGE: http://www-rcf.usc.edu/~kaizhu/work/py3to2/old/extension

ABSTRACT:
this is a minimal, standalone, proof-of-concept extension module for
python2.6, emulating limited python3.0 syntax behavior, thru usage of some
backported opcodes from python3.0. it is intended as a curiousity for hackers.

this module is derived from py3to2. the difference is that this is a
standalone module which requires no patching of python2.6 to work.
the tradeoff is that it is not 100& py3k language compliant, as py3to2
nearly is (see LIMITATIONS).

i wrote this module b/c i kno many ppl r loathe to patch their python-2.6 src
in order to run py3to2. this is a compromise, but plz note it has severe
limitations.

MECHANISM:
1. upon init, py3k_extension starts up a py3k server w/ pipe io.

2. -> received via pipe io from py3k_extension, the py3k server 1st
natively compiles the src code into a py3k codeobj, then converts it
to py2x format w/ the addition of the backported opcodes.

3. <- the serialized py2x codeobj is piped back to py3k_extension,
which unserializes it & eval/exec it as normal.

in theory, this mechanism should transparently implement any bytecode-level py3k
language feature. performance and robustness should b minimally impacted, since
the compiled code is directly run as native 2.x++ bytecode.

BACKWARD COMPATIBILITY:
since this is a standalone extension module which doesn't modify python's
source code in any way, there shouldn't b any backward compatibility issues as
long as the module is not imported

################################################################################

LIMITATIONS:
as a minimal extension module, this module DOES NOT SUPPORT CLASSES,
IMPORTING PY3K MODULES, OR FUNCTION KEYWORD-ONLY ARGUMENTS.
any py3k code containing classes will not work.

PY3K FEATURES TESTED TO WORK:
pep3104 Access to Names in Outer Scopes
pep3112 Bytes literals in Python 3000
pep3113 Removal of Tuple Parameter Unpacking
pep3132 Extended Iterable Unpacking

REQUIREMENTS:
* linux / unix (windows has io problems w/ py3k server)

BUILD/INSTALL: python setup.py build install

USAGE:
this module provides 3 wrapper functions similar to what's in python-3.0's
builtins:
- py3k_compile(code, filename, mode, flags, dont_inherit)
- py3k_eval(code, globals = None, locals = None)
- py3k_exec(code, globals = None, locals = None)

EXAMPLE:
Python 2.6 (r26:66714, Oct 19 2008, 02:49:13)
[GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
>>> import py3k_extension
created read/write pipes: (4, 5)
py3k server starting with pipes in/out/err: 7 5 -2
py3k server: Python 3.0rc1 (r30rc1:66499, Oct 15 2008, 15:43:09)
py3k server: [GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2
py3k server: Type "help", "copyright", "credits" or "license" for more
information.
py3k server: >>> ''
>>>
>>> py3k_exec( "a, *b = 1,2,3" ) # pep3132 Extended Iterable Unpacking
>>> print a, b
1 [2, 3]
>>>
################################################################################

CHANGELOG:
20081023
created a standalone extension module w/ limited capabilities
20081019
ported to python-2.6
consolidate & simplify patches to 1 file: ceval.c
created extension module builtins_py3k
revamped import hook again
removed unicode support & restrict source code to ascii-only
20080727
revampled import hook
20080911
consolidate patches to 2 files: bltinmodule.c & ceval.c
20080828
add kwonlyargcount 'attr' to codeobj
add __annotations__ & __kwdefaults__ attr to funcobj
add __pseudomethod__ feature to baseobj
20080819
pure python import hook - removed magic comment & use magic path instead
revamped str & bytes handling
revamped py3k .pyc file handling
20080802
pep3135 New Super
20080717
pep3107 Function Annotations
pep3120 Using UTF-8 as the default source encoding
pep3131 Supporting Non-ASCII Identifiers
20080713
import / reload works transparently on py3k scripts using a magic comment
added pep3102 Keyword-Only Arguments
20080709 added a py3k preparser
20080702
rewrote py3k server's pipe io. implemented partial bytearray & bytes class.
wrote a few simple tests
20080630
__build_class__ function to bltmodule.c. tested class decorators to b working.
################################################################################

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py3k_extension-20081023.tar.gz (51.9 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page