diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2003-04-18 10:39:54 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2003-04-18 10:39:54 (GMT) |
commit | 2548c730c17d766ca04b2bf633552655f7f96cdf (patch) | |
tree | b128f16abd8b4c3058d1be4093f30bfb5454b59e /Modules | |
parent | 8d17a90b830ae9b9c672a504f01d4f93bac3d23d (diff) | |
download | cpython-2548c730c17d766ca04b2bf633552655f7f96cdf.zip cpython-2548c730c17d766ca04b2bf633552655f7f96cdf.tar.gz cpython-2548c730c17d766ca04b2bf633552655f7f96cdf.tar.bz2 |
Implement IDNA (Internationalized Domain Names in Applications).
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/socketmodule.c | 30 |
1 files changed, 25 insertions, 5 deletions
diff --git a/Modules/socketmodule.c b/Modules/socketmodule.c index 9d8d614..ba64cb8 100644 --- a/Modules/socketmodule.c +++ b/Modules/socketmodule.c @@ -874,7 +874,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, args->ob_type->tp_name); return 0; } - if (!PyArg_ParseTuple(args, "si:getsockaddrarg", &host, &port)) + if (!PyArg_ParseTuple(args, "eti:getsockaddrarg", + "idna", &host, &port)) return 0; if (setipaddr(host, (struct sockaddr *)addr, sizeof(*addr), AF_INET) < 0) return 0; @@ -893,7 +894,8 @@ getsockaddrarg(PySocketSockObject *s, PyObject *args, int port, flowinfo, scope_id; addr = (struct sockaddr_in6*)&(s->sock_addr).in6; flowinfo = scope_id = 0; - if (!PyArg_ParseTuple(args, "si|ii", &host, &port, &flowinfo, + if (!PyArg_ParseTuple(args, "eti|ii", + "idna", &host, &port, &flowinfo, &scope_id)) { return 0; } @@ -2782,6 +2784,7 @@ socket_getaddrinfo(PyObject *self, PyObject *args) { struct addrinfo hints, *res; struct addrinfo *res0 = NULL; + PyObject *hobj = NULL; PyObject *pobj = (PyObject *)NULL; char pbuf[30]; char *hptr, *pptr; @@ -2789,12 +2792,27 @@ socket_getaddrinfo(PyObject *self, PyObject *args) int error; PyObject *all = (PyObject *)NULL; PyObject *single = (PyObject *)NULL; + PyObject *idna = NULL; family = socktype = protocol = flags = 0; family = AF_UNSPEC; - if (!PyArg_ParseTuple(args, "zO|iiii:getaddrinfo", - &hptr, &pobj, &family, &socktype, - &protocol, &flags)) { + if (!PyArg_ParseTuple(args, "OO|iiii:getaddrinfo", + &hobj, &pobj, &family, &socktype, + &protocol, &flags)) { + return NULL; + } + if (hobj == Py_None) { + hptr = NULL; + } else if (PyUnicode_Check(hobj)) { + idna = PyObject_CallMethod(hobj, "encode", "s", "idna"); + if (!idna) + return NULL; + hptr = PyString_AsString(idna); + } else if (PyString_Check(hobj)) { + hptr = PyString_AsString(hobj); + } else { + PyErr_SetString(PyExc_TypeError, + "getaddrinfo() argument 1 must be string or None"); return NULL; } if (PyInt_Check(pobj)) { @@ -2838,12 +2856,14 @@ socket_getaddrinfo(PyObject *self, PyObject *args) goto err; Py_XDECREF(single); } + Py_XDECREF(idna); if (res0) freeaddrinfo(res0); return all; err: Py_XDECREF(single); Py_XDECREF(all); + Py_XDECREF(idna); if (res0) freeaddrinfo(res0); return (PyObject *)NULL; |