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


Python exc.HTTPBadRequest类代码示例

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


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

示例1: GETorHEAD

 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,代码行数:30,代码来源:account.py

示例2: PUT

 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,代码行数:28,代码来源:account.py

示例3: 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:hortonworkstest,项目名称:Hadoop-and-Swift-integration,代码行数:31,代码来源:account.py

示例4: 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:hortonworkstest,项目名称:Hadoop-and-Swift-integration,代码行数:33,代码来源:account.py

示例5: POST

 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,代码行数:35,代码来源:account.py

示例6: __init__

 def __init__(self, error_name):
     HTTPBadRequest.__init__(self)
     self.error_data = {
         'reason': error_name,
         'explanation': error_list[error_name],
     }
     self.explanation = error_list[error_name]
开发者ID:Cophy08,项目名称:reddit,代码行数:7,代码来源:errors.py

示例7: 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)
     except ValueError, err:
         resp = HTTPBadRequest(request=request)
         resp.content_type = 'text/plain'
         resp.body = str(err)
         return resp
开发者ID:Nupta,项目名称:swift,代码行数:10,代码来源:server.py

示例8: HEAD

 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,代码行数:12,代码来源:server.py

示例9: PUT

 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,代码行数:47,代码来源:container.py

示例10: GET_scopes

    def GET_scopes(self, scope_str):
        """Retrieve descriptions of reddit's OAuth2 scopes.

        If no scopes are given, information on all scopes are returned.

        Invalid scope(s) will result in a 400 error with body that indicates
        the invalid scope(s).

        """
        scopes = OAuth2Scope(scope_str or self.THREE_SIXTY)
        if scope_str and not scopes.is_valid():
            invalid = [s for s in scopes.scopes if s not in scopes.scope_info]
            error = {"error": "invalid_scopes", "invalid_scopes": invalid}
            http_err = HTTPBadRequest()
            http_err.error_data = error
            abort(http_err)
        return self.api_wrapper({k: v for k, v in scopes.details() if k})
开发者ID:pra85,项目名称:reddit,代码行数:17,代码来源:scopes.py

示例11: PUT

 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,代码行数:20,代码来源:account.py

示例12: handle_upgrade

    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,代码行数:21,代码来源:view.py

示例13: handle_upgrade

    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,代码行数:23,代码来源:websocket.py

示例14: __init__

 def __init__(self, error):
     HTTPBadRequest.__init__(self)
     self.error_data = {
         'reason': error,
         'explanation': error_list[error],
     }
开发者ID:benmordecai,项目名称:reddit,代码行数:6,代码来源:errors.py

示例15: __init__

 def __init__(self, error_name):
     HTTPBadRequest.__init__(self)
     self.error_data = {"reason": error_name, "explanation": error_list[error_name]}
开发者ID:RGood,项目名称:reddit,代码行数:3,代码来源:errors.py


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