当前位置: 首页>>代码示例>>Python>>正文


Python PBClientFactory.getRootObject方法代码示例

本文整理汇总了Python中twisted.spread.pb.PBClientFactory.getRootObject方法的典型用法代码示例。如果您正苦于以下问题:Python PBClientFactory.getRootObject方法的具体用法?Python PBClientFactory.getRootObject怎么用?Python PBClientFactory.getRootObject使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在twisted.spread.pb.PBClientFactory的用法示例。


在下文中一共展示了PBClientFactory.getRootObject方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: UbuntuOneClient

# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import getRootObject [as 别名]
class UbuntuOneClient(object):
    """Root object that provides access to all the remote objects."""

    def __init__(self):
        """Create a new instance."""
        self.status = None
        self.events = None
        self.sync_daemon = None
        self.file_system = None
        self.shares = None
        self.config = None
        self.folders = None
        self.public_files = None
        self.factory = None
        self.client = None

    @defer.inlineCallbacks
    def _request_remote_objects(self, root):
        """Request all the diff remote objects used for the communication."""
        status = yield root.callRemote('get_status')
        self.status = StatusClient(status)

        events = yield root.callRemote('get_events')
        self.events = EventsClient(events)

        sync_daemon = yield root.callRemote('get_sync_daemon')
        self.sync_daemon = SyncDaemonClient(sync_daemon)

        file_system = yield root.callRemote('get_file_system')
        self.file_system = FileSystemClient(file_system)

        shares = yield root.callRemote('get_shares')
        self.shares = SharesClient(shares)

        config = yield root.callRemote('get_config')
        self.config = ConfigClient(config)

        folders = yield root.callRemote('get_folders')
        self.folders = FoldersClient(folders)

        public_files = yield root.callRemote('get_public_files')
        self.public_files = PublicFilesClient(public_files)

        defer.returnValue(self)

    @defer.inlineCallbacks
    def connect(self):
        """Connect to the syncdaemon service."""
        # pylint: disable=W0702
        try:
            # connect to the remote objects
            self.factory = PBClientFactory()
            self.client = yield ipc_client_connect(self.factory)
            root = yield self.factory.getRootObject()
            yield self._request_remote_objects(root)
            yield self.register_to_signals()
            defer.returnValue(self)
        except Exception, e:
            raise SyncDaemonClientConnectionError(
                            'Could not connect to the syncdaemon ipc.', e)
开发者ID:thnguyn2,项目名称:ECE_527_MP,代码行数:62,代码来源:ipc_client.py

示例2: run

# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import getRootObject [as 别名]
 def run(self, *args, **kwargs):
     def connected(reference):
         self._reference = reference
         return super(Client, self).run(*args, **kwargs)
     client = PBClientFactory()
     d = client.getRootObject()
     d.addCallback(connected)
     self._reactor.connectTCP('127.0.0.1', self._port, client)
     return d
开发者ID:AlekSi,项目名称:twisted-benchmarks,代码行数:11,代码来源:pb.py

示例3: _sendMessage

# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import getRootObject [as 别名]
def _sendMessage(channel, message):
    """
    Establish a connection to the bot and direct it to send the given message
    to the given channel.

    @type channel: C{str}
    @type message: C{str}
    """
    messageFactory = PBClientFactory()
    reactor.connectTCP(BOT_HOST, BOT_PORT, messageFactory)

    def cbGotRoot(rootObj):
        return rootObj.callRemote('message', channel, message)

    rootDeferred = messageFactory.getRootObject()
    rootDeferred.addCallback(cbGotRoot)
    rootDeferred.addErrback(err)
    rootDeferred.addCallback(lambda ign: reactor.stop())
开发者ID:rodrigc,项目名称:braid,代码行数:20,代码来源:message.py

示例4: UbuntuSSOClient

# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import getRootObject [as 别名]
class UbuntuSSOClient(object):
    """Root client that provides access to the sso API."""

    def __init__(self):
        self.sso_login = None
        self.cred_management = None
        self.factory = None
        self.client = None

    @defer.inlineCallbacks
    def _request_remote_objects(self, root):
        """Get the status remote object."""
        sso_login = yield root.callRemote('get_sso_login')
        logger.debug('SSOLogin is %s', sso_login)
        self.sso_login = SSOLoginClient(sso_login)
        cred_management = yield root.callRemote('get_cred_manager')
        self.cred_management = CredentialsManagementClient(cred_management)
        defer.returnValue(self)

    @defer.inlineCallbacks
    def connect(self):
        """Connect to the sso service."""
        ac = ActivationClient(get_activation_config())
        port = yield ac.get_active_port()
        # got the port, lets try and connect to it and get the diff
        # remote objects for the wrappers
        self.factory = PBClientFactory()
        # the reactor does have a connectTCP method
        # pylint: disable=E1101
        self.client = reactor.connectTCP(LOCALHOST, port, self.factory)
        # pylint: enable=E1101
        root = yield self.factory.getRootObject()
        client = yield self._request_remote_objects(root)
        defer.returnValue(client)

    def disconnect(self):
        """Disconnect from the process."""
        if self.client:
            self.client.disconnect()
开发者ID:Alberto-Beralix,项目名称:Beralix,代码行数:41,代码来源:windows.py

示例5: UbuntuOneClient

# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import getRootObject [as 别名]
class UbuntuOneClient(object):
    """Root object that provides access to all the remote objects."""

    connection_lock = defer.DeferredLock()

    def __init__(self):
        """Create a new instance."""
        self.status = None
        self.events = None
        self.sync_daemon = None
        self.file_system = None
        self.shares = None
        self.config = None
        self.folders = None
        self.public_files = None
        self.factory = None
        self.client = None

    @defer.inlineCallbacks
    def _request_remote_objects(self, root):
        """Request all the diff remote objects used for the communication."""
        status = yield root.callRemote('get_status')
        self.status = StatusClient(status)

        events = yield root.callRemote('get_events')
        self.events = EventsClient(events)

        sync_daemon = yield root.callRemote('get_sync_daemon')
        self.sync_daemon = SyncDaemonClient(sync_daemon)

        file_system = yield root.callRemote('get_file_system')
        self.file_system = FileSystemClient(file_system)

        shares = yield root.callRemote('get_shares')
        self.shares = SharesClient(shares)

        config = yield root.callRemote('get_config')
        self.config = ConfigClient(config)

        folders = yield root.callRemote('get_folders')
        self.folders = FoldersClient(folders)

        public_files = yield root.callRemote('get_public_files')
        self.public_files = PublicFilesClient(public_files)

        defer.returnValue(self)

    @defer.inlineCallbacks
    def connect(self):
        """Connect to the syncdaemon service."""
        yield self.connection_lock.acquire()
        try:
            if self.client is None:
                # connect to the remote objects
                self.factory = PBClientFactory()
                self.client = yield ipc_client_connect(self.factory)
                root = yield self.factory.getRootObject()
                yield self._request_remote_objects(root)
                yield self.register_to_signals()
            defer.returnValue(self)
        except Exception as e:
            raise SyncDaemonClientConnectionError(
                'Could not connect to the syncdaemon ipc.', e)
        finally:
            self.connection_lock.release()

    @defer.inlineCallbacks
    def reconnect(self):
        """Reconnect and get the new remote objects."""
        try:
            root = yield self.factory.getRootObject()
            yield self._request_remote_objects(root)
            yield self.register_to_signals()
            defer.returnValue(self)
        except Exception as e:
            raise SyncDaemonClientConnectionError(
                'Could not reconnect to the syncdaemon ipc.', e)

    def is_connected(self):
        """Return if the client is connected."""
        return (self.client is not None)

    @defer.inlineCallbacks
    def register_to_signals(self):
        """Register the different clients to the signals."""
        for client in [self.status, self.events, self.sync_daemon, self.shares,
                       self.folders, self.public_files]:
            register = getattr(client, 'register_to_signals', None)
            if register is not None:
                yield register()
        defer.returnValue(self)

    @defer.inlineCallbacks
    def unregister_to_signals(self):
        """Unregister from the diff signals."""
        for client in [self.status, self.events, self.sync_daemon, self.shares,
                       self.folders, self.public_files]:
            unregister = getattr(client, 'unregister_to_signals', None)
            if unregister is not None:
                yield unregister()
#.........这里部分代码省略.........
开发者ID:CSRedRat,项目名称:magicicada-client,代码行数:103,代码来源:ipc_client.py

示例6: BaseClient

# 需要导入模块: from twisted.spread.pb import PBClientFactory [as 别名]
# 或者: from twisted.spread.pb.PBClientFactory import getRootObject [as 别名]
class BaseClient(object):
    """Client that will connect to the service listening on service_port.

    Inherit from this class and define service_name, service_port and
    service_cmdline so they return the proper values.

    The service_cmdline must be redefined so it returns the command line to
    execute to run the service, if it's not running.

    If 'connect' is called, 'disconnect' should be called when done.

    """

    # a mapping of (client name, client class (an instance of RemoteClient))
    clients = {}
    service_name = None
    service_port = None
    service_cmdline = None

    def __init__(self):
        self.factory = None
        self.client = None
        for client in self.clients:
            setattr(self, client, None)

    @defer.inlineCallbacks
    def _request_remote_objects(self, root):
        """Request all the diff remote objects used for the communication."""
        logger.debug('Requesting remote objects (%r) for %s',
                     self.clients.keys(), self.__class__.__name__)
        for name, client_class in self.clients.iteritems():
            remote = yield root.callRemote('get_%s' % name)
            setattr(self, name, client_class(remote))

    @defer.inlineCallbacks
    def connect(self):
        """Connect to the remote service."""
        self.factory = PBClientFactory()
        self.client = yield client_connect(self.factory,
                                           self.service_name,
                                           self.service_cmdline,
                                           self.service_port)
        root = yield self.factory.getRootObject()
        yield self._request_remote_objects(root)
        yield self.register_to_signals()

    @defer.inlineCallbacks
    def register_to_signals(self):
        """Register all the clients to their signals."""
        for name in self.clients:
            client = getattr(self, name)
            yield client.register_to_signals()

    @defer.inlineCallbacks
    def unregister_to_signals(self):
        """Unregister from the all the client's signals."""
        for name in self.clients:
            client = getattr(self, name)
            yield client.unregister_to_signals()

    @defer.inlineCallbacks
    def disconnect(self):
        """Disconnect from the process."""
        yield self.unregister_to_signals()
        if self.client:
            self.client.disconnect()
开发者ID:thnguyn2,项目名称:ECE_527_MP,代码行数:68,代码来源:ipc.py


注:本文中的twisted.spread.pb.PBClientFactory.getRootObject方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。