r66624 - in python/trunk/Lib: collections.py test/test_collections.py
Author: raymond.hettinger Date: Fri Sep 26 01:31:52 2008 New Revision: 66624 Log: Fix namedtuple bug reported by Glenn Linderman. Template did not form correctly if the field names were input in Unicode. Modified: python/trunk/Lib/collections.py python/trunk/Lib/test/test_collections.py Modified: python/trunk/Lib/collections.py ============================================================================== --- python/trunk/Lib/collections.py (original) +++ python/trunk/Lib/collections.py Fri Sep 26 01:31:52 2008 @@ -38,7 +38,7 @@ # generating informative error messages and preventing template injection attacks. if isinstance(field_names, basestring): field_names = field_names.replace(',', ' ').split() # names separated by whitespace and/or commas - field_names = tuple(field_names) + field_names = tuple(map(str, field_names)) for name in (typename,) + field_names: if not all(c.isalnum() or c=='_' for c in name): raise ValueError('Type names and field names can only contain alphanumeric characters and underscores: %r' % name) Modified: python/trunk/Lib/test/test_collections.py ============================================================================== --- python/trunk/Lib/test/test_collections.py (original) +++ python/trunk/Lib/test/test_collections.py Fri Sep 26 01:31:52 2008 @@ -34,6 +34,11 @@ namedtuple('Point0', 'x1 y2') # Verify that numbers are allowed in names namedtuple('_', 'a b c') # Test leading underscores in a typename + nt = namedtuple('nt', u'the quick brown fox') # check unicode input + self.assert_("u'" not in repr(nt._fields)) + nt = namedtuple('nt', (u'the', u'quick')) # check unicode input + self.assert_("u'" not in repr(nt._fields)) + self.assertRaises(TypeError, Point._make, [11]) # catch too few args self.assertRaises(TypeError, Point._make, [11, 22, 33]) # catch too many args
participants (1)
-
raymond.hettinger