summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorChristian Heimes <christian@cheimes.de>2008-02-24 13:08:18 (GMT)
committerChristian Heimes <christian@cheimes.de>2008-02-24 13:08:18 (GMT)
commita612dc02ced728f553dcc91ca557a2a8b7fa0ca6 (patch)
tree62b717da0813ba63b61537d380ea923a1e657b3d /Objects
parent8e21a3cf059aa8195716f6e7d3bfd0602daca6f1 (diff)
downloadcpython-a612dc02ced728f553dcc91ca557a2a8b7fa0ca6.zip
cpython-a612dc02ced728f553dcc91ca557a2a8b7fa0ca6.tar.gz
cpython-a612dc02ced728f553dcc91ca557a2a8b7fa0ca6.tar.bz2
Merged revisions 61034-61036,61038-61048 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r61034 | georg.brandl | 2008-02-24 01:03:22 +0100 (Sun, 24 Feb 2008) | 4 lines #900744: If an invalid chunked-encoding header is sent by a server, httplib will now raise IncompleteRead and close the connection instead of raising ValueError. ........ r61035 | georg.brandl | 2008-02-24 01:14:24 +0100 (Sun, 24 Feb 2008) | 2 lines #1627: httplib now ignores negative Content-Length headers. ........ r61039 | andrew.kuchling | 2008-02-24 03:39:15 +0100 (Sun, 24 Feb 2008) | 1 line Remove stray word ........ r61040 | neal.norwitz | 2008-02-24 03:40:58 +0100 (Sun, 24 Feb 2008) | 3 lines Add a little info to the 3k deprecation warnings about what to use instead. Suggested by Raymond Hettinger. ........ r61041 | facundo.batista | 2008-02-24 04:17:21 +0100 (Sun, 24 Feb 2008) | 4 lines Issue 1742669. Now %d accepts very big float numbers. Thanks Gabriel Genellina. ........ r61046 | neal.norwitz | 2008-02-24 08:21:56 +0100 (Sun, 24 Feb 2008) | 5 lines Get ctypes working on the Alpha (Tru64). The problem was that there were two module_methods and the one used depended on the order the modules were loaded. By making the test module_methods static, it is not exported and the correct version is picked up. ........ r61048 | neal.norwitz | 2008-02-24 09:27:49 +0100 (Sun, 24 Feb 2008) | 1 line Fix typo of hexidecimal ........
Diffstat (limited to 'Objects')
-rw-r--r--Objects/unicodeobject.c44
1 files changed, 31 insertions, 13 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
index 86d8b54..7359821 100644
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -8600,6 +8600,7 @@ PyObject *PyUnicode_Format(PyObject *format,
int prec = -1;
Py_UNICODE c = '\0';
Py_UNICODE fill;
+ int isnumok;
PyObject *v = NULL;
PyObject *temp = NULL;
Py_UNICODE *pbuf;
@@ -8804,21 +8805,38 @@ PyObject *PyUnicode_Format(PyObject *format,
case 'X':
if (c == 'i')
c = 'd';
- if (PyLong_Check(v)) {
- temp = formatlong(v, flags, prec, c);
- if (!temp)
- goto onError;
- pbuf = PyUnicode_AS_UNICODE(temp);
- len = PyUnicode_GET_SIZE(temp);
- sign = 1;
+ isnumok = 0;
+ if (PyNumber_Check(v)) {
+ PyObject *iobj=NULL;
+
+ if (PyLong_Check(v)) {
+ iobj = v;
+ Py_INCREF(iobj);
+ }
+ else {
+ iobj = PyNumber_Long(v);
+ }
+ if (iobj!=NULL) {
+ if (PyLong_Check(iobj)) {
+ isnumok = 1;
+ temp = formatlong(iobj, flags, prec, c);
+ Py_DECREF(iobj);
+ if (!temp)
+ goto onError;
+ pbuf = PyUnicode_AS_UNICODE(temp);
+ len = PyUnicode_GET_SIZE(temp);
+ sign = 1;
+ }
+ else {
+ Py_DECREF(iobj);
+ }
+ }
}
- else {
- pbuf = formatbuf;
- len = formatint(pbuf, sizeof(formatbuf)/sizeof(Py_UNICODE),
- flags, prec, c, v);
- if (len < 0)
+ if (!isnumok) {
+ PyErr_Format(PyExc_TypeError,
+ "%%%c format: a number is required, "
+ "not %.200s", c, Py_TYPE(v)->tp_name);
goto onError;
- sign = 1;
}
if (flags & F_ZERO)
fill = '0';