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


Python io.FileInput方法代码示例

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


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

示例1: publish_file

# 需要导入模块: from docutils import io [as 别名]
# 或者: from docutils.io import FileInput [as 别名]
def publish_file(source=None, source_path=None,
                 destination=None, destination_path=None,
                 reader=None, reader_name='standalone',
                 parser=None, parser_name='restructuredtext',
                 writer=None, writer_name='pseudoxml',
                 settings=None, settings_spec=None, settings_overrides=None,
                 config_section=None, enable_exit_status=False):
    """
    Set up & run a `Publisher` for programmatic use with file-like I/O.
    Return the encoded string output also.

    Parameters: see `publish_programmatically`.
    """
    output, pub = publish_programmatically(
        source_class=io.FileInput, source=source, source_path=source_path,
        destination_class=io.FileOutput,
        destination=destination, destination_path=destination_path,
        reader=reader, reader_name=reader_name,
        parser=parser, parser_name=parser_name,
        writer=writer, writer_name=writer_name,
        settings=settings, settings_spec=settings_spec,
        settings_overrides=settings_overrides,
        config_section=config_section,
        enable_exit_status=enable_exit_status)
    return output 
开发者ID:skarlekar,项目名称:faces,代码行数:27,代码来源:core.py

示例2: stylesheet_call

# 需要导入模块: from docutils import io [as 别名]
# 或者: from docutils.io import FileInput [as 别名]
def stylesheet_call(self, path):
        """Return code to reference or embed stylesheet file `path`"""
        if self.settings.embed_stylesheet:
            try:
                content = io.FileInput(source_path=path,
                                       encoding='utf-8').read()
                self.settings.record_dependencies.add(path)
            except IOError as err:
                msg = "Cannot embed stylesheet '%s': %s." % (
                                path, SafeString(err.strerror))
                self.document.reporter.error(msg)
                return '<--- %s --->\n' % msg
            return self.embedded_stylesheet % content
        # else link to style file:
        if self.settings.stylesheet_path:
            # adapt path relative to output (cf. config.html#stylesheet-path)
            path = utils.relative_path(self.settings._destination, path)
        return self.stylesheet_link % self.encode(path) 
开发者ID:skarlekar,项目名称:faces,代码行数:20,代码来源:_html_base.py

示例3: stylesheet_call

# 需要导入模块: from docutils import io [as 别名]
# 或者: from docutils.io import FileInput [as 别名]
def stylesheet_call(self, path):
        """Return code to reference or embed stylesheet file `path`"""
        # is it a package (no extension or *.sty) or "normal" tex code:
        (base, ext) = os.path.splitext(path)
        is_package = ext in ['.sty', '']
        # Embed content of style file:
        if self.settings.embed_stylesheet:
            if is_package:
                path = base + '.sty' # ensure extension
            try:
                content = io.FileInput(source_path=path,
                                       encoding='utf-8').read()
                self.settings.record_dependencies.add(path)
            except IOError, err:
                msg = u"Cannot embed stylesheet '%s':\n  %s." % (
                                path, SafeString(err.strerror))
                self.document.reporter.error(msg)
                return '% ' + msg.replace('\n', '\n% ')
            if is_package:
                content = '\n'.join([r'\makeatletter',
                                     content,
                                     r'\makeatother'])
            return '%% embedded stylesheet: %s\n%s' % (path, content)
        # Link to style file: 
开发者ID:jmwright,项目名称:cadquery-freecad-module,代码行数:26,代码来源:__init__.py

示例4: set_source

# 需要导入模块: from docutils import io [as 别名]
# 或者: from docutils.io import FileInput [as 别名]
def set_source(self, source=None, source_path=None):
        if source_path is None:
            source_path = self.settings._source
        else:
            self.settings._source = source_path
        # Raise IOError instead of system exit with `tracback == True`
        # TODO: change io.FileInput's default behaviour and remove this hack
        try:
            self.source = self.source_class(
                source=source, source_path=source_path,
                encoding=self.settings.input_encoding)
        except TypeError:
            self.source = self.source_class(
                source=source, source_path=source_path,
                encoding=self.settings.input_encoding) 
开发者ID:skarlekar,项目名称:faces,代码行数:17,代码来源:core.py

示例5: stylesheet_call

# 需要导入模块: from docutils import io [as 别名]
# 或者: from docutils.io import FileInput [as 别名]
def stylesheet_call(self, path):
        """Return code to reference or embed stylesheet file `path`"""
        # is it a package (no extension or *.sty) or "normal" tex code:
        (base, ext) = os.path.splitext(path)
        is_package = ext in ['.sty', '']
        # Embed content of style file:
        if self.settings.embed_stylesheet:
            if is_package:
                path = base + '.sty' # ensure extension
            try:
                content = io.FileInput(source_path=path,
                                       encoding='utf-8').read()
                self.settings.record_dependencies.add(path)
            except IOError as err:
                msg = "Cannot embed stylesheet '%s':\n  %s." % (
                                path, SafeString(err.strerror))
                self.document.reporter.error(msg)
                return '% ' + msg.replace('\n', '\n% ')
            if is_package:
                content = '\n'.join([r'\makeatletter',
                                     content,
                                     r'\makeatother'])
            return '%% embedded stylesheet: %s\n%s' % (path, content)
        # Link to style file:
        if is_package:
            path = base # drop extension
            cmd = r'\usepackage{%s}'
        else:
            cmd = r'\input{%s}'
        if self.settings.stylesheet_path:
            # adapt path relative to output (cf. config.html#stylesheet-path)
            path = utils.relative_path(self.settings._destination, path)
        return cmd % path 
开发者ID:skarlekar,项目名称:faces,代码行数:35,代码来源:__init__.py

示例6: run

# 需要导入模块: from docutils import io [as 别名]
# 或者: from docutils.io import FileInput [as 别名]
def run(self):
        """Include a file as part of the content of this reST file."""
        if not self.state.document.settings.file_insertion_enabled:
            raise self.warning('"%s" directive disabled.' % self.name)
        source = self.state_machine.input_lines.source(
            self.lineno - self.state_machine.input_offset - 1)
        source_dir = os.path.dirname(os.path.abspath(source))
        path = directives.path(self.arguments[0])
        if path.startswith('<') and path.endswith('>'):
            path = os.path.join(self.standard_include_path, path[1:-1])
        path = os.path.normpath(os.path.join(source_dir, path))
        path = utils.relative_path(None, path)
        path = nodes.reprunicode(path)
        encoding = self.options.get(
            'encoding', self.state.document.settings.input_encoding)
        e_handler=self.state.document.settings.input_encoding_error_handler
        tab_width = self.options.get(
            'tab-width', self.state.document.settings.tab_width)
        try:
            self.state.document.settings.record_dependencies.add(path)
            include_file = io.FileInput(source_path=path,
                                        encoding=encoding,
                                        error_handler=e_handler)
        except UnicodeEncodeError, error:
            raise self.severe(u'Problems with "%s" directive path:\n'
                              'Cannot encode input file path "%s" '
                              '(wrong locale?).' %
                              (self.name, SafeString(path))) 
开发者ID:skarlekar,项目名称:faces,代码行数:30,代码来源:misc.py


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