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: persistent.mapping.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.Persistent

Counter is a simple numeric persistent type with conflict proof increment and decrement functions.

class sheraf.types.largedict.LargeDict[source]

Bases: BTrees.OOBTree.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']
class sheraf.types.largelist.LargeList(items=None)[source]

Bases: BTrees.IOBTree.IOBTree

Large List.

insert(key, value) 0 or 1[source]

Add an item if the key is not already used. Return 1 if the item was added, or 0 otherwise.

pop(k[, d]) v, remove key and return the corresponding value.[source]

If key is not found, d is returned if given, otherwise KeyError is raised.