1 /* 2 Testcase to test %pythonprepend and %pythonappend %pythoncode %pythonbegin 3 */ 4 5 %module python_append 6 7 %pythoncode %{ 8 mypath = os.path.dirname("/a/b/c/d.txt") 9 funcpath = None 10 staticfuncpath = None 11 def grabpath(): 12 return funcpath 13 def grabstaticpath(): 14 return staticfuncpath 15 def clearstaticpath(): 16 global staticfuncpath 17 staticfuncpath = None 18 %} 19 20 %pythonappend Test::funk %{ 21 funcpath = os.path.dirname(funcpath) 22 %} 23 24 %pythonprepend Test::funk %{ 25 global funcpath 26 funcpath = mypath 27 %} 28 29 %pythonappend Test::static_func %{ 30 staticfuncpath = os.path.basename(staticfuncpath) 31 pass 32 %} 33 34 %pythonprepend Test::static_func { 35 global staticfuncpath 36 staticfuncpath = mypath 37 pass 38 } 39 40 %pythonbegin %{ 41 import os.path 42 %} 43 44 %inline %{ 45 class Test { 46 public: 47 static void static_func() {}; 48 void funk() {}; 49 }; 50 %} 51 52 // Github issue #1674 53 %extend ForSlots { 54 %pythoncode %{ 55 __slots__ = ["this"] 56 %} 57 } 58 // While __slots__ does not contain 'ValidVariable' in the list, it is still possible 59 // to set 'ValidVariable'. A little odd, but the whole attribute setting is bypassed 60 // for setting C/C++ member variables. 61 // Not sure how to test the equivalent for -builtin. 62 %inline %{ 63 struct ForSlots { 64 int ValidVariable; 65 ForSlots() : ValidVariable(99) {} 66 }; 67 %} 68 69 %inline %{ 70 #ifdef SWIGPYTHON_BUILTIN 71 bool is_python_builtin() { return true; } 72 #else 73 bool is_python_builtin() { return false; } 74 #endif 75 %} 76 77