import zlib
import cPickle
import sqlite3
import numpy
import collections

from gemini_utils import OrderedDict

# http://stackoverflow.com/questions/695794/more-efficient-way-to-
# pickle-a-string

def pack_blob(obj):
    return sqlite3.Binary(zdumps(obj))

def unpack_genotype_blob(blob):
    return cPickle.loads(zlib.decompress(blob))
    
def unpack_ordereddict_blob(blob):
	blob_val = cPickle.loads(zlib.decompress(blob))
	if blob_val is not None:
	    return OrderedDict(blob_val)
	return None

def zdumps(obj):
    return zlib.compress(cPickle.dumps(obj, cPickle.HIGHEST_PROTOCOL), 9)

def zloads(obj):
    return cPickle.loads(zlib.decompress(obj))

@@ -72,24 +72,82 @@
 ns%0A%0A
-from gemini_util
+try:%0A    from cyordereddict import OrderedDict%0Aexcept:%0A    from collection
 s im
@@ -394,13 +394,9 @@
 b))%0A
-    
 %0A
+
 def 
@@ -426,17 +426,20 @@
 (blob):%0A
-%09
+    
 blob_val
@@ -478,17 +478,20 @@
 (blob))%0A
-%09
+    
 if blob_
@@ -507,17 +507,20 @@
 t None:%0A
-%09
+    
     retu
@@ -548,9 +548,12 @@
 al)%0A
-%09
+    
 retu

indent and import