• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python pygments.format函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: format

 def format(tok, tik=None):
     if tik:
         tok = (tok, tik)
     if isinstance(tok, tuple):
         return pygments.format([tok], formatter)
     else:
         return pygments.format(tok, formatter)
开发者ID:Stenean,项目名称:voltron,代码行数:7,代码来源:register.py


示例2: render

    def render(self, results):
        target = None
        self.trunc_top = self.args.reverse

        t_res, m_res = results

        if t_res and t_res.is_success and len(t_res.targets) > 0:
            target = t_res.targets[0]

            if self.args.deref or self.args.words:
                self.args.bytes = target['addr_size']

            f = pygments.formatters.get_formatter_by_name(self.config.format.pygments_formatter,
                                                          style=self.config.format.pygments_style)

            if m_res and m_res.is_success:
                lines = pygments.format(self.generate_tokens(results), f).split('\n')
                self.body = '\n'.join(reversed(lines)).strip() if self.args.reverse else '\n'.join(lines)
                self.info = '[0x{0:0=4x}:'.format(len(m_res.memory)) + self.config.format.addr_format.format(m_res.address) + ']'
            else:
                log.error("Error reading memory: {}".format(m_res.message))
                self.body = pygments.format([(Error, m_res.message)], f)
                self.info = ''

            # Store the memory
            if self.args.track:
                self.last_address = m_res.address
                self.last_memory = m_res.memory
        else:
            self.body = self.colour("Failed to get targets", 'red')

        if not self.title:
            self.title = "[memory]"

        super(MemoryView, self).render(results)
开发者ID:huayl,项目名称:voltron,代码行数:35,代码来源:memory.py


示例3: test_unicode_handling

    def test_unicode_handling(self):
        # test that the formatter supports encoding and Unicode
        tokens = list(lexers.PythonLexer(encoding='utf-8').
                      get_tokens("def f(): 'ä'"))
        for formatter, info in formatters.FORMATTERS.iteritems():
            try:
                inst = formatter(encoding=None)
            except (ImportError, FontNotFound):
                # some dependency or font not installed
                continue

            if formatter.name != 'Raw tokens':
                out = format(tokens, inst)
                if formatter.unicodeoutput:
                    self.assert_(type(out) is unicode)

                inst = formatter(encoding='utf-8')
                out = format(tokens, inst)
                self.assert_(type(out) is bytes, '%s: %r' % (formatter, out))
                # Cannot test for encoding, since formatters may have to escape
                # non-ASCII characters.
            else:
                inst = formatter()
                out = format(tokens, inst)
                self.assert_(type(out) is bytes, '%s: %r' % (formatter, out))
开发者ID:erickt,项目名称:pygments,代码行数:25,代码来源:test_basic_api.py


示例4: test_bare_class_handler

def test_bare_class_handler():
    from pygments.formatters import HtmlFormatter
    from pygments.lexers import PythonLexer
    try:
        lex('test\n', PythonLexer)
    except TypeError as e:
        assert 'lex() argument must be a lexer instance' in str(e)
    else:
        assert False, 'nothing raised'
    try:
        format([], HtmlFormatter)
    except TypeError as e:
        assert 'format() argument must be a formatter instance' in str(e)
    else:
        assert False, 'nothing raised'
开发者ID:Oire,项目名称:gobyexample,代码行数:15,代码来源:test_basic_api.py


示例5: test_unicode_handling

    def test_unicode_handling(self):
        # test that the formatter supports encoding and Unicode
        tokens = list(lexers.PythonLexer(encoding='utf-8').get_tokens("def f(): 'ä'"))
        for formatter, info in formatters.FORMATTERS.iteritems():
            try:
                inst = formatter(encoding=None)
            except (ImportError, FontNotFound):
                # some dependency or font not installed
                continue
            out = format(tokens, inst)
            if formatter.unicodeoutput:
                self.assert_(type(out) is unicode)

            inst = formatter(encoding='utf-8')
            out = format(tokens, inst)
            self.assert_(type(out) is str)
开发者ID:smorstabilini,项目名称:ilmioquartiere,代码行数:16,代码来源:test_basic_api.py


示例6: push

    def push(self, line):
        """Push a line of code onto the buffer, run the buffer

        If the interpreter successfully runs the code, clear the buffer
        Return ("for stdout", "for_stderr", finished?)
        """
        self.buffer.append(line)
        indent = len(re.match(r'[ ]*', line).group())

        if line.endswith(':'):
            indent = max(0, indent + INDENT_AMOUNT)
        elif line and line.count(' ') == len(self._current_line):
            indent = max(0, indent - INDENT_AMOUNT)
        elif line and ':' not in line and line.strip().startswith(('return', 'pass', 'raise', 'yield')):
            indent = max(0, indent - INDENT_AMOUNT)
        out_spot = sys.stdout.tell()
        err_spot = sys.stderr.tell()
        #logging.debug('running %r in interpreter', self.buffer)
        unfinished = self.interp.runsource('\n'.join(self.buffer))
        self.display_buffer.append(bpythonparse(format(self.tokenize(line), self.formatter))) #current line not added to display buffer if quitting
        sys.stdout.seek(out_spot)
        sys.stderr.seek(err_spot)
        out = sys.stdout.read()
        err = sys.stderr.read()
        if unfinished and not err:
            logging.debug('unfinished - line added to buffer')
            return (None, None, False, indent)
        else:
            logging.debug('finished - buffer cleared')
            self.display_lines.extend(self.display_buffer_lines)
            self.display_buffer = []
            self.buffer = []
            if err:
                indent = 0
            return (out[:-1], err[:-1], True, indent)
开发者ID:dmlicht,项目名称:scottwasright,代码行数:35,代码来源:repl.py


示例7: string_to_fmtstr

def string_to_fmtstr(x):
    from pygments import format
    from bpython.formatter import BPythonFormatter
    from bpython._py3compat import PythonLexer
    from bpython.config import Struct, loadini, default_config_path
    config = Struct()
    loadini(config, default_config_path())
    return parse(format(PythonLexer().get_tokens(x), BPythonFormatter(config.color_scheme)))
开发者ID:0x0all,项目名称:curtsies,代码行数:8,代码来源:bpythonparse.py


示例8: highlightBlock

	def highlightBlock(self, text):
		"""Takes a block, applies format to the document. 
		according to what's in it.
		"""
		
		# I need to know where in the document we are,
		# because our formatting info is global to
		# the document
		cb = self.currentBlock()
		p = cb.position()
		'''print cb
		print p
		print cb.text()'''
		blockText = unicode(cb.text())+'\n'
		
		# The \n is not really needed, but sometimes  
		# you are in an empty last block, so your position is
		# **after** the end of the document.
		
		text=unicode(self.document().toPlainText())+'\n'
		
		# Yes, re-highlight the whole document.
		# There **must** be some optimization possibilities
		# but it seems fast enough.
		
		#highlight(blockText,self.lexer,self.formatter)
		tokens = pygments.lex(blockText, self.lexer)
		self.docTokens[cb.blockNumber()] = tokens
		pygments.format(tokens, self.formatter)
		data = self.formatter.getData()
		
		
		# Just apply the formatting to this block.
		# For titles, it may be necessary to backtrack
		# and format a couple of blocks **earlier**.
		for i in range(len(unicode(blockText))):
			try:
				self.setFormat(i,1,data[i])
			except IndexError:
				pass
		
		# I may need to do something about this being called
		# too quickly.
		self.tstamp=time.time() 
开发者ID:TokinT-Mac,项目名称:Jot,代码行数:44,代码来源:highlighter.py


示例9: raw_format

    def raw_format(cls, tokens):
        """Format the given list of tokens as a simple string (no color)

        :param tokens: the input list of token to format
        :type tokens: tuple[Token, str]
        :rtype: str
        """

        formatter = get_formatter_by_name(Formatter.NO_COLOR, encoding=Formatter.ENCODING)
        return pygments.format(tokens, formatter)
开发者ID:0xcharly,项目名称:pycr,代码行数:10,代码来源:output.py


示例10: test_formatter_encodings

def test_formatter_encodings():
    from pygments.formatters import HtmlFormatter

    # unicode output
    fmt = HtmlFormatter()
    tokens = [(Text, u"ä")]
    out = format(tokens, fmt)
    assert type(out) is text_type
    assert u"ä" in out

    # encoding option
    fmt = HtmlFormatter(encoding="latin1")
    tokens = [(Text, u"ä")]
    assert u"ä".encode("latin1") in format(tokens, fmt)

    # encoding and outencoding option
    fmt = HtmlFormatter(encoding="latin1", outencoding="utf8")
    tokens = [(Text, u"ä")]
    assert u"ä".encode("utf8") in format(tokens, fmt)
开发者ID:spencerlyon2,项目名称:pygments,代码行数:19,代码来源:test_basic_api.py


示例11: test_encodings

    def test_encodings(self):
        from pygments.formatters import HtmlFormatter

        # unicode output
        fmt = HtmlFormatter()
        tokens = [(Text, u"ä")]
        out = format(tokens, fmt)
        self.assert_(type(out) is unicode)
        self.assert_(u"ä" in out)

        # encoding option
        fmt = HtmlFormatter(encoding="latin1")
        tokens = [(Text, u"ä")]
        self.assert_(u"ä".encode("latin1") in format(tokens, fmt))

        # encoding and outencoding option
        fmt = HtmlFormatter(encoding="latin1", outencoding="utf8")
        tokens = [(Text, u"ä")]
        self.assert_(u"ä".encode("utf8") in format(tokens, fmt))
开发者ID:erickt,项目名称:pygments,代码行数:19,代码来源:test_basic_api.py


示例12: format

    def format(cls, tokens):
        """Format the given list of tokens

        :param tokens: the input list of token to format
        :type tokens: tuple[Token, str]
        :rtype: str
        """

        cls.__initialize()
        return pygments.format(tokens, cls.formatter)
开发者ID:0xcharly,项目名称:pycr,代码行数:10,代码来源:output.py


示例13: print_color

 def print_color(self, string, hide=False, **kwargs):
     if isinstance(string, str):
         s = self.format_color(string, hide=hide)
     else:
         # assume this is a list of (Token, str) tuples and format it
         env = builtins.__xonsh_env__
         self.styler.style_name = env.get('XONSH_COLOR_STYLE')
         style_proxy = pyghooks.xonsh_style_proxy(self.styler)
         formatter = Terminal256Formatter(style=style_proxy)
         s = pygments.format(string, formatter).rstrip()
     print(s, **kwargs)
开发者ID:PeterHancock,项目名称:xonsh,代码行数:11,代码来源:readline_shell.py


示例14: verify

    def verify(formatter):
        try:
            inst = formatter(encoding=None)
        except (ImportError, FontNotFound):
            # some dependency or font not installed
            return

        if formatter.name != "Raw tokens":
            out = format(tokens, inst)
            if formatter.unicodeoutput:
                assert type(out) is unicode

            inst = formatter(encoding="utf-8")
            out = format(tokens, inst)
            assert type(out) is bytes, "%s: %r" % (formatter, out)
            # Cannot test for encoding, since formatters may have to escape
            # non-ASCII characters.
        else:
            inst = formatter()
            out = format(tokens, inst)
            assert type(out) is bytes, "%s: %r" % (formatter, out)
开发者ID:dirkjan111,项目名称:dirkjandegroot.nl,代码行数:21,代码来源:test_basic_api.py


示例15: current_line_formatted

 def current_line_formatted(self):
     """The colored current line (no prompt, not wrapped)"""
     if self.config.syntax:
         fs = bpythonparse(format(self.tokenize(self._current_line), self.formatter))
         logging.debug('Display line %r -> %r', self._current_line, fs)
     else:
         fs = fmtstr(self._current_line)
     if hasattr(self, 'old_fs') and str(fs) != str(self.old_fs):
         pass
         #logging.debug('calculating current formatted line: %r', repr(fs))
     self.old_fs = fs
     return fs
开发者ID:NaveenPrasanth,项目名称:testingrepo,代码行数:12,代码来源:repl.py


示例16: unhighlight_paren

 def unhighlight_paren(self):
     """set self.display_buffer after """
     if self.highlighted_paren is not None:
         lineno, saved_tokens = self.highlighted_paren
         if lineno == len(self.display_buffer):
             # then this is the current line, so don't worry about it
             return
         self.highlighted_paren = None
         logging.debug('trying to unhighlight a paren on line %r', lineno)
         logging.debug('with these tokens: %r', saved_tokens)
         new = bpythonparse(format(saved_tokens, self.formatter))
         self.display_buffer[lineno][:len(new)] = new
开发者ID:dmlicht,项目名称:scottwasright,代码行数:12,代码来源:repl.py


示例17: log

    def log(self, tokens, stream=sys.stdout):
        """Log the input token stream with the standard Python logging
        mecanism.

        PARAMETERS
            log_fn: the logging function to use
            tokens: the input tokens stream
        """

        assert self.formatter is not None, 'Internal error'
        print >> stream, pygments.format(tokens, self.formatter)
        stream.flush()
开发者ID:AdaCore,项目名称:gnatdashboard,代码行数:12,代码来源:testsuite.py


示例18: verify

    def verify(formatter):
        try:
            inst = formatter(encoding=None)
        except (ImportError, FontNotFound):
            # some dependency or font not installed
            raise support.SkipTest

        if formatter.name != 'Raw tokens':
            out = format(tokens, inst)
            if formatter.unicodeoutput:
                assert type(out) is text_type, '%s: %r' % (formatter, out)

            inst = formatter(encoding='utf-8')
            out = format(tokens, inst)
            assert type(out) is bytes, '%s: %r' % (formatter, out)
            # Cannot test for encoding, since formatters may have to escape
            # non-ASCII characters.
        else:
            inst = formatter()
            out = format(tokens, inst)
            assert type(out) is bytes, '%s: %r' % (formatter, out)
开发者ID:spencerlyon2,项目名称:pygments,代码行数:21,代码来源:test_basic_api.py


示例19: write_module_coverage_file

    def write_module_coverage_file(self, app, moduleName, sourceFileName, num_of_lines, not_covered_lines = [], excluded_lines = []):
        ''' Set and writes the coverage report '''
        from django.template import Context
        from django.template.loader import get_template
        #Decode a file
        fo = codecs.open(sourceFileName, 'rb', "utf-8")
        try:
            source = fo.read()
        finally:
            fo.close()

        try:
            offset = 0
            lines = source.split("\n")
            while lines[ offset ] == "":
                offset += 1
                if offset > 0:
                    not_covered_lines = [x - 1 for x in not_covered_lines]
        except IndexError:
            offset = 0

        #Lexer tokenize an input string
        lexer = get_lexer_by_name("py")

        tokens = lex(source, lexer)
        fmt = CssHtmlFormatter(linenos = 'inline', hl_lines = not_covered_lines, noclasses = False, css_lines = {"skipped" : excluded_lines})
        fmt.lineseparator = "\n"
        source_html = format(tokens, fmt)

        ncl = len(not_covered_lines) # uncovered lines
        cl = num_of_lines - ncl # number covered lines
        el = len(excluded_lines)
        co = cl > 0 and float(cl * 100 / num_of_lines) or 0

        t = get_template('coverage_module.tpl.html')
        now = datetime.datetime.now()
        html = t.render(Context({'now': now,
                                 'module':moduleName,
                                 'app':moduleName.split('.')[0],
                                 'pkgs':moduleName.split("."),
                                 'tl': num_of_lines,
                                 'cl': cl,
                                 'el': el,
                                 'co': co,
                                 'title': "%s coverage" % moduleName,
                                 'code': source_html,
                                 'GLOBAL_COVERAGE': GLOBAL_COVERAGE,
                                 }))

        fp = self.get_file_handle(app, moduleName)
        fp.write(html.encode('utf-8'))
        fp.close()
开发者ID:adamhaney,项目名称:djangodevtools,代码行数:52,代码来源:cover.py


示例20: format

    def format(cls, tokens):
        """
        Format the given list of tokens.

        PARAMETERS
            tokens: the input list of token to format

        RETURNS
            the formatted string
        """

        cls.__initialize()
        return pygments.format(tokens, cls.formatter)
开发者ID:enzbang,项目名称:pycr,代码行数:13,代码来源:output.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python pygments.highlight函数代码示例发布时间:2022-05-25
下一篇:
Python pygmaps.maps函数代码示例发布时间:2022-05-25
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap