summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Bolen <db3l.net@gmail.com>2013-10-06 19:23:14 -0400
committerStephan Bergmann <sbergman@redhat.com>2013-10-07 15:15:36 +0200
commit2665c114f0adc466efa6ab49cd54d8f633f112fa (patch)
treebe9655b695d5203269e09c2e5a71fabae12656bf
parentfacd4bb410ce6b5f6d74f836affc7553babb05cf (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> (cherry picked from commit df1076965f63eedc6cc104c96b993ab598b8b1d4)
-rw-r--r--pyuno/source/module/uno.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py
index d99884a64d68..e887d860f80f 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