Package flumotion :: Package twisted :: Module compat
[hide private]

Source Code for Module flumotion.twisted.compat

 1  # -*- Mode: Python; test-case-name: flumotion.test.test_compat -*- 
 2  # vi:si:et:sw=4:sts=4:ts=4 
 3  # 
 4  # Flumotion - a streaming media server 
 5  # Copyright (C) 2004,2005,2006,2007 Fluendo, S.L. (www.fluendo.com). 
 6  # All rights reserved. 
 7   
 8  # This file may be distributed and/or modified under the terms of 
 9  # the GNU General Public License version 2 as published by 
10  # the Free Software Foundation. 
11  # This file is distributed without any warranty; without even the implied 
12  # warranty of merchantability or fitness for a particular purpose. 
13  # See "LICENSE.GPL" in the source distribution for more information. 
14   
15  # Licensees having purchased or holding a valid Flumotion Advanced 
16  # Streaming Server license may use this file in accordance with the 
17  # Flumotion Advanced Streaming Server Commercial License Agreement. 
18  # See "LICENSE.Flumotion" in the source distribution for more information. 
19   
20  # Headers in this file shall remain intact. 
21   
22  """ 
23  Flumotion Twisted compatibility assistance 
24  """ 
25   
26  import warnings 
27  from twisted.copyright import version 
28   
29 -def filterWarnings(namespace, category):
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
40 -def implementsInterface(object, interface):
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
47 -def implementedBy(object):
48 if version[0] < '2': 49 return getattr(object, '__implements__', ()) 50 else: 51 from zope.interface import implementedBy 52 return implementedBy(object)
53
54 -def isInterface(object):
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
66 - def implements(*interfaces):
67 frame = sys._getframe(1) 68 locals = frame.f_locals 69 70 # Try to make sure we were called from a class def 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