|
| 1 | +<!DOCTYPE html> |
| 2 | +<html> |
| 3 | + |
| 4 | +<head> |
| 5 | + <script |
| 6 | + src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.9/brython.min.js" |
| 7 | + integrity="sha256-U56d9Sn/Gtf1meSBXazW81LM1bUeyc1jFuoY3CBu6A8=" |
| 8 | + crossorigin="anonymous"> |
| 9 | + </script> |
| 10 | + <script |
| 11 | + src="https://cdnjs.cloudflare.com/ajax/libs/brython/3.8.9/brython_stdlib.min.js" |
| 12 | + integrity="sha256-twMHOlRBOpBkpyGFeXIBWoJqTpqf76Zp8HExOelwyRc=" |
| 13 | + crossorigin="anonymous" |
| 14 | + defer> |
| 15 | + </script> |
| 16 | + <style> |
| 17 | + table { border-collapse: collapse; } |
| 18 | + table, th, td { border: 1px solid grey; } |
| 19 | + </style> |
| 20 | +</head> |
| 21 | + |
| 22 | +<body onload="brython()"> |
| 23 | + |
| 24 | +<script type="text/python"> |
| 25 | +from browser import document, prompt, html |
| 26 | +import base64 |
| 27 | + |
| 28 | +b64_map = {} |
| 29 | + |
| 30 | +def base64_compute(evt): |
| 31 | + default = "Real Python" |
| 32 | + data = prompt("Enter a string:", default) |
| 33 | + data = data or default |
| 34 | + b64data = base64.b64encode(data.encode()).decode() |
| 35 | + b64_map[data] = b64data |
| 36 | + display_map() |
| 37 | + |
| 38 | +def display_map(): |
| 39 | + table = html.TABLE(style={'border': '1 solid grey'}) |
| 40 | + table <= html.TR(html.TH("Text") + html.TH("Base64")) |
| 41 | + table <= (html.TR(html.TD(key) + html.TD(b64_map[key])) for key in b64_map) |
| 42 | + document["base64-res"].clear() |
| 43 | + document["base64-res"] <= table |
| 44 | + |
| 45 | +document["base64-btn"].bind("click", base64_compute) |
| 46 | +</script> |
| 47 | + |
| 48 | +<button id="base64-btn">Base64</button> |
| 49 | +<p/> |
| 50 | +<div id="base64-res"></div> |
| 51 | + |
| 52 | +</body> |
| 53 | +</html> |
0 commit comments