dk.collections package

Submodules

dk.collections.OrderedSet module

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]

Bases: set

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]

dk.collections.invdict module

Inversable dictionary.

class dk.collections.invdict.invdict[source]

Bases: dict

Inversable dict:

>>> -invdict({'key': 'val'}) == {'val': 'key'}

dk.collections.mmap module

class dk.collections.mmap.mmap(**attrs)[source]

Bases: list

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]

dk.collections.pset module

Mapping classes.

class dk.collections.pset.defset(defval)[source]

Bases: dk.collections.pset.pset

pset with default value.

class dk.collections.pset.keyval(key, val)

Bases: tuple

key

Alias for field number 0

val

Alias for field number 1

class dk.collections.pset.pset(items=(), **attrs)[source]

Bases: dict

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]

Bases: dk.collections.pset.pset

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

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)
dk.collections.pset.xmlrepr(v, toplevel=False)[source]

Return v as xml tag-soup.

dk.collections.sdict module

class dk.collections.sdict.sdict(**attrs)[source]

Bases: dict

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 module

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]

Bases: dk.collections.pset.pset

convert = {'date': <function Date>, 'int': <type 'int'>, 'NOK': <function NOK>, 'bool': <function Boolean>, 'datetime': <function Datetime>}

Module contents

Abstract Data Types – mostly record types with different semantics.