當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。