Python-UNO bridge 0.9.2

- Introduction
- State
- Changes
- Installation guide
-- Binary
-- Source
- External references
- UNO type mapping
- Implementing UNO objects
- Implementing UNO components
- Out parameter handling
- Exception handling
- Dependencies
- Bootstrapping in non-OOo environments
- unohelper module
- Authors
- License

Introduction

The Python-UNO bridge allows to use the standard OpenOffice.org API from the well known python scripting language. It addtionally allows to develop UNO components in python, thus python UNO components may be run within the office process and e.g. can be called from Java, C++ or the built in StarBasic scripting langauge.

You should find the most current version of this document at http://udk.openoffice.org/python/python-bridge.html

State

The Python-UNO bridge is in a beta state. It runs with the instable OpenOffice.org 1.1 source tree (to be more exact with the OO643C version). It does not run with an OpenOffice.org 1.0.x source tree.

PyUNO can be downloaded as a separate binary package, it does not come with the default OpenOffice.org installation. This may change in future, when a signifcant number of people have shown interest in PyUNO. So if you think, that PyUNO should be part of OOo installation, raise your voice on the dev@udk.openoffice.org mailing list.

The documentation in its current state is targeted at developers, who have already some experience with OpenOffice.org API with some other programmaing language (Java/C++/StarBasic). If you are a newbie and you think, that some background information is missing, you should try the developer manual mentioned in the external reference section.

Changes

Installation Guide

Extending the OO643C installation

