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


Python i18n.format_date函数代码示例

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


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

示例1: __init__

    def __init__(self, builder, *args, **kwds):
        BaseTranslator.__init__(self, *args, **kwds)
        self.builder = builder

        self.in_productionlist = 0

        # first title is the manpage title
        self.section_level = -1

        # docinfo set by man_pages config value
        self._docinfo['title'] = self.document.settings.title
        self._docinfo['subtitle'] = self.document.settings.subtitle
        if self.document.settings.authors:
            # don't set it if no author given
            self._docinfo['author'] = self.document.settings.authors
        self._docinfo['manual_section'] = self.document.settings.section

        # docinfo set by other config values
        self._docinfo['title_upper'] = self._docinfo['title'].upper()
        if builder.config.today:
            self._docinfo['date'] = builder.config.today
        else:
            self._docinfo['date'] = format_date(builder.config.today_fmt or _('%b %d, %Y'),
                                                language=builder.config.language)
        self._docinfo['copyright'] = builder.config.copyright
        self._docinfo['version'] = builder.config.version
        self._docinfo['manual_group'] = builder.config.project

        # In docutils < 0.11 self.append_header() was never called
        if docutils_version < (0, 11):
            self.body.append(MACRO_DEF)

        # Overwrite admonition label translations with our own
        for label, translation in admonitionlabels.items():
            self.language.labels[label] = self.deunicode(translation)
开发者ID:lelit,项目名称:sphinx,代码行数:35,代码来源:manpage.py

示例2: __init__

    def __init__(self, builder, document):
        # type: (Builder, nodes.document) -> None
        super(ManualPageTranslator, self).__init__(builder, document)

        self.in_productionlist = 0

        # first title is the manpage title
        self.section_level = -1

        # docinfo set by man_pages config value
        self._docinfo['title'] = self.settings.title
        self._docinfo['subtitle'] = self.settings.subtitle
        if self.settings.authors:
            # don't set it if no author given
            self._docinfo['author'] = self.settings.authors
        self._docinfo['manual_section'] = self.settings.section

        # docinfo set by other config values
        self._docinfo['title_upper'] = self._docinfo['title'].upper()
        if self.config.today:
            self._docinfo['date'] = self.config.today
        else:
            self._docinfo['date'] = format_date(self.config.today_fmt or _('%b %d, %Y'),
                                                language=self.config.language)
        self._docinfo['copyright'] = self.config.copyright
        self._docinfo['version'] = self.config.version
        self._docinfo['manual_group'] = self.config.project

        # Overwrite admonition label translations with our own
        for label, translation in admonitionlabels.items():
            self.language.labels[label] = self.deunicode(translation)  # type: ignore
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:31,代码来源:manpage.py

示例3: html_page_context

    def html_page_context(cls, app, pagename, templatename, context, doctree):
        """Update the Jinja2 HTML context, exposes the Versions class instance to it.

        :param sphinx.application.Sphinx app: Sphinx application object.
        :param str pagename: Name of the page being rendered (without .html or any file extension).
        :param str templatename: Page name with .html.
        :param dict context: Jinja2 HTML context.
        :param docutils.nodes.document doctree: Tree of docutils nodes.
        """
        assert templatename or doctree  # Unused, for linting.
        cls.VERSIONS.context = context
        versions = cls.VERSIONS
        this_remote = versions[cls.CURRENT_VERSION]
        banner_main_remote = versions[cls.BANNER_MAIN_VERSION] if cls.SHOW_BANNER else None

        # Update Jinja2 context.
        context['bitbucket_version'] = cls.CURRENT_VERSION
        context['current_version'] = cls.CURRENT_VERSION
        context['github_version'] = cls.CURRENT_VERSION
        context['html_theme'] = app.config.html_theme
        context['scv_banner_greatest_tag'] = cls.BANNER_GREATEST_TAG
        context['scv_banner_main_ref_is_branch'] = banner_main_remote['kind'] == 'heads' if cls.SHOW_BANNER else None
        context['scv_banner_main_ref_is_tag'] = banner_main_remote['kind'] == 'tags' if cls.SHOW_BANNER else None
        context['scv_banner_main_version'] = banner_main_remote['name'] if cls.SHOW_BANNER else None
        context['scv_banner_recent_tag'] = cls.BANNER_RECENT_TAG
        context['scv_is_branch'] = this_remote['kind'] == 'heads'
        context['scv_is_greatest_tag'] = this_remote == versions.greatest_tag_remote
        context['scv_is_recent_branch'] = this_remote == versions.recent_branch_remote
        context['scv_is_recent_ref'] = this_remote == versions.recent_remote
        context['scv_is_recent_tag'] = this_remote == versions.recent_tag_remote
        context['scv_is_root'] = cls.IS_ROOT
        context['scv_is_tag'] = this_remote['kind'] == 'tags'
        context['scv_show_banner'] = cls.SHOW_BANNER
        context['versions'] = versions
        context['vhasdoc'] = versions.vhasdoc
        context['vpathto'] = versions.vpathto

        # Insert banner into body.
        if cls.SHOW_BANNER and 'body' in context:
            parsed = app.builder.templates.render('banner.html', context)
            context['body'] = parsed + context['body']
            # Handle overridden css_files.
            css_files = context.setdefault('css_files', list())
            if '_static/banner.css' not in css_files:
                css_files.append('_static/banner.css')
            # Handle overridden html_static_path.
            if STATIC_DIR not in app.config.html_static_path:
                app.config.html_static_path.append(STATIC_DIR)

        # Reset last_updated with file's mtime (will be last git commit authored date).
        if app.config.html_last_updated_fmt is not None:
            file_path = app.env.doc2path(pagename)
            if os.path.isfile(file_path):
                lufmt = app.config.html_last_updated_fmt or getattr(locale, '_')('%b %d, %Y')
                mtime = datetime.datetime.fromtimestamp(os.path.getmtime(file_path))
                context['last_updated'] = format_date(lufmt, mtime, language=app.config.language, warn=app.warn)
