From: Armin Ronacher Date: Sun, 19 May 2013 10:06:18 +0000 (+0100) Subject: Added a way to disable memcache error ignoring and documented the change. Also chang... X-Git-Tag: 2.7~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=840e7e060e3537172c57a8a96cf5bc502f55b67f;p=thirdparty%2Fjinja.git Added a way to disable memcache error ignoring and documented the change. Also changed a bare except to an except on the exception type. --- diff --git a/CHANGES b/CHANGES index e4aa398c..b7f28dde 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ Version 2.7 - Allow `contextfunction` and other decorators to be applied to `__call__`. - Added support for changing from newline to different signs in the `wordwrap` filter. +- Added support for ignoring memcache errors silently. Version 2.6 ----------- diff --git a/jinja2/bccache.py b/jinja2/bccache.py index 033ae7a2..f0229180 100644 --- a/jinja2/bccache.py +++ b/jinja2/bccache.py @@ -281,17 +281,25 @@ class MemcachedBytecodeCache(BytecodeCache): This bytecode cache does not support clearing of used items in the cache. The clear method is a no-operation function. + + .. versionadded:: 2.7 + Added support for ignoring memcache errors through the + `ignore_memcache_errors` parameter. """ - def __init__(self, client, prefix='jinja2/bytecode/', timeout=None): + def __init__(self, client, prefix='jinja2/bytecode/', timeout=None, + ignore_memcache_errors=True): self.client = client self.prefix = prefix self.timeout = timeout + self.ignore_memcache_errors = ignore_memcache_errors def load_bytecode(self, bucket): try: code = self.client.get(self.prefix + bucket.key) - except: + except Exception: + if not self.ignore_memcache_errors: + raise code = None if code is not None: bucket.bytecode_from_string(code) @@ -302,5 +310,6 @@ class MemcachedBytecodeCache(BytecodeCache): args += (self.timeout,) try: self.client.set(*args) - except: - pass + except Exception: + if not self.ignore_memcache_errors: + raise