本文整理汇总了Python中pystache.Renderer.encode方法的典型用法代码示例。如果您正苦于以下问题:Python Renderer.encode方法的具体用法?Python Renderer.encode怎么用?Python Renderer.encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pystache.Renderer
的用法示例。
在下文中一共展示了Renderer.encode方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: page_format
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import encode [as 别名]
def page_format(self, v={}, template=None, TemplateString="", root=None):
"""Format pages (obv)"""
temp = None
if root == None:
root = self.instance.workd + "/templates"
if template != None:
if len(self.TemplateCache) >= 5:
self.TemplateCache.popleft()
for item in copy.copy(self.TemplateCache):
if item[0] == template:
if os.path.getmtime("{0}/{1}".format(root, template)) > item[2]:
self.TemplateCache.remove(item)
break
else:
temp = item[1]
break
if not temp:
if template not in self.file_locks:
self.file_locks[template] = threading.RLock()
self.file_locks[template].acquire()
try:
with open(root + "/{0}".format(template), "r") as plate:
temp = plate.read()
self.TemplateCache.append((template, temp, time.time()))
self.file_locks[template].release()
except IOError:
if template in self.file_locks:
self.file_locks[template].release()
del self.file_locks[template]
return ""
elif TemplateString != "":
temp = TemplateString
else:
return ""
for x in v:
if isinstance(v[x], basestring):
try:
v[x] = v[x].decode("utf-8")
except:
pass
formatted = Renderer().render(temp, self.instance.lang.getDict, v, constant=self.TemplateConstants)
return formatted.encode("utf-8")
示例2: page_format
# 需要导入模块: from pystache import Renderer [as 别名]
# 或者: from pystache.Renderer import encode [as 别名]
def page_format(self, v={}, template=None, TemplateString="", root=None):
"""Format pages (obv)"""
temp = None
if root == None:
root = self.instance.workd + "/templates"
if template != None:
if len(self.TemplateCache) >= 5:
print("Removed template: {0} from cache.".format(self.TemplateCache.popleft()[0]));
for item in self.TemplateCache:
if item[0] == template:
temp = item[1]
break;
if not temp:
if template not in self.file_locks:
self.file_locks[template] = threading.RLock();
self.file_locks[template].acquire();
try:
with open(root + "/{0}".format(template), "r") as plate:
temp = plate.read();
self.TemplateCache.append((template, temp, time.time()));
print("Cached template: {0}".format(template));
self.file_locks[template].release();
except IOError:
if template in self.file_locks:
self.file_locks[template].release();
del self.file_locks[template];
return "";
elif TemplateString != "":
temp = TemplateString;
else:
return "";
for x in v:
if isinstance(v[x], basestring):
try:
v[x] = v[x].decode("utf-8")
except:
pass
formatted = Renderer().render(temp, self.instance.lang.getDict, v, constant=self.TemplateConstants)
return formatted.encode("utf-8");