Пример #1
0
    def _cook(self):
        """Compile the TAL and METAL statments.

        Cooking must not fail due to compilation errors in templates.
        """
        source_file = self.pt_source_file()
        if self.html():
            gen = TALGenerator(getEngine(), xml=0, source_file=source_file)
            parser = HTMLTALParser(gen)
        else:
            gen = TALGenerator(getEngine(), source_file=source_file)
            parser = TALParser(gen)

        self._v_errors = ()
        try:
            parser.parseString(self._text)
            self._v_program, self._v_macros = parser.getCode()
        except:
            self._v_errors = ["Compilation failed",
                              "%s: %s" % sys.exc_info()[:2]]
        self._v_warnings = parser.getWarnings()
        self._v_cooked = 1
 def _compile(self, source):
     parser = HTMLTALParser()
     parser.parseString(source)
     program, macros = parser.getCode()
     return program, macros
Пример #3
0
 def parse(self, eng, s, fn):
     gen = TALGenerator(expressionCompiler=eng, xml=0, source_file=fn)
     parser = HTMLTALParser(gen)
     parser.parseString(s)
     program, macros = parser.getCode()
     return program, macros
Пример #4
0
    class Devnull:
        def write(self, s):
            pass

    # check if we've already instantiated an engine;
    # if not, use the stupidest one available
    if not engine:
        engine = POEngine()

    # process each file specified
    for filename in args:
        try:
            engine.file = filename
            p = HTMLTALParser()
            p.parseFile(filename)
            program, macros = p.getCode()
            POTALInterpreter(program, macros, engine, stream=Devnull(),
                             metal=False)()
        except: # Hee hee, I love bare excepts!
            print 'There was an error processing', filename
            traceback.print_exc()

    # Now output the keys in the engine.  Write them to a file if --output or
    # --update was specified; otherwise use standard out.
    if (outfile is None):
        outfile = sys.stdout
    else:
        outfile = file(outfile, update_mode and "a" or "w")
    catalog = {}
    for domain in engine.catalog.keys():
        catalog.update(engine.catalog[domain])
Пример #5
0
 def parse(self, eng, s, fn):
     gen = TALGenerator(expressionCompiler=eng, xml=0, source_file=fn)
     parser = HTMLTALParser(gen)
     parser.parseString(s)
     program, macros = parser.getCode()
     return program, macros
Пример #6
0
 def _compile(self, source):
     parser = HTMLTALParser()
     parser.parseString(source)
     program, macros = parser.getCode()
     return program, macros