]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.11] gh-96320: WASI socket fixes (GH-96388) (GH-#96748)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 13 Sep 2022 10:05:25 +0000 (03:05 -0700)
committerGitHub <noreply@github.com>
Tue, 13 Sep 2022 10:05:25 +0000 (12:05 +0200)
- ignore missing functions in ``socket.__repr__``
- bundle network files with assets

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 a19652247a52937badc6eca68aca4a0156d78cca..0717c696b12e036a2c6bcd3265cded966589a832 100644 (file)
@@ -254,17 +254,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 40acea2efaef27c096fd8b1b30043f93e7d57ff3..34a9bb5640a310dd1ef78ea9ae52b915897092e2 100755 (executable)
@@ -229,7 +229,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)