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


Python httplib.ACCEPTED属性代码示例

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


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

示例1: test_accepted_v1

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def test_accepted_v1(self):
        """Give the response an HTTP "ACCEPTED" status code.

        Call ``_handle_response`` twice:

        * Do not pass the ``synchronous`` argument.
        * Pass ``synchronous=False``.

        """
        response = mock.Mock()
        response.status_code = ACCEPTED
        response.headers = {'content-type': 'application/json'}
        for args in [response, 'foo'], [response, 'foo', False]:
            self.assertEqual(
                entities._handle_response(*args),
                response.json.return_value,
            )
            self.assertEqual(
                response.mock_calls,
                [mock.call.raise_for_status(), mock.call.json()],
            )
            response.reset_mock() 
开发者ID:SatelliteQE,项目名称:nailgun,代码行数:24,代码来源:test_entities.py

示例2: send

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def send(self, request):
        url = self.__get_request_url_for_urllib(request)
        msg = request.message
        headers = request.headers
        try:
            u2request = urllib2.Request(url, msg, headers)
            self.addcookies(u2request)
            self.proxy = self.options.proxy
            request.headers.update(u2request.headers)
            log.debug('sending:\n%s', request)
            fp = self.u2open(u2request, timeout=request.timeout)
            self.getcookies(fp, u2request)
            headers = fp.headers
            if sys.version_info < (3, 0):
                headers = headers.dict
            reply = Reply(httplib.OK, headers, fp.read())
            log.debug('received:\n%s', reply)
            return reply
        except urllib2.HTTPError as e:
            if e.code not in (httplib.ACCEPTED, httplib.NO_CONTENT):
                raise TransportError(e.msg, e.code, e.fp) 
开发者ID:suds-community,项目名称:suds,代码行数:23,代码来源:http.py

示例3: _do_request

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def _do_request(address, path):
    conn = httplib.HTTPConnection(address)
    conn.request('GET', path)
    res = conn.getresponse()
    if res.status in (httplib.OK,
                      httplib.CREATED,
                      httplib.ACCEPTED,
                      httplib.NO_CONTENT):
        return res

    raise httplib.HTTPException(
        res, 'code %d reason %s' % (res.status, res.reason),
        res.getheaders(), res.read()) 
开发者ID:OpenState-SDN,项目名称:ryu,代码行数:15,代码来源:proxy.py

示例4: test_accepted_v2

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def test_accepted_v2(self):
        """Give the response an HTTP "ACCEPTED" status code.

        Pass ``synchronous=True`` as an argument.

        """
        response = mock.Mock()
        response.status_code = ACCEPTED
        response.json.return_value = {'id': gen_integer()}
        with mock.patch.object(entities, 'ForemanTask') as foreman_task:
            self.assertEqual(
                foreman_task.return_value.poll.return_value,
                entities._handle_response(response, 'foo', True),
            ) 
开发者ID:SatelliteQE,项目名称:nailgun,代码行数:16,代码来源:test_entities.py

示例5: post_init_error

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def post_init_error(self, error_response_data):
        endpoint = self.init_error_endpoint
        self.runtime_connection.request("POST", endpoint, error_response_data)
        response = self.runtime_connection.getresponse()
        response_body = response.read()

        if response.status != httplib.ACCEPTED:
            raise LambdaRuntimeClientError(endpoint, response.status, response_body) 
开发者ID:triggermesh,项目名称:knative-lambda-runtime,代码行数:10,代码来源:lambda_runtime_client.py

示例6: post_invocation_result

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def post_invocation_result(self, invoke_id, result_data):
        endpoint = self.response_endpoint.format(invoke_id)
        self.runtime_connection.request("POST", endpoint, result_data)
        response = self.runtime_connection.getresponse()
        response_body = response.read()

        if response.status != httplib.ACCEPTED:
            raise LambdaRuntimeClientError(endpoint, response.status, response_body) 
开发者ID:triggermesh,项目名称:knative-lambda-runtime,代码行数:10,代码来源:lambda_runtime_client.py

示例7: post_invocation_error

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def post_invocation_error(self, invoke_id, error_response_data):
        endpoint = self.error_response_endpoint.format(invoke_id)
        self.runtime_connection.request("POST", endpoint, error_response_data)
        response = self.runtime_connection.getresponse()
        response_body = response.read()

        if response.status != httplib.ACCEPTED:
            raise LambdaRuntimeClientError(endpoint, response.status, response_body) 
开发者ID:triggermesh,项目名称:knative-lambda-runtime,代码行数:10,代码来源:lambda_runtime_client.py

