Exemple #1
0
 def test_py_to_js_dict_conversion(self):
     import js
     jsobj = js.convert({b'foo': 'bar'})
     assert isinstance(jsobj, js.Object)
     assert jsobj.foo == 'bar'
     jsobj = js.convert({u'foo': 'bar'})
     assert isinstance(jsobj, js.Object)
     assert jsobj.foo == 'bar'
Exemple #2
0
def render(cell,val):
    print "RENDER %s"%cell
    if hasattr(val, 'to_js'):
        val2 = ["html", val.to_js()]
    elif type(val) == list:
        val2 = ["list", val]
    else:
        val2 = ["text", str(val)]
    plots = pt.get_plots()
    if (len(plots) > 0):
        js.globals['PLOTS'][cell] = js.convert(plots)
    js.globals['RESULTS'][cell] = js.convert(val2)
Exemple #3
0
def checkpoint(cell, val, local):
    import js
    import matplotlib.pyplot as pt
    if hasattr(val, 'to_js') and type(val) != type:
        val2 = ["html", val.to_js()]
    else:
        val2 = ["text", str(val)]
    plots = pt.get_plots()
    if (len(plots) > 0):
        js.globals['PLOTS'] = js.convert(plots)
    js.globals['RESULTS'] = js.convert(val2)
    types = dict([[k, {"name": k, "reflection": livebook_inspect(local[k])}] for k in local.keys()])
    js.globals['LOCALS'][cell] = js.convert(types)
Exemple #4
0
def checkpoint(cell, val, local):
    import js
    import matplotlib.pyplot as pt
    if hasattr(val, 'to_js') and type(val) != type:
        val2 = ["html", val.to_js()]
    else:
        val2 = ["text", str(val)]
    plots = pt.get_plots()
    if (len(plots) > 0):
        js.globals['PLOTS'] = js.convert(plots)
    js.globals['RESULTS'] = js.convert(val2)
    types = dict([[k, {
        "name": k,
        "reflection": livebook_inspect(local[k])
    }] for k in local.keys()])
    js.globals['LOCALS'][cell] = js.convert(types)
Exemple #5
0
 def test_py_to_js_conversion(self):
     import js
     assert isinstance(js.convert("hello"), js.String)
     assert isinstance(js.convert(u"\u2603"), js.String)
     assert isinstance(js.convert(42), js.Number)
     assert isinstance(js.convert(42.5), js.Number)
     assert isinstance(js.convert(True), js.Boolean)
     assert isinstance(js.convert(False), js.Boolean)
     assert isinstance(js.convert(None), js.Object)
     def func():
         pass
     assert isinstance(js.convert(func), js.Function)
     class cls():
         def meth(self):
             pass
     assert isinstance(js.convert(cls.meth), js.Function)
     assert isinstance(js.convert(cls().meth), js.Function)
Exemple #6
0
def execute():
    import js
    cell = int(js.globals['CELL'])
    code = str(js.globals['CODE'])
    (val, err, local) = do(code, cell)
    if err == None:
        checkpoint(cell, val, local)
    else:
        js.globals['ERROR'] = js.convert(err)
Exemple #7
0
def execute():
    import js
    cell = int(js.globals['CELL'])
    code = str(js.globals['CODE'])
    (val,err,local) = do(code,cell)
    if err == None:
        checkpoint(cell,val,local)
    else:
        js.globals['ERROR'] = js.convert(err)
Exemple #8
0
 def test_py_to_js_list_conversion(self):
     import js
     jsobj = js.convert([1, 2, 3])
     assert jsobj[0] == 1
     assert jsobj[1] == 2
     assert jsobj[2] == 3
Exemple #9
0
def mark(n):
    print "CELL %s" % n
    if type(js.globals["NEXT_JOB"]) <> js.Undefined:
        js.globals["INTERRUPT"] = js.convert(True)
        raise BaseException("INTERRUPT")