當前位置: 首頁>>代碼示例>>Python>>正文


Python httplib2.Response方法代碼示例

本文整理匯總了Python中httplib2.Response方法的典型用法代碼示例。如果您正苦於以下問題:Python httplib2.Response方法的具體用法?Python httplib2.Response怎麽用?Python httplib2.Response使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在httplib2的用法示例。


在下文中一共展示了httplib2.Response方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: set_data

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def set_data(self, r_code, enc=None, r_body=None, absolute_limit=True):
        if enc is None:
            enc = self.c_type
        resp_dict = {'status': r_code, 'content-type': enc}
        resp_body = {'resp_body': 'fake_resp_body'}

        if absolute_limit is False:
            resp_dict.update({'retry-after': 120})
            resp_body.update({'overLimit': {'message': 'fake_message'}})
        resp = httplib2.Response(resp_dict)
        data = {
            "method": "fake_method",
            "url": "fake_url",
            "headers": "fake_headers",
            "body": "fake_body",
            "resp": resp,
            "resp_body": json.dumps(resp_body)
        }
        if r_body is not None:
            data.update({"resp_body": r_body})
        return data 
開發者ID:openstack,項目名稱:tempest-lib,代碼行數:23,代碼來源:test_rest_client.py

示例2: request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def request(self, uri, method="GET", body=None, headers=None,
                redirections=5, connection_type=None):
        if not self.return_type:
            fake_headers = httplib2.Response(headers)
            return_obj = {
                'uri': uri,
                'method': method,
                'body': body,
                'headers': headers
            }
            return (fake_headers, return_obj)
        elif isinstance(self.return_type, int):
            body = body or "fake_body"
            header_info = {
                'content-type': 'text/plain',
                'status': str(self.return_type),
                'content-length': len(body)
            }
            resp_header = httplib2.Response(header_info)
            return (resp_header, body)
        else:
            msg = "unsupported return type %s" % self.return_type
            raise TypeError(msg) 
開發者ID:openstack,項目名稱:tempest-lib,代碼行數:25,代碼來源:fake_http.py

示例3: request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def request(self, uri,
              method='GET',
              body=None,
              headers=None,
              redirections=1,
              connection_type=None):
    resp, content = self._iterable.pop(0)
    if content == 'echo_request_headers':
      content = headers
    elif content == 'echo_request_headers_as_json':
      content = simplejson.dumps(headers)
    elif content == 'echo_request_body':
      if hasattr(body, 'read'):
        content = body.read()
      else:
        content = body
    elif content == 'echo_request_uri':
      content = uri
    return httplib2.Response(resp), content 
開發者ID:splunk,項目名稱:splunk-ref-pas-code,代碼行數:21,代碼來源:http.py

示例4: test_http_error

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_http_error(self, mock_hook):
        http_error_code = 403
        hook_instance = mock_hook.return_value
        hook_instance.create_job.side_effect = HttpError(
            resp=httplib2.Response({
                'status': http_error_code
            }),
            content=b'Forbidden')

        with self.assertRaises(HttpError) as context:
            training_op = MLEngineStartTrainingJobOperator(
                **self.TRAINING_DEFAULT_ARGS)
            training_op.execute(None)

        mock_hook.assert_called_once_with(
            gcp_conn_id='google_cloud_default', delegate_to=None)
        # Make sure only 'create_job' is invoked on hook instance
        self.assertEqual(len(hook_instance.mock_calls), 1)
        hook_instance.create_job.assert_called_once_with(
            project_id='test-project', job=self.TRAINING_INPUT, use_existing_job_fn=ANY)
        self.assertEqual(http_error_code, context.exception.resp.status) 
開發者ID:apache,項目名稱:airflow,代碼行數:23,代碼來源:test_mlengine.py

示例5: test_successful_copy_template

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_successful_copy_template(self, mock_hook):
        mock_hook.return_value.get_instance_template.side_effect = [
            HttpError(resp=httplib2.Response({'status': 404}), content=EMPTY_CONTENT),
            GCE_INSTANCE_TEMPLATE_BODY_GET,
            GCE_INSTANCE_TEMPLATE_BODY_GET_NEW
        ]
        op = ComputeEngineCopyInstanceTemplateOperator(
            project_id=GCP_PROJECT_ID,
            resource_id=GCE_INSTANCE_TEMPLATE_NAME,
            task_id='id',
            body_patch={"name": GCE_INSTANCE_TEMPLATE_NEW_NAME}
        )
        result = op.execute(None)
        mock_hook.assert_called_once_with(api_version='v1',
                                          gcp_conn_id='google_cloud_default')
        mock_hook.return_value.insert_instance_template.assert_called_once_with(
            project_id=GCP_PROJECT_ID,
            body=GCE_INSTANCE_TEMPLATE_BODY_INSERT,
            request_id=None
        )
        self.assertEqual(GCE_INSTANCE_TEMPLATE_BODY_GET_NEW, result) 
