cache (and compile) parse_template in run_view_in, fix #1474

This commit is contained in:
ilvalle
2016-09-25 10:08:26 +02:00
parent 0e4ff55306
commit 576aaf668d
5 changed files with 33 additions and 68 deletions
+5 -11
View File
@@ -24,9 +24,6 @@ try:
# have web2py
from gluon.restricted import RestrictedError
from gluon.globals import current
from gluon.cfs import getcfs
from gluon.fileutils import read_file
HAS_CFS = True
except ImportError:
# do not have web2py
current = None
@@ -783,14 +780,11 @@ def parse_template(filename,
# First, if we have a str try to open the file
if isinstance(filename, str):
fname = os.path.join(path, filename)
if HAS_CFS:
text = getcfs(fname, fname, lambda: read_file(fname))
else:
try:
with open(fname, 'rb') as fp:
text = fp.read()
except IOError:
raise RestrictedError(filename, '', 'Unable to find the file')
try:
with open(fname, 'rb') as fp:
text = fp.read()
except IOError:
raise RestrictedError(filename, '', 'Unable to find the file')
else:
text = filename.read()
text = to_native(text)