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


Python lexer.Lexer方法代码示例

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


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

示例1: test_percent_escape

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_percent_escape(self):
        template = """

%% some whatever.

    %% more some whatever
    % if foo:
    % endif
        """
        node = Lexer(template).parse()
        self._compare(
            node,
            TemplateNode(
                {},
                [
                    Text("""\n\n""", (1, 1)),
                    Text("""% some whatever.\n\n""", (3, 2)),
                    Text("   %% more some whatever\n", (5, 2)),
                    ControlLine("if", "if foo:", False, (6, 1)),
                    ControlLine("if", "endif", True, (7, 1)),
                    Text("        ", (8, 1)),
                ],
            ),
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:26,代码来源:test_lexer.py

示例2: test_ns_tag_empty

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_ns_tag_empty(self):
        template = """
            <%form:option value=""></%form:option>
        """
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode(
                {},
                [
                    Text("\n            ", (1, 1)),
                    CallNamespaceTag(
                        "form:option", {"value": ""}, (2, 13), []
                    ),
                    Text("\n        ", (2, 51)),
                ],
            ),
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:20,代码来源:test_lexer.py

示例3: test_tricky_code_2

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_tricky_code_2(self):
        template = """<%
        # someone's comment
%>
        """
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode(
                {},
                [
                    Code(
                        """
        # someone's comment

""",
                        False,
                        (1, 1),
                    ),
                    Text("\n        ", (3, 3)),
                ],
            ),
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:25,代码来源:test_lexer.py

示例4: test_control_lines_2

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_control_lines_2(self):
        template = """% for file in requestattr['toc'].filenames:
    x
% endfor
"""
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode(
                {},
                [
                    ControlLine(
                        "for",
                        "for file in requestattr['toc'].filenames:",
                        False,
                        (1, 1),
                    ),
                    Text("    x\n", (2, 1)),
                    ControlLine("for", "endfor", True, (3, 1)),
                ],
            ),
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:24,代码来源:test_lexer.py

示例5: test_comment_after_statement

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_comment_after_statement(self):
        template = """
        % if x: #comment
            hi
        % else: #next
            hi
        % endif #end
"""
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode(
                {},
                [
                    Text("\n", (1, 1)),
                    ControlLine("if", "if x: #comment", False, (2, 1)),
                    Text("            hi\n", (3, 1)),
                    ControlLine("else", "else: #next", False, (4, 1)),
                    Text("            hi\n", (5, 1)),
                    ControlLine("if", "endif #end", True, (6, 1)),
                ],
            ),
        ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:25,代码来源:test_lexer.py

示例6: test_text_and_tag

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_text_and_tag(self):
        template = """
<b>Hello world</b>
        <%def name="foo()">
                this is a def.
        </%def>

        and some more text.
"""
        node = Lexer(template).parse()
        self._compare(node, TemplateNode({},
                      [Text('''\n<b>Hello world</b>\n        ''', (1,
                      1)), DefTag('def', {'name': 'foo()'}, (3, 9),
                      [Text('''\n                this is a def.\n        ''',
                      (3, 28))]),
                      Text('''\n\n        and some more text.\n''',
                      (5, 16))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:19,代码来源:test_lexer.py

示例7: test_percent_escape

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_percent_escape(self):
        template = \
            """

%% some whatever.

    %% more some whatever
    % if foo:
    % endif
        """
        node = Lexer(template).parse()
        self._compare(node, TemplateNode({}, [Text('''\n\n''',
                      (1, 1)), Text('''% some whatever.\n\n''', (3, 2)),
                      Text('   %% more some whatever\n', (5, 2)),
                      ControlLine('if', 'if foo:', False, (6, 1)),
                      ControlLine('if', 'endif', True, (7, 1)),
                      Text('        ', (8, 1))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:19,代码来源:test_lexer.py

示例8: test_ns_tag_open

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_ns_tag_open(self):
        template = \
            """

            <%self:go x="1" y="${process()}">
                this is the body
            </%self:go>
        """
        nodes = Lexer(template).parse()
        self._compare(nodes, TemplateNode({},
                      [Text('''

            ''', (1, 1)),
                      CallNamespaceTag('self:go', {'x': '1', 'y'
                      : '${process()}'}, (3, 13),
                      [Text('''
                this is the body
            ''',
                      (3, 46))]), Text('\n        ', (5, 24))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:21,代码来源:test_lexer.py

示例9: test_expr_in_attribute

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_expr_in_attribute(self):
        """test some slightly trickier expressions.

        you can still trip up the expression parsing, though, unless we
        integrated really deeply somehow with AST."""

        template = \
            """
            <%call expr="foo>bar and 'lala' or 'hoho'"/>
            <%call expr='foo<bar and hoho>lala and "x" + "y"'/>
        """
        nodes = Lexer(template).parse()
        self._compare(nodes, TemplateNode({}, [Text('\n            ',
                      (1, 1)), CallTag('call', {'expr'
                      : "foo>bar and 'lala' or 'hoho'"}, (2, 13), []),
                      Text('\n            ', (2, 57)), CallTag('call'
                      , {'expr': 'foo<bar and hoho>lala and "x" + "y"'
                      }, (3, 13), []), Text('\n        ', (3, 64))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:20,代码来源:test_lexer.py

示例10: test_code

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_code(self):
            template = \
"""text
    <%
        print("hi")
        for x in range(1,5):
            print(x)
    %>
more text
    <%!
        import foo
    %>
"""
            nodes = Lexer(template).parse()
            self._compare(nodes,
            TemplateNode({}, [
                Text('text\n    ', (1, 1)),
                Code('\nprint("hi")\nfor x in range(1,5):\n    '
                            'print(x)\n    \n', False, (2, 5)),
                Text('\nmore text\n    ', (6, 7)),
                Code('\nimport foo\n    \n', True, (8, 5)),
                Text('\n', (10, 7))])
            ) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:25,代码来源:test_lexer.py

示例11: test_expression

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_expression(self):
        template = \
            """
        this is some ${text} and this is ${textwith | escapes, moreescapes}
        <%def name="hi()">
            give me ${foo()} and ${bar()}
        </%def>
        ${hi()}
"""
        nodes = Lexer(template).parse()
        self._compare(nodes, TemplateNode({},
                      [Text('\n        this is some ', (1, 1)),
                      Expression('text', [], (2, 22)),
                      Text(' and this is ', (2, 29)),
                      Expression('textwith ', ['escapes', 'moreescapes'
                      ], (2, 42)), Text('\n        ', (2, 76)),
                      DefTag('def', {'name': 'hi()'}, (3, 9),
                      [Text('\n            give me ', (3, 27)),
                      Expression('foo()', [], (4, 21)), Text(' and ',
                      (4, 29)), Expression('bar()', [], (4, 34)),
                      Text('\n        ', (4, 42))]), Text('\n        '
                      , (5, 16)), Expression('hi()', [], (6, 9)),
                      Text('\n', (6, 16))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:25,代码来源:test_lexer.py

示例12: test_tricky_code_3

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_tricky_code_3(self):
            template = \
                """<%
            print 'hi'
            # this is a comment
            # another comment
            x = 7 # someone's '''comment
            print '''
        there
        '''
            # someone else's comment
%> '''and now some text '''"""
            nodes = Lexer(template).parse()
            self._compare(nodes, TemplateNode({},
                      [Code("""\nprint 'hi'\n# this is a comment\n"""
                      """# another comment\nx = 7 """
                      """# someone's '''comment\nprint '''\n        """
                      """there\n        '''\n# someone else's """
                      """comment\n\n""",
                      False, (1, 1)),
                      Text(" '''and now some text '''", (10, 3))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:23,代码来源:test_lexer.py

示例13: test_long_control_lines

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_long_control_lines(self):
        template = \
        """
    % for file in \\
        requestattr['toc'].filenames:
        x
    % endfor
        """
        nodes = Lexer(template).parse()
        self._compare(
            nodes,
            TemplateNode({}, [
                Text('\n', (1, 1)),
                ControlLine('for', "for file in \\\n        "
                                "requestattr['toc'].filenames:",
                                False, (2, 1)),
                Text('        x\n', (4, 1)),
                ControlLine('for', 'endfor', True, (5, 1)),
                Text('        ', (6, 1))
            ])
        ) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:23,代码来源:test_lexer.py

示例14: test_ternary_control

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_ternary_control(self):
        template = \
            """
        % if x:
            hi
        % elif y+7==10:
            there
        % elif lala:
            lala
        % else:
            hi
        % endif
"""
        nodes = Lexer(template).parse()
        self._compare(nodes, TemplateNode({}, [Text('\n', (1, 1)),
                      ControlLine('if', 'if x:', False, (2, 1)),
                      Text('            hi\n', (3, 1)),
                      ControlLine('elif', 'elif y+7==10:', False, (4,
                      1)), Text('            there\n', (5, 1)),
                      ControlLine('elif', 'elif lala:', False, (6,
                      1)), Text('            lala\n', (7, 1)),
                      ControlLine('else', 'else:', False, (8, 1)),
                      Text('            hi\n', (9, 1)),
                      ControlLine('if', 'endif', True, (10, 1))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:26,代码来源:test_lexer.py

示例15: test_comment_after_statement

# 需要导入模块: from mako import lexer [as 别名]
# 或者: from mako.lexer import Lexer [as 别名]
def test_comment_after_statement(self):
        template = \
            """
        % if x: #comment
            hi
        % else: #next
            hi
        % endif #end
"""
        nodes = Lexer(template).parse()
        self._compare(nodes, TemplateNode({}, [Text('\n', (1, 1)),
                      ControlLine('if', 'if x: #comment', False, (2,
                      1)), Text('            hi\n', (3, 1)),
                      ControlLine('else', 'else: #next', False, (4,
                      1)), Text('            hi\n', (5, 1)),
                      ControlLine('if', 'endif #end', True, (6, 1))])) 
开发者ID:jhpyle,项目名称:docassemble,代码行数:18,代码来源:test_lexer.py


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