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


Python StringIO.getvalue方法代码示例

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


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

示例1: test_correct_output

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def test_correct_output(self):
        hfmt = HtmlFormatter(nowrap=True)
        houtfile = StringIO()
        hfmt.format(tokensource, houtfile)

        nfmt = NullFormatter()
        noutfile = StringIO()
        nfmt.format(tokensource, noutfile)

        stripped_html = re.sub('<.*?>', '', houtfile.getvalue())
        escaped_text = escape_html(noutfile.getvalue())
        self.assertEqual(stripped_html, escaped_text)
开发者ID:sol,项目名称:pygments,代码行数:14,代码来源:test_html_formatter.py

示例2: test_linenos

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def test_linenos(self):
     optdict = dict(linenos=True)
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre>\s+1\s+2\s+3", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例3: test_linenos_with_startnum

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def test_linenos_with_startnum(self):
     optdict = dict(linenos=True, linenostart=5)
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre>\s+5\s+6\s+7", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例4: test_filename

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def test_filename(self):
     optdict = dict(filename="test.py")
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<span class=\"filename\">test.py</span><pre>", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例5: test_lineanchors_with_startnum

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def test_lineanchors_with_startnum(self):
     optdict = dict(lineanchors="foo", linenostart=5)
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre><span></span><a name=\"foo-5\">", html))
开发者ID:sol,项目名称:pygments,代码行数:9,代码来源:test_html_formatter.py

示例6: test_lineanchors

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def test_lineanchors(self):
     optdict = dict(lineanchors="foo")
     outfile = StringIO()
     fmt = HtmlFormatter(**optdict)
     fmt.format(tokensource, outfile)
     html = outfile.getvalue()
     self.assertTrue(re.search("<pre><a name=\"foo-1\">", html))
开发者ID:hacksterio,项目名称:pygments.rb,代码行数:9,代码来源:test_html_formatter.py

示例7: format_rtf

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def format_rtf(self, t):
     tokensource = list(TextLexer().get_tokens(t))
     fmt = RtfFormatter()
     buf = StringIO()
     fmt.format(tokensource, buf)
     result = buf.getvalue()
     buf.close()
     return result
开发者ID:JasonGross,项目名称:pygments-main,代码行数:10,代码来源:test_rtf_formatter.py

示例8: test_reasonable_output_lineno

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def test_reasonable_output_lineno(self):
        out = StringIO()
        TerminalFormatter(linenos=True).format(DEMO_TOKENS, out)
        plain = strip_ansi(out.getvalue())
        self.assertEqual(DEMO_TEXT.count('\n') + 1, plain.count('\n'))
        print(repr(plain))

        for a, b in zip(DEMO_TEXT.splitlines(), plain.splitlines()):
            self.assertTrue(a in b)
开发者ID:sol,项目名称:pygments,代码行数:11,代码来源:test_terminal_formatter.py

示例9: format_unencoded

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def format_unencoded(self, tokensource, outfile):
        # TODO: add support for background colors
        t2n = self.ttype2name
        cp = self.commandprefix

        if self.full:
            realoutfile = outfile
            outfile = StringIO()

        outfile.write(r'\begin{Verbatim}[[email protected]\[\]')
        if self.linenos:
            start, step = self.linenostart, self.linenostep
            outfile.write(',numbers=left' +
                          (start and ',firstnumber=%d' % start or '') +
                          (step and ',stepnumber=%d' % step or ''))
        if self.verboptions:
            outfile.write(',' + self.verboptions)
        outfile.write(']\n')

        for ttype, value in tokensource:
            value = escape_tex(value, self.commandprefix)
            styles = []
            while ttype is not Token:
                try:
                    styles.append(t2n[ttype])
                except KeyError:
                    # not in current style
                    styles.append(_get_ttype_name(ttype))
                ttype = ttype.parent
            styleval = '+'.join(reversed(styles))
            if styleval:
                spl = value.split('\n')
                for line in spl[:-1]:
                    if line:
                        outfile.write("@%s[%s][%s]" % (cp, styleval, line))
                    outfile.write('\n')
                if spl[-1]:
                    outfile.write("@%s[%s][%s]" % (cp, styleval, spl[-1]))
            else:
                outfile.write(value)

        outfile.write('\\end{Verbatim}\n')

        if self.full:
            realoutfile.write(DOC_TEMPLATE %
                dict(docclass  = self.docclass,
                     preamble  = self.preamble,
                     title     = self.title,
                     encoding  = self.encoding or 'latin1',
                     styledefs = self.get_style_defs(),
                     code      = outfile.getvalue()))
开发者ID:Arachnid,项目名称:bloggart,代码行数:53,代码来源:latex.py

