Kaydet (Commit) 7fd81244 authored tarafından David Bolen's avatar David Bolen Kaydeden (comit) Stephan Bergmann

fdo#66025: Improve ImportError raised from _uno_import

Change-Id: I92301f0c37d69e5977a12ab4d5a360f7a4ff20fe
Signed-off-by: 's avatarStephan Bergmann <sbergman@redhat.com>
üst 794a1f8e
...@@ -263,7 +263,7 @@ def _uno_import( name, *optargs, **kwargs ): ...@@ -263,7 +263,7 @@ def _uno_import( name, *optargs, **kwargs ):
try: try:
# print "optargs = " + repr(optargs) # print "optargs = " + repr(optargs)
return _g_delegatee( name, *optargs, **kwargs ) return _g_delegatee( name, *optargs, **kwargs )
except ImportError: except ImportError as e:
# process optargs # process optargs
globals, locals, fromlist = list(optargs)[:3] + [kwargs.get('globals',{}), kwargs.get('locals',{}), kwargs.get('fromlist',[])][len(optargs):] globals, locals, fromlist = list(optargs)[:3] + [kwargs.get('globals',{}), kwargs.get('locals',{}), kwargs.get('fromlist',[])][len(optargs):]
if not fromlist: if not fromlist:
...@@ -279,28 +279,51 @@ def _uno_import( name, *optargs, **kwargs ): ...@@ -279,28 +279,51 @@ def _uno_import( name, *optargs, **kwargs ):
d = mod.__dict__ d = mod.__dict__
RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" ) RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
unknown = object() # unknown/missing sentinel
for x in fromlist: for x in fromlist:
if x not in d: if x not in d:
d[x] = unknown
if x.startswith( "typeOf" ): if x.startswith( "typeOf" ):
try: try:
d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] ) d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] )
except RuntimeException as e: except RuntimeException:
raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" ) pass
else: else:
try: try:
# check for structs, exceptions or interfaces # check for structs, exceptions or interfaces
d[x] = pyuno.getClass( name + "." + x ) d[x] = pyuno.getClass( name + "." + x )
except RuntimeException as e: except RuntimeException:
# check for enums # check for enums
try: try:
d[x] = Enum( name , x ) d[x] = Enum( name , x )
except RuntimeException as e2: except RuntimeException:
# check for constants # check for constants
try: try:
d[x] = getConstantByName( name + "." + x ) d[x] = getConstantByName( name + "." + x )
except RuntimeException as e3: except RuntimeException:
# no known uno type ! pass
raise ImportError( "type "+ name + "." +x + " is unknown" )
if d[x] is unknown:
# Remove unknown placeholder we created
del d[x]
# This can be a bad uno reference, or it can just result from any
# python import failure (in a "from xxx import yyy" statement).
# Synthesize a general purpose exception, reusing the original
# traceback to provide information for either case. We don't use
# the original python exception as uno failures will typically
# just reflect a missing top level module (such as "com").
# Note that we raise this outside of the nested exception handlers
# above, or otherwise Python 3 will generate additional tracebacks
# for each of the nested exceptions.
e = ImportError("No module named '%s' or '%s.%s' is unknown" %
(name, name, x))
e.__traceback__ = sys.exc_info()[2]
raise e
return mod return mod
# private function, don't use # private function, don't use
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment