本文整理汇总了Python中nevow.inevow.IRequest类的典型用法代码示例。如果您正苦于以下问题:Python IRequest类的具体用法?Python IRequest怎么用?Python IRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了IRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: render_POST
def render_POST(self, ctx):
req = IRequest(ctx)
log.msg(format="User reports incident through web page: %(details)s",
details=get_arg(req, "details", ""),
level=log.WEIRD, umid="LkD9Pw")
req.setHeader("content-type", "text/plain")
return "An incident report has been saved to logs/incidents/ in the node directory."
示例2: error
def error(f):
message, code = humanize_failure(f)
req = IRequest(ctx)
req.setResponseCode(code)
return json.dumps({
"error": message,
})
示例3: render_GET
def render_GET(self, ctx):
req = IRequest(ctx)
# This is where all of the directory-related ?t=* code goes.
t = get_arg(req, "t", "").strip()
# t=info contains variable ophandles, t=rename-form contains the name
# of the child being renamed. Neither is allowed an ETag.
FIXED_OUTPUT_TYPES = ["", "json", "uri", "readonly-uri"]
if not self.node.is_mutable() and t in FIXED_OUTPUT_TYPES:
si = self.node.get_storage_index()
if si and req.setETag('DIR:%s-%s' % (base32.b2a(si), t or "")):
return ""
if not t:
# render the directory as HTML, using the docFactory and Nevow's
# whole templating thing.
return DirectoryAsHTML(self.node,
self.client.mutable_file_default)
if t == "json":
return DirectoryJSONMetadata(ctx, self.node)
if t == "info":
return MoreInfo(self.node)
if t == "uri":
return DirectoryURI(ctx, self.node)
if t == "readonly-uri":
return DirectoryReadonlyURI(ctx, self.node)
if t == 'rename-form':
return RenameForm(self.node)
raise WebError("GET directory: bad t=%s" % t)
示例4: renderHTTP_exception
def renderHTTP_exception(self, ctx, f):
try:
text, code = humanize_failure(f)
except:
log.msg("exception in humanize_failure")
log.msg("argument was %s" % (f,))
log.err()
text, code = str(f), None
if code is not None:
return self.simple(ctx, text, code)
if f.check(server.UnsupportedMethod):
# twisted.web.server.Request.render() has support for transforming
# this into an appropriate 501 NOT_IMPLEMENTED or 405 NOT_ALLOWED
# return code, but nevow does not.
req = IRequest(ctx)
method = req.method
return self.simple(ctx,
"I don't know how to treat a %s request." % method,
http.NOT_IMPLEMENTED)
req = IRequest(ctx)
accept = req.getHeader("accept")
if not accept:
accept = "*/*"
if "*/*" in accept or "text/*" in accept or "text/html" in accept:
super = appserver.DefaultExceptionHandler
return super.renderHTTP_exception(self, ctx, f)
# use plain text
traceback = f.getTraceback()
return self.simple(ctx, traceback, http.INTERNAL_SERVER_ERROR)
示例5: render_GET
def render_GET(self, ctx):
req = IRequest(ctx)
t = get_arg(req, "t", "").strip()
# t=info contains variable ophandles, so is not allowed an ETag.
FIXED_OUTPUT_TYPES = ["", "json", "uri", "readonly-uri"]
if not self.node.is_mutable() and t in FIXED_OUTPUT_TYPES:
# if the client already has the ETag then we can
# short-circuit the whole process.
si = self.node.get_storage_index()
if si and req.setETag('%s-%s' % (base32.b2a(si), t or "")):
return ""
if not t:
# just get the contents
# the filename arrives as part of the URL or in a form input
# element, and will be sent back in a Content-Disposition header.
# Different browsers use various character sets for this name,
# sometimes depending upon how language environment is
# configured. Firefox sends the equivalent of
# urllib.quote(name.encode("utf-8")), while IE7 sometimes does
# latin-1. Browsers cannot agree on how to interpret the name
# they see in the Content-Disposition header either, despite some
# 11-year old standards (RFC2231) that explain how to do it
# properly. So we assume that at least the browser will agree
# with itself, and echo back the same bytes that we were given.
filename = get_arg(req, "filename", self.name) or "unknown"
d = self.node.get_best_readable_version()
d.addCallback(lambda dn: FileDownloader(dn, filename))
return d
if t == "json":
# We do this to make sure that fields like size and
# mutable-type (which depend on the file on the grid and not
# just on the cap) are filled in. The latter gets used in
# tests, in particular.
#
# TODO: Make it so that the servermap knows how to update in
# a mode specifically designed to fill in these fields, and
# then update it in that mode.
if self.node.is_mutable():
d = self.node.get_servermap(MODE_READ)
else:
d = defer.succeed(None)
if self.parentnode and self.name:
d.addCallback(lambda ignored:
self.parentnode.get_metadata_for(self.name))
else:
d.addCallback(lambda ignored: None)
d.addCallback(lambda md: FileJSONMetadata(ctx, self.node, md))
return d
if t == "info":
return MoreInfo(self.node)
if t == "uri":
return FileURI(ctx, self.node)
if t == "readonly-uri":
return FileReadOnlyURI(ctx, self.node)
raise WebError("GET file: bad t=%s" % t)
示例6: ManifestStreamer
class ManifestStreamer(dirnode.DeepStats):
implements(IPushProducer)
def __init__(self, ctx, origin):
dirnode.DeepStats.__init__(self, origin)
self.req = IRequest(ctx)
def setMonitor(self, monitor):
self.monitor = monitor
def pauseProducing(self):
pass
def resumeProducing(self):
pass
def stopProducing(self):
self.monitor.cancel()
def add_node(self, node, path):
dirnode.DeepStats.add_node(self, node, path)
d = {"path": path,
"cap": node.get_uri()}
if IDirectoryNode.providedBy(node):
d["type"] = "directory"
elif IFileNode.providedBy(node):
d["type"] = "file"
else:
d["type"] = "unknown"
v = node.get_verify_cap()
if v:
v = v.to_string()
d["verifycap"] = v or ""
r = node.get_repair_cap()
if r:
r = r.to_string()
d["repaircap"] = r or ""
si = node.get_storage_index()
if si:
si = base32.b2a(si)
d["storage-index"] = si or ""
j = simplejson.dumps(d, ensure_ascii=True)
assert "\n" not in j
self.req.write(j+"\n")
def finish(self):
stats = dirnode.DeepStats.get_results(self)
d = {"type": "stats",
"stats": stats,
}
j = simplejson.dumps(d, ensure_ascii=True)
assert "\n" not in j
self.req.write(j+"\n")
return ""
示例7: locateChild
def locateChild(self, context, segments):
"""
Unwrap the wrapped resource if HTTPS is already being used, otherwise
wrap it in a helper which will preserve the wrapping all the way down
to the final resource.
"""
request = IRequest(context)
if request.isSecure():
return self.wrappedResource, segments
return _SecureWrapper(self.urlGenerator, self.wrappedResource), segments
示例8: renderHTTP
def renderHTTP(self, context):
"""
Render the wrapped resource if HTTPS is already being used, otherwise
invoke a helper which may generate a redirect.
"""
request = IRequest(context)
if request.isSecure():
renderer = self.wrappedResource
else:
renderer = _SecureWrapper(self.urlGenerator, self.wrappedResource)
return renderer.renderHTTP(context)
示例9: setETag
def setETag(self, ctx, t):
"""Set the ETag on the response. If this matches a conditional
request, return True to short-circuit the request"""
req = IRequest(ctx)
if not self.node.is_mutable():
# If the client already has the ETag then we can
# short-circuit the whole process.
si = self.node.get_storage_index()
if si and req.setETag('CHK:%s-%s' % (base32.b2a(si), t or "")):
return True
return False
示例10: render_PUT
def render_PUT(self, ctx):
req = IRequest(ctx)
t = get_arg(req, "t", "").strip()
replace = parse_replace_arg(get_arg(req, "replace", "true"))
assert self.parentnode and self.name
if req.getHeader("content-range"):
raise WebError("Content-Range in PUT not yet supported", http.NOT_IMPLEMENTED)
if not t:
return self.replace_me_with_a_child(req, self.client, replace)
if t == "uri":
return self.replace_me_with_a_childcap(req, self.client, replace)
raise WebError("PUT to a file: bad t=%s" % t)
示例11: locateChild
def locateChild(self, context, segments):
"""
Delegate dispatch to a sharing resource if the request is for a user
subdomain, otherwise fall back to the wrapped resource's C{locateChild}
implementation.
"""
request = IRequest(context)
hostname = request.getHeader('host')
info = self.subdomain(hostname)
if info is not None:
username, domain = info
index = UserIndexPage(IRealm(self.siteStore),
self.webViewer)
resource = index.locateChild(None, [username])[0]
return resource, segments
return self.wrapped.locateChild(context, segments)
示例12: renderHTTP
def renderHTTP(self, ctx):
req = IRequest(ctx)
if req.method == 'GET':
req.setHeader('Content-Type', 'text/plain')
return 'PUT data here to create an object.'
elif req.method == 'PUT':
return self.handlePUT(req)
else:
req.setResponseCode(http.NOT_ALLOWED)
req.setHeader('Content-Type', 'text/plain')
return 'Method not allowed'
示例13: __init__
def __init__(self, ctx, origin):
dirnode.DeepStats.__init__(self, origin)
self.req = IRequest(ctx)
示例14: simple
def simple(self, ctx, text, code=http.BAD_REQUEST):
req = IRequest(ctx)
req.setResponseCode(code)
#req.responseHeaders.setRawHeaders("content-encoding", [])
#req.responseHeaders.setRawHeaders("content-disposition", [])
req.setHeader("content-type", "text/plain;charset=utf-8")
if isinstance(text, unicode):
text = text.encode("utf-8")
req.setHeader("content-length", str(len(text)))
req.write(text)
# TODO: consider putting the requested URL here
req.finishRequest(False)
示例15: text_plain
def text_plain(text, ctx):
req = IRequest(ctx)
req.setHeader("content-type", "text/plain")
req.setHeader("content-length", len(text))
return text