25#include <rtl/ustrbuf.hxx> 
   27#include <typelib/typedescription.hxx> 
   29#include <com/sun/star/lang/XServiceInfo.hpp> 
   30#include <com/sun/star/lang/XTypeProvider.hpp> 
   31#include <com/sun/star/beans/UnknownPropertyException.hpp> 
   32#include <com/sun/star/container/XEnumerationAccess.hpp> 
   33#include <com/sun/star/container/XIndexAccess.hpp> 
   34#include <com/sun/star/container/XIndexContainer.hpp> 
   35#include <com/sun/star/container/XIndexReplace.hpp> 
   36#include <com/sun/star/container/XNameAccess.hpp> 
   37#include <com/sun/star/container/XNameContainer.hpp> 
   38#include <com/sun/star/container/XNameReplace.hpp> 
   39#include <com/sun/star/script/CannotConvertException.hpp> 
   40#include <com/sun/star/script/XInvocation2.hpp> 
   41#include <com/sun/star/script/XTypeConverter.hpp> 
   42#include <com/sun/star/lang/XSingleServiceFactory.hpp> 
   49using com::sun::star::uno::XInterface;
 
   50using com::sun::star::uno::Any;
 
   51using com::sun::star::uno::UNO_QUERY;
 
   52using com::sun::star::uno::Type;
 
   53using com::sun::star::uno::TypeClass;
 
   54using com::sun::star::uno::TypeDescription;
 
   55using com::sun::star::uno::RuntimeException;
 
   56using com::sun::star::uno::Exception;
 
   57using com::sun::star::lang::XSingleServiceFactory;
 
   58using com::sun::star::lang::XServiceInfo;
 
   59using com::sun::star::lang::XTypeProvider;
 
   60using com::sun::star::lang::XUnoTunnel;
 
   61using com::sun::star::script::XInvocation2;
 
   62using com::sun::star::container::XEnumeration;
 
   63using com::sun::star::container::XEnumerationAccess;
 
   64using com::sun::star::container::XIndexAccess;
 
   65using com::sun::star::container::XIndexContainer;
 
   66using com::sun::star::container::XIndexReplace;
 
   67using com::sun::star::container::XNameAccess;
 
   68using com::sun::star::container::XNameContainer;
 
   69using com::sun::star::container::XNameReplace;
 
   74static PyObject *
PyUNO_str( PyObject * self );
 
   87OUString 
val2str( 
const void * pVal, typelib_TypeDescriptionReference * pTypeRef , sal_Int32 
mode )
 
   90    if (pTypeRef->eTypeClass == typelib_TypeClass_VOID)
 
   93    OUStringBuffer buf( 64 );
 
   94    buf.append( 
"(" + OUString::unacquired(&pTypeRef->pTypeName) + 
")" );
 
   96    switch (pTypeRef->eTypeClass)
 
   98    case typelib_TypeClass_INTERFACE:
 
  101            OUString::number( 
reinterpret_cast< sal_IntPtr 
>(*
static_cast<void * 
const *
>(pVal)), 16 ));
 
  107            if( serviceInfo.is() )
 
  109                buf.append(
"implementationName=" 
  110                    + serviceInfo->getImplementationName()
 
  111                    + 
", supportedServices={" );
 
  113                for( 
int i = 0 ; 
i < seq.getLength() ; 
i ++ )
 
  115                    buf.append( seq[
i] );
 
  116                    if( 
i +1 != seq.getLength() )
 
  122            if( typeProvider.is() )
 
  124                buf.append(
", supportedInterfaces={" );
 
  126                for( 
int i = 0 ; 
i < seq.getLength() ; 
i ++ )
 
  129                    if( 
i +1 != seq.getLength() )
 
  139    case typelib_TypeClass_STRUCT:
 
  140    case typelib_TypeClass_EXCEPTION:
 
  144        TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
 
  145        assert( pTypeDescr );
 
  147        typelib_CompoundTypeDescription * pCompType = 
