annotate python/abstract.py @ 230:691b508084f1

fix module
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 10 Jul 2012 16:10:10 -0700
parents fe8befc5bdfc
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
188
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
1
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
2 def abstractmethod(method):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
3 line = method.func_code.co_firstlineno
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
4 filename = method.func_code.co_filename
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
5 def not_implemented(*args, **kwargs):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
6 raise NotImplementedError('Abstract method %s at File "%s", line %s should be implemented by a concrete class' % (repr(method), filename, line))
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
7 return not_implemented
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
8
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
9 class AbstractBaseClass(object):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
10
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
11 @abstractmethod
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
12 def foo(self, arg):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
13 """foo does such and such"""
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
14
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
15 @abstractmethod
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
16 def bar(self):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
17 """bar does something else"""
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
18
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
19 class ConcreteClass(AbstractBaseClass):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
20
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
21 def foo(self, arg):
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
22 print 'hello'
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
23
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
24 if __name__ == '__main__':
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
25 c = ConcreteClass()
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
26 c.foo(1)
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
27 a = AbstractBaseClass()
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
28 try:
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
29 a.foo(1)
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
30 except NotImplementedError, e:
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
31 print e
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
32 try:
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
33 a.bar()
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
34 except NotImplementedError, e:
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
35 print e
189
fe8befc5bdfc add another print just for fun
Jeff Hammel <jhammel@mozilla.com>
parents: 188
diff changeset
36 c.foo(1)
188
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
37 a.foo(1)
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
38
5b82653ccda3 add demonstration of abc error
Jeff Hammel <jhammel@mozilla.com>
parents:
diff changeset
39