Files
LeoVasanko b4404b42e6
release / build-wheels (windows, cmd) (push) Failing after 11s
release / build-wheels (linux, bash) (push) Failing after 10s
release / build-wheels (macos, bash) (push) Failing after 11s
release / publish-pypi (push) Skipped
Fix ruff 0.16 findings; bump dependency minimums to match
- pyproject [tool.ruff.lint]: ignore RUF022/RUF023 (deliberately grouped
  __all__/__slots__), SIM117, BLE001 (blind except is intentional at
  CFFI callback boundaries)
- Legit fixes: dict/tuple instead of typing.Dict/Tuple in generate.py,
  unquoted annotations in raf.py, Self return for __enter__ methods,
  explicit check=False on subprocess.run, collapsed nested ifs, sorted
  test imports, unused-unpacked-variable in test_raises
- Bump minimum versions to the synced toolchain: cffi 2.1.1, ruff
  0.16.10, pytest 9.1.1, auditwheel 6.8.2, setuptools 84.0.0,
  setuptools-scm 10.3.4 (project deps and build-system requires)
2026-10-04 16:24:40 +00:00

28 lines
670 B
Python

import random
_rng = random.SystemRandom()
def random_split_bytes(data: bytes) -> list[bytes]:
"""Split ``data`` into one to a few random-sized chunks.
Keeps chunk sizes positive and varies the number of pieces between 1 and 4.
"""
if not data:
return [data]
if len(data) == 1:
return [data]
max_chunks = min(4, len(data))
chunks = _rng.randint(1, max_chunks)
if chunks == 1:
return [data]
cut_points = sorted(_rng.sample(range(1, len(data)), chunks - 1))
start = 0
parts = []
for stop in (*cut_points, len(data)):
parts.append(data[start:stop])
start = stop
return parts