Files
pyscript/pyscript.core/test/fetch.html
2024-03-14 19:36:23 +01:00

76 lines
2.5 KiB
HTML

<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="../dist/core.css">
</head>
<body>
<script type="module">
import fetch from 'https://esm.run/@webreflection/fetch';
globalThis.fetch_text = await fetch("config.json").text();
globalThis.fetch_json = JSON.stringify(await fetch("config.json").json());
globalThis.fetch_buffer = new Uint8Array((await fetch("config.json").arrayBuffer())).length;
document.head.appendChild(
Object.assign(
document.createElement('script'),
{
type: 'module',
src: '../dist/core.js'
}
)
);
</script>
<script type="mpy" async>
import js, json
from pyscript import document, fetch
fetch_text = await fetch("config.json").text()
if (fetch_text != js.fetch_text):
raise Exception("fetch_text")
fetch_json = await fetch("config.json").json()
if (json.dumps(fetch_json).replace(" ", "") != js.fetch_json):
raise Exception("fetch_json")
fetch_buffer = await fetch("config.json").bytearray()
if (len(fetch_buffer) != js.fetch_buffer):
raise Exception("fetch_buffer")
print(await fetch("config.json").bytearray())
print(await fetch("config.json").blob())
try:
await fetch("shenanigans.nope").text()
except:
document.documentElement.classList.add('mpy')
</script>
<script type="py" async>
import js, json
from pyscript import document, fetch
fetch_text = await fetch("config.json").text()
if (fetch_text != js.fetch_text):
raise Exception("fetch_text")
fetch_json = await fetch("config.json").json()
if (json.dumps(fetch_json).replace(" ", "") != js.fetch_json):
raise Exception("fetch_json")
fetch_buffer = await fetch("config.json").bytearray()
if (len(fetch_buffer) != js.fetch_buffer):
raise Exception("fetch_buffer")
print(await fetch("config.json").bytearray())
print(await fetch("config.json").blob())
try:
await fetch("shenanigans.nope").text()
except:
document.documentElement.classList.add('py')
</script>
</body>
</html>