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")
Exemplo n.º 2
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" )
Exemplo n.º 3
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
Exemplo n.º 4
0
def _uno_import(name, *optargs, **kwargs):
    """Overrides built-in import to allow directly importing LibreOffice classes."""

    try:
        return _builtin_import(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

    mod = None
    d = sys.modules

    for module in name.split("."):
        if module in d:
            mod = d[module]
        else:
            # How to create a module ??
            mod = pyuno.__class__(module)

        d = mod.__dict__

    RuntimeException = pyuno.getClass("com.sun.star.uno.RuntimeException")

    for class_name in fromlist:
        if class_name not in d:
            failed = False

            try:
                # check for structs, exceptions or interfaces
                d[class_name] = pyuno.getClass(name + "." + class_name)
            except RuntimeException:
                # check for enums
                try:
                    d[class_name] = Enum(name, class_name)
                except RuntimeException:
                    # check for constants
                    try:
                        d[class_name] = getConstantByName(name + "." +
                                                          class_name)
                    except RuntimeException:
                        # check for constant group
                        try:
                            d[class_name] = _impl_getConstantGroupByName(
                                name, class_name)
                        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, class_name))

                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
Exemplo n.º 5
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:
                            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.
                #
                # 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
Exemplo n.º 6
0
Arquivo: uno.py Projeto: 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