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


Python pycompat.b函数代码示例

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


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

示例1: run

    def run(self):
        env = self.state.document.settings.env
        baseurl = env.config.rss_baseurl
        assert baseurl, "rss_baseurl must be defined in your config.py"

        source = self.state_machine.input_lines.source(self.lineno - self.state_machine.input_offset - 1)

        rss_doc = utils.new_document(b("<rss>"), self.state.document.settings)
        Parser().parse("\n".join(self.content), rss_doc)

        rst_suffix = env.config.source_suffix
        path = os.path.relpath(source, env.srcdir).replace(rst_suffix, ".html")

        builder = env.app.builder
        docwriter = HTMLWriter(self)
        docsettings = OptionParser(defaults=env.settings, components=(docwriter,)).get_default_values()
        docsettings.compact_lists = bool(env.config.html_compact_lists)

        dest = os.path.join(env.app.outdir, os_path(env.docname) + ".rss")
        pageurl = "%s/%s" % (baseurl, path)
        with open(dest, "w") as rss:
            title = self.options.get("title", "")
            description = self.options.get("description", None)
            rss.write('<?xml version="1.0" encoding="ISO-8859-1" ?>\n')
            rss.write('<rss version="2.0">\n')
            rss.write("<channel>\n")
            rss.write("<title>%s</title>\n" % cgi.escape(title))
            rss.write("<link>%s</link>\n" % pageurl)
            if description:
                rss.write("<description>%s</description>\n" % cgi.escape(description))

            for child in rss_doc.children:
                if not isinstance(child, nodes.section):
                    continue

                title_index = child.first_child_matching_class(nodes.title)
                if title_index is None:
                    continue

                node = nodes.paragraph()
                node.extend(child.children[title_index + 1 :])

                sec_doc = utils.new_document(b("<rss-section>"), docsettings)
                sec_doc.append(node)
                visitor = RssTranslator(builder, sec_doc)
                sec_doc.walkabout(visitor)

                title = child.children[title_index].astext()
                sectionurl = "%s#%s" % (pageurl, child.get("ids")[0])
                description = "".join(visitor.body)

                rss.write("<item>\n")
                rss.write("<title>%s</title>\n" % cgi.escape(title))
                rss.write("<link>%s</link>\n" % sectionurl)
                rss.write("<description><![CDATA[%s]]></description>\n" % description)
                rss.write("</item>\n")
            rss.write("</channel>\n")
            rss.write("</rss>\n")

        return []
开发者ID:EmuxEvans,项目名称:eclim,代码行数:60,代码来源:rss.py

示例2: split_lines

 def split_lines(iter):
     buf = b('')
     for chunk in iter:
         buf += chunk
         lineend = buf.find(b('\n'))
         while lineend != -1:
             yield buf[:lineend].decode('utf-8')
             buf = buf[lineend+1:]
             lineend = buf.find(b('\n'))
     assert not buf
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:10,代码来源:intermanual.py

示例3: split_lines

 def split_lines(iter):
     buf = b("")
     for chunk in iter:
         buf += chunk
         lineend = buf.find(b("\n"))
         while lineend != -1:
             yield buf[:lineend].decode("utf-8")
             buf = buf[lineend + 1 :]
             lineend = buf.find(b("\n"))
     assert not buf
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:10,代码来源:intersphinx.py

示例4: test_config_eol

def test_config_eol(tmpdir):
    # test config file's eol patterns: LF, CRLF
    configfile = tmpdir / 'conf.py'
    for eol in ('\n', '\r\n'):
        configfile.write_bytes(b('project = "spam"' + eol))
        cfg = Config(tmpdir, 'conf.py', {}, None)
        cfg.init_values()
        assert cfg.project == u'spam'
开发者ID:SvenDowideit,项目名称:clearlinux,代码行数:8,代码来源:test_config.py

示例5: test_wordcollector

def test_wordcollector():
    doc = utils.new_document(b('test data'), settings)
    doc['file'] = 'dummy'
    parser.parse(FILE_CONTENTS, doc)

    ix = IndexBuilder(None, 'en', {}, None)
    ix.feed('filename', 'title', doc)
    assert 'boson' not in ix._mapping
    assert 'fermion' in ix._mapping
