commit:     f0e786f0096b75d886fca041c479e936fb27e0b9
Author:     Michał Górny <mgorny <AT> gentoo <DOT> org>
AuthorDate: Sun Oct  4 19:40:32 2020 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Sun Oct  4 21:14:40 2020 +0000
URL:        https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=f0e786f0

dev-python/pypy3-exe: Backport sethostname() fix

Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>

 .../files/pypy3-7.3.2-sethostname-bytes.patch      | 61 ++++++++++++++++++++++
 ...-exe-7.3.2.ebuild => pypy3-exe-7.3.2-r1.ebuild} |  4 ++
 ....2_p37.ebuild => pypy3-exe-7.3.2_p37-r1.ebuild} |  4 ++
 3 files changed, 69 insertions(+)

diff --git a/dev-python/pypy3-exe/files/pypy3-7.3.2-sethostname-bytes.patch 
b/dev-python/pypy3-exe/files/pypy3-7.3.2-sethostname-bytes.patch
new file mode 100644
index 00000000000..68025600b1f
--- /dev/null
+++ b/dev-python/pypy3-exe/files/pypy3-7.3.2-sethostname-bytes.patch
@@ -0,0 +1,61 @@
+From 5ee2925459372a8af805e952f433acd75e426325 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?Micha=C5=82=20G=C3=B3rny?= <mgo...@gentoo.org>
+Date: Sun, 4 Oct 2020 15:46:23 +0200
+Subject: [PATCH] Fix sethostname() failure when passed bytes
+
+My implementation of sethostname() was broken and failed when passed
+bytes on Python 3. Update the implementation to match CPython -- that
+is, use bytes if provided, or fsencode() when str is provided.
+
+--HG--
+branch : py3.6
+---
+ pypy/module/_socket/interp_func.py        |  8 +++++++-
+ pypy/module/_socket/test/test_sock_app.py | 12 ++++++++++++
+ 2 files changed, 19 insertions(+), 1 deletion(-)
+
+diff --git a/pypy/module/_socket/interp_func.py 
b/pypy/module/_socket/interp_func.py
+index bdc4f1293f..1727e51d51 100644
+--- a/pypy/module/_socket/interp_func.py
++++ b/pypy/module/_socket/interp_func.py
+@@ -392,7 +392,13 @@ if hasattr(rsocket, 'sethostname'):
+ 
+         Set the host name.
+         """
+-        hostname = space.text_w(w_hostname)
++        if space.isinstance_w(w_hostname, space.w_bytes):
++            hostname = space.bytes_w(w_hostname)
++        elif space.isinstance_w(w_hostname, space.w_unicode):
++            hostname = space.fsencode_w(w_hostname)
++        else:
++            raise oefmt(space.w_TypeError,
++                        "sethostname() argument 1 must be str or bytes")
+         try:
+             res = rsocket.sethostname(hostname)
+         except SocketError as e:
+diff --git a/pypy/module/_socket/test/test_sock_app.py 
b/pypy/module/_socket/test/test_sock_app.py
+index fe3efec8e3..355fb8a2a9 100644
+--- a/pypy/module/_socket/test/test_sock_app.py
++++ b/pypy/module/_socket/test/test_sock_app.py
+@@ -210,6 +210,18 @@ def test_getaddrinfo(space, w_socket):
+     assert space.unwrap(w_l) == True
+ 
+ 
++def test_sethostname(space, w_socket):
++    space.raises_w(space.w_OSError, space.appexec,
++                   [w_socket],
++                   "(_socket): _socket.sethostname(_socket.gethostname())")
++
++
++def test_sethostname_bytes(space, w_socket):
++    space.raises_w(space.w_OSError, space.appexec,
++                   [w_socket],
++                   "(_socket): 
_socket.sethostname(_socket.gethostname().encode())")
++
++
+ def test_unknown_addr_as_object(space, ):
+     from pypy.module._socket.interp_socket import addr_as_object
+     c_addr = lltype.malloc(rsocket._c.sockaddr, flavor='raw', 
track_allocation=False)
+-- 
+GitLab
+

diff --git a/dev-python/pypy3-exe/pypy3-exe-7.3.2.ebuild 
b/dev-python/pypy3-exe/pypy3-exe-7.3.2-r1.ebuild
similarity index 98%
rename from dev-python/pypy3-exe/pypy3-exe-7.3.2.ebuild
rename to dev-python/pypy3-exe/pypy3-exe-7.3.2-r1.ebuild
index a8648c1e6ea..73313264113 100644
--- a/dev-python/pypy3-exe/pypy3-exe-7.3.2.ebuild
+++ b/dev-python/pypy3-exe/pypy3-exe-7.3.2-r1.ebuild
@@ -35,6 +35,10 @@ BDEPEND="
                )
        )"
 
+PATCHES=(
+       "${FILESDIR}"/pypy3-7.3.2-sethostname-bytes.patch
+)
+
 check_env() {
        if use low-memory; then
                CHECKREQS_MEMORY="1750M"

diff --git a/dev-python/pypy3-exe/pypy3-exe-7.3.2_p37.ebuild 
b/dev-python/pypy3-exe/pypy3-exe-7.3.2_p37-r1.ebuild
similarity index 98%
rename from dev-python/pypy3-exe/pypy3-exe-7.3.2_p37.ebuild
rename to dev-python/pypy3-exe/pypy3-exe-7.3.2_p37-r1.ebuild
index 5992fb3e87e..592f395defc 100644
--- a/dev-python/pypy3-exe/pypy3-exe-7.3.2_p37.ebuild
+++ b/dev-python/pypy3-exe/pypy3-exe-7.3.2_p37-r1.ebuild
@@ -36,6 +36,10 @@ BDEPEND="
                )
        )"
 
+PATCHES=(
+       "${FILESDIR}"/pypy3-7.3.2-sethostname-bytes.patch
+)
+
 check_env() {
        if use low-memory; then
                CHECKREQS_MEMORY="1750M"

Reply via email to