開發者ID:apache,項目名稱:airflow,代碼行數:23,代碼來源:test_compute.py

示例6: test_successful_copy_template_missing_project_id

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_successful_copy_template_missing_project_id(self, mock_hook):
        mock_hook.return_value.get_instance_template.side_effect = [
            HttpError(resp=httplib2.Response({'status': 404}), content=EMPTY_CONTENT),
            GCE_INSTANCE_TEMPLATE_BODY_GET,
            GCE_INSTANCE_TEMPLATE_BODY_GET_NEW
        ]
        op = ComputeEngineCopyInstanceTemplateOperator(
            resource_id=GCE_INSTANCE_TEMPLATE_NAME,
            task_id='id',
            body_patch={"name": GCE_INSTANCE_TEMPLATE_NEW_NAME}
        )
        result = op.execute(None)
        mock_hook.assert_called_once_with(api_version='v1',
                                          gcp_conn_id='google_cloud_default')
        mock_hook.return_value.insert_instance_template.assert_called_once_with(
            project_id=None,
            body=GCE_INSTANCE_TEMPLATE_BODY_INSERT,
            request_id=None
        )
        self.assertEqual(GCE_INSTANCE_TEMPLATE_BODY_GET_NEW, result) 
開發者ID:apache,項目名稱:airflow,代碼行數:22,代碼來源:test_compute.py

示例7: test_successful_copy_template_with_request_id

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_successful_copy_template_with_request_id(self, mock_hook):
        mock_hook.return_value.get_instance_template.side_effect = [
            HttpError(resp=httplib2.Response({'status': 404}), content=EMPTY_CONTENT),
            GCE_INSTANCE_TEMPLATE_BODY_GET,
            GCE_INSTANCE_TEMPLATE_BODY_GET_NEW
        ]
        op = ComputeEngineCopyInstanceTemplateOperator(
            project_id=GCP_PROJECT_ID,
            resource_id=GCE_INSTANCE_TEMPLATE_NAME,
            request_id=GCE_INSTANCE_TEMPLATE_REQUEST_ID,
            task_id='id',
            body_patch={"name": GCE_INSTANCE_TEMPLATE_NEW_NAME}
        )
        result = op.execute(None)
        mock_hook.assert_called_once_with(api_version='v1',
                                          gcp_conn_id='google_cloud_default')
        mock_hook.return_value.insert_instance_template.assert_called_once_with(
            project_id=GCP_PROJECT_ID,
            body=GCE_INSTANCE_TEMPLATE_BODY_INSERT,
            request_id=GCE_INSTANCE_TEMPLATE_REQUEST_ID,
        )
        self.assertEqual(GCE_INSTANCE_TEMPLATE_BODY_GET_NEW, result) 
開發者ID:apache,項目名稱:airflow,代碼行數:24,代碼來源:test_compute.py

示例8: test_missing_name

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_missing_name(self, mock_hook):
        mock_hook.return_value.get_instance_template.side_effect = [
            HttpError(resp=httplib2.Response({'status': 404}), content=EMPTY_CONTENT),
            GCE_INSTANCE_TEMPLATE_BODY_GET,
            GCE_INSTANCE_TEMPLATE_BODY_GET_NEW
        ]
        with self.assertRaises(AirflowException) as cm:
            op = ComputeEngineCopyInstanceTemplateOperator(
                project_id=GCP_PROJECT_ID,
                resource_id=GCE_INSTANCE_TEMPLATE_NAME,
                request_id=GCE_INSTANCE_TEMPLATE_REQUEST_ID,
                task_id='id',
                body_patch={"description": "New description"}
            )
            op.execute(None)
        err = cm.exception
        self.assertIn("should contain at least name for the new operator "
                      "in the 'name' field", str(err))
        mock_hook.assert_not_called() 
開發者ID:apache,項目名稱:airflow,代碼行數:21,代碼來源:test_compute.py

示例9: test_bad_request_subscription

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_bad_request_subscription():
    with patch.object(googleplay.GooglePlayVerifier, "_authorize", return_value=None):
        verifier = GooglePlayVerifier("bundle_id", "private_key_path")

        auth = HttpMock(datafile("androidpublisher.json"), headers={"status": 200})

        request_mock_builder = RequestMockBuilder(
            {
                "androidpublisher.purchases.subscriptions.get": (
                    httplib2.Response({"status": 400, "reason": b"Bad request"}),
                    b'{"reason": "Bad request"}',
                )
            }
        )
        build_mock_result = googleplay.build("androidpublisher", "v3", http=auth, requestBuilder=request_mock_builder)

        with patch.object(googleplay, "build", return_value=build_mock_result):
            with pytest.raises(errors.GoogleError, match="Bad request"):
                verifier.verify("broken_purchase_token", "product_scu", is_subscription=True) 
開發者ID:dotpot,項目名稱:InAppPy,代碼行數:21,代碼來源:test_google_verifier.py

示例10: test_bad_request_product

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_bad_request_product():
    with patch.object(googleplay.GooglePlayVerifier, "_authorize", return_value=None):
        verifier = GooglePlayVerifier("bundle_id", "private_key_path")

        auth = HttpMock(datafile("androidpublisher.json"), headers={"status": 200})

        request_mock_builder = RequestMockBuilder(
            {
                "androidpublisher.purchases.products.get": (
                    httplib2.Response({"status": 400, "reason": b"Bad request"}),
                    b'{"reason": "Bad request"}',
                )
            }
        )
        build_mock_result = googleplay.build("androidpublisher", "v3", http=auth, requestBuilder=request_mock_builder)

        with patch.object(googleplay, "build", return_value=build_mock_result):
            with pytest.raises(errors.GoogleError, match="Bad request"):
                verifier.verify("broken_purchase_token", "product_scu") 
開發者ID:dotpot,項目名稱:InAppPy,代碼行數:21,代碼來源:test_google_verifier.py

示例11: request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def request(
        self, uri, method="GET", body=None, headers=None, redirections=5, connection_type=None
    ):
        for expected_uri, expected_method, result in EXPECTED_RESULTS:
            if re.match(expected_uri, uri) and method == expected_method:
                return (httplib2.Response({'status': '200'}), seven.json.dumps(result).encode())

        # Pass this one through since its the entire JSON schema used for dynamic object creation
        if uri == DATAPROC_SCHEMA_URI:
            response, content = super(HttpSnooper, self).request(
                uri,
                method=method,
                body=body,
                headers=headers,
                redirections=redirections,
                connection_type=connection_type,
            )
            return response, content 
開發者ID:dagster-io,項目名稱:dagster,代碼行數:20,代碼來源:test_resources.py

示例12: __init__

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def __init__(self, resp, content, postproc):
    """Constructor for HttpRequestMock

    Args:
      resp: httplib2.Response, the response to emulate coming from the request
      content: string, the response body
      postproc: callable, the post processing function usually supplied by
                the model class. See model.JsonModel.response() as an example.
    """
    self.resp = resp
    self.content = content
    self.postproc = postproc
    if resp is None:
      self.resp = httplib2.Response({'status': 200, 'reason': 'OK'})
    if 'reason' in self.resp:
      self.resp.reason = self.resp['reason'] 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:18,代碼來源:http.py

示例13: request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def request(self, uri,
              method='GET',
              body=None,
              headers=None,
              redirections=1,
              connection_type=None):
    resp, content = self._iterable.pop(0)
    if content == 'echo_request_headers':
      content = headers
    elif content == 'echo_request_headers_as_json':
      content = json.dumps(headers)
    elif content == 'echo_request_body':
      if hasattr(body, 'read'):
        content = body.read()
      else:
        content = body
    elif content == 'echo_request_uri':
      content = uri
    if isinstance(content, six.text_type):
      content = content.encode('utf-8')
    return httplib2.Response(resp), content 
開發者ID:fniephaus,項目名稱:alfred-gmail,代碼行數:23,代碼來源:http.py

示例14: request

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def request(self, uri,
              method='GET',
              body=None,
              headers=None,
              redirections=1,
              connection_type=None):
    self.requests_made.append(self.HttpCall(uri, method, body, headers))
    headers = None
    body = None
    for candidate in self._uris:
      if candidate[0].match(uri):
        _, headers, body = candidate
        break
    if not headers:
      raise AssertionError("Unexpected request to %s" % uri)
    return httplib2.Response(headers), body 
開發者ID:luci,項目名稱:luci-py,代碼行數:18,代碼來源:httplib2_utils.py

示例15: test_directory_api_insert_role__errors

# 需要導入模塊: import httplib2 [as 別名]
# 或者: from httplib2 import Response [as 別名]
def test_directory_api_insert_role__errors(
      self, error_code, expected_error):
    """Test the insert_role API method for the Google Admin Directory API."""
    test_directory_api = directory.DirectoryAPI(self.config, mock.Mock())
    test_directory_api._client.roles.side_effect = errors.HttpError(
        httplib2.Response({
            'reason': 'NOT USED', 'status': error_code}),
        'NOT USED.'.encode(encoding='UTF-8'))
    with self.assertRaises(expected_error):
      test_directory_api.insert_role() 
開發者ID:google,項目名稱:loaner,代碼行數:12,代碼來源:directory_test.py


注:本文中的httplib2.Response方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。