예제 #1
0
    def recv(self, atom, args):
        if atom is RUN_1:
            pname = unwrapStr(args[0])
            for extension in [".ty", ".mast"]:
                path = pname.encode("utf-8") + extension
                for base in self.paths:
                    try:
                        with open(os.path.join(base, path), "rb") as handle:
                            source = handle.read()
                            with self.recorder.context("Deserialization"):
                                return loadMASTBytes(source)
                    except IOError:
                        continue
            raise userError(u"Could not locate " + pname)

        if atom is RUN_2:
            scope = unwrapMap(args[1])
            d = {}
            for k, v in scope.items():
                s = unwrapStr(k)
                if not s.startswith("&&"):
                    raise userError(u"evalMonteFile scope map must be of the "
                                    "form '[\"&&name\" => binding]'")
                d[s[2:]] = scope[k]

            code = obtainModule(self.paths,
                                unwrapStr(args[0]).encode("utf-8"),
                                self.recorder)
            return evaluateRaise([code], d)[0]
        raise Refused(self, atom, args)
예제 #2
0
    def recv(self, atom, args):
        if atom is RUN_1:
            pname = unwrapStr(args[0])
            for extension in [".ty", ".mast"]:
                path = pname.encode("utf-8") + extension
                for base in self.paths:
                    try:
                        with open(os.path.join(base, path), "rb") as handle:
                            source = handle.read()
                            with self.recorder.context("Deserialization"):
                                return loadMASTBytes(source)
                    except IOError:
                        continue
            raise userError(u"Could not locate " + pname)

        if atom is RUN_2:
            scope = unwrapMap(args[1])
            d = {}
            for k, v in scope.items():
                s = unwrapStr(k)
                if not s.startswith("&&"):
                    raise userError(u"evalMonteFile scope map must be of the "
                                    "form '[\"&&name\" => binding]'")
                d[s[2:]] = scope[k]

            code = obtainModule(self.paths, unwrapStr(args[0]).encode("utf-8"),
                                self.recorder)
            return evaluateRaise([code], d)[0]
        raise Refused(self, atom, args)
예제 #3
0
def evalToPair(code, topLocals, envMap, bindingNames=False):
    environment = {}
    if bindingNames:
        for k, v in unwrapMap(envMap).items():
            s = unwrapStr(k)
            if not s.startswith("&&"):
                raise userError(u"evalMonteFile scope map must be of the "
                                "form '[\"&&name\" => binding]'")
            environment[s[2:]] = v
    else:
        for k, v in unwrapMap(envMap).items():
            environment[unwrapStr(k)] = v
    # Don't catch user exceptions; on traceback, we'll have a trail
    # auto-added that indicates that the exception came through
    # eval() or whatnot.
    result, newEnv = evaluateRaise([code], environment)
    if newEnv is not None:
        # XXX monteMap()
        d = monteMap()
        for k, vi in topLocals.items():
            d[StrObject(k)] = newEnv.local[vi]
        addendum = ConstMap(d)
        envMap = addendum._or(envMap)
    return result, envMap
예제 #4
0
def evalToPair(code, topLocals, envMap, bindingNames=False):
    environment = {}
    if bindingNames:
        for k, v in unwrapMap(envMap).items():
            s = unwrapStr(k)
            if not s.startswith("&&"):
                raise userError(u"evalMonteFile scope map must be of the "
                                "form '[\"&&name\" => binding]'")
            environment[s[2:]] = v
    else:
        for k, v in unwrapMap(envMap).items():
            environment[unwrapStr(k)] = v
    # Don't catch user exceptions; on traceback, we'll have a trail
    # auto-added that indicates that the exception came through
    # eval() or whatnot.
    result, newEnv = evaluateRaise([code], environment)
    if newEnv is not None:
        # XXX monteMap()
        d = monteMap()
        for k, vi in topLocals.items():
            d[StrObject(k)] = newEnv.local[vi]
        addendum = ConstMap(d)
        envMap = addendum._or(envMap)
    return result, envMap