| Home | Trees | Indices | Help |
|
|---|
|
|
1 """L{dict} based collection"""
2 import cPickle
3 import os.path
4
5 from grassyknoll.collection import Collection
6
8 """an in-memory collection"""
9
12
15
16 @Collection.addMetaData
19
20 @Collection.addMetaData
22 for doc in docs:
23 self.data[doc.id]=doc
24 return Collection.CollectionIds([doc.id for doc in docs])
25
26 @Collection.addMetaData
31
32 @Collection.addMetaData
34 results=[]
35 for uid in ids:
36 doc=self.data.get(uid)
37 if doc is not None:
38 assert isinstance(doc, Collection.CollectionDocument)
39 if fields is None:
40 res=Collection.CollectionResult(doc)
41 else:
42 if '__id__' not in fields: fields+=('__id__',)
43 res=Collection.CollectionResult(dict((k, v) for k, v
44 in doc.iteritems()
45 if k in fields))
46 results.append(res)
47
48 return Collection.CollectionResultSet(results)
49
50 # no point testing this
52 """a L{DictCollection} that saves to a pickle"""
53
55 super(PersistentDictCollection, self).__init__()
56 self.fname=fname
57 if os.path.exists(fname):
58 self.data=cPickle.load(file(fname, 'r'))
59 assert isinstance(self.data, dict)
60
62 cPickle.dump(self.data, file(self.fname, 'w'), -1)
63
| Home | Trees | Indices | Help |
|
|---|
| Generated by Epydoc 3.0beta1 on Mon Mar 10 05:37:17 2008 | http://epydoc.sourceforge.net |