# Path: aioconsul/client/bases.py
# class EndpointBase:
# 
#     def __init__(self, api):
#         self._api = api
# 
#     def __repr__(self):
#         return "<%s(%r)>" % (self.__class__.__name__, str(self._api.address))
# 
# Path: aioconsul/api.py
# @singledispatch
# def consul(obj, meta=None):
#     meta = meta or {}
#     return ConsulValue(obj, meta=meta)
# 
# def extract_meta(headers):
#     meta = {}
#     for k, v in headers.items():
#         if k.lower().startswith("x-consul-"):
#             k = k[9:]
#             k = {
#                 'index': 'Index',
#                 'knownleader': 'KnownLeader',
#                 'lastcontact': 'LastContact',
#                 'token': 'Token',
#                 'translate-addresses': 'Translate-Addresses',
#             }.get(k.lower(), k)
#             meta[k] = json.loads(v)
#     return meta
# 
# Path: aioconsul/exceptions.py
# class NotFound(ConsulError):
#     """Raised when object does not exists
# 
#     Attributes:
#         value (Object): object of the error
#         meta (Meta): meta of the error
#     """
# 
# Path: aioconsul/util.py
# def extract_attr(obj, *, keys):
#     if isinstance(obj, Mapping):
#         for key in keys:
#             if key in obj:
#                 return obj[key]
#         raise TypeError("%s not found in obj %s" % (keys, obj))
#     return obj


from .bases import EndpointBase
from aioconsul.api import consul, extract_meta
from aioconsul.exceptions import NotFound
from aioconsul.util import extract_attr
                      Defaults to the agent's local datacenter.
            watch (Blocking): Do a blocking query
            consistency (Consistency): Force consistency
        Returns:
            ObjectMeta: where value is the queried session
        Raises:
            NotFound: session is absent

        Returns the requested session information within a given datacenter.

        It returns a mapping like this::

            {
                "LockDelay": datetime.timedelta(0, 15),
                "Checks": [
                    "serfHealth"
                ],
                "Node": "foobar",
                "ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e",
                "CreateIndex": 1086449
            }
        """
        session_id = extract_attr(session, keys=["ID"])
        response = await self._api.get("/v1/session/info", session_id,
                                       watch=watch,
                                       consistency=consistency,
                                       params={"dc": dc})
        try:
            result = response.body[0]
        except IndexError:

# Path: aioconsul/client/bases.py
# class EndpointBase:
# 
#     def __init__(self, api):
#         self._api = api
# 
#     def __repr__(self):
#         return "<%s(%r)>" % (self.__class__.__name__, str(self._api.address))
# 
# Path: aioconsul/api.py
# @singledispatch
# def consul(obj, meta=None):
#     meta = meta or {}
#     return ConsulValue(obj, meta=meta)
# 
# def extract_meta(headers):
#     meta = {}
#     for k, v in headers.items():
#         if k.lower().startswith("x-consul-"):
#             k = k[9:]
#             k = {
#                 'index': 'Index',
#                 'knownleader': 'KnownLeader',
#                 'lastcontact': 'LastContact',
#                 'token': 'Token',
#                 'translate-addresses': 'Translate-Addresses',
#             }.get(k.lower(), k)
#             meta[k] = json.loads(v)
#     return meta
# 
# Path: aioconsul/exceptions.py
# class NotFound(ConsulError):
#     """Raised when object does not exists
# 
#     Attributes:
#         value (Object): object of the error
#         meta (Meta): meta of the error
#     """
# 
# Path: aioconsul/util.py
# def extract_attr(obj, *, keys):
#     if isinstance(obj, Mapping):
#         for key in keys:
#             if key in obj:
#                 return obj[key]
#         raise TypeError("%s not found in obj %s" % (keys, obj))
#     return obj


# Path: aioconsul/client/session_endpoint.py
from .bases import EndpointBase
from aioconsul.api import consul, extract_meta
from aioconsul.exceptions import NotFound
from aioconsul.util import extract_attr

                      Defaults to the agent's local datacenter.
            watch (Blocking): Do a blocking query
            consistency (Consistency): Force consistency
        Returns:
            ObjectMeta: where value is the queried session
        Raises:
            NotFound: session is absent

        Returns the requested session information within a given datacenter.

        It returns a mapping like this::

            {
                "LockDelay": datetime.timedelta(0, 15),
                "Checks": [
                    "serfHealth"
                ],
                "Node": "foobar",
                "ID": "adf4238a-882b-9ddc-4a9d-5b6758e4159e",
                "CreateIndex": 1086449
            }
        """
        session_id = extract_attr(session, keys=["ID"])
        response = await self._api.get("/v1/session/info", session_id,
                                       watch=watch,
                                       consistency=consistency,
                                       params={"dc": dc})
        try:
            result = response.body[0]
        except IndexError:

            meta = extract_meta(response.headers)