def __getitem__(self, key): try: key = ESOType(key) except ValueError: raise KeyError("%s" % key) if key not in self: self[key] = dict() return dict.__getitem__(self, key)
def _get_proto_for_type(self, type_id): try: type_id = ESOType(type_id) except ValueError: self._LOG.error("Unsupported type: %d" % type_id) return proto = find_so_proto(type_id) if proto is None: self._LOG.error("Unable to locate proto for: %s" % repr(type_id)) return return proto
def _handle_destroy(self, message): result = self._parse_object_data(message.type_id, message.object_data) if result: key, obj = result type_id = ESOType(message.type_id) current = None if key is NO_KEY: current = self.pop(type_id, None) else: current = self[type_id].pop(key, None) if current: current.CopyFrom(obj) self.emit(('removed', type_id), current or obj)
def _handle_cache_unsubscribed(self, message): cache_key = message.owner_soid.type, message.owner_soid.id if cache_key not in self._caches: return cache = self._caches[cache_key] for type_id in cache['type_ids']: if type_id in self: type_id = ESOType(type_id) if isinstance(self[type_id], dict): for key in list(self[type_id].keys()): self.emit(('removed', type_id), self[type_id].pop(key)) else: self.emit(('removed', type_id), self.pop(type_id)) del self[type_id] del self._caches[cache_key]
def _update_object(self, type_id, object_data): result = self._parse_object_data(type_id, object_data) if result: key, obj = result type_id = ESOType(type_id) if key is NO_KEY: if not isinstance(self[type_id], dict): self[type_id].CopyFrom(obj) obj = self[type_id] else: self[type_id] = obj else: if key in self[type_id]: self[type_id][key].CopyFrom(obj) obj = self[type_id][key] else: self[type_id][key] = obj return type_id, obj