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.
-
add(key, val)[source]
-
append(kv)[source]
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.
-
add(item)[source]
Mapping classes.
-
class dk.collections.pset.defset(defval)[source]
pset with default value.
-
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')
-
apply(fn)[source]
Apply function fn to all values in self.
-
items()[source]
-
keys()[source]
-
pprint(indent=0, tab=' ', seen=None)[source]
Pretty print the pset, indented.
-
remove(key)[source]
Remove key from client vars.
-
values()[source]
-
class dk.collections.pset.record(items=(), **attrs)[source]
A property set with commit, rollback, and encoding translation.
-
changed()[source]
Return list of fields that have changed since last commit.
-
commit()[source]
Copy current state to self._history
-
decode(encoding)[source]
Decode using encoding.
-
encode(encoding)[source]
Encode using encoding.
-
fields[source]
Verbose name of all fields.
-
rollback()[source]
Copy snapshot from self._history into self.
-
strvals(empty='', none='NULL', encoding='u8')[source]
Return a list of all values, formatted for human consumption.
-
trans(source='iso-8859-1', dest='utf-8')[source]
Translate encoding.
-
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)
Traceback (most recent call last):
...
AttributeError: a
-
class dk.collections.sdict.sdict(**attrs)[source]
Sorted Dictionary class.
Iterating over the sdict will give back the key/value pairs in
order of insertion. A key can only be in a sdict once.
-
keys()[source]
-
values()[source]
-
dk.collections.xmlrec.Boolean(s)[source]
-
dk.collections.xmlrec.Date(s)[source]
-
dk.collections.xmlrec.Datetime(s)[source]
-
dk.collections.xmlrec.NOK(s)[source]
-
class dk.collections.xmlrec.xmlrec(soup, **types)[source]
-
convert = {'date': <function Date at 0x04A40E70>, 'int': <type 'int'>, 'NOK': <function NOK at 0x04706670>, 'bool': <function Boolean at 0x046FB7F0>, 'datetime': <function Datetime at 0x04706C30>}