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


Python Request.headers["Date"]方法代码示例

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


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

示例1: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers["Date"] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug("Calling S3Multipart Helper Middleware")
        # self.logger.debug(req.__dict__)

        #
        # Check that the request has the correct AA headers
        #
        if "AWSAccessKeyId" in req.params:
            try:
                req.headers["Date"] = req.params["Expires"]
                req.headers["Authorization"] = "AWS %(AWSAccessKeyId)s:%(Signature)s" % req.params
            except KeyError:
                return get_err_response("InvalidArgument")(env, start_response)

        if "Authorization" not in req.headers:
            return self.app(env, start_response)
        try:
            keyword, info = req.headers["Authorization"].split(" ")
        except:
            return get_err_response("AccessDenied")(env, start_response)

        if keyword != "AWS":
            return get_err_response("AccessDenied")(env, start_response)
        try:
            account, signature = info.rsplit(":", 1)
        except:
            return get_err_response("InvalidArgument")(env, start_response)

        if req.method == "GET":
            return self.GET(env, start_response)
        elif req.method == "POST":
            return self.POST(env, start_response)
        elif req.method == "DELETE":
            return self.DELETE(env, start_response)
        elif req.method != "PUT":
            return self.app(env, start_response)

        #
        # If none of the above, it must be a PUT
        #
        if "QUERY_STRING" in env:
            args = dict(urlparse.parse_qsl(env["QUERY_STRING"], 1))
        else:
            args = {}

        path = None

        if "partNumber" in args:
            partNo = args["partNumber"]

        uploadId = None
        if "uploadId" in args:
            uploadId = args["uploadId"]
        if "QUERY_STRING" in env:
            del env["QUERY_STRING"]

        if "HTTP_CONTENT_MD5" in env.items():
            value = env["HTTP_CONTENT_MD5"]
            if value == "":
                return get_err_response("InvalidDigest")
            try:
                env["HTTP_ETAG"] = value.decode("base64").encode("hex")
            except:
                return get_err_response("InvalidDigest")

            if env["HTTP_ETAG"] == "":
                return get_err_response("SignatureDoesNotMatch")

        #
        # If this is part of an S3 multipart upload, then put the parts
        # into the proper segment container instead of the primary container
        # that was requested.  This mimics the SWIFT multipart upload behavior
        # and leaves the objects so that they can be accessed by SWIFT or S3
        # API calls.
        #
        path = env["PATH_INFO"]
        if path is not None and uploadId is not None and partNo is not None:
            version, account, container, obj = split_path(path, 0, 4, True)
            env["PATH_INFO"] = "/%s/%s/%s_segments/%s/%s/%d" % (version, account, container, obj, uploadId, int(partNo))
            env["RAW_PATH_INFO"] = "/%s_segments/%s/%s/%08d" % (container, obj, uploadId, int(partNo))

        return self.app(env, start_response)
开发者ID:pyKun,项目名称:s3multi,代码行数:85,代码来源:middleware.py

示例2: handle_request

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers["Date"] [as 别名]
    def handle_request(self, env, start_response):
        req = Request(env)
        self.logger.debug("Calling Swift3 Middleware")
        # self.logger.debug(req.__dict__)

        if "AWSAccessKeyId" in req.params:
            try:
                req.headers["Date"] = req.params["Expires"]
                req.headers["Authorization"] = "AWS %(AWSAccessKeyId)s:%(Signature)s" % req.params
            except KeyError:
                return get_err_response("InvalidArgument")(env, start_response)

        if "Authorization" not in req.headers:
            return self.app(env, start_response)

        try:
            keyword, info = req.headers["Authorization"].split(" ")
        except:
            return get_err_response("AccessDenied")(env, start_response)

        if keyword != "AWS":
            return get_err_response("AccessDenied")(env, start_response)

        try:
            account, signature = info.split(":", 1)
        except:
            return get_err_response("InvalidArgument")(env, start_response)

        try:
            controller, path_parts = self.get_controller(env, req.path)
        except ValueError:
            return get_err_response("InvalidURI")(env, start_response)

        # print controller, req.method
        if "Date" in req.headers:
            date = email.utils.parsedate(req.headers["Date"])
            if date is None and "Expires" in req.params:
                d = email.utils.formatdate(float(req.params["Expires"]))
                date = email.utils.parsedate(d)

            if date is None:
                return get_err_response("AccessDenied")(env, start_response)

            d1 = datetime.datetime(*date[0:6])
            d2 = datetime.datetime.utcnow()
            epoch = datetime.datetime(1970, 1, 1, 0, 0, 0, 0)

            if d1 < epoch:
                return get_err_response("AccessDenied")(env, start_response)

            delta = datetime.timedelta(seconds=60 * 5)
            if d1 - d2 > delta or d2 - d1 > delta:
                return get_err_response("RequestTimeTooSkewed")(env, start_response)

        token = base64.urlsafe_b64encode(canonical_string(req))

        controller = controller(env, self.app, account, token, conf=self.conf, **path_parts)

        if hasattr(controller, req.method):
            res = getattr(controller, req.method)(env, start_response)
        else:
            return get_err_response("InvalidURI")(env, start_response)

        return res(env, start_response)
开发者ID:pyKun,项目名称:swift3,代码行数:66,代码来源:middleware.py


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