Trees | Indices | Help |
---|
|
1 # -*- Mode: Python -*- 2 # vi:si:et:sw=4:sts=4:ts=4 3 4 # Flumotion - a streaming media server 5 # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 6 # Copyright (C) 2010,2011 Flumotion Services, S.A. 7 # All rights reserved. 8 # 9 # This file may be distributed and/or modified under the terms of 10 # the GNU Lesser General Public License version 2.1 as published by 11 # the Free Software Foundation. 12 # This file is distributed without any warranty; without even the implied 13 # warranty of merchantability or fitness for a particular purpose. 14 # See "LICENSE.LGPL" in the source distribution for more information. 15 # 16 # Headers in this file shall remain intact. 17 18 """ 19 functions based on twisted.python.reflect 20 """ 21 22 # FIXME: pychecker: clean up unused imports 23 from twisted.cred.portal import IRealm, Portal 24 from twisted.spread.pb import PBClientFactory 25 26 __version__ = "$Rev$" 27 28 29 ### stolen from twisted.python.reflect and changed 30 ### the version in Twisted 1.3.0 checks length of backtrace as metric for 31 ### ImportError; for me this fails because two lines of ihooks.py are in 32 ### between 33 ### filed as http://www.twistedmatrix.com/users/roundup.twistd/twisted/issue698 34 ### remove this when fixed and depending on new upstream twisted 35 3638 """Get a fully named package, module, module-global object, or attribute. 39 """ 40 names = name.split('.') 41 topLevelPackage = None 42 moduleNames = names[:] 43 while not topLevelPackage: 44 try: 45 trialname = '.'.join(moduleNames) 46 topLevelPackage = __import__(trialname) 47 except ImportError: 48 import sys 49 # if the ImportError happened in the module being imported, 50 # this is a failure that should be handed to our caller. 51 shortname = trialname.split('.')[-1] 52 # if we're on python2.7 the module is wrapped in single quotation 53 # marks thus broking this method that relies on the message ending 54 # with the name that failed. 55 r = str(sys.exc_info()[1]).strip("'") 56 if not (r.startswith('No module named') and 57 r.endswith(shortname)): 58 raise 59 60 #if str(sys.exc_info()[1]) != "No module named %s" % trialname: 61 # raise 62 moduleNames.pop() 63 64 obj = topLevelPackage 65 for n in names[1:]: 66 obj = getattr(obj, n) 67 68 return obj69 70 # Use the method that comes with twisted if we're running on 8.0 or higher. 71 # FIXME: Remove this module when we can depend on Twisted 8.0 72 from twisted import version 73 if (version.major, version.minor, version.micro) >= (8, 0, 0): 74 from twisted.python.reflect import namedAny 75
Trees | Indices | Help |
---|
Generated by Epydoc 3.0.1 on Tue Aug 13 06:17:17 2013 | http://epydoc.sourceforge.net |