Index: Python/getargs.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Python/getargs.c,v retrieving revision 2.105 diff -u -p -r2.105 getargs.c --- Python/getargs.c 30 Mar 2005 16:41:55 -0000 2.105 +++ Python/getargs.c 25 Aug 2005 20:17:59 -0000 @@ -1595,3 +1595,29 @@ PyArg_UnpackTuple(PyObject *args, char * va_end(vargs); return 1; } + + +/* For type constructors that don't take keyword args + * + * Sets a TypeError and returns 0 if the kwds dict is + * not emtpy, returns 1 otherwise + */ +int +_PyArg_NoKeywords(char *funcname, PyObject *kw) +{ + if (kw == NULL) + return 1; + if (!PyDict_CheckExact(kw)) { + PyErr_BadInternalCall(); + return 0; + } + if (PyDict_Size(kw) == 0) + return 1; + + PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments", + funcname); + return 0; +} + + + Index: Include/modsupport.h =================================================================== RCS file: /cvsroot/python/python/dist/src/Include/modsupport.h,v retrieving revision 2.41 diff -u -p -r2.41 modsupport.h --- Include/modsupport.h 10 Jul 2004 22:20:17 -0000 2.41 +++ Include/modsupport.h 25 Aug 2005 20:17:59 -0000 @@ -15,6 +15,7 @@ PyAPI_FUNC(int) PyArg_ParseTupleAndKeywo char *, char **, ...); PyAPI_FUNC(int) PyArg_UnpackTuple(PyObject *, char *, int, int, ...); PyAPI_FUNC(PyObject *) Py_BuildValue(char *, ...); +PyAPI_FUNC(int) _PyArg_NoKeywords(char *funcname, PyObject *kw); PyAPI_FUNC(int) PyArg_VaParse(PyObject *, char *, va_list); PyAPI_FUNC(int) PyArg_VaParseTupleAndKeywords(PyObject *, PyObject *, Index: Objects/rangeobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/rangeobject.c,v retrieving revision 2.54 diff -u -p -r2.54 rangeobject.c --- Objects/rangeobject.c 3 Dec 2004 11:45:13 -0000 2.54 +++ Objects/rangeobject.c 25 Aug 2005 20:17:59 -0000 @@ -45,6 +45,9 @@ range_new(PyTypeObject *type, PyObject * long ilow = 0, ihigh = 0, istep = 1; long n; + if (!_PyArg_NoKeywords("xrange()", kw)) + return NULL; + if (PyTuple_Size(args) <= 1) { if (!PyArg_ParseTuple(args, "l;xrange() requires 1-3 int arguments", Index: Objects/setobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/setobject.c,v retrieving revision 1.54 diff -u -p -r1.54 setobject.c --- Objects/setobject.c 17 Aug 2005 12:27:17 -0000 1.54 +++ Objects/setobject.c 25 Aug 2005 20:18:00 -0000 @@ -935,6 +935,9 @@ frozenset_new(PyTypeObject *type, PyObje { PyObject *iterable = NULL, *result; + if (!_PyArg_NoKeywords("frozenset()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) return NULL; @@ -976,6 +979,9 @@ PySet_Fini(void) static PyObject * set_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { + if (!_PyArg_NoKeywords("set()", kwds)) + return NULL; + return make_new_set(type, NULL); } Index: Objects/bufferobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/bufferobject.c,v retrieving revision 2.26 diff -u -p -r2.26 bufferobject.c --- Objects/bufferobject.c 24 Sep 2004 19:17:26 -0000 2.26 +++ Objects/bufferobject.c 25 Aug 2005 20:18:00 -0000 @@ -192,7 +192,10 @@ buffer_new(PyTypeObject *type, PyObject int offset = 0; int size = Py_END_OF_BUFFER; - if ( !PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size) ) + if (!_PyArg_NoKeywords("buffer()", kw)) + return NULL; + + if (!PyArg_ParseTuple(args, "O|ii:buffer", &ob, &offset, &size)) return NULL; return PyBuffer_FromObject(ob, offset, size); } Index: Objects/sliceobject.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Objects/sliceobject.c,v retrieving revision 2.22 diff -u -p -r2.22 sliceobject.c --- Objects/sliceobject.c 5 Sep 2003 14:27:30 -0000 2.22 +++ Objects/sliceobject.c 25 Aug 2005 20:18:00 -0000 @@ -174,6 +174,9 @@ slice_new(PyTypeObject *type, PyObject * start = stop = step = NULL; + if (!_PyArg_NoKeywords("slice()", kw)) + return NULL; + if (!PyArg_UnpackTuple(args, "slice", 1, 3, &start, &stop, &step)) return NULL; Index: Modules/arraymodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/arraymodule.c,v retrieving revision 2.98 diff -u -p -r2.98 arraymodule.c --- Modules/arraymodule.c 16 Dec 2004 16:23:39 -0000 2.98 +++ Modules/arraymodule.c 25 Aug 2005 20:18:01 -0000 @@ -1799,18 +1799,9 @@ array_new(PyTypeObject *type, PyObject * char c; PyObject *initial = NULL, *it = NULL; struct arraydescr *descr; - - if (kwds != NULL) { - int i = PyObject_Length(kwds); - if (i < 0) - return NULL; - else if (i > 0) { - PyErr_SetString(PyExc_TypeError, - "array.array constructor takes " - "no keyword arguments"); - return NULL; - } - } + + if (!_PyArg_NoKeywords("array.array()", kwds)) + return NULL; if (!PyArg_ParseTuple(args, "c|O:array", &c, &initial)) return NULL; Index: Modules/itertoolsmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/itertoolsmodule.c,v retrieving revision 1.40 diff -u -p -r1.40 itertoolsmodule.c --- Modules/itertoolsmodule.c 5 Dec 2004 09:25:51 -0000 1.40 +++ Modules/itertoolsmodule.c 25 Aug 2005 20:18:01 -0000 @@ -618,6 +618,9 @@ cycle_new(PyTypeObject *type, PyObject * PyObject *saved; cycleobject *lz; + if (!_PyArg_NoKeywords("cycle()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "cycle", 1, 1, &iterable)) return NULL; @@ -765,6 +768,9 @@ dropwhile_new(PyTypeObject *type, PyObje PyObject *it; dropwhileobject *lz; + if (!_PyArg_NoKeywords("dropwhile()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "dropwhile", 2, 2, &func, &seq)) return NULL; @@ -906,6 +912,9 @@ takewhile_new(PyTypeObject *type, PyObje PyObject *it; takewhileobject *lz; + if (!_PyArg_NoKeywords("takewhile()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "takewhile", 2, 2, &func, &seq)) return NULL; @@ -1048,6 +1057,9 @@ islice_new(PyTypeObject *type, PyObject int numargs; isliceobject *lz; + if (!_PyArg_NoKeywords("islice()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "islice", 2, 4, &seq, &a1, &a2, &a3)) return NULL; @@ -1236,6 +1248,9 @@ starmap_new(PyTypeObject *type, PyObject PyObject *it; starmapobject *lz; + if (!_PyArg_NoKeywords("starmap()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "starmap", 2, 2, &func, &seq)) return NULL; @@ -1365,6 +1380,9 @@ imap_new(PyTypeObject *type, PyObject *a imapobject *lz; int numargs, i; + if (!_PyArg_NoKeywords("imap()", kwds)) + return NULL; + numargs = PyTuple_Size(args); if (numargs < 2) { PyErr_SetString(PyExc_TypeError, @@ -1544,6 +1562,9 @@ chain_new(PyTypeObject *type, PyObject * int i; PyObject *ittuple; + if (!_PyArg_NoKeywords("chain()", kwds)) + return NULL; + /* obtain iterators */ assert(PyTuple_Check(args)); ittuple = PyTuple_New(tuplesize); @@ -1684,6 +1705,9 @@ ifilter_new(PyTypeObject *type, PyObject PyObject *it; ifilterobject *lz; + if (!_PyArg_NoKeywords("ifilter()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "ifilter", 2, 2, &func, &seq)) return NULL; @@ -1825,6 +1849,9 @@ ifilterfalse_new(PyTypeObject *type, PyO PyObject *it; ifilterfalseobject *lz; + if (!_PyArg_NoKeywords("ifilterfalse()", kwds)) + return NULL; + if (!PyArg_UnpackTuple(args, "ifilterfalse", 2, 2, &func, &seq)) return NULL; @@ -1964,6 +1991,9 @@ count_new(PyTypeObject *type, PyObject * countobject *lz; long cnt = 0; + if (!_PyArg_NoKeywords("count()", kwds)) + return NULL; + if (!PyArg_ParseTuple(args, "|l:count", &cnt)) return NULL; @@ -2060,6 +2090,9 @@ izip_new(PyTypeObject *type, PyObject *a PyObject *result; int tuplesize = PySequence_Length(args); + if (!_PyArg_NoKeywords("izip()", kwds)) + return NULL; + /* args must be a tuple */ assert(PyTuple_Check(args)); @@ -2240,6 +2273,9 @@ repeat_new(PyTypeObject *type, PyObject PyObject *element; long cnt = -1; + if (!_PyArg_NoKeywords("repeat()", kwds)) + return NULL; + if (!PyArg_ParseTuple(args, "O|l:repeat", &element, &cnt)) return NULL; Index: Modules/operator.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/operator.c,v retrieving revision 2.30 diff -u -p -r2.30 operator.c --- Modules/operator.c 9 Mar 2005 16:38:46 -0000 2.30 +++ Modules/operator.c 25 Aug 2005 20:18:01 -0000 @@ -269,6 +269,9 @@ itemgetter_new(PyTypeObject *type, PyObj PyObject *item; int nitems; + if (!_PyArg_NoKeywords("itemgetter()", kwds)) + return NULL; + nitems = PyTuple_GET_SIZE(args); if (nitems <= 1) { if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &item)) @@ -405,6 +408,9 @@ attrgetter_new(PyTypeObject *type, PyObj PyObject *attr; int nattrs; + if (!_PyArg_NoKeywords("attrgetter()", kwds)) + return NULL; + nattrs = PyTuple_GET_SIZE(args); if (nattrs <= 1) { if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &attr)) Index: Modules/_randommodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/_randommodule.c,v retrieving revision 1.7 diff -u -p -r1.7 _randommodule.c --- Modules/_randommodule.c 5 Oct 2003 09:09:15 -0000 1.7 +++ Modules/_randommodule.c 25 Aug 2005 20:18:02 -0000 @@ -481,6 +481,9 @@ random_new(PyTypeObject *type, PyObject RandomObject *self; PyObject *tmp; + if (!_PyArg_NoKeywords("Random()", kwds)) + return NULL; + self = (RandomObject *)type->tp_alloc(type, 0); if (self == NULL) return NULL; Index: Modules/zipimport.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/zipimport.c,v retrieving revision 1.18 diff -u -p -r1.18 zipimport.c --- Modules/zipimport.c 10 Nov 2004 13:08:35 -0000 1.18 +++ Modules/zipimport.c 25 Aug 2005 20:18:02 -0000 @@ -65,6 +65,9 @@ zipimporter_init(ZipImporter *self, PyOb char *path, *p, *prefix, buf[MAXPATHLEN+2]; int len; + if (!_PyArg_NoKeywords("zipimporter()", kwds)) + return -1; + if (!PyArg_ParseTuple(args, "s:zipimporter", &path)) return -1; Index: Modules/collectionsmodule.c =================================================================== RCS file: /cvsroot/python/python/dist/src/Modules/collectionsmodule.c,v retrieving revision 1.38 diff -u -p -r1.38 collectionsmodule.c --- Modules/collectionsmodule.c 19 Mar 2005 00:00:48 -0000 1.38 +++ Modules/collectionsmodule.c 25 Aug 2005 20:18:02 -0000 @@ -95,6 +95,9 @@ deque_new(PyTypeObject *type, PyObject * dequeobject *deque; block *b; + if (!_PyArg_NoKeywords("deque()", kwds)) + return NULL; + /* create dequeobject structure */ deque = (dequeobject *)type->tp_alloc(type, 0); if (deque == NULL)