开发者ID:Robpol86,项目名称:sphinxcontrib-versioning,代码行数:56,代码来源:sphinx_.py

示例4: test_format_date

def test_format_date():
    date = datetime.date(2016, 2, 7)

    format = None
    assert i18n.format_date(format, date=date) == 'Feb 7, 2016'
    assert i18n.format_date(format, date=date, language='en') == 'Feb 7, 2016'
    assert i18n.format_date(format, date=date, language='ja') == '2016/02/07'
    assert i18n.format_date(format, date=date, language='de') == '07.02.2016'

    format = '%B %d, %Y'
    print(i18n.format_date(format, date=date))
    assert i18n.format_date(format, date=date) == 'February 07, 2016'
    assert i18n.format_date(format, date=date, language='en') == 'February 07, 2016'
    assert i18n.format_date(format, date=date, language='ja') == u'2月 07, 2016'
    assert i18n.format_date(format, date=date, language='de') == 'Februar 07, 2016'
开发者ID:Titan-C,项目名称:sphinx,代码行数:15,代码来源:test_util_i18n.py

示例5: correct_copyright_year

def correct_copyright_year(app, config):
    # type: (Sphinx, Config) -> None
    """correct values of copyright year that are not coherent with
    the SOURCE_DATE_EPOCH environment variable (if set)

    See https://reproducible-builds.org/specs/source-date-epoch/
    """
    if getenv('SOURCE_DATE_EPOCH') is not None:
        for k in ('copyright', 'epub_copyright'):
            if k in config:
                replace = r'\g<1>%s' % format_date('%Y')
                config[k] = copyright_year_re.sub(replace, config[k])
开发者ID:olivier-heurtier,项目名称:sphinx,代码行数:12,代码来源:config.py

示例6: apply

 def apply(self, **kwargs):
     # type: (Any) -> None
     # only handle those not otherwise defined in the document
     to_handle = default_substitutions - set(self.document.substitution_defs)
     for ref in self.document.traverse(nodes.substitution_reference):
         refname = ref['refname']
         if refname in to_handle:
             text = self.config[refname]
             if refname == 'today' and not text:
                 # special handling: can also specify a strftime format
                 text = format_date(self.config.today_fmt or _('%b %d, %Y'),
                                    language=self.config.language)
             ref.replace_self(nodes.Text(text, text))
开发者ID:lmregus,项目名称:Portfolio,代码行数:13,代码来源:__init__.py

示例7: apply

 def apply(self):
     config = self.document.settings.env.config
     # only handle those not otherwise defined in the document
     to_handle = default_substitutions - set(self.document.substitution_defs)
     for ref in self.document.traverse(nodes.substitution_reference):
         refname = ref['refname']
         if refname in to_handle:
             text = config[refname]
             if refname == 'today' and not text:
                 # special handling: can also specify a strftime format
                 text = format_date(config.today_fmt or _('MMMM dd, YYYY'),
                                    language=config.language)
             ref.replace_self(nodes.Text(text, text))
开发者ID:Proudmoor,项目名称:sphinx,代码行数:13,代码来源:transforms.py