reinterpret_cast<typelib_CompoundTypeDescription *
>(pTypeDescr);
 
  148        sal_Int32 nDescr = pCompType->nMembers;
 
  150        if (pCompType->pBaseTypeDescription)
 
  152            buf.append( 
val2str( pVal, pCompType->pBaseTypeDescription->aBase.pWeakRef, 
mode ) );
 
  157        typelib_TypeDescriptionReference ** ppTypeRefs = pCompType->ppTypeRefs;
 
  158        sal_Int32 * pMemberOffsets = pCompType->pMemberOffsets;
 
  159        rtl_uString ** ppMemberNames = pCompType->ppMemberNames;
 
  163            buf.append( OUString::unacquired(&ppMemberNames[
nPos]) + 
" = " );
 
  165            TYPELIB_DANGER_GET( &pMemberType, ppTypeRefs[
nPos] );
 
  166            buf.append( 
val2str( 
static_cast<char const *
>(pVal) + pMemberOffsets[
nPos], pMemberType->pWeakRef, 
mode ) );
 
  167            TYPELIB_DANGER_RELEASE( pMemberType );
 
  168            if (
nPos < (nDescr -1))
 
  172        TYPELIB_DANGER_RELEASE( pTypeDescr );
 
  177    case typelib_TypeClass_SEQUENCE:
 
  180        TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
 
  182        uno_Sequence * pSequence = *
static_cast<uno_Sequence * 
const *
>(pVal);
 
  184        TYPELIB_DANGER_GET( &pElementTypeDescr, 
reinterpret_cast<typelib_IndirectTypeDescription *
>(pTypeDescr)->pType );
 
  186        sal_Int32 nElementSize = pElementTypeDescr->nSize;
 
  187        sal_Int32 
nElements = pSequence->nElements;
 
  192            char * pElements = pSequence->elements;
 
  195                buf.append( 
val2str( pElements + (nElementSize * 
nPos), pElementTypeDescr->pWeakRef, 
mode ) );
 
  205        TYPELIB_DANGER_RELEASE( pElementTypeDescr );
 
  206        TYPELIB_DANGER_RELEASE( pTypeDescr );
 
  209    case typelib_TypeClass_ANY:
 
  212                             static_cast<uno_Any const *
>(pVal)->pType ,
 
  216    case typelib_TypeClass_TYPE:
 
  217        buf.append( (*
static_cast<typelib_TypeDescriptionReference * 
const *
>(pVal))->pTypeName );
 
  219    case typelib_TypeClass_STRING:
 
  221            OUString::unacquired(&*
static_cast<rtl_uString * 
const *
>(pVal)) +
 
  224    case typelib_TypeClass_ENUM:
 
  227        TYPELIB_DANGER_GET( &pTypeDescr, pTypeRef );
 
  229        sal_Int32 * 
pValues = 
reinterpret_cast<typelib_EnumTypeDescription *
>(pTypeDescr)->pEnumValues;
 
  230        sal_Int32 
nPos = 
reinterpret_cast<typelib_EnumTypeDescription *
>(pTypeDescr)->nEnumValues;
 
  233            if (
pValues[
nPos] == *
static_cast<int const *
>(pVal))
 
  237            buf.append( 
reinterpret_cast<typelib_EnumTypeDescription *
>(pTypeDescr)->ppEnumNames[
nPos] );
 
  241        TYPELIB_DANGER_RELEASE( pTypeDescr );
 
  244    case typelib_TypeClass_BOOLEAN:
 
  245        if (*
static_cast<sal_Bool const *
>(pVal))
 
  246            buf.append( 
"true" );
 
  248            buf.append( 
"false" );
 
  250    case typelib_TypeClass_CHAR:
 
  252            + OUStringChar(*
static_cast<sal_Unicode const *
>(pVal) )
 
  255    case typelib_TypeClass_FLOAT:
 
  256        buf.append( *
static_cast<float const *
>(pVal) );
 
  258    case typelib_TypeClass_DOUBLE:
 
  259        buf.append( *
static_cast<double const *
>(pVal) );
 
  261    case typelib_TypeClass_BYTE:
 
  263            OUString::number( 
static_cast<sal_Int32
>(*
static_cast<sal_Int8 const *
>(pVal)), 16 ));
 
  265    case typelib_TypeClass_SHORT:
 
  267            OUString::number( 
static_cast<sal_Int32
>(*
static_cast<sal_Int16 
const *
>(pVal)), 16 ));
 
  269    case typelib_TypeClass_UNSIGNED_SHORT:
 
  271            OUString::number( 
static_cast<sal_Int32
>(*
static_cast<sal_uInt16 
const *
>(pVal)), 16 ));
 
  273    case typelib_TypeClass_LONG:
 
  275            OUString::number( *
static_cast<sal_Int32 
const *
>(pVal), 16 ));
 
  277    case typelib_TypeClass_UNSIGNED_LONG:
 
  279            OUString::number( 
static_cast<sal_Int64
>(*
static_cast<sal_uInt32 
const *
>(pVal)), 16 ));
 
  281    case typelib_TypeClass_HYPER:
 
  282    case typelib_TypeClass_UNSIGNED_HYPER:
 
  284#if defined(__GNUC__) && defined(SPARC) 
  289            *(sal_Int32 *)&aVal = *(sal_Int32 *)pVal;
 
  290            *((sal_Int32 *)&aVal +1)= *((sal_Int32 *)pVal +1);
 
  291            buf.append( aVal, 16 );
 
  294        buf.append( *
static_cast<sal_Int64 
const *
>(pVal), 16 );
 
  298    case typelib_TypeClass_VOID:
 
  299    case typelib_TypeClass_UNKNOWN:
 
  300    case typelib_TypeClass_SERVICE:
 
  301    case typelib_TypeClass_MODULE:
 
  306    return buf.makeStringAndClear();
 
  312    PyRef rIndex( PyNumber_Index( pObj ), SAL_NO_ACQUIRE );
 
  319    long nResult = PyLong_AsLongAndOverflow( pObj, &nOverflow );
 
  321        PyErr_SetString( PyExc_IndexError, 
"Python int too large to convert to UNO long" );
 
  328static int lcl_PySlice_GetIndicesEx( PyObject *pObject, sal_Int32 nLen, sal_Int32 *nStart, sal_Int32 *nStop, sal_Int32 *nStep, sal_Int32 *nSliceLength )
 
  330    Py_ssize_t nStart_ssize, nStop_ssize, nStep_ssize, nSliceLength_ssize;
 
  332    int nResult = PySlice_GetIndicesEx(
pObject,
 
  333        nLen, &nStart_ssize, &nStop_ssize, &nStep_ssize, &nSliceLength_ssize );
 
  342        PyErr_SetString( PyExc_IndexError, 
"Python int too large to convert to UNO long" );
 
  346    *nStart = 
