예제 #1
0
    def lineReceived(self, line):
        """
        Called when a line has been received.

        :param line: the line
        """
        # Try to parse the line as a packet
        try:
            dct = json.loads(line, object_hook=self._byteify)
            packet = Packet.parsePacket(dct)
        except Exception as e:
            self._logger.warning("Invalid packet received: %s" % line)
            self._logger.exception(e)
            return

        # Wait for raw data if it is a container
        if isinstance(packet, Container):
            self._content = b''
            self._container = packet
            self.setRawMode()
            return  # do not go any further

        self.packetReceived(packet)