示例8: content_metadata

    def content_metadata(self):
        # type: () -> Dict
        """Create a dictionary with all metadata for the content.opf
        file properly escaped.
        """
        writing_mode = self.config.epub_writing_mode

        metadata = super(Epub3Builder, self).content_metadata()
        metadata['description'] = self.esc(self.config.epub_description)
        metadata['contributor'] = self.esc(self.config.epub_contributor)
        metadata['page_progression_direction'] = PAGE_PROGRESSION_DIRECTIONS.get(writing_mode)
        metadata['ibook_scroll_axis'] = IBOOK_SCROLL_AXIS.get(writing_mode)
        metadata['date'] = self.esc(format_date("%Y-%m-%dT%H:%M:%SZ"))
        metadata['version'] = self.esc(self.config.version)
        return metadata
开发者ID:LFYG,项目名称:sphinx,代码行数:15,代码来源:epub3.py

示例9: content_metadata

 def content_metadata(self, files, spine, guide):
     """Create a dictionary with all metadata for the content.opf
     file properly escaped.
     """
     metadata = {}
     metadata['title'] = self.esc(self.config.epub_title)
     metadata['author'] = self.esc(self.config.epub_author)
     metadata['uid'] = self.esc(self.config.epub_uid)
     metadata['lang'] = self.esc(self.config.epub_language)
     metadata['publisher'] = self.esc(self.config.epub_publisher)
     metadata['copyright'] = self.esc(self.config.epub_copyright)
     metadata['scheme'] = self.esc(self.config.epub_scheme)
     metadata['id'] = self.esc(self.config.epub_identifier)
     metadata['date'] = self.esc(format_date('YYYY-MM-dd', language=self.config.language))
     metadata['files'] = files
     metadata['spine'] = spine
     metadata['guide'] = guide
     return metadata
开发者ID:Proudmoor,项目名称:sphinx,代码行数:18,代码来源:epub.py

示例10: init_settings

 def init_settings(self):
     settings = self.settings = self.document.settings
     elements = self.elements = self.default_elements.copy()
     elements.update({
         # if empty, the title is set to the first section title
         'title': settings.title,
         'author': settings.author,
         # if empty, use basename of input file
         'filename': settings.texinfo_filename,
         'release': self.escape(self.builder.config.release),
         'project': self.escape(self.builder.config.project),
         'copyright': self.escape(self.builder.config.copyright),
         'date': self.escape(self.builder.config.today or
                             format_date(self.builder.config.today_fmt or
                                         _('MMMM dd, YYYY'),
                                         language=self.builder.config.language))
     })
     # title
     title = elements['title']
     if not title:
         title = self.document.next_node(nodes.title)
         title = (title and title.astext()) or '<untitled>'
     elements['title'] = self.escape_id(title) or '<untitled>'
     # filename
     if not elements['filename']:
         elements['filename'] = self.document.get('source') or 'untitled'
         if elements['filename'][-4:] in ('.txt', '.rst'):
             elements['filename'] = elements['filename'][:-4]
         elements['filename'] += '.info'
     # direntry
     if settings.texinfo_dir_entry:
         entry = self.format_menu_entry(
             self.escape_menu(settings.texinfo_dir_entry),
             '(%s)' % elements['filename'],
             self.escape_arg(settings.texinfo_dir_description))
         elements['direntry'] = ('@dircategory %s\n'
                                 '@direntry\n'
                                 '%s'
                                 '@end direntry\n') % (
             self.escape_id(settings.texinfo_dir_category), entry)
     elements['copying'] = COPYING % elements
     # allow the user to override them all
     elements.update(settings.texinfo_elements)
开发者ID:Proudmoor,项目名称:sphinx,代码行数:43,代码来源:texinfo.py

示例11: content_metadata

 def content_metadata(self):
     # type: () -> Dict[unicode, Any]
     """Create a dictionary with all metadata for the content.opf
     file properly escaped.
     """
     metadata = {}  # type: Dict[unicode, Any]
     metadata['title'] = self.esc(self.config.epub_title)
     metadata['author'] = self.esc(self.config.epub_author)
     metadata['uid'] = self.esc(self.config.epub_uid)
     metadata['lang'] = self.esc(self.config.epub_language)
     metadata['publisher'] = self.esc(self.config.epub_publisher)
     metadata['copyright'] = self.esc(self.config.epub_copyright)
     metadata['scheme'] = self.esc(self.config.epub_scheme)
     metadata['id'] = self.esc(self.config.epub_identifier)
     metadata['date'] = self.esc(format_date("%Y-%m-%d"))
     metadata['manifest_items'] = []
     metadata['spines'] = []
     metadata['guides'] = []
     return metadata
