Commit 6c9f4fbb authored by Roman Yurchak's avatar Roman Yurchak

Handle multi-line string input

parent 02e59bb2
......@@ -4,6 +4,7 @@ A library of helper utilities for connecting Python to the browser environment.
import ast
import io
from textwrap import dedent
__version__ = '0.1.11'
......@@ -24,6 +25,9 @@ def eval_code(code, ns):
"""
Runs a string of code, the last part of which may be an expression.
"""
# handle mis-indented input from multi-line strings
code = dedent(code)
mod = ast.parse(code)
if isinstance(mod.body[-1], ast.Expr):
expr = ast.Expression(mod.body[-1].value)
......
......@@ -102,17 +102,11 @@ class SeleniumWrapper:
self.driver.execute_script("window.logs = []")
def run(self, code):
if isinstance(code, str) and code.startswith('\n'):
# we have a multiline string, fix indentation
code = textwrap.dedent(code)
return self.run_js(
'return pyodide.runPython({!r})'.format(code))
def run_async(self, code):
from selenium.common.exceptions import TimeoutException
if isinstance(code, str) and code.startswith('\n'):
# we have a multiline string, fix indentation
code = textwrap.dedent(code)
self.run_js(
"""
window.done = false;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment