#check that this standard extension works
t.strftime("%f")
+ def test_strftime_trailing_percent(self):
+ # bpo-35066: make sure trailing '%' doesn't cause
+ # datetime's strftime to complain
+ t = self.theclass(2005, 3, 2)
+ try:
+ _time.strftime('%')
+ except ValueError:
+ self.skipTest('time module does not support trailing %')
+ self.assertEqual(t.strftime('%'), '%')
+ self.assertEqual(t.strftime("m:%m d:%d y:%y %"), "m:03 d:02 y:05 %")
+
def test_format(self):
dt = self.theclass(2007, 9, 10)
self.assertEqual(dt.__format__(''), str(dt))
--- /dev/null
+Previously, calling the strftime() method on a datetime object with a
+trailing '%' in the format string would result in an exception. However,
+this only occured when the datetime C module was being used; the python
+implementation did not match this behavior. Datetime is now PEP-399
+compliant, and will not throw an exception on a trailing '%'.
ntoappend = 1;
}
else if ((ch = *pin++) == '\0') {
- /* There's a lone trailing %; doesn't make sense. */
- PyErr_SetString(PyExc_ValueError, "strftime format "
- "ends with raw %");
- goto Done;
+ /* Null byte follows %, copy only '%'.
+ *
+ * Back the pin up one char so that we catch the null check
+ * the next time through the loop.*/
+ pin--;
+ ptoappend = pin - 1;
+ ntoappend = 1;
}
/* A % has been seen and ch is the character after it. */
else if (ch == 'z') {
usednew += ntoappend;
assert(usednew <= totalnew);
} /* end while() */
-
+
if (_PyBytes_Resize(&newfmt, usednew) < 0)
goto Done;
{