# Path: pyactor/exceptions.py
# class PyActorTimeoutError(Exception):
#     """Wait time expired."""
# 
#     def __init__(self, method='Not specified'):
#         self.method = method
# 
#     def __str__(self):
#         return f"Timeout triggered: {self.method!r}"
# 
# class HostError(Exception):
#     """Some problem with the Host."""
# 
#     def __init__(self, value='Not specified'):
#         self.value = value
# 
#     def __str__(self):
#         return f"Host ERROR: {self.value!r}"
# 
# Path: pyactor/util.py
# ASK = 'ASK'
# 
# TELL = 'TELL'
# 
# TYPE = 'TYPE'
# 
# METHOD = 'METHOD'
# 
# PARAMS = 'PARAMS'
# 
# CHANNEL = 'CHANNEL'
# 
# TO = 'TO'
# 
# RESULT = 'RESULT'
# 
# Path: pyactor/util.py
# def get_host():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         current = getcurrent()
#     for host in hosts.values():
#         if current in host.threads.keys():
#             return host
#         elif current in host.pthreads.keys():
#             return host
#     return main_host
# 
# def get_lock():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         return None
#     url = None
#     for host in hosts.values():
#         if current in host.threads.keys():
#             url = host.threads[current]
#         elif current in host.pthreads.keys():
#             url = host.pthreads[current]
#         if url in host.locks.keys():
#             lock = host.locks[url]
#             return lock
# 
# def get_current():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         current = getcurrent()
#     for host in hosts.values():
#         if current in host.threads.keys():
#             return host.actors[host.threads[current]]
#         elif current in host.pthreads.keys():
#             return host.actors[host.pthreads[current]]


from importlib import import_module
from queue import Empty
from .exceptions import PyActorTimeoutError, HostError
from .util import ASK, TELL, TYPE, METHOD, PARAMS, CHANNEL, TO, RESULT
from .util import get_host, get_lock, get_current
            new_args = host.dumps(list(args))
            new_kwargs = host.dumps(kwargs)
        else:
            raise HostError("No such Host on the context of the call.")

        if future:
            self.__lock = get_lock()
            future_ref = {METHOD: self._method, PARAMS: (new_args, new_kwargs),
                          CHANNEL: self._actor_channel, TO: self.target,
                          'LOCK': self.__lock}

            manager = get_current()
            if manager is None:
                manager = get_host().proxy.actor
            return manager.future_manager.new_future(future_ref, ref=True)
        else:
            result = super(AskRefWrapper, self).__call__(*new_args,
                                                         **new_kwargs)
            return get_host().loads(result)


class TellRefWrapper(TellWrapper):
    """Wrapper for Tell queries that have a proxy in parameters."""

    def __call__(self, *args, **kwargs):
        host = get_host()
        if host is not None:
            new_args = host.dumps(list(args))
            new_kwargs = host.dumps(kwargs)
        else:

# Path: pyactor/exceptions.py
# class PyActorTimeoutError(Exception):
#     """Wait time expired."""
# 
#     def __init__(self, method='Not specified'):
#         self.method = method
# 
#     def __str__(self):
#         return f"Timeout triggered: {self.method!r}"
# 
# class HostError(Exception):
#     """Some problem with the Host."""
# 
#     def __init__(self, value='Not specified'):
#         self.value = value
# 
#     def __str__(self):
#         return f"Host ERROR: {self.value!r}"
# 
# Path: pyactor/util.py
# ASK = 'ASK'
# 
# TELL = 'TELL'
# 
# TYPE = 'TYPE'
# 
# METHOD = 'METHOD'
# 
# PARAMS = 'PARAMS'
# 
# CHANNEL = 'CHANNEL'
# 
# TO = 'TO'
# 
# RESULT = 'RESULT'
# 
# Path: pyactor/util.py
# def get_host():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         current = getcurrent()
#     for host in hosts.values():
#         if current in host.threads.keys():
#             return host
#         elif current in host.pthreads.keys():
#             return host
#     return main_host
# 
# def get_lock():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         return None
#     url = None
#     for host in hosts.values():
#         if current in host.threads.keys():
#             url = host.threads[current]
#         elif current in host.pthreads.keys():
#             url = host.pthreads[current]
#         if url in host.locks.keys():
#             lock = host.locks[url]
#             return lock
# 
# def get_current():
#     if core_type == 'thread':
#         current = current_thread()
#     else:
#         current = getcurrent()
#     for host in hosts.values():
#         if current in host.threads.keys():
#             return host.actors[host.threads[current]]
#         elif current in host.pthreads.keys():
#             return host.actors[host.pthreads[current]]


# Path: pyactor/proxy.py
from importlib import import_module
from queue import Empty
from .exceptions import PyActorTimeoutError, HostError
from .util import ASK, TELL, TYPE, METHOD, PARAMS, CHANNEL, TO, RESULT
from .util import get_host, get_lock, get_current

            new_args = host.dumps(list(args))
            new_kwargs = host.dumps(kwargs)
        else:
            raise HostError("No such Host on the context of the call.")

        if future:
            self.__lock = get_lock()
            future_ref = {METHOD: self._method, PARAMS: (new_args, new_kwargs),
                          CHANNEL: self._actor_channel, TO: self.target,
                          'LOCK': self.__lock}

            manager = get_current()
            if manager is None:
                manager = get_host().proxy.actor
            return manager.future_manager.new_future(future_ref, ref=True)
        else:
            result = super(AskRefWrapper, self).__call__(*new_args,
                                                         **new_kwargs)
            return get_host().loads(result)


class TellRefWrapper(TellWrapper):
    """Wrapper for Tell queries that have a proxy in parameters."""

    def __call__(self, *args, **kwargs):
        host = get_host()
        if host is not None:
            new_args = host.dumps(list(args))
            new_kwargs = host.dumps(kwargs)
        else:

            raise HostError("No such Host on the context of the call.")