forked from lvh/axiombook
-
Notifications
You must be signed in to change notification settings - Fork 1
/
transformers.py
46 lines (29 loc) · 924 Bytes
/
transformers.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
from axiom import attributes, item
from twisted.internet import defer
from zope import interface
class IRobot(interface.Interface):
def attack(target):
"""
Attacks the target.
"""
class ICar(interface.Interface):
def drive(location):
"""
Drives to location.
"""
@interface.implementer(IRobot)
class Transformer(item.Item):
name = attributes.text(allowNone=False)
damage = attributes.integer(allowNone=False)
def attack(self, target):
print "{s} hits {t} for {s.damage} damage!".format(s=self, t=target)
@interface.implementer(ICar)
class Truck(item.Item):
wheels = attributes.integer(default=18)
def drive(self, location):
return defer.succeed(None)
@interface.implementer(ICar)
class HotRod(item.Item):
color = attributes.text(allowNone=False)
def drive(self, location):
return defer.succeed(None)