+try:
+ from gzip import compress, decompress
+except ImportError:
+ # Python < 3.2
+ from gzip import GzipFile
+ from StringIO import StringIO
+
+ def compress(data):
+ compressed = StringIO()
+ GzipFile(fileobj=compressed, mode="wb").write(data)
+ return compressed.getvalue()
+
+ def decompress(data):
+ return GzipFile(fileobj=StringIO(data)).read()
+