summaryrefslogtreecommitdiff
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorEric Smith <eric@trueblade.com>2007-08-25 02:26:07 +0000
committerEric Smith <eric@trueblade.com>2007-08-25 02:26:07 +0000
commit8c6632636807c35bee40210ed8483c1eca82664f (patch)
tree50f386d98ce14116eaf9d83085b82ff11bdb3e69 /Objects/longobject.c
parente4dc32488446240942123cf4e9e7296ad97e20bf (diff)
downloadcpython-git-8c6632636807c35bee40210ed8483c1eca82664f.tar.gz
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/longobject.c')
-rw-r--r--Objects/longobject.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index ddf359d0ea..b724edf3e0 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -5,6 +5,8 @@
#include "Python.h"
#include "longintrepr.h"
+#include "formatter_unicode.h"
+
#include <ctype.h>
long
@@ -3593,6 +3595,16 @@ long_getN(PyLongObject *v, void *context) {
}
static PyObject *
+long__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_long__format__(self, args);
+}
+
+
+static PyObject *
long_round(PyObject *self, PyObject *args)
{
#define UNDEF_NDIGITS (-0x7fffffff) /* Unlikely ndigits value */
@@ -3632,6 +3644,7 @@ static PyMethodDef long_methods[] = {
"Rounding an Integral returns itself.\n"
"Rounding with an ndigits arguments defers to float.__round__."},
{"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS},
+ {"__format__", (PyCFunction)long__format__, METH_VARARGS},
{NULL, NULL} /* sentinel */
};