21#include <typelib/typedescription.hxx>
22#include <com/sun/star/script/CannotConvertException.hpp>
25using com::sun::star::uno::RuntimeException;
26using com::sun::star::uno::XInterface;
27using com::sun::star::uno::TypeDescription;
41 PyErr_SetObject(
type.get(), exc.
get());
45 css::uno::Exception e;
48 OUString buf =
"Couldn't convert uno exception to a python exception (" +
49 anyExc.getValueType().getTypeName() +
": " + e.Message +
")";
55 catch(
const css::lang::IllegalArgumentException & e)
57 PyErr_SetString( PyExc_SystemError,
60 catch(
const css::script::CannotConvertException & e)
62 PyErr_SetString( PyExc_SystemError,
67 PyErr_SetString( PyExc_SystemError,
77 TypeDescription desc(
name );
83 bool isStruct = desc.get()->eTypeClass == typelib_TypeClass_STRUCT;
84 bool isExc = desc.get()->eTypeClass == typelib_TypeClass_EXCEPTION;
85 bool isInterface = desc.get()->eTypeClass == typelib_TypeClass_INTERFACE;
89 OUString::createFromAscii(
typeClassToString(
static_cast<css::uno::TypeClass
>(desc.get()->eTypeClass)) ) +
90 ", expected EXCEPTION, STRUCT or INTERFACE" );
97 typelib_InterfaceTypeDescription *pDesc =
reinterpret_cast<typelib_InterfaceTypeDescription *
>(desc.get());
98 if( pDesc->pBaseTypeDescription )
100 base =
getClass( pDesc->pBaseTypeDescription->aBase.pTypeName, runtime );
109 typelib_CompoundTypeDescription *pDesc =
reinterpret_cast<typelib_CompoundTypeDescription*
>(desc.get());
110 if( pDesc->pBaseTypeDescription )
112 base =
getClass( pDesc->pBaseTypeDescription->aBase.pTypeName, runtime );
129 bases =
PyRef( PyTuple_New( 1 ), SAL_NO_ACQUIRE );
131 PyTuple_SetItem( bases.
get(), 0 ,
base.getAcquired() );
135 bases =
PyRef( PyTuple_New( 0 ), SAL_NO_ACQUIRE );
140 PyTuple_SetItem(
args.get(), 2, PyDict_New() );
143 PyObject_CallObject(
reinterpret_cast<PyObject *
>(&PyType_Type) ,
args.get()),
149 PyObject_SetAttrString(
150 ret.
get(),
"__pyunointerface__",
162 PyObject_SetAttrString(
163 ret.
get(),
"__pyunostruct__",
165 PyObject_SetAttrString(
166 ret.
get(),
"typeName",
168 PyObject_SetAttrString(
169 ret.
get(),
"__init__", ctor.
get() );
170 PyObject_SetAttrString(
171 ret.
get(),
"__getattr__", getter.
get() );
172 PyObject_SetAttrString(
173 ret.
get(),
"__setattr__", setter.
get() );
174 PyObject_SetAttrString(
175 ret.
get(),
"__repr__", repr.
get() );
176 PyObject_SetAttrString(
177 ret.
get(),
"__str__", repr.
get() );
178 PyObject_SetAttrString(
179 ret.
get(),
"__eq__", eq.
get() );
180 PyObject_SetAttrString(
181 ret.
get(),
"__ne__", ne.
get() );
189 PyObject_GetAttrString(obj,
"__class__"),
192 return PyObject_HasAttrString(attr.
get(),
"__pyunostruct__");
200 return set.find( obj ) !=
set.end();
213 if( PyObject_HasAttrString(
214 ret.
get(),
"__pyunointerface__" ) )
217 PyObject_SetAttrString(
218 ret.
get(),
"__pyunointerface__",
Helper class for keeping references to python objects.
bool is() const
returns 1 when the reference points to a python object python object, otherwise 0.
PyObject * get() const noexcept
PyObject * getAcquired() const
The pyuno::Runtime class keeps the internal state of the python UNO bridge for the currently in use p...
PyRef any2PyObject(const css::uno::Any &source) const
converts something contained in a UNO Any to a Python object
RuntimeImpl * getImpl() const
Returns the internal handle.
void set(css::uno::UnoInterfaceReference const &value)
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
bool isInstanceOfStructOrException(PyObject *obj)
PyRef ustring2PyString(std::u16string_view source)
static PyRef createClass(const OUString &name, const Runtime &runtime)
const char * typeClassToString(css::uno::TypeClass t)
void raisePyExceptionWithAny(const css::uno::Any &anyExc)
std::unordered_set< PyRef, PyRef::Hash > ClassSet
bool isInterfaceClass(const Runtime &runtime, PyObject *obj)
@ NOT_NULL
definition of a no acquire enum for ctors
PyRef getObjectFromUnoModule(const Runtime &runtime, const char *object)
PyRef getClass(const OUString &name, const Runtime &runtime)
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
ExceptionClassMap exceptionMap
PyObject_HEAD struct RuntimeCargo * cargo