def get(self, binary=False): if self.__splitting is not None: (string, itemsize, count, index) = self.__splitting else: queue = self.__queue # we would use .delete_head_nowait() but it returns a crashy wrapper instead of a sensible value like None. So implement a test (which is safe as long as we're the only reader) message = safe_delete_head_nowait(queue) if not message: return None string = message.to_string() itemsize = int(message.arg1()) count = int(message.arg2()) index = 0 assert index < count # update state if index == count - 1: self.__splitting = None else: self.__splitting = (string, itemsize, count, index + 1) # extract value # TODO: this should be a separate concern, refactor item_string = string[itemsize * index:itemsize * (index + 1)] if binary: # In binary mode, pack info with already-binary data. value = struct.pack(self.__type.get_info_format(), *self.__igetter()) + item_string else: # In python-value mode, unpack binary data. unpacker = array.array(self.__type.get_array_format()) unpacker.fromstring(item_string) value = (self.__igetter(), unpacker.tolist()) return value
def get(self, binary=False): if self.__splitting is not None: (string, itemsize, count, index) = self.__splitting else: queue = self.__queue # we would use .delete_head_nowait() but it returns a crashy wrapper instead of a sensible value like None. So implement a test (which is safe as long as we're the only reader) message = safe_delete_head_nowait(queue) if not message: return None string = message.to_string() itemsize = int(message.arg1()) count = int(message.arg2()) index = 0 assert index < count # update state if index == count - 1: self.__splitting = None else: self.__splitting = (string, itemsize, count, index + 1) # extract value # TODO: this should be a separate concern, refactor item_string = string[itemsize * index:itemsize * (index + 1)] if binary: # In binary mode, pack info with already-binary data. value = struct.pack(self.__type.get_info_format(), * self.__igetter()) + item_string else: # In python-value mode, unpack binary data. unpacker = array.array(self.__type.get_array_format()) unpacker.fromstring(item_string) value = (self.__igetter(), unpacker.tolist()) return value
def get_text(self): message = safe_delete_head_nowait(self.__char_queue) if message: textstring = self.__text textstring += message.to_string().decode('us-ascii') # TODO: Make the buffer longer and arrange so partial updates rather than the entire buffer can be sent to clients. self.__text = textstring[-100:] return self.__text
def _poll_from_poller(self, fire): """Extract all items currently in the queue and deliver them.""" got_info = False latest_info = None while True: message = safe_delete_head_nowait(self.__queue) if not message: break if not got_info: got_info = True latest_info = self.__info_getter() self._deliver_message(message, latest_info, fire)