def __processCompressedData(self): '''Process compressed data. * data -- The compressed data to process ''' # Unzip the input stream decomp = self.__zipStream.decompress(self.__inputBuffer) self.__unzippedInput = ''.join(decomp) self.__inputBuffer = "" # Print the decompressed data for debugging purposes lines = [ "############# Decompressed Data #############", toHex(self.__unzippedInput), ] for line in lines: self.log.debug(line, level=7) self.log.debug("#" * 45, level=7) # Continue so long as there are other objects while self.__hasNextObject(): obj = self.__readNextObjectFromUnzipped() # Will be nil if the next object is a ping/pong if obj is not None: self.log.debug("Received object: [%s]" % obj['class'], level=2) # Print the add views object for debugging purposes if obj.get('class') == 'AddViews': self.log.debug("========== AddViews ==========", level=2) self.log.debug(obj, level=2) self.log.debug("========== AddViews ==========", level=2) # Give the world a chance to mess with folks newObject = self.__prepReceivedObject(obj) # Might be nil if "the world" decides to rid us of the object if newObject is not None: self.injectObjectToOutputStream(newObject)
def __hasNextObject(self): '''Determine if there is an object waiting to be processed.''' if len(self.__unzippedInput) == 0: return False unpacked = self.__unpackUnzippedInput(self.__unzippedInput[0:5]) self.log.debug("Unpacked: %s" % unpacked, level=7) # Ping or pong packet pattern = re.compile("^0[34]") if pattern.match(unpacked) is not None: return True # Clear context packet pattern = re.compile("^ff") if pattern.match(unpacked) is not None: return True # Rogue packet pattern = re.compile("^[0-9][15-9]") if pattern.match(unpacked) is not None: return False # Data packet pattern = re.compile("^0200(.{6})") matched = pattern.match(unpacked) if matched is None: self.log.error("Error matching packet!") self.log.error(toHex(unpacked)) return False objectLength = int(matched.groups()[0], 16) # Determine if the length of the next object (plus its prefix) # is less than the input buffer return (objectLength + 5) <= len(self.__unzippedInput)