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


Python BuildEnvironment.temp_data["docname"]方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sphinx.environment import BuildEnvironment [as 别名]
# 或者: from sphinx.environment.BuildEnvironment import temp_data["docname"] [as 别名]
    def __init__(self, filename, encoding="utf8", raise_exception=False):
        """
        create an instance of a blog post from a file or a string

        @param      filename            filename or string
        @param      encoding            encoding
        @param      raise_exception     to raise an exception when the blog cannot be parsed

        The constructor creates the following members:

        * title
        * date
        * keywords
        * categories
        * _filename
        * _raw
        * rst_obj: the object generated by docutils (@see cl BlogPostDirective)
        * pub: Publisher

        .. versionchanged:: 1.3
            Parameter *raise_exception* was added to catch the standard error.
            The constructor aims at getting the text of a blog post, not
            interpreting it. The code used to throw warnings or errors due to
            unreferenced nodes.

        """
        if os.path.exists(filename):
            with open(filename, "r", encoding=encoding) as f:
                try:
                    content = f.read()
                except UnicodeDecodeError as e:
                    raise Exception(
                        'unable to read filename (encoding issue):\n  File "{0}", line 1'.format(filename)) from e
            self._filename = filename
        else:
            content = filename
            self._filename = None

        self._raw = content

        overrides = {}
        overrides['input_encoding'] = encoding
        overrides["out_blogpostlist"] = []
        overrides["blog_background"] = False
        overrides["sharepost"] = None

        overrides.update({'doctitle_xform': True,
                          'initial_header_level': 2,
                          'warning_stream': StringIO(),
                          'out_blogpostlist': [],
                          'out_runpythonlist': [],
                          })

        config = Config(None, None, overrides=overrides, tags=None)
        config.blog_background = False
        config.sharepost = None
        env = BuildEnvironment(None, None, config=config)
        env.temp_data["docname"] = "string"
        overrides["env"] = env

        errst = sys.stderr
        keeperr = StringIO()
        sys.stderr = keeperr

        output, pub = publish_programmatically(
            source_class=docio.StringInput,
            source=content,
            source_path=None,
            destination_class=docio.StringOutput,
            destination=None,
            destination_path=None,
            reader=None,
            reader_name='standalone',
            parser=None,
            parser_name='restructuredtext',
            writer=None,
            writer_name='null',
            settings=None,
            settings_spec=None,
            settings_overrides=overrides,
            config_section=None,
            enable_exit_status=None)

        sys.stderr = errst
        all_err = keeperr.getvalue()
        if len(all_err) > 0:
            if raise_exception:
                raise BlogPostParseError("unable to parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
                    all_err, self._filename, content))
            else:
                # we assume we just need the content, raising a warnings
                # might make some process fail later
                # warnings.warn("Raw rst was caught but unable to fully parse a blogpost:\nERR:\n{0}\nFILE\n{1}\nCONTENT\n{2}".format(
                #     all_err, self._filename, content))
                pass

        # document = pub.writer.document
        objects = pub.settings.out_blogpostlist

        if len(objects) != 1:
#.........这里部分代码省略.........
开发者ID:,项目名称:,代码行数:103,代码来源:

示例2: rst2html

# 需要导入模块: from sphinx.environment import BuildEnvironment [as 别名]
# 或者: from sphinx.environment.BuildEnvironment import temp_data["docname"] [as 别名]

#.........这里部分代码省略.........
        setup_plot(mockapp)
        setup_only(mockapp)

        # titles
        title_names.append("todoext_node")
        title_names.append("todo_node")
        title_names.append("mathdef_node")
        title_names.append("blocref_node")
        title_names.append("faqref_node")
        title_names.append("nbref_node")
        title_names.append("exref_node")
    else:
        writer_name = 'html'
        mockapp = MockSphinxApp(None)

    if writer is None and directives is not None and len(directives) > 0:
        raise NotImplementedError(
            "the writer must not be null if custom directives will be added, check the documentation of the fucntion")

    if directives is not None:
        for tu in directives:
            if len(tu) != 5:
                raise ValueError(
                    "directives is a list of tuple with 5 elements, check the documentation")
            name, cl, node, f1, f2 = tu
            doc_directives.register_directive(name, cl)
            # not necessary
            # nodes._add_node_class_names([node.__name__])
            writer.connect_directive_node(node.__name__, f1, f2)

    settings_overrides = default_settings.copy()
    settings_overrides.update({k: v[0]
                               for k, v in mockapp.new_options.items()})

    # next
    defopt = default_sphinx_options(**options)
    settings_overrides.update(defopt)
    warning_stringio = defopt["warning_stream"]
    _nbeq[1] = warning_stringio

    config = mockapp.config
    config.init_values(fLOG)
    config.blog_background = False
    config.sharepost = None

    writer.add_configuration_options(mockapp.new_options)
    for k in {'outdir', 'imagedir', 'confdir', 'doctreedir'}:
        setattr(writer.builder, k, settings_overrides[k])

    env = BuildEnvironment(None, None, config=config)
    env.temp_data["docname"] = "string"
    mockapp.builder.env.temp_data["docname"] = "string"
    settings_overrides["env"] = env

    lang = languages.get_language(language)
    for name in title_names:
        if name not in lang.labels:
            lang.labels[name] = TITLES[language][name]

    for k, v in sorted(settings_overrides.items()):
        fLOG("[rst2html] {0}={1}{2}".format(
            k, v, " --- added" if hasattr(config, k) else ""))
    for k, v in sorted(settings_overrides.items()):
        if hasattr(writer.builder.config, k) and writer.builder.config[k] != v:
            writer.builder.config[k] = v

    # something is screwing with sphinx or docutils, it is due to
    # direct call to nbconvert or sphinx
    # raise an exception for unknown role pending_xref
    output, pub = core.publish_programmatically(source=s, source_path=None,
                                                destination_path=None, writer=writer,
                                                writer_name=writer_name,
                                                settings_overrides=settings_overrides,
                                                source_class=StringInput,
                                                destination_class=StringOutput,
                                                destination=None,
                                                reader=None, reader_name='standalone',
                                                parser=None, parser_name='restructuredtext',
                                                settings=None, settings_spec=None,
                                                config_section=None,
                                                enable_exit_status=False)

    doctree = pub.document
    mockapp.emit('doctree-read', doctree)
    parts = pub.writer.parts

    warnval = settings_overrides["warning_stream"].getvalue()
    if warnval is not None and len(warnval) > 0:
        if warnings_log:
            fLOG(warnval)
        else:
            warnings.warn(warnval)

    if not keep_warnings:
        exp = re.sub(
            '(<div class="system-message">(.|\\n)*?</div>)', "", parts["whole"])
    else:
        exp = parts["whole"]

    return exp
开发者ID:,项目名称:,代码行数:104,代码来源:


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