Package: py3to2
this project is being superseded by asciiporn at http://code.google.com/p/asciiporn/AUTHORkai zhukaizhu256@gmail.comREQUIREMENTS- posix/unix os (Windows currently unsupported)- w/ python2.6 & python3.0 installedINSTALL$ python2.6 setup.py build$ python2.6 setup.py install$ python2.6 setup.py dev --quicktest$ python2.6 setup.py dev --py2to3test ## takes awhile to finishthe above will build & install 3 files:- extended python2.6 interpreter: bin/py3to2- initialization script:          lib/python2.6/site-packages/py3to2_init.py- python3.0 bytecode compiler:    lib/python2.6/site-packages/py3to2.py################################################################################ABSTRACTpy3to2 is a python2.6 interpreter w/ extended python3.0 opcodes, allowing it tonatively run python3.0 & 2to3 generated scripts. it should bmostly backwards-compatible w/ cpython2.6 & its extensions.the intended purpose is to allow developers to migrate python2.6 scripts topython3.0 while retaining backwards compatibility w/ existing extension modules.py3to2 coexists w/ ur existing python2.6 installation (it consists of 3 files)for a real-world py3to2 app (python3.0 script using 2.6 extension modules),checkout asciiporn: http://pypi.python.org/pypi/asciipornMECHANISMpy3to2 has 3 components:- py3to2python interpreter. can evaluate python2.6 bytecode containing additionalpython3.0 opcode instructions- py3to2_init.pyinitialization script.  sets up import hook for recognizing python3.0 scripts- py3to2.pybytecode compiler. the compile process takes 2 steps:- a persistent python3.0 process is created for compiling scripts intopython3.0 code- py3to2.py then converts the code from python3.0 to python2.6 formatMANIFEST./patch/ - patched files./py3to2.diff - summary of patches (maybe out-of-date)################################################################################MAGICsimply add the MAGIC LINE:from __future__ import py3k_syntaxto make py3to2 aware that a script is using python3.0 syntaxPSEUDOMETHODpy3to2 supports ".." syntax notation for pseudomethodsgoto: http://pypi.python.org/pypi/pseudomethodfor more details about this feature2TO3py3to2 includes convenience functions for automatically generating &testing scripts using 2to3:- class py2to3:- __call__ - overwrites file w/ one generated by 2to3- overwrite_and_load_module - overwrites file & then attempt to import it- test_stdlib - given a directory containing a copy of python2.6'sstandard library, it will overwrite them using 2to3 & thenattempts to load each fileAPI: try help(py3to2)  ^_-py3to2 module:- class codetree - mutable codeobj & disassembler/assembler/debugger- class compiler - compiling tools- python3.0 wrappers:- py3k_compile() - compile python3.0 src- py3k_eval() - eval py3thon3.0 src- py3k_exec() - exec python3.0 srcUSAGEstart up the py3to2 interpreter by typing "py3to2" in ur shell:$ py3to2Python 2.6.py3to2 (r26:66714, Nov 18 2008, 00:56:43)[GCC 3.4.6 20060404 (Red Hat 3.4.6-10)] on linux2Type "help", "copyright", "credits" or "license" for more information.>>>try out this simple python3.0 script:################################################################## PEP3132  Extended Iterable Unpacking## copy this to file test_pep3132.pyfrom __future__ import py3k_syntaxa,*b = 1,2,3assert a == 1 and b == [2,3]print(a,b)################################################################>>>>>> import test_pep3132created...py3k server starting......py3k server started w/...1 [2, 3]here's another python3.0 script using scipy (python2.6) extension module:################################################################## u must have scipy installed for this script to work## copy this to file test_pep3132_scipy.pyfrom __future__ import py3k_syntaximport scipya,*b = scipy.array([1,2,3])assert a == 1 and b == [2,3]print(a,b)################################################################>>>>>> import test_pep3132_scipy1 [2, 3]another simple, but more thorough test script, test_py3k,is included w/ this distribution:>>>>>> import test_py3ktesting PEP3102  Keyword-Only Argumentstesting PEP3104  Access to Names in Outer Scopestesting PEP3105  Make print a functiontesting PEP3107  Function Annotationstesting PEP3112  Bytes literals in Python 3000testing PEP3113  Removal of Tuple Parameter Unpackingtesting PEP3114  Renaming iterator.next() to .__next__()testing PEP3115  Metaclasses in Python 3000testing PEP3120  Using UTF-8 as the default source encodingtesting PEP3127  Integer Literal Support and Syntaxtesting PEP3129  Class Decoratorstesting PEP3131  Supporting Non-ASCII Identifierstesting PEP3132  Extended Iterable Unpackingtesting PEP3135  New Supertesting pseudomethod example 0testing pseudomethod example 1testing pseudomethod example 2testing pseudomethod example 3testing numpy exampleFEATURESPEP3102  Keyword-Only ArgumentsPEP3104  Access to Names in Outer ScopesPEP3105  Make print a functionPEP3107  Function AnnotationsPEP3111  Simple input built-in in Python 3000PEP3112  Bytes literals in Python 3000PEP3113  Removal of Tuple Parameter UnpackingPEP3114  Renaming iterator.next() to .__next__()PEP3115  Metaclasses in Python 3000PEP3120  Using UTF-8 as the default source encodingPEP3127  Integer Literal Support and SyntaxPEP3129  Class DecoratorsPEP3131  Supporting Non-ASCII IdentifiersPEP3132  Extended Iterable UnpackingPEP3135  New SuperUNICODE SUPPORTpy3to2 will only load ascii & utf8-encoded scripts(utf8 is the default encoding in python3.0).although they're illegal in python3.0, for backwards-compatibility sake,py3to2 supports unicode literals for explicit <unicode> obj creation:u"\u1234" is an explicit <unicode> obj (note unicode literal in front)"\u1234" is NOT a <unicode> obj when converted back to python2.6note also the following r equivalent under python2.6:u"\u1234"  <==>  "\u1234".decode("raw_unicode_escape")so u MUST do either u"..." or "...".decode("raw_unicode_escape")to create explicit <unicode> obj in py3to2.LIMITATIONS (FEATURES NOT FULLY SUPPORTED)except for the aforementioned unicode issue, from a migration standpoint,py3to2 is mostly feature complete in terms of python3.0's language syntax,language issue aside, python3.0 scripts will still behave differently b/c ofinternal differences between python2.6 & python3.0:- exception handling.  py3to2 implements python3.0 syntax for raising &catching exceptions.  but the underlying behavior is still python2.6- builtin functions / types.  a few of these have become different beastsunder python3.0################################################################################PYTHON2.6 COMPATIBILITY TEST$ python setup.py dev --maketest...test_systest test_sys failed -- Traceback (most recent call last):File ".../Python-2.6/Lib/test/test_sys.py", line 487, in test_objecttypescheck(get_cell().func_code, size(h + '4i8Pi2P'))File ".../Python-2.6/Lib/test/test_sys.py", line 423, in check_sizeofself.assertEqual(result, size, msg)AssertionError: wrong size for <type 'code'>: got 128, expected 120...325 tests OK.1 test failed:test_sys35 tests skipped:test_aepack test_al test_applesingle test_bsddb185 test_bsddb3test_cd test_cl test_codecmaps_cn test_codecmaps_hktest_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_cursestest_gdbm test_gl test_imgfile test_kqueue test_linuxaudiodevtest_macos test_macostools test_normalization test_ossaudiodevtest_pep277 test_py3kwarn test_scriptpackages test_socketservertest_startfile test_sunaudiodev test_tcl test_timeouttest_urllib2net test_urllibnet test_winreg test_winsoundtest_zipfile642 skips unexpected on linux2:test_tcl test_gdbm2TO3 COMPATIBILITY TEST$ python setup.py dev --py2to3test...tested 200 2to3 generated scripts from 2.6.1.py3to2 (r261:67515, Jan  4 2009,01:28:21)[GCC 4.2.3 20071123 (prerelease) (Debian 4.2.2-4)] standard library0 skipped:28 couldn't import required modules:BaseHTTPServer CGIHTTPServer cgi cookielib copy DocXMLRPCServerdummy_threading HTMLParser httplib _LWPCookieJar macurl2path mimetools mimetypes_MozillaCookieJar os pdb pickle pydoc re robotparser sgmllib SimpleHTTPServerSimpleXMLRPCServer _strptime tempfile threading urllib2 urllib6 were non-utf8 compliant scripts:base64 getopt heapq shlex smtpd tarfile8 failed import due to other reasons:anydbm dbhash doctest imputil sets trace UserList UserString159 passed import:_abcoll abc aifc ast asynchat asyncore atexit audiodev Bastion bdb binhexbisect calendar cgitb chunk cmd codecs codeop code collections colorsys commandscompileall ConfigParser contextlib Cookie copy_reg cProfile csv decimal difflibdircache dis dumbdbm dummy_thread filecmp fileinput fnmatch formatter fpformatfractions ftplib functools __future__ genericpath getpass gettext glob gziphashlib hmac htmlentitydefs htmllib ihooks imaplib imghdr inspect io keywordlinecache locale macpath mailbox mailcap markupbase md5 mhlib MimeWriter mimifymodulefinder multifile mutex netrc new nntplib ntpath nturl2path numbers opcodeoptparse os2emxpath __phello__.foo pickletools pipes pkgutil platform plistlibpopen2 poplib posixfile posixpath pprint profile pstats pty pyclbr py_compilepydoc_topics Queue quopri random repr rexec rfc822 rlcompleter runpy sched shashelve shutil site smtplib sndhdr socket SocketServer sre_compile sre_constantssre_parse sre ssl stat statvfs StringIO stringold stringprep string structsubprocess sunaudio sunau symbol symtable tabnanny telnetlib textwrap this_threading_local timeit toaiff tokenize token traceback tty types unittesturlparse UserDict user uuid uu warnings wave weakref webbrowser whichdb xdrlibxmllib xmlrpclib zipfile################################################################################RECENT CHANGES:20090103 updated to python 2.6.120081129 - major revisionPyCodeObject now has kwonlyargcount attr- breaks one regression test but greatly simplifies patch & prevents manyfuture bugs- fixes pydoc bugPyFunctionObject now has __kwdefaults__ & __annotations__ attrceval.c re-patched in light of above changes (much simpler)20081128more documentationadded 2to3 convenience functionsadded unicode utf-8 support20081123moved pseudomethod syntax handling to py3k serveradded more checks during setupadded more documentationbackported patch r67299 fixing an issue w/ super()cleaned up py3to2.compiler class20081120fixed package importing bug - py3to2 failed to import foo.bar20081119created self-installing distutils distribution20081019ported to python-2.6consolidate & simplify patches to 1 file: ceval.ccreated extension module builtins_py3krevamped import hook againremoved unicode support & restrict source code to ascii-only20080727revampled import hook20080911consolidate patches to 2 files: bltinmodule.c & ceval.c20080828add kwonlyargcount 'attr' to codeobjadd __annotations__ & __kwdefaults__ attr to funcobjadd __pseudomethod__ feature to baseobj20080819pure python import hook - removed magic comment & use magic path insteadrevamped str & bytes handlingrevamped py3k .pyc file handling20080802pep3135  New Super20080717pep3107  Function Annotationspep3120  Using UTF-8 as the default source encodingpep3131  Supporting Non-ASCII Identifiers20080713import / reload works transparently on py3k scripts using a magic commentadded pep3102  Keyword-Only Arguments20080709 added a py3k preparser20080702rewrote py3k server's pipe io.  implemented partial bytearray & bytes class.wrote a few simple tests20080630__build_class__ function to bltmodule.c.  tested class decorators to bworking.################################################################################