# Path: google/cloud/ndb/_batch.py
# def get_batch(batch_cls, options=None):
#     def idler(batch):
#         def idle():
# 
# Path: google/cloud/ndb/context.py
# @property
# def context(self):
#     return self._context.get()
# 
# Path: google/cloud/ndb/tasklets.py
# class Future(object):
# class _TaskletFuture(Future):
# class _MultiFuture(Future):
# class Return(Exception):
# class QueueFuture(object):
# class ReducingFuture(object):
# class SerialQueueFuture(object):
#     def __init__(self, info="Unknown"):
#     def __repr__(self):
#     def done(self):
#     def running(self):
#     def wait(self):
#     def check_success(self):
#     def set_result(self, result):
#     def set_exception(self, exception):
#     def _finish(self):
#     def result(self):
#     def exception(self):
#     def get_traceback(self):
#     def add_done_callback(self, callback):
#     def cancel(self):
#     def cancelled(self):
#     def wait_any(futures):
#     def wait_all(futures):
#     def __init__(self, generator, context, info="Unknown"):
#     def _advance_tasklet(self, send_value=None, error=None):
#         def done_callback(yielded):
#     def cancel(self):
# def _get_return_value(stop):
#     def __init__(self, dependencies):
#     def __repr__(self):
#     def _dependency_done(self, dependency):
#     def cancel(self):
# def tasklet(wrapped):
#     def tasklet_wrapper(*args, **kwargs):
# def wait_any(futures):
# def wait_all(futures):
# def sleep(seconds):
# def add_flow_exception(*args, **kwargs):
# def make_context(*args, **kwargs):
# def make_default_context(*args, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
# def set_context(*args, **kwargs):
# def synctasklet(wrapped):
#     def synctasklet_wrapper(*args, **kwargs):
# def toplevel(wrapped):
#     def toplevel_wrapper(*args, **kwargs):
# 
# Path: google/cloud/ndb/utils.py
# TRUTHY_STRINGS = {"t", "true", "y", "yes", "on", "1"}
# DEBUG = asbool(os.environ.get("NDB_DEBUG", False))
# def asbool(value):
# def code_info(*args, **kwargs):
# def decorator(*args, **kwargs):
# def frame_info(*args, **kwargs):
# def func_info(*args, **kwargs):
# def gen_info(*args, **kwargs):
# def get_stack(*args, **kwargs):
# def logging_debug(log, message, *args, **kwargs):
#     def __init__(self, **kwargs):
#     def __call__(self, wrapped):
#         def wrapper(*args, **kwargs):
# def positional(max_pos_args):
#     def positional_decorator(wrapped):
#         def positional_wrapper(*args, **kwds):
# def tweak_logging(*args, **kwargs):
# def wrapping(*args, **kwargs):
# class keyword_only(object):


import functools
import itertools
import logging
import uuid
import warnings
from google.api_core import retry as core_retry
from google.cloud.ndb import _batch
from google.cloud.ndb import context as context_module
from google.cloud.ndb import tasklets
from google.cloud.ndb import utils

class ContextCache(dict):
    """A per-context in-memory entity cache.

    This cache verifies the fetched entity has the correct key before
    returning a result, in order to handle cases where the entity's key was
    modified but the cache's key was not updated.
    """

    def get_and_validate(self, key):
        """Verify that the entity's key has not changed since it was added
        to the cache. If it has changed, consider this a cache miss.
        See issue 13.  http://goo.gl/jxjOP"""
        entity = self[key]  # May be None, meaning "doesn't exist".
        if entity is None or entity._key == key:
            return entity
        else:
            del self[key]
            raise KeyError(key)

    def __repr__(self):
        return "ContextCache()"


def _future_result(result):
    """Returns a completed Future with the given result.

    For conforming to the asynchronous interface even if we've gotten the
    result synchronously.
    """

