1import logging
2import_stmts = (
3    'from pysnappy2 import snappy',
4    'from pysnappy2_24 import snappy'
5)
6
7for status, stmt in enumerate(import_stmts):
8    try:
9        exec stmt
10        break
11    except ImportError:
12        status = None
13#if status is None:
14#    logging.warn("could not import snappy module. Compress/uncompress function will be skipped.")
15
16def uncompress(data, decoding=None):
17    try:
18        return snappy.uncompress(data, decoding)
19    except Exception, err:
20        return data
21
22def compress(data, encoding='utf-8'):
23    try:
24        return snappy.compress(data, encoding)
25    except Exception, err:
26        return data
27