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


Python IRequest.getHeader方法代码示例

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


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

示例1: renderHTTP_exception

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import getHeader [as 别名]
 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)
开发者ID:gnusosa,项目名称:tahoe-lafs,代码行数:31,代码来源:common.py

示例2: render_PUT

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import getHeader [as 别名]
    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)
开发者ID:p-static,项目名称:tahoe-lafs,代码行数:16,代码来源:filenode.py

示例3: locateChild

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import getHeader [as 别名]
    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)
开发者ID:fusionapp,项目名称:mantissa,代码行数:19,代码来源:_webutil.py

示例4: renderHTTP

# 需要导入模块: from nevow.inevow import IRequest [as 别名]
# 或者: from nevow.inevow.IRequest import getHeader [as 别名]
    def renderHTTP(self, ctx):
        req = IRequest(ctx)
        gte = static.getTypeAndEncoding
        ctype, encoding = gte(self.filename,
                              static.File.contentTypes,
                              static.File.contentEncodings,
                              defaultType="text/plain")
        req.setHeader("content-type", ctype)
        if encoding:
            req.setHeader("content-encoding", encoding)

        if boolean_of_arg(get_arg(req, "save", "False")):
            # tell the browser to save the file rather display it we don't
            # try to encode the filename, instead we echo back the exact same
            # bytes we were given in the URL. See the comment in
            # FileNodeHandler.render_GET for the sad details.
            req.setHeader("content-disposition",
                          'attachment; filename="%s"' % self.filename)

        filesize = self.filenode.get_size()
        assert isinstance(filesize, (int,long)), filesize
        first, size = 0, None
        contentsize = filesize
        req.setHeader("accept-ranges", "bytes")

        # TODO: for mutable files, use the roothash. For LIT, hash the data.
        # or maybe just use the URI for CHK and LIT.
        rangeheader = req.getHeader('range')
        if rangeheader:
            ranges = self.parse_range_header(rangeheader)

            # ranges = None means the header didn't parse, so ignore
            # the header as if it didn't exist.  If is more than one
            # range, then just return the first for now, until we can
            # generate multipart/byteranges.
            if ranges is not None:
                first, last = ranges[0]

                if first >= filesize:
                    raise WebError('First beyond end of file',
                                   http.REQUESTED_RANGE_NOT_SATISFIABLE)
                else:
                    first = max(0, first)
                    last = min(filesize-1, last)

                    req.setResponseCode(http.PARTIAL_CONTENT)
                    req.setHeader('content-range',"bytes %s-%s/%s" %
                                  (str(first), str(last),
                                   str(filesize)))
                    contentsize = last - first + 1
                    size = contentsize

        req.setHeader("content-length", b"%d" % contentsize)
        if req.method == "HEAD":
            return ""

        finished = []
        def _request_finished(ign):
            finished.append(True)
        req.notifyFinish().addBoth(_request_finished)

        d = self.filenode.read(req, first, size)

        def _finished(ign):
            if not finished:
                req.finish()
        def _error(f):
            lp = log.msg("error during GET", facility="tahoe.webish", failure=f,
                         level=log.UNUSUAL, umid="xSiF3w")
            if finished:
                log.msg("but it's too late to tell them", parent=lp,
                        level=log.UNUSUAL, umid="j1xIbw")
                return
            req._tahoe_request_had_error = f # for HTTP-style logging
            if req.startedWriting:
                # The content-type is already set, and the response code has
                # already been sent, so we can't provide a clean error
                # indication. We can emit text (which a browser might
                # interpret as something else), and if we sent a Size header,
                # they might notice that we've truncated the data. Keep the
                # error message small to improve the chances of having our
                # error response be shorter than the intended results.
                #
                # We don't have a lot of options, unfortunately.
                req.write("problem during download\n")
                req.finish()
            else:
                # We haven't written anything yet, so we can provide a
                # sensible error message.
                eh = MyExceptionHandler()
                eh.renderHTTP_exception(ctx, f)
        d.addCallbacks(_finished, _error)
        return req.deferred
开发者ID:tahoe-lafs,项目名称:tahoe-lafs,代码行数:95,代码来源:filenode.py


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