]> git.jsancho.org Git - mojodb.git/blobdiff - cursor.py
Custom serializer in connection object; default is msgpack
[mojodb.git] / cursor.py
index 6246872c35ab3c66c2d1d5c32c949deb22565864..eec8b65e71d865e7b0bc6fd1112d11cd4d4f06f1 100644 (file)
--- a/cursor.py
+++ b/cursor.py
@@ -19,7 +19,6 @@
 #
 ##############################################################################
 
-import msgpack
 
 class Cursor(object):
     def __init__(self, collection, spec=None, fields=None, **kwargs):
@@ -32,6 +31,8 @@ class Cursor(object):
         self.Constraint = collection.database.connection.Constraint
         self.Literal = collection.database.connection.Literal
 
+        self.serializer = collection.database.connection.serializer
+
         self.collection = collection
         self.spec = spec
         if self.collection.exists():
@@ -116,7 +117,7 @@ class Cursor(object):
             field_type = 'number'
         else:
             field_type = 'value'
-            field_value = msgpack.dumps(field_value)
+            field_value = self.serializer.dumps(field_value)
 
         fields = [self.Field(table_field, 'id')]
         tables = [table_field]
@@ -139,11 +140,11 @@ class Cursor(object):
             else:
                 document = {}
                 if '_id' in self.fields:
-                    document['_id'] = msgpack.loads(res[0])
+                    document['_id'] = self.serializer.loads(res[0])
                 fields_without_id = filter(lambda x: x != '_id', self.fields)
                 for i in xrange(len(fields_without_id)):
                     if not res[i + 1] is None:
-                        document[fields_without_id[i]] = msgpack.loads(res[i + 1])
+                        document[fields_without_id[i]] = self.serializer.loads(res[i + 1])
                 return document
         else:
             return None