static_cast<sal_Int32
>(nStart_ssize);
 
  347    *nStop = 
static_cast<sal_Int32
>(nStop_ssize);
 
  348    *nStep = 
static_cast<sal_Int32
>(nStep_ssize);
 
  349    *nSliceLength = 
static_cast<sal_Int32
>(nSliceLength_ssize);
 
  356    TypeDescription typeDesc( interfaceName );
 
  357    Any aInterface = xInterface->queryInterface( typeDesc.get()->pWeakRef );
 
  359    return aInterface.hasValue();
 
  374    return sal::static_int_cast< Py_hash_t >( 
reinterpret_cast< sal_IntPtr 
> (
 
  379PyObject *
PyUNO_invoke( PyObject *
object, 
const char *name , PyObject *args )
 
  386        PyRef paras,callable;
 
  406            paras = 
PyRef(PyTuple_New( 
size ), SAL_NO_ACQUIRE);
 
  408            for( 
int i = 0 ; 
i < 
size ;
i ++ )
 
  410                PyObject * element = PyTuple_GetItem( 
args , 
i );
 
  411                if( PyObject_IsInstance( element , 
getAnyClass( runtime ).
get() ) )
 
  413                    element = PyObject_GetAttrString(
 
  418                    Py_XINCREF( element );
 
  420                PyTuple_SetItem( paras.
get(), 
i , element );
 
  422            callable = 
PyRef( PyObject_GetAttrString( 
object , 
name ), SAL_NO_ACQUIRE );
 
  426        ret = 
PyRef( PyObject_CallObject( callable.
get(), paras.
get() ), SAL_NO_ACQUIRE );
 
  428    catch (
const css::lang::IllegalArgumentException &e)
 
  432    catch (
const css::script::CannotConvertException &e)
 
  436    catch (
const css::uno::RuntimeException &e)
 
  440    catch (
const css::uno::Exception &e)
 
  462    return PyUnicode_FromString( buf.getStr() );
 
  469    PyObject* member_list = 
nullptr;
 
  475        member_list = PyList_New (oo_member_list.getLength ());
 
  476        for (
int i = 0; 
i < oo_member_list.getLength (); 
i++)
 
  500    if ( xIndexAccess.is() )
 
  502        return xIndexAccess->getCount();
 
  508    if ( xNameAccess.is() )
 
  510        return xNameAccess->getElementNames().getLength();
 
  524            return nLen == 0 ? 0 : 1;
 
  529    catch( 
const css::uno::RuntimeException &e )
 
  547        PyErr_SetString( PyExc_TypeError, 
"object has no len()" );
 
  549    catch( 
const css::uno::RuntimeException &e )
 
  564    nRows = xIndexAccessRows->getCount();
 
  565    aRet = me->
members->
xInvocation->invoke ( 
"getColumns", aParams, aOutParamIndex, aOutParam );
 
  567    nColumns = xIndexAccessCols->getCount();
 
  572    Py_ssize_t 
nIndex = PyNumber_AsSsize_t( rIndex.
get(), PyExc_IndexError );
 
  573    if (
nIndex == -1 && PyErr_Occurred())
 
  575    PyRef rStart( PyLong_FromSsize_t( 
nIndex ), SAL_NO_ACQUIRE );
 
  576    PyRef rStop( PyLong_FromSsize_t( 
nIndex+1 ), SAL_NO_ACQUIRE );
 
  577    PyRef rStep( PyLong_FromLong( 1 ), SAL_NO_ACQUIRE );
 
  578    PyRef rSlice( PySlice_New( rStart.
get(), rStop.
get(), rStep.
get() ), SAL_NO_ACQUIRE );
 
  593    if ( PyUnicode_Check( pKey ) ) {
 
  599                "getCellRangeByName", aParams, aOutParamIndex, aOutParam );
 
  607    if ( PyIndex_Check( pKey ) )
 
  611        rKey1 = PySlice_New( 
nullptr, 
nullptr, 
nullptr );
 
  613    else if ( PyTuple_Check( pKey ) && (PyTuple_Size( pKey ) == 2) )
 
  615        rKey0 = PyTuple_GetItem( pKey, 0 );
 
  616        rKey1 = PyTuple_GetItem( pKey, 1 );
 
  620        PyErr_SetString( PyExc_KeyError, 
"invalid subscript" );
 
  625    if ( PyIndex_Check( rKey0.
get() ) && PyIndex_Check( rKey1.
get() ))
 
  630        if ( ((nKey0_s == -1) || (nKey1_s == -1)) && PyErr_Occurred() )
 
  633        aParams = { 
Any(nKey1_s), 
Any(nKey0_s) };
 
  637                "getCellByPosition", aParams, aOutParamIndex, aOutParam );
 
  644    if ( PyIndex_Check( rKey0.
get() ) )
 
  647    if ( PyIndex_Check( rKey1.
get() ) )
 
  651    if ( PySlice_Check( rKey0.
get() ) && PySlice_Check( rKey1.
get() ) )
 
  654        sal_Int32 nStart0 = 0, nStop0 = 0, nStep0 = 0, nSliceLength0 = 0;
 
  655        sal_Int32 nStart1 = 0, nStop1 = 0, nStep1 = 0, nSliceLength1 = 0;
 
  668        if ( ((nSuccess1 == -1) || (nSuccess2 == -1)) && PyErr_Occurred() )
 
  671        if ( nSliceLength0 <= 0 || nSliceLength1 <= 0 )
 
  673            PyErr_SetString( PyExc_KeyError, 
"invalid number of rows or columns" );
 
  677        if ( nStep0 == 1 && nStep1 == 1 )
 
  679            aParams = { 
Any(nStart1), 
Any(nStart0), 
Any(nStop1 - 1), 
Any(nStop0 - 1) };
 
  683                    "getCellRangeByPosition", aParams, aOutParamIndex, aOutParam );
 
  689        PyErr_SetString( PyExc_KeyError, 
"step != 1 not supported" );
 
  693    PyErr_SetString( PyExc_KeyError, 
"invalid subscript" );
 
  703    if (
nIndex == -1 && PyErr_Occurred())
 
  710        if ( xIndexAccess.is() )
 
  713                nIndex += xIndexAccess->getCount();
 
  714            aRet = xIndexAccess->getByIndex( 
nIndex );
 
  717    if ( aRet.hasValue() )
 
  737        if ( xIndexAccess.is() )
 
  738            nLen = xIndexAccess->getCount();
 
  744    sal_Int32 nStart = 0, nStop = 0, nStep = 0, nSliceLength = 0;
 
  746    if ( nSuccess == -1 && PyErr_Occurred() )
 
  749    PyRef rTuple( PyTuple_New( nSliceLength ), SAL_NO_ACQUIRE, 
NOT_NULL );
 
  751    for ( nCur = nStart, 
i = 0; 
i < nSliceLength; nCur += nStep, 
i++ )
 
  758            aRet = xIndexAccess->getByIndex( nCur );
 
  776        if ( xNameAccess.is() )
 
  778            aRet = xNameAccess->getByName( sKey );
 
  781    if ( aRet.hasValue() )
 
  798        if ( PyIndex_Check( pKey ) )
 
  801            if ( pRet != 
nullptr || PyErr_Occurred() )
 
  806        if ( PySlice_Check( pKey ) )
 
  809            if ( pRet != 
nullptr || PyErr_Occurred() )
 
  814        if ( PyUnicode_Check( pKey ) )
 
  817            if ( pRet != 
nullptr )
 
  823        bool hasXCellRange = 
false;
 
  841        if ( xIndexAccess.is() || xNameAccess.is() )
 
  843            PyErr_SetString( PyExc_TypeError, 
"subscription with invalid type" );
 
  847        PyErr_SetString( PyExc_TypeError, 
"object is not subscriptable" );
 
  849    catch( 
const css::lang::IndexOutOfBoundsException & )
 
  851        PyErr_SetString( PyExc_IndexError, 
"index out of range" );
 
  853    catch( 
const css::container::NoSuchElementException & )
 
  855        PyErr_SetString( PyExc_KeyError, 
"key not found" );
 
  857    catch( 
const css::script::CannotConvertException &e )
 
  861    catch( 
const css::lang::IllegalArgumentException &e )
 
  865    catch( 
const css::lang::WrappedTargetException &e )
 
  869    catch( 
const css::uno::RuntimeException &e )
 
  884    if ( 
nIndex == -1 && PyErr_Occurred() )
 
  887    bool isTuple = 
false;
 
  890    if ( pValue != 
nullptr )
 
  892        isTuple = PyTuple_Check( pValue );
 
  898        catch ( 
const css::uno::RuntimeException & )
 
  903            throw css::script::CannotConvertException();
 
  911        if ( xIndexContainer.is() )
 
  912            xIndexReplace = xIndexContainer;
 
  916        if ( xIndexReplace.is() && 
nIndex < 0 )
 
  917            nIndex += xIndexReplace->getCount();
 
  920        if ( (pValue != 
nullptr) && xIndexReplace.is() )
 
  925                Type aType = xIndexReplace->getElementType();
 
  929            xIndexReplace->replaceByIndex( 
nIndex, aValue );
 
  934        if ( (pValue == 
nullptr) && xIndexContainer.is() )
 
  936            xIndexContainer->removeByIndex( 
nIndex );
 
  941    PyErr_SetString( PyExc_TypeError, 
"cannot assign to object" );
 
  958        if ( xIndexContainer.is() )
 
  959            xIndexReplace = xIndexContainer;
 
  963        if ( xIndexReplace.is() )
 
  964            nLen = xIndexReplace->getCount();
 
  967    if ( xIndexReplace.is() )
 
  969        sal_Int32 nStart = 0, nStop = 0, nStep = 0, nSliceLength = 0;
 
  971        if ( (nSuccess == -1) && PyErr_Occurred() )
 
  974        if ( pValue == 
nullptr )
 
  976            pValue = PyTuple_New( 0 );
 
  979        if ( !PyTuple_Check (pValue) )
 
  981            PyErr_SetString( PyExc_TypeError, 
"value is not a tuple" );
 
  985        Py_ssize_t nTupleLength_ssize = PyTuple_Size( pValue );
 
  988            PyErr_SetString( PyExc_ValueError, 
"tuple too large" );
 
  991        sal_Int32 nTupleLength = 
static_cast<sal_Int32
>(nTupleLength_ssize);
 
  993        if ( (nTupleLength != nSliceLength) && (nStep != 1) )
 
  995            PyErr_SetString( PyExc_ValueError, 
"number of items assigned must be equal" );
 
  999        if ( (nTupleLength != nSliceLength) && !xIndexContainer.is() )
 
 1001            PyErr_SetString( PyExc_ValueError, 
"cannot change length" );
 
 1006        sal_Int32 nMax = ::std::max( nSliceLength, nTupleLength );
 
 1007        for ( nCur = nStart, 
i = 0; 
i < nMax; nCur += nStep, 
i++ )
 
 1009            if ( 
i < nTupleLength )
 
 1011                PyRef rItem = PyTuple_GetItem( pValue, 
i );
 
 1012                bool isTuple = PyTuple_Check( rItem.
get() );
 
 1019                catch ( 
const css::uno::RuntimeException & )
 
 1024                    throw css::script::CannotConvertException();
 
 1033                        Type aType = xIndexReplace->getElementType();
 
 1037                    if ( 
i < nSliceLength )
 
 1039                        xIndexReplace->replaceByIndex( nCur, aItem );
 
 1043                        xIndexContainer->insertByIndex( nCur, aItem );
 
 1051                xIndexContainer->removeByIndex( nCur );
 
 1059    PyErr_SetString( PyExc_TypeError, 
"cannot assign to object" );
 
 1068    bool isTuple = 
false;
 
 1071    if ( pValue != 
nullptr)
 
 1073        isTuple = PyTuple_Check( pValue );
 
 1078        catch( 
const css::uno::RuntimeException & )
 
 1083            throw css::script::CannotConvertException();
 
 1092        if ( xNameContainer.is() )
 
 1093            xNameReplace = xNameContainer;
 
 1097        if ( xNameReplace.is() )
 
 1099            if ( isTuple && aValue.hasValue() )
 
 1102                Type aType = xNameReplace->getElementType();
 
 1106            if ( aValue.hasValue() )
 
 1108                if ( xNameContainer.is() )
 
 1111                        xNameContainer->insertByName( sKey, aValue );
 
 1114                    catch( 
const css::container::ElementExistException & )
 
 1120                xNameReplace->replaceByName( sKey, aValue );
 
 1123            else if ( xNameContainer.is() )
 
 1125                xNameContainer->removeByName( sKey );
 
 1131    PyErr_SetString( PyExc_TypeError, 
"cannot assign to object" );
 
 1141        if ( PyIndex_Check( pKey ) )
 
 1145        else if ( PySlice_Check( pKey ) )
 
 1149        else if ( PyUnicode_Check( pKey ) )
 
 1154        PyErr_SetString( PyExc_TypeError, 
"list index has invalid type" );
 
 1156    catch( 
const css::lang::IndexOutOfBoundsException & )
 
 1158        PyErr_SetString( PyExc_IndexError, 
"list index out of range" );
 
 1160    catch( 
const css::container::NoSuchElementException & )
 
 1162        PyErr_SetString( PyExc_KeyError, 
"key not found" );
 
 1164    catch( 
const css::lang::IllegalArgumentException & )
 
 1166        PyErr_SetString( PyExc_TypeError, 
"value has invalid type" );
 
 1168    catch( 
const css::script::CannotConvertException & )
 
 1170        PyErr_SetString( PyExc_TypeError, 
"value has invalid type" );
 
 1172    catch( 
const css::container::ElementExistException &e )
 
 1176    catch( 
const css::lang::WrappedTargetException &e )
 
 1180    catch( 
const css::uno::RuntimeException &e )
 
 1203            if ( xEnumerationAccess.is() )
 
 1204                xEnumeration = xEnumerationAccess->createEnumeration();
 
 1208            if ( !xEnumeration.is() )
 
 1211            if ( !xIndexAccess.is() )
 
 1217        if (xEnumeration.is())
 
 1223        if ( xIndexAccess.is() )
 
 1231        if (xNameAccess.is())
 
 1240                aRet <<= xNameAccess->getElementNames();
 
 1246        PyErr_SetString ( PyExc_TypeError, 
"object is not iterable" );
 
 1248    catch( css::script::CannotConvertException &e )
 
 1252    catch( css::lang::IllegalArgumentException &e )
 
 1256    catch( 
const css::uno::RuntimeException &e )
 
 1277        catch( 
const css::uno::RuntimeException & )
 
 1282            throw css::script::CannotConvertException();
 
 1289        if ( PyUnicode_Check( pKey ) )
 
 1299                if ( xNameAccess.is() )
 
 1301                    bool hasKey = xNameAccess->hasByName( sKey );
 
 1302                    return hasKey ? 1 : 0;
 
 1310        if ( rIterator.
is() )
 
 1312            while ( PyObject* pItem = PyIter_Next( rIterator.
get() ) )
 
 1314                PyRef rItem( pItem, SAL_NO_ACQUIRE );
 
 1315                if ( PyObject_RichCompareBool( pKey, rItem.
get(), Py_EQ ) == 1 )
 
 1323        PyErr_SetString( PyExc_TypeError, 
"argument is not iterable" );
 
 1325    catch( 
const css::script::CannotConvertException& )
 
 1327        PyErr_SetString( PyExc_TypeError, 
"invalid type passed as left argument to 'in'" );
 
 1329    catch( 
const css::container::NoSuchElementException &e )
 
 1333    catch( 
const css::lang::IndexOutOfBoundsException &e )
 
 1337    catch( 
const css::lang::IllegalArgumentException &e )
 
 1341    catch( 
const css::lang::WrappedTargetException &e )
 
 1345    catch( 
const css::uno::RuntimeException &e )
 
 1361        if (strcmp (
name, 
"__dict__") == 0)
 
 1363            Py_INCREF (Py_TYPE(me)->tp_dict);
 
 1364            return Py_TYPE(me)->tp_dict;
 
 1366        if (strcmp (
name, 
"__class__") == 0)
 
 1368            Py_INCREF (Py_None);
 
 1372        PyObject *pRet = PyObject_GenericGetAttr( self, PyUnicode_FromString( 
name ) );
 
 1377        OUString 
attrName( OUString::createFromAscii( 
name ) );
 
 1390            Py_XINCREF( ret.
get() );
 
 1410            Py_XINCREF( ret.
get() );
 
 1415        PyErr_SetString (PyExc_AttributeError, 
name);
 
 1417    catch( 
const css::reflection::InvocationTargetException & e )
 
 1421    catch( 
const css::beans::UnknownPropertyException & e )
 
 1425    catch( 
const css::lang::IllegalArgumentException &e )
 
 1429    catch( 
const css::script::CannotConvertException &e )
 
 1445    me = 
reinterpret_cast<PyUNO*
>(self);
 
 1451        OUString 
attrName( OUString::createFromAscii( 
name ) );
 
 1461    catch( 
const css::reflection::InvocationTargetException & e )
 
 1466    catch( 
const css::beans::UnknownPropertyException & e )
 
 1471    catch( 
const css::script::CannotConvertException &e )
 
 1481    PyErr_SetString (PyExc_AttributeError, 
name);
 
 1485static PyObject* 
PyUNO_cmp( PyObject *self, PyObject *that, 
int op )
 
 1489    if(op != Py_EQ && op != Py_NE)
 
 1491        PyErr_SetString(PyExc_TypeError, 
"only '==' and '!=' comparisons are defined");
 
 1496        result = (op == Py_EQ ? Py_True : Py_False);
 
 1506            PyUNO *me = 
reinterpret_cast< PyUNO*
> ( self );
 
 1507            PyUNO *other = 
reinterpret_cast< PyUNO *
> (that );
 
 1511            if( tcMe == tcOther )
 
 1515                    result = (op == Py_EQ ? Py_True : Py_False);
 
 1522    catch( 
const css::uno::RuntimeException & e)
 
 1527    result = (op == Py_EQ ? Py_False : Py_True);
 
 1534    {
"__dir__",    
reinterpret_cast<PyCFunction
>(
PyUNO_dir),    METH_NOARGS,  
nullptr},
 
 1535    {
nullptr,         
nullptr,                                        0,            
nullptr}
 
 1576#if PY_MAJOR_VERSION == 3 && PY_MINOR_VERSION >= 5 
 1605    PyVarObject_HEAD_INIT( &PyType_Type, 0 )
 
 1610#
if PY_VERSION_HEX >= 0x03080000
 
 1656#
if PY_VERSION_HEX >= 0x03040000
 
 1658#
if PY_VERSION_HEX >= 0x03080000
 
 1660#
if PY_VERSION_HEX < 0x03090000
 
 1661#
if defined __clang__
 
 1662#pragma clang diagnostic push
 
 1663#pragma clang diagnostic ignored 
"-Wdeprecated-declarations" 
 1666#
if defined __clang__
 
 1667#pragma clang diagnostic pop
 
 1685    const Any &targetInterface,
 
 1693            ssf->createInstanceWithArguments( 
Sequence<Any>( &targetInterface, 1 ) ), css::uno::UNO_QUERY_THROW );
 
 1695        auto that = comphelper::getFromUnoTunnel<Adapter>(
 
 1698            return that->getWrappedObject();
 
 1700    if( !Py_IsInitialized() )
 
 1704    if (self == 
nullptr)
 
 1709    return PyRef( 
reinterpret_cast<PyObject*
>(self), SAL_NO_ACQUIRE );
 
const PropertyValue * pValues
 
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
 
helper class for detaching the current thread from the python runtime to do some blocking,...
 
The pyuno::Runtime class keeps the internal state of the python UNO bridge for the currently in use p...
 
css::uno::Any pyObject2Any(const PyRef &source, enum ConversionMode mode=REJECT_UNO_ANY) const
converts a Python object to a UNO any
 
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.
 
EmbeddedObjectRef * pObject
 
std::unique_ptr< sal_Int32[]> pData
 
struct _typelib_TypeDescription typelib_TypeDescription
 
rtl::OUString getTypeName(rtl::OUString const &rEnvDcp)
 
OString OUStringToOString(std::u16string_view str, ConnectionSettings const *settings)
 
static Py_ssize_t PyUNO_len(PyObject *self)
 
static PyObject * PyUNO_str(PyObject *self)
 
static sal_Int32 lcl_PyNumber_AsSal_Int32(PyObject *pObj)
 
static PyObject * lcl_getitem_XCellRange(PyUNO const *me, PyObject *pKey)
 
static PySequenceMethods PyUNOSequenceMethods[]
 
static PyObject * PyUNO_cmp(PyObject *self, PyObject *that, int op)
 
PyObject * PyUNO_list_iterator_new(const css::uno::Reference< css::container::XIndexAccess > &xIndexAccess)
 
static PyNumberMethods PyUNONumberMethods[]
 
static sal_Int32 lcl_detach_getLength(PyUNO const *me)
 
static Py_hash_t PyUNO_hash(PyObject *self)
 
static void PyUNO_del(PyObject *self)
 
PyRef PyUNO_new(const Any &targetInterface, const Reference< XSingleServiceFactory > &ssf)
 
const sal_Int32 VAL2STR_MODE_DEEP
 
static int PyUNO_setattr(PyObject *self, char *name, PyObject *value)
 
static int lcl_setitem_string(PyUNO const *me, PyObject *pKey, PyObject *pValue)
 
static int lcl_setitem_slice(PyUNO const *me, PyObject *pKey, PyObject *pValue)
 
static PyObject * PyUNO_repr(PyObject *self)
 
static PyRef lcl_indexToSlice(const PyRef &rIndex)
 
PyRef ustring2PyString(std::u16string_view source)
 
static PyObject * PyUNO_getattr(PyObject *self, char *name)
 
static PyObject * lcl_getitem_index(PyUNO const *me, PyObject *pKey, Runtime const &runtime)
 
static int lcl_PySlice_GetIndicesEx(PyObject *pObject, sal_Int32 nLen, sal_Int32 *nStart, sal_Int32 *nStop, sal_Int32 *nStep, sal_Int32 *nSliceLength)
 
static PyObject * PyUNO_dir(PyObject *self)
 
static PyMethodDef PyUNOMethods[]
 
static int PyUNO_contains(PyObject *self, PyObject *pKey)
 
void raisePyExceptionWithAny(const css::uno::Any &anyExc)
 
static PyObject * lcl_getitem_string(PyUNO const *me, PyObject *pKey, Runtime const &runtime)
 
PyObject * PyUNO_iterator_new(const css::uno::Reference< css::container::XEnumeration > &xEnumeration)
 
static int PyUNO_setitem(PyObject *self, PyObject *pKey, PyObject *pValue)
 
static int PyUNO_bool(PyObject *self)
 
static PyTypeObject PyUNOType
 
OUString val2str(const void *pVal, typelib_TypeDescriptionReference *pTypeRef, sal_Int32 mode)
 
static void lcl_getRowsColumns(PyUNO const *me, sal_Int32 &nRows, sal_Int32 &nColumns)
 
static PyObject * lcl_getitem_slice(PyUNO const *me, PyObject *pKey)
 
static PyObject * PyUNO_getitem(PyObject *self, PyObject *pKey)
 
OUString pyString2ustring(PyObject *str)
 
PyObject * PyUNO_invoke(PyObject *object, const char *name, PyObject *args)
 
@ NOT_NULL
definition of a no acquire enum for ctors
 
PyRef PyUNO_callable_new(const Reference< XInvocation2 > &my_inv, const OUString &methodName, enum ConversionMode mode)
 
PyRef getAnyClass(const Runtime &)
 
static bool lcl_hasInterfaceByName(Any const &object, OUString const &interfaceName)
 
static PyMappingMethods PyUNOMappingMethods[]
 
static PyObject * PyUNO_iter(PyObject *self)
 
static int lcl_setitem_index(PyUNO const *me, PyObject *pKey, PyObject *pValue)
 
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
 
Reference< XInvocation2 > xInvocation
 
#define Py_TPFLAGS_HAVE_SEQUENCE_IN
 
#define Py_TPFLAGS_HAVE_ITER
 
#define Py_TPFLAGS_HAVE_RICHCOMPARE
 
css::uno::Any wrappedObject
 
css::uno::Reference< css::script::XInvocation2 > xInvocation
 
PyObject_HEAD PyUNOInternals * members
 
css::uno::Reference< css::script::XTypeConverter > xTypeConverter
 
PyObject_HEAD struct RuntimeCargo * cargo