# Path: magnumclient/common/apiclient/exceptions.py
# class GatewayTimeout(HttpServerError):
#     """HTTP 504 - Gateway Timeout.
# 
#     The server was acting as a gateway or proxy and did not receive a timely
#     response from the upstream server.
#     """
#     http_status = 504
#     message = _("Gateway Timeout")
# 
# Path: magnumclient/common/apiclient/exceptions.py
# class MultipleChoices(HTTPRedirection):
#     """HTTP 300 - Multiple Choices.
# 
#     Indicates multiple options for the resource that the client may follow.
#     """
# 
#     http_status = 300
#     message = _("Multiple Choices")
# 
# Path: magnumclient/common/httpclient.py
# LOG = logging.getLogger(__name__)
# USER_AGENT = 'python-magnumclient'
# CHUNKSIZE = 1024 * 64  # 64kB
# API_VERSION = '/v1'
# DEFAULT_API_VERSION = 'latest'
# def _extract_error_json_text(body_json):
# def _extract_error_json(body, resp):
#     def __init__(self, endpoint, api_version=DEFAULT_API_VERSION, **kwargs):
#     def get_connection_params(endpoint, **kwargs):
#     def get_connection(self):
#     def log_curl_request(self, method, url, kwargs):
#     def log_http_response(resp, body=None):
#     def _make_connection_url(self, url):
#     def _http_request(self, url, method, **kwargs):
#     def json_request(self, method, url, **kwargs):
#     def raw_request(self, method, url, **kwargs):
#     def __init__(self, host, port, key_file=None, cert_file=None,
#                  ca_file=None, timeout=None, insecure=False):
#     def connect(self):
#     def get_system_ca_file():
#     def __init__(self, user_agent=USER_AGENT, logger=LOG,
#                  api_version=DEFAULT_API_VERSION, *args, **kwargs):
#     def _http_request(self, url, method, **kwargs):
#     def json_request(self, method, url, **kwargs):
#     def raw_request(self, method, url, **kwargs):
#     def __init__(self, resp):
#     def __iter__(self):
#     def __bool__(self):
#     def next(self):
# def _construct_http_client(*args, **kwargs):
# class HTTPClient(object):
# class VerifiedHTTPSConnection(http_client.HTTPSConnection):
# class SessionClient(adapter.LegacyJsonAdapter):
# class ResponseBodyIterator(object):
# 
# Path: magnumclient/exceptions.py
# class AmbiguousAuthSystem(exceptions.ClientException):
# class InvalidAttribute(exceptions.ClientException):
# def from_response(response, message=None, traceback=None, method=None,
#                   url=None):
# 
# Path: magnumclient/tests/utils.py
# FAKE_ENV = {'OS_USERNAME': 'username',
#             'OS_PASSWORD': 'password',
#             'OS_PROJECT_NAME': 'project_name',
#             'OS_AUTH_URL': 'http://no.where/v2.0'}
#     TEST_REQUEST_BASE = {
#         'verify': True,
#     }
# class BaseTestCase(testtools.TestCase):
# class FakeAPI(object):
# class FakeConnection(object):
# class FakeResponse(object):
# class FakeServiceCatalog(object):
# class FakeKeystone(object):
# class TestCase(testtools.TestCase):
# class FakeSessionResponse(object):
# class FakeSession(object):
#     def setUp(self):
#     def __init__(self, responses):
#     def _request(self, method, url, headers=None, body=None):
#     def raw_request(self, *args, **kwargs):
#     def json_request(self, *args, **kwargs):
#     def __init__(self, response=None, **kwargs):
#     def request(self, method, conn_url, **kwargs):
#     def setresponse(self, response):
#     def getresponse(self):
#     def __init__(self, headers, body=None, version=None, status=None,
#                  reason=None):
#     def __getitem__(self, key):
#     def getheaders(self):
#     def getheader(self, key, default):
#     def read(self, amt):
#     def url_for(self, endpoint_type, service_type, attr=None,
#                 filter_value=None):
#     def __init__(self, auth_token):
#     def setUp(self):
#     def make_env(self, exclude=None, fake_env=FAKE_ENV):
#     def shell(self, argstr, exitcodes=(0,)):
#     def __init__(self, headers, content=None, status_code=None):
#     def json(self):
#     def __init__(self, headers, content=None, status_code=None):
#     def request(self, url, method, **kwargs):


