context.py 文件源码

python
阅读 22 收藏 0 点赞 0 评论 0

项目:pyactor 作者: pedrotgn 项目源码 文件源码
def lookup_url(self, url, klass, module=None):
        '''
        Gets a proxy reference to the actor indicated by the URL in the
        parameters. It can be a local reference or a remote direction to
        another host.

        This method can be called remotely synchronously.

        :param srt. url: address that identifies an actor.
        :param class klass: the class of the actor.
        :param srt. module: if the actor class is not in the calling module,
            you need to specify the module where it is here. Also, the *klass*
            parameter change to be a string.
        :return: :class:`~.Proxy` of the actor requested.
        :raises: :class:`NotFoundError`, if the URL specified do not
            correspond to any actor in the host.
        :raises: :class:`HostDownError`  if the host is down.
        :raises: :class:`HostError`  if there is an error looking for
            the actor in another server.
        '''
        if not self.alive:
            raise HostDownError()
        aurl = urlparse(url)
        if self.is_local(aurl):
            if url not in self.actors.keys():
                raise NotFoundError(url)
            else:
                return Proxy(self.actors[url])
        else:
            try:
                dispatcher = self.actors[aurl.scheme]
                if module is not None:
                    try:
                        module_ = __import__(module, globals(), locals(),
                                             [klass], -1)
                        klass_ = getattr(module_, klass)
                    except Exception, e:
                        raise HostError("At lookup_url: " +
                                        "Import failed for module " + module +
                                        ", class " + klass +
                                        ". Check this values for the lookup." +
                                        " ERROR: " + str(e))
                elif isinstance(klass, (types.TypeType, types.ClassType)):
                    klass_ = klass
                else:
                    raise HostError("The class specified to look up is" +
                                    " not a class.")
                remote_actor = actor.ActorRef(url, klass_, dispatcher.channel)
                return Proxy(remote_actor)
            except HostError:
                raise
            except Exception, e:
                raise HostError("ERROR looking for the actor on another " +
                                "server. Hosts must " +
                                "be in http to work properly. " + str(e))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号