[pypy-commit] pypy unicode-utf8-py3: test, fix encoding port from unicode to bytes

mattip pypy.commits at gmail.com
Mon Jan 21 10:08:31 EST 2019


Author: Matti Picus <matti.picus at gmail.com>
Branch: unicode-utf8-py3
Changeset: r95687:15a9ac1c0012
Date: 2019-01-21 17:07 +0200
http://bitbucket.org/pypy/pypy/changeset/15a9ac1c0012/

Log:	test, fix encoding port from unicode to bytes

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
@@ -311,7 +311,7 @@
     elif space.isinstance_w(w_port, space.w_bytes):
         port = space.bytes_w(w_port)
     elif space.isinstance_w(w_port, space.w_unicode):
-        port = space.text_w(w_port)
+        port = space.bytes_w(space.encode_unicode_object(w_port, 'utf-8', 'strict'))
     else:
         raise oefmt(space.w_TypeError,
                     "getaddrinfo() argument 2 must be integer or string")
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
@@ -209,6 +209,17 @@
     w_l = space.appexec([w_socket, space.newbytes(host), space.wrap('smtp')],
                         "(_socket, host, port): return _socket.getaddrinfo(host, port)")
     assert space.unwrap(w_l) == socket.getaddrinfo(host, 'smtp')
+    w_l = space.appexec([w_socket, space.newbytes(host), space.wrap(u'\uD800')], '''
+
+       (_socket, host, port):
+            try:
+                info = _socket.getaddrinfo(host, port)
+            except Exception as e:
+                return e.reason == 'surrogates not allowed'
+            return -1
+        ''')
+    assert space.unwrap(w_l) == True
+
 
 def test_unknown_addr_as_object():
     from pypy.module._socket.interp_socket import addr_as_object
@@ -729,7 +740,7 @@
     def setup_class(cls):
         if not hasattr(os, 'getpid'):
             pytest.skip("AF_NETLINK needs os.getpid()")
-        
+
         if cls.runappdirect:
             import _socket
             w_ok = hasattr(_socket, 'AF_NETLINK')


More information about the pypy-commit mailing list