From d0b3d235dbc560ada459e386b6fa5b5ce1952c7e Mon Sep 17 00:00:00 2001 From: Christian Heimes Date: Tue, 30 Aug 2022 06:36:11 +0200 Subject: [PATCH] gh-96320: WASI socket fixes (#96388) * gh-96320: WASI socket fixes - ignore missing functions in ``socket.__repr__`` - bundle network files with assets * blurb --- Lib/socket.py | 5 +++-- .../Library/2022-08-29-16-54-36.gh-issue-96388.dCpJcu.rst | 2 ++ Tools/wasm/wasm_assets.py | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) create mode 100644 Misc/NEWS.d/next/Library/2022-08-29-16-54-36.gh-issue-96388.dCpJcu.rst diff --git a/Lib/socket.py b/Lib/socket.py index 0ed86afb4a9..1c8cef6ce65 100644 --- a/Lib/socket.py +++ b/Lib/socket.py @@ -255,17 +255,18 @@ class socket(_socket.socket): self.type, self.proto) if not closed: + # getsockname and getpeername may not be available on WASI. try: laddr = self.getsockname() if laddr: s += ", laddr=%s" % str(laddr) - except error: + except (error, AttributeError): pass try: raddr = self.getpeername() if raddr: s += ", raddr=%s" % str(raddr) - except error: + except (error, AttributeError): pass s += '>' return s diff --git a/Misc/NEWS.d/next/Library/2022-08-29-16-54-36.gh-issue-96388.dCpJcu.rst b/Misc/NEWS.d/next/Library/2022-08-29-16-54-36.gh-issue-96388.dCpJcu.rst new file mode 100644 index 00000000000..3a35c473487 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2022-08-29-16-54-36.gh-issue-96388.dCpJcu.rst @@ -0,0 +1,2 @@ +Work around missing socket functions in :class:`~socket.socket`'s +``__repr__``. diff --git a/Tools/wasm/wasm_assets.py b/Tools/wasm/wasm_assets.py index a300d594414..a35acfd9387 100755 --- a/Tools/wasm/wasm_assets.py +++ b/Tools/wasm/wasm_assets.py @@ -230,7 +230,8 @@ def main(): extmods = detect_extension_modules(args) omit_files = list(OMIT_FILES) - omit_files.extend(OMIT_NETWORKING_FILES) + if sysconfig.get_platform().startswith("emscripten"): + omit_files.extend(OMIT_NETWORKING_FILES) for modname, modfiles in OMIT_MODULE_FILES.items(): if not extmods.get(modname): omit_files.extend(modfiles)