pyuno/source/module/uno.py | 81 ++++++++++++++++++++++++++------------------- 1 file changed, 47 insertions(+), 34 deletions(-)
New commits: commit d6c63c9a84d989bdb8671c4f42be9acbf37d0309 Author: Stephan Bergmann <sberg...@redhat.com> Date: Mon Jul 29 11:34:59 2013 +0200 Remove whitespace from line ends Change-Id: Ie894879eaebda32bc4f99e7ad7f810c569e86a7a diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index 1b25816..2396641 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -40,8 +40,8 @@ _g_delegatee = __builtin__.__dict__["__import__"] def getComponentContext(): """ returns the UNO component context, that was used to initialize the python runtime. - """ - return _g_ctx + """ + return _g_ctx def getConstantByName( constant ): "Looks up the value of a idl constant by giving its explicit name" @@ -50,7 +50,7 @@ def getConstantByName( constant ): def getTypeByName( typeName): """ returns a uno.Type instance of the type given by typeName. In case the type does not exist, a com.sun.star.uno.RuntimeException is raised. - """ + """ return pyuno.getTypeByName( typeName ) def createUnoStruct( typeName, *args, **kwargs ): @@ -82,7 +82,7 @@ def isInterface( obj ): def generateUuid(): "returns a 16 byte sequence containing a newly generated uuid or guid, see rtl/uuid.h " - return pyuno.generateUuid() + return pyuno.generateUuid() def systemPathToFileUrl( systemPath ): "returns a file-url for the given system path" @@ -112,9 +112,9 @@ def setCurrentContext( newContext ): """ return pyuno.setCurrentContext( newContext ) - + class Enum: - "Represents a UNO idl enum, use an instance of this class to explicitly pass a boolean to UNO" + "Represents a UNO idl enum, use an instance of this class to explicitly pass a boolean to UNO" #typeName the name of the enum as a string #value the actual value of this enum as a string def __init__(self,typeName, value): @@ -150,7 +150,7 @@ class Type: return self.typeName.__hash__() class Bool(object): - """Represents a UNO boolean, use an instance of this class to explicitly + """Represents a UNO boolean, use an instance of this class to explicitly pass a boolean to UNO. Note: This class is deprecated. Use python's True and False directly instead """ @@ -173,13 +173,13 @@ class Char: def __repr__(self): return "<Char instance %s>" % (self.value, ) - + def __eq__(self, that): if isinstance(that, (str, unicode)): if len(that) > 1: return False return self.value == that[0] - if isinstance(that, Char): + if isinstance(that, Char): return self.value == that.value return False @@ -190,12 +190,12 @@ class Char: # def __repr__(self): # return "<ByteSequence instance %s>" % str.__repr__(self) - # for a little bit compatitbility; setting value is not possible as + # for a little bit compatitbility; setting value is not possible as # strings are immutable # def _get_value(self): # return self # -# value = property(_get_value) +# value = property(_get_value) class ByteSequence: def __init__(self, value): @@ -254,7 +254,7 @@ class Any: def invoke( object, methodname, argTuple ): "use this function to pass exactly typed anys to the callee (using uno.Any)" return pyuno.invoke( object, methodname, argTuple ) - + #--------------------------------------------------------------------------------------- # don't use any functions beyond this point, private section, likely to change #--------------------------------------------------------------------------------------- @@ -286,7 +286,7 @@ def _uno_import( name, *optargs, **kwargs ): if x not in d: failed = False if x.startswith( "typeOf" ): - try: + try: d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] ) except RuntimeException: failed = True @@ -295,7 +295,7 @@ def _uno_import( name, *optargs, **kwargs ): # check for structs, exceptions or interfaces d[x] = pyuno.getClass( name + "." + x ) except RuntimeException: - # check for enums + # check for enums try: d[x] = Enum( name , x ) except RuntimeException: @@ -309,7 +309,7 @@ def _uno_import( name, *optargs, **kwargs ): # We have an import failure, but cannot distinguish between # 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, @@ -321,7 +321,7 @@ def _uno_import( name, *optargs, **kwargs ): # Our exception is raised outside of the nested exception # handlers above, to avoid Python 3 nested exception # information for the RuntimeExceptions during lookups. - # + # # Finally, a private attribute is used to prevent further # processing if this failure was in a nested import. That # keeps the exception relevant to the primary failure point, @@ -342,7 +342,7 @@ def _impl_extractName(name): if name[i] == ".": name = name[i+1:len(name)] break - return name + return name # private, referenced from the pyuno shared library def _uno_struct__init__(self,*args, **kwargs): @@ -355,7 +355,7 @@ def _uno_struct__init__(self,*args, **kwargs): RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" ) raise RuntimeException("_uno_struct__init__: unused keyword argument '" + kw + "'", None) self.__dict__["value"] = struct - + # private, referenced from the pyuno shared library def _uno_struct__getattr__(self,name): return __builtin__.getattr(self.__dict__["value"],name) commit 948b6ea02ea9de7fb4e1e2baf95ecae3ba1cd54e Author: David Bolen <db3l....@gmail.com> Date: Fri Jul 26 14:59:48 2013 -0400 fdo#66025: Improve accuracy of ImportError traceback and message The ImportError raised on an import failure with the uno module loaded now includes a complete traceback and the original Python exception message text, combined with the most relevant (nearest to failure if imports are nested) uno lookup that also failed. Change-Id: Id968d84d7f09d555a81017a99369beb503d61439 Signed-off-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/pyuno/source/module/uno.py b/pyuno/source/module/uno.py index 15af94a..1b25816 100644 --- a/pyuno/source/module/uno.py +++ b/pyuno/source/module/uno.py @@ -263,11 +263,14 @@ 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: + # from import form only, but skip if an uno lookup has already failed + if not fromlist or hasattr(e, '_uno_import_failed'): raise + # hang onto exception for possible use on subsequent uno lookup failure + py_import_exc = e modnames = name.split( "." ) mod = None d = sys.modules @@ -303,22 +306,32 @@ def _uno_import( name, *optargs, **kwargs ): failed = True if failed: - # 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 + # We have an import failure, but cannot distinguish between + # 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. + # This is more ambiguous, but it plus the traceback should be + # sufficient to identify a root cause for python or uno issues. + # + # Our exception is raised outside of the nested exception + # handlers above, to avoid Python 3 nested exception + # information for the RuntimeExceptions during lookups. + # + # Finally, a private attribute is used to prevent further + # processing if this failure was in a nested import. That + # 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._uno_import_failed = True + raise uno_import_exc return mod _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits