From 8feddb8f1375c86a526af70910236c22d60e55d6 Mon Sep 17 00:00:00 2001 From: Tibor Arpas Date: Wed, 3 Jun 2015 16:22:33 +0200 Subject: [PATCH] Adding zlib compression. --- testmon/testmon_core.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/testmon/testmon_core.py b/testmon/testmon_core.py index 2e0d55f..c28c7c8 100644 --- a/testmon/testmon_core.py +++ b/testmon/testmon_core.py @@ -1,8 +1,9 @@ +import zlib + try: import configparser except ImportError: import ConfigParser as configparser -import gzip import json import os from collections import defaultdict @@ -14,6 +15,8 @@ from testmon.process_code import checksum_coverage from testmon.process_code import Module +if sys.version_info > (3,): + buffer = memoryview def _get_python_lib_paths(): res = [sys.prefix] @@ -164,20 +167,23 @@ def _fetch_attribute(self, attribute, default=None): [self.variant + ':' + attribute]) result = cursor.fetchone() if result: - return json.loads(result[0]) + return json.loads(zlib.decompress(result[0]).decode('utf-8)')) else: return default def _write_attribute(self, attribute, data): dataid = self.variant + ':' + attribute + json_data = json.dumps(data).encode('utf-8') + compressed_data_buffer = buffer(zlib.compress(json_data)) cursor = self.connection.execute("UPDATE alldata SET data=? WHERE dataid=?", - [json.dumps(data), dataid]) + [compressed_data_buffer, dataid]) if not cursor.rowcount: + cursor.execute("INSERT INTO alldata VALUES (?, ?)", - [dataid, json.dumps(data)]) + [dataid, compressed_data_buffer]) def init_tables(self): - self.connection.execute('CREATE TABLE alldata (dataid text primary key, data text)') + self.connection.execute('CREATE TABLE alldata (dataid text primary key, data blob)') def read_data(self): self.mtimes, \