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


Python File.render_GET方法代码示例

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


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

示例1: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
 def render_GET(self, request):
     since = request.getHeader('if-modified-since')
     if since:
         tsince = time.strptime(since.replace(" GMT", ""))
         tfrom = time.strptime(time.ctime(os.path.getmtime(self.path)))
         if tfrom > tsince:
             return File.render_GET(self, request)
         else:
             request.setResponseCode(304)
             return ""
     return File.render_GET(self, request)
开发者ID:irregulator,项目名称:bitmask_client,代码行数:13,代码来源:fake_provider.py

示例2: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
 def render_GET(self,request):
   print("----------------------")
   print(request.getClientIP() +" : HEADERS")
   print("----------------------")
   print(request.getClientIP() +" : "+ str(request.getAllHeaders()))
   print("----------------------")
   return(File.render_GET(self,request))
开发者ID:shrinidhi666,项目名称:wtfBox,代码行数:9,代码来源:webServer.py

示例3: Insist

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [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

示例4: process

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
 def process(self):
     syslog.syslog(syslog.LOG_ERR,"DEBUG: http request received.")        
     needredirect=False
     #Normaly the client should be addressed by its IP.
     if self.getRequestHostname() == self.getHost().host:
         syslog.syslog(syslog.LOG_ERR,"DEBUG: by ip")
         #Our main application page generated at startup time.
         if self.path == "/gatewaylist":
             self.setHeader('Content-Type', 'text/html')
             self.write(self.html)
         #The dynamic ajaxy status stuff.
         elif self.path == "/routerstatus":
             clientip=self.getClientIP()
             serverip=self.getHost().host
             self.setHeader('Content-Type', 'application/json')
             self.write(self.state(serverip,clientip))
         #Changing the current gateway for a given client ip.
         elif self.path == "/setgateway":
             self.setHeader('Content-Type', 'text/html')
             clientip=self.getClientIP()
             gatewaynum = int(self.args["gw"][0])
             self.dbusclient.setGateway(clientip,gatewaynum,self.state,self.getHost().host)
             self.write("<h1>Request made</h1>")
         #Our static files (images and javascript.
         elif self.files.has_key(self.path):
             realfile="/var/dynr-web/" + self.files[self.path] + self.path
             rfile=File(realfile)
             rfile.render_GET(self)
             self.unregisterProducer()
         #Anything else we redirect to our main application page.
         else:
             needredirect=True
     #If directed at a host name, the client will likely be 'parked'.
     else:
         #If the client uses a hostname, redirect to the main url.
         needredirect=True
     if needredirect:
         host=self.getHost().host
         port=self.getHost().port
         self.redirect("http://" + str(host) + ":" + str(port) + "/gatewaylist")
     self.finish()
     self.unregisterProducer()
     syslog.syslog(syslog.LOG_ERR,"DEBUG: http request handled.")        
开发者ID:DNPA,项目名称:dynr-web,代码行数:45,代码来源:dynr-web.py

示例5: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
    def render_GET(self, request):
        if self._cache_timeout is not None:
            request.setHeader(b'cache-control', u'max-age={}, public'.format(self._cache_timeout).encode('utf8'))
            request.setHeader(b'expires', http.datetimeToString(time.time() + self._cache_timeout))

        # set response headers for cross-origin requests
        #
        if self._allow_cross_origin:
            set_cross_origin_headers(request)

        return File.render_GET(self, request)
开发者ID:NinjaMSP,项目名称:crossbar,代码行数:13,代码来源:resource.py

示例6: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
    def render_GET(self, request):
        timestamp = datetime.now()
        uniqueRequestId = timestamp.isoformat()

        # Log first byte time
        self.log("Starting request for %s" % (uniqueRequestId))

        # Give the client a unique identifier
        request.setHeader('X-Torperf-request-id', uniqueRequestId)

        # Log last byte time when the request finishes
        request.notifyFinish().addCallback(self.log,
                                           "Finished request for %s" % (uniqueRequestId))
        request.notifyFinish().addErrback(self.log)

        return File.render_GET(self, request)
开发者ID:gsathya,项目名称:torperf2,代码行数:18,代码来源:fileserver.py

示例7: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
        def render_GET(self, request):
            if self._cache_timeout is not None:
                request.setHeader(b'cache-control', 'max-age={}, public'.format(self._cache_timeout))
                request.setHeader(b'expires', http.datetimeToString(time.time() + self._cache_timeout))

            return File.render_GET(self, request)
开发者ID:OspreyX,项目名称:crossbar,代码行数:8,代码来源:resource.py

示例8: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
 def render_GET(self, request):
     f = File(os.path.join(sibpath(__file__, "webpages"), 'index.html'))
     return f.render_GET(request)
开发者ID:RachelLader,项目名称:txOpenBCI,代码行数:5,代码来源:web.py

示例9: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
    def render_GET(self, request):
        if self._cache_timeout is not None:
            request.setHeader(b"cache-control", u"max-age={}, public".format(self._cache_timeout).encode("utf8"))
            request.setHeader(b"expires", http.datetimeToString(time.time() + self._cache_timeout))

        return File.render_GET(self, request)
开发者ID:Tsunami2069,项目名称:crossbar,代码行数:8,代码来源:resource.py

示例10: render_GET

# 需要导入模块: from twisted.web.static import File [as 别名]
# 或者: from twisted.web.static.File import render_GET [as 别名]
 def render_GET(self, request):
     """Intercept the request and print to console"""
     return File.render_GET(self, request)
开发者ID:aworkingteam,项目名称:ismyJSONvalid,代码行数:5,代码来源:ismyJSONvalid.py


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