def __init__(self, cxn, context=None): HasDynamicAttrs.__init__(self) self._backend = cxn self._mgr = ManagerService(cxn) if context is None: context = cxn.context() self._ctx = context
class Client(HasDynamicAttrs): def __init__(self, cxn, context=None): HasDynamicAttrs.__init__(self) self._backend = cxn self._mgr = ManagerService(cxn) if context is None: context = cxn.context() self._ctx = context def __enter__(self): """Enter the body of a with statement.""" return self def __exit__(self, exc_type, exc_val, exc_tb): """Exit the body of a with statement.""" try: self.disconnect() except: pass return False def __call__(self, context=None): return Client(self._backend, context) def _getAttrs(self): if not self.connected: return [] return self._mgr.getServersList() _staticAttrs = ['servers', 'connect', 'disconnect', 'context'] _wrapAttr = ServerWrapper @property def servers(self): self._refresh() return self._attrs # attributes proxied to the underlying connection, which may be shared among multiple clients @property def name(self): return self._backend.name @property def ID(self): return self._backend.ID @property def host(self): return self._backend.host @property def port(self): return self._backend.port @property def connected(self): return self._backend.connected def connect(self, host, port=C.MANAGER_PORT, timeout=C.TIMEOUT, password=None): self._backend.connect(host, port=port, timeout=timeout, password=password) def disconnect(self): self._backend.disconnect() def context(self): return self._backend.context() def _send(self, target, records, *args, **kw): """Send a packet over this connection.""" if 'context' not in kw or kw['context'] is None: kw['context'] = self._ctx return self._backend.sendRequest(target, records, *args, **kw) def _sendMessage(self, target, records, *args, **kw): """Send a message over this connection.""" if 'context' not in kw or kw['context'] is None: kw['context'] = self._ctx return self._backend.sendMessage(target, records, *args, **kw) def __repr__(self): if self.connected: return unwrap("""\ |LabRAD Client: '%s' on %s:%s | |Available servers: |%s""") % (self.name, self.host, self.port, indent(repr(self.servers))) else: return unwrap("""\ |LabRAD Client: '%s' | |Disconnected""") % self.name
class Client(HasDynamicAttrs): def __init__(self, cxn, context=None): HasDynamicAttrs.__init__(self) self._backend = cxn self._mgr = ManagerService(cxn) if context is None: context = cxn.context() self._ctx = context def __enter__(self): """Enter the body of a with statement.""" return self def __exit__(self, exc_type, exc_val, exc_tb): """Exit the body of a with statement.""" try: self.disconnect() except: pass return False def __call__(self, context=None): return Client(self._backend, context) def _getAttrs(self): if not self.connected: return [] return self._mgr.getServersList() _staticAttrs = ['servers', 'connect', 'disconnect', 'context', 'spawn'] _wrapAttr = ServerWrapper @property def servers(self): self._refresh() return self._attrs # attributes proxied to the underlying connection, which may be shared among multiple clients @property def name(self): return self._backend.name @property def ID(self): return self._backend.ID @property def host(self): return self._backend.host @property def port(self): return self._backend.port @property def connected(self): return self._backend.connected def connect(self, host, port=None, timeout=C.TIMEOUT, password=None, tls_mode=C.MANAGER_TLS): self._backend.connect(host, port=port, timeout=timeout, password=password, tls_mode=tls_mode) def disconnect(self): self._backend.disconnect() def context(self): return self._backend.context() def spawn(self): """Start a new independent connection to the same manager.""" return Client(self._backend.spawn()) def _send(self, target, records, *args, **kw): """Send a packet over this connection.""" if 'context' not in kw or kw['context'] is None: kw['context'] = self._ctx return self._backend.sendRequest(target, records, *args, **kw) def _sendMessage(self, target, records, *args, **kw): """Send a message over this connection.""" if 'context' not in kw or kw['context'] is None: kw['context'] = self._ctx return self._backend.sendMessage(target, records, *args, **kw) def __repr__(self): if self.connected: return unwrap("""\ |LabRAD Client: '%s' on %s:%s | |Available servers: |%s""") % (self.name, self.host, self.port, indent(repr(self.servers))) else: return unwrap("""\ |LabRAD Client: '%s' | |Disconnected""") % self.name