本文整理汇总了Python中jinja2.utils.open_if_exists方法的典型用法代码示例。如果您正苦于以下问题:Python utils.open_if_exists方法的具体用法?Python utils.open_if_exists怎么用?Python utils.open_if_exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jinja2.utils
的用法示例。
在下文中一共展示了utils.open_if_exists方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_source
# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import open_if_exists [as 别名]
def get_source(self, environment, template):
pieces = split_template_path(template)
for searchpath in self.searchpath:
filename = path.join(searchpath, *pieces)
f = open_if_exists(filename)
if f is None:
continue
try:
contents = f.read().decode(self.encoding)
finally:
f.close()
mtime = path.getmtime(filename)
def uptodate():
try:
return path.getmtime(filename) == mtime
except OSError:
return False
return contents, filename, uptodate
raise TemplateNotFound(template)
示例2: get_source
# 需要导入模块: from jinja2 import utils [as 别名]
# 或者: from jinja2.utils import open_if_exists [as 别名]
def get_source(self, environment, template):
pieces = split_template_path(template)
for searchpath in self.searchpath:
filename = path.join(searchpath, *pieces)
f = open_if_exists(filename)
if f is None:
continue
try:
contents = f.read().decode(self.encoding)
finally:
f.close()
mtime = path.getmtime(filename)
def uptodate():
try:
return path.getmtime(filename) == mtime
except OSError:
return False
return contents, filename, uptodate
raise TemplateNotFound(template)