-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathstack.py
57 lines (40 loc) · 1.18 KB
/
stack.py
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
# Copyright (C) 2012 Buttinsky Developers.
# See 'COPYING' for copying permission.
class Message(object):
def __init__(self, data="", left=""):
self.data = data
if not left:
self.left = ""
else:
self.left = left
class Layer(object):
def __init__(self, plugin, lower=None, upper=None):
self.plugin = plugin
self.upper = upper
self.lower = lower
def setLower(self, lower):
self.lower = lower
def setUpper(self, upper):
self.upper = upper
def transmit(self, msg):
msg = self.plugin.transmit(msg)
if self.lower:
self.lower.transmit(msg)
def receive(self, msg):
msg = self.plugin.receive(msg)
if self.upper:
self.upper.receive(msg)
else:
self.transmit(msg)
def settings(self, settings):
self.plugin.settings(settings)
class LayerPlugin(object):
def __init__(self):
pass
def transmit(self, msg):
raise NotImplementedError
def receive(self, msg):
raise NotImplementedError
def settings(self, settings):
raise NotImplementedError