[issue9291] mimetypes initialization fails on Windows because of non-Latin characters in registry
kai zhu added the comment: python 3.1.2 mimetypes initialization also fails in redhat linux: >>> import http.server Traceback (most recent call last): File "/home/public/i386-redhat-linux-gnu/python/lib/python3.1/http/server.py", line 588, in class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): File "/home/public/i386-redhat-linux-gnu/python/lib/python3.1/http/server.py", line 764, in SimpleHTTPRequestHandler mimetypes.init() # try to read system mime.types File "/home/public/i386-redhat-linux-gnu/python/lib/python3.1/mimetypes.py", line 305, in init db.readfp(open(file)) File "/home/public/i386-redhat-linux-gnu/python/lib/python3.1/mimetypes.py", line 209, in readfp line = fp.readline() File "/home/public/i386-redhat-linux-gnu/bin/../python/lib/python3.1/encodings/ascii.py", line 26, in decode return codecs.ascii_decode(input, self.errors)[0] UnicodeDecodeError: 'ascii' codec can't decode byte 0xc2 in position 3921: ordinal not in range(128) -- nosy: +kaizhu ___ Python tracker <http://bugs.python.org/issue9291> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
New submission from kai zhu : i'm working on an independent py2to3 utility which directly imports py2x modules, by reverse compiling ast trees (code.google.com/p/asciiporn/source/browse/stable.py) while forward porting the python2x redis client, this issue came up. i kno its bad to use strings in sockets, but it seems webapps use it exploiting the fact utf8 is becoming a defacto web 'binary' standard $ python3.1 echo.py connected ('127.0.0.1', 41115) $ python3.1 client.py b'hello\r\n' recv() b'hello\r\n' makefile(mode = "rb") 'hello\n' makefile(mode = "r") ## echo.py - echo server program import socket serv = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: serv.bind(('localhost', 12345)) serv.listen(1) while True: conn, addr = serv.accept() print( 'connected', conn, addr ) while True: data = conn.recv(4096) if not data: conn.close() break conn.send(data) finally: serv.close() ## client.py - client program data = b'hello\r\n' import socket clie = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: clie.connect(('localhost', 12345)) clie.send(data) data = clie.recv(4096) print(repr(data), 'recv()') clie.send(data) file = clie.makefile('rb') data = file.readline() print(repr(data), 'makefile(mode = "rb")') clie.send(data) file = clie.makefile('r') data = file.readline() print(repr(data), 'makefile(mode = "r")') ## '\r' is silently dropped finally: clie.close() -- components: 2to3 (2.x to 3.0 conversion tool), IO, Library (Lib), Unicode messages: 118095 nosy: kaizhu priority: normal severity: normal status: open title: socket.makefile(mode = 'r').readline() silently removes carriage return type: behavior versions: Python 3.1, Python 3.2 ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
kai zhu added the comment: my bad for not rtfm, but it seems the newline argument has no effect in socket.makefile. the TextIOWrapper signatures don't seem to match. a hack to put newline parameter in 4th position or making it a keyword arg doesn't work either (scratch my head...) socket.py source text = io.TextIOWrapper(buffer, encoding, newline) textio.c static int textiowrapper_init(textio *self, PyObject *args, PyObject *kwds) { char *kwlist[] = {"buffer", "encoding", "errors", "newline", "line_buffering", NULL}; $ python3 echo.py ## from previous example $ python3 client.py b'hello\r\n' recv() b'hello\r\n' makefile(mode = "rb") 'hello\n' makefile(mode = "r", newline = "") # echo client program data = b'hello\r\n' import socket clie = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: clie.connect(('localhost', 12345)) clie.send(data) data = clie.recv(4096) print(repr(data), 'recv()') clie.send(data) file = clie.makefile('rb') data = file.readline() print(repr(data), 'makefile(mode = "rb")') clie.send(data) file = clie.makefile('r', newline = '') data = file.readline() print(repr(data), 'makefile(mode = "r", newline = "")') ## '\r' is still silently dropped finally: clie.close() -- resolution: invalid -> status: closed -> open ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
kai zhu added the comment: my bad again, hacking newline parameter to the correct argument position works (its in the position where error should b). a one line patch would be: socket.py -text = io.TextIOWrapper(buffer, encoding, newline) +text = io.TextIOWrapper(buffer, encoding, newline = newline) -- ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
Changes by kai zhu : -- keywords: +patch Added file: http://bugs.python.org/file19156/socket.makefile.newline.kwarg.patch ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
kai zhu added the comment: np antoine :) this 2 line patch will match socket.makefile() signature with open(). any chance it can b committed b4 python3.2 beta? i rely on this patch in order to forward-port redis to python3 -- Added file: http://bugs.python.org/file19193/makefile.errors.newline.patch ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
kai zhu added the comment: added unittest to patch tested test.test_socket on debian colinux running under winxp i get 2 unrelated errors (in both patched and unpatched version) from testRDM and testStream about socket.AF_TIPC being unsupported: pub...@colinux 3 ~/build/py3k.patch: ./python -m unittest test.test_socket ..s..EE == ERROR: testRDM (test.test_socket.TIPCTest) -- Traceback (most recent call last): File "/home/public/build/py3k.patch/Lib/test/test_socket.py", line 1683, in testRDM srv = socket.socket(socket.AF_TIPC, socket.SOCK_RDM) File "/home/public/build/py3k.patch/Lib/socket.py", line 94, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) socket.error: [Errno 97] Address family not supported by protocol == ERROR: testStream (test.test_socket.TIPCThreadableTest) -- Traceback (most recent call last): File "/home/public/build/py3k.patch/Lib/test/test_socket.py", line 131, in _setUp self.__setUp() File "/home/public/build/py3k.patch/Lib/test/test_socket.py", line 1707, in setUp self.srv = socket.socket(socket.AF_TIPC, socket.SOCK_STREAM) File "/home/public/build/py3k.patch/Lib/socket.py", line 94, in __init__ _socket.socket.__init__(self, family, type, proto, fileno) socket.error: [Errno 97] Address family not supported by protocol -- Ran 131 tests in 15.960s FAILED (errors=2, skipped=1) -- Added file: http://bugs.python.org/file19194/socket.makefile.with.unittest.patch ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
kai zhu added the comment: updated unittest patch -- Added file: http://bugs.python.org/file19195/socket.makefile.with.unittest.v2.patch ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10041] socket.makefile(mode = 'r').readline() silently removes carriage return
kai zhu added the comment: done ;p added separate unicode read, write, and readwrite test cases (which all pass) keep in mind my issue is specific to truncation of carriage return (imo a priority for py3k migration). i think this can b resolved by python 3.2 more general unicode issues should b raised in separate bug reports. -- Added file: http://bugs.python.org/file19209/socket.makefile.with.unittest.v3.patch ___ Python tracker <http://bugs.python.org/issue10041> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12075] python3.2 memory leak when setting integer key in dictionary
New submission from kai zhu : i'm using the latest debian unstable python3.2 build on colinux (2011, may, 14) ## leak.py ## >>> import imp, leak; imp.reload(leak) ## will leak ~2.5mb per reload ## on i386 debian unstable machine (according to top). ## in my real world app (an automatic build system), ## i run out of memory after a number reloads :( class Foo(object): pass Foo.leaky_dictionary = {} for aa in range(256): for bb in range(256): Foo.leaky_dictionary[(bb << 8) | aa] = None $ python3.2 Python 3.2.1a0 (default, May 5 2011, 00:47:12) [GCC 4.6.1 20110428 (prerelease)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import imp, leak; imp.reload(leak) ## 11mb >>> import imp, leak; imp.reload(leak) ## 13mb >>> import imp, leak; imp.reload(leak) ## 16mb >>> import imp, leak; imp.reload(leak) ## 19mb -- messages: 135961 nosy: kaizhu priority: normal severity: normal status: open title: python3.2 memory leak when setting integer key in dictionary type: resource usage versions: Python 3.2 ___ Python tracker <http://bugs.python.org/issue12075> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10756] Error in atexit._run_exitfuncs [...] Exception expected for value, str found
kai zhu added the comment: should this bug b closed? it seems fixed in python3.2 for me. -- ___ Python tracker <http://bugs.python.org/issue10756> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue12075] python3.2 memory leak when setting integer key in dictionary
kai zhu added the comment: explicit gc.collect() doesn't seem to fix the leak in my application. my current fix is to not re-instantiate the class attribute (which cost ~7mb) during reload & instead reference one created earlier. i haven't pinpointed y, but i suspect its a corner case, which would rarely occur in general usage. my class also inherits from subprocess.Popen, which has a __del__ method, which might interfere w/ collection (although gc.garbage says otherwise ;). the reason i reload is that the script gets modified frequently, which the auto-build system will detect & reload. -- ___ Python tracker <http://bugs.python.org/issue12075> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10756] Error in atexit._run_exitfuncs [...] Exception expected for value, str found
New submission from kai zhu : pub...@colinux 3 ~: python3.2 Python 3.2b2 (py3k, Dec 22 2010, 02:38:55) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import atexit; atexit.register(lambda:1/0) at 0xb7c7e12c> >>> exit() Error in atexit._run_exitfuncs: TypeError: print_exception(): Exception expected for value, str found might b related to Issue5089, so included those ppl to nosy. this bug is subtle. unit tests which explicitly 'raise' exceptions will not b caught, e.g. this will raise properly: @exit.register def foo(): raise ZeroDivisionError() -- components: Interpreter Core messages: 124490 nosy: BreamoreBoy, kaizhu, mark.dickinson priority: normal severity: normal status: open title: Error in atexit._run_exitfuncs [...] Exception expected for value, str found type: behavior versions: Python 3.2 ___ Python tracker <http://bugs.python.org/issue10756> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10802] python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows
New submission from kai zhu : i have 2 debian i386 unstable distros. 1) python3.2 (latest hg) running under vps @ linode.com seems ok 2) python3.2 (latest hg) running under colinux (in windows xp) breaks *NOTE 3) python3.2 (release b2) works fine under colinux pub...@colinux: python3.2 Python 3.2b2+ (py3k, Jan 1 2011, 17:42:23) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> subprocess.Popen('ls') Traceback (most recent call last): File "", line 1, in File "/home/public/i486-pc-linux-gnu/lib/python3.2/subprocess.py", line 708, in __init__ restore_signals, start_new_session) File "/home/public/i486-pc-linux-gnu/lib/python3.2/subprocess.py", line 1136, in _execute_child errpipe_read, errpipe_write = _create_pipe() OSError: [Errno 38] Function not implemented >>> -- components: IO, Interpreter Core messages: 125020 nosy: kaizhu priority: normal severity: normal status: open title: python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows type: behavior versions: Python 3.2 ___ Python tracker <http://bugs.python.org/issue10802> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10802] python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows
kai zhu added the comment: tested w/ following debug code. looks like greg is correct - HAVE_PIPE2 should NOT b defined under colinux. diff -r 6fa1e3b94d8f Modules/_posixsubprocess.c --- a/Modules/_posixsubprocess.cSat Jan 01 22:18:46 2011 +0100 +++ b/Modules/_posixsubprocess.cSun Jan 02 03:48:47 2011 -0500 @@ -412,10 +412,12 @@ int fds[2]; int res; #ifdef HAVE_PIPE2 +PyErr_Format(PyExc_RuntimeError, "HAVE_PIPE2 = %i, O_CLOEXEC = %i", HAVE_PIPE2, O_CLOEXEC); return NULL; Py_BEGIN_ALLOW_THREADS res = pipe2(fds, O_CLOEXEC); Py_END_ALLOW_THREADS #else +PyErr_Format(PyExc_RuntimeError, "HAVE_PIPE2 not defined, O_CLOEXEC = %i", O_CLOEXEC); return NULL; /* We hold the GIL which offers some protection from other code calling * fork() before the CLOEXEC flags have been set but we can't guarantee * anything without pipe2(). */ b2 release: ./python -c 'import _posixsubprocess; _posixsubprocess.cloexec_pipe()' Traceback (most recent call last): File "", line 1, in RuntimeError: HAVE_PIPE2 not defined, O_CLOEXEC = 524288 latest hg: ./python -c 'import _posixsubprocess; _posixsubprocess.cloexec_pipe()' Traceback (most recent call last): File "", line 1, in RuntimeError: HAVE_PIPE2 = 1, O_CLOEXEC = 524288 -- ___ Python tracker <http://bugs.python.org/issue10802> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10802] python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows
kai zhu added the comment: i used the same almost vanilla configure for both: $ ./configure --prefix=$USERPATH; make -- ___ Python tracker <http://bugs.python.org/issue10802> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10802] python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows
kai zhu added the comment: the culprit was my colinux kernel (2.6.26.8-co-0.7.7.1) did not have pipe2 support (which libc erronenously assumed). updating the kernel fixed the problem. the libc issue is partially discussed @ http://www.0x61.com/forum/linux-kernel-f109/popen2-popen-call-t1229012.html. according to manpage pipe2 was not added to the kernel til 2.6.27 my guess is this affects all unstable debian systems which are running kernels 2.6.26 or older (u decide whether or not using old kernels for debian unstable is an edge case ;) -- ___ Python tracker <http://bugs.python.org/issue10802> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10802] python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows
kai zhu added the comment: hi martin, did an strace & the 'not implemented' system call was pipe2() pipe2 exists in libc (checked w/ ctypes), but is broken for old linux kernels as mentioned previously. -- Added file: http://bugs.python.org/file20221/trace2.txt ___ Python tracker <http://bugs.python.org/issue10802> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10802] python3.2 AFTER b2 release has subprocess.Popen broken under colinux/windows
kai zhu added the comment: re-tested under old 2.6.26 kernel using previous foo.py example: 1. unpatched python3.2 broken as expected 2. patched python3.2 now works :) strace confirms ENOSYS being raised from pipe2() in both cases -- ___ Python tracker <http://bugs.python.org/issue10802> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue10953] safely eval serialized dict/list data from arbitrary string over web with no side effects
New submission from kai zhu : rather than serialize python dicts & list to json / xml / protocol buffer for web use, its more efficient to just serialize w/ repr() & then use eval(), if only there was a way to guarantee arbitrary code can't b executed. this is a very simple proposed method for the latter. b4 eval(), it compiles string to python code object & checks for: 1. co_names list can only contain 'False', 'None', 'True' -this ensures no function call can b made 2. co_consts list cannot contain code objects -embedded lambda's r forbidden. 3. grave accents are explicitly forbidden. here is the code for both python2.5 (intended for google appengine) & python 3k: ## safe_eval.py import sys, types if sys.version_info[0] == 2: ## py2x _co_safe = 'co_argcount co_nlocals co_varnames co_filename co_freevars co_cellvars'.split(' ') else: ## py3k _co_safe = 'co_argcount co_kwonlyargcount co_nlocals co_names co_varnames co_filename co_freevars co_cellvars'.split(' ') ## safely eval string with no side-effects def safe_eval(ss): if not ss: return None if '`' in ss: raise ValueError('grave accent "`" forbidden') cc = compile(ss, '', 'eval') for aa in _co_safe: if getattr(cc, aa): raise ValueError(aa + ' must be empty / none / zero') for aa in cc.co_names: if aa not in ['False', 'None', 'True']: raise ValueError('co_names can only contain False, None, True') for aa in cc.co_consts: if isinstance(aa, types.CodeType): raise TypeError('code objects not allowed in co_consts') return eval(cc, {}) python2.5 Python 2.5.5 (r255:77872, Nov 28 2010, 19:00:19) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> from safe_eval import safe_eval >>> safe_eval('[False, None, True, {1:2}]') [False, None, True, {1: 2}] >>> safe_eval('[None, False, True, {1:2}, evil_code()]') Traceback (most recent call last): File "", line 1, in File "safe_eval.py", line 19, in safe_eval if aa not in ['False', 'None', 'True']: raise ValueError('co_names can only contain False, None, True') ValueError: co_names can only contain False, None, True >>> safe_eval('[None, False, True, {1:2}, `evil_code()`]') Traceback (most recent call last): File "", line 1, in File "safe_eval.py", line 14, in safe_eval if '`' in ss: raise ValueError('grave accent "`" forbidden') ValueError: grave accent "`" forbidden >>> safe_eval('[None, False, True, {1:2}, lambda: evil_code()]') Traceback (most recent call last): File "", line 1, in File "safe_eval.py", line 21, in safe_eval if isinstance(aa, types.CodeType): raise TypeError('code objects not allowed in co_consts') TypeError: code objects not allowed in co_consts -- components: Library (Lib) messages: 126586 nosy: kaizhu priority: normal severity: normal status: open title: safely eval serialized dict/list data from arbitrary string over web with no side effects type: feature request versions: Python 2.5, Python 3.3 ___ Python tracker <http://bugs.python.org/issue10953> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11095] subprocess popen broken for bytes and backslash
New submission from kai zhu : noticed when trying to call grep w/ backslashes in regexp, in shell mode. same behavior on python2.5 & python3.2 in shell mode: 1. bytes is broken 2. 1st character after backslash is always silently truncated (with exception of '\\') $ python3.2 Python 3.2rc1+ (py3k, Jan 24 2011, 15:00:02) [GCC 4.4.5] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> subprocess.call(b'echo aa', shell = True) ## bytes broken Traceback (most recent call last): File "", line 1, in File "/home/public/i486-pc-linux-gnu/lib/python3.2/subprocess.py", line 460, in call return Popen(*popenargs, **kwargs).wait() File "/home/public/i486-pc-linux-gnu/lib/python3.2/subprocess.py", line 736, in __init__ restore_signals, start_new_session) File "/home/public/i486-pc-linux-gnu/lib/python3.2/subprocess.py", line 1175, in _execute_child restore_signals, start_new_session, preexec_fn) TypeError: Can't convert 'int' object to str implicitly >>> subprocess.call('echo \aa', shell = True) ## backslash \ a 0 >>> subprocess.call('echo \\aa', shell = True) ## backslash \\ aa 0 >>> subprocess.call('echo \\\aa', shell = True) ## backslash \\\ a 0 >>> subprocess.call('echo aa', shell = True) ## backslash a 0 >>> subprocess.call('echo \aa', shell = True) ## backslash \ \a 0 >>> subprocess.call('echo \\aa', shell = True) ## backslash \\ a 0 >>> subprocess.call('echo \aa', shell = True) \\\a 0 -- messages: 127714 nosy: kaizhu priority: normal severity: normal status: open title: subprocess popen broken for bytes and backslash type: behavior versions: Python 2.5, Python 3.2 ___ Python tracker <http://bugs.python.org/issue11095> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue11095] subprocess popen broken for bytes and backslash
Changes by kai zhu : -- components: +IO, Library (Lib) ___ Python tracker <http://bugs.python.org/issue11095> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3225] backport python 3.0 language functionality to python 2.5 by adding 8 opcodes to ceval.c
New submission from kai zhu <[EMAIL PROTECTED]>: this patch touches only Python/ceval.c. 1. the only existing thing it modifies is PyEval_EvalFrameEx (adds 8 extra cases for the new 3.0 opcodes, doesn't mess w/ any of the existing ones, or anything else as a matter of fact) 2. that, plus it defines (the new opcodes) #define SET_ADD 17 #define STORE_MAP 54 #define STORE_LOCALS 69 #define LOAD_BUILD_CLASS 34 #define MAKE_BYTES 35 #define POP_EXCEPT 36 #define UNPACK_EX 94 #define BUILD_SET 109 and some backported vars & helper functions only 2 contiguous areas of ceval.c is patched (1. & 2. - areas are delimited by the comments '// py3k') this simple patch seems sufficient in theory to allow the interpreter to natively execute most of 3.0's language syntax (nonlocal, print, extended unpacking... have been tested to work) *the one exception being pep3102 - keyword-only arguments i wrote 2 small scripts which gives an interactive function 'compile_py3k' similar to __builtin__.compile except it works only for 3.0 syntax. it doesn't actually compile, but rather cheats by querying it to a python 3.0 server via pipe io. here is an interactive demonstration of my script: example demonstrating pep3132 extended unpacking syntax: a,b,*c = 1,2,3,4 Python 2.5.2 (r252:60911, Jun 27 2008, 21:19:51) [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import py3to2 py3to2 server restarting with io: (4, 5) py3to2 server: Python 3.0b1 (r30b1:64395, Jun 24 2008, 21:53:55) py3to2 server: [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2 py3to2 server: Type "help", "copyright", "credits" or "license" for more information. py3to2 server: >>> src = "a,b,*c = 1,2,3,4" >>> codeobject = py3to2.compile_py3k(src,"","exec") 1 0 LOAD_CONST 5 ((1, 2, 3, 4)) 3 UNPACK_EX_py3k 2 6 STORE_NAME 0 (a) 9 STORE_NAME 1 (b) 12 STORE_NAME 2 (c) 15 LOAD_CONST 4 (None) 18 RETURN_VALUE >>> exec(codeobject); print "a=%s, b=%s, c=%s"%(a,b,c) a=1, b=2, c=[3, 4] >>> u can go c http://pypi.python.org/pypi?name=py3to2&version=20080628&:action=display for more info anyway, i think it would b a great boost for python 3.0 (which i think is very cool) if developers can test/develop it under the robust 2.5 environment. this patch plus some scripts could go a long way in making that happen -- assignee: collinwinter components: 2to3 (2.x to 3.0 conversion tool) files: ceval.c messages: 68873 nosy: collinwinter, kaizhu severity: normal status: open title: backport python 3.0 language functionality to python 2.5 by adding 8 opcodes to ceval.c type: feature request versions: Python 2.5 Added file: http://bugs.python.org/file10758/ceval.c ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3225> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3225] backport python 3.0 language functionality to python 2.5 by adding 8 opcodes to ceval.c
Changes by kai zhu <[EMAIL PROTECTED]>: ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3225> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
New submission from kai zhu <[EMAIL PROTECTED]>: this patch touches only Python/ceval.c. 1. the only existing thing it modifies is PyEval_EvalFrameEx (adds 7 extra cases for the new 3.0 opcodes, doesn't mess w/ any of the existing ones, or anything else as a matter of fact) 2. that, plus it defines (the new opcodes) #define SET_ADD 17 #define STORE_LOCALS 69 #define LOAD_BUILD_CLASS 34 // 71 in py3k #define MAKE_BYTES 35 // unused in py3k #define POP_EXCEPT 36 // 89 in py3k #define UNPACK_EX 94 #define BUILD_SET 109 // 104 in py3k and some backported vars & helper functions only 2 contiguous areas of ceval.c is patched (1. & 2. - areas are delimited by the comments '// py3k') this simple patch seems sufficient in theory to allow the interpreter to natively execute most of 3.0's language syntax (nonlocal, print, extended unpacking, ... have been tested to work) *the one exception being pep3102 - keyword-only arguments i wrote 2 small scripts which gives an interactive function 'compile_py3k' similar to __builtin__.compile. its a wrapper function which queries the byte-compiling task to a python 3.0 server via pipe io. example demonstrating pep3132 extended unpacking syntax: a,b,*c = 1,2,3,4 (note the backported 3.0 opcode used in line2 of the disassembly) Python 2.5.2 (r252:60911, Jun 27 2008, 21:19:51) [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import py3to2 py3to2 server restarting with io: (4, 5) py3to2 server: Python 3.0b1 (r30b1:64395, Jun 24 2008, 21:53:55) py3to2 server: [GCC 3.4.6 20060404 (Red Hat 3.4.6-9)] on linux2 py3to2 server: Type "help", "copyright", "credits" or "license" for more information. py3to2 server: >>> src = "a,b,*c = 1,2,3,4" >>> codeobject = py3to2.compile_py3k(src,"","exec") 1 0 LOAD_CONST 5 ((1, 2, 3, 4)) 3 UNPACK_EX_py3k 2 6 STORE_NAME 0 (a) 9 STORE_NAME 1 (b) 12 STORE_NAME 2 (c) 15 LOAD_CONST 4 (None) 18 RETURN_VALUE >>> exec(codeobject) >>> print a,b,c 1, 2, [3, 4] >>> u can go c http://pypi.python.org/pypi?name=py3to2&version=20080628&:action=display for more info on the script anyway, i think it would b a great boost for python 3.0 (which i think is very cool) if developers can test/develop it under the 2.x environment. this patch plus some scripts to emulated 3k extensions (bytes, bytearray, ...) can go a long way in making 3.0 available for the masses. ps. i've also attempted the reverse (forward-port 2.x opcodes to 3.0), & its a bit more complicated (namely the PRINTxxx opcodes). if there's significant interest in that, i could work on it a bit more, but my current interest is in extending 3.0 functionality to the vast 2.x software base. -- assignee: collinwinter components: 2to3 (2.x to 3.0 conversion tool) files: ceval.2.6b1.c messages: 68964 nosy: collinwinter, kaizhu severity: normal status: open title: backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c type: feature request versions: Python 2.6 Added file: http://bugs.python.org/file10776/ceval.2.6b1.c ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: ok ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: ideally that may be true. but its quite frustrating testing/developing new py3k software when many modules/extensions we take for granted in 2.x isn't available. in the meantime, this patch serves as a very convenient stopgap for developers (even w/ its bugs), for writing py3k migration code in 2.x (& access to all its extensions) for example, its a difficult task to port a big project like numpy to py3k all @ once. but this patch could allow u to piece-wise transform it, one script @ a time, to py3k language syntax compliance. ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: update: these 3k language features have been tested to work in python 2.5.2 w/ the backported opcodes pep3104 Access to Names in Outer Scopes pep3105 Make print a function pep3111 Simple input built-in in Python 3000 pep3113 Removal of Tuple Parameter Unpacking pep3114 Renaming iterator.next() to .__next__() pep3115 Metaclasses in Python 3000 pep3127 Integer Literal Support and Syntax pep3129 Class Decorators pep3132 Extended Iterable Unpacking had to backport __build_class__ in bltinmodule.c to get metaclasses working. u can go to http://www-rcf.usc.edu/~kaizhu/work/py3to2/ for more info install/usage summary: 1. build python 2.5.2 w/ patched ceval.c & bltinmodule.c 2. download scripts: py3to2.py & _py3to2.py 3. ln -s python3.0 python3k 4. run python2.5 & type 'import py3to2' # it will automatically run the pep tests the script provides 3 functions similar to those in __builtin__: compile_py3k, exec_py3k, eval_py3k right now, working on backporting pep 3102 & 3107 - annotations & keyword-only arguments. apparently appending the co_kwonlyargcount attr to codeobject in 2.5.2 doesn't seem to affect the build ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: import/reload now works. accomplished by adding 5 lines in parse_source_module (import.c) to 1st check for the hook __builtins__.parse_source_module_py3k. the hook will automatically compile in py3k format if it finds the magic comment: "# import as py3k\n" * below is a working python 3.0 script integrated w/ numpy. also added: pep3102 Keyword-Only Arguments pep3112 Bytes literals in Python 3000 download: http://www-rcf.usc.edu/~kaizhu/work/py3to2/current/ patched files: ceval.c (unchanged from last) bltinmodule.c (unchanged from last) import.c (added 5 continuous lines to parse_source_module) there r 7 unimplemented pep's remaining: any suggested solutions? pep3107 Function Annotations (easy, just haven't gotten around yet) pep3109/3110 Exceptions in Python 3000 (hard?) pep3120 Using UTF-8 as the default source encoding pep3123 Making PyObject_HEAD conform to C (hard/who cares for 2.x?) pep3131 Supporting Non-ASCII Identifiers (looks emulable) pep3138 String representation in Python 3000 @ any rate, i think its feature complete enough to b useful in certain areas (for me its scientific computing). """ numpy_py3k.py this is a py3to2 demo showing a python3.0 script being run under python 2.5 & utilizing numpy, a python2.5 extension module. add the magic comment '# import as py3k\n' to import / reload a script in py3k format interactive usage: >>> import py3to2 >>> import numpy_py3k >>> reload(numpy_py3k) commandline usage: python -c 'import py3to2; import numpy_py3k' """ # import as py3k import numpy print('pep3102 Keyword-Only Arguments') # nth order polynomial fit of multiple y data def polyfits(nth, x, *ys, rcond = None, full = False): return [numpy.polyfit(x, y, nth, rcond, full) for y in ys] fits = polyfits(2, # 2nd order fit numpy.arange(16), # x data numpy.random.rand(16), numpy.random.rand(16), # multiple y data rcond = numpy.MachAr().eps, # precision full = False, # return only coeffs ) print('fits', fits); print('#'*64) print('pep3112 Bytes literals in Python 3000') x = bytes( numpy.arange(256, dtype = numpy.int8).tostring() ) print('bytes', x); print('#'*64) print('pep3114 Renaming iterator.next() to .__next__()') x = (x for x in numpy.arange(16)) print('x.__next__()', x.__next__(), x.__next__(), x.__next__()); print('#'*64) print('pep3132 Extended Iterable Unpacking') a,b,*c = numpy.random.rand(4) print('a = %s, b = %s, c = %s'%(a,b,c)); print('#'*64) -- assignee: -> collinwinter components: +2to3 (2.x to 3.0 conversion tool), Demos and Tools, Interpreter Core, Tests -None ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: why not? it allows developers to migrate 2.x scripts one-by-one to working 3.0 conformant ones while maintaining backwards-compatibility w/ existing 2.x scripts & extension modules (eg. numpy, PIL, zope, ...) py3to2 can transparently import & mix & match 2.x & 3.0 scripts (but builtins/extensions must b 2.x - hence its a 2to3 migration tool). @ the moment, every script compilable by py3to2 should b 3.0 language conformant, or otherwise it would fail the syntax check & byte-compile stage performed by the python 3.0 slave interpreter (see Mechanism for details). -- components: +None nosy: +benjamin.peterson ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: then the 2 can complement each other well ;) i don't c any competition between them as they have completely different objectives 2to3 -> convert 2x scripts to 3k py3to2 <- use the newly created 3k scripts in existing 2x environ u have to admit migrating to 3k is quite painful & slow w/ its lack of 2x's vast extension base. given py3to2's potential to alleviate this problem for migrating developers, don't u think that possibly merits its mention in the 2to3 category? btw, py3to2's patches minimally affects 2.x compatibility: ceval.c - backports missing 3.0 opcodes (8 in python 2.5.2) bltinmodule.c - backports missing 3.0 function __build_class__ import.c - adds a 5 line hook to function parse_source_module allowing automatic checking for and compiling of 3k scripts during import/reload i just ran 'make test' w/ a patched build of python 2.5.2 w/ following results on redhat, x86_64: 285 tests OK. 37 tests skipped: test_aepack test_al test_applesingle test_bsddb185 test_bsddb3 test_cd test_cl test_codecmaps_cn test_codecmaps_hk test_codecmaps_jp test_codecmaps_kr test_codecmaps_tw test_curses test_dl test_gdbm test_gl test_imageop test_imgfile test_linuxaudiodev test_macfs test_macostools test_normalization test_ossaudiodev test_pep277 test_plistlib test_rgbimg test_scriptpackages test_socket_ssl test_socketserver test_startfile test_sunaudiodev test_timeout test_urllib2net test_urllibnet test_winreg test_winsound test_zipfile64 1 skip unexpected on linux2: test_gdbm not bad considering it now supports 11 of the 18 (soon to b 12 & likely more...) 3000 series pep's ^_^ ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3692] improper scope in list comprehension, when used in class declaration
New submission from kai zhu <[EMAIL PROTECTED]>: in 3rd line, list comprehension tries to access class_attribute1 as a global variable (code is valid in python 2.5) >>> class Foo(object): ... class_attribute1 = 1 ... class_attribute2 = [class_attribute1 for x in range(8)] ... Traceback (most recent call last): File "", line 1, in File "", line 3, in Foo File "", line 3, in NameError: global name 'class_attribute1' is not defined -- components: Interpreter Core messages: 72002 nosy: kaizhu severity: normal status: open title: improper scope in list comprehension, when used in class declaration type: behavior versions: Python 3.0 ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3692> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7775] str.rpartition(sep) -> (tail, sep, head)
Changes by kai zhu : -- assignee: georg.brandl components: Documentation nosy: georg.brandl, kaizhu severity: normal status: open title: str.rpartition(sep) -> (tail, sep, head) versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue7775> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7775] str.rpartition(sep) -> (tail, sep, head)
kai zhu added the comment: documentation bug should be changed to: "S.rpartition(sep) -> (head, sep, tail)" >>> help(str.rpartition) Help on method_descriptor: rpartition(...) S.rpartition(sep) -> (tail, sep, head) Search for the separator sep in S, starting at the end of S, and return the part before it, the separator itself, and the part after it. If the separator is not found, return two empty strings and S. -- ___ Python tracker <http://bugs.python.org/issue7775> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: ported to python-2.6 & is a bit more stable (written a few py3k programs w/ it). the patches have been simplified & consolidated to a single file: ceval.c u can also test out scripts generated by 2to3 by adding to them the magic line: "from __future__ import py3k_syntax" an example "python-2.6" script using "python-3.0" language syntax (& numpy if its installed) is provided @: http://www-rcf.usc.edu/~kaizhu/work/py3to2/current/example_py3k.py new features added by patch to python-2.6 (under py3k_syntax mode): pep3102 Keyword-Only Arguments pep3104 Access to Names in Outer Scopes pep3107 Function Annotations pep3111 Simple input built-in in Python 3000 pep3113 Removal of Tuple Parameter Unpacking pep3114 Renaming iterator.next() to iterator.__next__() pep3115 Metaclasses in Python 3000 pep3127 Integer Literal Support and Syntax - oct() functions differently in py3k_syntax mode pep3129 Class Decorators pep3132 Extended Iterable Unpacking pep3135 New Super misc exec becomes a function sans unicode & py3k's builtins module, the above (plus __future__) implements pretty much all of py3k's language syntax py3k_syntax mode: a special bitflag is embedded in codeobj->co_argcount, which triggers PyEval_EvalFrameEx to enable the backported opcodes (which r disabled by default) & use an alternate py3k __builtin__. codeobj->co_argcount now limited to range 0-0x with upper bits reserved for py3k flags codeobj->co_kwonlyargcount (limited to range 0-0xff) is embedded in upper bits of codeobj->co_argcount most of the trouble have been gettin kwonlyarg, annotations, & classes to work. there is one unrelated opcode (LOAD_ATTR_py3k) added to ceval.c for my personal use (curries attributes as a universal function), but can b safely disabled by commenting its case out of PyEvalFrameEx in ceval.c & deleting it from dict opnew_py2x in py3to2.py -- components: +Extension Modules, Library (Lib) -None Added file: http://bugs.python.org/file11842/README.txt ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
Changes by kai zhu <[EMAIL PROTECTED]>: -- keywords: +patch Added file: http://bugs.python.org/file11843/ceval.20081020.diff ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
Changes by kai zhu <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file11844/py3to2.py ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: hi, i'm happy i got a response on this :) anyway, can u elaborate on the "reason" y something like this was never done? yes, i kno the patch is rough right now (& will never get accepted in its current state), but its now proven to work, & gives migrating developers *something* to test their py3k_syntax code while *still* maintaining compatibility w/ python2.x extension modules. isn't that the spirit of python 2.7? in the meantime, i'm in no hurry to have anything committed. Added file: http://bugs.python.org/file11845/example_py3k.py ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: k ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
kai zhu <[EMAIL PROTECTED]> added the comment: post fyi: here's moderately complex python-3.0 script (plus curry extension) i wrote using numpy, PIL, & scipy.weave 2.6 extensions. it takes a jpeg, gif... image file & outputs it in colorized ascii art. the actual purpose is for colorized 3-d scientific plottin in text terminal (screenshots of image conversion & 3d plots in putty terminal included) usage: python -c "import py3to2; import img2txt; img2txt.img2txt.test()" python -c "import py3to2; import img2txt; img2txt.tplot3d.test()" Added file: http://bugs.python.org/file11872/img2txt mario.jpg screenshot.gif ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
Changes by kai zhu <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file11873/img2txt 3dplot screenshot.gif ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
Changes by kai zhu <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file11874/img2txt.py ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3238] backport python 3.0 language functionality to python 2.6 by adding 7 opcodes to ceval.c
Changes by kai zhu <[EMAIL PROTECTED]>: Added file: http://bugs.python.org/file11875/mario.jpg ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue3238> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4360] SystemError when method has both super() & closure
New submission from kai zhu <[EMAIL PROTECTED]>: # super_closure.py class A(object): def foo(self): return super() # remove the closure below # & SystemError goes away ??? lambda: self A().foo() when run on 3.0rc1 & 3.0rc2: hpc-login2 3 ~/work/py3to2: python3.0 super_closure.py Traceback (most recent call last): File "super_closure.py", line 9, in A().foo() File "super_closure.py", line 5, in foo return super() SystemError: super(): __class__ is not a type (A) SystemError seems to b raised from typeobject.c (line6155): static int super_init(PyObject *self, PyObject *args, PyObject *kwds) {... if (!PyType_Check(type)) { PyErr_Format(PyExc_SystemError, "super(): __class__ is not a type (%s)", Py_TYPE(type)->tp_name); return -1; } break; -- components: Build, Interpreter Core messages: 76093 nosy: kaizhu severity: normal status: open title: SystemError when method has both super() & closure type: behavior versions: Python 3.0 ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4360> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4360] SystemError when method has both super() & closure
kai zhu <[EMAIL PROTECTED]> added the comment: here's a printout of bytecode from script >>> >>> s = open("super_closure.py").read() >>> c = compile(s, "super_closure.py", "exec") >>> t = py3to2.codetree(c) >>> print( t ) codetree( co_argcount = 0, co_cellvars = (), co_code = b'Gd\x00\x00\x84\x00\x00d\x01\x00e\x00\x00\x83\x03\x00Z\x01\x00e\x01\x00\x83\x00\x00j\x02\x00\x83\x00\x00\x01d\x02\x00S', co_filename = 'super_closure.py', co_firstlineno = 3, co_flags =64, co_freevars = (), co_kwonlyargcount =0, co_lnotab = b'\x13\x06', co_name = '', co_names =('object', 'A', 'foo'), co_nlocals = 0, co_stacksize =4, co_varnames = (), depth = 0, co_consts = ( codetree( co_argcount = 1, co_cellvars = ('__class__',), co_code = b'|\x00\x00Ee\x00\x00Z\x01\x00\x87\x00\x00f\x01\x00d\x00\x00\x86\x00\x00Z\x02\x00\x87\x00\x00S', co_filename = 'super_closure.py', co_firstlineno = 3, co_flags =2, co_freevars = (), co_kwonlyargcount =0, co_lnotab = b'\n\x01', co_name = 'A', co_names =('__name__', '__module__', 'foo'), co_nlocals = 1, co_stacksize =2, co_varnames = ('__locals__',), depth = 1, co_consts = ( codetree( co_argcount = 1, co_cellvars = ('self',), co_code = b't\x00\x00\x83\x00\x00S\x87\x00\x00f\x01\x00d\x01\x00\x86\x00\x00\x01', co_filename = 'super_closure.py', co_firstlineno = 4, co_flags =3, co_freevars = ('__class__',), co_kwonlyargcount =0, co_lnotab = b'\x00\x01\x07\x03', co_name = 'foo', co_names =('super',), co_nlocals = 1, co_stacksize =2, co_varnames = ('self',), depth = 2, co_consts = ( None, codetree( co_argcount = 0, co_cellvars = (), co_code = b'\x88\x00\x00S', co_filename = 'super_closure.py', co_firstlineno = 8, co_flags =19, co_freevars = ('self',), co_kwonlyargcount =0, co_lnotab = b'', co_name = '', co_names =(), co_nlocals = 0, co_stacksize =1, co_varnames = (), depth = 3, co_consts = ( )), )), )), A, None, )) >>> and disassembly: >>> >>> print( t.dis() ) 3 0 LOAD_BUILD_CLASS 1 LOAD_CONST 0 () 4 MAKE_FUNCTION0 7 LOAD_CONST 1 ('A') 10 LOAD_NAME0 (object) 13 CALL_FUNCTION3 16 STORE_NAME 1 (A) 9 19 LOAD_NAME1 (A) 22 CALL_FUNCTION0 25 LOAD_ATTR2 (foo) 28 CALL_FUNCTION0 31 POP_TOP 32 LOAD_CONST 2 (None) 35 RETURN_VALUE 3 0 LOAD_FAST0 (__locals__) 3 STORE_LOCALS 4 LOAD_NAME0 (__name__) 7 STORE_NAME 1 (__module__) 4 10 LOAD_CLOSURE 0 (__class__) 13 BUILD_TUPLE 1 16 LOAD_CONST 0 () 19 MAKE_CLOSURE 0 22 STORE_NAME 2 (foo) 25 LOAD_CLOSURE 0 (__class__) 28 RETURN_VALUE 5 0 LOAD_GLOBAL 0 (super) 3 CALL_FUNCTION0 6 RETURN_VALUE 8 7 LOAD_CLOSURE 0 (self) 10 BUILD_TUPLE 1 13 LOAD_CONST 1 ( at 0x2a984c0530, file "super_closure.py", line 8>) 16 MAKE_CLOSURE 0 19 POP_TOP 8 0 LOAD_DEREF 0 (self) 3 RETURN_VALUE >>> ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4360> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4360] SystemError when method has both super() & closure
kai zhu <[EMAIL PROTECTED]> added the comment: same thing, except w/ closure commented out (& everything is happy) # super_ok.py class A(object): def foo(self): return super() # comment the closure below # & SystemError goes away # lambda: self A().foo() >>> >>> s = open("super_ok.py").read() >>> c = compile(s, "super_ok.py", "exec") >>> t = py3to2.codetree(t) >>> print( t ) codetree( co_argcount = 0, co_cellvars = (), co_code = b'Gd\x00\x00\x84\x00\x00d\x01\x00e\x00\x00\x83\x03\x00Z\x01\x00e\x01\x00\x83\x00\x00j\x02\x00\x83\x00\x00\x01d\x02\x00S', co_filename = 'super_closure.py', co_firstlineno = 3, co_flags =64, co_freevars = (), co_kwonlyargcount =0, co_lnotab = b'\x13\x06', co_name = '', co_names =('object', 'A', 'foo'), co_nlocals = 0, co_stacksize =4, co_varnames = (), depth = 0, co_consts = ( codetree( co_argcount = 1, co_cellvars = ('__class__',), co_code = b'|\x00\x00Ee\x00\x00Z\x01\x00\x87\x00\x00f\x01\x00d\x00\x00\x86\x00\x00Z\x02\x00\x87\x00\x00S', co_filename = 'super_closure.py', co_firstlineno = 3, co_flags =2, co_freevars = (), co_kwonlyargcount =0, co_lnotab = b'\n\x01', co_name = 'A', co_names =('__name__', '__module__', 'foo'), co_nlocals = 1, co_stacksize =2, co_varnames = ('__locals__',), depth = 1, co_consts = ( codetree( co_argcount = 1, co_cellvars = ('self',), co_code = b't\x00\x00\x83\x00\x00S\x87\x00\x00f\x01\x00d\x01\x00\x86\x00\x00\x01', co_filename = 'super_closure.py', co_firstlineno = 4, co_flags =3, co_freevars = ('__class__',), co_kwonlyargcount =0, co_lnotab = b'\x00\x01\x07\x03', co_name = 'foo', co_names =('super',), co_nlocals = 1, co_stacksize =2, co_varnames = ('self',), depth = 2, co_consts = ( None, codetree( co_argcount = 0, co_cellvars = (), co_code = b'\x88\x00\x00S', co_filename = 'super_closure.py', co_firstlineno = 8, co_flags =19, co_freevars = ('self',), co_kwonlyargcount =0, co_lnotab = b'', co_name = '', co_names =(), co_nlocals = 0, co_stacksize =1, co_varnames = (), depth = 3, co_consts = ( )), )), )), A, None, )) >>> >>> print( t.dis() ) 3 0 LOAD_BUILD_CLASS 1 LOAD_CONST 0 () 4 MAKE_FUNCTION0 7 LOAD_CONST 1 ('A') 10 LOAD_NAME0 (object) 13 CALL_FUNCTION3 16 STORE_NAME 1 (A) 9 19 LOAD_NAME1 (A) 22 CALL_FUNCTION0 25 LOAD_ATTR2 (foo) 28 CALL_FUNCTION0 31 POP_TOP 32 LOAD_CONST 2 (None) 35 RETURN_VALUE 3 0 LOAD_FAST0 (__locals__) 3 STORE_LOCALS 4 LOAD_NAME0 (__name__) 7 STORE_NAME 1 (__module__) 4 10 LOAD_CLOSURE 0 (__class__) 13 BUILD_TUPLE 1 16 LOAD_CONST 0 () 19 MAKE_CLOSURE 0 22 STORE_NAME 2 (foo) 25 LOAD_CLOSURE 0 (__class__) 28 RETURN_VALUE 5 0 LOAD_GLOBAL 0 (super) 3 CALL_FUNCTION0 6 RETURN_VALUE 8 7 LOAD_CLOSURE 0 (self) 10 BUILD_TUPLE 1 13 LOAD_CONST 1 ( at 0x2a987af5b0, file "super_closure.py", line 8>) 16 MAKE_CLOSURE 0 19 POP_TOP 8 0 LOAD_DEREF 0 (self) 3 RETURN_VALUE >>> ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4360> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue4360] SystemError when method has both super() & closure
kai zhu <[EMAIL PROTECTED]> added the comment: oops, sorry reprinted the same code ^^;;; ignore previous post, & use this: (sorry again for mucking up this page) # super_ok.py class A(object): def foo(self): return super() # comment the closure below # & SystemError goes away # lambda: self A().foo() >>> s = open("super_ok.py").read(); c = compile(s, "super_ok.py", "exec"); t = py3to2.codetree(c) >>> print( t ) codetree( co_argcount = 0, co_cellvars = (), co_code = b'Gd\x00\x00\x84\x00\x00d\x01\x00e\x00\x00\x83\x03\x00Z\x01\x00e\x01\x00\x83\x00\x00j\x02\x00\x83\x00\x00\x01d\x02\x00S', co_filename = 'super_ok.py', co_firstlineno = 3, co_flags =64, co_freevars = (), co_kwonlyargcount =0, co_lnotab = b'\x13\x06', co_name = '', co_names =('object', 'A', 'foo'), co_nlocals = 0, co_stacksize =4, co_varnames = (), depth = 0, co_consts = ( codetree( co_argcount = 1, co_cellvars = ('__class__',), co_code = b'|\x00\x00Ee\x00\x00Z\x01\x00\x87\x00\x00f\x01\x00d\x00\x00\x86\x00\x00Z\x02\x00\x87\x00\x00S', co_filename = 'super_ok.py', co_firstlineno = 3, co_flags =2, co_freevars = (), co_kwonlyargcount =0, co_lnotab = b'\n\x01', co_name = 'A', co_names =('__name__', '__module__', 'foo'), co_nlocals = 1, co_stacksize =2, co_varnames = ('__locals__',), depth = 1, co_consts = ( codetree( co_argcount = 1, co_cellvars = (), co_code = b't\x00\x00\x83\x00\x00S', co_filename = 'super_ok.py', co_firstlineno = 4, co_flags =3, co_freevars = ('__class__',), co_kwonlyargcount =0, co_lnotab = b'\x00\x01', co_name = 'foo', co_names =('super',), co_nlocals = 1, co_stacksize =1, co_varnames = ('self',), depth = 2, co_consts = ( None, )), )), A, None, )) >>> print( t.dis() ) 3 0 LOAD_BUILD_CLASS 1 LOAD_CONST 0 () 4 MAKE_FUNCTION0 7 LOAD_CONST 1 ('A') 10 LOAD_NAME0 (object) 13 CALL_FUNCTION3 16 STORE_NAME 1 (A) 9 19 LOAD_NAME1 (A) 22 CALL_FUNCTION0 25 LOAD_ATTR2 (foo) 28 CALL_FUNCTION0 31 POP_TOP 32 LOAD_CONST 2 (None) 35 RETURN_VALUE 3 0 LOAD_FAST0 (__locals__) 3 STORE_LOCALS 4 LOAD_NAME0 (__name__) 7 STORE_NAME 1 (__module__) 4 10 LOAD_CLOSURE 0 (__class__) 13 BUILD_TUPLE 1 16 LOAD_CONST 0 () 19 MAKE_CLOSURE 0 22 STORE_NAME 2 (foo) 25 LOAD_CLOSURE 0 (__class__) 28 RETURN_VALUE 5 0 LOAD_GLOBAL 0 (super) 3 CALL_FUNCTION0 6 RETURN_VALUE >>> ___ Python tracker <[EMAIL PROTECTED]> <http://bugs.python.org/issue4360> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6502] documentation error: missing comma between kwonlyargcount & nlocals
New submission from kai zhu : missing comma between kwonlyargcount & nlocals class code(object) | code(argcount, kwonlyargcount nlocals, stacksize, flags, codestring, |constants, names, varnames, filename, name, firstlineno, |lnotab[, freevars[, cellvars]]) -- assignee: georg.brandl components: Documentation messages: 90619 nosy: georg.brandl, kaizhu severity: normal status: open title: documentation error: missing comma between kwonlyargcount & nlocals type: behavior versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue6502> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6504] infinite recursion from calling builtins.open()
New submission from kai zhu : # copy this to test.py # > touch foo.txt # > python3.1 -c "import test; import collections" # > ... # > File "test.py", line 5, in find_module # > def find_module(self, mname, path = None): open("foo.txt") # > File "test.py", line 5, in find_module # > def find_module(self, mname, path = None): open("foo.txt") # > File "test.py", line 5, in find_module # > def find_module(self, mname, path = None): open("foo.txt") # > File "test.py", line 5, in find_module # > def find_module(self, mname, path = None): open("foo.txt") # > RuntimeError: maximum recursion depth exceeded while calling a # > Python object class importer(object): def find_module(self, mname, path = None): open("foo.txt") import sys; sys.meta_path.append(importer) *** # note recursion behavior stops if we don't call open() class importer(object): def find_module(self, mname, path = None): pass import sys; sys.meta_path.append(importer) -- components: IO, Interpreter Core messages: 90627 nosy: kaizhu severity: normal status: open title: infinite recursion from calling builtins.open() type: behavior versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue6504> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6504] infinite recursion from calling builtins.open()
kai zhu added the comment: recursion also goes away if we open as raw bytes: open("foo.txt", "rb"). modes "r+" & "w" also give infinite recursion, while "rb+" & "wb" do not. note found another bug: instance method find_module should raise exception anyway, since its class was uninstantiated in sys.meta_path (proper behavior in python2.6) -- ___ Python tracker <http://bugs.python.org/issue6504> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6509] re.py - encounter unexpected str-object
New submission from kai zhu : >>> import re >>> compiled = re.compile(b"a(\w)") >>> s = b"aa" >>> s = compiled.sub(b"a\\1", s) Traceback (most recent call last): File "", line 1, in File ".../lib/python3.1/re.py", line 303, in filter return sre_parse.expand_template(template, match) File ".../lib/python3.1/sre_parse.py", line 810, in expand_template return sep.join(literals) TypeError: sequence item 0: expected bytes, str found -- components: Library (Lib) messages: 90650 nosy: kaizhu severity: normal status: open title: re.py - encounter unexpected str-object type: behavior versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue6509> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6509] re.py - encounter unexpected str-object
Changes by kai zhu : -- components: +Regular Expressions ___ Python tracker <http://bugs.python.org/issue6509> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6509] re.py - encounter unexpected str-object
kai zhu added the comment: traced culprit to sre_parse.py (where literal is always str): ... def parse_template(source, pattern): # parse 're' replacement string into list of literals and # group references s = Tokenizer(source) sget = s.get p = [] a = p.append def literal(literal, p=p, pappend=a): if p and p[-1][0] is LITERAL: p[-1] = LITERAL, p[-1][1] + literal else: pappend((LITERAL, literal)) ... a possible hack-around is : ... a = p.append def literal(literal, p=p, pappend=a): if isinstance(source, (bytes, bytearray)): # hack literal = literal.encode() # hack str->bytes if p and p[-1][0] is LITERAL: ... -- ___ Python tracker <http://bugs.python.org/issue6509> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6504] infinite recursion from calling builtins.open()
kai zhu added the comment: current hack-around, then is to pre-import locale, which is verified to work: # beg test.py class importer(object): def find_module(self, mname, path = None): open("foo.txt") import sys, locale; sys.meta_path.append(importer) import collections # no recursion # end test.py -- ___ Python tracker <http://bugs.python.org/issue6504> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6239] c_char_p return value returns string, not bytes
kai zhu added the comment: i just found this bug independently, but yes its a bug, which i hope gets fixed for sake of extension community: // test.c beg char s[4] = "ab\xff"; char *foo() { return s; } // test.c end $ gcc -fPIC -g -c -Wall test.c $ gcc -shared test.o -o test.so $ python3.1 -c "import ctypes; lib = ctypes.cdll.LoadLibrary('./test.so'); lib.foo.restype = ctypes.c_char_p; lib.foo()" Traceback (most recent call last): File "", line 1, in UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 2: unexpected code byte -- nosy: +kaizhu ___ Python tracker <http://bugs.python.org/issue6239> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6239] c_char_p return value returns string, not bytes
kai zhu added the comment: wrote an extension application which relies on the patch (works after applying patch to python 3.1.1). it converts png images to colorized ascii-art on ansi-compatible terminal. requires the patch b/c a ctype function returns a c-string w/ ansi-escape characters. >>> import ctypes >>> lib = ctypes.cdll.LoadLibrary("_asciiporn.so") >>> lib.img_read(b"foo.png") // load png image >>> lib.asc_itp(4, 16) // ascii-rize algorithm >>> lib.asc_str.restype = ctypes.c_char_p >>> print( lib.asc_str() ) // prints out ansi-colorized ascii-art hopefully, this is more motivation to commit the patch to trunk -- Added file: http://bugs.python.org/file14768/_asciiporn.c ___ Python tracker <http://bugs.python.org/issue6239> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6239] c_char_p return value returns string, not bytes
Changes by kai zhu : Added file: http://bugs.python.org/file14769/_asciiporn.h ___ Python tracker <http://bugs.python.org/issue6239> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6861] bytearray.__new__ doesn't subclass
New submission from kai zhu : # a00.py parent = bytearray # fails # parent = bytes # works # parent = str # works class Foo(parent): def __new__(klass, x): return parent.__new__(klass, x) Foo(x = None) $ python3.1 -c "import a00" Traceback (most recent call last): File "", line 1, in File "a00.py", line 11, in Foo(x = None) TypeError: 'x' is an invalid keyword argument for this function lethe 3 /tmp/kaizhu/Python-3.1.1: -- components: Interpreter Core, Library (Lib) messages: 92406 nosy: kaizhu severity: normal status: open title: bytearray.__new__ doesn't subclass type: behavior versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue6861> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue6950] online documentation error: PyObject* PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len)
New submission from kai zhu : according to bytearrayobject.c, PyByteArray_Resize should return int (not PyObject *) error found @ http://docs.python.org/dev/py3k/c-api/bytearray.html http://docs.python.org/c-api/bytearray.html -- assignee: georg.brandl components: Documentation messages: 92872 nosy: georg.brandl, kaizhu severity: normal status: open title: online documentation error: PyObject* PyByteArray_Resize(PyObject *bytearray, Py_ssize_t len) versions: Python 2.7, Python 3.2 ___ Python tracker <http://bugs.python.org/issue6950> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue7338] recursive __attribute__ -> Fatal Python error: Cannot recover from stack overflow.
New submission from kai zhu : Python 3.1.1 (r311:74480, Sep 13 2009, 17:17:12) [GCC 4.3.2] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> class Foo(object): ... def __getattribute__(self, attr): ... try: return object.__getattribute__(attr) ... except: return self.x ... >>> Foo().y Fatal Python error: Cannot recover from stack overflow. Aborted $ python2.6 recovers from above w/ a RuntimeError -- components: Interpreter Core messages: 95381 nosy: kaizhu severity: normal status: open title: recursive __attribute__ -> Fatal Python error: Cannot recover from stack overflow. type: crash versions: Python 3.1 ___ Python tracker <http://bugs.python.org/issue7338> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue3555] Regression: nested exceptions crash (Cannot recover from stack overflow)
kai zhu added the comment: just submitted a nearly identical bug (#7338) b4 checking for this one. so u think it works correctly up to the 2nd N+50 check. can someone give a reason y we should crash after that instead of throwing a fallback RuntimeError? -- nosy: +kaizhu ___ Python tracker <http://bugs.python.org/issue3555> ___ ___ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com