diff options
| author | Chris Rossi <chris@archimedeanco.com> | 2014-07-24 17:13:08 -0400 |
|---|---|---|
| committer | Chris Rossi <chris@archimedeanco.com> | 2014-07-24 17:13:08 -0400 |
| commit | 15b979413c700fbc289328b25aaa4ba1c4cbdda9 (patch) | |
| tree | e9ed97a79517d212624e90f2efdc72be04afd859 | |
| parent | 4d32f73a86e7223dbdb96b39193d357b38ea1a13 (diff) | |
| download | pyramid-15b979413c700fbc289328b25aaa4ba1c4cbdda9.tar.gz pyramid-15b979413c700fbc289328b25aaa4ba1c4cbdda9.tar.bz2 pyramid-15b979413c700fbc289328b25aaa4ba1c4cbdda9.zip | |
cachebuster -> cachebust
| -rw-r--r-- | CHANGES.txt | 2 | ||||
| -rw-r--r-- | docs/narr/assets.rst | 20 | ||||
| -rw-r--r-- | docs/narr/environment.rst | 6 | ||||
| -rw-r--r-- | pyramid/config/settings.py | 14 | ||||
| -rw-r--r-- | pyramid/config/views.py | 30 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_settings.py | 54 | ||||
| -rw-r--r-- | pyramid/tests/test_config/test_views.py | 28 |
7 files changed, 77 insertions, 77 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index 54c1a20ed..63987d980 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -5,7 +5,7 @@ Features -------- - Cache busting for static resources has been added and is available via a new - argument to ``pyramid.config.Configurator.add_static_view``: ``cachebuster``. + argument to ``pyramid.config.Configurator.add_static_view``: ``cachebust``. Bug Fixes --------- diff --git a/docs/narr/assets.rst b/docs/narr/assets.rst index fea3fae48..7fb0ec40b 100644 --- a/docs/narr/assets.rst +++ b/docs/narr/assets.rst @@ -318,7 +318,7 @@ requests a copy, regardless of any caching policy set for the resource's old URL. :app:`Pyramid` can be configured to produce cache busting URLs for static -assets by passing the optional argument, ``cachebuster`` to +assets by passing the optional argument, ``cachebust`` to :meth:`~pyramid.config.Configurator.add_static_view`: .. code-block:: python @@ -326,9 +326,9 @@ assets by passing the optional argument, ``cachebuster`` to # config is an instance of pyramid.config.Configurator config.add_static_view(name='static', path='mypackage:folder/static', - cachebuster=True) + cachebust=True) -Setting the ``cachebuster`` argument instructs :app:`Pyramid` to use a cache +Setting the ``cachebust`` argument instructs :app:`Pyramid` to use a cache busting scheme which adds the md5 checksum for a static asset as a path segment in the asset's URL: @@ -339,7 +339,7 @@ in the asset's URL: # Returns: 'http://www.example.com/static/c9658b3c0a314a1ca21e5988e662a09e/js/myapp.js` When the asset changes, so will its md5 checksum, and therefore so will its -URL. Supplying the ``cachebuster`` argument also causes the static view to set +URL. Supplying the ``cachebust`` argument also causes the static view to set headers instructing clients to cache the asset for ten years, unless the ``max_cache_age`` argument is also passed, in which case that value is used. @@ -355,8 +355,8 @@ Disabling the Cache Buster It can be useful in some situations (e.g. development) to globally disable all configured cache busters without changing calls to :meth:`~pyramid.config.Configurator.add_static_view`. To do this set the -``PYRAMID_PREVENT_CACHEBUSTER`` environment variable or the -``pyramid.prevent_cachebuster`` configuration value to a true value. +``PYRAMID_PREVENT_CACHEBUST`` environment variable or the +``pyramid.prevent_cachebust`` configuration value to a true value. Customizing the Cache Buster ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -368,11 +368,11 @@ Revisiting from the previous section: # config is an instance of pyramid.config.Configurator config.add_static_view(name='static', path='mypackage:folder/static', - cachebuster=True) + cachebust=True) -Setting ``cachebuster`` to ``True`` instructs :app:`Pyramid` to use a default +Setting ``cachebust`` to ``True`` instructs :app:`Pyramid` to use a default cache busting implementation that should work for many situations. The -``cachebuster`` may be set to any object that implements the interface, +``cachebust`` may be set to any object that implements the interface, :class:`~pyramid.interfaces.ICacheBuster`. The above configuration is exactly equivalent to: @@ -383,7 +383,7 @@ equivalent to: # config is an instance of pyramid.config.Configurator config.add_static_view(name='static', path='mypackage:folder/static', - cachebuster=PathSegmentCacheBuster()) + cachebust=PathSegmentCacheBuster()) :app:`Pyramid` includes two ready to use cache buster implementations: :class:`~pyramid.static.PathSegmentCacheBuster`, which inserts an asset token diff --git a/docs/narr/environment.rst b/docs/narr/environment.rst index 7e2f19278..a81ad19af 100644 --- a/docs/narr/environment.rst +++ b/docs/narr/environment.rst @@ -161,7 +161,7 @@ feature when this is true. Preventing Cache Busting ------------------------ -Prevent the ``cachebuster`` static view configuration argument from having any +Prevent the ``cachebust`` static view configuration argument from having any effect globally in this process when this value is true. No cache buster will be configured or used when this is true. @@ -172,8 +172,8 @@ be configured or used when this is true. +---------------------------------+----------------------------------+ | Environment Variable Name | Config File Setting Name | +=================================+==================================+ -| ``PYRAMID_PREVENT_CACHEBUSTER`` | ``pyramid.prevent_cachebuster`` | -| | or ``prevent_cachebuster`` | +| ``PYRAMID_PREVENT_CACHEBUST`` | ``pyramid.prevent_cachebust`` | +| | or ``prevent_cachebust`` | | | | | | | +---------------------------------+----------------------------------+ diff --git a/pyramid/config/settings.py b/pyramid/config/settings.py index 4d7af6015..492b7d524 100644 --- a/pyramid/config/settings.py +++ b/pyramid/config/settings.py @@ -117,11 +117,11 @@ class Settings(dict): config_prevent_http_cache) eff_prevent_http_cache = asbool(eget('PYRAMID_PREVENT_HTTP_CACHE', config_prevent_http_cache)) - config_prevent_cachebuster = self.get('prevent_cachebuster', '') - config_prevent_cachebuster = self.get('pyramid.prevent_cachebuster', - config_prevent_cachebuster) - eff_prevent_cachebuster = asbool(eget('PYRAMID_PREVENT_CACHEBUSTER', - config_prevent_cachebuster)) + config_prevent_cachebust = self.get('prevent_cachebust', '') + config_prevent_cachebust = self.get('pyramid.prevent_cachebust', + config_prevent_cachebust) + eff_prevent_cachebust = asbool(eget('PYRAMID_PREVENT_CACHEBUST', + config_prevent_cachebust)) update = { 'debug_authorization': eff_debug_all or eff_debug_auth, @@ -133,7 +133,7 @@ class Settings(dict): 'reload_assets':eff_reload_all or eff_reload_assets, 'default_locale_name':eff_locale_name, 'prevent_http_cache':eff_prevent_http_cache, - 'prevent_cachebuster':eff_prevent_cachebuster, + 'prevent_cachebust':eff_prevent_cachebust, 'pyramid.debug_authorization': eff_debug_all or eff_debug_auth, 'pyramid.debug_notfound': eff_debug_all or eff_debug_notfound, @@ -144,7 +144,7 @@ class Settings(dict): 'pyramid.reload_assets':eff_reload_all or eff_reload_assets, 'pyramid.default_locale_name':eff_locale_name, 'pyramid.prevent_http_cache':eff_prevent_http_cache, - 'pyramid.prevent_cachebuster':eff_prevent_cachebuster, + 'pyramid.prevent_cachebust':eff_prevent_cachebust, } self.update(update) diff --git a/pyramid/config/views.py b/pyramid/config/views.py index 62feca77e..e6c5baf58 100644 --- a/pyramid/config/views.py +++ b/pyramid/config/views.py @@ -1783,17 +1783,17 @@ class ViewsConfiguratorMixin(object): Note that this argument has no effect when the ``name`` is a *url prefix*. By default, this argument is ``None``, meaning that no particular Expires or Cache-Control headers are set in the response, - unless ``cachebuster`` is specified. + unless ``cachebust`` is specified. - The ``cachebuster`` keyword argument may be set to cause + The ``cachebust`` keyword argument may be set to cause :meth:`~pyramid.request.Request.static_url` to use cache busting when generating URLs. See :ref:`cache_busting` for general information - about cache busting. The value of the ``cachebuster`` argument may be + about cache busting. The value of the ``cachebust`` argument may be ``True``, in which case a default cache busting implementation is used. - The value of the ``cachebuster`` argument may also be an object which + The value of the ``cachebust`` argument may also be an object which implements :class:`~pyramid.interfaces.ICacheBuster`. See the :mod:`~pyramid.static` module for some implementations. If the - ``cachebuster`` argument is provided, the default for ``cache_max_age`` + ``cachebust`` argument is provided, the default for ``cache_max_age`` is modified to be ten years. ``cache_max_age`` may still be explicitly provided to override this default. @@ -1894,7 +1894,7 @@ def isexception(o): @implementer(IStaticURLInfo) class StaticURLInfo(object): # Indirection for testing - _default_cachebuster = PathSegmentCacheBuster + _default_cachebust = PathSegmentCacheBuster def _get_registrations(self, registry): try: @@ -1909,13 +1909,13 @@ class StaticURLInfo(object): except AttributeError: # bw compat (for tests) registry = get_current_registry() registrations = self._get_registrations(registry) - for (url, spec, route_name, cachebuster) in registrations: + for (url, spec, route_name, cachebust) in registrations: if path.startswith(spec): subpath = path[len(spec):] if WIN: # pragma: no cover subpath = subpath.replace('\\', '/') # windows - if cachebuster: - subpath, kw = cachebuster(subpath, kw) + if cachebust: + subpath, kw = cachebust(subpath, kw) if url is None: kw['subpath'] = subpath return request.route_url(route_name, **kw) @@ -1955,20 +1955,20 @@ class StaticURLInfo(object): # make sure it ends with a slash name = name + '/' - if config.registry.settings.get('pyramid.prevent_cachebuster'): + if config.registry.settings.get('pyramid.prevent_cachebust'): cb = None else: - cb = extra.pop('cachebuster', None) + cb = extra.pop('cachebust', None) if cb is True: - cb = self._default_cachebuster() + cb = self._default_cachebust() if cb: - def cachebuster(subpath, kw): + def cachebust(subpath, kw): token = cb.token(spec + subpath) subpath_tuple = tuple(subpath.split('/')) subpath_tuple, kw = cb.pregenerate(token, subpath_tuple, kw) return '/'.join(subpath_tuple), kw else: - cachebuster = None + cachebust = None if url_parse(name).netloc: # it's a URL @@ -2026,7 +2026,7 @@ class StaticURLInfo(object): registrations.pop(idx) # url, spec, route_name - registrations.append((url, spec, route_name, cachebuster)) + registrations.append((url, spec, route_name, cachebust)) intr = config.introspectable('static views', name, diff --git a/pyramid/tests/test_config/test_settings.py b/pyramid/tests/test_config/test_settings.py index 7cf550c1d..d2a98b347 100644 --- a/pyramid/tests/test_config/test_settings.py +++ b/pyramid/tests/test_config/test_settings.py @@ -131,34 +131,34 @@ class TestSettings(unittest.TestCase): self.assertEqual(result['prevent_http_cache'], True) self.assertEqual(result['pyramid.prevent_http_cache'], True) - def test_prevent_cachebuster(self): + def test_prevent_cachebust(self): settings = self._makeOne({}) - self.assertEqual(settings['prevent_cachebuster'], False) - self.assertEqual(settings['pyramid.prevent_cachebuster'], False) - result = self._makeOne({'prevent_cachebuster':'false'}) - self.assertEqual(result['prevent_cachebuster'], False) - self.assertEqual(result['pyramid.prevent_cachebuster'], False) - result = self._makeOne({'prevent_cachebuster':'t'}) - self.assertEqual(result['prevent_cachebuster'], True) - self.assertEqual(result['pyramid.prevent_cachebuster'], True) - result = self._makeOne({'prevent_cachebuster':'1'}) - self.assertEqual(result['prevent_cachebuster'], True) - self.assertEqual(result['pyramid.prevent_cachebuster'], True) - result = self._makeOne({'pyramid.prevent_cachebuster':'t'}) - self.assertEqual(result['prevent_cachebuster'], True) - self.assertEqual(result['pyramid.prevent_cachebuster'], True) - result = self._makeOne({}, {'PYRAMID_PREVENT_CACHEBUSTER':'1'}) - self.assertEqual(result['prevent_cachebuster'], True) - self.assertEqual(result['pyramid.prevent_cachebuster'], True) - result = self._makeOne({'prevent_cachebuster':'false', - 'pyramid.prevent_cachebuster':'1'}) - self.assertEqual(result['prevent_cachebuster'], True) - self.assertEqual(result['pyramid.prevent_cachebuster'], True) - result = self._makeOne({'prevent_cachebuster':'false', - 'pyramid.prevent_cachebuster':'f'}, - {'PYRAMID_PREVENT_CACHEBUSTER':'1'}) - self.assertEqual(result['prevent_cachebuster'], True) - self.assertEqual(result['pyramid.prevent_cachebuster'], True) + self.assertEqual(settings['prevent_cachebust'], False) + self.assertEqual(settings['pyramid.prevent_cachebust'], False) + result = self._makeOne({'prevent_cachebust':'false'}) + self.assertEqual(result['prevent_cachebust'], False) + self.assertEqual(result['pyramid.prevent_cachebust'], False) + result = self._makeOne({'prevent_cachebust':'t'}) + self.assertEqual(result['prevent_cachebust'], True) + self.assertEqual(result['pyramid.prevent_cachebust'], True) + result = self._makeOne({'prevent_cachebust':'1'}) + self.assertEqual(result['prevent_cachebust'], True) + self.assertEqual(result['pyramid.prevent_cachebust'], True) + result = self._makeOne({'pyramid.prevent_cachebust':'t'}) + self.assertEqual(result['prevent_cachebust'], True) + self.assertEqual(result['pyramid.prevent_cachebust'], True) + result = self._makeOne({}, {'PYRAMID_PREVENT_CACHEBUST':'1'}) + self.assertEqual(result['prevent_cachebust'], True) + self.assertEqual(result['pyramid.prevent_cachebust'], True) + result = self._makeOne({'prevent_cachebust':'false', + 'pyramid.prevent_cachebust':'1'}) + self.assertEqual(result['prevent_cachebust'], True) + self.assertEqual(result['pyramid.prevent_cachebust'], True) + result = self._makeOne({'prevent_cachebust':'false', + 'pyramid.prevent_cachebust':'f'}, + {'PYRAMID_PREVENT_CACHEBUST':'1'}) + self.assertEqual(result['prevent_cachebust'], True) + self.assertEqual(result['pyramid.prevent_cachebust'], True) def test_reload_templates(self): settings = self._makeOne({}) diff --git a/pyramid/tests/test_config/test_views.py b/pyramid/tests/test_config/test_views.py index 8f600c1d2..a0d9ee0c3 100644 --- a/pyramid/tests/test_config/test_views.py +++ b/pyramid/tests/test_config/test_views.py @@ -3845,12 +3845,12 @@ class TestStaticURLInfo(unittest.TestCase): self.assertEqual(result, 'http://example.com/abc%20def#La%20Pe%C3%B1a') - def test_generate_url_cachebuster(self): - def cachebuster(subpath, kw): + def test_generate_url_cachebust(self): + def cachebust(subpath, kw): kw['foo'] = 'bar' return 'foo' + '/' + subpath, kw inst = self._makeOne() - registrations = [(None, 'package:path/', '__viewname', cachebuster)] + registrations = [(None, 'package:path/', '__viewname', cachebust)] inst._get_registrations = lambda *x: registrations request = self._makeRequest() def route_url(n, **kw): @@ -3944,28 +3944,28 @@ class TestStaticURLInfo(unittest.TestCase): def test_add_cachebust_default(self): config = self._makeConfig() inst = self._makeOne() - inst._default_cachebuster = DummyCacheBuster - inst.add(config, 'view', 'mypackage:path', cachebuster=True) - cachebuster = config.registry._static_url_registrations[0][3] - subpath, kw = cachebuster('some/path', {}) + inst._default_cachebust = DummyCacheBuster + inst.add(config, 'view', 'mypackage:path', cachebust=True) + cachebust = config.registry._static_url_registrations[0][3] + subpath, kw = cachebust('some/path', {}) self.assertEqual(subpath, 'some/path') self.assertEqual(kw['x'], 'foo') def test_add_cachebust_prevented(self): config = self._makeConfig() - config.registry.settings['pyramid.prevent_cachebuster'] = True + config.registry.settings['pyramid.prevent_cachebust'] = True inst = self._makeOne() - inst.add(config, 'view', 'mypackage:path', cachebuster=True) - cachebuster = config.registry._static_url_registrations[0][3] - self.assertEqual(cachebuster, None) + inst.add(config, 'view', 'mypackage:path', cachebust=True) + cachebust = config.registry._static_url_registrations[0][3] + self.assertEqual(cachebust, None) def test_add_cachebust_custom(self): config = self._makeConfig() inst = self._makeOne() inst.add(config, 'view', 'mypackage:path', - cachebuster=DummyCacheBuster()) - cachebuster = config.registry._static_url_registrations[0][3] - subpath, kw = cachebuster('some/path', {}) + cachebust=DummyCacheBuster()) + cachebust = config.registry._static_url_registrations[0][3] + subpath, kw = cachebust('some/path', {}) self.assertEqual(subpath, 'some/path') self.assertEqual(kw['x'], 'foo') |
