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


Python python.PythonLexer方法代码示例

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


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

示例1: main

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def main():
    # Create user interface.
    hello_world_window()

    # Enable threading in GTK. (Otherwise, GTK will keep the GIL.)
    gtk.gdk.threads_init()

    # Read input from the command line, using an event loop with this hook.
    # We use `patch_stdout`, because clicking the button will print something;
    # and that should print nicely 'above' the input line.
    with patch_stdout():
        session = PromptSession(
            "Python >>> ", inputhook=inputhook, lexer=PygmentsLexer(PythonLexer)
        )
        result = session.prompt()
    print("You said: %s" % result) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:18,代码来源:inputhook.py

示例2: __init__

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def __init__(self, **kwargs):
        super(Python2Tokenizer, self).__init__(**kwargs)
        self._lexer = PythonLexer() 
开发者ID:danhper,项目名称:bigcode-tools,代码行数:5,代码来源:tokenizer.py

示例3: _highlight

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def _highlight(self, source: str) -> str:
        """Highlight the given source code if we have markup support."""
        if not self.hasmarkup or not self.code_highlight:
            return source
        try:
            from pygments.formatters.terminal import TerminalFormatter
            from pygments.lexers.python import PythonLexer
            from pygments import highlight
        except ImportError:
            return source
        else:
            highlighted = highlight(
                source, PythonLexer(), TerminalFormatter(bg="dark")
            )  # type: str
            return highlighted 
开发者ID:pytest-dev,项目名称:pytest,代码行数:17,代码来源:terminalwriter.py

示例4: __init__

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def __init__(self, **options):
        super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer,
                                               **options) 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:5,代码来源:parsers.py

示例5: get_tokens_unprocessed

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def get_tokens_unprocessed(self, text):
        pylexer = PythonLexer(**self.options)
        for pos, type_, value in pylexer.get_tokens_unprocessed(text):
            if type_ == Token.Error and value == '$':
                type_ = Comment.Preproc
            yield pos, type_, value 
开发者ID:joxeankoret,项目名称:pigaios,代码行数:8,代码来源:templates.py

示例6: main

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def main():
    # Printing a manually constructed list of (Token, text) tuples.
    text = [
        (Token.Keyword, "print"),
        (Token.Punctuation, "("),
        (Token.Literal.String.Double, '"'),
        (Token.Literal.String.Double, "hello"),
        (Token.Literal.String.Double, '"'),
        (Token.Punctuation, ")"),
        (Token.Text, "\n"),
    ]

    print_formatted_text(PygmentsTokens(text))

    # Printing the output of a pygments lexer.
    tokens = list(pygments.lex('print("Hello")', lexer=PythonLexer()))
    print_formatted_text(PygmentsTokens(tokens))

    # With a custom style.
    style = Style.from_dict(
        {
            "pygments.keyword": "underline",
            "pygments.literal.string": "bg:#00ff00 #ffffff",
        }
    )
    print_formatted_text(PygmentsTokens(tokens), style=style) 
开发者ID:prompt-toolkit,项目名称:python-prompt-toolkit,代码行数:28,代码来源:pygments-tokens.py

示例7: output_why_test_failed

# 需要导入模块: from pygments.lexers import python [as 别名]
# 或者: from pygments.lexers.python import PythonLexer [as 别名]
def output_why_test_failed(self, test_result: TestResult):
        err = test_result.error
        if isinstance(err, TestFailure):
            src_lines, line_num = inspect.getsourcelines(test_result.test.fn)

            # TODO: Only include lines up to where the failure occurs
            if src_lines[-1].strip() == "":
                src_lines = src_lines[:-1]

            gutter_width = len(str(len(src_lines) + line_num))

            def gutter(i):
                offset_line_num = i + line_num
                rv = f"{str(offset_line_num):>{gutter_width}}"
                if offset_line_num == err.error_line:
                    return colored(f"{rv} ! ", color="red")
                else:
                    return lightblack(f"{rv} | ")

            if err.operator in Comparison:
                src = "".join(src_lines)
                src = highlight(src, PythonLexer(), TerminalFormatter())
                src = f"".join(
                    [gutter(i) + l for i, l in enumerate(src.splitlines(keepends=True))]
                )
                print(indent(src, DOUBLE_INDENT))

                if err.operator == Comparison.Equals:
                    self.print_failure_equals(err)
        else:
            self.print_traceback(err)

        print(Style.RESET_ALL) 
开发者ID:darrenburns,项目名称:ward,代码行数:35,代码来源:terminal.py


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