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 /\/\ /\ >< `/
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)

Reply via email to