# 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
        By default, this is ``release``, causing any locks that are held to be
        released. Changing this to ``delete`` causes any locks that are held
        to be deleted. ``delete`` is useful for creating ephemeral key/value
        entries.

        **TTL** field is a duration string, and like ``LockDelay`` it can use
        "s" as a suffix for seconds. If specified, it must be between 10s and
        86400s currently. When provided, the session is invalidated if it is
        not renewed before the TTL expires. The lowest practical TTL should be
        used to keep the number of managed sessions low.
        When locks are forcibly expired, such as during a leader election,
        sessions may not be reaped for up to double this TTL, so long TTL
        values (>1 hour) should be avoided.
        """
        response = await self._api.put(
            "/v1/session/create",
            data=session,
            params={"dc": dc})
        return response.body

    async def destroy(self, session, *, dc=None):
        """Destroys a given session

        Parameters:
            session (ObjectID): Session ID
            dc (str): Specify datacenter that will be used.
                      Defaults to the agent's local datacenter.
        Returns:
            bool: ``True`` on success
        """

# 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

        By default, this is ``release``, causing any locks that are held to be
        released. Changing this to ``delete`` causes any locks that are held
        to be deleted. ``delete`` is useful for creating ephemeral key/value
        entries.

        **TTL** field is a duration string, and like ``LockDelay`` it can use
        "s" as a suffix for seconds. If specified, it must be between 10s and
        86400s currently. When provided, the session is invalidated if it is
        not renewed before the TTL expires. The lowest practical TTL should be
        used to keep the number of managed sessions low.
        When locks are forcibly expired, such as during a leader election,
        sessions may not be reaped for up to double this TTL, so long TTL
        values (>1 hour) should be avoided.
        """
        response = await self._api.put(
            "/v1/session/create",
            data=session,
            params={"dc": dc})
        return response.body

    async def destroy(self, session, *, dc=None):
        """Destroys a given session

        Parameters:
            session (ObjectID): Session ID
            dc (str): Specify datacenter that will be used.
                      Defaults to the agent's local datacenter.
        Returns:
            bool: ``True`` on success
        """

        session_id = extract_attr(session, keys=["ID"])