Skip to content

Commit 8eee817

Browse files
committed
added manual test for File
1 parent df793d1 commit 8eee817

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

test/file/index.html

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<script type="module" src="../../dist/index.js"></script>
7+
</head>
8+
<body>
9+
<script type="micropython" src="./main.py" worker></script>
10+
<input type="file" id="file" disabled>
11+
</body>
12+
</html>

test/file/main.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
try:
2+
from polyscript import xworker
3+
document = xworker.window.document
4+
except:
5+
import js
6+
document = js.document
7+
8+
try:
9+
from pyodide.ffi import create_proxy
10+
except:
11+
create_proxy = lambda x: x
12+
13+
file = document.querySelector('#file')
14+
file.disabled = False
15+
16+
async def on_file_change(event):
17+
file = event.target.files[0]
18+
print('name:', file.name)
19+
print('size:', file.size)
20+
print('text:', await file.text())
21+
22+
file.addEventListener('change', create_proxy(on_file_change))

0 commit comments

Comments
 (0)