Exemplo n.º 1
0
 def __init__(self):
     self.stage.align = StageAlign.TOP_LEFT
     self.stage.scaleMode = StageScaleMode.NO_SCALE
     wurl = None
     newparams = {}
     for k, v in items(self.loaderInfo.parameters):
         if k == 'wrapped_url':
             wurl = v
         else:
             newparams[k] = v
     self.params = newparams
     self.namespace = {
         'load': self.load,
         'params': newparams,
         'unload': self.unload,
         'root': self.get_root,
         '_root': self,
         'print': self.print,
         'repr': repr,
         'locals': self.print_namespace,
         }
     self.console = Console(self, Evaluator(self.namespace))
     self.namespace.console = self.console
     Log.add_handler(self.console)
     if wurl:
         Log.info("Loading url " + repr(wurl))
         self.load(wurl)
Exemplo n.º 2
0
 def _run(ev):
     console.clearinput()
     fun = cur.content.function
     del self._cur
     try:
         self.last_value = fun.apply(self.scope, [self.last_value])
     except Error as e:
         console.add_text("Runtime Error: "+(e.getStackTrace() or e),
             console.levelcolors[LogLevel.ERROR])
     else:
         if self.last_value != undefined:
             console.add_text(repr(self.last_value))
Exemplo n.º 3
0
    def testRepr(self):
        self.assertEquals(repr("test"), '"test"')
        self.assertEquals(repr("""Hello
World!"""), r'"Hello\nWorld!"')
        self.assertEquals(repr([1, 2, 3, "val"]), '[1, 2, 3, "val"]')
        v = repr({'a': 'b', 'c': 3})
        self.assertTrue(v == '{"a": "b", "c": 3}' or v == '{"c": 3, "a": "b"}')
        v = repr({'ar': [1,2], 'c': 3})
        self.assertTrue(v == '{"ar": [1, 2], "c": 3}'
            or v == '{"c": 3, "ar": [1, 2]}')
        self.assertEquals(repr(Failure("test")), '<Instance of [class Failure]>')
Exemplo n.º 4
0
    def testEval(self):

        @__eval__
        def test1(_):
            a = 1
            b = 3
            (a+b)*a

        @__eval__
        def test2(_):
            c = a+b
            c*2

        @__eval__
        def test3(_):
            def fun(arg):
                return arg*2
            fun(3)

        @__eval__
        def test4(_):
            fun(a+b)

        @__eval__
        def test5(_):
            def fun2():
                return _*2
            fun2()

        @__eval__
        def test6(_):
            fun2()

        @__eval__
        def test7(_):
            def fun3(c):
                return a+b+c

        @__eval__
        def test8(_):
            fun3(2)

        @__eval__
        def test9(_):
            def fun4(c):
                def fun(d):
                    return (a+b+c)*d
                return fun
            ff = fun4(10)
            ff(1)

        @__eval__
        def test10(_):
            [ff(2), ff(4), fun4(7)(2)]

        scope = {}
        val = test1.apply(scope, [val])
        self.assertEquals(val, 4)
        val = test2.apply(scope, [val])
        self.assertEquals(val, 8)
        val = test3.apply(scope, [val])
        self.assertEquals(val, 6)
        val = test4.apply(scope, [val])
        self.assertEquals(val, 8)
        val = test5.apply(scope, [val])
        self.assertEquals(val, 16)
        val = test6.apply(scope, [val])
        self.assertEquals(val, 32)
        val = test7.apply(scope, [val])
        self.assertEquals(val, undefined)
        val = test8.apply(scope, [val])
        self.assertEquals(val, 6)
        val = test9.apply(scope, [val])
        self.assertEquals(val, 14)
        val = test10.apply(scope, [val])
        self.assertEquals(repr(val), '[28, 56, 22]')
        self.assertEquals(scope.a, 1)
        self.assertEquals(scope.b, 3)
        self.assertEquals(scope.c, 4)
        self.assertEquals(scope._, 14)