summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2015-12-07 22:58:06 -0600
committerMichael Merickel <michael@merickel.org>2015-12-07 22:58:06 -0600
commitd0bd5fb326d8999e3a40e6e2d121aa69cfe05476 (patch)
treec0e6ccb5a733dfb67d57aed18402c202daf387bd
parent62222d69b7b6ef573d7f52529b15285af4111f20 (diff)
downloadpyramid-d0bd5fb326d8999e3a40e6e2d121aa69cfe05476.tar.gz
pyramid-d0bd5fb326d8999e3a40e6e2d121aa69cfe05476.tar.bz2
pyramid-d0bd5fb326d8999e3a40e6e2d121aa69cfe05476.zip
add a first cut at an add_cache_buster api
-rw-r--r--pyramid/config/views.py32
1 files changed, 25 insertions, 7 deletions
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index 67a70145c..f496dfb7d 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -1,5 +1,5 @@
-import bisect
import inspect
+import posixpath
import operator
import os
import warnings
@@ -21,6 +21,7 @@ from pyramid.interfaces import (
IException,
IExceptionViewClassifier,
IMultiView,
+ IPackageOverrides,
IRendererFactory,
IRequest,
IResponse,
@@ -1987,6 +1988,8 @@ class StaticURLInfo(object):
subpath = subpath.replace('\\', '/') # windows
# translate spec into overridden spec and lookup cache buster
# to modify subpath, kw
+ subpath, kw = self._bust_asset_path(
+ request.registry, spec, subpath, kw)
if url is None:
kw['subpath'] = subpath
return request.route_url(route_name, **kw)
@@ -2099,9 +2102,7 @@ class StaticURLInfo(object):
idx = specs.index(spec)
cache_busters.pop(idx)
- lengths = [len(t[0]) for t in cache_busters]
- new_idx = bisect.bisect_left(lengths, len(spec))
- cache_busters.insert(new_idx, (spec, cachebust))
+ cache_busters.insert(0, (spec, cachebust))
intr = config.introspectable('cache busters',
spec,
@@ -2112,7 +2113,24 @@ class StaticURLInfo(object):
config.action(None, callable=register, introspectables=(intr,))
- def _find_cache_buster(self, registry, spec):
+ def _bust_asset_path(self, registry, spec, subpath, kw):
+ pkg_name, pkg_subpath = spec.split(':')
+ absspec = rawspec = '{0}:{1}{2}'.format(pkg_name, pkg_subpath, subpath)
+ overrides = registry.queryUtility(IPackageOverrides, name=pkg_name)
+ if overrides is not None:
+ resource_name = posixpath.join(pkg_subpath, subpath)
+ sources = overrides.filtered_sources(resource_name)
+ for source, filtered_path in sources:
+ rawspec = source.get_path(filtered_path)
+ if hasattr(source, 'pkg_name'):
+ rawspec = '{0}:{1}'.format(source.pkg_name, rawspec)
+ break
+
for base_spec, cachebust in self.cache_busters:
- if base_spec.startswith(spec):
- pass
+ if (
+ base_spec == rawspec or
+ (base_spec.endswith('/') and rawspec.startswith(base_spec))
+ ):
+ subpath, kw = cachebust(absspec, subpath, kw)
+ break
+ return subpath, kw