from http import client as http_client
from unittest import mock
from oslo_serialization import jsonutils
from magnumclient.common.apiclient.exceptions import GatewayTimeout
from magnumclient.common.apiclient.exceptions import MultipleChoices
from magnumclient.common import httpclient as http
from magnumclient import exceptions as exc
from magnumclient.tests import utils
import io
import socket
        self.assertEqual(jsonutils.dumps(body), err)

    def test_raw_request(self):
        fake_resp = utils.FakeResponse(
            {'content-type': 'application/octet-stream'},
            'bar', version=1, status=200)
        client = http.HTTPClient('http://localhost/')
        conn = utils.FakeConnection(fake_resp)
        client.get_connection = (lambda *a, **kw: conn)

        resp, body = client.raw_request('GET', '/v1/resources')

        self.assertEqual(resp, fake_resp)
        self.assertIsInstance(body, http.ResponseBodyIterator)


class SessionClientTest(utils.BaseTestCase):

    def test_server_exception_msg_and_traceback(self):
        error_msg = 'another test error'
        error_trace = ("\"Traceback (most recent call last):\\n\\n  "
                       "File \\\"/usr/local/lib/python2.7/...")
        error_body = _get_error_body(error_msg, error_trace)

        fake_session = utils.FakeSession({'Content-Type': 'application/json'},
                                         error_body,
                                         500)

        client = http.SessionClient(session=fake_session)


