forked from RustPython/RustPython
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowser.py
More file actions
37 lines (21 loc) · 791 Bytes
/
browser.py
File metadata and controls
37 lines (21 loc) · 791 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
from _browser import *
from _js import JsValue
from _window import window
jsstr = window.new_from_str
_alert = window.get_prop("alert")
def alert(msg):
if type(msg) != str:
raise TypeError("msg must be a string")
_alert.call(jsstr(msg))
_confirm = window.get_prop("confirm")
def confirm(msg):
if type(msg) != str:
raise TypeError("msg must be a string")
return _confirm.call(jsstr(msg)).as_bool()
_prompt = window.get_prop("prompt")
def prompt(msg, default_val=None):
if type(msg) != str:
raise TypeError("msg must be a string")
if default_val is not None and type(default_val) != str:
raise TypeError("default_val must be a string")
return _prompt.call(*(jsstr(arg) for arg in [msg, default_val] if arg)).as_str()