开发者ID:4grim,项目名称:hackbright-django,代码行数:9,代码来源:test_search.py

示例6: render_map

def render_map(builder, node):
    if node:
        doc = new_document(b('<partial node>'))
        doc.append(node)

        publisher = Publisher( source_class = DocTreeInput, destination_class=StringOutput)
        publisher.set_components('standalone', 'restructuredtext', 'pseudoxml')
        publisher.reader = DoctreeReader()
        publisher.writer = DitaMapWriter(builder)
        publisher.process_programmatic_settings(None, {'output_encoding': 'utf-8'}, None)
        publisher.set_source(doc, None)
        publisher.set_destination(None, None)
        publisher.publish()
        return publisher.writer.output
    output = XML_HEAD
    output += u"<map></map>"
    return output
开发者ID:Deadolus,项目名称:learning-guides,代码行数:17,代码来源:ditamapwriter.py

示例7: verify_re

def verify_re(rst, html_expected, latex_expected):
    document = utils.new_document(b('test data'), settings)
    document['file'] = 'dummy'
    parser.parse(rst, document)
    for msg in document.traverse(nodes.system_message):
        if msg['level'] == 1:
            msg.replace_self([])

    if html_expected:
        html_translator = ForgivingHTMLTranslator(app.builder, document)
        document.walkabout(html_translator)
        html_translated = ''.join(html_translator.fragment).strip()
        assert re.match(html_expected, html_translated), 'from ' + rst

    if latex_expected:
        latex_translator = ForgivingLaTeXTranslator(document, app.builder)
        latex_translator.first_document = -1 # don't write \begin{document}
        document.walkabout(latex_translator)
        latex_translated = ''.join(latex_translator.body).strip()
        assert re.match(latex_expected, latex_translated), 'from ' + repr(rst)
开发者ID:jklukas,项目名称:sphinx,代码行数:20,代码来源:test_markup.py

示例8: render_partial

    def render_partial(self, node):
        """Utility: Render a lone doctree node."""
        if node is None:
            return {"fragment": ""}
        doc = new_document(b("<partial node>"))
        doc.append(node)

        if self._publisher is None:
            self._publisher = Publisher(source_class=DocTreeInput, destination_class=StringOutput)
            self._publisher.set_components("standalone", "restructuredtext", "pseudoxml")

        pub = self._publisher

        pub.reader = DoctreeReader()
        pub.writer = HTMLWriter(self)
        pub.process_programmatic_settings(None, {"output_encoding": "unicode"}, None)
        pub.set_source(doc, None)
        pub.set_destination(None, None)
        pub.publish()
        return pub.writer.parts
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:20,代码来源:html.py

示例9: render_math

DOC_BODY = r'''
\begin{document}
%s
\end{document}
'''

DOC_BODY_PREVIEW = r'''
\usepackage[active]{preview}
\begin{document}
\begin{preview}
%s
\end{preview}
\end{document}
'''

depth_re = re.compile(b(r'\[\d+ depth=(-?\d+)\]'))

def render_math(self, math):
    """Render the LaTeX math expression *math* using latex and dvipng.

    Return the filename relative to the built document and the "depth",
    that is, the distance of image bottom and baseline in pixels, if the
    option to use preview_latex is switched on.

    Error handling may seem strange, but follows a pattern: if LaTeX or
    dvipng aren't available, only a warning is generated (since that enables
    people on machines without these programs to at least build the rest
    of the docs successfully).  If the programs are there, however, they
    may not fail since that indicates a problem in the math source.
    """
    use_preview = self.builder.config.pngmath_use_preview
开发者ID:DEShawResearch,项目名称:SIMPLEchangepoint,代码行数:31,代码来源:pngmath.py

示例10: read_chunks

 def read_chunks():
     decompressor = zlib.decompressobj()
     for chunk in iter(lambda: f.read(bufsize), b('')):
         yield decompressor.decompress(chunk)
     yield decompressor.flush()
开发者ID:MarkTseng,项目名称:docs-tools,代码行数:5,代码来源:intermanual.py

