python-websockets: FTBFS building against python 3.15

Maximiliano Curia <[email protected]>
Newsgroups gmane.linux.debian.devel.python
Message-ID <[email protected]>
Package: src:python-websockets
Version: 16.0-1
User: [email protected]
Usertags: python3.15
Tags: patch

Hi!

While rebuilding the python related packages against the python version
3.15rc1 we found that python-websocket fails to build from source [1].

This is due to a change in 3.15 in the requirements on how the buffers need to
be present in memory. Upstream already applied a fix for this included
in the release 16.1.

I'm attaching the upstream patch that I'm using the sandbox, please
consider either adding this patch or updating the version.

Happy hacking,

[1]: https://debusine.debian.net/debian/r-python-python3.15/work-request/999586/
-- 
"Can you imagine what I would do if I could do all I can?" -- Sun Tzu
Saludos /\/\ /\ >< `/
py315_requires_c-contiguous_buffers_for_int_from_bytes.patch (text/x-diff, 1.2 KB)
commit f3bf8033276aa4fc272940e650c319c517bb3479
Author: Lumir Balhar <[email protected]>
Date:   Tue Apr 7 09:16:08 2026 +0200

    Python 3.15+ requires C-contiguous buffers for int.from_bytes()

diff --git a/src/websockets/utils.py b/src/websockets/utils.py
index b2a90e52..84904ea0 100644
--- a/src/websockets/utils.py
+++ b/src/websockets/utils.py
@@ -47,6 +47,14 @@ def apply_mask(data: BytesLike, mask: bytes | bytearray) -> bytes:
     if len(mask) != 4:
         raise ValueError("mask must contain 4 bytes")
 
+    # Python 3.15+ requires C-contiguous buffers for int.from_bytes()
+    # CPython (https://github.com/python/cpython/pull/132109) optimized
+    # int.from_bytes() to use the buffer protocol with PyBUF_SIMPLE, which requires
+    # C-contiguous buffers. Non-contiguous memoryviews (e.g., created by [::-1])
+    # now raise BufferError. Convert to bytes to create a contiguous copy.
+    if isinstance(data, memoryview) and not data.c_contiguous:
+        data = bytes(data)
+
     data_int = int.from_bytes(data, sys.byteorder)
     mask_repeated = mask * (len(data) // 4) + mask[: len(data) % 4]
     mask_int = int.from_bytes(mask_repeated, sys.byteorder)
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.