1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Flumotion Twisted compatibility assistance
24 """
25
26 import warnings
27 from twisted.copyright import version
28
30 """
31 Filter the given warnings category from the given namespace if it exists.
32
33 @type category: string
34 """
35 if not hasattr(namespace, category):
36 return
37 c = getattr(namespace, category)
38 warnings.filterwarnings('ignore', category=c)
39
41 if version[0] < '2':
42 from twisted.python import components
43 return components.implements(object, interface)
44 else:
45 return interface.providedBy(object)
46
53
55 if version[0] < '2':
56 raise NotImplementedError()
57 from zope.interface.interface import InterfaceClass
58 return isinstance(object, InterfaceClass)
59
60 if version[0] < '2':
61 from twisted.python.components import Interface as OurLovelyInterface
62 import sys
63
64 Interface = OurLovelyInterface
65
67 frame = sys._getframe(1)
68 locals = frame.f_locals
69
70
71 if (locals is frame.f_globals) or ('__module__' not in locals):
72 raise TypeError("implements can be used only from a class definition.")
73
74 if '__implements__' in locals:
75 raise TypeError("implements can be used only once in a class definition.")
76
77 locals['__implements__'] = interfaces
78
79
80 else:
81 from zope.interface import Interface as OurLovelyInterface
82 from zope.interface import implements as OurLovelyImplements
83
84 Interface = OurLovelyInterface
85 implements = OurLovelyImplements
86