當前位置: 首頁>>代碼示例>>Python>>正文


Python directives.encoding方法代碼示例

本文整理匯總了Python中docutils.parsers.rst.directives.encoding方法的典型用法代碼示例。如果您正苦於以下問題:Python directives.encoding方法的具體用法?Python directives.encoding怎麽用?Python directives.encoding使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在docutils.parsers.rst.directives的用法示例。


在下文中一共展示了directives.encoding方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: run

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def run(self):
        if not isinstance(self.state, states.SubstitutionDef):
            raise self.error(
                'Invalid context: the "%s" directive can only be used within '
                'a substitution definition.' % self.name)
        format_str = '\n'.join(self.content) or '%Y-%m-%d'
        if sys.version_info< (3, 0):
            try:
                format_str = format_str.encode(locale_encoding or 'utf-8')
            except UnicodeEncodeError:
                raise self.warning('Cannot encode date format string '
                    'with locale encoding "%s".' % locale_encoding)
        # @@@
        # Use timestamp from the `SOURCE_DATE_EPOCH`_ environment variable?
        # Pro: Docutils-generated documentation
        #      can easily be part of `reproducible software builds`__
        #
        #      __ https://reproducible-builds.org/
        #
        # Con: Changes the specs, hard to predict behaviour,
        #      no actual use case!
        #
        # See also the discussion about \date \time \year in TeX
        # http://tug.org/pipermail/tex-k/2016-May/002704.html
        # source_date_epoch = os.environ.get('SOURCE_DATE_EPOCH')
        # if (source_date_epoch
        #     and self.state.document.settings.use_source_date_epoch):
        #     text = time.strftime(format_str,
        #                          time.gmtime(int(source_date_epoch)))
        # else:
        text = time.strftime(format_str)
        if sys.version_info< (3, 0):
            # `text` is a byte string that may contain non-ASCII characters:
            try:
                text = text.decode(locale_encoding or 'utf-8')
            except UnicodeDecodeError:
                text = text.decode(locale_encoding or 'utf-8', 'replace')
                raise self.warning('Error decoding "%s"'
                    'with locale encoding "%s".' % (text, locale_encoding))
        return [nodes.Text(text)] 
開發者ID:skarlekar,項目名稱:faces,代碼行數:42,代碼來源:misc.py

