Skip to content

Commit d7b0e0c

Browse files
authored
Merge pull request #61 from JarbasHiveMind/release-0.4.0a1
Release 0.4.0a1
2 parents 3767782 + 4f00277 commit d7b0e0c

File tree

21 files changed

+1302
-118
lines changed

21 files changed

+1302
-118
lines changed

.github/workflows/build_tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Setup Python
1414
uses: actions/setup-python@v1
1515
with:
16-
python-version: 3.8
16+
python-version: "3.10"
1717
- name: Install Build Tools
1818
run: |
1919
python -m pip install build wheel

.github/workflows/release_workflow.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
- name: Setup Python
4747
uses: actions/setup-python@v1
4848
with:
49-
python-version: 3.8
49+
python-version: "3.10"
5050
- name: Install Build Tools
5151
run: |
5252
python -m pip install build wheel

.github/workflows/unit_tests.yml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Run UnitTests
2+
on:
3+
pull_request:
4+
branches:
5+
- dev
6+
paths-ignore:
7+
- 'hivemind_bus_client/version.py'
8+
- '.github/**'
9+
- '.gitignore'
10+
- 'LICENSE'
11+
- 'CHANGELOG.md'
12+
- 'MANIFEST.in'
13+
- 'README.md'
14+
push:
15+
branches:
16+
- master
17+
paths-ignore:
18+
- 'hivemind_bus_client/version.py'
19+
- '.github/**'
20+
- '.gitignore'
21+
- 'LICENSE'
22+
- 'CHANGELOG.md'
23+
- 'MANIFEST.in'
24+
- 'README.md'
25+
workflow_dispatch:
26+
27+
jobs:
28+
unit_tests:
29+
strategy:
30+
matrix:
31+
python-version: ["3.10", "3.11" ]
32+
runs-on: ubuntu-latest
33+
timeout-minutes: 15
34+
steps:
35+
- uses: actions/checkout@v2
36+
- name: Set up python ${{ matrix.python-version }}
37+
uses: actions/setup-python@v2
38+
with:
39+
python-version: ${{ matrix.python-version }}
40+
- name: Install System Dependencies
41+
run: |
42+
sudo apt-get update
43+
sudo apt install python3-dev swig
44+
python -m pip install build wheel
45+
- name: Install repo
46+
run: |
47+
pip install -e .
48+
- name: Install test dependencies
49+
run: |
50+
pip install -r test/requirements.txt
51+
- name: Run unittests
52+
run: |
53+
pytest --cov=hivemind_bus_client --cov-report xml test
54+
- name: Upload coverage
55+
if: "${{ matrix.python-version == '3.11' }}"
56+
env:
57+
CODECOV_TOKEN: ${{secrets.CODECOV_TOKEN}}
58+
uses: codecov/codecov-action@v2

CHANGELOG.md

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
# Changelog
22

3-
## [0.2.1a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.2.1a1) (2025-01-03)
3+
## [0.4.0a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.4.0a1) (2025-01-08)
44

5-
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.2.0...0.2.1a1)
5+
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.3.0a2...0.4.0a1)
66

77
**Merged pull requests:**
88

9-
- fix:binarization\_protocol [\#53](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/53) ([JarbasAl](https://github.com/JarbasAl))
9+
- feat:http client [\#60](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/60) ([JarbasAl](https://github.com/JarbasAl))
10+
11+
## [0.3.0a2](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.3.0a2) (2025-01-03)
12+
13+
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.3.0a1...0.3.0a2)
14+
15+
**Merged pull requests:**
16+
17+
- chore:benchmark [\#57](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/57) ([JarbasAl](https://github.com/JarbasAl))
18+
19+
## [0.3.0a1](https://github.com/JarbasHiveMind/hivemind-websocket-client/tree/0.3.0a1) (2025-01-03)
20+
21+
[Full Changelog](https://github.com/JarbasHiveMind/hivemind-websocket-client/compare/0.2.1...0.3.0a1)
22+
23+
**Merged pull requests:**
24+
25+
- feat:more encodings [\#55](https://github.com/JarbasHiveMind/hivemind-websocket-client/pull/55) ([JarbasAl](https://github.com/JarbasAl))
1026

1127

1228

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from hivemind_bus_client.encodings.z85b import Z85B
2+
from hivemind_bus_client.encodings.z85p import Z85P
3+
from hivemind_bus_client.encodings.b91 import B91
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
from typing import Union
2+
3+
4+
class B91:
5+
ALPHABET = [
6+
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M',
7+
'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z',
8+
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
9+
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
10+
'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '!', '#', '$',
11+
'%', '&', '(', ')', '*', '+', ',', '.', '/', ':', ';', '<', '=',
12+
'>', '?', '@', '[', ']', '^', '_', '`', '{', '|', '}', '~', '"'
13+
]
14+
15+
DECODE_TABLE = {char: idx for idx, char in enumerate(ALPHABET)}
16+
17+
@classmethod
18+
def decode(cls, encoded_data: Union[str, bytes], encoding: str = "utf-8") -> bytes:
19+
"""
20+
Decodes a Base91-encoded string into its original binary form.
21+
22+
Args:
23+
encoded_data (Union[str, bytes]): Base91-encoded input data. If `bytes`, it is decoded as UTF-8.
24+
encoding (str): The encoding to use if `encoded_data` is provided as a string. Default is 'utf-8'.
25+
26+
Returns:
27+
bytes: The decoded binary data.
28+
29+
Raises:
30+
ValueError: If the input contains invalid Base91 characters.
31+
"""
32+
if isinstance(encoded_data, bytes):
33+
encoded_data = encoded_data.decode(encoding)
34+
35+
v = -1
36+
b = 0
37+
n = 0
38+
out = bytearray()
39+
40+
for char in encoded_data:
41+
if char not in cls.DECODE_TABLE:
42+
raise ValueError(f"Invalid Base91 character: {char}")
43+
c = cls.DECODE_TABLE[char]
44+
if v < 0:
45+
v = c
46+
else:
47+
v += c * 91
48+
b |= v << n
49+
n += 13 if (v & 8191) > 88 else 14
50+
while n >= 8:
51+
out.append(b & 255)
52+
b >>= 8
53+
n -= 8
54+
v = -1
55+
56+
if v >= 0:
57+
out.append((b | v << n) & 255)
58+
59+
return bytes(out)
60+
61+
@classmethod
62+
def encode(cls, data: Union[bytes, str], encoding: str = "utf-8") -> bytes:
63+
"""
64+
Encodes binary data into a Base91-encoded string.
65+
66+
Args:
67+
data (Union[bytes, str]): Input binary data to encode. If `str`, it is encoded as UTF-8.
68+
encoding (str): The encoding to use if `data` is provided as a string. Default is 'utf-8'.
69+
70+
Returns:
71+
str: The Base91-encoded string.
72+
"""
73+
if isinstance(data, str):
74+
data = data.encode(encoding)
75+
76+
b = 0
77+
n = 0
78+
out = []
79+
80+
for byte in data:
81+
b |= byte << n
82+
n += 8
83+
if n > 13:
84+
v = b & 8191
85+
if v > 88:
86+
b >>= 13
87+
n -= 13
88+
else:
89+
v = b & 16383
90+
b >>= 14
91+
n -= 14
92+
out.append(cls.ALPHABET[v % 91])
93+
out.append(cls.ALPHABET[v // 91])
94+
95+
if n:
96+
out.append(cls.ALPHABET[b % 91])
97+
if n > 7 or b > 90:
98+
out.append(cls.ALPHABET[b // 91])
99+
100+
return ''.join(out).encode(encoding)

0 commit comments

Comments
 (0)