Skip to content

Commit 7492efa

Browse files
committed
Fix some nits
1 parent 07fe68c commit 7492efa

File tree

2 files changed

+6
-22
lines changed

2 files changed

+6
-22
lines changed

examples/python/client.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33

44
import sys
55
import hashlib
6-
import logging
76
from pathlib import Path
87

8+
# Add path to project for local testing
99
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "python"))
1010

1111
from dff import Client
@@ -35,11 +35,7 @@ def process_sha(method: str, inputs: list[bytes]) -> bytes:
3535

3636
def main() -> None:
3737
"""Main entry point."""
38-
logging.basicConfig(level=logging.INFO)
39-
40-
name = sys.argv[1] if len(sys.argv) > 1 else "python"
41-
42-
client = Client(name, process_sha)
38+
client = Client("python", process_sha)
4339

4440
try:
4541
client.connect()
@@ -54,4 +50,4 @@ def main() -> None:
5450

5551

5652
if __name__ == "__main__":
57-
main()
53+
main()

examples/python/server.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import random
66
from pathlib import Path
77

8+
# Add path to project for local testing
89
sys.path.insert(0, str(Path(__file__).parent.parent.parent / "python"))
910

1011
from dff import Server
@@ -22,26 +23,13 @@ def data_provider() -> list[bytes]:
2223
# Use a deterministic seed that increments
2324
if not hasattr(data_provider, "seed_counter"):
2425
data_provider.seed_counter = 1
25-
2626
seed = data_provider.seed_counter
2727
data_provider.seed_counter += 1
2828

2929
# Generate random data with deterministic seed
3030
random.seed(seed)
3131
size = random.randint(MIN_SIZE, MAX_SIZE)
32-
33-
# Generate random bytes efficiently using random.randbytes (Python 3.9+)
34-
# or random.getrandbits for older versions
35-
try:
36-
data = random.randbytes(size) # Fast method for Python 3.9+
37-
except AttributeError:
38-
# Fallback for Python < 3.9 - still much faster than per-byte generation
39-
data = bytearray(size)
40-
for i in range(0, size, 1024):
41-
chunk_size = min(1024, size - i)
42-
chunk = random.getrandbits(chunk_size * 8).to_bytes(chunk_size, 'little')
43-
data[i:i+chunk_size] = chunk
44-
data = bytes(data)
32+
data = random.randbytes(size)
4533

4634
return [data]
4735

@@ -60,4 +48,4 @@ def main() -> None:
6048

6149

6250
if __name__ == "__main__":
63-
main()
51+
main()

0 commit comments

Comments
 (0)