#
##############################################################################
-import cPickle
+import msgpack
from cursor import Cursor
import uuid
class Collection(object):
def __init__(self, database, table_name):
self.database = database
- self.table_name = unicode(table_name)
+ self.table_name = str(table_name)
def __repr__(self):
return "Collection(%r, %r)" % (self.database, self.table_name)
def _get_fields(self):
tables = self.database.connection._get_tables(self.database.db_name)
- return [unicode(x[x.find('$')+1:]) for x in filter(lambda x: x.startswith('%s$' % self.table_name), tables)]
+ return [str(x[x.find('$')+1:]) for x in filter(lambda x: x.startswith('%s$' % self.table_name), tables)]
def count(self):
return self.database.connection._count(self.database.db_name, self.table_name)
else:
docs = doc_or_docs
for doc in docs:
- if not u'_id' in doc:
- doc[u'_id'] = uuid.uuid4().hex
+ if not '_id' in doc:
+ doc['_id'] = uuid.uuid4().hex
self._insert_document(doc)
if type(doc_or_docs) in (list, tuple):
- return [d[u'_id'] for d in docs]
+ return [d['_id'] for d in docs]
else:
- return docs[0][u'_id']
+ return docs[0]['_id']
def _insert_document(self, doc):
table_id = '%s$_id' % self.table_name
fields = self._get_fields()
- coded_id = cPickle.dumps(doc['_id'])
+ coded_id = msgpack.dumps(doc['_id'])
self.database.connection._insert(self.database.db_name, table_id, {'id': coded_id})
for f in doc:
if f == '_id':
table_f = '%s$%s' % (self.table_name, f)
values = {
'id': coded_id,
- 'value': cPickle.dumps(doc[f]),
+ 'value': msgpack.dumps(doc[f]),
}
if type(doc[f]) in (int, float):
values['number'] = doc[f]