diff options
author | David Bolen <db3l.net@gmail.com> | 2013-10-06 19:23:14 -0400 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2013-10-07 15:10:54 +0200 |
commit | df1076965f63eedc6cc104c96b993ab598b8b1d4 (patch) | |
tree | d3110bcb5ef576378d88a20a37f91533a13b17d7 /pyuno/source | |
parent | 597e198022c1e1393b78f346aa7eb00b521065ab (diff) |
fdo#70196: Python 2 compatibility for UNO import error handling
Add backwards compatibility support for Python 2 to the earlier
change in fdo#66025 to improve import error handling under Python 3.
Change-Id: I47bf8ef255c4c2a3e4a2754414977aaa8ed32483
Signed-off-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'pyuno/source')
-rw-r--r-- | pyuno/source/module/uno.py | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index 2396641e865c..6f8744bc0348 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -310,11 +310,11 @@ def _uno_import( name, *optargs, **kwargs ): # uno and non-uno errors as uno lookups are attempted for all # "from xxx import yyy" imports following a python failure. # - # The traceback from the original python exception is kept to - # pinpoint the actual failing location, but in Python 3 the - # original message is most likely unhelpful for uno failures, - # as it will most commonly be a missing top level module, - # like 'com'. Our exception appends the uno lookup failure. + # In Python 3, the original python exception traceback is reused + # to help pinpoint the actual failing location. Its original + # message, unlike Python 2, is unlikely to be helpful for uno + # failures, as it most commonly is just a top level module like + # 'com'. So our exception appends the uno lookup failure. # This is more ambiguous, but it plus the traceback should be # sufficient to identify a root cause for python or uno issues. # @@ -327,9 +327,10 @@ def _uno_import( name, *optargs, **kwargs ): # keeps the exception relevant to the primary failure point, # preventing us from re-processing our own import errors. - uno_import_exc = ImportError( - "%s (or '%s.%s' is unknown)" % (py_import_exc, name, x) - ).with_traceback(py_import_exc.__traceback__) + uno_import_exc = ImportError("%s (or '%s.%s' is unknown)" % + (py_import_exc, name, x)) + if sys.version_info[0] >= 3: + uno_import_exc = uno_import_exc.with_traceback(py_import_exc.__traceback__) uno_import_exc._uno_import_failed = True raise uno_import_exc |