[Tutor] PyInit__tkinter fails with UnicodeEncodeError

lakshman.sah at wipro.com lakshman.sah at wipro.com
Tue Sep 15 14:41:31 CEST 2009


Hi,

 

I have a standalone python executable created using PyInstaller
(modified to support Python 3) on Linux. This executable was running
well with Python 3.0.1. But on Python 3.1.1 it is breaking with
UnicodeEncodeError. 

Executable created with same code on Windows it is running without any
error.

 

After debugging the Python code I found that the PyInit__tkinter in file
_tkinter.c is not able to encode the executable name or path when it
finds characters other than 'a' ('A') through 'p' ('P') at position
multiple of 4 (0 based).

For example if my executable name is "setup" it finds 's' at the
position 0 and breaks with UnicodeEncodeError. 

NOTE: If I change the name to "etup" (removed 's') it is executing well.
And also if I replace 's' with any character 'a' through 'p' it is
working.

 

This is happening because here by default 'strict' error handler is
being used.

 

I tried to play a little with the Python code. And modified
PyInit__tkinter() to used "surrogatepass" error handler while it is
encoding the Unicode string with utf-8 encoding.

i.e. I replaced 

 

cexe = PyUnicode_AsEncodeString(uexe,Py_FileSystemDefaultEncoding,NULL);

 

with

 

cexe = PyUnicode_AsEncodeString(uexe,Py_FileSystemDefaultEncoding,
"surrogatepass");

 

My executable started running without changing its name.

 

I have no idea whether this is a feature or bug in PyInit__tkinter().

 

Is there any way I can specify PyInit__tkinter to use "surrogatepass"
instead of "strict" error handler.

 

Please help me with your suggestions.

 

Thanks,

Lakshman


Please do not print this email unless it is absolutely necessary. 

The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. 

WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. 

www.wipro.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090915/81e67158/attachment.htm>


More information about the Tutor mailing list