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


Python swob.HTTPBadRequest类代码示例

本文整理汇总了Python中swift.common.swob.HTTPBadRequest的典型用法代码示例。如果您正苦于以下问题:Python HTTPBadRequest类的具体用法?Python HTTPBadRequest怎么用?Python HTTPBadRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: GETorHEAD

    def GETorHEAD(self, req):
        """Handler for HTTP GET/HEAD requests."""
	print 'in GETorHEAD function of accountcontroller class'
        if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Account name length of %d longer than %d' % \
                        (len(self.account_name),
                         constraints.MAX_ACCOUNT_NAME_LENGTH)
            return resp

        partition = self.app.account_ring.get_part(self.account_name)
	print 'partition',partition
        node_iter = self.app.iter_nodes(self.app.account_ring, partition)
	print 'node_iter',node_iter
        resp = self.GETorHEAD_base(
            req, _('Account'), node_iter, partition,
            req.swift_entity_path.rstrip('/'))
	print 'resp',resp
        if resp.status_int == HTTP_NOT_FOUND:
	    print 'resp.status_int == HTTP_NOT_FOUND'
            if resp.headers.get('X-Account-Status', '').lower() == 'deleted':
                resp.status = HTTP_GONE
            elif self.app.account_autocreate:
                resp = account_listing_response(self.account_name, req,
                                                get_listing_content_type(req))
        if req.environ.get('swift_owner'):
	    print 'req.environ.get(swift_owner), true'
            self.add_acls_from_sys_metadata(resp)
        else:
	    for header in self.app.swift_owner_headers:
		print 'header',header
                resp.headers.pop(header, None)
	print 'resp',resp
	print 'in GETorHEAD function of accountcontroller class end'
        return resp
开发者ID:jannatunnoor,项目名称:test_swift,代码行数:35,代码来源:account.py

示例2: GETorHEAD

    def GETorHEAD(self, req):
        """Handler for HTTP GET/HEAD requests."""
        if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Account name length of %d longer than %d' % \
                        (len(self.account_name),
                         constraints.MAX_ACCOUNT_NAME_LENGTH)
            return resp

        partition = self.app.account_ring.get_part(self.account_name)
        concurrency = self.app.account_ring.replica_count \
            if self.app.concurrent_gets else 1
        node_iter = self.app.iter_nodes(self.app.account_ring, partition)
        resp = self.GETorHEAD_base(
            req, _('Account'), node_iter, partition,
            req.swift_entity_path.rstrip('/'), concurrency)
        if resp.status_int == HTTP_NOT_FOUND:
            if resp.headers.get('X-Account-Status', '').lower() == 'deleted':
                resp.status = HTTP_GONE
            elif self.app.account_autocreate:
                resp = account_listing_response(self.account_name, req,
                                                get_listing_content_type(req))
        if req.environ.get('swift_owner'):
            self.add_acls_from_sys_metadata(resp)
        else:
            for header in self.app.swift_owner_headers:
                resp.headers.pop(header, None)
        return resp
开发者ID:Ahiknsr,项目名称:swift,代码行数:28,代码来源:account.py

示例3: PUT

 def PUT(self, req):
     """HTTP PUT request handler."""
     error_response = self.clean_acls(req) or check_metadata(req, "container")
     if error_response:
         return error_response
     if len(self.container_name) > MAX_CONTAINER_NAME_LENGTH:
         resp = HTTPBadRequest(request=req)
         resp.body = "Container name length of %d longer than %d" % (
             len(self.container_name),
             MAX_CONTAINER_NAME_LENGTH,
         )
         return resp
     account_partition, accounts, container_count = self.account_info(self.account_name, req)
     if not accounts and self.app.account_autocreate:
         self.autocreate_account(req.environ, self.account_name)
         account_partition, accounts, container_count = self.account_info(self.account_name, req)
     if not accounts:
         return HTTPNotFound(request=req)
     if (
         self.app.max_containers_per_account > 0
         and container_count >= self.app.max_containers_per_account
         and self.account_name not in self.app.max_containers_whitelist
     ):
         resp = HTTPForbidden(request=req)
         resp.body = "Reached container limit of %s" % self.app.max_containers_per_account
         return resp
     container_partition, containers = self.app.container_ring.get_nodes(self.account_name, self.container_name)
     headers = self._backend_requests(req, len(containers), account_partition, accounts)
     clear_info_cache(self.app, req.environ, self.account_name, self.container_name)
     resp = self.make_requests(req, self.app.container_ring, container_partition, "PUT", req.path_info, headers)
     return resp
