Update mako to 1.1.0

This commit is contained in:
JonnyWong16 2019-11-23 18:57:21 -08:00
parent 84ce4758d1
commit f2d7beec90
27 changed files with 2424 additions and 1890 deletions

View file

@ -1,10 +1,11 @@
# mako/cache.py
# Copyright (C) 2006-2015 the Mako authors and contributors <see AUTHORS file>
# Copyright 2006-2019 the Mako authors and contributors <see AUTHORS file>
#
# This module is part of Mako and is released under
# the MIT License: http://www.opensource.org/licenses/mit-license.php
from mako import compat, util
from mako import compat
from mako import util
_cache_plugins = util.PluginLoader("mako.cache")
@ -13,6 +14,7 @@ register_plugin("beaker", "mako.ext.beaker_cache", "BeakerCacheImpl")
class Cache(object):
"""Represents a data content cache made available to the module
space of a specific :class:`.Template` object.
@ -89,12 +91,11 @@ class Cache(object):
return creation_function()
return self.impl.get_or_create(
key,
creation_function,
**self._get_cache_kw(kw, context))
key, creation_function, **self._get_cache_kw(kw, context)
)
def set(self, key, value, **kw):
"""Place a value in the cache.
r"""Place a value in the cache.
:param key: the value's key.
:param value: the value.
@ -112,7 +113,7 @@ class Cache(object):
"""
def get(self, key, **kw):
"""Retrieve a value from the cache.
r"""Retrieve a value from the cache.
:param key: the value's key.
:param \**kw: cache configuration arguments. The
@ -124,7 +125,7 @@ class Cache(object):
return self.impl.get(key, **self._get_cache_kw(kw, None))
def invalidate(self, key, **kw):
"""Invalidate a value in the cache.
r"""Invalidate a value in the cache.
:param key: the value's key.
:param \**kw: cache configuration arguments. The
@ -140,7 +141,7 @@ class Cache(object):
template.
"""
self.invalidate('render_body', __M_defname='render_body')
self.invalidate("render_body", __M_defname="render_body")
def invalidate_def(self, name):
"""Invalidate the cached content of a particular ``<%def>`` within this
@ -148,7 +149,7 @@ class Cache(object):
"""
self.invalidate('render_%s' % name, __M_defname='render_%s' % name)
self.invalidate("render_%s" % name, __M_defname="render_%s" % name)
def invalidate_closure(self, name):
"""Invalidate a nested ``<%def>`` within this template.
@ -164,7 +165,7 @@ class Cache(object):
self.invalidate(name, __M_defname=name)
def _get_cache_kw(self, kw, context):
defname = kw.pop('__M_defname', None)
defname = kw.pop("__M_defname", None)
if not defname:
tmpl_kw = self.template.cache_args.copy()
tmpl_kw.update(kw)
@ -176,11 +177,12 @@ class Cache(object):
self._def_regions[defname] = tmpl_kw
if context and self.impl.pass_context:
tmpl_kw = tmpl_kw.copy()
tmpl_kw.setdefault('context', context)
tmpl_kw.setdefault("context", context)
return tmpl_kw
class CacheImpl(object):
"""Provide a cache implementation for use by :class:`.Cache`."""
def __init__(self, cache):
@ -192,7 +194,7 @@ class CacheImpl(object):
"""
def get_or_create(self, key, creation_function, **kw):
"""Retrieve a value from the cache, using the given creation function
r"""Retrieve a value from the cache, using the given creation function
to generate a new value.
This function *must* return a value, either from
@ -210,7 +212,7 @@ class CacheImpl(object):
raise NotImplementedError()
def set(self, key, value, **kw):
"""Place a value in the cache.
r"""Place a value in the cache.
:param key: the value's key.
:param value: the value.
@ -220,7 +222,7 @@ class CacheImpl(object):
raise NotImplementedError()
def get(self, key, **kw):
"""Retrieve a value from the cache.
r"""Retrieve a value from the cache.
:param key: the value's key.
:param \**kw: cache configuration arguments.
@ -229,7 +231,7 @@ class CacheImpl(object):
raise NotImplementedError()
def invalidate(self, key, **kw):
"""Invalidate a value in the cache.
r"""Invalidate a value in the cache.
:param key: the value's key.
:param \**kw: cache configuration arguments.