开发者ID:LFYG,项目名称:sphinx,代码行数:19,代码来源:_epub_base.py

示例12: __init__

    def __init__(self, dirname, filename, overrides, tags):
        # type: (unicode, unicode, Dict, Tags) -> None
        self.overrides = overrides
        self.values = Config.config_values.copy()
        config = {}  # type: Dict[unicode, Any]
        if dirname is not None:
            config_file = path.join(dirname, filename)
            config['__file__'] = config_file
            config['tags'] = tags
            with cd(dirname):
                # we promise to have the config dir as current dir while the
                # config file is executed
                try:
                    execfile_(filename, config)
                except SyntaxError as err:
                    raise ConfigError(CONFIG_SYNTAX_ERROR % err)
                except SystemExit:
                    raise ConfigError(CONFIG_EXIT_ERROR)
                except Exception:
                    raise ConfigError(CONFIG_ERROR % traceback.format_exc())

        self._raw_config = config
        # these two must be preinitialized because extensions can add their
        # own config values
        self.setup = config.get('setup', None)  # type: Callable

        if 'extensions' in overrides:
            if isinstance(overrides['extensions'], string_types):
                config['extensions'] = overrides.pop('extensions').split(',')
            else:
                config['extensions'] = overrides.pop('extensions')
        self.extensions = config.get('extensions', [])  # type: List[unicode]

        # correct values of copyright year that are not coherent with
        # the SOURCE_DATE_EPOCH environment variable (if set)
        # See https://reproducible-builds.org/specs/source-date-epoch/
        if getenv('SOURCE_DATE_EPOCH') is not None:
            for k in ('copyright', 'epub_copyright'):
                if k in config:
                    config[k] = copyright_year_re.sub(r'\g<1>%s' % format_date('%Y'),
                                                      config[k])
开发者ID:AWhetter,项目名称:sphinx,代码行数:41,代码来源:config.py

示例13: init_context

    def init_context(self):
        # type: () -> None
        self.context = DEFAULT_SETTINGS.copy()

        # Add special settings for latex_engine
        self.context.update(ADDITIONAL_SETTINGS.get(self.config.latex_engine, {}))

        # for xelatex+French, don't use polyglossia by default
        if self.config.latex_engine == 'xelatex':
            if self.config.language:
                if self.config.language[:2] == 'fr':
                    self.context['polyglossia'] = ''
                    self.context['babel'] = r'\usepackage{babel}'

        # Apply extension settings to context
        self.context['packages'] = self.usepackages

        # Apply user settings to context
        self.context.update(self.config.latex_elements)
        self.context['release'] = self.config.release
        self.context['use_xindy'] = self.config.latex_use_xindy

        if self.config.today:
            self.context['date'] = self.config.today
        else:
            self.context['date'] = format_date(self.config.today_fmt or _('%b %d, %Y'),
                                               language=self.config.language)

        if self.config.latex_logo:
            self.context['logofilename'] = path.basename(self.config.latex_logo)

        # for compatibilities
        self.context['indexname'] = _('Index')
        if self.config.release:
            # Show the release label only if release value exists
            self.context['releasename'] = _('Release')
开发者ID:lmregus,项目名称:Portfolio,代码行数:36,代码来源:__init__.py

示例14: prepare_writing

    def prepare_writing(self, docnames):
        # create the search indexer
        self.indexer = None

        self.docwriter = MarkdownWriter(self)
        self.docsettings = OptionParser(
            defaults=self.env.settings, components=(self.docwriter,), read_config_files=True
        ).get_default_values()
        self.docsettings.compact_lists = bool(self.config.html_compact_lists)

        # determine the additional indices to include
        self.domain_indices = []
        # html_domain_indices can be False/True or a list of index names
        indices_config = self.config.html_domain_indices
        if indices_config:
            for domain_name in sorted(self.env.domains):
                domain = self.env.domains[domain_name]
                for indexcls in domain.indices:
                    indexname = "%s-%s" % (domain.name, indexcls.name)
                    if isinstance(indices_config, list):
                        if indexname not in indices_config:
                            continue
                    # deprecated config value
                    if indexname == "py-modindex" and not self.config.html_use_modindex:
                        continue
                    content, collapse = indexcls(domain).generate()
                    if content:
                        self.domain_indices.append((indexname, indexcls, content, collapse))

        # format the "last updated on" string, only once is enough since it
        # typically doesn't include the time of day
        lufmt = self.config.html_last_updated_fmt
        if lufmt is not None:
            self.last_updated = format_date(lufmt or _("%b %d, %Y"), language=self.config.language, warn=self.warn)
        else:
            self.last_updated = None

        self.relations = self.env.collect_relations()

        rellinks = []
        if self.get_builder_config("use_index", "html"):
            rellinks.append(("genindex", _("General Index"), "I", _("index")))
        for indexname, indexcls, content, collapse in self.domain_indices:
            # if it has a short name
            if indexcls.shortname:
                rellinks.append((indexname, indexcls.localname, "", indexcls.shortname))

        self.globalcontext = dict(
            embedded=self.embedded,
            project=self.config.project,
            release=self.config.release,
            version=self.config.version,
            last_updated=self.last_updated,
            copyright=self.config.copyright,
            master_doc=self.config.master_doc,
            docstitle=self.config.html_title,
            shorttitle=self.config.html_short_title,
            show_copyright=self.config.html_show_copyright,
            show_sphinx=self.config.html_show_sphinx,
            has_source=self.config.html_copy_source,
            show_source=self.config.html_show_sourcelink,
            file_suffix=self.out_suffix,
            language=self.config.language,
            sphinx_version=__display_version__,
            rellinks=rellinks,
            builder=self.name,
            parents=[],
        )
