Example #1
0
    def __init__(self, req, filename=None, string=None, vars={}):

        if (string and filename):
            raise ValueError, "Must specify either filename or string"

        self.req, self.vars = req, vars

        if not filename and not string:
            filename = req.filename

        self.filename, self.string = filename, string

        if filename:

            # if filename is not absolute, default to our guess
            # of current directory
            if not os.path.isabs(filename):
                base = os.path.split(req.filename)[0]
                self.filename = os.path.join(base, filename)

            self.load_from_file()
        else:

            cached = mem_scache.get(string)
            if cached:
                self.code = cached
            else:
                source = _psp.parsestring(string)
                code = compile(source, "__psp__", "exec")
                mem_scache.store(string,code)
                self.code = code
Example #2
0
def parsestring(str):

    return _psp.parsestring(str)