pyuno.cxx (564d9007) | pyuno.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 --- 328 unchanged lines hidden (view full) --- 337PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args ) 338{ 339 PyRef ret; 340 try 341 { 342 Runtime runtime; 343 344 PyRef paras,callable; | 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 --- 328 unchanged lines hidden (view full) --- 337PyObject *PyUNO_invoke( PyObject *object, const char *name , PyObject *args ) 338{ 339 PyRef ret; 340 try 341 { 342 Runtime runtime; 343 344 PyRef paras,callable; |
345 if( PyObject_IsInstance( object, getPyUnoClass( runtime ).get() ) ) | 345 if( PyObject_IsInstance( object, getPyUnoClass().get() ) ) |
346 { 347 PyUNO* me = (PyUNO*) object; 348 OUString attrName = OUString::createFromAscii(name); 349 if (! me->members->xInvocation->hasMethod (attrName)) 350 { 351 OUStringBuffer buf; 352 buf.appendAscii( "Attribute " ); 353 buf.append( attrName ); --- 82 unchanged lines hidden (view full) --- 436 PyThreadDetach antiguard; 437 buf.append( "pyuno object " ); 438 439 OUString s = val2str( (void*)me->members->wrappedObject.getValue(), 440 me->members->wrappedObject.getValueType().getTypeLibType() ); 441 buf.append( OUStringToOString(s,RTL_TEXTENCODING_ASCII_US) ); 442 } 443 | 346 { 347 PyUNO* me = (PyUNO*) object; 348 OUString attrName = OUString::createFromAscii(name); 349 if (! me->members->xInvocation->hasMethod (attrName)) 350 { 351 OUStringBuffer buf; 352 buf.appendAscii( "Attribute " ); 353 buf.append( attrName ); --- 82 unchanged lines hidden (view full) --- 436 PyThreadDetach antiguard; 437 buf.append( "pyuno object " ); 438 439 OUString s = val2str( (void*)me->members->wrappedObject.getValue(), 440 me->members->wrappedObject.getValueType().getTypeLibType() ); 441 buf.append( OUStringToOString(s,RTL_TEXTENCODING_ASCII_US) ); 442 } 443 |
444 return PyBytes_FromString( buf.getStr()); | 444 return PYSTR_FROMSTR( buf.getStr() ); |
445} 446 | 445} 446 |
447#if PY_MAJOR_VERSION >= 3 448PyObject* PyUNO_getattr (PyObject* self, PyObject* attr_name) 449#else |
|
447PyObject* PyUNO_getattr (PyObject* self, char* name) | 450PyObject* PyUNO_getattr (PyObject* self, char* name) |
451#endif |
|
448{ 449 PyUNO* me; 450 | 452{ 453 PyUNO* me; 454 |
455#if PY_VERSION_HEX >= 0x03030000 456 char *name = PyUnicode_AsUTF8(attr_name); 457#elif PY_MAJOR_VERSION >= 3 458 PyRef pUtf8(PyUnicode_AsUTF8String(attr_name), SAL_NO_ACQUIRE); 459 char *name = PyBytes_AsString(pUtf8.get()); 460#endif |
|
451 try 452 { 453 454 Runtime runtime; 455 456 me = (PyUNO*) self; | 461 try 462 { 463 464 Runtime runtime; 465 466 me = (PyUNO*) self; |
467#if PY_MAJOR_VERSION < 3 |
|
457 //Handle Python dir () stuff first... 458 if (strcmp (name, "__members__") == 0) 459 { 460 PyObject* member_list; 461 Sequence<OUString> oo_member_list; 462 463 oo_member_list = me->members->xInvocation->getMemberNames (); 464 member_list = PyList_New (oo_member_list.getLength ()); 465 for (int i = 0; i < oo_member_list.getLength (); i++) 466 { 467 // setitem steals a reference 468 PyList_SetItem (member_list, i, ustring2PyString(oo_member_list[i]).getAcquired() ); 469 } 470 return member_list; 471 } | 468 //Handle Python dir () stuff first... 469 if (strcmp (name, "__members__") == 0) 470 { 471 PyObject* member_list; 472 Sequence<OUString> oo_member_list; 473 474 oo_member_list = me->members->xInvocation->getMemberNames (); 475 member_list = PyList_New (oo_member_list.getLength ()); 476 for (int i = 0; i < oo_member_list.getLength (); i++) 477 { 478 // setitem steals a reference 479 PyList_SetItem (member_list, i, ustring2PyString(oo_member_list[i]).getAcquired() ); 480 } 481 return member_list; 482 } |
472 | 483#endif 484 |
473 if (strcmp (name, "__dict__") == 0) 474 { 475 Py_INCREF (Py_None); 476 return Py_None; 477 } | 485 if (strcmp (name, "__dict__") == 0) 486 { 487 Py_INCREF (Py_None); 488 return Py_None; 489 } |
490#if PY_MAJOR_VERSION < 3 |
|
478 if (strcmp (name, "__methods__") == 0) 479 { 480 Py_INCREF (Py_None); 481 return Py_None; 482 } | 491 if (strcmp (name, "__methods__") == 0) 492 { 493 Py_INCREF (Py_None); 494 return Py_None; 495 } |
496#endif |
|
483 if (strcmp (name, "__class__") == 0) 484 { 485 if( me->members->wrappedObject.getValueTypeClass() == 486 com::sun::star::uno::TypeClass_STRUCT || 487 me->members->wrappedObject.getValueTypeClass() == 488 com::sun::star::uno::TypeClass_EXCEPTION ) 489 { 490 return getClass( --- 54 unchanged lines hidden (view full) --- 545 catch( RuntimeException &e ) 546 { 547 raisePyExceptionWithAny( makeAny(e) ); 548 } 549 550 return NULL; 551} 552 | 497 if (strcmp (name, "__class__") == 0) 498 { 499 if( me->members->wrappedObject.getValueTypeClass() == 500 com::sun::star::uno::TypeClass_STRUCT || 501 me->members->wrappedObject.getValueTypeClass() == 502 com::sun::star::uno::TypeClass_EXCEPTION ) 503 { 504 return getClass( --- 54 unchanged lines hidden (view full) --- 559 catch( RuntimeException &e ) 560 { 561 raisePyExceptionWithAny( makeAny(e) ); 562 } 563 564 return NULL; 565} 566 |
567#if PY_MAJOR_VERSION >= 3 568int PyUNO_setattr (PyObject* self, PyObject* attr_name, PyObject* value) 569#else |
|
553int PyUNO_setattr (PyObject* self, char* name, PyObject* value) | 570int PyUNO_setattr (PyObject* self, char* name, PyObject* value) |
571#endif |
|
554{ 555 PyUNO* me; 556 | 572{ 573 PyUNO* me; 574 |
575#if PY_VERSION_HEX >= 0x03030000 576 char *name = PyUnicode_AsUTF8(attr_name); 577#elif PY_MAJOR_VERSION >= 3 578 PyRef pUtf8(PyUnicode_AsUTF8String(attr_name), SAL_NO_ACQUIRE); 579 char *name = PyBytes_AsString(pUtf8.get()); 580#endif |
|
557 me = (PyUNO*) self; 558 try 559 { 560 Runtime runtime; 561 Any val= runtime.pyObject2Any(value, ACCEPT_UNO_ANY); 562 563 OUString attrName( OUString::createFromAscii( name ) ); 564 { --- 24 unchanged lines hidden (view full) --- 589 { 590 raisePyExceptionWithAny( makeAny( e ) ); 591 return 1; 592 } 593 PyErr_SetString (PyExc_AttributeError, name); 594 return 1; //as above. 595} 596 | 581 me = (PyUNO*) self; 582 try 583 { 584 Runtime runtime; 585 Any val= runtime.pyObject2Any(value, ACCEPT_UNO_ANY); 586 587 OUString attrName( OUString::createFromAscii( name ) ); 588 { --- 24 unchanged lines hidden (view full) --- 613 { 614 raisePyExceptionWithAny( makeAny( e ) ); 615 return 1; 616 } 617 PyErr_SetString (PyExc_AttributeError, name); 618 return 1; //as above. 619} 620 |
621#if PY_MAJOR_VERSION >= 3 622static PyObject *PyUNO_dir( PyObject *self, PyObject *that ) 623{ 624 PyUNO* me; 625 PyObject* member_list; 626 Sequence<OUString> oo_member_list; 627 628 me = (PyUNO*) self; 629 oo_member_list = me->members->xInvocation->getMemberNames (); 630 member_list = PyList_New (oo_member_list.getLength ()); 631 for (int i = 0; i < oo_member_list.getLength (); i++) 632 { 633 // setitem steals a reference 634 PyList_SetItem (member_list, i, ustring2PyUnicode(oo_member_list[i]).getAcquired() ); 635 } 636 return member_list; 637} 638 639static PyObject *PyUNO_richcompare( PyObject *self, PyObject *that, int op ) 640{ 641 switch (op) 642 { 643 case Py_EQ: 644 case Py_NE: 645 if( self == that ) 646 { 647 if (op == Py_EQ) 648 Py_RETURN_TRUE; 649 else 650 Py_RETURN_FALSE; 651 } 652 try 653 { 654 Runtime runtime; 655 if( PyObject_IsInstance( that, getPyUnoClass().get() ) ) 656 { 657 PyUNO *me = reinterpret_cast< PyUNO*> ( self ); 658 PyUNO *other = reinterpret_cast< PyUNO *> (that ); 659 com::sun::star::uno::TypeClass tcMe = me->members->wrappedObject.getValueTypeClass(); 660 com::sun::star::uno::TypeClass tcOther = other->members->wrappedObject.getValueTypeClass(); 661 662 if( tcMe == tcOther ) 663 { 664 if( tcMe == com::sun::star::uno::TypeClass_STRUCT || 665 tcMe == com::sun::star::uno::TypeClass_EXCEPTION ) 666 { 667 Reference< XMaterialHolder > xMe( me->members->xInvocation,UNO_QUERY); 668 Reference< XMaterialHolder > xOther( other->members->xInvocation,UNO_QUERY ); 669 if( xMe->getMaterial() == xOther->getMaterial() ) 670 { 671 if (op == Py_EQ) 672 Py_RETURN_TRUE; 673 else 674 Py_RETURN_FALSE; 675 } 676 } 677 else if( tcMe == com::sun::star::uno::TypeClass_INTERFACE ) 678 { 679 if( me->members->wrappedObject == other->members->wrappedObject ) 680 { 681 if (op == Py_EQ) 682 Py_RETURN_TRUE; 683 else 684 Py_RETURN_FALSE; 685 } 686 } 687 } 688 } 689 if (op == Py_EQ) 690 Py_RETURN_FALSE; 691 else 692 Py_RETURN_TRUE; 693 } 694 catch( com::sun::star::uno::RuntimeException & e) 695 { 696 raisePyExceptionWithAny( makeAny( e ) ); 697 } 698 break; 699 default: 700 PyErr_SetString(Py_NotImplemented, "not implemented"); 701 break; 702 } 703 704 return NULL; 705} 706 707 708static struct PyMethodDef PyUNO_methods[] = { 709 { "__dir__", (PyCFunction)PyUNO_dir, METH_VARARGS, NULL}, 710 { NULL, NULL } 711}; 712 713#else |
|
597// ensure object identity and struct equality 598static int PyUNO_cmp( PyObject *self, PyObject *that ) 599{ 600 if( self == that ) 601 return 0; 602 int retDefault = self > that ? 1 : -1; 603 try 604 { 605 Runtime runtime; | 714// ensure object identity and struct equality 715static int PyUNO_cmp( PyObject *self, PyObject *that ) 716{ 717 if( self == that ) 718 return 0; 719 int retDefault = self > that ? 1 : -1; 720 try 721 { 722 Runtime runtime; |
606 if( PyObject_IsInstance( that, getPyUnoClass( runtime ).get() ) ) | 723 if( PyObject_IsInstance( that, getPyUnoClass().get() ) ) |
607 { 608 609 PyUNO *me = reinterpret_cast< PyUNO*> ( self ); 610 PyUNO *other = reinterpret_cast< PyUNO *> (that ); 611 com::sun::star::uno::TypeClass tcMe = me->members->wrappedObject.getValueTypeClass(); 612 com::sun::star::uno::TypeClass tcOther = other->members->wrappedObject.getValueTypeClass(); 613 614 if( tcMe == tcOther ) --- 16 unchanged lines hidden (view full) --- 631 } 632 } 633 catch( com::sun::star::uno::RuntimeException & e) 634 { 635 raisePyExceptionWithAny( makeAny( e ) ); 636 } 637 return retDefault; 638} | 724 { 725 726 PyUNO *me = reinterpret_cast< PyUNO*> ( self ); 727 PyUNO *other = reinterpret_cast< PyUNO *> (that ); 728 com::sun::star::uno::TypeClass tcMe = me->members->wrappedObject.getValueTypeClass(); 729 com::sun::star::uno::TypeClass tcOther = other->members->wrappedObject.getValueTypeClass(); 730 731 if( tcMe == tcOther ) --- 16 unchanged lines hidden (view full) --- 748 } 749 } 750 catch( com::sun::star::uno::RuntimeException & e) 751 { 752 raisePyExceptionWithAny( makeAny( e ) ); 753 } 754 return retDefault; 755} |
756#endif |
|
639 640static PyTypeObject PyUNOType = 641{ 642 PyVarObject_HEAD_INIT(&PyType_Type, 0) 643 const_cast< char * >("pyuno"), 644 sizeof (PyUNO), 645 0, 646 (destructor) PyUNO_del, 647 (printfunc) 0, | 757 758static PyTypeObject PyUNOType = 759{ 760 PyVarObject_HEAD_INIT(&PyType_Type, 0) 761 const_cast< char * >("pyuno"), 762 sizeof (PyUNO), 763 0, 764 (destructor) PyUNO_del, 765 (printfunc) 0, |
648 (getattrfunc) PyUNO_getattr, 649 (setattrfunc) PyUNO_setattr, 650 PyUNO_cmp, | 766#if PY_MAJOR_VERSION >= 3 767 (getattrfunc) 0, 768 (setattrfunc) 0, 769 0, 770#else 771 (getattrfunc) PyUNO_getattr, /* tp_getattr */ 772 (setattrfunc) PyUNO_setattr, /* tp_setattr */ 773 (cmpfunc) PyUNO_cmp, 774#endif |
651 (reprfunc) PyUNO_repr, 652 0, 653 0, 654 0, 655 (hashfunc) 0, 656 (ternaryfunc) 0, 657 (reprfunc) PyUNO_str, | 775 (reprfunc) PyUNO_repr, 776 0, 777 0, 778 0, 779 (hashfunc) 0, 780 (ternaryfunc) 0, 781 (reprfunc) PyUNO_str, |
782#if PY_MAJOR_VERSION >= 3 783 (getattrofunc)PyUNO_getattr, /* tp_getattro */ 784 (setattrofunc)PyUNO_setattr, /* tp_setattro */ 785#else |
|
658 (getattrofunc)0, 659 (setattrofunc)0, | 786 (getattrofunc)0, 787 (setattrofunc)0, |
788#endif |
|
660 NULL, 661 0, 662 NULL, 663 (traverseproc)0, 664 (inquiry)0, | 789 NULL, 790 0, 791 NULL, 792 (traverseproc)0, 793 (inquiry)0, |
794#if PY_MAJOR_VERSION >= 3 795 PyUNO_richcompare, /* tp_richcompare */ 796#else |
|
665 (richcmpfunc)0, | 797 (richcmpfunc)0, |
798#endif |
|
666 0, 667 (getiterfunc)0, 668 (iternextfunc)0, | 799 0, 800 (getiterfunc)0, 801 (iternextfunc)0, |
802#if PY_MAJOR_VERSION >= 3 803 PyUNO_methods, /* tp_methods */ 804#else |
|
669 NULL, | 805 NULL, |
806#endif |
|
670 NULL, 671 NULL, 672 NULL, 673 NULL, 674 (descrgetfunc)0, 675 (descrsetfunc)0, 676 0, 677 (initproc)0, --- 7 unchanged lines hidden (view full) --- 685 NULL, 686 NULL, 687 (destructor)0 688#if PY_VERSION_HEX >= 0x02060000 689 , 0 690#endif 691}; 692 | 807 NULL, 808 NULL, 809 NULL, 810 NULL, 811 (descrgetfunc)0, 812 (descrsetfunc)0, 813 0, 814 (initproc)0, --- 7 unchanged lines hidden (view full) --- 822 NULL, 823 NULL, 824 (destructor)0 825#if PY_VERSION_HEX >= 0x02060000 826 , 0 827#endif 828}; 829 |
693PyRef getPyUnoClass( const Runtime &) | 830PyRef getPyUnoClass() |
694{ 695 return PyRef( reinterpret_cast< PyObject * > ( &PyUNOType ) ); 696} 697 698PyObject* PyUNO_new ( 699 const Any & targetInterface, const Reference<XSingleServiceFactory> &ssf) 700{ 701 Reference<XInterface> tmp_interface; --- 38 unchanged lines hidden --- | 831{ 832 return PyRef( reinterpret_cast< PyObject * > ( &PyUNOType ) ); 833} 834 835PyObject* PyUNO_new ( 836 const Any & targetInterface, const Reference<XSingleServiceFactory> &ssf) 837{ 838 Reference<XInterface> tmp_interface; --- 38 unchanged lines hidden --- |