Example #1
0
def getTypeByName(typeName):
    """Returns a `uno.Type` instance of the type given by typeName.

    If the type does not exist, a `com.sun.star.uno.RuntimeException` is raised.
    """

    return pyuno.getTypeByName(typeName)
Example #2
0
File: uno.py Project: hanya/pyuno3
    def __getattr__(self, elt):
        value = None

        RuntimeException = pyuno.getClass("com.sun.star.uno.RuntimeException")
        try:
            value = pyuno.getClass(self.__path__ + "." + elt)
        except RuntimeException:
            try:
                value = Enum(self.__path__, elt)
            except RuntimeException:
                try:
                    value = pyuno.getConstantByName(self.__path__ + "." + elt)
                except RuntimeException:
                    if elt.startswith("typeOf"):
                        try:
                            value = pyuno.getTypeByName(self.__path__ + "." + elt[6:])
                        except RuntimeException:
                            raise AttributeError("type {}.{} is unknown".format(self.__path__, elt))
                    elif elt == "__all__":
                        try:
                            module_names = pyuno.getModuleElementNames(self.__path__)
                            self.__all__ = module_names
                            return module_names
                        except RuntimeException:
                            raise AttributeError("__all__")
                    else:
                        raise AttributeError("type {}.{} is unknown".format(self.__path__, elt))
        setattr(self, elt, value)
        return value
Example #3
0
def unotype(name: str) -> uno.Type:
    """
    >>> unotype('com.sun.star.uno.XInterface') # doctest: +NORMALIZE_WHITESPACE
    <Type instance com.sun.star.uno.XInterface
        (<uno.Enum com.sun.star.uno.TypeClass ('INTERFACE')>)>
    """
    return pyuno.getTypeByName(name)
Example #4
0
def getTypeByName(typeName):
    """Returns a `uno.Type` instance of the type given by typeName.

    If the type does not exist, a `com.sun.star.uno.RuntimeException` is raised.
    """

    return pyuno.getTypeByName(typeName)
def _uno_import(name, *optargs, **kwargs):
    try:
        #       print "optargs = " + repr(optargs)
        if len(optargs) == 0:
            return _g_delegatee(name, **kwargs)
        return _g_delegatee(name, *optargs, **kwargs)
    except ImportError:
        # process optargs
        globals, locals, fromlist = list(optargs)[:3] + [
            kwargs.get('globals', {}),
            kwargs.get('locals', {}),
            kwargs.get('fromlist', [])
        ][len(optargs):]
        if not fromlist:
            raise
    modnames = name.split(".")
    mod = None
    d = sys.modules
    for x in modnames:
        if d.has_key(x):
            mod = d[x]
        else:
            mod = pyuno.__class__(x)  # How to create a module ??
        d = mod.__dict__

    RuntimeException = pyuno.getClass("com.sun.star.uno.RuntimeException")
    for x in fromlist:
        if not d.has_key(x):
            if x.startswith("typeOf"):
                try:
                    d[x] = pyuno.getTypeByName(name + "." + x[6:len(x)])
                except RuntimeException, e:
                    raise ImportError("type " + name + "." + x[6:len(x)] +
                                      " is unknown")
            else:
                try:
                    # check for structs, exceptions or interfaces
                    d[x] = pyuno.getClass(name + "." + x)
                except RuntimeException, e:
                    # check for enums
                    try:
                        d[x] = Enum(name, x)
                    except RuntimeException, e2:
                        # check for constants
                        try:
                            d[x] = getConstantByName(name + "." + x)
                        except RuntimeException, e3:
                            # no known uno type !
                            raise ImportError("type " + name + "." + x +
                                              " is unknown")
Example #6
0
def _uno_import( name, *optargs ):
    try:
#       print "optargs = " + repr(optargs)
        if len(optargs) == 0:
           return _g_delegatee( name )
           #print _g_delegatee
        return _g_delegatee( name, *optargs )
    except ImportError:
        if len(optargs) != 3 or not optargs[2]:
           raise
    globals = optargs[0]
    locals = optargs[1]
    fromlist = optargs[2]
    modnames = name.split( "." )
    mod = None
    d = sys.modules
    for x in modnames:
        if d.has_key(x):
           mod = d[x]
        else:
           mod = pyuno.__class__(x)  # How to create a module ??
        d = mod.__dict__

    RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
    for x in fromlist:
       if not d.has_key(x):
          if x.startswith( "typeOf" ):
             try: 
                d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] )
             except RuntimeException,e:
                raise ImportError( "type " + name + "." + x[6:len(x)] +" is unknown" )
          else:
            try:
                # check for structs, exceptions or interfaces
                d[x] = pyuno.getClass( name + "." + x )
            except RuntimeException,e:
                # check for enums 
                try:
                   d[x] = Enum( name , x )
                except RuntimeException,e2:
                   # check for constants
                   try:
                      d[x] = getConstantByName( name + "." + x )
                   except RuntimeException,e3:
                      # no known uno type !
                      raise ImportError( "type "+ name + "." +x + " is unknown" )
Example #7
0
def _uno_import( name, *optargs, **kwargs ):
    try:
