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

Unified Diff: third_party/jinja2/loaders.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/lexer.py ('k') | third_party/jinja2/meta.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/jinja2/loaders.py
diff --git a/third_party/jinja2/loaders.py b/third_party/jinja2/loaders.py
index 419a9c8c6c1566a918c041e5d28e767f85a1ff24..a9a2625274c28c36125ecd01f70601194e36d6a1 100644
--- a/third_party/jinja2/loaders.py
+++ b/third_party/jinja2/loaders.py
@@ -13,12 +13,10 @@ import sys
import weakref
from types import ModuleType
from os import path
-try:
- from hashlib import sha1
-except ImportError:
- from sha import new as sha1
+from hashlib import sha1
from jinja2.exceptions import TemplateNotFound
-from jinja2.utils import LRUCache, open_if_exists, internalcode
+from jinja2.utils import open_if_exists, internalcode
+from jinja2._compat import string_types, iteritems
def split_template_path(template):
@@ -153,7 +151,7 @@ class FileSystemLoader(BaseLoader):
"""
def __init__(self, searchpath, encoding='utf-8'):
- if isinstance(searchpath, basestring):
+ if isinstance(searchpath, string_types):
searchpath = [searchpath]
self.searchpath = list(searchpath)
self.encoding = encoding
@@ -274,7 +272,7 @@ class DictLoader(BaseLoader):
def get_source(self, environment, template):
if template in self.mapping:
source = self.mapping[template]
- return source, None, lambda: source != self.mapping.get(template)
+ return source, None, lambda: source == self.mapping.get(template)
raise TemplateNotFound(template)
def list_templates(self):
@@ -306,7 +304,7 @@ class FunctionLoader(BaseLoader):
rv = self.load_func(template)
if rv is None:
raise TemplateNotFound(template)
- elif isinstance(rv, basestring):
+ elif isinstance(rv, string_types):
return rv, None, None
return rv
@@ -330,12 +328,16 @@ class PrefixLoader(BaseLoader):
self.mapping = mapping
self.delimiter = delimiter
- def get_source(self, environment, template):
+ def get_loader(self, template):
try:
prefix, name = template.split(self.delimiter, 1)
loader = self.mapping[prefix]
except (ValueError, KeyError):
raise TemplateNotFound(template)
+ return loader, name
+
+ def get_source(self, environment, template):
+ loader, name = self.get_loader(template)
try:
return loader.get_source(environment, name)
except TemplateNotFound:
@@ -343,9 +345,19 @@ class PrefixLoader(BaseLoader):
# (the one that includes the prefix)
raise TemplateNotFound(template)
+ @internalcode
+ def load(self, environment, name, globals=None):
+ loader, local_name = self.get_loader(name)
+ try:
+ return loader.load(environment, local_name)
+ except TemplateNotFound:
+ # re-raise the exception with the correct fileame here.
+ # (the one that includes the prefix)
+ raise TemplateNotFound(name)
+
def list_templates(self):
result = []
- for prefix, loader in self.mapping.iteritems():
+ for prefix, loader in iteritems(self.mapping):
for template in loader.list_templates():
result.append(prefix + self.delimiter + template)
return result
@@ -376,6 +388,15 @@ class ChoiceLoader(BaseLoader):
pass
raise TemplateNotFound(template)
+ @internalcode
+ def load(self, environment, name, globals=None):
+ for loader in self.loaders:
+ try:
+ return loader.load(environment, name, globals)
+ except TemplateNotFound:
+ pass
+ raise TemplateNotFound(name)
+
def list_templates(self):
found = set()
for loader in self.loaders:
@@ -408,7 +429,7 @@ class ModuleLoader(BaseLoader):
# create a fake module that looks for the templates in the
# path given.
mod = _TemplateModule(package_name)
- if isinstance(path, basestring):
+ if isinstance(path, string_types):
path = [path]
else:
path = list(path)
« no previous file with comments | « third_party/jinja2/lexer.py ('k') | third_party/jinja2/meta.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698