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


Python File.render方法代码示例

本文整理汇总了Python中twisted.web.static.File.render方法的典型用法代码示例。如果您正苦于以下问题:Python File.render方法的具体用法?Python File.render怎么用?Python File.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.web.static.File的用法示例。


在下文中一共展示了File.render方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: Insist

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render [as 别名]
class Insist(Resource):
    isLeaf = True

    def __init__(self, cacheloc):
        self.cacheloc = cacheloc
        self.cachefile = None
        if os.path.exists(cacheloc):
            self.cachefile = File(cacheloc)
        self.reqs_waiting = []
        self.started = False
        Resource.__init__(self)

    def render_GET(self, req):
        # Check if someone else has created the file somehow
        if self.cachefile is None and os.path.exists(self.cacheloc):
            self.cachefile = File(self.cacheloc)
        # Check if someone else has *deleted* the file
        elif self.cachefile is not None and not os.path.exists(self.cacheloc):
            self.cachefile = None

        if self.cachefile is not None:
            return self.cachefile.render_GET(req)
        else:
            self.reqs_waiting.append(req)
            req.notifyFinish().addErrback(
                self._nevermind, req)
            if not self.started:
                self.started = True
                reactor.callInThread(self.desist)
            return NOT_DONE_YET

    def _nevermind(self, _err, req):
        self.reqs_waiting.remove(req)

    def desist(self):
        self.serialize_computation(self.cacheloc)
        reactor.callFromThread(self.resist)

    def _get_mime(self):
        return mimetypes.guess_type(self.cacheloc)[0]

    def resist(self):
        if not os.path.exists(self.cacheloc):
            # Error!
            print "%s does not exist - rendering fail!" % (self.cacheloc)
            for req in self.reqs_waiting:
                req.headers["Content-Type"] = "text/plain"
                req.write("cyst error")
                req.finish()
            return

        self.cachefile = File(self.cacheloc)

        # Send content to all interested parties
        for req in self.reqs_waiting:
            self.cachefile.render(req)

    def serialize_computation(self, outpath):
        raise NotImplemented
开发者ID:EnGassa,项目名称:gentle,代码行数:61,代码来源:cyst.py

示例2: render

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render [as 别名]
 def render(self, request):
   basename = self.basename()
   if basename == 'index.html':
     filename = self.dirname() + '/' + basename
     with open(filename, 'r') as f:
       html_string = f.read()
       t = Template(html_string)
       global results
       if results.v:
         return t.substitute(PORT=str(results.ws), VIDEO='true')
       else:
         return t.substitute(PORT=str(results.ws), VIDEO='false')
   else:
     return File.render(self, request)
开发者ID:named-data,项目名称:peets,代码行数:16,代码来源:server.py

示例3: render

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render [as 别名]
 def render(self, request):
     """Overrides :meth:`.File.render` and sets the expires header"""
     request.responseHeaders.addRawHeader(
         "Cache-Control", "max-age=%s" % self.EXPIRES)
     return File.render(self, request)
开发者ID:xlhtc007,项目名称:pyfarm-agent,代码行数:7,代码来源:server.py


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