当前位置: 首页>>代码示例>>Python>>正文


Python Renderer.encode方法代码示例

本文整理汇总了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")
开发者ID:stal888,项目名称:DropServ,代码行数:44,代码来源:Functions.py

示例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");
开发者ID:seisatsu,项目名称:DropServ,代码行数:41,代码来源:Functions.py


注:本文中的pystache.Renderer.encode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。