]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-96320: WASI socket fixes (#96388)
authorChristian Heimes <christian@python.org>
Tue, 30 Aug 2022 04:36:11 +0000 (06:36 +0200)
committerGitHub <noreply@github.com>
Tue, 30 Aug 2022 04:36:11 +0000 (06:36 +0200)
* gh-96320: WASI socket fixes

- ignore missing functions in ``socket.__repr__``
- bundle network files with assets

* blurb

Lib/socket.py
Misc/NEWS.d/next/Library/2022-08-29-16-54-36.gh-issue-96388.dCpJcu.rst [new file with mode: 0644]
Tools/wasm/wasm_assets.py

index 0ed86afb4a9ea5fae78330c8fa752ee6a32d559d..1c8cef6ce658102f2670a929e8eae78d51395ae1 100644 (file)
@@ -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 (file)
index 0000000..3a35c47
--- /dev/null
@@ -0,0 +1,2 @@
+Work around missing socket functions in :class:`~socket.socket`'s
+``__repr__``.
index a300d594414acc4a79e903463e1bdf7f66a882d3..a35acfd9387b41fb2cd8aba4c27e8306b6e8c822 100755 (executable)
@@ -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)