@@ -1506,6 +1506,32 @@ format_utcoffset(char *buf, size_t buflen, const char *sep,
1506
1506
return 0 ;
1507
1507
}
1508
1508
1509
+ static PyObject *
1510
+ make_somezreplacement (PyObject * object , char * sep , PyObject * tzinfoarg )
1511
+ {
1512
+ char buf [100 ];
1513
+ PyObject * tzinfo = get_tzinfo_member (object );
1514
+ PyObject * replacement = PyBytes_FromStringAndSize (NULL , 0 );
1515
+
1516
+ if (replacement == NULL )
1517
+ return NULL ;
1518
+ if (tzinfo == Py_None || tzinfo == NULL )
1519
+ return replacement ;
1520
+
1521
+ Py_DECREF (replacement );
1522
+
1523
+ assert (tzinfoarg != NULL );
1524
+ if (format_utcoffset (buf ,
1525
+ sizeof (buf ),
1526
+ sep ,
1527
+ tzinfo ,
1528
+ tzinfoarg ) < 0 )
1529
+ return NULL ;
1530
+
1531
+ replacement = PyBytes_FromStringAndSize (buf , strlen (buf ));
1532
+ return replacement ;
1533
+ }
1534
+
1509
1535
static PyObject *
1510
1536
make_Zreplacement (PyObject * object , PyObject * tzinfoarg )
1511
1537
{
@@ -1644,26 +1670,10 @@ wrap_strftime(PyObject *object, PyObject *format, PyObject *timetuple,
1644
1670
replacement_p = & zreplacement ;
1645
1671
}
1646
1672
if (* replacement_p == NULL ) {
1647
- /* format utcoffset */
1648
- char buf [100 ];
1649
- PyObject * tzinfo = get_tzinfo_member (object );
1650
- * replacement_p = PyBytes_FromStringAndSize ("" , 0 );
1651
- if (* replacement_p == NULL ) goto Done ;
1652
- if (tzinfo != Py_None && tzinfo != NULL ) {
1653
- assert (tzinfoarg != NULL );
1654
- if (format_utcoffset (buf ,
1655
- sizeof (buf ),
1656
- sep ,
1657
- tzinfo ,
1658
- tzinfoarg ) < 0 )
1659
- goto Done ;
1660
- Py_DECREF (* replacement_p );
1661
- * replacement_p =
1662
- PyBytes_FromStringAndSize (buf ,
1663
- strlen (buf ));
1664
- if (* replacement_p == NULL )
1665
- goto Done ;
1666
- }
1673
+ * replacement_p = make_somezreplacement (object ,
1674
+ sep , tzinfoarg );
1675
+ if (* replacement_p == NULL )
1676
+ goto Done ;
1667
1677
}
1668
1678
assert (* replacement_p != NULL );
1669
1679
assert (PyBytes_Check (* replacement_p ));
0 commit comments