# Path: glanceclient/common/http.py
# LOG = logging.getLogger(__name__)
# USER_AGENT = 'python-glanceclient'
# CHUNKSIZE = 1024 * 64  # 64kB
# REQ_ID_HEADER = 'X-OpenStack-Request-ID'
# TOKEN_HEADERS = ['X-Auth-Token', 'X-Service-Token']
# def encode_headers(headers):
#     def _chunk_body(body):
#     def _set_common_request_kwargs(self, headers, kwargs):
#     def _handle_response(self, resp):
#     def __init__(self, endpoint, **kwargs):
#     def __del__(self):
#     def parse_endpoint(endpoint):
#     def log_curl_request(self, method, url, headers, data, kwargs):
#     def log_http_response(resp):
#     def _request(self, method, url, **kwargs):
#     def head(self, url, **kwargs):
#     def get(self, url, **kwargs):
#     def post(self, url, **kwargs):
#     def put(self, url, **kwargs):
#     def patch(self, url, **kwargs):
#     def delete(self, url, **kwargs):
# def _close_after_stream(response, chunk_size):
#     def __init__(self, session, **kwargs):
#     def request(self, url, method, **kwargs):
# def get_http_client(endpoint=None, session=None, **kwargs):
# class _BaseHTTPClient(object):
# class HTTPClient(_BaseHTTPClient):
# class SessionClient(adapter.Adapter, _BaseHTTPClient):
# 
# Path: glanceclient/tests/utils.py
# class FakeAPI(object):
# class FakeSchemaAPI(FakeAPI):
# class RawRequest(object):
# class FakeResponse(object):
# class TestCase(testtools.TestCase):
# class FakeTTYStdout(io.StringIO):
# class FakeNoTTYStdout(FakeTTYStdout):
#     def __init__(self, fixtures):
#     def _request(self, method, url, headers=None, data=None,
#                  content_length=None):
#     def get(self, *args, **kwargs):
#     def post(self, *args, **kwargs):
#     def put(self, *args, **kwargs):
#     def patch(self, *args, **kwargs):
#     def delete(self, *args, **kwargs):
#     def head(self, *args, **kwargs):
#     def get(self, *args, **kwargs):
#     def __init__(self, headers, body=None,
#                  version=1.0, status=200, reason="Ok"):
#     def getheaders(self):
#     def getheader(self, key, default):
#     def read(self, amt):
#     def __init__(self, headers=None, body=None,
#                  version=1.0, status_code=200, reason="Ok"):
#     def status(self):
#     def ok(self):
#     def read(self, amt):
#     def close(self):
#     def content(self):
#     def text(self):
#     def json(self, **kwargs):
#     def iter_content(self, chunk_size=1, decode_unicode=False):
#     def release_conn(self, **kwargs):
#     def isatty(self):
#     def write(self, data):
#     def isatty(self):
# def sort_url_by_query_keys(url):
# def build_call_record(method, url, headers, data):
#     TEST_REQUEST_BASE = {
#         'config': {'danger_mode': False},
#         'verify': True}


import functools
import json
import logging
import uuid
import fixtures
import io
import requests
import testtools
import types
import glanceclient
from unittest import mock
from keystoneauth1 import session
from keystoneauth1 import token_endpoint
from oslo_utils import encodeutils
from requests_mock.contrib import fixture
from urllib import parse
from testscenarios import load_tests_apply_scenarios as load_tests  # noqa
from testtools import matchers
from glanceclient.common import http
from glanceclient.tests import utils
#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.




def original_only(f):
    @functools.wraps(f)
    def wrapper(self, *args, **kwargs):
        if not hasattr(self.client, 'log_curl_request'):
            self.skipTest('Skip logging tests for session client')

        return f(self, *args, **kwargs)


class TestClient(testtools.TestCase):

    scenarios = [
        ('httpclient', {'create_client': '_create_http_client'}),
        ('session', {'create_client': '_create_session_client'})
    ]

    def _create_http_client(self):
        return http.HTTPClient(self.endpoint, token=self.token)

    def _create_session_client(self):
        auth = token_endpoint.Token(self.endpoint, self.token)
        sess = session.Session(auth=auth)

