[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[pygame] PATCH: fix printing of event in python3



The attached patch FIXES the bug described below.

BUG description:
Using python3, print(event) raises UnicodeEncodeError,
if event.unicode cannot be represented in ASCII.

Example:
$ python3
>>> import pygame
>>> pygame.display.set_mode((640, 480))
>>> while True:
...     for event in pygame.event.get():
...         print(event)
[ user presses a key that cannot be represented in ASCII, like: őüöóúűáí ]
UnicodeEncodeError: 'ascii' codec can't encode character '\xed' in position 13:
ordinal not in range(128)
Index: event.c
===================================================================
--- event.c	(revision 3193)
+++ event.c	(working copy)
@@ -392,7 +392,7 @@
         return NULL;
     }
 #if PY3
-    encodedobj = PyUnicode_AsASCIIString (strobj);
+    encodedobj = PyUnicode_AsUTF8String (strobj);
     Py_DECREF (strobj);
     strobj = encodedobj;
     encodedobj = NULL;