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


Python Bundle.get_version方法代码示例

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


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

示例1: resolve_source_to_url

# 需要导入模块: from webassets import Bundle [as 别名]
# 或者: from webassets.Bundle import get_version [as 别名]
    def resolve_source_to_url(self, filepath, item):
        request = get_current_request()
        env = self.env

        # Copied from webassets 0.8. Reproduced here for backwards
        # compatibility with the previous webassets release.
        # This ensures files which do not require building are still served
        # with proper versioning of URLs.
        # This can likely be removed once miracle2k/webassets#117 is fixed.

        # Only query the version if we need to for performance
        version = None
        if has_placeholder(filepath) or env.url_expire is not False:
            # If auto-build is enabled, we must not use a cached version
            # value, or we might serve old versions.
            bundle = Bundle(item, output=filepath)
            version = bundle.get_version(env, refresh=env.auto_build)

        url = filepath
        if has_placeholder(url):
            url = url % {'version': version}

        # This part is different from webassets. Try to resolve with an asset
        # spec first, then try the base class source URL resolver.

        resolved = False
        if request is not None:
            # Attempt to resolve the filepath as passed (but after versioning).
            # If this fails, it may be because the static route was registered
            # with an asset spec. In this case, the original item may also be
            # an asset spec contained therein, so try to resolve that.
            for attempt in (url, item):
                try:
                    url = request.static_url(attempt)
                except ValueError:
                    continue
                else:
                    resolved = True
                    break

        if not resolved:
            url = super(PyramidResolver, self).resolve_source_to_url(
                url,
                item
            )

        if env.url_expire or (
                env.url_expire is None and not has_placeholder(filepath)):
            url = "%s?%s" % (url, version)
        return url
开发者ID:sekimura,项目名称:pyramid_webassets,代码行数:52,代码来源:__init__.py


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