[pypy-commit] pypy py3.5: gethostbyname(): support for the 'idna' encoding
arigo
pypy.commits at gmail.com
Mon Jan 2 10:49:51 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r89301:4fbab31451c0
Date: 2017-01-02 16:49 +0100
http://bitbucket.org/pypy/pypy/changeset/4fbab31451c0/
Log: gethostbyname(): support for the 'idna' encoding
diff --git a/pypy/module/_socket/interp_func.py b/pypy/module/_socket/interp_func.py
--- a/pypy/module/_socket/interp_func.py
+++ b/pypy/module/_socket/interp_func.py
@@ -21,12 +21,16 @@
raise converted_error(space, e)
return space.fsdecode(space.newbytes(res))
- at unwrap_spec(host=str)
-def gethostbyname(space, host):
+def encode_idna(space, w_host):
+ return space.bytes_w(space.call_method(space.w_unicode, 'encode',
+ w_host, space.wrap('idna')))
+
+def gethostbyname(space, w_host):
"""gethostbyname(host) -> address
Return the IP address (a string of the form '255.255.255.255') for a host.
"""
+ host = encode_idna(space, w_host)
try:
addr = rsocket.gethostbyname(host)
ip = addr.get_host()
diff --git a/pypy/module/_socket/test/test_sock_app.py b/pypy/module/_socket/test/test_sock_app.py
--- a/pypy/module/_socket/test/test_sock_app.py
+++ b/pypy/module/_socket/test/test_sock_app.py
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
import sys, os
import pytest
from pypy.tool.pytest.objspace import gettestobjspace
@@ -681,6 +682,11 @@
s1.close()
s2.close()
+ def test_gethostbyname_unicode(self):
+ import _socket
+ domain = u"испытание.pythontest.net"
+ _socket.gethostbyname(domain)
+
class AppTestNetlink:
def setup_class(cls):
More information about the pypy-commit
mailing list