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


Python Reader.find_closing_tag方法代码示例

本文整理汇总了Python中reader.Reader.find_closing_tag方法的典型用法代码示例。如果您正苦于以下问题:Python Reader.find_closing_tag方法的具体用法?Python Reader.find_closing_tag怎么用?Python Reader.find_closing_tag使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在reader.Reader的用法示例。


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

示例1: _compile

# 需要导入模块: from reader import Reader [as 别名]
# 或者: from reader.Reader import find_closing_tag [as 别名]
    def _compile(self, otag, ctag):
        if self.compiled:
            return True

        reader = Reader(self.source)
        self.section = SectionBlock(self, reader, u'', None, u'{{', u'}}')
        section = self.section

        while True:
            last_idx = reader.get_start_idx()

            # first find the next opening tag
            if not reader.find_opening_tag(otag):
                # end of file
                if last_idx < reader.end:
                    section.blocks.append(StaticBlock(self, reader))
                if section != self.section:
                    unclosed = []
                    while section != self.section:
                        unclosed.append(section.tag)
                        section = section.parent
                    raise SyntaxError('Unclosed sections : %s' % ' '.join(unclosed))
                self.compiled = True
                return True

            # examine the control character as it affects the end tag
            if reader.tag_inner_start >= reader.end:
                raise SyntaxError('Premature end of script')

            control = reader.source[reader.tag_inner_start]
            if control == u'{':
                reader.skip_over(u'}')
            elif control == u'=':
                reader.skip_over(u'=')

            # now find the closing tag
            if not reader.find_closing_tag(ctag):
                raise SyntaxError('Premature end of script')

            # untagged content can change depending on whether the tag
            # is standalone, so just store the information to write it
            add_static_to = section.blocks
            static_idx = len(section.blocks)

            tag = reader.source[reader.tag_inner_start:reader.tag_inner_end]

            if control == u'#':
                new_section = SectionBlock(self, reader, tag[1:], section, otag, ctag)
                section.blocks.append(new_section)
                section = new_section
            elif control == u'^':
                new_section = InverseSectionBlock(self, reader, tag[1:], section)
                section.blocks.append(new_section)
                section = new_section
            elif control == u'/':
                if not section.parent:
                    raise SyntaxError('Unmatched closing tag %s at top level' % repr(tag))
                tag = tag[1:].strip()
                if tag != section.tag:
                    raise SyntaxError('Unmatched closing tag %s, expecting %s' % (repr(tag), repr(section.tag)))
                section.inner_end = reader.tag_start
                section = section.parent
            elif control == u'=':
                otag, ctag = tag[1:-1].split()
            elif control == u'{':
                reader.never_standalone()
                section.blocks.append(UnquotedValueBlock(self, reader, tag[1:-1]))
            elif control == u'&':
                reader.never_standalone()
                section.blocks.append(UnquotedValueBlock(self, reader, tag[1:]))
            elif control == u'!':
                # comment
                pass
            elif control == u'>':
                # partial
                partial = PartialBlock(self, reader, tag[1:],
                    self.loader.load(tag[1:].strip(), self.filename))
                section.blocks.append(partial)
            else:
                reader.never_standalone()
                section.blocks.append(ValueBlock(self, reader, tag))

            # now insert the static content
            add_static_to.insert(static_idx, StaticBlock(self, reader))
开发者ID:dgym,项目名称:cystache,代码行数:86,代码来源:template.py


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