nuwa/dev/: wasm-file-http-0.1.4 metadata and description
Proxy HTTP support for wasmtime runtime
| author | Tim |
| author_email | tim.lai@nuwainfo.com |
| classifiers |
|
| description_content_type | text/markdown |
| requires_dist |
|
| requires_python | >=3.11 |
Because this project isn't in the mirror_whitelist,
no releases from root/pypi are included.
| File | Tox results | History |
|---|---|---|
wasm_file_http-0.1.4-py3-none-any.whl
|
|
使用方法
from wasm_file_http import run, WasmHandler
WASM_PATH = "wasm_file_http/tests/fixtures/data/monit/Monit.wasm" WORKSPACE_PATH = "wasm_file_http/examples/workspace" OUTPUT_DIR = "wasm_file_http/examples"
method 1 (利用 factory 只進行一次 checksum 的計算,方便後續多次執行)
handler = WasmHandler(wasmFilePath=WASM_PATH, outputDir=OUTPUT_DIR) result = handler.run(workspaceDir=WORKSPACE_PATH)
method 2 (最簡單的使用,每次執行都會計算 checksum)
result = run( wasmFilePath=WASM_PATH, outputDir=OUTPUT_DIR, workspaceDir=WORKSPACE_PATH )
原理
wasi 因為本身的限制導致沒辦法透過 os 執行 http reqeuests,wasm_file_http 套件會透過 patching 的方式修改由 wasm 編譯的 wat 檔, 在 file open 和 file read 的動作新增用來下 http requests 的 callback 函數,這樣一來就可以在 wasm 實作中透過 file open/read 的方式來 執行 http requests,範例如下 (Python):
with open("./requests/get.txt", 'w') as f: f.write(json.dumps({ "url": "https://dog.ceo/api/breed/hound/list" }))
with open("requests/response.txt", 'r') as f: response = f.read()
上述例子先對 get.txt 檔案進行寫入,接著讀取 response.txt 時就會觸發 callback 函數來獲取 get.txt 檔案的內容,再依照內容來執行 http requests, 並將結果寫入 response.txt 中
細節
若要查看實作的細節,可以參考 https://code.nuwainfo.com/trac/mercurius/ticket/3811
如何執行測試
- 到 wasm_file_http folder
- python -m unittest wasm_file_http.tests.RunTest
如何 build 這個 package
- python setup.py sdist bdist_wheel
上傳 package
twine upload --repository-url {repo_url} -u {username} -p {password} .\dist\wasm_file_http-{版號}-py3-none-any.whl