# Path: ironicclient/common/filecache.py
# LOG = logging.getLogger(__name__)
# AUTHOR = 'openstack'
# PROGNAME = 'python-ironicclient'
# CACHE = None
# CACHE_DIR = appdirs.user_cache_dir(PROGNAME, AUTHOR)
# CACHE_EXPIRY_ENV_VAR = 'IRONICCLIENT_CACHE_EXPIRY'  # environment variable
# CACHE_FILENAME = os.path.join(CACHE_DIR, 'ironic-api-version.dbm')
# DEFAULT_EXPIRY = 300  # seconds
#         CACHE = dogpile.cache.make_region(key_mangler=str).configure(
#             'dogpile.cache.dbm',
#             expiration_time=expiry_time,
#             arguments={
#                 "filename": CACHE_FILENAME,
#             }
#         )
# def _get_cache():
# def _build_key(host, port):
# def save_data(host, port, data):
# def retrieve_data(host, port, expiry=None):
# 
# Path: ironicclient/common/i18n.py
# def _(msg):
#     return msg
# 
# Path: ironicclient/exc.py
# class AmbiguousAuthSystem(exceptions.ClientException):
# class InvalidAttribute(exceptions.ClientException):
# class StateTransitionFailed(exceptions.ClientException):
# class StateTransitionTimeout(exceptions.ClientException):
# def from_response(response, message=None, traceback=None, method=None,
#                   url=None):


from distutils.version import StrictVersion
from http import client as http_client
from urllib import parse as urlparse
from keystoneauth1 import adapter
from keystoneauth1 import exceptions as kexc
from ironicclient.common import filecache
from ironicclient.common.i18n import _
from ironicclient import exc
import functools
import json
import logging
import re
import textwrap
import time


def get_server(url):
    """Extract and return the server & port."""
    if url is None:
        return None, None
    parts = urlparse.urlparse(url)
    return parts.hostname, str(parts.port)


class VersionNegotiationMixin(object):
    def negotiate_version(self, conn, resp):
        """Negotiate the server version

        Assumption: Called after receiving a 406 error when doing a request.

        :param conn: A connection object
        :param resp: The response object from http request
        """
        def _query_server(conn):
            if (self.os_ironic_api_version
                    and not isinstance(self.os_ironic_api_version, list)
                    and self.os_ironic_api_version != 'latest'):
                base_version = ("/v%s" %
                                str(self.os_ironic_api_version).split('.')[0])
            else:
                base_version = API_VERSION
            # Raise exception on client or server error.
            resp = self._make_simple_request(conn, 'GET', base_version)
            if not resp.ok:

# Path: ironicclient/common/filecache.py
# LOG = logging.getLogger(__name__)
# AUTHOR = 'openstack'
# PROGNAME = 'python-ironicclient'
# CACHE = None
# CACHE_DIR = appdirs.user_cache_dir(PROGNAME, AUTHOR)
# CACHE_EXPIRY_ENV_VAR = 'IRONICCLIENT_CACHE_EXPIRY'  # environment variable
# CACHE_FILENAME = os.path.join(CACHE_DIR, 'ironic-api-version.dbm')
# DEFAULT_EXPIRY = 300  # seconds
#         CACHE = dogpile.cache.make_region(key_mangler=str).configure(
#             'dogpile.cache.dbm',
#             expiration_time=expiry_time,
#             arguments={
#                 "filename": CACHE_FILENAME,
#             }
#         )
# def _get_cache():
# def _build_key(host, port):
# def save_data(host, port, data):
# def retrieve_data(host, port, expiry=None):
# 
# Path: ironicclient/common/i18n.py
# def _(msg):
#     return msg
# 
# Path: ironicclient/exc.py
# class AmbiguousAuthSystem(exceptions.ClientException):
# class InvalidAttribute(exceptions.ClientException):
# class StateTransitionFailed(exceptions.ClientException):
# class StateTransitionTimeout(exceptions.ClientException):
# def from_response(response, message=None, traceback=None, method=None,
#                   url=None):


# Path: ironicclient/common/http.py
from distutils.version import StrictVersion
from http import client as http_client
from urllib import parse as urlparse
from keystoneauth1 import adapter
from keystoneauth1 import exceptions as kexc
from ironicclient.common import filecache
from ironicclient.common.i18n import _
from ironicclient import exc
import functools
import json
import logging
import re
import textwrap
import time



def get_server(url):
    """Extract and return the server & port."""
    if url is None:
        return None, None
    parts = urlparse.urlparse(url)
    return parts.hostname, str(parts.port)


class VersionNegotiationMixin(object):
    def negotiate_version(self, conn, resp):
        """Negotiate the server version

        Assumption: Called after receiving a 406 error when doing a request.

        :param conn: A connection object
        :param resp: The response object from http request
        """
        def _query_server(conn):
            if (self.os_ironic_api_version
                    and not isinstance(self.os_ironic_api_version, list)
                    and self.os_ironic_api_version != 'latest'):
                base_version = ("/v%s" %
                                str(self.os_ironic_api_version).split('.')[0])
            else:
                base_version = API_VERSION
            # Raise exception on client or server error.
            resp = self._make_simple_request(conn, 'GET', base_version)
            if not resp.ok:

                raise exc.from_response(resp, method='GET', url=base_version)