# Path: google/cloud/ndb/_batch.py
# def get_batch(batch_cls, options=None):
#     def idler(batch):
#         def idle():
# 
# Path: google/cloud/ndb/context.py
# @property
# def context(self):
#     return self._context.get()
# 
# Path: google/cloud/ndb/tasklets.py
# class Future(object):
# class _TaskletFuture(Future):
# class _MultiFuture(Future):
# class Return(Exception):
# class QueueFuture(object):
# class ReducingFuture(object):
# class SerialQueueFuture(object):
#     def __init__(self, info="Unknown"):
#     def __repr__(self):
#     def done(self):
#     def running(self):
#     def wait(self):
#     def check_success(self):
#     def set_result(self, result):
#     def set_exception(self, exception):
#     def _finish(self):
#     def result(self):
#     def exception(self):
#     def get_traceback(self):
#     def add_done_callback(self, callback):
#     def cancel(self):
#     def cancelled(self):
#     def wait_any(futures):
#     def wait_all(futures):
#     def __init__(self, generator, context, info="Unknown"):
#     def _advance_tasklet(self, send_value=None, error=None):
#         def done_callback(yielded):
#     def cancel(self):
# def _get_return_value(stop):
#     def __init__(self, dependencies):
#     def __repr__(self):
#     def _dependency_done(self, dependency):
#     def cancel(self):
# def tasklet(wrapped):
#     def tasklet_wrapper(*args, **kwargs):
# def wait_any(futures):
# def wait_all(futures):
# def sleep(seconds):
# def add_flow_exception(*args, **kwargs):
# def make_context(*args, **kwargs):
# def make_default_context(*args, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
#     def __init__(self, *args, **kwargs):
# def set_context(*args, **kwargs):
# def synctasklet(wrapped):
#     def synctasklet_wrapper(*args, **kwargs):
# def toplevel(wrapped):
#     def toplevel_wrapper(*args, **kwargs):
# 
# Path: google/cloud/ndb/utils.py
# TRUTHY_STRINGS = {"t", "true", "y", "yes", "on", "1"}
# DEBUG = asbool(os.environ.get("NDB_DEBUG", False))
# def asbool(value):
# def code_info(*args, **kwargs):
# def decorator(*args, **kwargs):
# def frame_info(*args, **kwargs):
# def func_info(*args, **kwargs):
# def gen_info(*args, **kwargs):
# def get_stack(*args, **kwargs):
# def logging_debug(log, message, *args, **kwargs):
#     def __init__(self, **kwargs):
#     def __call__(self, wrapped):
#         def wrapper(*args, **kwargs):
# def positional(max_pos_args):
#     def positional_decorator(wrapped):
#         def positional_wrapper(*args, **kwds):
# def tweak_logging(*args, **kwargs):
# def wrapping(*args, **kwargs):
# class keyword_only(object):


# Path: google/cloud/ndb/_cache.py
import functools
import itertools
import logging
import uuid
import warnings
from google.api_core import retry as core_retry
from google.cloud.ndb import _batch
from google.cloud.ndb import context as context_module
from google.cloud.ndb import tasklets
from google.cloud.ndb import utils


class ContextCache(dict):
    """A per-context in-memory entity cache.

    This cache verifies the fetched entity has the correct key before
    returning a result, in order to handle cases where the entity's key was
    modified but the cache's key was not updated.
    """

    def get_and_validate(self, key):
        """Verify that the entity's key has not changed since it was added
        to the cache. If it has changed, consider this a cache miss.
        See issue 13.  http://goo.gl/jxjOP"""
        entity = self[key]  # May be None, meaning "doesn't exist".
        if entity is None or entity._key == key:
            return entity
        else:
            del self[key]
            raise KeyError(key)

    def __repr__(self):
        return "ContextCache()"


def _future_result(result):
    """Returns a completed Future with the given result.

    For conforming to the asynchronous interface even if we've gotten the
    result synchronously.
    """

    future = tasklets.Future()