summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2007-08-25 02:26:07 (GMT)
committerEric Smith <eric@trueblade.com>2007-08-25 02:26:07 (GMT)
commit8c6632636807c35bee40210ed8483c1eca82664f (patch)
tree50f386d98ce14116eaf9d83085b82ff11bdb3e69 /Objects/floatobject.c
parente4dc32488446240942123cf4e9e7296ad97e20bf (diff)
downloadcpython-8c6632636807c35bee40210ed8483c1eca82664f.zip
cpython-8c6632636807c35bee40210ed8483c1eca82664f.tar.gz
cpython-8c6632636807c35bee40210ed8483c1eca82664f.tar.bz2
Implementation of PEP 3101, Advanced String Formatting.
Known issues: The string.Formatter class, as discussed in the PEP, is incomplete. Error handling needs to conform to the PEP. Need to fix this warning that I introduced in Python/formatter_unicode.c: Objects/stringlib/unicodedefs.h:26: warning: `STRINGLIB_CMP' defined but not used Need to make sure sign formatting is correct, more tests needed. Need to remove '()' sign formatting, left over from an earlier version of the PEP.
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 09efa12..ca94750 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -6,6 +6,8 @@
#include "Python.h"
+#include "formatter_unicode.h"
+
#include <ctype.h>
#if !defined(__STDC__)
@@ -1015,6 +1017,21 @@ float_getzero(PyObject *v, void *closure)
return PyFloat_FromDouble(0.0);
}
+static PyObject *
+float__format__(PyObject *self, PyObject *args)
+{
+ /* when back porting this to 2.6, check type of the format_spec
+ and call either unicode_long__format__ or
+ string_long__format__ */
+ return unicode_float__format__(self, args);
+}
+
+PyDoc_STRVAR(float__format__doc,
+"float.__format__(format_spec) -> string\n"
+"\n"
+"Formats the float according to format_spec.");
+
+
static PyMethodDef float_methods[] = {
{"conjugate", (PyCFunction)float_float, METH_NOARGS,
"Returns self, the complex conjugate of any float."},
@@ -1028,6 +1045,8 @@ static PyMethodDef float_methods[] = {
METH_O|METH_CLASS, float_getformat_doc},
{"__setformat__", (PyCFunction)float_setformat,
METH_VARARGS|METH_CLASS, float_setformat_doc},
+ {"__format__", (PyCFunction)float__format__,
+ METH_VARARGS, float__format__doc},
{NULL, NULL} /* sentinel */
};