I have an versioned document store which I want to access through an dict like interface. Common usage is to access the latest revision (get, set, del), but one should be able to access specific revisions too (keys are always str/unicode or int).
from UserDict import DictMixin
class VDict(DictMixin):
def __getitem__(self, key):
if isinstance(key, tuple):
docid, rev = key
else:
docid = key
rev = None # set to tip rev
print docid, rev
# return ...
In [1]: d = VDict()
In [2]: d[2]
2 None
In [3]: d[2, 1]
2 1
This solution is a little bit tricky and I'm not sure if it is a clean, understandable interface. Should I provide a function
def getrev(self, docid, rev):
...
instead?