示例2: run

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [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

示例3: setup

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def setup(app):
    setup.app = app
    setup.config = app.config
    setup.confdir = app.confdir

    options = {'alt': directives.unchanged,
               'height': directives.length_or_unitless,
               'width': directives.length_or_percentage_or_unitless,
               'scale': directives.nonnegative_int,
               'align': _option_align,
               'class': directives.class_option,
               'include-source': _option_boolean,
               'format': _option_format,
               'context': directives.flag,
               'nofigs': directives.flag,
               'encoding': directives.encoding
               }

    app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
    app.add_config_value('plot_pre_code', None, True)
    app.add_config_value('plot_include_source', False, True)
    app.add_config_value('plot_formats', ['png', 'hires.png', 'pdf'], True)
    app.add_config_value('plot_basedir', None, True)
    app.add_config_value('plot_html_show_formats', True, True)
    app.add_config_value('plot_rcparams', {}, True)
    app.add_config_value('plot_apply_rcparams', False, True)
    app.add_config_value('plot_working_directory', None, True)
    app.add_config_value('plot_template', None, True)

    app.connect('doctree-read', mark_plot_labels)

#------------------------------------------------------------------------------
# Doctest handling
#------------------------------------------------------------------------------ 
開發者ID:ktraunmueller,項目名稱:Computable,代碼行數:36,代碼來源:plot_directive.py

示例4: setup

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def setup(app):
    setup.app = app
    setup.config = app.config
    setup.confdir = app.confdir

    options = {'alt': directives.unchanged,
               'height': directives.length_or_unitless,
               'width': directives.length_or_percentage_or_unitless,
               'scale': directives.nonnegative_int,
               'align': _option_align,
               'class': directives.class_option,
               'include-source': _option_boolean,
               'format': _option_format,
               'context': _option_context,
               'nofigs': directives.flag,
               'encoding': directives.encoding
               }

    app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
    app.add_config_value('plot_pre_code', None, True)
    app.add_config_value('plot_include_source', False, True)
    app.add_config_value('plot_html_show_source_link', True, True)
    app.add_config_value('plot_formats', ['png', 'hires.png', 'pdf'], True)
    app.add_config_value('plot_basedir', None, True)
    app.add_config_value('plot_html_show_formats', True, True)
    app.add_config_value('plot_rcparams', {}, True)
    app.add_config_value('plot_apply_rcparams', False, True)
    app.add_config_value('plot_working_directory', None, True)
    app.add_config_value('plot_template', None, True)

    app.connect(str('doctree-read'), mark_plot_labels)

    metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
    return metadata

#------------------------------------------------------------------------------
# Doctest handling
#------------------------------------------------------------------------------ 
開發者ID:statlab,項目名稱:permute,代碼行數:40,代碼來源:plot_directive.py

示例5: setup

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def setup(app):
    setup.app = app
    setup.config = app.config
    setup.confdir = app.confdir

    options = {'alt': directives.unchanged,
               'height': directives.length_or_unitless,
               'width': directives.length_or_percentage_or_unitless,
               'scale': directives.nonnegative_int,
               'align': _option_align,
               'class': directives.class_option,
               'include-source': _option_boolean,
               'format': _option_format,
               'context': _option_context,
               'nofigs': directives.flag,
               'encoding': directives.encoding
               }

    app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
    app.add_config_value('plot_pre_code', None, True)
    app.add_config_value('plot_include_source', False, True)
    app.add_config_value('plot_html_show_source_link', True, True)
    app.add_config_value('plot_formats', ['png', 'hires.png', 'pdf'], True)
    app.add_config_value('plot_basedir', None, True)
    app.add_config_value('plot_html_show_formats', True, True)
    app.add_config_value('plot_rcparams', {}, True)
    app.add_config_value('plot_apply_rcparams', False, True)
    app.add_config_value('plot_working_directory', None, True)
    app.add_config_value('plot_template', None, True)

    app.connect(str('doctree-read'), mark_plot_labels)

#------------------------------------------------------------------------------
# Doctest handling
#------------------------------------------------------------------------------ 
開發者ID:miloharper,項目名稱:neural-network-animation,代碼行數:37,代碼來源:plot_directive.py

示例6: setup

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def setup(app):
    setup.app = app
    setup.config = app.config
    setup.confdir = app.confdir

    options = {'alt': directives.unchanged,
               'height': directives.length_or_unitless,
               'width': directives.length_or_percentage_or_unitless,
               'scale': directives.nonnegative_int,
               'align': _option_align,
               'class': directives.class_option,
               'include-source': _option_boolean,
               'format': _option_format,
               'context': _option_context,
               'nofigs': directives.flag,
               'encoding': directives.encoding
               }

    app.add_directive('plot', plot_directive, True, (0, 2, False), **options)
    app.add_config_value('plot_pre_code', None, True)
    app.add_config_value('plot_include_source', False, True)
    app.add_config_value('plot_html_show_source_link', True, True)
    app.add_config_value('plot_formats', ['png', 'hires.png', 'pdf'], True)
    app.add_config_value('plot_basedir', None, True)
    app.add_config_value('plot_html_show_formats', True, True)
    app.add_config_value('plot_rcparams', {}, True)
    app.add_config_value('plot_apply_rcparams', False, True)
    app.add_config_value('plot_working_directory', None, True)
    app.add_config_value('plot_template', None, True)

    app.connect('doctree-read', mark_plot_labels)

    metadata = {'parallel_read_safe': True, 'parallel_write_safe': True}
    return metadata

#------------------------------------------------------------------------------
# Doctest handling
#------------------------------------------------------------------------------ 
開發者ID:Relph1119,項目名稱:GraphicDesignPatternByPython,代碼行數:40,代碼來源:plot_directive.py

示例7: _get_spec

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def _get_spec(abspath, encoding):
    with open(abspath, 'rt', encoding=encoding) as stream:
        return yaml.safe_load(stream) 
開發者ID:sphinx-contrib,項目名稱:openapi,代碼行數:5,代碼來源:directive.py

示例8: create_directive_from_renderer

# 需要導入模塊: from docutils.parsers.rst import directives [as 別名]
# 或者: from docutils.parsers.rst.directives import encoding [as 別名]
def create_directive_from_renderer(renderer_cls):
    """Create rendering directive from a renderer class."""

    class _RenderingDirective(SphinxDirective):
        required_arguments = 1                  # path to openapi spec
        final_argument_whitespace = True        # path may contain whitespaces
        option_spec = dict(
            {
                'encoding': directives.encoding,    # useful for non-ascii cases :)
            },
            **renderer_cls.option_spec
        )

        def run(self):
            relpath, abspath = self.env.relfn2path(directives.path(self.arguments[0]))

            # URI parameter is crucial for resolving relative references. So we
            # need to set this option properly as it's used later down the
            # stack.
            self.options.setdefault('uri', 'file://%s' % abspath)

            # Add a given OpenAPI spec as a dependency of the referring
            # reStructuredText document, so the document is rebuilt each time
            # the spec is changed.
            self.env.note_dependency(relpath)

            # Read the spec using encoding passed to the directive or fallback to
            # the one specified in Sphinx's config.
            encoding = self.options.get('encoding', self.config.source_encoding)
            spec = _get_spec(abspath, encoding)
            return renderer_cls(self.state, self.options).render(spec)

    return _RenderingDirective 
開發者ID:sphinx-contrib,項目名稱:openapi,代碼行數:35,代碼來源:directive.py


注:本文中的docutils.parsers.rst.directives.encoding方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。