Author: Alex Gaynor <[email protected]>
Branch: stdlib-2.7.8
Changeset: r73103:4cde5141989b
Date: 2014-08-27 14:11 -0700
http://bitbucket.org/pypy/pypy/changeset/4cde5141989b/
Log: Fix one of the two remaining tcl bugs
diff --git a/lib_pypy/_tkinter/app.py b/lib_pypy/_tkinter/app.py
--- a/lib_pypy/_tkinter/app.py
+++ b/lib_pypy/_tkinter/app.py
@@ -2,7 +2,7 @@
from .tklib import tklib, tkffi
from . import TclError
-from .tclobj import TclObject, FromObj, AsObj, TypeCache
+from .tclobj import TclObject, FromObj, FromTclString, AsObj, TypeCache
import contextlib
import sys
@@ -55,7 +55,7 @@
assert self.app.interp == interp
with self.app._tcl_lock_released():
try:
- args = [tkffi.string(arg) for arg in argv[1:argc]]
+ args = [FromTclString(tkffi.string(arg)) for arg in
argv[1:argc]]
result = self.func(*args)
obj = AsObj(result)
tklib.Tcl_SetObjResult(interp, obj)
diff --git a/lib_pypy/_tkinter/tclobj.py b/lib_pypy/_tkinter/tclobj.py
--- a/lib_pypy/_tkinter/tclobj.py
+++ b/lib_pypy/_tkinter/tclobj.py
@@ -13,26 +13,29 @@
self.StringType = tklib.Tcl_GetObjType("string")
+def FromTclString(s):
+ # If the result contains any bytes with the top bit set, it's
+ # UTF-8 and we should decode it to Unicode.
+ try:
+ s.decode('ascii')
+ except UnicodeDecodeError:
+ try:
+ return s.decode('utf8')
+ except UnicodeDecodeError:
+ # Tcl encodes null character as \xc0\x80
+ try:
+ return s.replace('\xc0\x80', '\x00').decode('utf-8')
+ except UnicodeDecodeError:
+ pass
+ return s
+
+
def FromObj(app, value):
"""Convert a TclObj pointer into a Python object."""
typeCache = app._typeCache
if not value.typePtr:
buf = tkffi.buffer(value.bytes, value.length)
- result = buf[:]
- # If the result contains any bytes with the top bit set, it's
- # UTF-8 and we should decode it to Unicode.
- try:
- result.decode('ascii')
- except UnicodeDecodeError:
- try:
- result = result.decode('utf8')
- except UnicodeDecodeError:
- # Tcl encodes null character as \xc0\x80
- try:
- result = result.replace('\xc0\x80', '\x00').decode('utf-8')
- except UnicodeDecodeError:
- pass
- return result
+ return FromTclString(buf[:])
elif value.typePtr == typeCache.BooleanType:
return bool(value.internalRep.longValue)
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit