[Python-checkins] python/dist/src/Lib/test test_builtin.py,1.6,1.7
doerwalter@users.sourceforge.net
doerwalter@users.sourceforge.net
Tue, 04 Feb 2003 08:28:02 -0800
Update of /cvsroot/python/python/dist/src/Lib/test
In directory sc8-pr-cvs1:/tmp/cvs-serv5503/Lib/test
Modified Files:
test_builtin.py
Log Message:
filterstring() and filterunicode() in Python/bltinmodule.c
blindly assumed that tp_as_sequence->sq_item always returns
a str or unicode object. This might fail with str or unicode
subclasses.
This patch checks whether the object returned from __getitem__
is a str/unicode object and raises a TypeError if not (and
the filter function returned true).
Furthermore the result for __getitem__ can be more than one
character long, so checks for enough memory have to be done.
Index: test_builtin.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_builtin.py,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** test_builtin.py 28 Jan 2003 19:21:18 -0000 1.6
--- test_builtin.py 4 Feb 2003 16:28:00 -0000 1.7
***************
*** 368,371 ****
--- 368,381 ----
self.assertRaises(ValueError, filter, lambda x: x >="3", badstr("1234"))
+ class badstr2(str):
+ def __getitem__(self, index):
+ return 42
+ self.assertRaises(TypeError, filter, lambda x: x >=42, badstr2("1234"))
+
+ class weirdstr(str):
+ def __getitem__(self, index):
+ return weirdstr(2*str.__getitem__(self, index))
+ self.assertEqual(filter(lambda x: x>="33", weirdstr("1234")), "3344")
+
if have_unicode:
# test bltinmodule.c::filterunicode()
***************
*** 374,377 ****
--- 384,398 ----
self.assertRaises(TypeError, filter, 42, unicode("12"))
self.assertRaises(ValueError, filter, lambda x: x >="3", badstr(unicode("1234")))
+
+ class badunicode(unicode):
+ def __getitem__(self, index):
+ return 42
+ self.assertRaises(TypeError, filter, lambda x: x >=42, badunicode("1234"))
+
+ class weirdunicode(unicode):
+ def __getitem__(self, index):
+ return weirdunicode(2*unicode.__getitem__(self, index))
+ self.assertEqual(
+ filter(lambda x: x>=unicode("33"), weirdunicode("1234")), unicode("3344"))
def test_float(self):