@@ -6236,12 +6236,28 @@ datetime_str(PyDateTime_DateTime *self)
6236
6236
return res ;
6237
6237
}
6238
6238
6239
+ /*[clinic input]
6240
+ datetime.datetime.isoformat
6241
+
6242
+ defcls: defining_class
6243
+ sep: int(accept={str}, c_default="'T'", py_default="'T'") = 0
6244
+ timespec: str = NULL
6245
+
6246
+ [sep] -> string in ISO 8601 format,
6247
+
6248
+ YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].
6249
+ sep is used to separate the year from the time, and defaults to 'T'.
6250
+ The optional argument timespec specifies the number of additional terms
6251
+ of the time to include. Valid options are 'auto', 'hours', 'minutes',
6252
+ 'seconds', 'milliseconds' and 'microseconds'.
6253
+ [clinic start generated code]*/
6254
+
6239
6255
static PyObject *
6240
- datetime_isoformat (PyDateTime_DateTime * self , PyObject * args , PyObject * kw )
6256
+ datetime_datetime_isoformat_impl (PyDateTime_DateTime * self ,
6257
+ PyTypeObject * defcls , int sep ,
6258
+ const char * timespec )
6259
+ /*[clinic end generated code: output=d7968a085a5f38c7 input=dbd22819421fe7be]*/
6241
6260
{
6242
- int sep = 'T' ;
6243
- char * timespec = NULL ;
6244
- static char * keywords [] = {"sep" , "timespec" , NULL };
6245
6261
char buffer [100 ];
6246
6262
PyObject * result = NULL ;
6247
6263
int us = DATE_GET_MICROSECOND (self );
@@ -6254,9 +6270,6 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
6254
6270
};
6255
6271
size_t given_spec ;
6256
6272
6257
- if (!PyArg_ParseTupleAndKeywords (args , kw , "|Cs:isoformat" , keywords , & sep , & timespec ))
6258
- return NULL ;
6259
-
6260
6273
if (timespec == NULL || strcmp (timespec , "auto" ) == 0 ) {
6261
6274
if (us == 0 ) {
6262
6275
/* seconds */
@@ -6294,7 +6307,7 @@ datetime_isoformat(PyDateTime_DateTime *self, PyObject *args, PyObject *kw)
6294
6307
return result ;
6295
6308
6296
6309
/* We need to append the UTC offset. */
6297
- datetime_state * st = find_module_state_by_def ( Py_TYPE ( self ) );
6310
+ datetime_state * st = get_module_state_by_cls ( defcls );
6298
6311
if (format_utcoffset (st , buffer , sizeof (buffer ), ":" , self -> tzinfo ,
6299
6312
(PyObject * )self ) < 0 ) {
6300
6313
Py_DECREF (result );
@@ -7056,16 +7069,7 @@ static PyMethodDef datetime_methods[] = {
7056
7069
{"utctimetuple" , (PyCFunction )datetime_utctimetuple , METH_NOARGS ,
7057
7070
PyDoc_STR ("Return UTC time tuple, compatible with time.localtime()." )},
7058
7071
7059
- {"isoformat" , _PyCFunction_CAST (datetime_isoformat ), METH_VARARGS | METH_KEYWORDS ,
7060
- PyDoc_STR ("[sep] -> string in ISO 8601 format, "
7061
- "YYYY-MM-DDT[HH[:MM[:SS[.mmm[uuu]]]]][+HH:MM].\n"
7062
- "sep is used to separate the year from the time, and "
7063
- "defaults to 'T'.\n"
7064
- "The optional argument timespec specifies the number "
7065
- "of additional terms\nof the time to include. Valid "
7066
- "options are 'auto', 'hours', 'minutes',\n'seconds', "
7067
- "'milliseconds' and 'microseconds'.\n" )},
7068
-
7072
+ DATETIME_DATETIME_ISOFORMAT_METHODDEF
7069
7073
DATETIME_DATETIME_UTCOFFSET_METHODDEF
7070
7074
DATETIME_DATETIME_TZNAME_METHODDEF
7071
7075
DATETIME_DATETIME_DST_METHODDEF
0 commit comments