示例11: Config

    :copyright: Copyright 2007-2011 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import os
import re
import sys
from os import path

from sphinx.errors import ConfigError
from sphinx.locale import l_
from sphinx.util.osutil import make_filename
from sphinx.util.pycompat import bytes, b, convert_with_2to3

nonascii_re = re.compile(b(r'[\x80-\xff]'))

CONFIG_SYNTAX_ERROR = "There is a syntax error in your configuration file: %s"
if sys.version_info >= (3, 0):
    CONFIG_SYNTAX_ERROR += "\nDid you change the syntax from 2.x to 3.x?"

class Config(object):
    """
    Configuration file abstraction.
    """

    # the values are: (default, what needs to be rebuilt if changed)

    # If you add a value here, don't forget to include it in the
    # quickstart.py file template as well as in the docs!
开发者ID:APSL,项目名称:django-braces,代码行数:29,代码来源:config.py

示例12: b

    PNG image manipulation helpers.

    :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import struct
import binascii

from sphinx.util.pycompat import b

LEN_IEND = 12
LEN_DEPTH = 22

DEPTH_CHUNK_LEN = struct.pack('!i', 10)
DEPTH_CHUNK_START = b('tEXtDepth\x00')
IEND_CHUNK = b('\x00\x00\x00\x00IEND\xAE\x42\x60\x82')


def read_png_depth(filename):
    """Read the special tEXt chunk indicating the depth from a PNG file."""
    result = None
    f = open(filename, 'rb')
    try:
        f.seek(- (LEN_IEND + LEN_DEPTH), 2)
        depthchunk = f.read(LEN_DEPTH)
        if not depthchunk.startswith(DEPTH_CHUNK_LEN + DEPTH_CHUNK_START):
            # either not a PNG file or not containing the depth chunk
            return None
        result = struct.unpack('!i', depthchunk[14:18])[0]
    finally:
开发者ID:4grim,项目名称:hackbright-django,代码行数:31,代码来源:png.py

示例13: b

    PNG image manipulation helpers.

    :copyright: Copyright 2007-2013 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import struct
import binascii

from sphinx.util.pycompat import b

LEN_IEND = 12
LEN_DEPTH = 22

DEPTH_CHUNK_LEN = struct.pack("!i", 10)
DEPTH_CHUNK_START = b("tEXtDepth\x00")
IEND_CHUNK = b("\x00\x00\x00\x00IEND\xAE\x42\x60\x82")


def read_png_depth(filename):
    """Read the special tEXt chunk indicating the depth from a PNG file."""
    result = None
    f = open(filename, "rb")
    try:
        f.seek(-(LEN_IEND + LEN_DEPTH), 2)
        depthchunk = f.read(LEN_DEPTH)
        if not depthchunk.startswith(DEPTH_CHUNK_LEN + DEPTH_CHUNK_START):
            # either not a PNG file or not containing the depth chunk
            return None
        result = struct.unpack("!i", depthchunk[14:18])[0]
    finally:
开发者ID:ethanfine,项目名称:oh-mainline,代码行数:31,代码来源:png.py

示例14: Config

    :copyright: Copyright 2007-2014 by the Sphinx team, see AUTHORS.
    :license: BSD, see LICENSE for details.
"""

import os
import re
import sys
from os import path

from sphinx.errors import ConfigError
from sphinx.locale import l_
from sphinx.util.osutil import make_filename
from sphinx.util.pycompat import bytes, b, execfile_

nonascii_re = re.compile(b(r"[\x80-\xff]"))

CONFIG_SYNTAX_ERROR = "There is a syntax error in your configuration file: %s"
if sys.version_info >= (3, 0):
    CONFIG_SYNTAX_ERROR += "\nDid you change the syntax from 2.x to 3.x?"


class Config(object):
    """
    Configuration file abstraction.
    """

    # the values are: (default, what needs to be rebuilt if changed)

    # If you add a value here, don't forget to include it in the
    # quickstart.py file template as well as in the docs!
开发者ID:ymarfoq,项目名称:outilACVDesagregation,代码行数:30,代码来源:config.py


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