# Path: pyhaystack/util/state.py
# @property
# def state(self):
#     """
#     Return the current state machine's state.
#     """
#     return self._state_machine.current
# 
# Path: pyhaystack/util/asyncexc.py
# class AsynchronousException(object):
#     def __init__(self):
#         self._exc_info = exc_info()
# 
#     def reraise(self):
#         reraise(*self._exc_info)
# 
# Path: pyhaystack/exception.py
# class HaystackError(Exception):
#     """
#     Exception thrown when an error grid is returned by the Haystack server.
#     See http://project-haystack.org/doc/Rest#errorGrid
#     """
# 
#     def __init__(self, message, traceback=None, *args, **kwargs):
#         super(HaystackError, self).__init__(message, *args, **kwargs)
#         self.traceback = traceback


import hszinc
import fysom
from ...util import state
from ...util.asyncexc import AsynchronousException
from ...exception import HaystackError
                entity_id = entity_id.name

            try:
                self._entities[entity_id] = self._session._entities[entity_id]
            except KeyError:
                pass

        if not self._refresh_all:
            # Throw out what we've done
            list(map(self._todo.discard, list(self._entities.keys())))
        self._state_machine.cache_checked()

    def _do_read(self, event):
        """
        Read the entities that are left behind.
        """
        try:
            if bool(self._todo):
                self._session.read(ids=list(self._todo), callback=self._on_read)
            else:
                # Nothing needed to read.
                if self._single:
                    try:
                        result = list(self._entities.values())[0]
                    except IndexError:
                        raise NameError("No matching entity found")
                else:
                    result = self._entities
                self._state_machine.read_done(result=result)
        except:  # Catch all exceptions to pass to caller.

# Path: pyhaystack/util/state.py
# @property
# def state(self):
#     """
#     Return the current state machine's state.
#     """
#     return self._state_machine.current
# 
# Path: pyhaystack/util/asyncexc.py
# class AsynchronousException(object):
#     def __init__(self):
#         self._exc_info = exc_info()
# 
#     def reraise(self):
#         reraise(*self._exc_info)
# 
# Path: pyhaystack/exception.py
# class HaystackError(Exception):
#     """
#     Exception thrown when an error grid is returned by the Haystack server.
#     See http://project-haystack.org/doc/Rest#errorGrid
#     """
# 
#     def __init__(self, message, traceback=None, *args, **kwargs):
#         super(HaystackError, self).__init__(message, *args, **kwargs)
#         self.traceback = traceback


# Path: pyhaystack/client/ops/entity.py
import hszinc
import fysom
from ...util import state
from ...util.asyncexc import AsynchronousException
from ...exception import HaystackError

                entity_id = entity_id.name

            try:
                self._entities[entity_id] = self._session._entities[entity_id]
            except KeyError:
                pass

        if not self._refresh_all:
            # Throw out what we've done
            list(map(self._todo.discard, list(self._entities.keys())))
        self._state_machine.cache_checked()

    def _do_read(self, event):
        """
        Read the entities that are left behind.
        """
        try:
            if bool(self._todo):
                self._session.read(ids=list(self._todo), callback=self._on_read)
            else:
                # Nothing needed to read.
                if self._single:
                    try:
                        result = list(self._entities.values())[0]
                    except IndexError:
                        raise NameError("No matching entity found")
                else:
                    result = self._entities
                self._state_machine.read_done(result=result)
        except:  # Catch all exceptions to pass to caller.

            self._state_machine.exception(result=AsynchronousException())