当前位置: 首页>>代码示例>>Python>>正文


Python htmltalparser.HTMLTALParser类代码示例

本文整理汇总了Python中zope.tal.htmltalparser.HTMLTALParser的典型用法代码示例。如果您正苦于以下问题:Python HTMLTALParser类的具体用法?Python HTMLTALParser怎么用?Python HTMLTALParser使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HTMLTALParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __call__

 def __call__(self, value, *args, **kw):
     gen = TALGenerator(getEngine(), xml=1, source_file=None)
     parser = HTMLTALParser(gen)
     try:
         parser.parseString(value)
     except Exception, err:
         return ("Validation Failed(%s): \n %s" % (self.name, err))
开发者ID:dtgit,项目名称:dtedu,代码行数:7,代码来源:validators.py

示例2: compilefile

def compilefile(file, mode=None):
    assert mode in ("html", "xml", None)
    if mode is None:
        ext = os.path.splitext(file)[1]
        if ext.lower() in (".html", ".htm"):
            mode = "html"
        else:
            mode = "xml"
    # make sure we can find the file
    prefix = os.path.dirname(os.path.abspath(__file__)) + os.path.sep
    if (not os.path.exists(file)
        and os.path.exists(os.path.join(prefix, file))):
        file = os.path.join(prefix, file)
    # normalize filenames for test output
    filename = os.path.abspath(file)
    if filename.startswith(prefix):
        filename = filename[len(prefix):]
    filename = filename.replace(os.sep, '/') # test files expect slashes
    # parse
    from zope.tal.talgenerator import TALGenerator
    if mode == "html":
        from zope.tal.htmltalparser import HTMLTALParser
        p = HTMLTALParser(gen=TALGenerator(source_file=filename, xml=0))
    else:
        from zope.tal.talparser import TALParser
        p = TALParser(gen=TALGenerator(source_file=filename))
    p.parseFile(file)
    return p.getCode()
开发者ID:benjolitz,项目名称:zope.tal,代码行数:28,代码来源:driver.py

示例3: talEval

def talEval(expression, context, extra=None):
    """
    Perform a TAL eval on the expression.
    """
    # First, account for the possibility that it is merely TALES; if there are
    # no <tal> in it at all (nor the ${python:} you can do with this function),
    # just send it to talesEval
    isTales = '<tal' not in expression and '${python:' not in expression
    if isTales:
        return talesEvalStr(expression, context, extra)

    # Next, as a convenience, replace all ${} blocks that aren't inside a <tal>
    # with <tal:block content="..."/> equivalent
    chunks = TAG.split(expression)
    modified = []
    for chunk in chunks:
        if chunk.startswith('<tal'):
            modified.append(chunk)
        else:
            modified.append(TPLBLOCK.sub(_chunk_repl, chunk))
    expression = ''.join(modified)

    # Finally, compile the expression and apply context
    gen = TALGenerator(Engine, xml=0)
    parser = HTMLTALParser(gen)
    parser.parseString(expression)
    program, macros = parser.getCode()
    output = cStringIO.StringIO()
    context = Engine.getContext(context)
    TALInterpreter(program, macros, context, output, tal=True)()
    return output.getvalue()
开发者ID:SteelHouseLabs,项目名称:zenoss-prodbin,代码行数:31,代码来源:ZenTales.py

示例4: test_dynamic_msgids

 def test_dynamic_msgids(self):
     sample_source = """
         <p i18n:translate="">
           Some
           <span tal:replace="string:strange">dynamic</span>
           text.
         </p>
         <p i18n:translate="">
           A <a tal:attributes="href path:dynamic">link</a>.
         </p>
     """
     p = HTMLTALParser()
     p.parseString(sample_source)
     program, macros = p.getCode()
     engine = POEngine()
     engine.file = 'sample_source'
     POTALInterpreter(program, macros, engine, stream=StringIO(),
                      metal=False)()
     msgids = []
     for domain in engine.catalog.values():
         msgids += list(domain)
     msgids.sort()
     self.assertEqual(msgids,
         ['A <a href="${DYNAMIC_CONTENT}">link</a>.',
         'Some ${DYNAMIC_CONTENT} text.'])
