Commits

Lenard Lindstrom  committed 0e6b422

BUG: fix problem with Event.__repr__ reported on Pygame mailing list on July 24, 2011; thanks Dávid Gábor

  • Participants
  • Parent commits 636a34b

Comments (0)

Files changed (2)

         return NULL;
     }
 #if PY3
-    encodedobj = PyUnicode_AsASCIIString (strobj);
+    encodedobj = PyUnicode_AsUTF8String (strobj);
     Py_DECREF (strobj);
     strobj = encodedobj;
     encodedobj = NULL;

File test/event_test.py

 else:
     from test.test_utils import test_not_implemented, unittest
 import pygame
+from pygame.compat import as_unicode
 
 ################################################################################
 
         self.assert_('other_attr' in d)
         self.assert_('new_attr' in d)
 
+    def test_as_str(self):
+        # Bug reported on Pygame mailing list July 24, 2011:
+        # For Python 3.x str(event) to raises an UnicodeEncodeError when
+        # an event attribute is a string with a non-ascii character.
+        try:
+            str(pygame.event.Event(1, a=as_unicode(r"\xed")))
+        except UnicodeEncodeError:
+            self.fail("Event object raised exception for non-ascii character")
+        # Passed.
+
+
 race_condition_notification = """
 This test is dependent on timing. The event queue is cleared in preparation for 
 tests. There is a small window where outside events from the OS may have effected