开发者ID:zaitcev,项目名称:swift-lfs,代码行数:31,代码来源:container.py

示例4: GETorHEAD

 def GETorHEAD(self, req):
     """Handler for HTTP GET/HEAD requests."""
     partition, nodes = self.app.account_ring.get_nodes(self.account_name)
     resp = self.GETorHEAD_base(
         req, _('Account'), self.app.account_ring, partition,
         req.path_info.rstrip('/'))
     if resp.status_int == HTTP_NOT_FOUND and self.app.account_autocreate:
         if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
             resp = HTTPBadRequest(request=req)
             resp.body = 'Account name length of %d longer than %d' % \
                         (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
             return resp
         headers = self.generate_request_headers(req)
         resp = self.make_requests(
             Request.blank('/v1/' + self.account_name),
             self.app.account_ring, partition, 'PUT',
             '/' + self.account_name, [headers] * len(nodes))
         if not is_success(resp.status_int):
             self.app.logger.warning('Could not autocreate account %r' %
                                     self.account_name)
             return resp
         resp = self.GETorHEAD_base(
             req, _('Account'), self.app.account_ring, partition,
             req.path_info.rstrip('/'))
     return resp
开发者ID:blapid,项目名称:swift,代码行数:25,代码来源:account.py

示例5: POST

 def POST(self, req):
     """HTTP POST request handler."""
     error_response = check_metadata(req, 'account')
     if error_response:
         return error_response
     account_partition, accounts = \
         self.app.account_ring.get_nodes(self.account_name)
     headers = self.generate_request_headers(req, transfer=True)
     if self.app.memcache:
         self.app.memcache.delete(
             get_account_memcache_key(self.account_name))
     resp = self.make_requests(
         req, self.app.account_ring, account_partition, 'POST',
         req.path_info, [headers] * len(accounts))
     if resp.status_int == HTTP_NOT_FOUND and self.app.account_autocreate:
         if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
             resp = HTTPBadRequest(request=req)
             resp.body = 'Account name length of %d longer than %d' % \
                         (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
             return resp
         resp = self.make_requests(
             Request.blank('/v1/' + self.account_name),
             self.app.account_ring, account_partition, 'PUT',
             '/' + self.account_name, [headers] * len(accounts))
         if not is_success(resp.status_int):
             self.app.logger.warning('Could not autocreate account %r' %
                                     self.account_name)
             return resp
     return resp
开发者ID:blapid,项目名称:swift,代码行数:29,代码来源:account.py

示例6: PUT

    def PUT(self, req):
        """HTTP PUT request handler."""
        error_response = \
            self.clean_acls(req) or check_metadata(req, 'container')
        if error_response:
            return error_response
        if not req.environ.get('swift_owner'):
            for key in self.app.swift_owner_headers:
                req.headers.pop(key, None)
        if len(self.container_name) > constraints.MAX_CONTAINER_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Container name length of %d longer than %d' % \
                        (len(self.container_name),
                         constraints.MAX_CONTAINER_NAME_LENGTH)
            return resp
        container_count = self.account_info(self.account_name, req)

        clear_info_cache(self.app, req.environ,
                         self.account_name, self.container_name)

        storage = self.app.storage
        try:
            storage.container_create(self.account_name, self.container_name)
        except exceptions.OioException:
            return HTTPServerError(request=req)
        resp = HTTPCreated(request=req)
        return resp
开发者ID:GuillaumeDelaporte,项目名称:oio-swift,代码行数:27,代码来源:container.py

示例7: PUT

 def PUT(self, req):
     """HTTP PUT request handler."""
     if not self.app.allow_account_management:
         return HTTPMethodNotAllowed(
             request=req,
             headers={'Allow': ', '.join(self.allowed_methods)})
     error_response = check_metadata(req, 'account')
     if error_response:
         return error_response
     if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
         resp = HTTPBadRequest(request=req)
         resp.body = 'Account name length of %d longer than %d' % \
                     (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
         return resp
     account_partition, accounts = \
         self.app.account_ring.get_nodes(self.account_name)
     headers = {'X-Timestamp': normalize_timestamp(time.time()),
                'x-trans-id': self.trans_id,
                'Connection': 'close'}
     self.transfer_headers(req.headers, headers)
     if self.app.memcache:
         self.app.memcache.delete('account%s' % req.path_info.rstrip('/'))
     resp = self.make_requests(
         req, self.app.account_ring, account_partition, 'PUT',
         req.path_info, [headers] * len(accounts))
     return resp
开发者ID:a3linux,项目名称:swift,代码行数:26,代码来源:account.py

示例8: PUT

 def PUT(self, req):
     """HTTP PUT request handler."""
     error_response = \
         self.clean_acls(req) or check_metadata(req, 'container')
     if error_response:
         return error_response
     if len(self.container_name) > MAX_CONTAINER_NAME_LENGTH:
         resp = HTTPBadRequest(request=req)
         resp.body = 'Container name length of %d longer than %d' % \
                     (len(self.container_name), MAX_CONTAINER_NAME_LENGTH)
         return resp
     account_partition, accounts, container_count = \
         self.account_info(self.account_name,
                           autocreate=self.app.account_autocreate)
     if self.app.max_containers_per_account > 0 and \
             container_count >= self.app.max_containers_per_account and \
             self.account_name not in self.app.max_containers_whitelist:
         resp = HTTPForbidden(request=req)
         resp.body = 'Reached container limit of %s' % \
                     self.app.max_containers_per_account
         return resp
     if not accounts:
         return HTTPNotFound(request=req)
     container_partition, containers = self.app.container_ring.get_nodes(
         self.account_name, self.container_name)
     headers = self._backend_requests(req, len(containers),
                                      account_partition, accounts)
     if self.app.memcache:
         cache_key = get_container_memcache_key(self.account_name,
                                                self.container_name)
         self.app.memcache.delete(cache_key)
     resp = self.make_requests(
         req, self.app.container_ring,
         container_partition, 'PUT', req.path_info, headers)
     return resp
开发者ID:Neil-Jubinville,项目名称:swift,代码行数:35,代码来源:container.py

示例9: POST

 def POST(self, req):
     """HTTP POST request handler."""
     error_response = check_metadata(req, 'account')
     if error_response:
         return error_response
     account_partition, accounts = \
         self.app.account_ring.get_nodes(self.account_name)
     headers = {'X-Timestamp': normalize_timestamp(time.time()),
                'X-Trans-Id': self.trans_id,
                'Connection': 'close'}
     self.transfer_headers(req.headers, headers)
     if self.app.memcache:
         self.app.memcache.delete('account%s' % req.path_info.rstrip('/'))
     resp = self.make_requests(
         req, self.app.account_ring, account_partition, 'POST',
         req.path_info, [headers] * len(accounts))
     if resp.status_int == HTTP_NOT_FOUND and self.app.account_autocreate:
         if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
             resp = HTTPBadRequest(request=req)
             resp.body = 'Account name length of %d longer than %d' % \
                         (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
             return resp
         resp = self.make_requests(
             Request.blank('/v1/' + self.account_name),
             self.app.account_ring, account_partition, 'PUT',
             '/' + self.account_name, [headers] * len(accounts))
         if not is_success(resp.status_int):
             self.app.logger.warning('Could not autocreate account %r' %
                                     self.account_name)
             return resp
     return resp
开发者ID:a3linux,项目名称:swift,代码行数:31,代码来源:account.py

示例10: PUT

    def PUT(self, req):
        """HTTP PUT request handler."""
	print 'in PUT function of accountcontroller class'
        if not self.app.allow_account_management:
            return HTTPMethodNotAllowed(
                request=req,
                headers={'Allow': ', '.join(self.allowed_methods)})
        error_response = check_metadata(req, 'account')
	print 'error_response'
        if error_response:
            return error_response
        if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Account name length of %d longer than %d' % \
                        (len(self.account_name),
                         constraints.MAX_ACCOUNT_NAME_LENGTH)
            return resp
        account_partition, accounts = \
            self.app.account_ring.get_nodes(self.account_name)
	print ' account_partition, accounts',account_partion,accounts
        headers = self.generate_request_headers(req, transfer=True)
	print 'headers',headers
        clear_info_cache(self.app, req.environ, self.account_name)
        resp = self.make_requests(
            req, self.app.account_ring, account_partition, 'PUT',
            req.swift_entity_path, [headers] * len(accounts))
	print 'resp',resp
        self.add_acls_from_sys_metadata(resp)
	print 'in PUT function of accountcontroller class END'
        return resp
开发者ID:jannatunnoor,项目名称:test_swift,代码行数:30,代码来源:account.py

示例11: GETorHEAD

 def GETorHEAD(self, req):
     """Handler for HTTP GET/HEAD requests."""
     partition, nodes = self.app.account_ring.get_nodes(self.account_name)
     shuffle(nodes)
     resp = self.GETorHEAD_base(
         req, _('Account'), partition, nodes, req.path_info.rstrip('/'),
         len(nodes))
     if resp.status_int == HTTP_NOT_FOUND and self.app.account_autocreate:
         if len(self.account_name) > MAX_ACCOUNT_NAME_LENGTH:
             resp = HTTPBadRequest(request=req)
             resp.body = 'Account name length of %d longer than %d' % \
                         (len(self.account_name), MAX_ACCOUNT_NAME_LENGTH)
             return resp
         headers = {'X-Timestamp': normalize_timestamp(time.time()),
                    'X-Trans-Id': self.trans_id,
                    'Connection': 'close'}
         resp = self.make_requests(
             Request.blank('/v1/' + self.account_name),
             self.app.account_ring, partition, 'PUT',
             '/' + self.account_name, [headers] * len(nodes))
         if not is_success(resp.status_int):
             self.app.logger.warning('Could not autocreate account %r' %
                                     self.account_name)
             return resp
         resp = self.GETorHEAD_base(
             req, _('Account'), partition, nodes, req.path_info.rstrip('/'),
             len(nodes))
     return resp
开发者ID:a3linux,项目名称:swift,代码行数:28,代码来源:account.py

示例12: POST

 def POST(self, req):
     """HTTP POST request handler."""
     if len(self.account_name) > constraints.MAX_ACCOUNT_NAME_LENGTH:
         resp = HTTPBadRequest(request=req)
         resp.body = 'Account name length of %d longer than %d' % \
                     (len(self.account_name),
                      constraints.MAX_ACCOUNT_NAME_LENGTH)
         return resp
     error_response = check_metadata(req, 'account')
     if error_response:
         return error_response
     account_partition, accounts = \
         self.app.account_ring.get_nodes(self.account_name)
     headers = self.generate_request_headers(req, transfer=True)
     clear_info_cache(self.app, req.environ, self.account_name)
     resp = self.make_requests(
         req, self.app.account_ring, account_partition, 'POST',
         req.swift_entity_path, [headers] * len(accounts))
     if resp.status_int == HTTP_NOT_FOUND and self.app.account_autocreate:
         self.autocreate_account(req, self.account_name)
         resp = self.make_requests(
             req, self.app.account_ring, account_partition, 'POST',
             req.swift_entity_path, [headers] * len(accounts))
     self.add_acls_from_sys_metadata(resp)
     return resp
开发者ID:Ahiknsr,项目名称:swift,代码行数:25,代码来源:account.py

示例13: HEAD

 def HEAD(self, request):
     """Handle HTTP HEAD requests for the Swift Object Server."""
     try:
         device, partition, account, container, obj = split_path(unquote(request.path), 5, 5, True)
         validate_device_partition(device, partition)
     except ValueError, err:
         resp = HTTPBadRequest(request=request)
         resp.content_type = "text/plain"
         resp.body = str(err)
         return resp
开发者ID:schatt,项目名称:swift,代码行数:10,代码来源:server.py

示例14: PUT

    def PUT(self, req):
        """HTTP PUT request handler."""
        error_response = \
            self.clean_acls(req) or check_metadata(req, 'container')
        if error_response:
            return error_response
        policy_index = self._convert_policy_to_index(req)
        if policy_index is None:
            policy_index = int(POLICIES.default)
        if not req.environ.get('swift_owner'):
            for key in self.app.swift_owner_headers:
                req.headers.pop(key, None)
        if len(self.container_name) > constraints.MAX_CONTAINER_NAME_LENGTH:
            resp = HTTPBadRequest(request=req)
            resp.body = 'Container name length of %d longer than %d' % \
                        (len(self.container_name),
                         constraints.MAX_CONTAINER_NAME_LENGTH)
            return resp
        account_partition, accounts, container_count = \
            self.account_info(self.account_name, req)
        if not accounts and self.app.account_autocreate:
            self.autocreate_account(req, self.account_name)
            account_partition, accounts, container_count = \
                self.account_info(self.account_name, req)
        if not accounts:
            return HTTPNotFound(request=req)
        if self.app.max_containers_per_account > 0 and \
                container_count >= self.app.max_containers_per_account and \
                self.account_name not in self.app.max_containers_whitelist:
            container_info = \
                self.container_info(self.account_name, self.container_name,
                                    req)
            if not is_success(container_info.get('status')):
                resp = HTTPForbidden(request=req)
                resp.body = 'Reached container limit of %s' % \
                    self.app.max_containers_per_account
                return resp
        container_partition, containers = self.app.container_ring.get_nodes(
            self.account_name, self.container_name)
        headers = self._backend_requests(req, len(containers),
                                         account_partition, accounts,
                                         policy_index)
        clear_info_cache(self.app, req.environ,
                         self.account_name, self.container_name)
        resp = self.make_requests(
            req, self.app.container_ring,
            container_partition, 'PUT', req.swift_entity_path, headers)

        cloud_ring = CloudRing(self.container_name, POLICIES.get_by_index(policy_index))
        return_flag, _info = cloud_ring.create_containers()
        if not return_flag:
            msg = 'Failed:' + str(_info)
            raise PUTCloudContainerException(msg)

        return resp
开发者ID:kun--hust,项目名称:sdscloud,代码行数:55,代码来源:container.py

示例15: GETorHEAD

    def GETorHEAD(self, req):
        """Handler for HTTP GET/HEAD requests."""
        length_limit = self.get_name_length_limit()
        if len(self.account_name) > length_limit:
            resp = HTTPBadRequest(request=req)
            resp.body = b'Account name length of %d longer than %d' % \
                        (len(self.account_name), length_limit)
            # Don't cache this. We know the account doesn't exist because
            # the name is bad; we don't need to cache that because it's
            # really cheap to recompute.
            return resp

        partition = self.app.account_ring.get_part(self.account_name)
        concurrency = self.app.account_ring.replica_count \
            if self.app.concurrent_gets else 1
        node_iter = self.app.iter_nodes(self.app.account_ring, partition)
        params = req.params
        params['format'] = 'json'
        req.params = params
        resp = self.GETorHEAD_base(
            req, _('Account'), node_iter, partition,
            req.swift_entity_path.rstrip('/'), concurrency)
        if resp.status_int == HTTP_NOT_FOUND:
            if resp.headers.get('X-Account-Status', '').lower() == 'deleted':
                resp.status = HTTP_GONE
            elif self.app.account_autocreate:
                # This is kind of a lie; we pretend like the account is
                # there, but it's not. We'll create it as soon as something
                # tries to write to it, but we don't need databases on disk
                # to tell us that nothing's there.
                #
                # We set a header so that certain consumers can tell it's a
                # fake listing. The important one is the PUT of a container
                # to an autocreate account; the proxy checks to see if the
                # account exists before actually performing the PUT and
                # creates the account if necessary. If we feed it a perfect
                # lie, it'll just try to create the container without
                # creating the account, and that'll fail.
                resp = account_listing_response(
                    self.account_name, req,
                    listing_formats.get_listing_content_type(req))
                resp.headers['X-Backend-Fake-Account-Listing'] = 'yes'

        # Cache this. We just made a request to a storage node and got
        # up-to-date information for the account.
        resp.headers['X-Backend-Recheck-Account-Existence'] = str(
            self.app.recheck_account_existence)
        set_info_cache(self.app, req.environ, self.account_name, None, resp)

        if req.environ.get('swift_owner'):
            self.add_acls_from_sys_metadata(resp)
        else:
            for header in self.app.swift_owner_headers:
                resp.headers.pop(header, None)
        return resp
开发者ID:mahak,项目名称:swift,代码行数:55,代码来源:account.py


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