~pythonregexp2.7/python/issue2636-12

« back to all changes in this revision

Viewing changes to Objects/intobject.c

  • Committer: Jeffrey C. "The TimeHorse" Jacobs
  • Date: 2008-06-09 14:52:42 UTC
  • mfrom: (39033.1.3 Regexp-2.6)
  • Revision ID: darklord@timehorse.com-20080609145242-9m268zc6u87rp1vp
Merged in changes from the core Regexp branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
 
4
4
#include "Python.h"
5
5
#include <ctype.h>
6
 
#include "formatter_string.h"
7
6
 
8
7
static PyObject *int_int(PyIntObject *v);
9
8
 
1116
1115
 
1117
1116
        if (!PyArg_ParseTuple(args, "O:__format__", &format_spec))
1118
1117
                return NULL;
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;
1126
 
 
1127
 
                string_format_spec = PyObject_Str(format_spec);
1128
 
                if (string_format_spec == NULL)
1129
 
                        goto done;
1130
 
 
1131
 
                newargs = Py_BuildValue("(O)", string_format_spec);
1132
 
                if (newargs == NULL)
1133
 
                        goto done;
1134
 
 
1135
 
                result = string_int__format__(self, newargs);
1136
 
 
1137
 
                done:
1138
 
                Py_XDECREF(string_format_spec);
1139
 
                Py_XDECREF(newargs);
 
1124
                PyObject *result;
 
1125
                PyObject *str_spec = PyObject_Str(format_spec);
 
1126
 
 
1127
                if (str_spec == NULL)
 
1128
                        return NULL;
 
1129
 
 
1130
                result = _PyInt_FormatAdvanced(self,
 
1131
                                               PyBytes_AS_STRING(str_spec),
 
1132
                                               PyBytes_GET_SIZE(str_spec));
 
1133
 
 
1134
                Py_DECREF(str_spec);
1140
1135
                return result;
1141
1136
        }
1142
1137
        PyErr_SetString(PyExc_TypeError, "__format__ requires str or unicode");