#       print "optargs = " + repr(optargs)
        return _g_delegatee( name, *optargs, **kwargs )
    except ImportError:
        # process optargs
        globals, locals, fromlist = list(optargs)[:3] + [kwargs.get('globals',{}), kwargs.get('locals',{}), kwargs.get('fromlist',[])][len(optargs):]
        if not fromlist:
            raise
    modnames = name.split( "." )
    mod = None
    d = sys.modules
    for x in modnames:
        if x in d:
            mod = d[x]
        else:
            mod = pyuno.__class__(x)  # How to create a module ??
        d = mod.__dict__
    
    RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
    for x in fromlist:
        if x not in d:
            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" )
            else:
                try:
                    # check for structs, exceptions or interfaces
                    d[x] = pyuno.getClass( name + "." + x )
                except RuntimeException as e:
                    # check for enums
                    try:
                        d[x] = Enum( name , x )
                    except RuntimeException as e2:
                        # check for constants
                        try:
                            d[x] = getConstantByName( name + "." + x )
                        except RuntimeException as e3:
                            # no known uno type !
                            raise ImportError( "type "+ name + "." +x + " is unknown" )
    return mod
Example #8
0
 def __getattr__(self, name):
     try:
         value = pyuno.importValue(self.__path__, name)
     except:
         if pyuno.hasModule(self.__path__ + "." + name):
             value = _UNOModuleLoader().load_module(self.__path__ + "." + name)
         elif name == "__all__" or name == "*":
             try:
                 module_names = pyuno.getModuleElementNames(self.__path__)
                 self.__all__ = module_names
                 return module_names
             except:
                 raise AttributeError(name)
         elif name.startswith("typeOf"):
             try:
                 value = pyuno.getTypeByName(self.__path__ + "." + name[6:])
             except:
                 raise AttributeError(
                         "type {}.{} is unknown".format(self.__path__, name))
         else:
             raise AttributeError(name)
     setattr(self, name, value)
     return value
Example #9
0
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 )
Example #10
0
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)
Example #11
0
def _uno_import(name, *optargs, **kwargs):
    try:
        #       print "optargs = " + repr(optargs)
        return _g_delegatee(name, *optargs, **kwargs)
    except ImportError as e:
        # process optargs
        globals, locals, fromlist = list(optargs)[:3] + [
            kwargs.get('globals', {}),
            kwargs.get('locals', {}),
            kwargs.get('fromlist', [])
        ][len(optargs):]
        # 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
    for x in modnames:
        if x in d:
            mod = d[x]
        else:
            mod = pyuno.__class__(x)  # How to create a module ??
        d = mod.__dict__

    RuntimeException = pyuno.getClass("com.sun.star.uno.RuntimeException")
    for x in fromlist:
        if x not in d:
            failed = False
            if x.startswith("typeOf"):
                try:
                    d[x] = pyuno.getTypeByName(name + "." + x[6:len(x)])
                except RuntimeException:
                    failed = True
            else:
                try:
                    # check for structs, exceptions or interfaces
                    d[x] = pyuno.getClass(name + "." + x)
                except RuntimeException:
                    # check for enums
                    try:
                        d[x] = Enum(name, x)
                    except RuntimeException:
                        # check for constants
                        try:
                            d[x] = getConstantByName(name + "." + x)
                        except RuntimeException:
                            # check for constant group
                            try:
                                d[x] = _impl_getConstantGroupByName(name, x)
                            except ValueError:
                                failed = True

            if failed:
                # 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.
                #
                # 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.
                #
                # 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))
                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

    return mod
Example #12
0
File: uno.py Project: mszostak/core
def _uno_import( name, *optargs, **kwargs ):
    try:
#       print "optargs = " + repr(optargs)
        return _g_delegatee( name, *optargs, **kwargs )
    except ImportError as e:
        # process optargs
        globals, locals, fromlist = list(optargs)[:3] + [kwargs.get('globals',{}), kwargs.get('locals',{}), kwargs.get('fromlist',[])][len(optargs):]
        # 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
    for x in modnames:
        if x in d:
           mod = d[x]
        else:
           mod = pyuno.__class__(x)  # How to create a module ??
        d = mod.__dict__

    RuntimeException = pyuno.getClass( "com.sun.star.uno.RuntimeException" )
    for x in fromlist:
       if x not in d:
          failed = False
          if x.startswith( "typeOf" ):
             try:
                d[x] = pyuno.getTypeByName( name + "." + x[6:len(x)] )
             except RuntimeException:
                failed = True
          else:
            try:
                # check for structs, exceptions or interfaces
                d[x] = pyuno.getClass( name + "." + x )
            except RuntimeException:
                # check for enums
                try:
                   d[x] = Enum( name , x )
                except RuntimeException:
                   # check for constants
                   try:
                      d[x] = getConstantByName( name + "." + x )
                   except RuntimeException:
                      # check for constant group
                      try:
                          d[x] = _impl_getConstantGroupByName( name, x )
                      except ValueError:
                          failed = True

          if failed:
              # 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.
              #
              # 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.
              #
              # 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))
              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

    return mod