# Path: magnumclient/common/apiclient/exceptions.py
# class GatewayTimeout(HttpServerError):
#     """HTTP 504 - Gateway Timeout.
# 
#     The server was acting as a gateway or proxy and did not receive a timely
#     response from the upstream server.
#     """
#     http_status = 504
#     message = _("Gateway Timeout")
# 
# Path: magnumclient/common/apiclient/exceptions.py
# class MultipleChoices(HTTPRedirection):
#     """HTTP 300 - Multiple Choices.
# 
#     Indicates multiple options for the resource that the client may follow.
#     """
# 
#     http_status = 300
#     message = _("Multiple Choices")
# 
# Path: magnumclient/common/httpclient.py
# LOG = logging.getLogger(__name__)
# USER_AGENT = 'python-magnumclient'
# CHUNKSIZE = 1024 * 64  # 64kB
# API_VERSION = '/v1'
# DEFAULT_API_VERSION = 'latest'
# def _extract_error_json_text(body_json):
# def _extract_error_json(body, resp):
#     def __init__(self, endpoint, api_version=DEFAULT_API_VERSION, **kwargs):
#     def get_connection_params(endpoint, **kwargs):
#     def get_connection(self):
#     def log_curl_request(self, method, url, kwargs):
#     def log_http_response(resp, body=None):
#     def _make_connection_url(self, url):
#     def _http_request(self, url, method, **kwargs):
#     def json_request(self, method, url, **kwargs):
#     def raw_request(self, method, url, **kwargs):
#     def __init__(self, host, port, key_file=None, cert_file=None,
#                  ca_file=None, timeout=None, insecure=False):
#     def connect(self):
#     def get_system_ca_file():
#     def __init__(self, user_agent=USER_AGENT, logger=LOG,
#                  api_version=DEFAULT_API_VERSION, *args, **kwargs):
#     def _http_request(self, url, method, **kwargs):
#     def json_request(self, method, url, **kwargs):
#     def raw_request(self, method, url, **kwargs):
#     def __init__(self, resp):
#     def __iter__(self):
#     def __bool__(self):
#     def next(self):
# def _construct_http_client(*args, **kwargs):
# class HTTPClient(object):
# class VerifiedHTTPSConnection(http_client.HTTPSConnection):
# class SessionClient(adapter.LegacyJsonAdapter):
# class ResponseBodyIterator(object):
# 
# Path: magnumclient/exceptions.py
# class AmbiguousAuthSystem(exceptions.ClientException):
# class InvalidAttribute(exceptions.ClientException):
# def from_response(response, message=None, traceback=None, method=None,
#                   url=None):
# 
# Path: magnumclient/tests/utils.py
# FAKE_ENV = {'OS_USERNAME': 'username',
#             'OS_PASSWORD': 'password',
#             'OS_PROJECT_NAME': 'project_name',
#             'OS_AUTH_URL': 'http://no.where/v2.0'}
#     TEST_REQUEST_BASE = {
#         'verify': True,
#     }
# class BaseTestCase(testtools.TestCase):
# class FakeAPI(object):
# class FakeConnection(object):
# class FakeResponse(object):
# class FakeServiceCatalog(object):
# class FakeKeystone(object):
# class TestCase(testtools.TestCase):
# class FakeSessionResponse(object):
# class FakeSession(object):
#     def setUp(self):
#     def __init__(self, responses):
#     def _request(self, method, url, headers=None, body=None):
#     def raw_request(self, *args, **kwargs):
#     def json_request(self, *args, **kwargs):
#     def __init__(self, response=None, **kwargs):
#     def request(self, method, conn_url, **kwargs):
#     def setresponse(self, response):
#     def getresponse(self):
#     def __init__(self, headers, body=None, version=None, status=None,
#                  reason=None):
#     def __getitem__(self, key):
#     def getheaders(self):
#     def getheader(self, key, default):
#     def read(self, amt):
#     def url_for(self, endpoint_type, service_type, attr=None,
#                 filter_value=None):
#     def __init__(self, auth_token):
#     def setUp(self):
#     def make_env(self, exclude=None, fake_env=FAKE_ENV):
#     def shell(self, argstr, exitcodes=(0,)):
#     def __init__(self, headers, content=None, status_code=None):
#     def json(self):
#     def __init__(self, headers, content=None, status_code=None):
#     def request(self, url, method, **kwargs):


# Path: magnumclient/tests/test_httpclient.py
from http import client as http_client
from unittest import mock
from oslo_serialization import jsonutils
from magnumclient.common.apiclient.exceptions import GatewayTimeout
from magnumclient.common.apiclient.exceptions import MultipleChoices
from magnumclient.common import httpclient as http
from magnumclient import exceptions as exc
from magnumclient.tests import utils
import io
import socket

        self.assertEqual(jsonutils.dumps(body), err)

    def test_raw_request(self):
        fake_resp = utils.FakeResponse(
            {'content-type': 'application/octet-stream'},
            'bar', version=1, status=200)
        client = http.HTTPClient('http://localhost/')
        conn = utils.FakeConnection(fake_resp)
        client.get_connection = (lambda *a, **kw: conn)

        resp, body = client.raw_request('GET', '/v1/resources')

        self.assertEqual(resp, fake_resp)
        self.assertIsInstance(body, http.ResponseBodyIterator)


class SessionClientTest(utils.BaseTestCase):

    def test_server_exception_msg_and_traceback(self):
        error_msg = 'another test error'
        error_trace = ("\"Traceback (most recent call last):\\n\\n  "
                       "File \\\"/usr/local/lib/python2.7/...")
        error_body = _get_error_body(error_msg, error_trace)

        fake_session = utils.FakeSession({'Content-Type': 'application/json'},
                                         error_body,
                                         500)

        client = http.SessionClient(session=fake_session)


        error = self.assertRaises(exc.InternalServerError,