File: Map.py

package info (click to toggle)
zope-cmfsin 0.6.1-5
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 156 kB
  • ctags: 164
  • sloc: python: 752; makefile: 30; sh: 2
file content (40 lines) | stat: -rw-r--r-- 1,108 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import ZODB
from ZODB.PersistentMapping import PersistentMapping
from OFS.SimpleItem import SimpleItem
from OrderPolicy import defaultPolicy, lookupPolicy, listPolicies, _policy

class Map(SimpleItem):
    def __init__(self, id):
        self.id = id
        self.channels = PersistentMapping()
        self.policy = defaultPolicy

    def setPolicy(self, name):
        self.policy = lookupPolicy(name, defaultPolicy)

    def setPriority(self, channel, pri):
        if not isinstance(channel, Channel):
            id = channel.id
        else:
            id = channel

        channel = self.channels[id]
        channel['priority'] = int(pri)


    def addChannel(self, channel, **kwargs):
        enabled  = kwargs.get('enabled', 1)
        priority = kwargs.get('priority', 0)

        self.channels[channel.id] = {'channel' : channel,
                                     'enabled' : enabled,
                                     'priority': priority,
                                     }
    def Channels(self):
        return self.channels.values()