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


Python HTTPBadRequest.body方法代码示例

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


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

示例1: PUT

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 def PUT(self, req):
     """HTTP PUT request handler."""
     start_time = time.time()
     if not self.app.allow_account_management:
         self.app.logger.timing_since('PUT.timing', start_time)
         return HTTPMethodNotAllowed(request=req)
     error_response = check_metadata(req, 'account')
     if error_response:
         self.app.logger.increment('errors')
         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)
         self.app.logger.increment('errors')
         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))
     self.app.logger.timing_since('PUT.timing', start_time)
     return resp
开发者ID:missall,项目名称:swift,代码行数:30,代码来源:account.py

示例2: POST

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 def POST(self, req):
     """HTTP POST request handler."""
     start_time = time.time()
     error_response = check_metadata(req, 'account')
     if error_response:
         self.app.logger.increment('errors')
         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)
             self.app.logger.increment('errors')
             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
     self.app.logger.timing_since('POST.timing', start_time)
     return resp
开发者ID:missall,项目名称:swift,代码行数:37,代码来源:account.py

示例3: GETorHEAD

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 def GETorHEAD(self, req, stats_type):
     """Handler for HTTP GET/HEAD requests."""
     start_time = time.time()
     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)
             self.app.logger.timing_since(
                 '%s.timing' % (stats_type,), start_time)
             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))
     self.app.logger.timing_since('%s.timing' % (stats_type,), start_time)
     return resp
开发者ID:missall,项目名称:swift,代码行数:32,代码来源:account.py

示例4: GETorHEAD

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 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:hortonworkstest,项目名称:Hadoop-and-Swift-integration,代码行数:33,代码来源:account.py

示例5: POST

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 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:hortonworkstest,项目名称:Hadoop-and-Swift-integration,代码行数:35,代码来源:account.py

示例6: PUT

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 def PUT(self, req):
     """HTTP PUT request handler."""
     start_time = time.time()
     error_response = \
         self.clean_acls(req) or check_metadata(req, 'container')
     if error_response:
         self.app.logger.increment('errors')
         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)
         self.app.logger.increment('errors')
         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:
         self.app.logger.timing_since('PUT.timing', start_time)
         return HTTPNotFound(request=req)
     container_partition, containers = self.app.container_ring.get_nodes(
         self.account_name, self.container_name)
     headers = []
     for account in accounts:
         nheaders = {'X-Timestamp': normalize_timestamp(time.time()),
                     'x-trans-id': self.trans_id,
                     'X-Account-Host': '%(ip)s:%(port)s' % account,
                     'X-Account-Partition': account_partition,
                     'X-Account-Device': account['device'],
                     'Connection': 'close'}
         self.transfer_headers(req.headers, nheaders)
         headers.append(nheaders)
     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)
     self.app.logger.timing_since('PUT.timing', start_time)
     return resp
开发者ID:missall,项目名称:swift,代码行数:49,代码来源:container.py

示例7: HEAD

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 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)
     except ValueError, err:
         resp = HTTPBadRequest(request=request)
         resp.content_type = 'text/plain'
         resp.body = str(err)
         return resp
开发者ID:Nupta,项目名称:swift,代码行数:12,代码来源:server.py

示例8: HEAD

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 def HEAD(self, request):
     """Handle HTTP HEAD requests for the Swift Object Server."""
     start_time = time.time()
     try:
         device, partition, account, container, obj = split_path(unquote(request.path), 5, 5, True)
         validate_device_partition(device, partition)
     except ValueError, err:
         self.logger.increment("HEAD.errors")
         resp = HTTPBadRequest(request=request)
         resp.content_type = "text/plain"
         resp.body = str(err)
         return resp
开发者ID:andrewgaul,项目名称:swift,代码行数:14,代码来源:server.py

示例9: PUT

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
 def PUT(self, req):
     """HTTP PUT request handler."""
     if not self.app.allow_account_management:
         return HTTPMethodNotAllowed(request=req)
     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:hortonworkstest,项目名称:Hadoop-and-Swift-integration,代码行数:22,代码来源:account.py

示例10: handle_upgrade

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
    def handle_upgrade(self):
        """Completes the upgrade request sent by the browser

        Sends the headers required to set up to websocket connection back to
        the browser and then hands off to :meth:`handle_websocket`.

        See [websocket_protocol]_

        :returns: :exc:`webob.exc.HTTPBadRequest` if handshake fails
        """
        try:
            handshake_reply = websocket_handshake(self.request.headers)
        except HandShakeFailed:
            _, val, _ = sys.exc_info()
            response = HTTPBadRequest(headers=dict(Connection='Close'))
            response.body = 'Upgrade negotiation failed:\n\t%s\n%s' % \
                            (val, self.request.headers)
            return response
        sock = self.environ['eventlet.input'].get_socket()
        sock.sendall(handshake_reply)
        return self.handle_websocket(WebSocket(self.sock, self.environ))
开发者ID:okoye,项目名称:stargate,代码行数:23,代码来源:view.py

示例11: handle_upgrade

# 需要导入模块: from webob.exc import HTTPBadRequest [as 别名]
# 或者: from webob.exc.HTTPBadRequest import body [as 别名]
    def handle_upgrade(self):
        """Completes the upgrade request sent by the browser

        Sends the headers required to set up to websocket connection back to
        the browser and then hands off to :meth:`handle_websocket`. See:
        http://en.wikipedia.org/wiki/Web_Sockets#WebSocket_Protocol_Handshake
        """
        if not (self.environ.get('HTTP_CONNECTION') == 'Upgrade' and
        self.environ.get('HTTP_UPGRADE') == 'WebSocket'):
            response = HTTPBadRequest(headers=dict(Connection='Close'))
            response.body = 'Bad:\n%s' % pformat(self.environ)
            return response
        sock = self.environ['eventlet.input'].get_socket()
        handshake_reply = ("HTTP/1.1 101 Web Socket Protocol Handshake\r\n"
        "Upgrade: WebSocket\r\n"
        "Connection: Upgrade\r\n"
        "WebSocket-Origin: %s\r\n"
        "WebSocket-Location: ws://%s%s\r\n\r\n" % (
        self.request.host_url,
        self.request.host, self.request.path_info))
        sock.sendall(handshake_reply)
        websocket = WebSocket(self.sock, self.environ)
        return self.handle_websocket(websocket)
开发者ID:boothead,项目名称:multivisor,代码行数:25,代码来源:websocket.py


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