Types
Types are used to define the internal storage in ZODB.
There are no need to setup specific types in basic usage of sheraf because Model uses xAttribute, not Type.
- class sheraf.types.SmallDict(**kwargs)[source]
Bases:
PersistentMapping
SmallDict is a
PersistentMapping
implementation with a simple conflict resolution implementation.When two different keys of the mapping are edited in concurrency, no conflict is raised.
- class sheraf.types.counter.Counter(value=0)[source]
Bases:
Persistent
Counter is a simple numeric persistent type with conflict proof increment and decrement functions.
- class sheraf.types.largedict.LargeDict[source]
Bases:
OOBTree
A Large Dictionnary based on a Object-Object-BTree.
LargeDicts keys are ordered and thus they can be iterated:
>>> mydict = sheraf.types.LargeDict({ ... "D": "four", ... "C": "three", ... "B": "two", ... "A": "one", ... }) # declaration is unordered ... >>> list(v for v in mydict.values()) ... # iteration is ordered ['one', 'two', 'three', 'four']
LargeDicts can also be sliced. Slices return a generator over the values:
>>> list(mydict["B":"D"]) ['two', 'three', 'four'] >>> list(mydict[::-1]) ['four', 'three', 'two', 'one']
When using integers as dictionnary keys, be careful that slices behave a bit different than they would do for a list, as we use keys and not indexes.
>>> mydict = sheraf.types.LargeDict({1:"one", 2:"two", 3:"three"}) >>> mylist = ["one", "two", "three"] >>> >>> list(mydict[1:2]) # 1 and 2 are keys ['one', 'two'] >>> >>> mylist[1:2] # 1 and 2 are indices ['two']