New submission from Thomas Herve:

I attach a patch where I use PyArg_ParseTupleAndKeywords in socketmodule
where ARGSUSED was mentioned, or removed ARGSUSED if keywords already used.

----------
components: Library (Lib)
files: socket_keywords.diff
messages: 58189
nosy: therve
severity: normal
status: open
title: [patch] socketmodule cleanups: allow the use of keywords in socket 
functions
type: rfe
versions: Python 2.6
Added file: http://bugs.python.org/file8873/socket_keywords.diff

__________________________________
Tracker <[EMAIL PROTECTED]>
<http://bugs.python.org/issue1554>
__________________________________
Index: Modules/socketmodule.c
===================================================================
--- Modules/socketmodule.c      (revision 59319)
+++ Modules/socketmodule.c      (working copy)
@@ -945,7 +945,6 @@
    The family field of the sockaddr structure is inspected
    to determine what kind of address it really is. */
 
-/*ARGSUSED*/
 static PyObject *
 makesockaddr(int sockfd, struct sockaddr *addr, int addrlen, int proto)
 {
@@ -2817,7 +2816,6 @@
 
 /* Initialize a new socket object. */
 
-/*ARGSUSED*/
 static int
 sock_initobj(PyObject *self, PyObject *args, PyObject *kwds)
 {
@@ -2898,9 +2896,8 @@
 
 /* Python interface to gethostname(). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_gethostname(PyObject *self, PyObject *unused)
+socket_gethostname(PyObject *self)
 {
        char buf[1024];
        int res;
@@ -2921,14 +2918,15 @@
 
 /* Python interface to gethostbyname(name). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_gethostbyname(PyObject *self, PyObject *args)
+socket_gethostbyname(PyObject *self, PyObject *args, PyObject *kwds)
 {
        char *name;
        sock_addr_t addrbuf;
 
-       if (!PyArg_ParseTuple(args, "s:gethostbyname", &name))
+       static char *keywords[] = {"host", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:gethostbyname", 
keywords, &name))
                return NULL;
        if (setipaddr(name, SAS2SA(&addrbuf),  sizeof(addrbuf), AF_INET) < 0)
                return NULL;
@@ -3080,9 +3078,8 @@
 
 /* Python interface to gethostbyname_ex(name). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_gethostbyname_ex(PyObject *self, PyObject *args)
+socket_gethostbyname_ex(PyObject *self, PyObject *args, PyObject *kwds)
 {
        char *name;
        struct hostent *h;
@@ -3107,7 +3104,9 @@
 #endif
 #endif /* HAVE_GETHOSTBYNAME_R */
 
-       if (!PyArg_ParseTuple(args, "s:gethostbyname_ex", &name))
+       static char *keywords[] = {"host", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:gethostbyname_ex", 
keywords, &name))
                return NULL;
        if (setipaddr(name, (struct sockaddr *)&addr, sizeof(addr), AF_INET) < 
0)
                return NULL;
@@ -3152,9 +3151,8 @@
 
 /* Python interface to gethostbyaddr(IP). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_gethostbyaddr(PyObject *self, PyObject *args)
+socket_gethostbyaddr(PyObject *self, PyObject *args, PyObject *kwds)
 {
 #ifdef ENABLE_IPV6
        struct sockaddr_storage addr;
@@ -3182,7 +3180,9 @@
        int al;
        int af;
 
-       if (!PyArg_ParseTuple(args, "s:gethostbyaddr", &ip_num))
+       static char *keywords[] = {"host", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:gethostbyaddr", 
keywords, &ip_num))
                return NULL;
        af = AF_UNSPEC;
        if (setipaddr(ip_num, sa, sizeof(addr), af) < 0)
@@ -3244,13 +3244,15 @@
    This only returns the port number, since the other info is already
    known or not useful (like the list of aliases). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_getservbyname(PyObject *self, PyObject *args)
+socket_getservbyname(PyObject *self, PyObject *args, PyObject *kwds)
 {
        char *name, *proto=NULL;
        struct servent *sp;
-       if (!PyArg_ParseTuple(args, "s|s:getservbyname", &name, &proto))
+
+       static char *keywords[] = {"servicename", "protocolname", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|s:getservbyname", 
keywords, &name, &proto))
                return NULL;
        Py_BEGIN_ALLOW_THREADS
        sp = getservbyname(name, proto);
@@ -3274,14 +3276,16 @@
    This only returns the service name, since the other info is already
    known or not useful (like the list of aliases). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_getservbyport(PyObject *self, PyObject *args)
+socket_getservbyport(PyObject *self, PyObject *args, PyObject *kwds)
 {
        unsigned short port;
        char *proto=NULL;
        struct servent *sp;
-       if (!PyArg_ParseTuple(args, "H|s:getservbyport", &port, &proto))
+
+       static char *keywords[] = {"servicename", "protocolname", NULL};
+       
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "H|s:getservbyport", 
keywords, &port, &proto))
                return NULL;
        Py_BEGIN_ALLOW_THREADS
        sp = getservbyport(htons(port), proto);
@@ -3304,9 +3308,8 @@
    This only returns the protocol number, since the other info is
    already known or not useful (like the list of aliases). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_getprotobyname(PyObject *self, PyObject *args)
+socket_getprotobyname(PyObject *self, PyObject *args, PyObject *kwds)
 {
        char *name;
        struct protoent *sp;
@@ -3315,7 +3318,10 @@
        PyErr_SetString(socket_error, "getprotobyname not supported");
        return NULL;
 #else
-       if (!PyArg_ParseTuple(args, "s:getprotobyname", &name))
+
+       static char *keywords[] = {"name", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "s:getprotobyname", 
keywords, &name))
                return NULL;
        Py_BEGIN_ALLOW_THREADS
        sp = getprotobyname(name);
@@ -3339,9 +3345,8 @@
    Arguments as for socket() except the default family is AF_UNIX if
    defined on the platform; otherwise, the default is AF_INET. */
 
-/*ARGSUSED*/
 static PyObject *
-socket_socketpair(PyObject *self, PyObject *args)
+socket_socketpair(PyObject *self, PyObject *args, PyObject *kwds)
 {
        PySocketSockObject *s0 = NULL, *s1 = NULL;
        SOCKET_T sv[2];
@@ -3353,7 +3358,10 @@
 #else
        family = AF_INET;
 #endif
-       if (!PyArg_ParseTuple(args, "|iii:socketpair",
+
+       static char *keywords[] = {"family", "type", "proto", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "|iii:socketpair", 
keywords,
                              &family, &type, &proto))
                return NULL;
        /* Create a pair of socket fds */
@@ -3395,14 +3403,16 @@
    Useful e.g. if stdin is a socket.
    Additional arguments as for socket(). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_fromfd(PyObject *self, PyObject *args)
+socket_fromfd(PyObject *self, PyObject *args, PyObject *kwds)
 {
        PySocketSockObject *s;
        SOCKET_T fd;
        int family, type, proto = 0;
-       if (!PyArg_ParseTuple(args, "iii|i:fromfd",
+
+       static char *keywords[] = {"fd", "family", "type", "proto", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "iii|i:fromfd", keywords,
                              &fd, &family, &type, &proto))
                return NULL;
        /* Dup the fd so it and the socket can be closed independently */
@@ -3773,9 +3783,8 @@
 
 /* Python interface to getaddrinfo(host, port). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_getaddrinfo(PyObject *self, PyObject *args)
+socket_getaddrinfo(PyObject *self, PyObject *args, PyObject *kwds)
 {
        struct addrinfo hints, *res;
        struct addrinfo *res0 = NULL;
@@ -3791,7 +3800,10 @@
 
        family = socktype = protocol = flags = 0;
        family = AF_UNSPEC;
-       if (!PyArg_ParseTuple(args, "OO|iiii:getaddrinfo",
+
+       static char *keywords[] = {"host", "port", "family", "socktype", 
"proto", "flags", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|iiii:getaddrinfo", 
keywords,
                              &hobj, &pobj, &family, &socktype,
                              &protocol, &flags)) {
                return NULL;
@@ -3876,9 +3888,8 @@
 
 /* Python interface to getnameinfo(sa, flags). */
 
-/*ARGSUSED*/
 static PyObject *
-socket_getnameinfo(PyObject *self, PyObject *args)
+socket_getnameinfo(PyObject *self, PyObject *args, PyObject *kwds)
 {
        PyObject *sa = (PyObject *)NULL;
        int flags;
@@ -3890,7 +3901,10 @@
        PyObject *ret = (PyObject *)NULL;
 
        flags = flowinfo = scope_id = 0;
-       if (!PyArg_ParseTuple(args, "Oi:getnameinfo", &sa, &flags))
+
+       static char *keywords[] = {"sockaddr", "flags", NULL};
+
+       if (!PyArg_ParseTupleAndKeywords(args, kwds, "Oi:getnameinfo", 
keywords, &sa, &flags))
                return NULL;
        if  (!PyArg_ParseTuple(sa, "si|ii",
                               &hostp, &port, &flowinfo, &scope_id))
@@ -4010,26 +4024,26 @@
 /* List of functions exported by this module. */
 
 static PyMethodDef socket_methods[] = {
-       {"gethostbyname",       socket_gethostbyname,
+       {"gethostbyname",       (PyCFunction)socket_gethostbyname,
         METH_VARARGS, gethostbyname_doc},
-       {"gethostbyname_ex",    socket_gethostbyname_ex,
+       {"gethostbyname_ex",    (PyCFunction)socket_gethostbyname_ex,
         METH_VARARGS, ghbn_ex_doc},
-       {"gethostbyaddr",       socket_gethostbyaddr,
+       {"gethostbyaddr",       (PyCFunction)socket_gethostbyaddr,
         METH_VARARGS, gethostbyaddr_doc},
-       {"gethostname",         socket_gethostname,
+       {"gethostname",         (PyCFunction)socket_gethostname,
         METH_NOARGS,  gethostname_doc},
-       {"getservbyname",       socket_getservbyname,
+       {"getservbyname",       (PyCFunction)socket_getservbyname,
         METH_VARARGS, getservbyname_doc},
-       {"getservbyport",       socket_getservbyport,
+       {"getservbyport",       (PyCFunction)socket_getservbyport,
         METH_VARARGS, getservbyport_doc},
-       {"getprotobyname",      socket_getprotobyname,
+       {"getprotobyname",      (PyCFunction)socket_getprotobyname,
         METH_VARARGS, getprotobyname_doc},
 #ifndef NO_DUP
-       {"fromfd",              socket_fromfd,
+       {"fromfd",              (PyCFunction)socket_fromfd,
         METH_VARARGS, fromfd_doc},
 #endif
 #ifdef HAVE_SOCKETPAIR
-       {"socketpair",          socket_socketpair,
+       {"socketpair",          (PyCFunction)socket_socketpair,
         METH_VARARGS, socketpair_doc},
 #endif
        {"ntohs",               socket_ntohs,
@@ -4050,9 +4064,9 @@
        {"inet_ntop",           socket_inet_ntop,
         METH_VARARGS, inet_ntop_doc},
 #endif
-       {"getaddrinfo",         socket_getaddrinfo,
+       {"getaddrinfo",         (PyCFunction)socket_getaddrinfo,
         METH_VARARGS, getaddrinfo_doc},
-       {"getnameinfo",         socket_getnameinfo,
+       {"getnameinfo",         (PyCFunction)socket_getnameinfo,
         METH_VARARGS, getnameinfo_doc},
        {"getdefaulttimeout",   (PyCFunction)socket_getdefaulttimeout,
         METH_NOARGS, getdefaulttimeout_doc},
_______________________________________________
Python-bugs-list mailing list 
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to