[Python-checkins] r54145 - sandbox/trunk/pep3101/test_simpleformat.py sandbox/trunk/pep3101/unicodeformat.c
patrick.maupin
python-checkins at python.org
Tue Mar 6 04:58:52 CET 2007
Author: patrick.maupin
Date: Tue Mar 6 04:58:48 2007
New Revision: 54145
Modified:
sandbox/trunk/pep3101/test_simpleformat.py
sandbox/trunk/pep3101/unicodeformat.c
Log:
Added some tests, squashed a recursion bug and fixed an error message
Modified: sandbox/trunk/pep3101/test_simpleformat.py
==============================================================================
--- sandbox/trunk/pep3101/test_simpleformat.py (original)
+++ sandbox/trunk/pep3101/test_simpleformat.py Tue Mar 6 04:58:48 2007
@@ -300,12 +300,9 @@
self.formatRaises(ValueError, "}{", True)
self.formatRaises(ValueError, "{0", True)
self.formatRaises(ValueError, "{0.[]}", True)
- # XXX: these raise the wrong exceptions
- #self.formatRaises(ValueError, "{0[0}", True)
- #self.formatRaises(ValueError, "{0[0:foo}", True)
+ self.formatRaises(ValueError, "{0[0}", [1])
+ self.formatRaises(ValueError, "{0[0:foo}", [1])
self.formatRaises(ValueError, "{c]}", True)
- # XXX: this should *not* raise
- #self.formatRaises(ValueError, "{{1}}", True, 0)
self.formatRaises(ValueError, "{{ {{{0}}", True)
self.formatRaises(ValueError, "{0}}", True)
@@ -387,6 +384,15 @@
self.formatRaises(ValueError, '{!syntax3}{')
self.formatEquals('{', '{!syntax3}{ ')
+ def test_computed_lookups(self):
+ class Custom(object):
+ fred = 'Hi there'
+ self.formatEquals('e', '{0[{1}]}', 'abcdefg', 4)
+ self.formatEquals('e', '{foo[{bar}]}', foo='abcdefg', bar=4)
+ self.formatEquals(Custom.fred, '{0.{1}}', Custom, 'fred')
+ self.formatEquals(Custom.fred, '{x.{y}}', x=Custom, y='fred')
+ self.formatEquals('t', '{x.{y}[{0}]}', 3, x=Custom, y='fred')
+
def test_main():
test_support.run_unittest(FormatTest)
Modified: sandbox/trunk/pep3101/unicodeformat.c
==============================================================================
--- sandbox/trunk/pep3101/unicodeformat.c (original)
+++ sandbox/trunk/pep3101/unicodeformat.c Tue Mar 6 04:58:48 2007
@@ -572,6 +572,7 @@
/* This little bit of mutual recursion allows nested dictionary
lookups and computed attribute names
*/
+ fs->fmtstr.ptr++;
if (--(fs->max_recursion) < 0)
return SetError(fs, "Maximum string recursion limit exceeded");
result = get_field_object(fs);
@@ -1968,7 +1969,7 @@
at_end = ptr >= end;
switch (syntaxmode) {
case 0:
- if ((c == '}') && (!at_end) && (c != *ptr))
+ if ((c == '}') && (at_end || (c != *ptr)))
return (int)SetError(fs, "Single } encountered");
case 1:
if (at_end)
More information about the Python-checkins
mailing list