summaryrefslogtreecommitdiff
path: root/pyuno
diff options
context:
space:
mode:
authorDavid Bolen <db3l.net@gmail.com>2013-07-24 09:57:03 +0200
committerStephan Bergmann <sbergman@redhat.com>2013-07-24 10:04:44 +0200
commit7fd81244c21ad54a8b9766902fd7c34e8055b165 (patch)
tree23f8d1601b9d8dfc51d7b86492e3ca4bfdf792fa /pyuno
parent794a1f8e685216d6bbf5f753b04138a2711ce62d (diff)
fdo#66025: Improve ImportError raised from _uno_import
Change-Id: I92301f0c37d69e5977a12ab4d5a360f7a4ff20fe Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'pyuno')
-rw-r--r--pyuno/source/module/uno.py39
1 files changed, 31 insertions, 8 deletions
diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py
index 86011f3b4c97..62ad01fb9be3 100644
--- a/pyuno/source/module/uno.py
+++ b/pyuno/source/module/uno.py
@@ -263,7 +263,7 @@ def _uno_import( name, *optargs, **kwargs ):
try:
# print "optargs = " + repr(optargs)
return _g_delegatee( name, *optargs, **kwargs )
- except ImportError:
+ except ImportError as e:
# process optargs
globals, locals, fromlist = list(optargs)[:3] + [kwargs.get('globals',{}), kwargs.get('locals',{}), kwargs.get('fromlist',[])][len(optargs):]
if not fromlist:
@@ -279,28 +279,51 @@ def _uno_import( name, *optargs, **kwargs ):
d = mod.__dict__
RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
+ unknown = object() # unknown/missing sentinel
for x in fromlist:
if x not in d:
+ d[x] = unknown
if x.startswith( "typeOf" ):
try:
d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] )
- except RuntimeException as e:
- raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" )
+ except RuntimeException:
+ pass
else:
try:
# check for structs, exceptions or interfaces
d[x] = pyuno.getClass( name + "." + x )
- except RuntimeException as e:
+ except RuntimeException:
# check for enums
try:
d[x] = Enum( name , x )
- except RuntimeException as e2:
+ except RuntimeException:
# check for constants
try:
d[x] = getConstantByName( name + "." + x )
- except RuntimeException as e3:
- # no known uno type !
- raise ImportError( "type "+ name + "." +x + " is unknown" )
+ except RuntimeException:
+ pass
+
+ 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
# private function, don't use