示例10: test_ctags

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
 def test_ctags(self):
     try:
         import ctags
     except ImportError:
         # we can't check without the ctags module, but at least check the exception
         self.assertRaises(RuntimeError, HtmlFormatter, tagsfile='support/tags')
     else:
         # this tagfile says that test_ctags() is on line 165, even if it isn't
         # anymore in the actual source
         fmt = HtmlFormatter(tagsfile='support/tags', lineanchors='L',
                             tagurlformat='%(fname)s%(fext)s')
         outfile = StringIO()
         fmt.format(tokensource, outfile)
         self.assertTrue('<a href="test_html_formatter.py#L-165">test_ctags</a>'
                         in outfile.getvalue())
开发者ID:sol,项目名称:pygments,代码行数:17,代码来源:test_html_formatter.py

示例11: format_unencoded

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def format_unencoded(self, tokensource, outfile):
        # TODO: add support for background colors
        t2n = self.ttype2name
        cp = self.commandprefix

        if self.full:
            realoutfile = outfile
            outfile = StringIO()

        outfile.write(r'\begin{Verbatim}[commandchars=\\\{\}')
        if self.linenos:
            start, step = self.linenostart, self.linenostep
            outfile.write(',numbers=left' +
                          (start and ',firstnumber=%d' % start or '') +
                          (step and ',stepnumber=%d' % step or ''))
        if self.mathescape or self.texcomments:
            outfile.write(r',codes={\catcode`\$=3\catcode`\^=7\catcode`\_=8}')
        if self.verboptions:
            outfile.write(',' + self.verboptions)
        outfile.write(']\n')

        for ttype, value in tokensource:
            if ttype in Token.Comment:
                if self.texcomments:
                    # Try to guess comment starting lexeme and escape it ...
                    start = value[0:1]
                    for i in xrange(1, len(value)):
                        if start[0] != value[i]:
                            break
                        start += value[i]

                    value = value[len(start):]
                    start = escape_tex(start, self.commandprefix)

                    # ... but do not escape inside comment.
                    value = start + value
                elif self.mathescape:
                    # Only escape parts not inside a math environment.
                    parts = value.split('$')
                    in_math = False
                    for i, part in enumerate(parts):
                        if not in_math:
                            parts[i] = escape_tex(part, self.commandprefix)
                        in_math = not in_math
                    value = '$'.join(parts)
                else:
                    value = escape_tex(value, self.commandprefix)
            else:
                value = escape_tex(value, self.commandprefix)
            styles = []
            while ttype is not Token:
                try:
                    styles.append(t2n[ttype])
                except KeyError:
                    # not in current style
                    styles.append(_get_ttype_name(ttype))
                ttype = ttype.parent
            styleval = '+'.join(reversed(styles))
            if styleval:
                spl = value.split('\n')
                for line in spl[:-1]:
                    if line:
                        outfile.write("\\%s{%s}{%s}" % (cp, styleval, line))
                    outfile.write('\n')
                if spl[-1]:
                    outfile.write("\\%s{%s}{%s}" % (cp, styleval, spl[-1]))
            else:
                outfile.write(value)

        outfile.write('\\end{Verbatim}\n')

        if self.full:
            realoutfile.write(DOC_TEMPLATE %
                dict(docclass  = self.docclass,
                     preamble  = self.preamble,
                     title     = self.title,
                     encoding  = self.encoding or 'latin1',
                     styledefs = self.get_style_defs(),
                     code      = outfile.getvalue()))
开发者ID:abevoelker,项目名称:pygments.rb,代码行数:81,代码来源:latex.py

示例12: _wrap_tablelinenos

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def _wrap_tablelinenos(self, inner):
        dummyoutfile = StringIO()
        lncount = 0
        for t, line in inner:
            if t:
                lncount += 1
            dummyoutfile.write(line)

        fl = self.linenostart
        mw = len(str(lncount + fl - 1))
        sp = self.linenospecial
        st = self.linenostep
        la = self.lineanchors
        aln = self.anchorlinenos
        nocls = self.noclasses
        if sp:
            lines = []

            for i in range(fl, fl+lncount):
                if i % st == 0:
                    if i % sp == 0:
                        if aln:
                            lines.append('<a href="#%s-%d" class="special">%*d</a>' %
                                         (la, i, mw, i))
                        else:
                            lines.append('<span class="special">%*d</span>' % (mw, i))
                    else:
                        if aln:
                            lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
                        else:
                            lines.append('%*d' % (mw, i))
                else:
                    lines.append('')
            ls = '\n'.join(lines)
        else:
            lines = []
            for i in range(fl, fl+lncount):
                if i % st == 0:
                    if aln:
                        lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
                    else:
                        lines.append('%*d' % (mw, i))
                else:
                    lines.append('')
            ls = '\n'.join(lines)

        # in case you wonder about the seemingly redundant <div> here: since the
        # content in the other cell also is wrapped in a div, some browsers in
        # some configurations seem to mess up the formatting...
        if nocls:
            yield 0, ('<table class="%stable">' % self.cssclass +
                      '<tr><td><div class="linenodiv" '
                      'style="background-color: #f0f0f0; padding-right: 10px">'
                      '<pre style="line-height: 125%">' +
                      ls + '</pre></div></td><td class="code">')
        else:
            yield 0, ('<table class="%stable">' % self.cssclass +
                      '<tr><td class="linenos"><div class="linenodiv"><pre>' +
                      ls + '</pre></div></td><td class="code">')
        yield 0, dummyoutfile.getvalue()
        yield 0, '</td></tr></table>'
开发者ID:Jenyay,项目名称:outwiker,代码行数:63,代码来源:html.py

示例13: format_unencoded

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def format_unencoded(self, tokensource, outfile):
        # TODO: add support for background colors
        t2n = self.ttype2name
        cp = self.commandprefix

        if self.full:
            realoutfile = outfile
            outfile = StringIO()

        outfile.write(u'{\\tt')

        for ttype, value in tokensource:
            if ttype in Token.Comment:
                if self.texcomments:
                    # Try to guess comment starting lexeme and escape it ...
                    start = value[0:1]
                    for i in xrange(1, len(value)):
                        if start[0] != value[i]:
                            break
                        start += value[i]

                    value = value[len(start):]
                    start = escape_tex(start, cp)

                    # ... but do not escape inside comment.
                    value = start + value
                elif self.mathescape:
                    # Only escape parts not inside a math environment.
                    parts = value.split('$')
                    in_math = False
                    for i, part in enumerate(parts):
                        if not in_math:
                            parts[i] = escape_tex(part, cp)
                        in_math = not in_math
                    value = '$'.join(parts)
                elif self.escapeinside:
                    text = value
                    value = ''
                    while text:
                        a, sep1, text = text.partition(self.left)
                        if sep1:
                            b, sep2, text = text.partition(self.right)
                            if sep2:
                                value += escape_tex(a, cp) + b
                            else:
                                value += escape_tex(a + sep1 + b, cp)
                        else:
                            value += escape_tex(a, cp)
                else:
                    value = escape_tex(value, cp)
            elif ttype not in Token.Escape:
                value = escape_tex(value, cp)
            styles = []
            while ttype is not Token:
                try:
                    styles.append(t2n[ttype])
                except KeyError:
                    # not in current style
                    styles.append(_get_ttype_name(ttype))
                ttype = ttype.parent
            styleval = list(reversed(styles))[0]
            if styleval:
                spl = value.split('\n')
                for line in spl[:-1]:
                    if line:
                        outfile.write("\\%s%s{%s}" % (cp, styleval, line))
                    outfile.write('\n')
                if spl[-1]:
                    outfile.write("\\%s%s{%s}" % (cp, styleval, spl[-1]))
            else:
                outfile.write(value)

        outfile.write(u'}\n')

        if self.full:
            encoding = self.encoding or 'utf8'
            # map known existings encodings from LaTeX distribution
            encoding = {
                'utf_8': 'utf8',
                'latin_1': 'latin1',
                'iso_8859_1': 'latin1',
            }.get(encoding.replace('-', '_'), encoding)
            realoutfile.write(DOC_TEMPLATE %
                dict(docclass  = self.docclass,
                     preamble  = self.preamble,
                     title     = self.title,
                     encoding  = encoding,
                     styledefs = self.get_style_defs(),
                     code      = outfile.getvalue()))
开发者ID:evacchi,项目名称:lecturer-playground,代码行数:91,代码来源:plaintex.py

示例14: format_unencoded

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def format_unencoded(self, tokensource, outfile):
        # TODO: add support for background colors
        t2n = self.ttype2name
        cp = self.commandprefix

        if self.full:
            realoutfile = outfile
            outfile = StringIO()

        outfile.write(r'\begin{lstlisting}[language=,breaklines=true,escapeinside={(*@}{@*)},tabsize=4,framesep=0pt,xleftmargin=\FrameSep,xrightmargin=\FrameSep,frame=none,backgroundcolor=,fillcolor=')
        if self.linenos:
            start, step = self.linenostart, self.linenostep
            outfile.write(',numbers=left' +
                          (start and ',firstnumber=%d' % start or '') +
                          (step and ',stepnumber=%d' % step or ''))
        if self.mathescape:
            outfile.write(r',mathescape=true')
        if self.texcomments:
            outfile.write(r',texcl=true')
        # Switching to lstlisting broke these.
        if self.verboptions:
            outfile.write(',' + self.verboptions)
        outfile.write(']\n')

        for ttype, value in tokensource:
#            if ttype in Token.Comment:
#                if self.texcomments:
#                    # Try to guess comment starting lexeme and escape it ...
#                    start = value[0:1]
#                    for i in xrange(1, len(value)):
#                        if start[0] != value[i]:
#                            break
#                        start += value[i]
#
#                    value = value[len(start):]
#                    start = escape_tex(start, self.commandprefix)
#
#                    # ... but do not escape inside comment.
#                    value = start + value
#                elif self.mathescape:
#                    # Only escape parts not inside a math environment.
#                    parts = value.split('$')
#                    in_math = False
#                    for i, part in enumerate(parts):
#                        if not in_math:
#                            parts[i] = escape_tex(part, self.commandprefix)
#                        in_math = not in_math
#                    value = '$'.join(parts)
#                else:
#                    value = escape_tex(value, self.commandprefix)
#            else:
#                value = escape_tex(value, self.commandprefix)
            styles = []
            while ttype is not Token:
                try:
                    styles.append(t2n[ttype])
                except KeyError:
                    # not in current style
                    styles.append(_get_ttype_name(ttype))
                ttype = ttype.parent
            styleval = '+'.join(reversed(styles))
            if styleval:
                spl = value.split('\n')
                for line in spl[:-1]:
                    if line:
                        outfile.write("(*@\\%s{%s}{%s}@*)" % (cp, styleval, escape_tex(line)))
                    outfile.write('\n')
                if spl[-1]:
                    outfile.write("(*@\\%s{%s}{%s}@*)" % (cp, styleval, escape_tex(spl[-1])))
            else:
                outfile.write(value)

        outfile.write('\\end{lstlisting}\n')

        if self.full:
            realoutfile.write(DOC_TEMPLATE %
                dict(docclass  = self.docclass,
                     preamble  = self.preamble,
                     title     = self.title,
                     encoding  = self.encoding or 'utf-8',
                     styledefs = self.get_style_defs(),
                     code      = outfile.getvalue()))
开发者ID:hmphu,项目名称:2be-extras,代码行数:84,代码来源:latexlisting.py

示例15: _wrap_tablelinenos

# 需要导入模块: from pygments.util import StringIO [as 别名]
# 或者: from pygments.util.StringIO import getvalue [as 别名]
    def _wrap_tablelinenos(self, inner):
        dummyoutfile = StringIO()
        lncount = 0
        for t, line in inner:
            if t:
                lncount += 1
                dummyoutfile.write(line)

        fl = self.linenostart
        mw = len(str(lncount + fl - 1))
        sp = self.linenospecial
        st = self.linenostep
        la = self.lineanchors
        aln = self.anchorlinenos
        nocls = self.noclasses
        if sp:
            lines = []

            for i in range(fl, fl+lncount):
                if i % st == 0:
                    if i % sp == 0:
                        if aln:
                            lines.append('<a href="#%s-%d" class="special">%*d</a>' %
                                         (la, i, mw, i))
                        else:
                            lines.append('<span class="special">%*d</span>' % (mw, i))
                    else:
                        if aln:
                            lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
                        else:
                            lines.append('%*d' % (mw, i))
                else:
                    lines.append('')
            ls = '\n'.join(lines)
        else:
            lines = []
            for i in range(fl, fl+lncount):
                if i % st == 0:
                    if aln:
                        lines.append('<a href="#%s-%d">%*d</a>' % (la, i, mw, i))
                    else:
                        lines.append('%*d' % (mw, i))
                else:
                    lines.append('')
            ls = '\n'.join(lines)

        yield 0, ('<table class="%stable" data-filename="%s">' % (self.cssclass, self.filename))
        lineno = fl
        for lineno_html, code in itertools.izip(ls.split('\n'), dummyoutfile.getvalue().split('\n')):
            if nocls:
                yield 0, ('<tr><td><pre style="line-height: 125%">' +
                          lineno_html + '</pre></td><td class="code">' +
                          self._wrap_code_line(code) + '</td></tr>')
            else:
                yield 0, ('<tr><td class="linenos"><pre>' +
                          lineno_html + '</pre></td><td class="code">' +
                          self._wrap_code_line(code) + '</td></tr>')
            if lineno in self.comments:
                yield 0, self.render_diff_comment(lineno, self.comments[lineno])

            lineno += 1
        yield 0, '</table>'
开发者ID:juju-solutions,项目名称:review-queue,代码行数:64,代码来源:helpers.py


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