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


Python exceptions.SyntaxException方法代码示例

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


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

示例1: match_tag_end

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def match_tag_end(self):
        match = self.match(r"\</%[\t ]*(.+?)[\t ]*>")
        if match:
            if not len(self.tag):
                raise exceptions.SyntaxException(
                    "Closing tag without opening tag: </%%%s>"
                    % match.group(1),
                    **self.exception_kwargs
                )
            elif self.tag[-1].keyword != match.group(1):
                raise exceptions.SyntaxException(
                    "Closing tag </%%%s> does not match tag: <%%%s>"
                    % (match.group(1), self.tag[-1].keyword),
                    **self.exception_kwargs
                )
            self.tag.pop()
            return True
        else:
            return False 
开发者ID:remg427,项目名称:misp42splunk,代码行数:21,代码来源:lexer.py

示例2: match_tag_end

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def match_tag_end(self):
        match = self.match(r'\</%[\t ]*(.+?)[\t ]*>')
        if match:
            if not len(self.tag):
                raise exceptions.SyntaxException(
                    "Closing tag without opening tag: </%%%s>" %
                    match.group(1),
                    **self.exception_kwargs)
            elif self.tag[-1].keyword != match.group(1):
                raise exceptions.SyntaxException(
                    "Closing tag </%%%s> does not match tag: <%%%s>" %
                    (match.group(1), self.tag[-1].keyword),
                    **self.exception_kwargs)
            self.tag.pop()
            return True
        else:
            return False 
开发者ID:jpush,项目名称:jbox,代码行数:19,代码来源:lexer.py

示例3: match_tag_end

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def match_tag_end(self):
        match = self.match(r'\</%[\t ]*(.+?)[\t ]*>')
        if match:
            if not len(self.tag):
                raise exceptions.SyntaxException(
                                "Closing tag without opening tag: </%%%s>" %
                                match.group(1),
                                **self.exception_kwargs)
            elif self.tag[-1].keyword != match.group(1):
                raise exceptions.SyntaxException(
                            "Closing tag </%%%s> does not match tag: <%%%s>" %
                            (match.group(1), self.tag[-1].keyword),
                            **self.exception_kwargs)
            self.tag.pop()
            return True
        else:
            return False 
开发者ID:fboender,项目名称:ansible-cmdb,代码行数:19,代码来源:lexer.py

示例4: parse_until_text

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def parse_until_text(self, watch_nesting, *text):
        startpos = self.match_position
        text_re = r"|".join(text)
        brace_level = 0
        paren_level = 0
        bracket_level = 0
        while True:
            match = self.match(r"#.*\n")
            if match:
                continue
            match = self.match(
                r"(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1", re.S
            )
            if match:
                continue
            match = self.match(r"(%s)" % text_re)
            if match and not (
                watch_nesting
                and (brace_level > 0 or paren_level > 0 or bracket_level > 0)
            ):
                return (
                    self.text[
                        startpos : self.match_position - len(match.group(1))
                    ],
                    match.group(1),
                )
            elif not match:
                match = self.match(r"(.*?)(?=\"|\'|#|%s)" % text_re, re.S)
            if match:
                brace_level += match.group(1).count("{")
                brace_level -= match.group(1).count("}")
                paren_level += match.group(1).count("(")
                paren_level -= match.group(1).count(")")
                bracket_level += match.group(1).count("[")
                bracket_level -= match.group(1).count("]")
                continue
            raise exceptions.SyntaxException(
                "Expected: %s" % ",".join(text), **self.exception_kwargs
            ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:41,代码来源:lexer.py

示例5: parse

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def parse(code, mode="exec", **exception_kwargs):
    """Parse an expression into AST"""

    try:
        return _ast_util.parse(code, "<unknown>", mode)
    except Exception:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)"
            % (
                compat.exception_as().__class__.__name__,
                compat.exception_as(),
                code[0:50],
            ),
            **exception_kwargs
        ) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:17,代码来源:pyparser.py

示例6: match_control_line

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def match_control_line(self):
        match = self.match(
            r"(?<=^)[\t ]*(%(?!%)|##)[\t ]*((?:(?:\\r?\n)|[^\r\n])*)"
            r"(?:\r?\n|\Z)",
            re.M,
        )
        if match:
            operator = match.group(1)
            text = match.group(2)
            if operator == "%":
                m2 = re.match(r"(end)?(\w+)\s*(.*)", text)
                if not m2:
                    raise exceptions.SyntaxException(
                        "Invalid control line: '%s'" % text,
                        **self.exception_kwargs
                    )
                isend, keyword = m2.group(1, 2)
                isend = isend is not None

                if isend:
                    if not len(self.control_line):
                        raise exceptions.SyntaxException(
                            "No starting keyword '%s' for '%s'"
                            % (keyword, text),
                            **self.exception_kwargs
                        )
                    elif self.control_line[-1].keyword != keyword:
                        raise exceptions.SyntaxException(
                            "Keyword '%s' doesn't match keyword '%s'"
                            % (text, self.control_line[-1].keyword),
                            **self.exception_kwargs
                        )
                self.append_node(parsetree.ControlLine, keyword, isend, text)
            else:
                self.append_node(parsetree.Comment, text)
            return True
        else:
            return False 
开发者ID:remg427,项目名称:misp42splunk,代码行数:40,代码来源:lexer.py

示例7: parse_until_text

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def parse_until_text(self, watch_nesting, *text):
        startpos = self.match_position
        text_re = r'|'.join(text)
        brace_level = 0
        paren_level = 0
        bracket_level = 0
        while True:
            match = self.match(r'#.*\n')
            if match:
                continue
            match = self.match(r'(\"\"\"|\'\'\'|\"|\')[^\\]*?(\\.[^\\]*?)*\1',
                               re.S)
            if match:
                continue
            match = self.match(r'(%s)' % text_re)
            if match and not (watch_nesting
                              and (brace_level > 0 or paren_level > 0
                                   or bracket_level > 0)):
                return \
                    self.text[startpos:
                              self.match_position - len(match.group(1))],\
                    match.group(1)
            elif not match:
                match = self.match(r"(.*?)(?=\"|\'|#|%s)" % text_re, re.S)
            if match:
                brace_level += match.group(1).count('{')
                brace_level -= match.group(1).count('}')
                paren_level += match.group(1).count('(')
                paren_level -= match.group(1).count(')')
                bracket_level += match.group(1).count('[')
                bracket_level -= match.group(1).count(']')
                continue
            raise exceptions.SyntaxException(
                "Expected: %s" %
                ','.join(text),
                **self.exception_kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:38,代码来源:lexer.py

示例8: append_node

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def append_node(self, nodecls, *args, **kwargs):
        kwargs.setdefault('source', self.text)
        kwargs.setdefault('lineno', self.matched_lineno)
        kwargs.setdefault('pos', self.matched_charpos)
        kwargs['filename'] = self.filename
        node = nodecls(*args, **kwargs)
        if len(self.tag):
            self.tag[-1].nodes.append(node)
        else:
            self.template.nodes.append(node)
        # build a set of child nodes for the control line
        # (used for loop variable detection)
        # also build a set of child nodes on ternary control lines
        # (used for determining if a pass needs to be auto-inserted
        if self.control_line:
            control_frame = self.control_line[-1]
            control_frame.nodes.append(node)
            if not (isinstance(node, parsetree.ControlLine) and
                    control_frame.is_ternary(node.keyword)):
                if self.ternary_stack and self.ternary_stack[-1]:
                    self.ternary_stack[-1][-1].nodes.append(node)
        if isinstance(node, parsetree.Tag):
            if len(self.tag):
                node.parent = self.tag[-1]
            self.tag.append(node)
        elif isinstance(node, parsetree.ControlLine):
            if node.isend:
                self.control_line.pop()
                self.ternary_stack.pop()
            elif node.is_primary:
                self.control_line.append(node)
                self.ternary_stack.append([])
            elif self.control_line and \
                    self.control_line[-1].is_ternary(node.keyword):
                self.ternary_stack[-1].append(node)
            elif self.control_line and \
                    not self.control_line[-1].is_ternary(node.keyword):
                raise exceptions.SyntaxException(
                    "Keyword '%s' not a legal ternary for keyword '%s'" %
                    (node.keyword, self.control_line[-1].keyword),
                    **self.exception_kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:43,代码来源:lexer.py

示例9: parse

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def parse(code, mode='exec', **exception_kwargs):
    """Parse an expression into AST"""

    try:
        return _ast_util.parse(code, '<unknown>', mode)
    except Exception:
        raise exceptions.SyntaxException(
            "(%s) %s (%r)" % (
                compat.exception_as().__class__.__name__,
                compat.exception_as(),
                code[0:50]
            ), **exception_kwargs) 
开发者ID:jpush,项目名称:jbox,代码行数:14,代码来源:pyparser.py

示例10: test_unclosed_tag

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

            <%def name="foo()">
             other text
        """
        try:
            Lexer(template).parse()
            assert False
        except exceptions.SyntaxException:
            eq_(
                str(compat.exception_as()),
                "Unclosed tag: <%def> at line: 5 char: 9",
            ) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:16,代码来源:test_lexer.py

示例11: test_onlyclosed_tag

# 需要导入模块: from mako import exceptions [as 别名]
# 或者: from mako.exceptions import SyntaxException [as 别名]
def test_onlyclosed_tag(self):
        template = """
            <%def name="foo()">
                foo
            </%def>

            </%namespace>

            hi.
        """
        self.assertRaises(exceptions.SyntaxException, Lexer(template).parse) 
开发者ID:sqlalchemy,项目名称:mako,代码行数:13,代码来源:test_lexer.py


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