本文整理匯總了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)