There are binary extension sets of the Python-UNO bridge available for win32, linux-x86 and linux-ppc.
  1. If you are new to pyuno, skip to the next step. If you have used pyuno in version 0.9.1 on the same OOo installation, where you want to install the new version, you should first delete files belonging to the older version to avoid confusion. The following files should be deleted
    all platforms:
    program/pydemo
    program/uno.py
    program/unohelper.py
    program/pythonloader.py
    
    additionally on windows:
    program/pyuno.dll
    program/pycpld.dll
    program/pyuno_setup.bat
    program/regcomp.exe
    program/pyunoenv.bat
    program/pyuno.ini                                     
    
    addtiionally on unix:
    program/pyuno_setup.sh
    program/libpyuno.so
    program/libpycpld.so
    program/regcomp
    program/pyunoenv.tcsh
    program/pyuno.so
    program/libpython.so
    program/pyunorc                                                                   
    
    Note that pyuno now ships with a python runtime, so you don't need to install python anymore.
  2. Download and install an OpenOffice643C build (see http://www.openoffice.org )
  3. Download the Python-UNO bridge for your platform

    windows http://udk.openoffice.org/python/download/pyuno-win32-0.9.2.zip
    linux x86 http://udk.openoffice.org/python/download/pyuno-linux-x86-0.9.2.tar.gz
    linux-ppc ftp://ftp.yellowdoglinux.com/pub/yellowdog/software/openoffice/pyuno-linux-ppc-0.9.2.tar.gz (and its mirrors).

  4. Start a shell ( tcsh on linux, cmd shell on windows ) and switch to the OpenOffice.org installation directory (e.g. /home/joe/OpenOffice.org643).
  5. Unzip the Python-UNO installation set into the office installation directory.

    e.g. Linux:

         joe@foobar:/home/joe/OpenOffice.org643> gunzip < pyuno-linux-x86-0.9.2.tar.gz | tar -xvf -
         
  6. Switch to the program directory (e.g. /home/joe/OpenOffice.org643/program)
  7. Fire up your favourite text editor and edit the pyunoenv.tcsh (linux) or pyunoenv.bat (windows). Please set the OOOHOME variables appropriately in these files, e.g. (linux)

    setenv OOOHOME /home/joe/OpenOffice.org643

    or (windows)
    set OOOHOME=c:\programs\OpenOffice.org643

  8. On linux, source the pyunoenv.tcsh script ( source pyunoenv.tcsh ), on windows simply start the pyunoenv.bat batch file (you must redo this step for every new shell).
  9. Start the ./pyuno_setup[.sh|.bat] script. It will register two components to the office installation. When everything runs successful, you should get the following output:
    register component "pycpld" in registry "applicat.rdb" succesful!
     
    register component "swritercomp" in registry "applicat.rdb" succesful!                            
         
    If you get an error message, have a look at the troubleshooting section below.
You have now successfully installed the Python-UNO bridge. There comes some sample scripts and a sample python component with the installation sets, which can be found in the program/pydemo directory.

Make sure, that the office doesn't run. Start the office from a python prepared shell ( do the pyunoenv step above). In order to let the demos run, start the office with

./soffice "-accept=socket,host=localhost,port=2002;urp;"

Now start the swriter demo script

python pydemo/swriter.py

It should connect to the office, create a new document and put some text and a table into it. Note that this swriter.py example does the same things as the swriter.java example, which comes with the OpenOffice.org development kit. If you have some java source code and you are unsure how to translate it to python, you might have a look at these source files to get an idea how to do this.

Additionally, there comes a python UNO component named swritercomponent.py, which implements the com.sun.star.lang.XMain interface. The only method run() does the same thing as the swriter.py example, the only difference is, that it is run within the OpenOffice.org process, which improves performance. You may either trigger the python component in the office directory from another python script

python pydemo/swritercompclient.py

or you may use the following Basic script via Tools/Macro/New macro

dim args()
pycomp = createUnoService( "org.openoffice.demo.SWriter" )
pycomp.run( args )
Now have a look at the sample files to get an idea, how to use the bridge. Visit the rest of this document, if you are uncertain, how a concrete UNO feature is treated by the python bridge. Have fun !
Troubleshooting
  1. I can't find a pyunoenv.tcsh (or .bat) file
    Make sure to extract the pyuno bridge files into the toplevel directory of the OpenOffice.org installation. There should go multiple files into program subdirectory.
  2. An error occurs during the the python pyuno_setup.py step.
    Make sure, that you have filled out the pyunoenv.bat (pyunoenv.tcsh) correctly, check especially for typos in the pathes.

Building from source

The Python-UNO bridge has already been adapted for the OpenOffice build environment. So you should first establish the OpenOffice.org build environment for the 643C.

Note for python 0.9.1 users ! When you want to build pyuno 0.9.2 in a solver tree, which already contains pyuno 0.9.1, you should first remove the files from the solver tree. These are the

your-platform/bin/python[.exe]
your-platform/lib/[lib]pycpld.[dll|so]
your-platform/lib/[lib]python.[dll|so]
your-platform/lib/[lib]pyuno.[dll|so]
your-platform/lib/python2.2  (whole directory)
your-platform/inc/python2.2  (whole directory)

Linux: Please add the following line to your LinuxIntelEnv.Set (Attention 0.9.1-users: The pathes have changed ! )

setenv PYTHONPATH .:"$SOLARVER"/"$UPD"/"$INPATH"/lib/python:
         	    "$SOLARVER"/"$UPD"/"$INPATH"/lib/python/lib-dynload
Windows: Please add the following to your winenv.bat file
set PYTHONPATH=.;%SOLARVER%\%UPD%\%INPATH%\lib\python;
		 %SOLARVER%\%UPD%\%INPATH%\lib\python\lib-dynload
Checkout the source from the CVS repository. These are external/python and udk/pyuno (I hope to get the alias python and pyuno working). The external/python project might not yet be available because of legal issues, it can be downloaded from the attachment of the issue http://www.openoffice.org/issues/show_bug.cgi?id=11753 inbetween.
  1. external/python
    This module builds the external python source. Put the python source tar file into the python/download directory, but make sure to rename it from Python-2.2.2.tgz to Python-2.2.2.tar.gz. (Note: Currently, you must use the Python-2.2.2 version !)

    Build and deliver this project.

  2. udk/pyuno
    The following table gives an overview about the pyuno project.
    prj              -- build details
    source/module    -- contains the core Python-UNO bridge and 
                        the module, that is loaded my the python executable.
    		    The result is a shared C++ library, to which the python loader
    		    links to.
    source/loader    -- contains the UNO loader for python components
    inc/pyuno        -- contains exported API for the python module. 
    unotypes         -- generates the types needed for the bridge
    test             -- contains test python scripts. In order to execture the tests,
                        simply type dmake test
    demo             -- contains demo python scripts and a makefile
                        , which creates a deployment file for the OO643C build.
    
    Build this project. In order to run the tests, you need to get a HEAD version of the testtools project, which currently does not get built by default, build and deliver the testtools project. Afterwards run the tests in the pyuno/test directory using dmake runtest, you shouldn't get any errors there. Deliver this project.

    From now on, you can use UNO python scripts in the build environment, e.g. create some glue code for some UNO components to do a certain job. In the build environment, only the core UNO components to make the bridge work are preregistered. Have a look at the Bootstrapping section below to see, how you can register your components. The really nice thing is that you now can do UNO just with a text editor without any compilation :o).

External references

