Skip to content

Commit

Permalink
pythongh-96320: WASI socket fixes (python#96388)
Browse files Browse the repository at this point in the history
* pythongh-96320: WASI socket fixes

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

* blurb
  • Loading branch information
tiran committed Aug 30, 2022
1 parent 6d403e2 commit d0b3d23
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
5 changes: 3 additions & 2 deletions Lib/socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,17 +255,18 @@ def __repr__(self):
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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Work around missing socket functions in :class:`~socket.socket`'s
``__repr__``.
3 changes: 2 additions & 1 deletion Tools/wasm/wasm_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d0b3d23

Please sign in to comment.