Example #1
0
    def eval(self, console, input):
        m = url_re.exec(console.loaderInfo.loaderURL)
        domain = m and m[3] or ''
        val = ["""
from flash.display import Sprite
from flash.system import Security
@package("logging.eval")
class Main(Sprite):
    def __init__(self):
        @__eval__
        def evaluate(_):
"""]
        first = True
        for i in values(input):
            val.push('            ' + i + '\n')
            if first:
                console.add_text(self.ps1 + i)
                first = False
            else:
                console.add_text(self.ps2 + i)
        val.push('        self.function = evaluate\n')
        data = val.join('')
        req = URLRequest()
        req.url = self.url
        req.method = 'POST'
        req.data = data
        cur = Loader()
        if self.security == None or self.security == 'ok':
            context = LoaderContext()
            context.securityDomain = SecurityDomain.currentDomain
            context.applicationDomain = ApplicationDomain(
                ApplicationDomain.currentDomain)
            context.checkPolicyFile = True
            try:
                cur.load(req, context)
            except SecurityError as e: #probably in local filesystem
                console.add_text(str(e),
                    console.levelcolors[LogLevel.ERROR])
                console.add_text("Trying different security domain, "
                    "some functionality may be absent")
                console.add_text("(It's ok if you are on local filesystem)")
                cur.load(req)
                self.security = 'bad'
        else:
            cur.load(req)

        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))

        cur.contentLoaderInfo.addEventListener(Event.COMPLETE, _run)
Example #2
0
 def load(self, url):
     if self.child:
         self.unload()
     context = LoaderContext()
     context.securityDomain = SecurityDomain.currentDomain
     context.applicationDomain = ApplicationDomain()
     context.checkPolicyFile = True
     req = URLRequest()
     req.url = url
     loader = Loader()
     for k, v in items(self.params):
         loader.contentLoaderInfo.parameters[k] = v
     self.addChild(loader)
     try:
         loader.load(req, context)
     except SecurityError as e:
         Log.error(str(e))
         Log.info("Trying different security domain, "
             "some functionality may be absent")
         Log.info("(It's ok if you are on local filesystem)")
         loader.load(req)
     self.child = loader
     loader.contentLoaderInfo.addEventListener(
         Event.COMPLETE, self._bindcontent)