[Pydev-cvs] org.python.pydev/PySrc importsTipper.py,1.7,1.8
Brought to you by:
fabioz
From: Fabio Z. <fa...@us...> - 2005-07-29 18:00:42
|
Update of /cvsroot/pydev/org.python.pydev/PySrc In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21543/PySrc Modified Files: importsTipper.py Log Message: Index: importsTipper.py =================================================================== RCS file: /cvsroot/pydev/org.python.pydev/PySrc/importsTipper.py,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** importsTipper.py 17 Mar 2005 17:07:50 -0000 1.7 --- importsTipper.py 29 Jul 2005 18:00:34 -0000 1.8 *************** *** 13,68 **** ! ! def find_class( module, name): ! __import__(module) ! mod = sys.modules[module] ! klass = getattr(mod, name) ! return klass ! ! ! def FindClass( p_full_class_ ): ! import types ! type = p_full_class_.split('.') ! module_ = '.'.join( type[:-1] ) ! class_ = type[-1] ! ! if class_ == 'NoneType': ! return types.NoneType ! ! if module_: ! return find_class( module_, class_ ) ! else: ! return eval( class_ ) ! ! def _genMod( toks ): ! ret = '' ! ! for t in toks: ! if len(ret) > 0: ! ret += '.' ! ret += t ! ! return ret ! ! def ImportMod(name): ! ''' ! Method used to import a module from a string. ! ''' components = name.split('.') - - raised = False - for c in components: - if not raised: - try: - mod = __import__(c) - except: - raised = True - - if raised: - mod = getattr(mod, c) - - return mod --- 13,36 ---- + def _imp(name): + try: + return __import__(name) + except: + import sys;exc_info = sys.exc_info() + import traceback;traceback.print_exception(exc_info[0], exc_info[1], exc_info[2], file = f) + if '.' in name: + sub = name[0:name.rfind('.')] + return _imp(sub) + else: + s = 'Unable to import module: %s - sys.path: %s' % (str(name), sys.path) + raise RuntimeError(s) ! def Find( name ): ! mod = _imp(name) components = name.split('.') + for comp in components[1:]: + mod = getattr(mod, comp) + return mod *************** *** 72,81 **** data = data.rstrip( '.' ) ! ! try: ! mod = FindClass( data ) ! except: ! mod = ImportMod( data ) ! return GenerateImportsTipForModule( mod ) --- 40,46 ---- data = data.rstrip( '.' ) ! mod = Find( data ) ! tips = GenerateImportsTipForModule( mod ) ! return tips *************** *** 100,104 **** r += ', ' r += str( a ) ! args = '( %s )' % (r) except TypeError: --- 65,69 ---- r += ', ' r += str( a ) ! args = '(%s)' % (r) except TypeError: |