本文整理汇总了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)
示例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))
示例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
示例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.")
示例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)
示例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)
示例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)
示例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)
示例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)
示例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)