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


Python httplib.responses方法代码示例

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


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

示例1: serve_image

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def serve_image(self, environ, start_response):
    """Dynamically serve an image from blobstore."""
    blobkey, options = self._parse_path(environ['PATH_INFO'])
    # Make sure that the blob URL has been registered by
    # calling get_serving_url
    key = datastore.Key.from_path(_BLOB_SERVING_URL_KIND, blobkey, namespace='')
    try:
      datastore.Get(key)
    except datastore_errors.EntityNotFoundError:
      logging.error('The blobkey %s has not registered for image '
                    'serving. Please ensure get_serving_url is '
                    'called before attempting to serve blobs.', blobkey)
      start_response('404 %s' % httplib.responses[404], [])
      return []
    image, mime_type = self._transform_image(blobkey, options)
    start_response('200 OK', [
        ('Content-Type', mime_type),
        ('Cache-Control', 'public, max-age=600, no-transform')])
    return [image] 
开发者ID:elsigh,项目名称:browserscope,代码行数:21,代码来源:blob_image.py

示例2: __write_error

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def __write_error(self, status_code, error_message=None):
    """Return the HTTP status line and body for a given error code and message.

    Args:
      status_code: HTTP status code to be returned.
      error_message: Error message to be returned.

    Returns:
      Tuple (http_status, body):
        http_status: HTTP status line, e.g. 200 OK.
        body: Body of the HTTP request.
    """
    if error_message is None:
      error_message = httplib.responses[status_code]
    status = '%d %s' % (status_code, httplib.responses[status_code])
    message = EndpointsErrorMessage(
        state=EndpointsErrorMessage.State.APPLICATION_ERROR,
        error_message=error_message)
    return status, self.__PROTOJSON.encode_message(message) 
开发者ID:cloudendpoints,项目名称:endpoints-python,代码行数:21,代码来源:apiserving.py

示例3: write_headers

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def write_headers(self, start_line, headers, chunk=None, callback=None):
        """Write an HTTP header block.

        :arg start_line: a `.RequestStartLine` or `.ResponseStartLine`.
        :arg headers: a `.HTTPHeaders` instance.
        :arg chunk: the first (optional) chunk of data.  This is an optimization
            so that small responses can be written in the same call as their
            headers.
        :arg callback: a callback to be run when the write is complete.

        The ``version`` field of ``start_line`` is ignored.

        Returns a `.Future` if no callback is given.

        .. deprecated:: 5.1

           The ``callback`` argument is deprecated and will be removed
           in Tornado 6.0.
        """
        raise NotImplementedError() 
开发者ID:tp4a,项目名称:teleport,代码行数:22,代码来源:httputil.py

示例4: set_label

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def set_label(self, item,label, changed):
        if self.encode_password is None:
            return
        if not changed:
            return 
        try:
            bundle = {"label": {"external_id": self.encode(item), "text": self.encode(label)}}
            params = json.dumps(bundle)
            connection = httplib.HTTPConnection(self.target_host)
            connection.request("POST", ("/api/wallets/%s/labels.json?auth_token=%s" % (self.wallet_id, self.auth_token())), params, {'Content-Type': 'application/json'})

            response = connection.getresponse()
            if response.reason == httplib.responses[httplib.NOT_FOUND]:
                return
            response = json.loads(response.read())
        except socket.gaierror as e:
            print_error('Error connecting to service: %s ' %  e)
            return False 
开发者ID:mazaclub,项目名称:encompass,代码行数:20,代码来源:labels.py

示例5: _test_connectivity

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _test_connectivity(self, param):
        """
        Called when the user depresses the test connectivity button on the Phantom UI.
        Use a basic query to determine if the IP address, username and password is correct,
            curl -k -u admin:redacted -X GET https://192.0.2.1/mgmt/tm/ltm/
        """
        self.debug_print("%s TEST_CONNECTIVITY %s" % (F5_Connector.BANNER, param))

        config = self.get_config()
        host = config.get("device")
        F5 = iControl.BIG_IP(host=host,
                    username=config.get("username"),
                    password=config.get("password"),
                    uri="/mgmt/tm/sys/software/image",
                    method="GET")
        msg = "test connectivity to %s status_code: " % host

        if F5.genericGET():
            # True is success
            return self.set_status_save_progress(phantom.APP_SUCCESS, msg + "%s %s" % (F5.status_code, httplib.responses[F5.status_code]))
        else:
            # None or False, is a failure based on incorrect IP address, username, passords
            return self.set_status_save_progress(phantom.APP_ERROR, msg + "%s %s" % (F5.status_code, F5.response)) 
开发者ID:joelwking,项目名称:Phantom-Cyber,代码行数:25,代码来源:F5_connector.py

示例6: _test_connectivity

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _test_connectivity(self, param, LADS):
        """
        Called when the user depresses the test connectivity button on the Phantom UI.
        This query returns a list of configured applications
            https://api.a10networks.com/api/v2/applications
        """
        self.debug_print("%s _test_connectivity %s" % (A10_LADS_Connector.BANNER, param))

        msg = "test connectivity to %s status_code: " % (LADS.dashboard)

        if LADS.genericGET(uri="/api/v2/applications"):
            # True is success
            return self.set_status_save_progress(phantom.APP_SUCCESS, msg + "%s %s apps: %s" %
                   (LADS.status_code, httplib.responses[LADS.status_code], LADS.get_names(LADS.response)))
        else:
            # None or False, is a failure based on incorrect IP address, username, passords
            return self.set_status_save_progress(phantom.APP_ERROR, msg + "%s %s" % (LADS.status_code, LADS.response)) 
