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


Python TextWriter.write方法代码示例

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


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

示例1: TextBuilder

# 需要导入模块: from sphinx.writers.text import TextWriter [as 别名]
# 或者: from sphinx.writers.text.TextWriter import write [as 别名]
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    epilog = __('The text files are in %(outdir)s.')

    out_suffix = '.txt'
    allow_parallel = True
    default_translator_class = TextTranslator

    current_docname = None  # type: str

    def init(self):
        # type: () -> None
        # section numbers for headings in the currently visited document
        self.secnumbers = {}  # type: Dict[str, Tuple[int, ...]]

    def get_outdated_docs(self):
        # type: () -> Iterator[str]
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = path.join(self.outdir, docname + self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except OSError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        # type: (str, str) -> str
        return ''

    def prepare_writing(self, docnames):
        # type: (Set[str]) -> None
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        # type: (str, nodes.Node) -> None
        self.current_docname = docname
        self.secnumbers = self.env.toc_secnumbers.get(docname, {})
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            with open(outfilename, 'w', encoding='utf-8') as f:
                f.write(self.writer.output)
        except OSError as err:
            logger.warning(__("error writing file %s: %s"), outfilename, err)

    def finish(self):
        # type: () -> None
        pass
开发者ID:lmregus,项目名称:Portfolio,代码行数:62,代码来源:text.py

示例2: TextBuilder

# 需要导入模块: from sphinx.writers.text import TextWriter [as 别名]
# 或者: from sphinx.writers.text.TextWriter import write [as 别名]
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    out_suffix = '.txt'
    allow_parallel = True
    default_translator_class = TextTranslator

    current_docname = None  # type: unicode

    def init(self):
        # type: () -> None
        pass

    def get_outdated_docs(self):
        # type: () -> Iterator[unicode]
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.env.doc2path(docname, self.outdir,
                                           self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        # type: (unicode, unicode) -> unicode
        return ''

    def prepare_writing(self, docnames):
        # type: (Set[unicode]) -> None
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        # type: (unicode, nodes.Node) -> None
        self.current_docname = docname
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            with codecs.open(outfilename, 'w', 'utf-8') as f:  # type: ignore
                f.write(self.writer.output)
        except (IOError, OSError) as err:
            logger.warning("error writing file %s: %s", outfilename, err)

    def finish(self):
        # type: () -> None
        pass
开发者ID:nvmanh,项目名称:plant,代码行数:59,代码来源:text.py

示例3: write

# 需要导入模块: from sphinx.writers.text import TextWriter [as 别名]
# 或者: from sphinx.writers.text.TextWriter import write [as 别名]
 def write(self, *ignored):
     writer = TextWriter(self)
     for label in self.status_iterator(pydoc_topic_labels, "building topics... ", length=len(pydoc_topic_labels)):
         if label not in self.env.domaindata["std"]["labels"]:
             self.warn("label %r not in documentation" % label)
             continue
         docname, labelid, sectname = self.env.domaindata["std"]["labels"][label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document("<section node>")
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding="utf-8")
         writer.write(document, destination)
         self.topics[label] = str(writer.output)
开发者ID:amjith,项目名称:oscon2012-inside-python,代码行数:15,代码来源:pyspecific.py

示例4: write

# 需要导入模块: from sphinx.writers.text import TextWriter [as 别名]
# 或者: from sphinx.writers.text.TextWriter import write [as 别名]
 def write(self, *ignored):
     writer = TextWriter(self)
     for label in self.status_iterator(pydoc_topic_labels, 'building topics... '):
         if label not in self.env.labels:
             self.warn('label %r not in documentation' % label)
             continue
         docname, labelid, sectname = self.env.labels[label]
         doctree = self.env.get_and_resolve_doctree(docname, self)
         document = new_document('<section node>')
         document.append(doctree.ids[labelid])
         destination = StringOutput(encoding='utf-8')
         writer.write(document, destination)
         self.topics[label] = writer.output
开发者ID:AkshayJoshi,项目名称:python,代码行数:15,代码来源:pyspecific.py

示例5: TextBuilder

# 需要导入模块: from sphinx.writers.text import TextWriter [as 别名]
# 或者: from sphinx.writers.text.TextWriter import write [as 别名]
class TextBuilder(Builder):
    name = 'text'
    format = 'text'
    out_suffix = '.txt'
    allow_parallel = True

    def init(self):
        pass

    def get_outdated_docs(self):
        for docname in self.env.found_docs:
            if docname not in self.env.all_docs:
                yield docname
                continue
            targetname = self.env.doc2path(docname, self.outdir,
                                           self.out_suffix)
            try:
                targetmtime = path.getmtime(targetname)
            except Exception:
                targetmtime = 0
            try:
                srcmtime = path.getmtime(self.env.doc2path(docname))
                if srcmtime > targetmtime:
                    yield docname
            except EnvironmentError:
                # source doesn't exist anymore
                pass

    def get_target_uri(self, docname, typ=None):
        return ''

    def prepare_writing(self, docnames):
        self.writer = TextWriter(self)

    def write_doc(self, docname, doctree):
        self.current_docname = docname
        destination = StringOutput(encoding='utf-8')
        self.writer.write(doctree, destination)
        outfilename = path.join(self.outdir, os_path(docname) + self.out_suffix)
        ensuredir(path.dirname(outfilename))
        try:
            f = codecs.open(outfilename, 'w', 'utf-8')
            try:
                f.write(self.writer.output)
            finally:
                f.close()
        except (IOError, OSError) as err:
            self.warn("error writing file %s: %s" % (outfilename, err))

    def finish(self):
        pass
开发者ID:lehmannro,项目名称:sphinx-mirror,代码行数:53,代码来源:text.py

示例6: render

# 需要导入模块: from sphinx.writers.text import TextWriter [as 别名]
# 或者: from sphinx.writers.text.TextWriter import write [as 别名]
    def render(self, nodes, document):

        new_document = document.copy()

        new_document.children = nodes

        writer = TextWriter(TextBuilder(self.app))
        output = writer.write(new_document, FakeDestination())

        return output.split('\n')[0]
开发者ID:k-okada,项目名称:breathe,代码行数:12,代码来源:directives.py


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