Python homepage http://www.python.org
Python tutorial TODO
UNO homepage http://udk.openoffice.org
OpenOffice.org developer manual http://api.openoffice.org/DevelopersGuide/DevelopersGuide.html

UNO Type mapping

IDL datatype representation in python
integer types (byte, short, unsigned short, long, unsigned long, hyper, unsigned hyper Python internally knows only the C datatypes long and long long as integer types. On most machines, a long is a 32 bit value while long long is a 64 bit value.
  • Values coming from UNO (for instance the return value of a UNO method)

    Values which have the type byte, short, unsigned short, long or unsigned long are converted to a python long value. Values which have the type hyper or unsigned hyper are converted to a python long long.

  • Values going to UNO (for instance the argument of a UNO method)

    If there is a concrete type in the idl method signature, the value is converted to the concrete type (in fact the invocation service does this work). If the method signature just has an any, every integer value is converted to the smallest data type, where the value fits into and send to the UNO object ( so 5 becomes a byte, 150 becomes a short, 0x1f023 becomes a long and values larger than 0xffffffff become a hyper.

boolean Python internally has a boolean data type, which is derived from the integer type ( see http://python.org/peps/pep-0285.html ). There exists the singletons True and False, which pyuno uses to distinguish between integers and boolean values.

As long as a boolean is specified in the interface method signature, you may also you numbers. In the following example, all calls are valid:
#idl signature void takeBool( [in] boolean bool )

unoObject.takeBool( 1 )             # valid, passing true
unoObject.takeBool( True) )   # valid, passing true
unoObject.takeBool( False )   # valid, passing false
However, when you want to explicitly pass a boolean, where only an any is specified, you must use True or False.
# idl signature void foo( [in] any value )

# implementation expects a boolean (which is separately documented
# e.g. in the service specification.
unoObject.foo( True ) # valid, pass a true
unoObject.foo( 1 )    # bad, just passing a 1, implementation will
                      # probably not be able to deal with it correctly.

Note: There also exists the uno.Bool class, which is deprecated since pyuno 0.9.2, but still supported. Don't use it anymore.

string In general, the string is mapped to the python unicode string. However, you may pass an 8 bit python string where a UNO string is expected, the bridge converts the 8 bit string to a unicode string using the system locale.
# idl signatore foo( [in] string value )
# both lines are valid
unoObject.foo( u'my foo string' )
unoObject.foo( 'my foo string' )
char A char is mapped to a uno.Char. It has a public unicode string member value with length 1 containing the unicode char.
# idl signature foo( [in] char c)
unoObject.foo( uno.Char( u'h' ) )  #valid
unoObject.foo( 'h' )               #wrong
enum A concrete enum value is represented by an instance of the class uno.Enum. It has two members, typeName is a string containing the name of the enum type and value contains the value of the enum.

You may create concrete enum values in two ways

  1. (suggested) by importing
    from enumname import enumvalue.

    E.g.

    from com.sun.star.uno.TypeClass import UNSIGNED_LONG
    .
    .
    .
    unoObject.setValue( UNSIGNED_LONG )
    if unoObject.getValue() == UNSIGNED_LONG:
       .
       .
    

  2. (in rare situations)
    import uno
         
    unoObject.setValue( uno.Enum( "com.sun.star.uno.TypeClass", "UNSIGNED_LONG") )
    if unoObject.getValue() == uno.Enum( "com.sun.star.uno.TypeClass", "UNSIGNED_LONG"):
       .
       .
       .
    
The first solution has the advantage, that a mispelled enum name already leads to a RuntimeException, when the python source file is imported.
type A type is mapped to a uno.Type. It has public members typeName (string) and typeClass (enum value of com.sun.star.uno.TypeClass). There exists a function uno.getTypeByName() to easily create a type instance, the functions raises a RuntimeException in case the type is unknown.

You may create concrete type values in two ways

  1. (suggested) by importing
    from module-where-type-lives-in import typeOfTypeName.

    E.g. to create XComponent's type, use

    from com.sun.star.lang import typeOfXComponent
    .
    .
    .
    unoObject.setType( typeOfXComponent )
    if unoObject.getType() == typeOfXComponent:
       .
       .
    

  2. (in rare situations, e.g. for types of simple values)
    import uno
         
    unoObject.setType( uno.getTypeByName( "com.sun.star.uno.XComponent" ) )
    if unoObject.getType() == uno.getTypeByName( "com.sun.star.uno.XComponent"):
       .
       .
       .
    
struct (and exception) For each UNO struct (or exception), a new python class is generated on the fly. It is guaranteed, that there is only one instance of the struct (or exception) class per python interpreter instance. The generated class does reflect the inheritance hierarchy of the conrete UNO type (e.g. important for exception handling, see below).

One can generate a struct class by using the import mechanism. An instance of a struct can then be instantiated by using the python constructor. The constructor supports zero arguments (members get default constructed), 1 argument which the same type (copy constructor), and n arguments, where n is the number of elements of the concrete struct. The struct supports the equality operator, two structs are equal, if they are of the same type and each member is equal.

Example:
from com.sun.star.beans import PropertyValue
from com.sun.star.uno import Exception,RuntimeException

propVal = PropertyValue()                 # Default constructor
propVal.Name = "foo"
propVal.Value = 2

if propVal == PropertyValue( "foo", 2 ):  # Memberwise constructor
   # true !
   pass

if propVal == PropertyValue( propVal ):   # Copy Constructor
   # true 


An instance of a UNO struct can be initially constructed with the function uno.createUnoStruct() and passing the name of the struct as the first parameter and optionial constructor arguments (see above for an example of possible ctors).

ATTENTION: In UNO, structs have value semantic, however the handling in python does not reflect this. When a struct gets passed as a parameter to a function, the values are passed to the callee. Later modification of the struct instance does not influence the callee anymore. However, simply assigning a struct to another local variable does not create a copy, but simply creates an alias to the original instance.
struct = uno.createIdlStruct( "com.sun.star.beans.PropertyValue" )

struct.Name = "foo"
struct2 = struct
struct2.Name = "python"           # modifies also struct, probably not desired !
unoObject.call( struct, struct2 ) # passes the same struct 2 times !

struct.Name = "doobidooo"         # even worse style. If the UNO object is implemented
                                  # in python, you possibly modify the callee's value.
				  # Don't do this !

sequence A sequence is in general mapped to a python tuple. A python list is not (!) accepted.
# idl signature XInterface createInstanceWithArguments(
#                        [in] string servicename,  [in] sequence <any> )
doc = smgr.createInstanceWithArguments( "foo.service", ("arg1",2))
Attention (since 0.9.2): The idl sequence<byte> is mapped to the class uno.ByteSequence . It has a string member named value, which holds the data of the byte sequence. As the bytesequence most often is a container for binary data, this class allows to handle binaries efficiently. This also embeds pyuno nicely into python, as python keeps binary data in strings. Example:
# idl signature writeBytes( [in] sequence%lt; byte > data )
#
out.writeBytes( uno.ByteSequence( "abc" ) )

# you could also write the following
begin = uno.ByteSequence( "ab" )
out.writeBytes( begin + "c" )

# but this does not work !
out.writeBytes( "abc" ) # ERROR, no implict conversion supported by the runtime !


# idl signature long readBytes( [out] sequence<byte> , [in] length )
len,seq = in.readBytes( dummy, 3 )

# the statements do the same thing 
print seq == "abc":
print seq == uno.ByteSequence( "abc" )
constants An UNO idl constant can be given by the following ways:
  1. Use the concrete value specified in the idl file
    A constant is its value and only its value. As modification of the constant values is incompatible, one may simply rely on the values.
  2. (suggested) Use the import mechanism to create variable with the constant name
    This solution is the most readable one.
  3. Use uno.getConstantByName()
    Might be useful from time to time. Function raises a RuntimeException in case the constant is unknown.
from com.sun.star.beans.PropertyConcept import ATTRIBUTES
.
.
.
# the following 3 lines are equivalent
unoObject.setConcept( ATTRIBUTES )
unoObject.setConcept( 4 )
unoObject.setConcept( uno.getConstantByName( "com.sun.star.beans.PropertyConcept.ATTRIBUTES" ) )

Implementing UNO objects

One may use python classes to implement UNO objects. Instances of a python class may then be passed as argument to UNO calls where anys or concrete interfaces are specified.

To be an UNO object, a python class MUST implement the com.sun.star.lang.XTypeProvider interface by implementing two methods getTypes() and getImplementationId(), which inform the python-UNO bridge, which concrete UNO interfaces the python class implements. The getTypes() function defines, which interfaces are implemented by the class.

To make this easier, there exists a unohelper.Base class, where a python UNO object should derive from. You can then implement a UNO interface simply by deriving from the wanted interfaces. The following example implements a com.sun.star.io.XOutputStream, which stores all data written into the stream within a ByteSequence. (Note that this is quite a poor implementation, which is just for demonstration purposes).
import unohelper
from com.sun.star.io import XOutputStream
class SequenceOutputStream( unohelper.Base, XOutputStream ):
      def __init__( self ):
          self.s = uno.ByteSequence("")
          self.closed = 0
          
      def closeOutput(self):
          self.closed = 1

      def writeBytes( self, seq ):
          self.s = self.s + seq

      def flush( self ):
          pass

      def getSequence( self ):
          return self.s
          
From the list of base classes given (here only XOutputStream), the unohelper.Base implementation correctly implements the XTypeProvider interface.

Implementing Python UNO components

There exists a loader for python components. It allows to create instances of python classes not just within the python process but in every arbitrary UNO process including OpenOffice.org. The python loader loads the python runtime on demand if it is not already loaded and executes python code within the root python interpreter.

If the reader is unfamilar with the component registration process, it should visit the OpenOffice.org developer manual for a comprehensive explanation.

The python loader supports currently supports the following protocols for incoming urls.
Protocol name Description
vnd.openoffice.pymodule The protocol dependend part is interpreted as a python module name, which is imported using the common python import mechanism (which uses the PYTHONPATH environment variable).

After the module has been imported, the python loader looks for a module-global variable with the name g_ImplementationHelper, which is expected to be an instance of unohelper.ImplementationHelper

More protocols may be supported in future (e.g. absolute file urls ). The following sample code makes a uno component out of the above UNO object ( note that the component is neither useful, because there is no UNO method to retrieve the tuple nor does a com.sun.star.io.OutputStream service specification exist, it's just here as an example).
import unohelper
from com.sun.star.io import XOutputStream

g_ImplementationHelper = unohelper.ImplementationHelper()

class TupleOutputStream( unohelper.Base, XOutputStream ):
      # The component must have a ctor with the component context as argument.
      def __init__( self, ctx ):
	  self.t = ()
	  self.closed = 0

      # idl void closeOutput();
      def closeOutput(self):
	  self.closed = 1

      # idl void writeBytes( [in] sequence seq );
      def writeBytes( self, seq ):
	  self.t = self.t + seq      # simply add the incoming tuple to the member

      # idl void flush();
      def flush( self ):
	  pass

      # convenience function to retrieve the tuple later (no UNO function, may
      # only be called from python )
      def getTuple( self ):
	  return self.t

# add the TupleOutputStream class to the implementation container,
# which the loader uses to register/instantiate the component.
g_ImplementationHelper.addImplementation( \
	TupleOutputStream,"org.openoffice.pyuno.PythonOutputStream",
	                    ("com.sun.star.io.OutputStream",),)
Lets assume, that this code is stored in a file named tuplestrm.py and the file exists somewhere within the PYTHONPATH variable, it can be registered to an OO643C build with the following command :

regcomp -register -br applicat.rdb -r applicat.rdb -c vnd.openoffice.pymodule:tuplestrm

The component can be instantiated e.g. from OpenOffice Basic with
tupleStrm = createUnoService( "com.sun.star.io.OutputStream" )
tupleStrm.flush()

Out parameter handling

UNO out parameters are handled through the python multiple return value feature. For pure outparameters, a dummy None value should be used as a place holder. This is best explained with an example. Lets' assume we have the following IDL method spec
long foo( [in] long first, [inout] long second, [out] third )
A python UNO object implements such a method the following way :
class Dummy( XFoo ):
    def foo( self, first,second,third):
        # Note: the value of third is always None, but it must be there
	#       as a placeholder if more args would follow !
        return first,2*second,second + first	
then such a method would be called from python the following way
ret,second,third = unoObject.foo( 2, 5 , None )
print ret,second,third    # results into 2,10,7
. This also emphasizes, that out-parameters are quite close to multiple return values (though the semantic association of a inout parameter gets lost).

However, note that

Exception handling

The Python-UNO bridge uses the common Python exception handling mechanism. For every UNO exception, a concrete exception class is generated on the fly (see above type mapping table for an explanation how to do this).

Example for catching
from com.sun.star.uno  import RuntimeException
from com.sun.star.lang import IllegalArgumentException
from com.sun.star.connection import NoConnectException
try:
    uuresoler.resolve( "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext" )
except NoConnectException e:
    print "The OpenOffice process is not started or does not listen on the resource ("+e.Message+")"
except IllegalArgumentException e:
    print "The url is invalid ( "+ e.Message+ ")"
except RuntimeException e:
    print "An unknown error occured: " + e.Message
Example for throwing
class TupleOutputStream(XOutputStream,unohelper.Base):
      def writeBytes( self, seq ):
          if self.closed:
	     raise IOException( "Output stream already closed", self )
          self.t = self.t + seq

Dependencies

This chapter is most interesting for people who want to use the Python-UNO bridge independently from OpenOffice.org.

Unlike the Java or C++ UNO binding, the python UNO binding is not self contained. It requires the C++ UNO binding and additional scripting components. These additional components currently live in the shared libraries tcv,inv,corefl,insp,invadp,proxyfac,pycpld (on windows tcv.dll,inv.dll,etc.; unix libtcv.so, etc.).

Often, the components for setting up an interprocess connection are additonally required. These are uuresolver,connectr,remotebridge,brdgfctr shared libraries.

The path environment variables ( LD_LIBRARY_PATH on unix, PATH on windows) must point to a directory, where the core UNO libraries, the above listed components and the pyuno shared library is located. (On unix, there exists two files: libpyuno.so containing the code and a pyuno.so which is needed for importing a native python module). Additionally, the python module uno.py, unohelper.py and pythonloader.py must be located in a directory, which is listed in the PYTHONPATH environment variable.

Bootstrapping pyuno from the python executable

When the uno module gets first imported from an arbitrary python script, it must bootstrap a properly prepared UNO component context.
# bootstraps the uno component context
import uno

# retrieve the already bootstrapped component context
unoContext = uno.getComponentContext()
As the python programmer can't (and probably doesn't want to) give parameters during importing a module, the python-uno binding uses the pyuno[rc|.ini] file located beside the pyuno shared library to bootstrap the UNO context (see uno bootstrap variable concept). The bootstrap variables UNO_SERVICES must point to a registry file, where the above given components got registered to.

PYUNOLIBDIR is a special bootstrap variable, which contains the path to the currently used pyuno shared library. Example:
# The bootstrap variable PYUNOLIBDIR will be set by the pyuno runtime library
UNO_TYPES=$PYUNOLIBDIR/applicat.rdb
UNO_SERVICES=$PYUNOLIBDIR/pyuno_services.rdb
If the above preconditions are fulfilled, the script can simply be started with

$ python myscript.py

Sometimes it is preferable to mention the librarynames of the desired components directly within the script instead of preparing a registry (however note that the above mentioned bootstrap components always needs to be registered in a registry). This can be achieved by using the function unohelper.addComponentsToContext( toBeExtendedContext, contextRuntime, componentUrls, loaderName )

Example:
import uno
import unohelper

localContext = uno.getComponentContext()

unohelper.addComponentsToContext(
       localContext, localContext, ("stm",),
       "com.sun.star.loader.SharedLibrary")

pipe = localContext.ServiceManager.createInstanceWithContext(
              "com.sun.star.io.Pipe", localContext )

pipe.writeBytes( uno.ByteSequence( "abc" ) )
ret,seq = pipe.readBytes( None, 3 )

unohelper module

The unohelper.py module contains some sugar functions/classes, which are nice to use with pyuno, but not mandatory. This paragraph lists some of the unohelper.py features.
def systemPathToFileUrl( systemPath ) Returns a file-url for the given system path. Most of the OOo API functions expect a file-url, while the python runtime functions in general only work with system pathes. The function is implemented using the core C function osl_getFileUrlFromSystemPath().
def fileUrlToSystemPath( url ) Returns a system path (determined by the system, the python interpreter is running on). Most OOo function return a file-url, while most python runtime functions expect system pathes. The function is implemented by using the core osl_getSystemPathFromFileUrl() function.
def absolutize( path, relativeUrl ) Returns an absolute file url from a given, mandatory absolute, directory url and a relative file url, which may be absolute or relative (which includes e.g. ../ parts. The function is implemented by using the core osl_getAbsolutePathFromFileUrl() function.
def addComponentsToContext( toBeExtendedContext, contextRuntime, componentUrls, loaderName ) This functions adds a tuple of component urls to the toBeExtendedContext using the contextRuntime to instantiate the loader loaderName and some other services needed for this task. After completing the function, all services within these components can be instantiated as long as the toBeExtendedContext is not disposed. The changes are not made persistent.

Authors

The UNO python bridge was initially created by Ralph Thomas and is now maintained by Joerg Budischewski.

Please use the dev@udk.openoffice.org mailing list for further questions.

License

The code is currently available under the BSD licence available from http://www.opensource.org/licenses/bsd-license.php.