开发者ID:benjolitz,项目名称:zope.tal,代码行数:25,代码来源:test_talgettext.py

示例5: insertHTMLStructure

 def insertHTMLStructure(self, text, repldict):
     from zope.tal.htmltalparser import HTMLTALParser
     gen = AltTALGenerator(repldict, self.engine._engine, 0)
     p = HTMLTALParser(gen) # Raises an exception if text is invalid
     p.parseString(text)
     program, macros = p.getCode()
     self.interpret(program)
开发者ID:benjolitz,项目名称:zope.tal,代码行数:7,代码来源:talinterpreter.py

示例6: time_tal

def time_tal(fn, count):
    p = HTMLTALParser()
    p.parseFile(fn)
    program, macros = p.getCode()
    engine = DummyEngine(macros)
    engine.globals = data
    tal = TALInterpreter(program, macros, engine, StringIO(), wrap=0,
                         tal=1, strictinsert=0)
    return time_apply(tal, (), {}, count)
开发者ID:benjolitz,项目名称:zope.tal,代码行数:9,代码来源:markbench.py

示例7: cook

    def cook(cls, source_file, text, engine, content_type):
        if content_type == 'text/html':
            gen = TALGenerator(engine, xml=0, source_file=source_file)
            parser = HTMLTALParser(gen)
        else:
            gen = TALGenerator(engine, source_file=source_file)
            parser = TALParser(gen)

        parser.parseString(text)
        program, macros = parser.getCode()

        return cls(program), macros
开发者ID:kislovm,项目名称:findburo,代码行数:12,代码来源:pagetemplate.py

示例8: profile_tal

def profile_tal(fn, count, profiler):
    p = HTMLTALParser()
    p.parseFile(fn)
    program, macros = p.getCode()
    engine = DummyEngine(macros)
    engine.globals = data
    tal = TALInterpreter(program, macros, engine, StringIO(), wrap=0,
                         tal=1, strictinsert=0)
    for i in range(4):
        tal()
    r = [None] * count
    for i in r:
        profiler.runcall(tal)
开发者ID:benjolitz,项目名称:zope.tal,代码行数:13,代码来源:markbench.py

示例9: tal_strings

def tal_strings(dir, domain="zope", include_default_domain=False, exclude=()):
    """Retrieve all TAL messages from `dir` that are in the `domain`.
    """
    # We import zope.tal.talgettext here because we can't rely on the
    # right sys path until app_dir has run
    from zope.tal.talgettext import POEngine, POTALInterpreter
    from zope.tal.htmltalparser import HTMLTALParser
    from zope.tal.talparser import TALParser
    import sys
    # i18n patch if templates using special characters
    reload(sys)
    sys.setdefaultencoding('UTF8')
    engine = POEngine()

    class Devnull(object):
        def write(self, s):
            pass

    for filename in (find_files(dir, '*.*pt', exclude=tuple(exclude)) +
                     find_files(dir, '*.html', exclude=tuple(exclude)) +
                     find_files(dir, '*.kupu', exclude=tuple(exclude)) +
                     find_files(dir, '*.pox', exclude=tuple(exclude)) +
                     find_files(dir, '*.xsl', exclude=tuple(exclude))):
        try:
            engine.file = filename
            name, ext = os.path.splitext(filename)
            if ext == '.html' or ext.endswith('pt'):
                p = HTMLTALParser()
            else:
                p = TALParser()
            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()

    # See whether anything in the domain was found
    if not domain in engine.catalog:
        return {}
    # We do not want column numbers.
    catalog = engine.catalog[domain].copy()
    # When the Domain is 'default', then this means that none was found;
    # Include these strings; yes or no?
    if include_default_domain:
        catalog.update(engine.catalog['default'])
    for msgid, locations in catalog.items():
        catalog[msgid] = [(l[0], l[1][0]) for l in locations]
    return catalog
