1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "pyuno_impl.hxx"
29 
30 #include <osl/module.hxx>
31 #include <osl/thread.h>
32 #include <osl/file.hxx>
33 
34 #include <typelib/typedescription.hxx>
35 
36 #include <rtl/strbuf.hxx>
37 #include <rtl/ustrbuf.hxx>
38 #include <rtl/uuid.h>
39 #include <rtl/bootstrap.hxx>
40 
41 #include <uno/current_context.hxx>
42 #include <cppuhelper/bootstrap.hxx>
43 
44 #include <com/sun/star/reflection/XIdlReflection.hpp>
45 #include <com/sun/star/reflection/XIdlClass.hpp>
46 #include <com/sun/star/registry/InvalidRegistryException.hpp>
47 
48 using osl::Module;
49 
50 using rtl::OString;
51 using rtl::OUString;
52 using rtl::OUStringToOString;
53 using rtl::OUStringBuffer;
54 using rtl::OStringBuffer;
55 
56 using com::sun::star::uno::Sequence;
57 using com::sun::star::uno::Reference;
58 using com::sun::star::uno::XInterface;
59 using com::sun::star::uno::Any;
60 using com::sun::star::uno::makeAny;
61 using com::sun::star::uno::UNO_QUERY;
62 using com::sun::star::uno::RuntimeException;
63 using com::sun::star::uno::TypeDescription;
64 using com::sun::star::uno::XComponentContext;
65 using com::sun::star::container::NoSuchElementException;
66 using com::sun::star::reflection::XIdlReflection;
67 using com::sun::star::reflection::XIdlClass;
68 using com::sun::star::script::XInvocation2;
69 
70 using namespace pyuno;
71 
72 namespace {
73 
74 /**
75    @ index of the next to be used member in the initializer list !
76  */
77 sal_Int32 fillStructWithInitializer(
78     const Reference< XInvocation2 > &inv,
79     typelib_CompoundTypeDescription *pCompType,
80     PyObject *initializer,
81     const Runtime &runtime) throw ( RuntimeException )
82 {
83     sal_Int32 nIndex = 0;
84     if( pCompType->pBaseTypeDescription )
85         nIndex = fillStructWithInitializer(
86             inv, pCompType->pBaseTypeDescription, initializer, runtime );
87 
88     sal_Int32 nTupleSize =  PyTuple_Size(initializer);
89     int i;
90     for( i = 0 ; i < pCompType->nMembers ; i ++ )
91     {
92         if( i + nIndex >= nTupleSize )
93         {
94             OUStringBuffer buf;
95             buf.appendAscii( "pyuno._createUnoStructHelper: too few elements in the initializer tuple,");
96             buf.appendAscii( "expected at least " ).append( nIndex + pCompType->nMembers );
97             buf.appendAscii( ", got " ).append( nTupleSize );
98             throw RuntimeException(buf.makeStringAndClear(), Reference< XInterface > ());
99         }
100         PyObject *element = PyTuple_GetItem( initializer, i + nIndex );
101         Any a = runtime.pyObject2Any( element, ACCEPT_UNO_ANY );
102         inv->setValue( pCompType->ppMemberNames[i], a );
103     }
104     return i+nIndex;
105 }
106 
107 OUString getLibDir()
108 {
109     static OUString *pLibDir;
110     if( !pLibDir )
111     {
112         osl::MutexGuard guard( osl::Mutex::getGlobalMutex() );
113         if( ! pLibDir )
114         {
115             static OUString libDir;
116 
117             // workarounds the $(ORIGIN) until it is available
118             if( Module::getUrlFromAddress(
119                     reinterpret_cast< oslGenericFunction >(getLibDir), libDir ) )
120             {
121                 libDir = OUString( libDir.getStr(), libDir.lastIndexOf('/' ) );
122                 OUString name ( RTL_CONSTASCII_USTRINGPARAM( "PYUNOLIBDIR" ) );
123                 rtl_bootstrap_set( name.pData, libDir.pData );
124             }
125             pLibDir = &libDir;
126         }
127     }
128     return *pLibDir;
129 }
130 
131 void raisePySystemException( const char * exceptionType, const OUString & message )
132 {
133     OStringBuffer buf;
134     buf.append( "Error during bootstrapping uno (");
135     buf.append( exceptionType );
136     buf.append( "):" );
137     buf.append( OUStringToOString( message, osl_getThreadTextEncoding() ) );
138     PyErr_SetString( PyExc_SystemError, buf.makeStringAndClear().getStr() );
139 }
140 
141 extern "C" {
142 
143 static PyObject* getComponentContext (PyObject*, PyObject*)
144 {
145     PyRef ret;
146     try
147     {
148         Reference<XComponentContext> ctx;
149 
150         // getLibDir() must be called in order to set bootstrap variables correctly !
151         OUString path( getLibDir());
152         if( Runtime::isInitialized() )
153         {
154             Runtime runtime;
155             ctx = runtime.getImpl()->cargo->xContext;
156         }
157         else
158         {
159             OUString iniFile;
160             if( !path.getLength() )
161             {
162                 PyErr_SetString(
163                     PyExc_RuntimeError, "osl_getUrlFromAddress fails, that's why I cannot find ini "
164                     "file for bootstrapping python uno bridge\n" );
165                 return NULL;
166             }
167 
168             OUStringBuffer iniFileName;
169             iniFileName.append( path );
170             iniFileName.appendAscii( "/" );
171             iniFileName.appendAscii( SAL_CONFIGFILE( "pyuno" ) );
172             iniFile = iniFileName.makeStringAndClear();
173             osl::DirectoryItem item;
174             if( osl::DirectoryItem::get( iniFile, item ) == item.E_None )
175             {
176                 // in case pyuno.ini exists, use this file for bootstrapping
177                 PyThreadDetach antiguard;
178                 ctx = cppu::defaultBootstrap_InitialComponentContext (iniFile);
179             }
180             else
181             {
182                 // defaulting to the standard bootstrapping
183                 PyThreadDetach antiguard;
184                 ctx = cppu::defaultBootstrap_InitialComponentContext ();
185             }
186 
187         }
188 
189         if( ! Runtime::isInitialized() )
190         {
191             Runtime::initialize( ctx );
192         }
193         Runtime runtime;
194         ret = runtime.any2PyObject( makeAny( ctx ) );
195     }
196     catch (com::sun::star::registry::InvalidRegistryException &e)
197     {
198         // can't use raisePyExceptionWithAny() here, because the function
199         // does any conversions, which will not work with a
200         // wrongly bootstrapped pyuno!
201         raisePySystemException( "InvalidRegistryException", e.Message );
202     }
203     catch( com::sun::star::lang::IllegalArgumentException & e)
204     {
205         raisePySystemException( "IllegalArgumentException", e.Message );
206     }
207     catch( com::sun::star::script::CannotConvertException & e)
208     {
209         raisePySystemException( "CannotConvertException", e.Message );
210     }
211     catch (com::sun::star::uno::RuntimeException & e)
212     {
213         raisePySystemException( "RuntimeException", e.Message );
214     }
215     catch (com::sun::star::uno::Exception & e)
216     {
217         raisePySystemException( "uno::Exception", e.Message );
218     }
219     return ret.getAcquired();
220 }
221 
222 PyObject * extractOneStringArg( PyObject *args, char const *funcName )
223 {
224     if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
225     {
226         OStringBuffer buf;
227         buf.append( funcName ).append( ": expecting one string argument" );
228         PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
229         return NULL;
230     }
231     PyObject *obj = PyTuple_GetItem( args, 0 );
232     if( !PyString_Check( obj ) && ! PyUnicode_Check(obj))
233     {
234         OStringBuffer buf;
235         buf.append( funcName ).append( ": expecting one string argument" );
236         PyErr_SetString( PyExc_TypeError, buf.getStr());
237         return NULL;
238     }
239     return obj;
240 }
241 
242 static PyObject *createUnoStructHelper(PyObject *, PyObject* args )
243 {
244     Any IdlStruct;
245     PyRef ret;
246 
247     try
248     {
249         Runtime runtime;
250         if( PyTuple_Size( args ) == 2 )
251         {
252             PyObject *structName = PyTuple_GetItem( args,0 );
253             PyObject *initializer = PyTuple_GetItem( args ,1 );
254 
255             if( PyString_Check( structName ) )
256             {
257                 if( PyTuple_Check( initializer ) )
258                 {
259                     OUString typeName( OUString::createFromAscii(PyString_AsString(structName)));
260                     RuntimeCargo *c = runtime.getImpl()->cargo;
261                     Reference<XIdlClass> idl_class ( c->xCoreReflection->forName (typeName),UNO_QUERY);
262                     if (idl_class.is ())
263                     {
264                         idl_class->createObject (IdlStruct);
265                         PyUNO *me = (PyUNO*)PyUNO_new_UNCHECKED( IdlStruct, c->xInvocation );
266                         PyRef returnCandidate( (PyObject*)me, SAL_NO_ACQUIRE );
267                         if( PyTuple_Size( initializer ) > 0 )
268                         {
269                             TypeDescription desc( typeName );
270                             OSL_ASSERT( desc.is() ); // could already instantiate an XInvocation2 !
271 
272                             typelib_CompoundTypeDescription *pCompType =
273                                 ( typelib_CompoundTypeDescription * ) desc.get();
274                             sal_Int32 n = fillStructWithInitializer(
275                                 me->members->xInvocation, pCompType, initializer, runtime );
276                             if( n != PyTuple_Size(initializer) )
277                             {
278                                 OUStringBuffer buf;
279                                 buf.appendAscii( "pyuno._createUnoStructHelper: wrong number of ");
280                                 buf.appendAscii( "elements in the initializer list, expected " );
281                                 buf.append( n );
282                                 buf.appendAscii( ", got " );
283                                 buf.append( (sal_Int32) PyTuple_Size(initializer) );
284                                 throw RuntimeException(
285                                     buf.makeStringAndClear(), Reference< XInterface > ());
286                             }
287                         }
288                         ret = returnCandidate;
289                     }
290                     else
291                     {
292                         OStringBuffer buf;
293                         buf.append( "UNO struct " );
294                         buf.append( PyString_AsString(structName) );
295                         buf.append( " is unkown" );
296                         PyErr_SetString (PyExc_RuntimeError, buf.getStr());
297                     }
298                 }
299                 else
300                 {
301                     PyErr_SetString(
302                         PyExc_RuntimeError,
303                         "pyuno._createUnoStructHelper: 2nd argument (initializer sequence) is no tuple" );
304                 }
305             }
306             else
307             {
308                 PyErr_SetString (PyExc_AttributeError, "createUnoStruct: first argument wasn't a string");
309             }
310         }
311         else
312         {
313             PyErr_SetString (PyExc_AttributeError, "1 Arguments: Structure Name");
314         }
315     }
316     catch( com::sun::star::uno::RuntimeException & e )
317     {
318         raisePyExceptionWithAny( makeAny( e ) );
319     }
320     catch( com::sun::star::script::CannotConvertException & e )
321     {
322         raisePyExceptionWithAny( makeAny( e ) );
323     }
324     catch( com::sun::star::uno::Exception & e )
325     {
326         raisePyExceptionWithAny( makeAny( e ) );
327     }
328     return ret.getAcquired();
329 }
330 
331 static PyObject *getTypeByName( PyObject *, PyObject *args )
332 {
333     PyObject * ret = NULL;
334 
335     try
336     {
337         char *name;
338 
339         if (PyArg_ParseTuple (args, const_cast< char * >("s"), &name))
340         {
341             OUString typeName ( OUString::createFromAscii( name ) );
342             TypeDescription typeDesc( typeName );
343             if( typeDesc.is() )
344             {
345                 Runtime runtime;
346                 ret = PyUNO_Type_new(
347                     name, (com::sun::star::uno::TypeClass)typeDesc.get()->eTypeClass, runtime );
348             }
349             else
350             {
351                 OStringBuffer buf;
352                 buf.append( "Type " ).append(name).append( " is unknown" );
353                 PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
354             }
355         }
356     }
357     catch ( RuntimeException & e )
358     {
359         raisePyExceptionWithAny( makeAny( e ) );
360     }
361     return ret;
362 }
363 
364 static PyObject *getConstantByName( PyObject *, PyObject *args )
365 {
366     PyObject *ret = 0;
367     try
368     {
369         char *name;
370 
371         if (PyArg_ParseTuple (args, const_cast< char * >("s"), &name))
372         {
373             OUString typeName ( OUString::createFromAscii( name ) );
374             Runtime runtime;
375             Any a = runtime.getImpl()->cargo->xTdMgr->getByHierarchicalName(typeName);
376             if( a.getValueType().getTypeClass() ==
377                 com::sun::star::uno::TypeClass_INTERFACE )
378             {
379                 // a idl constant cannot be an instance of an uno-object, thus
380                 // this cannot be a constant
381                 OUStringBuffer buf;
382                 buf.appendAscii( "pyuno.getConstantByName: " ).append( typeName );
383                 buf.appendAscii( "is not a constant" );
384                 throw RuntimeException(buf.makeStringAndClear(), Reference< XInterface > () );
385             }
386             PyRef constant = runtime.any2PyObject( a );
387             ret = constant.getAcquired();
388         }
389     }
390     catch( NoSuchElementException & e )
391     {
392         // to the python programmer, this is a runtime exception,
393         // do not support tweakings with the type system
394         RuntimeException runExc( e.Message, Reference< XInterface > () );
395         raisePyExceptionWithAny( makeAny( runExc ) );
396     }
397     catch( com::sun::star::script::CannotConvertException & e)
398     {
399         raisePyExceptionWithAny( makeAny( e ) );
400     }
401     catch( com::sun::star::lang::IllegalArgumentException & e)
402     {
403         raisePyExceptionWithAny( makeAny( e ) );
404     }
405     catch( RuntimeException & e )
406     {
407         raisePyExceptionWithAny( makeAny(e) );
408     }
409     return ret;
410 }
411 
412 static PyObject *checkType( PyObject *, PyObject *args )
413 {
414     if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
415     {
416         OStringBuffer buf;
417         buf.append( "pyuno.checkType : expecting one uno.Type argument" );
418         PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
419         return NULL;
420     }
421     PyObject *obj = PyTuple_GetItem( args, 0 );
422 
423     try
424     {
425         PyType2Type( obj );
426     }
427     catch( RuntimeException & e)
428     {
429         raisePyExceptionWithAny( makeAny( e ) );
430         return NULL;
431     }
432     Py_INCREF( Py_None );
433     return Py_None;
434 }
435 
436 static PyObject *checkEnum( PyObject *, PyObject *args )
437 {
438     if( !PyTuple_Check( args ) || PyTuple_Size( args) != 1 )
439     {
440         OStringBuffer buf;
441         buf.append( "pyuno.checkType : expecting one uno.Type argument" );
442         PyErr_SetString( PyExc_RuntimeError, buf.getStr() );
443         return NULL;
444     }
445     PyObject *obj = PyTuple_GetItem( args, 0 );
446 
447     try
448     {
449         PyEnum2Enum( obj );
450     }
451     catch( RuntimeException & e)
452     {
453         raisePyExceptionWithAny( makeAny( e) );
454         return NULL;
455     }
456     Py_INCREF( Py_None );
457     return Py_None;
458 }
459 
460 static PyObject *getClass( PyObject *, PyObject *args )
461 {
462     PyObject *obj = extractOneStringArg( args, "pyuno.getClass");
463     if( ! obj )
464         return NULL;
465 
466     try
467     {
468         Runtime runtime;
469         PyRef ret = getClass(
470             OUString( PyString_AsString( obj), strlen(PyString_AsString(obj)),RTL_TEXTENCODING_ASCII_US),
471             runtime );
472         Py_XINCREF( ret.get() );
473         return ret.get();
474     }
475     catch( RuntimeException & e)
476     {
477         // NOOPT !!!
478         // gcc 3.2.3 crashes here in the regcomp test scenario
479         // only since migration to python 2.3.4 ???? strange thing
480         // optimization switched off for this module !
481         raisePyExceptionWithAny( makeAny(e) );
482     }
483     return NULL;
484 }
485 
486 static PyObject *isInterface( PyObject *, PyObject *args )
487 {
488 
489     if( PyTuple_Check( args ) && PyTuple_Size( args ) == 1 )
490     {
491         PyObject *obj = PyTuple_GetItem( args, 0 );
492         Runtime r;
493         return PyInt_FromLong( isInterfaceClass( r, obj ) );
494     }
495     return PyInt_FromLong( 0 );
496 }
497 
498 static PyObject * generateUuid( PyObject *, PyObject * )
499 {
500     Sequence< sal_Int8 > seq( 16 );
501     rtl_createUuid( (sal_uInt8*)seq.getArray() , 0 , sal_False );
502     PyRef ret;
503     try
504     {
505         Runtime runtime;
506         ret = runtime.any2PyObject( makeAny( seq ) );
507     }
508     catch( RuntimeException & e )
509     {
510         raisePyExceptionWithAny( makeAny(e) );
511     }
512     return ret.getAcquired();
513 }
514 
515 static PyObject *systemPathToFileUrl( PyObject *, PyObject * args )
516 {
517     PyObject *obj = extractOneStringArg( args, "pyuno.systemPathToFileUrl" );
518     if( ! obj )
519         return NULL;
520 
521     OUString sysPath = pyString2ustring( obj );
522     OUString url;
523     osl::FileBase::RC e = osl::FileBase::getFileURLFromSystemPath( sysPath, url );
524 
525     if( e != osl::FileBase::E_None )
526     {
527         OUStringBuffer buf;
528         buf.appendAscii( "Couldn't convert " );
529         buf.append( sysPath );
530         buf.appendAscii( " to a file url for reason (" );
531         buf.append( (sal_Int32) e );
532         buf.appendAscii( ")" );
533         raisePyExceptionWithAny(
534             makeAny( RuntimeException( buf.makeStringAndClear(), Reference< XInterface > () )));
535         return NULL;
536     }
537     return ustring2PyUnicode( url ).getAcquired();
538 }
539 
540 static PyObject * fileUrlToSystemPath( PyObject *, PyObject * args )
541 {
542     PyObject *obj = extractOneStringArg( args, "pyuno.fileUrlToSystemPath" );
543     if( ! obj )
544         return NULL;
545 
546     OUString url = pyString2ustring( obj );
547     OUString sysPath;
548     osl::FileBase::RC e = osl::FileBase::getSystemPathFromFileURL( url, sysPath );
549 
550     if( e != osl::FileBase::E_None )
551     {
552         OUStringBuffer buf;
553         buf.appendAscii( "Couldn't convert file url " );
554         buf.append( sysPath );
555         buf.appendAscii( " to a system path for reason (" );
556         buf.append( (sal_Int32) e );
557         buf.appendAscii( ")" );
558         raisePyExceptionWithAny(
559             makeAny( RuntimeException( buf.makeStringAndClear(), Reference< XInterface > () )));
560         return NULL;
561     }
562     return ustring2PyUnicode( sysPath ).getAcquired();
563 }
564 
565 static PyObject * absolutize( PyObject *, PyObject * args )
566 {
567     if( PyTuple_Check( args ) && PyTuple_Size( args ) == 2 )
568     {
569         OUString ouPath = pyString2ustring( PyTuple_GetItem( args , 0 ) );
570         OUString ouRel = pyString2ustring( PyTuple_GetItem( args, 1 ) );
571         OUString ret;
572         oslFileError e = osl_getAbsoluteFileURL( ouPath.pData, ouRel.pData, &(ret.pData) );
573         if( e != osl_File_E_None )
574         {
575             OUStringBuffer buf;
576             buf.appendAscii( "Couldn't absolutize " );
577             buf.append( ouRel );
578             buf.appendAscii( " using root " );
579             buf.append( ouPath );
580             buf.appendAscii( " for reason (" );
581             buf.append( (sal_Int32) e );
582             buf.appendAscii( ")" );
583 
584             PyErr_SetString(
585                 PyExc_OSError,
586                 OUStringToOString(buf.makeStringAndClear(),osl_getThreadTextEncoding()));
587             return 0;
588         }
589         return ustring2PyUnicode( ret ).getAcquired();
590     }
591     return 0;
592 }
593 
594 static PyObject * invoke ( PyObject *, PyObject * args )
595 {
596     PyObject *ret = 0;
597     if( PyTuple_Check( args ) && PyTuple_Size( args ) == 3 )
598     {
599         PyObject *object = PyTuple_GetItem( args, 0 );
600 
601         if( PyString_Check( PyTuple_GetItem( args, 1 ) ) )
602         {
603             const char *name = PyString_AsString( PyTuple_GetItem( args, 1 ) );
604             if( PyTuple_Check( PyTuple_GetItem( args , 2 )))
605             {
606                 ret = PyUNO_invoke( object, name , PyTuple_GetItem( args, 2 ) );
607             }
608             else
609             {
610                 OStringBuffer buf;
611                 buf.append( "uno.invoke expects a tuple as 3rd argument, got " );
612                 buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 2) ) ) );
613                 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
614             }
615         }
616         else
617         {
618             OStringBuffer buf;
619             buf.append( "uno.invoke expected a string as 2nd argument, got " );
620             buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 1) ) ) );
621             PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
622         }
623     }
624     else
625     {
626         OStringBuffer buf;
627         buf.append( "uno.invoke expects object, name, (arg1, arg2, ... )\n" );
628         PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
629     }
630     return ret;
631 }
632 
633 static PyObject *getCurrentContext( PyObject *, PyObject * )
634 {
635     PyRef ret;
636     try
637     {
638         Runtime runtime;
639         ret = runtime.any2PyObject(
640             makeAny( com::sun::star::uno::getCurrentContext() ) );
641     }
642     catch( com::sun::star::uno::Exception & e )
643     {
644         raisePyExceptionWithAny( makeAny( e ) );
645     }
646     return ret.getAcquired();
647 }
648 
649 static PyObject *setCurrentContext( PyObject *, PyObject * args )
650 {
651     PyRef ret;
652     try
653     {
654         if( PyTuple_Check( args ) && PyTuple_Size( args ) == 1 )
655         {
656 
657             Runtime runtime;
658             Any a = runtime.pyObject2Any( PyTuple_GetItem( args, 0 ) );
659 
660             Reference< com::sun::star::uno::XCurrentContext > context;
661 
662             if( (a.hasValue() && (a >>= context)) || ! a.hasValue() )
663             {
664                 ret = com::sun::star::uno::setCurrentContext( context ) ? Py_True : Py_False;
665             }
666             else
667             {
668                 OStringBuffer buf;
669                 buf.append( "uno.setCurrentContext expects an XComponentContext implementation, got " );
670                 buf.append( PyString_AsString( PyObject_Str( PyTuple_GetItem( args, 0) ) ) );
671                 PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
672             }
673         }
674         else
675         {
676             OStringBuffer buf;
677             buf.append( "uno.setCurrentContext expects exactly one argument (the current Context)\n" );
678             PyErr_SetString( PyExc_RuntimeError, buf.makeStringAndClear() );
679         }
680     }
681     catch( com::sun::star::uno::Exception & e )
682     {
683         raisePyExceptionWithAny( makeAny( e ) );
684     }
685     return ret.getAcquired();
686 }
687 
688 }
689 
690 struct PyMethodDef PyUNOModule_methods [] =
691 {
692     {const_cast< char * >("getComponentContext"), getComponentContext, 1, NULL},
693     {const_cast< char * >("_createUnoStructHelper"), createUnoStructHelper, 2, NULL},
694     {const_cast< char * >("getTypeByName"), getTypeByName, 1, NULL},
695     {const_cast< char * >("getConstantByName"), getConstantByName,1, NULL},
696     {const_cast< char * >("getClass"), getClass,1, NULL},
697     {const_cast< char * >("checkEnum"), checkEnum, 1, NULL},
698     {const_cast< char * >("checkType"), checkType, 1, NULL},
699     {const_cast< char * >("generateUuid"), generateUuid,0, NULL},
700     {const_cast< char * >("systemPathToFileUrl"),systemPathToFileUrl,1, NULL},
701     {const_cast< char * >("fileUrlToSystemPath"),fileUrlToSystemPath,1, NULL},
702     {const_cast< char * >("absolutize"),absolutize,2, NULL},
703     {const_cast< char * >("isInterface"),isInterface,1, NULL},
704     {const_cast< char * >("invoke"),invoke, 2, NULL},
705     {const_cast< char * >("setCurrentContext"),setCurrentContext,1, NULL},
706     {const_cast< char * >("getCurrentContext"),getCurrentContext,1, NULL},
707     {NULL, NULL, 0, NULL}
708 };
709 
710 }
711 
712 extern "C" PY_DLLEXPORT void initpyuno()
713 {
714     // noop when called already, otherwise needed to allow multiple threads
715     PyEval_InitThreads();
716     Py_InitModule (const_cast< char * >("pyuno"), PyUNOModule_methods);
717 }
718