开发者ID:joelwking,项目名称:Phantom-Cyber,代码行数:19,代码来源:A10_LADS_Connector.py

示例7: _handle_request_exception

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _handle_request_exception(self, e):
        if isinstance(e, HTTPError):
            if e.log_message:
                format = "%d %s: " + e.log_message
                args = [e.status_code, self._request_summary()] + list(e.args)
                #logging.warning(format, *args)
                ht.logger.warning(format, *args)
            if e.status_code not in httplib.responses:
                #logging.error("Bad HTTP status code: %d", e.status_code)
                ht.logger.error("Bad HTTP status code: %d", e.status_code)
                self.send_error(500, exc_info=sys.exc_info())
            else:
                self.send_error(e.status_code, exc_info=sys.exc_info())
        else:
            #logging.error("Uncaught exception %s\n%r", self._request_summary(),
            #              self.request, exc_info=True)
            ht.logger.error("Uncaught exception %s\n%r", self._request_summary(),
                          self.request, exc_info=True)
            self.send_error(500, exc_info=sys.exc_info()) 
开发者ID:omererdem,项目名称:honeything,代码行数:21,代码来源:web.py

示例8: _in_progress_response

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _in_progress_response(start_response, ntlm_data=None,
                              client_id=None, cookie_name=None):
        status = "401 %s" % httplib.responses[401]
        content = "More data needed..."
        headers = [("Content-Type", "text/plain"),
                   ("Content-Length", "%d" % len(content))]
        if ntlm_data is None:
            www_auth_value = "NTLM"
        else:
            enc_ntlm_data = ntlm_data.encode("base64")
            www_auth_value = ("NTLM %s"
                              % enc_ntlm_data.strip().replace("\n", ""))

        if client_id is not None:
            # MUST occur when ntlm_data is None, can still occur otherwise
            headers.append(("Set-Cookie", "%s=%s" % (cookie_name, client_id)))

        headers.append(("WWW-Authenticate", www_auth_value))
        start_response(status, headers)

        return [content] 
开发者ID:byt3bl33d3r,项目名称:pth-toolkit,代码行数:23,代码来源:NTLMAuthHandler.py

示例9: test_handle_build_err

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_handle_build_err(self):
        # Special-cased above for testing.
        self.res.request = FakeHttpRequest('POST')
        settings.DEBUG = False
        self.addCleanup(setattr, settings, 'DEBUG', True)

        resp = self.res.handle('detail')
        self.assertEqual(resp['Content-Type'], 'application/json')
        self.assertEqual(resp.status_code, 500)
        self.assertEqual(resp.reason_phrase.title(), responses[500])
        self.assertEqual(json.loads(resp.content.decode('utf-8')), {
            'error': {
                'code': 'random-crazy',
                'message': 'This is a random & crazy exception.',
            }
        }) 
开发者ID:toastdriven,项目名称:restless,代码行数:18,代码来源:test_dj.py

示例10: _error_response

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def _error_response(self, environ, start_response, status):
    start_response('%d %s' % (status, httplib.responses[status]), [])
    return [] 
开发者ID:elsigh,项目名称:browserscope,代码行数:5,代码来源:server.py

示例11: __call__

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def __call__(self, environ, start_response):
    with self._lock:
      app = self._app
      error = self._error
    if app:
      return app(environ, start_response)
    else:
      start_response('%d %s' % (error, httplib.responses[error]), [])
      return [] 
开发者ID:elsigh,项目名称:browserscope,代码行数:11,代码来源:wsgi_server.py

示例12: test_not_get

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_not_get(self):
    """Tests POSTing to a url."""
    self._environ['REQUEST_METHOD'] = 'POST'
    self.assertResponse('405 %s' % httplib.responses[405], [], '', self.app,
                        self._environ) 
开发者ID:elsigh,项目名称:browserscope,代码行数:7,代码来源:blob_image_test.py

示例13: test_key_not_found

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_key_not_found(self):
    """Tests an image request for a key that doesn't exist."""
    self.expect_datatore_lookup('SomeBlobKey', False)
    self.mox.ReplayAll()
    self.assertResponse('404 %s' % httplib.responses[404], [], '', self.app,
                        self._environ) 
开发者ID:elsigh,项目名称:browserscope,代码行数:8,代码来源:blob_image_test.py

示例14: test_invalid_url

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def test_invalid_url(self):
    """Tests an image request with an invalid path."""
    self._environ['PATH_INFO'] = '/_ah/img/'
    self.mox.ReplayAll()
    self.assertResponse('400 %s' % httplib.responses[400], [], '', self.app,
                        self._environ) 
开发者ID:elsigh,项目名称:browserscope,代码行数:8,代码来源:blob_image_test.py

示例15: __call__

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import responses [as 别名]
def __call__(self, environ, start_response):
    if environ['REQUEST_METHOD'] != 'GET':
      start_response('405 %s' % httplib.responses[405], [])
      return []
    try:
      return self.serve_image(environ, start_response)
    except InvalidRequestError:
      start_response('400 %s' % httplib.responses[400], [])
      return [] 
开发者ID:elsigh,项目名称:browserscope,代码行数:11,代码来源:blob_image.py


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