开发者ID:affinitic,项目名称:i18ndude,代码行数:50,代码来源:extract.py

示例10: _cook

    def _cook(self):
        self._v_program = None

        if not self._source:
            return

        parser = HTMLTALParser(TALGenerator(TrustedEngine))
        try:
            parser.parseString(self.source)
            self._v_program, macros = parser.getCode()
            self._v_errors = ()
        except Exception, e:
            self._v_program = None
            self._v_errors = [unicode(err) for err in sys.exc_info()[:2]]
开发者ID:Zojax,项目名称:zojax.persistentlayout,代码行数:14,代码来源:pt.py

示例11: talToHtml

def talToHtml(tal):
    """
    Expects TAL-string, returns interpreted HTML-string.
    Works only with string-(and python?)-expressions, not
    with path-expressions.
    """
    generator = TALGenerator(xml=0, source_file=None)
    parser = HTMLTALParser(generator)
    parser.parseString(tal)
    program, macros = parser.getCode()
    engine = DummyEngine(macros)
    result = StringIO()
    interpreter = TALInterpreter(program, {}, engine, stream=result)
    interpreter()
    tal = result.getvalue().strip()
    return tal
开发者ID:ida,项目名称:adi.devgen,代码行数:16,代码来源:tal.py

示例12: test_potalinterpreter_translate_default

 def test_potalinterpreter_translate_default(self):
     sample_source = '<p i18n:translate="">text</p>'
     p = HTMLTALParser()
     p.parseString(sample_source)
     program, macros = p.getCode()
     engine = POEngine()
     engine.file = 'sample_source'
     interpreter = POTALInterpreter(
         program, macros, engine, stream=StringIO(), metal=False)
     # We simply call this, to make sure we don't get a NameError
     # for 'unicode' in python 3.
     # The return value (strangely: 'x') is not interesting here.
     interpreter.translate('text')
     msgids = []
     for domain in engine.catalog.values():
         msgids += list(domain)
     self.assertIn('text', msgids)
开发者ID:zopefoundation,项目名称:zope.tal,代码行数:17,代码来源:test_talgettext.py

示例13: cook

def cook(self):
    """Compile the TAL and METAL statments.

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

    self._v_errors = ()
    try:
        #### the patch
        text = self._text
        text = expression.sub('', text)
        text = expression2.sub('', text)
        parser.parseString(text)
        #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
开发者ID:kroman0,项目名称:products,代码行数:28,代码来源:__init__.py

示例14: compilefile

def compilefile(file, mode=None):
    assert mode in ("html", "xml", None)
    if mode is None:
        ext = os.path.splitext(file)[1]
        if ext.lower() in (".html", ".htm"):
            mode = "html"
        else:
            mode = "xml"
    from zope.tal.talgenerator import TALGenerator
    filename = os.path.abspath(file)
    prefix = os.path.dirname(os.path.abspath(__file__)) + os.path.sep
    if filename.startswith(prefix):
        filename = filename[len(prefix):]
    filename = filename.replace(os.sep, '/') # test files expect slashes
    if mode == "html":
        from zope.tal.htmltalparser import HTMLTALParser
        p = HTMLTALParser(gen=TALGenerator(source_file=filename, xml=0))
    else:
        from zope.tal.talparser import TALParser
        p = TALParser(gen=TALGenerator(source_file=filename))
    p.parseFile(file)
    return p.getCode()
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:22,代码来源:driver.py

示例15: _cook

    def _cook(self):
        """Compile the TAL and METAL statments.

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

        self._v_errors = ()
        try:
            parser.parseString(self._text)
            self._v_program, self._v_macros = parser.getCode()
        except:
            etype, e = sys.exc_info()[:2]
            self._v_errors = ["Compilation failed",
                              "%s.%s: %s" % (etype.__module__, etype.__name__, e)]
        self._v_cooked = 1
开发者ID:Andyvs,项目名称:TrackMonthlyExpenses,代码行数:23,代码来源:pagetemplate.py


注:本文中的zope.tal.htmltalparser.HTMLTALParser类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。