dk.collections¶
Inversable dictionary.
- class dk.collections.invdict.invdict[source]¶
Inversable dict:
>>> -invdict({'key': 'val'}) == {'val': 'key'}
- class dk.collections.mmap.mmap(**attrs)[source]¶
Multi Map class, ie. a key/value collection where each key can occur multiple times. Implemented as a list of key/value tuples.
Ordered Set. Items can only be added once, further additions have no effect. The iterator iterates over the items in insertion order.
- class dk.collections.OrderedSet.oset(iterable=())[source]¶
Ordered Set. Items can only be added once, further additions have no effect. The iterator iterates over the items in insertion order.
Mapping classes.
- class dk.collections.pset.keyval¶
keyval(key, val)
- key¶
Alias for field number 0
- val¶
Alias for field number 1
- class dk.collections.pset.pset(items=(), **attrs)[source]¶
This code is placed in the Public Domain, or released under the wtfpl (http://sam.zoy.org/wtfpl/COPYING) wherever PD is problematic.
Property Set class. A property set is an object where values are attached to attributes, but can still be iterated over as key/value pairs. The order of assignment is maintained during iteration. Only one value allowed per key.
>>> x = pset() >>> x.a = 42 >>> x.b = 'foo' >>> x.a = 314 >>> x pset(a=314, b='foo')
- class dk.collections.pset.record(items=(), **attrs)[source]¶
A property set with commit, rollback, and encoding translation.
- dk.collections.pset.test_pset()[source]¶
Unit tests...
>>> request = pset(REQUEST={}, META={}, path='/', user=None, session={}, method='GET', ... COOKIES={}, LANGUAGE_CODE='no') >>> p = page(request) >>> p.forms = 'fruit' >>> p.forms.foo = 'bar' >>> print p.forms.foo bar >>> p.forms.fob = 'baz' >>> print p.forms.fob baz >>> x = pset() >>> x.a Traceback (most recent call last): ... AttributeError: a >>> y = pset(a=1, b=2, c=3) >>> y.a 1 >>> y.b 2 >>> y.c 3 >>> z = pset() >>> z.a = 1 >>> z.b = 2 >>> z.c = 3 >>> z[1] 2 >>> z pset(a=1, b=2, c=3) >>> class Point(pset): pass >>> p = Point(x=11, y=22) >>> p Point(y=22, x=11)