1117
1116
if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
1119
if (PyString_Check(format_spec))
1120
return string_int__format__(self, args);
1118
if (PyBytes_Check(format_spec))
1119
return _PyInt_FormatAdvanced(self,
1120
PyBytes_AS_STRING(format_spec),
1121
PyBytes_GET_SIZE(format_spec));
1121
1122
if (PyUnicode_Check(format_spec)) {
1122
1123
/* Convert format_spec to a str */
1123
PyObject *result = NULL;
1124
PyObject *newargs = NULL;
1125
PyObject *string_format_spec = NULL;
1127
string_format_spec = PyObject_Str(format_spec);
1128
if (string_format_spec == NULL)
1131
newargs = Py_BuildValue("(O)", string_format_spec);
1132
if (newargs == NULL)
1135
result = string_int__format__(self, newargs);
1138
Py_XDECREF(string_format_spec);
1139
Py_XDECREF(newargs);
1125
PyObject *str_spec = PyObject_Str(format_spec);
1127
if (str_spec == NULL)
1130
result = _PyInt_FormatAdvanced(self,
1131
PyBytes_AS_STRING(str_spec),
1132
PyBytes_GET_SIZE(str_spec));
1134
Py_DECREF(str_spec);
1142
1137
PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");