Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(324)

Unified Diff: third_party/jinja2/bccache.py

Issue 23506004: Update Jinja2 (Python template library) to 2.7.1 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/jinja2/_stringdefs.py ('k') | third_party/jinja2/compiler.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/jinja2/bccache.py
diff --git a/third_party/jinja2/bccache.py b/third_party/jinja2/bccache.py
index 0b0ccad1f243c598fc23c84191275d2570c65330..f2f9db61b31c552e2ebac965004330ba9ff517b0 100644
--- a/third_party/jinja2/bccache.py
+++ b/third_party/jinja2/bccache.py
@@ -18,22 +18,17 @@ from os import path, listdir
import sys
import marshal
import tempfile
-import cPickle as pickle
import fnmatch
-try:
- from hashlib import sha1
-except ImportError:
- from sha import new as sha1
+from hashlib import sha1
from jinja2.utils import open_if_exists
+from jinja2._compat import BytesIO, pickle, PY2, text_type
# marshal works better on 3.x, one hack less required
-if sys.version_info > (3, 0):
- from io import BytesIO
+if not PY2:
marshal_dump = marshal.dump
marshal_load = marshal.load
else:
- from cStringIO import StringIO as BytesIO
def marshal_dump(code, f):
if isinstance(f, file):
@@ -165,7 +160,7 @@ class BytecodeCache(object):
hash = sha1(name.encode('utf-8'))
if filename is not None:
filename = '|' + filename
- if isinstance(filename, unicode):
+ if isinstance(filename, text_type):
filename = filename.encode('utf-8')
hash.update(filename)
return hash.hexdigest()
@@ -282,15 +277,26 @@ 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):
- code = self.client.get(self.prefix + bucket.key)
+ try:
+ code = self.client.get(self.prefix + bucket.key)
+ except Exception:
+ if not self.ignore_memcache_errors:
+ raise
+ code = None
if code is not None:
bucket.bytecode_from_string(code)
@@ -298,4 +304,8 @@ class MemcachedBytecodeCache(BytecodeCache):
args = (self.prefix + bucket.key, bucket.bytecode_to_string())
if self.timeout is not None:
args += (self.timeout,)
- self.client.set(*args)
+ try:
+ self.client.set(*args)
+ except Exception:
+ if not self.ignore_memcache_errors:
+ raise
« no previous file with comments | « third_party/jinja2/_stringdefs.py ('k') | third_party/jinja2/compiler.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698