metaframe-widget 0.3.2__tar.gz → 0.3.5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/PKG-INFO +1 -1
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/pyproject.toml +1 -1
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/src/metaframe_widget/_widget.py +11 -2
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/tests/test_widget.py +4 -2
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/.gitignore +0 -0
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/LICENSE +0 -0
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/README.md +0 -0
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/src/metaframe_widget/__init__.py +0 -0
- {metaframe_widget-0.3.2 → metaframe_widget-0.3.5}/src/metaframe_widget/_esm.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: metaframe-widget
|
|
3
|
-
Version: 0.3.
|
|
3
|
+
Version: 0.3.5
|
|
4
4
|
Summary: anywidget for embedding metaframe URLs in Jupyter and marimo notebooks
|
|
5
5
|
Project-URL: Homepage, https://github.com/metapages/metaframe-js
|
|
6
6
|
Project-URL: Repository, https://github.com/metapages/metaframe-js
|
|
@@ -6,6 +6,15 @@ import traitlets
|
|
|
6
6
|
|
|
7
7
|
from ._esm import ESM
|
|
8
8
|
|
|
9
|
+
import base64
|
|
10
|
+
|
|
11
|
+
import urllib.parse
|
|
12
|
+
|
|
13
|
+
# Equivalent to btoa(encodeURIComponent(value));
|
|
14
|
+
def string_to_base64_string(value: str) -> str:
|
|
15
|
+
encoded_uri_component = urllib.parse.quote(value, safe="-_.!~*'()")
|
|
16
|
+
return base64.b64encode(encoded_uri_component.encode("ascii")).decode("ascii")
|
|
17
|
+
|
|
9
18
|
|
|
10
19
|
class MetaframeWidget(anywidget.AnyWidget):
|
|
11
20
|
"""Widget that renders a metaframe iframe (works in Jupyter and marimo).
|
|
@@ -62,8 +71,8 @@ class MetaframeWidget(anywidget.AnyWidget):
|
|
|
62
71
|
height: CSS height for the widget container (default "400px").
|
|
63
72
|
allow: iframe allow attribute string (e.g. "camera; microphone").
|
|
64
73
|
"""
|
|
65
|
-
encoded =
|
|
66
|
-
url = f"https://js.mtfm.io/#?js={
|
|
74
|
+
encoded = string_to_base64_string(js_code)
|
|
75
|
+
url = f"https://js.mtfm.io/#?js={encoded}"
|
|
67
76
|
return cls(url=url, width=width, height=height, allow=allow, **kwargs)
|
|
68
77
|
|
|
69
78
|
def pipe_to(self, target: "MetaframeWidget", output_key: str, input_key: str = None):
|
|
@@ -31,8 +31,10 @@ def test_set_input():
|
|
|
31
31
|
def test_from_code():
|
|
32
32
|
code = 'console.log("hello");'
|
|
33
33
|
w = MetaframeWidget.from_code(code)
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
# from_code does: encodeURIComponent(code) then base64
|
|
35
|
+
encoded_uri = urllib.parse.quote(code, safe="-_.!~*'()")
|
|
36
|
+
encoded = base64.b64encode(encoded_uri.encode("ascii")).decode("ascii")
|
|
37
|
+
expected_url = f"https://js.mtfm.io/#?js={encoded}"
|
|
36
38
|
assert w.url == expected_url
|
|
37
39
|
|
|
38
40
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|