Commit fec86e26 authored by Julien Muchembled's avatar Julien Muchembled

fixup! Add support for custom compression levels

parent 0c34630c
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
# You should have received a copy of the GNU General Public License # You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>. # along with this program. If not, see <http://www.gnu.org/licenses/>.
from functools import partial
import zlib import zlib
decompress_list = ( decompress_list = (
...@@ -40,7 +39,8 @@ def getCompress(value): ...@@ -40,7 +39,8 @@ def getCompress(value):
alg, level = (0, None) if value is True else value alg, level = (0, None) if value is True else value
_compress = zlib.compress _compress = zlib.compress
if level: if level:
_compress = partial(_compress, level=level) zlib_compress = _compress
_compress = lambda data: zlib_compress(data, level)
alg += 1 alg += 1
assert 0 < alg < len(decompress_list), 'invalid compression algorithm' assert 0 < alg < len(decompress_list), 'invalid compression algorithm'
def compress(data): def compress(data):
......
...@@ -55,8 +55,8 @@ class ConfigTests(NEOThreadedTest): ...@@ -55,8 +55,8 @@ class ConfigTests(NEOThreadedTest):
for kw['compress'] in '9', 'best', 'zlib=0', 'zlib=100': for kw['compress'] in '9', 'best', 'zlib=0', 'zlib=100':
self.assertRaises(ConfigurationSyntaxError, databaseFromDict, **kw) self.assertRaises(ConfigurationSyntaxError, databaseFromDict, **kw)
for compress in valid: for compress in valid:
with self._db(cluster, compress=compress): with self._db(cluster, compress=compress) as db:
pass self.assertEqual((0,0,''), db.storage.app.compress(''))
if __name__ == "__main__": if __name__ == "__main__":
unittest.main() unittest.main()
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment