Esempio n. 1
0
    def DoParseScriptText(self, code, sourceContextCookie, startLineNumber,
                          bWantResult, flags):
        code = framework.RemoveCR(code) + "\n"
        if flags & SCRIPTTEXT_ISEXPRESSION:
            name = "Script Expression"
            exec_type = "eval"
        else:
            name = "Script Block"
            exec_type = "exec"
        num = self._GetNextCodeBlockNumber()
        if num == 1: num = ""
        name = "%s %s" % (name, num)
        codeBlock = AXScriptCodeBlock(name, code, sourceContextCookie,
                                      startLineNumber, flags)
        self._AddScriptCodeBlock(codeBlock)
        globs = self.globalNameSpaceModule.__dict__
        if bWantResult:  # always immediate.
            if self.CompileInScriptedSection(codeBlock, exec_type):
                if flags & SCRIPTTEXT_ISEXPRESSION:
                    return self.EvalInScriptedSection(codeBlock, globs)
                else:
                    return self.ExecInScriptedSection(codeBlock, globs)

            # else compile failed, but user chose to keep running...
        else:
            if flags & SCRIPTTEXT_FORCEEXECUTION:
                if self.CompileInScriptedSection(codeBlock, exec_type):
                    self.ExecInScriptedSection(codeBlock, globs)
            else:
                self.codeBlocks.append(codeBlock)
Esempio n. 2
0
    def DoProcessScriptItemEvent(self, item, event, lcid, wFlags, args):
        #		trace("ScriptItemEvent", self, item, event, event.name, lcid, wFlags, args)
        funcName = self.MakeEventMethodName(item.name, event.name)
        codeBlock = function = None
        try:
            function = item.scriptlets[funcName]
            if type(function) == type(self):  # ie, is a CodeBlock instance
                codeBlock = function
                function = None
        except KeyError:
            pass
        if codeBlock is not None:
            realCode = "def %s():\n" % funcName
            for line in framework.RemoveCR(codeBlock.codeText).split("\n"):
                realCode = realCode + '\t' + line + '\n'
            realCode = realCode + '\n'
            if not self.CompileInScriptedSection(codeBlock, "exec", realCode):
                return
            dict = {}
            self.ExecInScriptedSection(codeBlock,
                                       self.globalNameSpaceModule.__dict__,
                                       dict)
            function = dict[funcName]
            # cache back in scriptlets as a function.
            item.scriptlets[funcName] = function
        if function is None:
            # still no function - see if in the global namespace.
            try:
                function = self.globalNameSpaceModule.__dict__[funcName]
            except KeyError:
                # Not there _exactly_ - do case ins search.
                funcNameLook = funcName.lower()
                for attr in self.globalNameSpaceModule.__dict__.keys():
                    if funcNameLook == attr.lower():
                        function = self.globalNameSpaceModule.__dict__[attr]
                        # cache back in scriptlets, to avoid this overhead next time
                        item.scriptlets[funcName] = function

        if function is None:
            raise Exception(scode=winerror.DISP_E_MEMBERNOTFOUND)
        return self.ApplyInScriptedSection(codeBlock, function, args)