示例8: get_access_token

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def get_access_token(self, KeyVaultResourceName, AuthorizeUri, AADClientID, AADClientCertThumbprint, AADClientSecret):
        if not AADClientSecret and not AADClientCertThumbprint:
            raise ValueError("Missing Credentials.  Either AADClientSecret or AADClientCertThumbprint must be specified")

        if AADClientSecret and AADClientCertThumbprint:
            raise ValueError("Both AADClientSecret and AADClientCertThumbprint were supplied, when only one of these was expected.")

        if AADClientCertThumbprint:
            return self.get_access_token_with_certificate(KeyVaultResourceName, AuthorizeUri, AADClientID, AADClientCertThumbprint)
        else:
            # retrieve access token directly, adal library not required
            token_uri = AuthorizeUri + "/oauth2/token"
            request_content = "resource=" + urllib.quote(KeyVaultResourceName) + "&client_id=" + AADClientID + "&client_secret=" + urllib.quote(AADClientSecret) + "&grant_type=client_credentials"
            headers = {}
            http_util = HttpUtil(self.logger)
            result = http_util.Call(method='POST', http_uri=token_uri, data=request_content, headers=headers)

            self.logger.log("{0} {1}".format(result.status, result.getheaders()))
            result_content = result.read()
            if result.status != httplib.OK and result.status != httplib.ACCEPTED:
                self.logger.log(str(result_content))
                return None
            http_util.connection.close()

            result_json = json.loads(result_content)
            access_token = result_json["access_token"]
            return access_token 
开发者ID:Azure,项目名称:azure-linux-extensions,代码行数:29,代码来源:KeyVaultUtil.py

示例9: encrypt_passphrase

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def encrypt_passphrase(self, AccessToken, Passphrase, KeyVaultURL, KeyEncryptionKeyURL, AADClientID, KeyEncryptionAlgorithm, AADClientSecret):
        try:
            """
            wrap our passphrase using the encryption key
            api ref for wrapkey: https://msdn.microsoft.com/en-us/library/azure/dn878066.aspx
            """
            self.logger.log("encrypting the secret using key: " + KeyEncryptionKeyURL)

            request_content = '{"alg":"' + str(KeyEncryptionAlgorithm) + '","value":"' + str(Passphrase) + '"}'
            headers = {}
            headers["Content-Type"] = "application/json"
            headers["Authorization"] = "Bearer " + str(AccessToken)
            relative_path = KeyEncryptionKeyURL + "/wrapkey" + '?api-version=' + self.api_version
            http_util = HttpUtil(self.logger)
            result = http_util.Call(method='POST', http_uri=relative_path, data=request_content, headers=headers)

            result_content = result.read()
            self.logger.log("result_content is: {0}".format(result_content))
            self.logger.log("{0} {1}".format(result.status, result.getheaders()))
            if result.status != httplib.OK and result.status != httplib.ACCEPTED:
                return None
            http_util.connection.close()
            result_json = json.loads(result_content)
            secret_value = result_json[u'value']
            return secret_value
        except Exception as e:
            self.logger.log("Failed to encrypt_passphrase with error: {0}, stack trace: %s".format(e, traceback.format_exc()))
            return None 
开发者ID:Azure,项目名称:azure-linux-extensions,代码行数:30,代码来源:KeyVaultUtil.py

示例10: create_secret

# 需要导入模块: import httplib [as 别名]
# 或者: from httplib import ACCEPTED [as 别名]
def create_secret(self, AccessToken, KeyVaultURL, secret_value, KeyEncryptionAlgorithm, DiskEncryptionKeyFileName):
        """
        create secret api https://msdn.microsoft.com/en-us/library/azure/dn903618.aspx
        https://mykeyvault.vault.azure.net/secrets/{secret-name}?api-version={api-version}
        """
        try:
            secret_name = str(uuid.uuid4())
            secret_keyvault_uri = self.urljoin(KeyVaultURL, "secrets", secret_name)
            self.logger.log("secret_keyvault_uri is: {0} and keyvault_uri is:{1}".format(secret_keyvault_uri, KeyVaultURL))
            if KeyEncryptionAlgorithm is None:
                request_content = '{{"value":"{0}","attributes":{{"enabled":"true"}},"tags":{{"DiskEncryptionKeyFileName":"{1}"}}}}'\
                    .format(str(secret_value), DiskEncryptionKeyFileName)
            else:
                request_content = '{{"value":"{0}","attributes":{{"enabled":"true"}},"tags":{{"DiskEncryptionKeyEncryptionAlgorithm":"{1}","DiskEncryptionKeyFileName":"{2}"}}}}'\
                    .format(str(secret_value), KeyEncryptionAlgorithm, DiskEncryptionKeyFileName)
            http_util = HttpUtil(self.logger)
            headers = {}
            headers["Content-Type"] = "application/json"
            headers["Authorization"] = "Bearer " + AccessToken
            result = http_util.Call(method='PUT', http_uri=secret_keyvault_uri + '?api-version=' + self.api_version, data=request_content, headers=headers)

            self.logger.log("{0} {1}".format(result.status, result.getheaders()))
            result_content = result.read()
            # Do NOT log the result_content. It contains the uploaded secret and we don't want that in the logs.
            result_json = json.loads(result_content)
            secret_id = result_json["id"]
            http_util.connection.close()
            if result.status != httplib.OK and result.status != httplib.ACCEPTED:
                self.logger.log("the result status failed.")
                return None
            return secret_id
        except Exception as e:
            self.logger.log("Failed to create_secret with error: {0}, stack trace: {1}".format(e, traceback.format_exc()))
            return None 
开发者ID:Azure,项目名称:azure-linux-extensions,代码行数:36,代码来源:KeyVaultUtil.py


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