[Python-checkins] r54135 - sandbox/trunk/pep3101/test_simpleformat.py sandbox/trunk/pep3101/unicodeformat.c
patrick.maupin
python-checkins at python.org
Mon Mar 5 07:34:26 CET 2007
Author: patrick.maupin
Date: Mon Mar 5 07:34:22 2007
New Revision: 54135
Modified:
sandbox/trunk/pep3101/test_simpleformat.py
sandbox/trunk/pep3101/unicodeformat.c
Log:
More alt-syntax checks and a fix for markup escape at string end on syntax 2
Modified: sandbox/trunk/pep3101/test_simpleformat.py
==============================================================================
--- sandbox/trunk/pep3101/test_simpleformat.py (original)
+++ sandbox/trunk/pep3101/test_simpleformat.py Mon Mar 5 07:34:22 2007
@@ -318,11 +318,22 @@
def test_alt_syntax(self):
self.formatEquals('{}1', '{!syntax1}{{}{0}', 1)
- self.formatEquals('{ ${ 1 $1 $${0}',
- '{!syntax2}{ $${ ${0} $$${0} $$$${0}',
+ self.formatEquals('{ ${ 1 $1 $${0} ${',
+ '{!syntax2}{ $${ ${0} $$${0} $$$${0} $${',
1)
self.formatEquals('1 {0} {\n0}',
'{!syntax3}{0} { 0} {\n0}', 1)
+ self.formatRaises(ValueError, '}')
+ self.formatRaises(ValueError, '{')
+ self.formatEquals('}', '{!syntax1}}')
+ self.formatRaises(ValueError, '{!syntax1}{')
+ self.formatEquals('}', '{!syntax2}}')
+ self.formatEquals('{', '{!syntax2}{')
+ self.formatRaises(ValueError, '{!syntax1}${')
+ self.formatEquals('${', '{!syntax2}$${')
+ self.formatEquals('}', '{!syntax3}}')
+ self.formatRaises(ValueError, '{!syntax3}{')
+ self.formatEquals('{', '{!syntax3}{ ')
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 Mon Mar 5 07:34:22 2007
@@ -1729,7 +1729,7 @@
{
CH_TYPE c, *start, *ptr, *end;
Py_ssize_t count;
- int syntaxmode, escape;
+ int syntaxmode, escape, at_end;
end = fs->fmtstr.end;
syntaxmode = fs->syntaxmode;
@@ -1753,61 +1753,61 @@
escape = 1;
break;
}
+ fs->fmtstr.ptr = ptr;
count = ptr - start;
- if (ptr < end) {
- switch (syntaxmode) {
- case 0:
- if ((c == '}') && (c != *ptr)) {
- fs->fmtstr.ptr = ptr;
- return (int)SetError(fs, "Single } encountered");
- }
- case 1:
- if (c == *ptr) {
- ptr++;
- escape = 0;
- }
- else
- count--;
- break;
- case 2: {
- CH_TYPE *first_dollar = ptr - 2;
- int num_dollars;
- while ((first_dollar > start) &&
- (first_dollar[-1] == '$'))
- first_dollar--;
- num_dollars = ptr - 1 - first_dollar;
- count = first_dollar - start + (num_dollars / 2);
- escape = num_dollars & 1;
- if (!escape)
- ptr--;
+ at_end = ptr >= end;
+ switch (syntaxmode) {
+ case 0:
+ if ((c == '}') && (!at_end) && (c != *ptr))
+ return (int)SetError(fs, "Single } encountered");
+ case 1:
+ if (at_end)
break;
+ if (c == *ptr) {
+ fs->fmtstr.ptr++;
+ escape = 0;
}
- case 3:
- switch (*ptr) {
- case ' ':
- ptr++;
- case '\n': case '\r':
- escape = 0;
- break;
- default:
- count--;
- break;
- }
+ else
+ count--;
+ break;
+ case 2: {
+ CH_TYPE *first_dollar = ptr - 2;
+ int num_dollars;
+ if (!escape)
break;
- default:
- fs->fmtstr.ptr = ptr;
- return (int)SetError(fs, "Unsupported syntax mode");
+ while ((first_dollar > start) &&
+ (first_dollar[-1] == '$'))
+ first_dollar--;
+ num_dollars = ptr - 1 - first_dollar;
+ count = first_dollar - start + (num_dollars / 2);
+ escape = num_dollars & 1;
+ if (!escape)
+ fs->fmtstr.ptr--;
+ break;
}
- }
- else if (escape) {
- fs->fmtstr.ptr = ptr;
- return (int)SetError(fs, "Unexpected escape to markup");
+ case 3:
+ if (at_end)
+ break;
+ switch (*ptr) {
+ case ' ':
+ fs->fmtstr.ptr++;
+ case '\n': case '\r':
+ escape = 0;
+ break;
+ default:
+ count--;
+ break;
+ }
+ break;
+ default:
+ return (int)SetError(fs, "Unsupported syntax mode");
}
- fs->fmtstr.ptr = ptr;
if (count && !output_data(fs, start, count))
return 0;
if (escape) {
+ if (at_end)
+ return (int)SetError(fs, "Unexpected escape to markup");
if (!get_field_and_render(fs))
return 0;
else
More information about the Python-checkins
mailing list