def _push(self, msg, code=None): promise = Promise() with self._lock: if self._should_stop != self._ST_NONE: promise.set(exc=ServiceStopped()) else: self._do_push(msg, promise, code) return promise.to_future()
def __lookup_tags(self, tags, as_bools): ret = {} cloud_tags = set() # FIXME not as closure def _ret_value(state): if as_bools: if not state: return False elif isinstance(state, TagBase): return state.IsLocallySet() else: return state.is_set else: if not state: return None elif isinstance(state, TagBase): return {'is_set': state.IsLocallySet()} else: return state.__dict__ for tag in tags: # FIXME Consider that tag may exists as LocalTag in infile_items or inmem_items? if self._is_cloud_tag_name(tag): cloud_tags.add(tag) else: # dont_create=True to distinguish unset tags from non-existed ret[tag] = _ret_value(self._RawTag(tag, dont_create=True)) promise = Promise() if not cloud_tags: promise.set(ret) return promise.to_future() cloud_done = self._cloud.lookup(cloud_tags) def on_cloud_done(f): if f.is_success(): cloud_result = f.get() for tag in cloud_tags: ret[tag] = _ret_value(cloud_result.get(tag, None)) promise.set(ret) else: promise.set(None, f.get_exception()) cloud_done.subscribe(on_cloud_done) return promise.to_future()
class SerialUpdateOnlyDummyCloudClient(object): """This class allows SafeCloud to work correctly""" def __init__(self, wrong_setup_exc): self._wrong_setup_future = Promise().set(None, wrong_setup_exc).to_future() self._serial_update_promise = Promise() self._serial_update_future = self._serial_update_promise.to_future() def stop(self, timeout=None): self._serial_update_promise.set(None, RuntimeError("cloud client stopped")) def is_stopped(self): return self._serial_update_future.is_set() def wait_outgoing_empty(self): raise NotImplementedError() def serial_update(self, update): return self._serial_update_future def debug_server(self): return self._wrong_setup_future def subscribe(self, tags, with_future=True): return READY_FUTURE def unsubscribe(self, tags, with_future=True): return READY_FUTURE def lookup(self, tags): return self._wrong_setup_future def match(self, prefix=None, regexp=None, limit=None): return self._wrong_setup_future def update(self, updates): return self._wrong_setup_future