@@ -1848,23 +1848,13 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
18481848 const char * ptoappend ; /* ptr to string to append to output buffer */
18491849 Py_ssize_t ntoappend ; /* # of bytes to append to output buffer */
18501850
1851- #ifdef Py_NORMALIZE_CENTURY
1852- /* Buffer of maximum size of formatted year permitted by long. */
1853- char buf [SIZEOF_LONG * 5 /2 + 2 ];
1854- #endif
1855-
18561851 assert (object && format && timetuple );
18571852 assert (PyUnicode_Check (format ));
18581853 /* Convert the input format to a C string and size */
18591854 pin = PyUnicode_AsUTF8AndSize (format , & flen );
18601855 if (!pin )
18611856 return NULL ;
18621857
1863- PyObject * strftime = _PyImport_GetModuleAttrString ("time" , "strftime" );
1864- if (strftime == NULL ) {
1865- goto Done ;
1866- }
1867-
18681858 /* Scan the input format, looking for %z/%Z/%f escapes, building
18691859 * a new format. Since computing the replacements for those codes
18701860 * is expensive, don't unless they're actually used.
@@ -1946,47 +1936,8 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
19461936 ptoappend = PyBytes_AS_STRING (freplacement );
19471937 ntoappend = PyBytes_GET_SIZE (freplacement );
19481938 }
1949- #ifdef Py_NORMALIZE_CENTURY
1950- else if (ch == 'Y' || ch == 'G' ) {
1951- /* 0-pad year with century as necessary */
1952- PyObject * item = PyTuple_GET_ITEM (timetuple , 0 );
1953- long year_long = PyLong_AsLong (item );
1954-
1955- if (year_long == -1 && PyErr_Occurred ()) {
1956- goto Done ;
1957- }
1958- /* Note that datetime(1000, 1, 1).strftime('%G') == '1000' so year
1959- 1000 for %G can go on the fast path. */
1960- if (year_long >= 1000 ) {
1961- goto PassThrough ;
1962- }
1963- if (ch == 'G' ) {
1964- PyObject * year_str = PyObject_CallFunction (strftime , "sO" ,
1965- "%G" , timetuple );
1966- if (year_str == NULL ) {
1967- goto Done ;
1968- }
1969- PyObject * year = PyNumber_Long (year_str );
1970- Py_DECREF (year_str );
1971- if (year == NULL ) {
1972- goto Done ;
1973- }
1974- year_long = PyLong_AsLong (year );
1975- Py_DECREF (year );
1976- if (year_long == -1 && PyErr_Occurred ()) {
1977- goto Done ;
1978- }
1979- }
1980-
1981- ntoappend = PyOS_snprintf (buf , sizeof (buf ), "%04ld" , year_long );
1982- ptoappend = buf ;
1983- }
1984- #endif
19851939 else {
19861940 /* percent followed by something else */
1987- #ifdef Py_NORMALIZE_CENTURY
1988- PassThrough :
1989- #endif
19901941 ptoappend = pin - 2 ;
19911942 ntoappend = 2 ;
19921943 }
@@ -2018,21 +1969,24 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
20181969 goto Done ;
20191970 {
20201971 PyObject * format ;
1972+ PyObject * strftime = _PyImport_GetModuleAttrString ("time" , "strftime" );
20211973
1974+ if (strftime == NULL )
1975+ goto Done ;
20221976 format = PyUnicode_FromString (PyBytes_AS_STRING (newfmt ));
20231977 if (format != NULL ) {
20241978 result = PyObject_CallFunctionObjArgs (strftime ,
20251979 format , timetuple , NULL );
20261980 Py_DECREF (format );
20271981 }
1982+ Py_DECREF (strftime );
20281983 }
20291984 Done :
20301985 Py_XDECREF (freplacement );
20311986 Py_XDECREF (zreplacement );
20321987 Py_XDECREF (colonzreplacement );
20331988 Py_XDECREF (Zreplacement );
20341989 Py_XDECREF (newfmt );
2035- Py_XDECREF (strftime );
20361990 return result ;
20371991}
20381992
0 commit comments