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


Python Request.headers["X-Object-Manifest"]方法代码示例

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


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

示例1: completeMultipartUpload

# 需要导入模块: from swift.common.swob import Request [as 别名]
# 或者: from swift.common.swob.Request import headers["X-Object-Manifest"] [as 别名]
    def completeMultipartUpload(self, env, start_response):
        req = Request(env)
        if "QUERY_STRING" in env:
            args = dict(urlparse.parse_qsl(env["QUERY_STRING"], 1))
        else:
            args = {}

        uploadId = args["uploadId"]

        parts = urlparse.urlparse(req.url)
        version, auth, container, obj = split_path(parts.path, 0, 4, True)

        if obj is None:
            obj = os.path.basename(env["RAW_PATH_INFO"])

        #
        # Query for the objects in the segments area to make sure it completed
        #
        env["REQUEST_METHOD"] = "GET"
        env["PATH_INFO"] = "/%s/%s/%s_segments" % (version, auth, container)
        env["RAW_PATH_INFO"] = "/%s/%s/%s_segments" % (version, auth, container)
        env["QUERY_STRING"] = "format=json&limit=1001&prefix=%s/%s/" "&delimiter=/" % (obj, uploadId)
        env["SCRIPT_NAME"] = ""

        req = Request(env)

        body_iter = self._app_call(env)
        status = self._get_status_int()

        objinfo = loads("".join(list(body_iter)))

        if len(objinfo) == 0:
            return get_err_response("NoSuchBucket")

        #
        # Tell Swift the manifest info
        # The content length should be 0 and the manifest should point to
        # the segment container.
        #
        req.method = "PUT"
        req.headers["X-Object-Manifest"] = "%s_segments/%s/%s" % (container, obj, uploadId)
        req.headers["Content-Length"] = "0"
        env["PATH_INFO"] = "/%s/%s/%s/%s" % (version, auth, container, obj)
        env["RAW_PATH_INFO"] = "/%s/%s/%s/%s" % (version, auth, container, obj)
        del env["QUERY_STRING"]
        env["SCRIPT_NAME"] = ""
        req.body = ""

        body_iter = self._app_call(env)
        status = self._get_status_int()

        if status != HTTP_OK and status != HTTP_CREATED:
            if status == HTTP_UNAUTHORIZED:
                return get_err_response("AccessDenied")
            elif status == HTTP_NOT_FOUND:
                return get_err_response("NoSuchBucket")
            else:
                return get_err_response("InvalidURI")

        o = objinfo[0]

        body = (
            '<?xml version="1.0" encoding="UTF-8"?>'
            "<CompleteMultipartUploadResult "
            'xmlns="http://s3.amazonaws.com/doc/2006-03-01">'
            "<Location>%s://%s/%s/%s</Location>"
            "<Bucket>%s</Bucket>"
            "<Key>%s</Key>"
            '<ETag>"%s"</ETag>'
            "</CompleteMultipartUploadResult>"
            % (parts.scheme, parts.netloc, container, obj, container, o["name"], o["hash"])
        )

        resp = Response(body=body, content_type="application/xml")
        return resp
开发者ID:pyKun,项目名称:s3multi,代码行数:77,代码来源:middleware.py


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