Mercurial > cpython-lru_cache-weakref
diff Modules/socketmodule.c @ 68659:c61b72b0650d 3.1
Issue #5421: Fix misleading error message when one of socket.sendto()'s
arguments has the wrong type. Patch by Nikita Vetoshkin.
| author | Antoine Pitrou <solipsis@pitrou.net> |
|---|---|
| date | Thu, 17 Mar 2011 22:38:37 +0100 |
| parents | bf94b6a73fc8 |
| children | 2af7a6d765fd |
line wrap: on
line diff
--- a/Modules/socketmodule.c Thu Mar 17 17:01:45 2011 +0800 +++ b/Modules/socketmodule.c Thu Mar 17 22:38:37 2011 +0100 @@ -2647,17 +2647,28 @@ Py_buffer pbuf; PyObject *addro; char *buf; - Py_ssize_t len; + Py_ssize_t len, arglen; sock_addr_t addrbuf; int addrlen, n = -1, flags, timeout; flags = 0; - if (!PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro)) { - PyErr_Clear(); - if (!PyArg_ParseTuple(args, "y*iO:sendto", - &pbuf, &flags, &addro)) - return NULL; + arglen = PyTuple_Size(args); + switch (arglen) { + case 2: + PyArg_ParseTuple(args, "y*O:sendto", &pbuf, &addro); + break; + case 3: + PyArg_ParseTuple(args, "y*iO:sendto", + &pbuf, &flags, &addro); + break; + default: + PyErr_Format(PyExc_TypeError, + "sendto() takes 2 or 3 arguments (%d given)", + arglen); } + if (PyErr_Occurred()) + return NULL; + buf = pbuf.buf; len = pbuf.len;
