本文整理汇总了Python中twisted.web.resource.NoResource.render方法的典型用法代码示例。如果您正苦于以下问题:Python NoResource.render方法的具体用法?Python NoResource.render怎么用?Python NoResource.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.web.resource.NoResource
的用法示例。
在下文中一共展示了NoResource.render方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_POST
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
def render_POST(self, request):
if request.path != self._path:
page = NoResource(
message="API path %s is not supported" % request.URLPath())
return page.render(request)
if request.getHeader(b"Content-Type") != b"application/json":
page = NoResource(
message="Unsupported Content-Type (must be \"application/json"
"\")" % request.URLPath())
return page.render(request)
request.setHeader(b"Content-Type", b"application/json")
self._callback(request)
return NOT_DONE_YET
示例2: CgiDirectory
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
class CgiDirectory(Resource, FilePath):
cgiscript = CgiScript
def __init__(self, pathname, filter, childNotFound=None):
Resource.__init__(self)
FilePath.__init__(self, pathname)
self.filter = filter
if childNotFound:
self.childNotFound = childNotFound
else:
self.childNotFound = NoResource("CGI directories do not support directory listing.")
def getChild(self, path, request):
fnp = self.child(path)
if not fnp.exists():
return File.childNotFound
elif fnp.isdir():
return CgiDirectory(fnp.path, self.filter, self.childNotFound)
else:
return self.cgiscript(fnp.path, self.filter)
return NoResource()
def render(self, request):
return self.childNotFound.render(request)
示例3: render
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
def render(self, request):
if self.type == self.types.REDIRECT:
return ""
elif self.type == self.types.QUEUE:
return NOT_DONE_YET
else:
return NoResource.render(self, request)
示例4: return_404
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
def return_404(self, request):
"""Return a 404 HTTP response.
:param request: The request to which we are responding.
:returns: NoResource's rendering of the request.
Performed if a request tries to access a nonexistent table.
"""
page = NoResource(message="Table %s could not be found" %
self.table_name)
return page.render(request)
示例5: Server
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
class Server(Resource):
def __init__(self):
Resource.__init__(self)
self.isLeaf = True
self.r404 = NoResource()
fp = file(sys.argv[0])
self.src = fp.read()
fp.close()
from subprocess import PIPE, Popen
try:
self.src_syn = Popen(['pandoc', '-s'], stdin=PIPE, stdout=PIPE, stderr=PIPE).communicate("~~~~ {.python}\n" + self.src + "~~~~\n")[0]
except OSError:
sys.stderr.write("pandoc not found; /src/ will default to plain text rather than syntax highlighted code\n")
self.src_syn = None
def render_GET(self, request):
host, path = request.client.host, request.path
print_flush_log("R %s %s" % (host, path))
request.setHeader("content-type", "text/plain")
if path == "/":
return "%s %s\n%s\n/tcp/[port]\n/udp/[port]\n/src/\n/src/raw\n/src/get\n" % (NAME, VERSION, __doc__)
try:
type, port = path[1:].split('/', 2)
if type == "src":
if port == "raw":
return self.src
elif port == "get":
request.setHeader("content-type", "text/x-python")
request.setHeader("content-disposition", "attachment; filename=\"%s\"" % FNAME);
return self.src
elif self.src_syn is not None:
request.setHeader("content-type", "text/html")
return self.src_syn
else:
return self.src
elif type not in PROTOCOL:
raise KeyError
port = int(port)
except (ValueError, KeyError):
return self.r404.render(request)
else:
start_connect(host, type, port, reactor.callLater)
return "awaiting connection to %s %s %s" % (host, type, port)
示例6: render_DELETE
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
def render_DELETE(self, request):
# print "KeyResource.render_DELETE"
if not self.isRemovable():
epage = NoResource(
"deleting collection %s failed." % request.uri)
return epage.render(request)
if self.isdir():
depth = get_depth(request)
if not depth:
epage = BadRequestResource(
"deleting collection %s failed."
"because depth is not "infinity""
% request.uri)
return epage.render(request)
self.rmtree()
else:
self.remove()
epage = NoContentResource("%s deleted" % request.uri)
return epage.render(request)
示例7: render
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
def render(self, request):
notFound = NoResource("CGI directories do not support directory listing.")
return notFound.render(request)
示例8: responseNotFound
# 需要导入模块: from twisted.web.resource import NoResource [as 别名]
# 或者: from twisted.web.resource.NoResource import render [as 别名]
def responseNotFound(self, request, failure):
errorPage = NoResource(message=failure.getErrorMessage())
request.write(errorPage.render(request))
request.finish()