Skip to content

Commit e644b52

Browse files
committed
Fix Raw Binary example
1 parent 6608396 commit e644b52

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

examples/call_python_from_js/call_python_from_js.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,16 +101,15 @@ def my_function_boolean(e: webui.Event):
101101

102102
def my_function_raw_binary(e: webui.Event):
103103
# JavaScript: my_function_raw_binary(new Uint8Array([0x41,0x42,0x43]), big_arr)
104-
raw_1 = e.get_string() # index 0 — raw bytes as str
105-
raw_2 = e.get_string_at(1)
106-
len_1 = e.get_size() # index 0
107-
len_2 = e.get_size_at(1)
104+
raw_1 = e.get_bytes()
105+
raw_2 = e.get_bytes_at(1)
106+
len_1 = len(raw_1)
107+
len_2 = len(raw_2)
108108

109-
hex_1 = " ".join(f"0x{b:02x}" for b in raw_1.encode("latin-1")[:len_1])
109+
hex_1 = " ".join(f"0x{b:02x}" for b in raw_1)
110110
print(f"my_function_raw_binary 1 ({len_1} bytes): {hex_1}")
111111

112-
raw_2_bytes = raw_2.encode("latin-1")
113-
valid = len_2 >= 2 and raw_2_bytes[0] == 0xA1 and raw_2_bytes[len_2 - 1] == 0xA2
112+
valid = len_2 >= 2 and raw_2[0] == 0xA1 and raw_2[len_2 - 1] == 0xA2
114113
print(f"my_function_raw_binary 2 big ({len_2} bytes): valid data? {'Yes' if valid else 'No'}")
115114

116115

0 commit comments

Comments
 (0)