pyuno_except.cxx (67c7d1c1) | pyuno_except.cxx (77dc4149) |
---|---|
1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 128 unchanged lines hidden (view full) --- 137 { 138 if( isExc ) 139 // we are currently creating the root UNO exception 140 base = PyRef(PyExc_Exception); 141 } 142 } 143 PyRef args( PyTuple_New( 3 ), SAL_NO_ACQUIRE ); 144 | 1/************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance --- 128 unchanged lines hidden (view full) --- 137 { 138 if( isExc ) 139 // we are currently creating the root UNO exception 140 base = PyRef(PyExc_Exception); 141 } 142 } 143 PyRef args( PyTuple_New( 3 ), SAL_NO_ACQUIRE ); 144 |
145 PyRef pyTypeName = ustring2PyString( name /*.replace( '.', '_' )*/ ); | 145 PyRef pyTypeName = USTR_TO_PYSTR( name /*.replace( '.', '_' )*/ ); |
146 147 PyRef bases; 148 if( base.is() ) 149 { 150 { // for CC, keeping ref-count being 1 151 bases = PyRef( PyTuple_New( 1 ), SAL_NO_ACQUIRE ); 152 } 153 PyTuple_SetItem( bases.get(), 0 , base.getAcquired() ); 154 } 155 else 156 { 157 bases = PyRef( PyTuple_New( 0 ), SAL_NO_ACQUIRE ); 158 } 159 160 PyTuple_SetItem( args.get(), 0, pyTypeName.getAcquired()); 161 PyTuple_SetItem( args.get(), 1, bases.getAcquired() ); 162 PyTuple_SetItem( args.get(), 2, PyDict_New() ); 163 164 PyRef ret( | 146 147 PyRef bases; 148 if( base.is() ) 149 { 150 { // for CC, keeping ref-count being 1 151 bases = PyRef( PyTuple_New( 1 ), SAL_NO_ACQUIRE ); 152 } 153 PyTuple_SetItem( bases.get(), 0 , base.getAcquired() ); 154 } 155 else 156 { 157 bases = PyRef( PyTuple_New( 0 ), SAL_NO_ACQUIRE ); 158 } 159 160 PyTuple_SetItem( args.get(), 0, pyTypeName.getAcquired()); 161 PyTuple_SetItem( args.get(), 1, bases.getAcquired() ); 162 PyTuple_SetItem( args.get(), 2, PyDict_New() ); 163 164 PyRef ret( |
165 PyObject_CallObject(reinterpret_cast<PyObject *>(&PyClass_Type) , args.get()), | 165 PyObject_CallObject(reinterpret_cast<PyObject *>(&PyType_Type) , args.get()), |
166 SAL_NO_ACQUIRE ); 167 168 // now overwrite ctor and attrib functions 169 if( isInterface ) 170 { 171 PyObject_SetAttrString( 172 ret.get(), const_cast< char * >("__pyunointerface__"), | 166 SAL_NO_ACQUIRE ); 167 168 // now overwrite ctor and attrib functions 169 if( isInterface ) 170 { 171 PyObject_SetAttrString( 172 ret.get(), const_cast< char * >("__pyunointerface__"), |
173 ustring2PyString(name).get() ); | 173 USTR_TO_PYSTR(name).get() ); |
174 } 175 else 176 { 177 PyRef ctor = getObjectFromUnoModule( runtime,"_uno_struct__init__" ); 178 PyRef setter = getObjectFromUnoModule( runtime,"_uno_struct__setattr__" ); 179 PyRef getter = getObjectFromUnoModule( runtime,"_uno_struct__getattr__" ); 180 PyRef repr = getObjectFromUnoModule( runtime,"_uno_struct__repr__" ); 181 PyRef eq = getObjectFromUnoModule( runtime,"_uno_struct__eq__" ); | 174 } 175 else 176 { 177 PyRef ctor = getObjectFromUnoModule( runtime,"_uno_struct__init__" ); 178 PyRef setter = getObjectFromUnoModule( runtime,"_uno_struct__setattr__" ); 179 PyRef getter = getObjectFromUnoModule( runtime,"_uno_struct__getattr__" ); 180 PyRef repr = getObjectFromUnoModule( runtime,"_uno_struct__repr__" ); 181 PyRef eq = getObjectFromUnoModule( runtime,"_uno_struct__eq__" ); |
182#if PY_MAJOR_VERSION >= 3 183 PyRef dir = getObjectFromUnoModule( runtime, "_uno_struct__dir__" ); 184#endif |
|
182 183 PyObject_SetAttrString( 184 ret.get(), const_cast< char * >("__pyunostruct__"), | 185 186 PyObject_SetAttrString( 187 ret.get(), const_cast< char * >("__pyunostruct__"), |
185 ustring2PyString(name).get() ); | 188 USTR_TO_PYSTR(name).get() ); |
186 PyObject_SetAttrString( 187 ret.get(), const_cast< char * >("typeName"), | 189 PyObject_SetAttrString( 190 ret.get(), const_cast< char * >("typeName"), |
188 ustring2PyString(name).get() ); | 191 USTR_TO_PYSTR(name).get() ); |
189 PyObject_SetAttrString( 190 ret.get(), const_cast< char * >("__init__"), ctor.get() ); 191 PyObject_SetAttrString( 192 ret.get(), const_cast< char * >("__getattr__"), getter.get() ); 193 PyObject_SetAttrString( 194 ret.get(), const_cast< char * >("__setattr__"), setter.get() ); 195 PyObject_SetAttrString( 196 ret.get(), const_cast< char * >("__repr__"), repr.get() ); 197 PyObject_SetAttrString( 198 ret.get(), const_cast< char * >("__str__"), repr.get() ); 199 PyObject_SetAttrString( 200 ret.get(), const_cast< char * >("__eq__"), eq.get() ); | 192 PyObject_SetAttrString( 193 ret.get(), const_cast< char * >("__init__"), ctor.get() ); 194 PyObject_SetAttrString( 195 ret.get(), const_cast< char * >("__getattr__"), getter.get() ); 196 PyObject_SetAttrString( 197 ret.get(), const_cast< char * >("__setattr__"), setter.get() ); 198 PyObject_SetAttrString( 199 ret.get(), const_cast< char * >("__repr__"), repr.get() ); 200 PyObject_SetAttrString( 201 ret.get(), const_cast< char * >("__str__"), repr.get() ); 202 PyObject_SetAttrString( 203 ret.get(), const_cast< char * >("__eq__"), eq.get() ); |
204#if PY_MAJOR_VERSION >= 3 205 PyObject_SetAttrString( 206 ret.get(), const_cast< char * >("__dir__"), dir.get() ); 207#endif |
|
201 } 202 return ret; 203} 204 205bool isInstanceOfStructOrException( PyObject *obj) 206{ 207 PyRef attr( 208 PyObject_GetAttrString(obj, const_cast< char * >("__class__")), --- 19 unchanged lines hidden (view full) --- 228 ret = createClass( name, runtime ); 229 cargo->exceptionMap[name] = ret; 230 if( PyObject_HasAttrString( 231 ret.get(), const_cast< char * >("__pyunointerface__") ) ) 232 cargo->interfaceSet.insert( ret ); 233 234 PyObject_SetAttrString( 235 ret.get(), const_cast< char * >("__pyunointerface__"), | 208 } 209 return ret; 210} 211 212bool isInstanceOfStructOrException( PyObject *obj) 213{ 214 PyRef attr( 215 PyObject_GetAttrString(obj, const_cast< char * >("__class__")), --- 19 unchanged lines hidden (view full) --- 235 ret = createClass( name, runtime ); 236 cargo->exceptionMap[name] = ret; 237 if( PyObject_HasAttrString( 238 ret.get(), const_cast< char * >("__pyunointerface__") ) ) 239 cargo->interfaceSet.insert( ret ); 240 241 PyObject_SetAttrString( 242 ret.get(), const_cast< char * >("__pyunointerface__"), |
236 ustring2PyString(name).get() ); | 243 USTR_TO_PYSTR(name).get() ); |
237 } 238 else 239 { 240 ret = ii->second; 241 } 242 243 return ret; 244} 245 246 247} | 244 } 245 else 246 { 247 ret = ii->second; 248 } 249 250 return ret; 251} 252 253 254} |