开发者ID:CartoDB,项目名称:bigmetadata,代码行数:68,代码来源:markdown.py

示例15: prepare_writing

    def prepare_writing(self, docnames):
        # create the search indexer
        self.indexer = None
        if self.search:
            from sphinx.search import IndexBuilder, languages
            lang = self.config.html_search_language or self.config.language
            if not lang or lang not in languages:
                lang = 'en'
            self.indexer = IndexBuilder(self.env, lang,
                                        self.config.html_search_options,
                                        self.config.html_search_scorer)
            self.load_indexer(docnames)

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

        # determine the additional indices to include
        self.domain_indices = []
        # html_domain_indices can be False/True or a list of index names
        indices_config = self.config.html_domain_indices
        if indices_config:
            for domain_name in sorted(self.env.domains):
                domain = self.env.domains[domain_name]
                for indexcls in domain.indices:
                    indexname = '%s-%s' % (domain.name, indexcls.name)
                    if isinstance(indices_config, list):
                        if indexname not in indices_config:
                            continue
                    # deprecated config value
                    if indexname == 'py-modindex' and \
                       not self.config.html_use_modindex:
                        continue
                    content, collapse = indexcls(domain).generate()
                    if content:
                        self.domain_indices.append(
                            (indexname, indexcls, content, collapse))

        # format the "last updated on" string, only once is enough since it
        # typically doesn't include the time of day
        lufmt = self.config.html_last_updated_fmt
        if lufmt is not None:
            self.last_updated = format_date(lufmt or _('MMM dd, YYYY'),
                                            language=self.config.language)
        else:
            self.last_updated = None

        logo = self.config.html_logo and \
            path.basename(self.config.html_logo) or ''

        favicon = self.config.html_favicon and \
            path.basename(self.config.html_favicon) or ''
        if favicon and os.path.splitext(favicon)[1] != '.ico':
            self.warn('html_favicon is not an .ico file')

        if not isinstance(self.config.html_use_opensearch, string_types):
            self.warn('html_use_opensearch config value must now be a string')

        self.relations = self.env.collect_relations()

        rellinks = []
        if self.get_builder_config('use_index', 'html'):
            rellinks.append(('genindex', _('General Index'), 'I', _('index')))
        for indexname, indexcls, content, collapse in self.domain_indices:
            # if it has a short name
            if indexcls.shortname:
                rellinks.append((indexname, indexcls.localname,
                                 '', indexcls.shortname))

        if self.config.html_style is not None:
            stylename = self.config.html_style
        elif self.theme:
            stylename = self.theme.get_confstr('theme', 'stylesheet')
        else:
            stylename = 'default.css'

        self.globalcontext = dict(
            embedded = self.embedded,
            project = self.config.project,
            release = self.config.release,
            version = self.config.version,
            last_updated = self.last_updated,
            copyright = self.config.copyright,
            master_doc = self.config.master_doc,
            use_opensearch = self.config.html_use_opensearch,
            docstitle = self.config.html_title,
            shorttitle = self.config.html_short_title,
            show_copyright = self.config.html_show_copyright,
            show_sphinx = self.config.html_show_sphinx,
            has_source = self.config.html_copy_source,
            show_source = self.config.html_show_sourcelink,
            file_suffix = self.out_suffix,
            script_files = self.script_files,
            language = self.config.language,
            css_files = self.css_files,
            sphinx_version = __display_version__,
            style = stylename,
#.........这里部分代码省略.........
开发者ID:Titan-C,项目名称:sphinx,代码行数:101,代码来源:html.py


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