# Path: glanceclient/common/http.py
# LOG = logging.getLogger(__name__)
# USER_AGENT = 'python-glanceclient'
# CHUNKSIZE = 1024 * 64  # 64kB
# REQ_ID_HEADER = 'X-OpenStack-Request-ID'
# TOKEN_HEADERS = ['X-Auth-Token', 'X-Service-Token']
# def encode_headers(headers):
#     def _chunk_body(body):
#     def _set_common_request_kwargs(self, headers, kwargs):
#     def _handle_response(self, resp):
#     def __init__(self, endpoint, **kwargs):
#     def __del__(self):
#     def parse_endpoint(endpoint):
#     def log_curl_request(self, method, url, headers, data, kwargs):
#     def log_http_response(resp):
#     def _request(self, method, url, **kwargs):
#     def head(self, url, **kwargs):
#     def get(self, url, **kwargs):
#     def post(self, url, **kwargs):
#     def put(self, url, **kwargs):
#     def patch(self, url, **kwargs):
#     def delete(self, url, **kwargs):
# def _close_after_stream(response, chunk_size):
#     def __init__(self, session, **kwargs):
#     def request(self, url, method, **kwargs):
# def get_http_client(endpoint=None, session=None, **kwargs):
# class _BaseHTTPClient(object):
# class HTTPClient(_BaseHTTPClient):
# class SessionClient(adapter.Adapter, _BaseHTTPClient):
# 
# Path: glanceclient/tests/utils.py
# class FakeAPI(object):
# class FakeSchemaAPI(FakeAPI):
# class RawRequest(object):
# class FakeResponse(object):
# class TestCase(testtools.TestCase):
# class FakeTTYStdout(io.StringIO):
# class FakeNoTTYStdout(FakeTTYStdout):
#     def __init__(self, fixtures):
#     def _request(self, method, url, headers=None, data=None,
#                  content_length=None):
#     def get(self, *args, **kwargs):
#     def post(self, *args, **kwargs):
#     def put(self, *args, **kwargs):
#     def patch(self, *args, **kwargs):
#     def delete(self, *args, **kwargs):
#     def head(self, *args, **kwargs):
#     def get(self, *args, **kwargs):
#     def __init__(self, headers, body=None,
#                  version=1.0, status=200, reason="Ok"):
#     def getheaders(self):
#     def getheader(self, key, default):
#     def read(self, amt):
#     def __init__(self, headers=None, body=None,
#                  version=1.0, status_code=200, reason="Ok"):
#     def status(self):
#     def ok(self):
#     def read(self, amt):
#     def close(self):
#     def content(self):
#     def text(self):
#     def json(self, **kwargs):
#     def iter_content(self, chunk_size=1, decode_unicode=False):
#     def release_conn(self, **kwargs):
#     def isatty(self):
#     def write(self, data):
#     def isatty(self):
# def sort_url_by_query_keys(url):
# def build_call_record(method, url, headers, data):
#     TEST_REQUEST_BASE = {
#         'config': {'danger_mode': False},
#         'verify': True}


# Path: glanceclient/tests/unit/test_http.py
import functools
import json
import logging
import uuid
import fixtures
import io
import requests
import testtools
import types
import glanceclient
from unittest import mock
from keystoneauth1 import session
from keystoneauth1 import token_endpoint
from oslo_utils import encodeutils
from requests_mock.contrib import fixture
from urllib import parse
from testscenarios import load_tests_apply_scenarios as load_tests  # noqa
from testtools import matchers
from glanceclient.common import http
from glanceclient.tests import utils

#    distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
#    WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
#    License for the specific language governing permissions and limitations
#    under the License.




def original_only(f):
    @functools.wraps(f)
    def wrapper(self, *args, **kwargs):
        if not hasattr(self.client, 'log_curl_request'):
            self.skipTest('Skip logging tests for session client')

        return f(self, *args, **kwargs)


class TestClient(testtools.TestCase):

    scenarios = [
        ('httpclient', {'create_client': '_create_http_client'}),
        ('session', {'create_client': '_create_session_client'})
    ]

    def _create_http_client(self):
        return http.HTTPClient(self.endpoint, token=self.token)

    def _create_session_client(self):
        auth = token_endpoint.Token(self.endpoint, self.token)
        sess = session.Session(auth=auth)

        return http.SessionClient(sess)