depot.py 文件源码

python
阅读 21 收藏 0 点赞 0 评论 0

项目:solaris-ips 作者: oracle 项目源码 文件源码
def __upload_file(self, *tokens):
                """Adds a file to an in-flight transaction for the Transaction
                ID specified in the request path.  The content is expected to be
                in the request body.  Returns no output."""

                try:
                        # cherrypy decoded it, but we actually need it encoded.
                        trans_id = quote(tokens[0], "")
                except IndexError:
                        raise
                        trans_id = None

                request = cherrypy.request
                response = cherrypy.response

                size = int(request.headers.get("Content-Length", 0))
                if size < 0:
                        raise cherrypy.HTTPError(http_client.BAD_REQUEST,
                            _("file/1 must be sent a file."))
                data = request.rfile
                attrs = dict(
                    val.split("=", 1)
                    for hdr, val in request.headers.items()
                    if hdr.lower().startswith("x-ipkg-setattr")
                )
                basename = attrs.get("basename", None)
                try:
                        self.repo.add_file(trans_id, data, basename, size)
                except srepo.RepositoryError as e:
                        # Assume a bad request was made.  A 404 can't be
                        # returned here as misc.versioned_urlopen will interpret
                        # that to mean that the server doesn't support this
                        # operation.
                        raise cherrypy.HTTPError(http_client.BAD_REQUEST, str(e))
                response.headers["Content-Length"] = "0"
                return response.body
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号