コード例 #1
0
ファイル: test.py プロジェクト: mrueg/py-lz4framed
    def test_decompressor_init(self):
        with self.assertRaises(TypeError):
            Decompressor()  # pylint: disable=no-value-for-parameter
        with self.assertRaisesRegex(AttributeError,
                                    'has no attribute \'read\''):
            Decompressor('1')

        # non-callable read attribute
        class Empty(object):
            read = 1

        with self.assertRaises(TypeError):
            Decompressor(Empty())
コード例 #2
0
ファイル: test.py プロジェクト: mrueg/py-lz4framed
    def test_decompressor_fp(self):
        # levels > 10 (v1.7.5) are significantly slower
        for level in (0, 10):
            out_bytes = BytesIO()
            for chunk in Decompressor(
                    BytesIO(compress(LONG_INPUT, level=level))):
                out_bytes.write(chunk)
            self.assertEqual(out_bytes.getvalue(), LONG_INPUT)

        # incomplete frame
        out_bytes.truncate()
        with self.assertRaises(Lz4FramedNoDataError):
            for chunk in Decompressor(BytesIO(compress(LONG_INPUT)[:-32])):
                out_bytes.write(chunk)
        # some data should have been written
        out_bytes.seek(SEEK_END)
        self.assertTrue(out_bytes.tell() > 0)
コード例 #3
0
def do_decompress(in_stream, out_stream):
    write = out_stream.write
    try:
        for chunk in Decompressor(in_stream):
            write(chunk)
    except Lz4FramedError as ex:
        __error('Compression error: %s' % ex)
        return 8
    return 0
コード例 #4
0
    def run(self):

        _, rmstream, rmerr = self.ssh.exec_command(self._read_loop)

        data = b''
        if SHOW_FPS:
            f = 0
            t = time.perf_counter()
            fps = 0

        try:
            for chunk in Decompressor(rmstream):
                data += chunk
                while len(data) >= TOTAL_BYTES:
                    pix = data[:TOTAL_BYTES]
                    data = data[TOTAL_BYTES:]
                    self.signals.onNewFrame.emit(
                        QImage(pix, WIDTH, HEIGHT, WIDTH * 2, self.img_format))
                    if SHOW_FPS:
                        f += 1
                        if f % 10 == 0:
                            fps = 10 / (time.perf_counter() - t)
                            t = time.perf_counter()
                        print("FRAME %d  |  FPS %.3f\r" % (f, fps), end='')
                if self._stop:
                    log.debug('Stopping framebuffer worker')
                    break
        except Lz4FramedNoDataError:
            e = rmerr.read().decode('ascii')
            s = rmstream.channel.recv_exit_status()
            if s == 127:
                log.info("Check if your remarkable has lz4 installed! %s", e)
                self.signals.onFatalError.emit(Exception(e))
            else:
                log.warning("Frame data stream is empty.\nExit status: %d %s",
                            s, e)

        except Exception as e:
            log.error("Error: %s %s", type(e), e)
            self.signals.onFatalError.emit(e)