1 | /* |
---|
2 | * proxy.swg : SWIG include file for defining automatic proxy classes |
---|
3 | * |
---|
4 | * ==================================================================== |
---|
5 | * Copyright (c) 2000-2003 CollabNet. All rights reserved. |
---|
6 | * |
---|
7 | * This software is licensed as described in the file COPYING, which |
---|
8 | * you should have received as part of this distribution. The terms |
---|
9 | * are also available at http://subversion.tigris.org/license-1.html. |
---|
10 | * If newer versions of this license are posted there, you may use a |
---|
11 | * newer version instead, at your option. |
---|
12 | * |
---|
13 | * This software consists of voluntary contributions made by many |
---|
14 | * individuals. For exact contribution history, see the revision |
---|
15 | * history and logs, available at http://subversion.tigris.org/. |
---|
16 | * ==================================================================== |
---|
17 | */ |
---|
18 | |
---|
19 | #ifdef SWIGPYTHON |
---|
20 | |
---|
21 | /* Note: See the big comment at the top of proxy_apr.swg for details on |
---|
22 | * how this _is_valid stuff actually works. It's part of the magic |
---|
23 | * that lets us gracefully handle objects that are allocated from |
---|
24 | * a pool that's been cleared or destroyed. |
---|
25 | */ |
---|
26 | |
---|
27 | /* Default code for all wrapped proxy classes in Python */ |
---|
28 | %define %proxy_pythoncode(TYPE) |
---|
29 | %pythoncode { |
---|
30 | def set_parent_pool(self, parent_pool=None): |
---|
31 | """Create a new proxy object for TYPE""" |
---|
32 | import libsvn.core, weakref |
---|
33 | self.__dict__["_parent_pool"] = \ |
---|
34 | parent_pool or libsvn.core.application_pool; |
---|
35 | if self.__dict__["_parent_pool"]: |
---|
36 | self.__dict__["_is_valid"] = weakref.ref( |
---|
37 | self.__dict__["_parent_pool"]._is_valid) |
---|
38 | |
---|
39 | def assert_valid(self): |
---|
40 | """Assert that this object is using valid pool memory""" |
---|
41 | if "_is_valid" in self.__dict__: |
---|
42 | assert self.__dict__["_is_valid"](), "Variable has already been deleted" |
---|
43 | |
---|
44 | def __getattr__(self, name): |
---|
45 | """Get an attribute from this object""" |
---|
46 | self.assert_valid() |
---|
47 | |
---|
48 | value = _swig_getattr(self, self.__class__, name) |
---|
49 | |
---|
50 | # Now, if this item has changed, SWIG must have generated a new object. |
---|
51 | # Copy the pool metadata from the old object over to the new one. |
---|
52 | members = self.__dict__.get("_members") |
---|
53 | if members is not None: |
---|
54 | old_value = members.get(name) |
---|
55 | if (old_value is not None and value is not None and |
---|
56 | value is not old_value): |
---|
57 | try: |
---|
58 | value.__dict__.update(old_value.__dict__) |
---|
59 | except AttributeError: |
---|
60 | pass |
---|
61 | |
---|
62 | # Verify that the new object is good |
---|
63 | if hasattr(value, "assert_valid"): |
---|
64 | value.assert_valid() |
---|
65 | |
---|
66 | return value |
---|
67 | |
---|
68 | def __setattr__(self, name, value): |
---|
69 | """Set an attribute on this object""" |
---|
70 | self.assert_valid() |
---|
71 | |
---|
72 | # Save a copy of the object, so that the garbage |
---|
73 | # collector won't kill the object while it's in |
---|
74 | # SWIG-land |
---|
75 | self.__dict__.setdefault("_members",{})[name] = value |
---|
76 | |
---|
77 | return _swig_setattr(self, self.__class__, name, value) |
---|
78 | } |
---|
79 | %enddef |
---|
80 | |
---|
81 | /* Define a proxy for wrapping an existing struct */ |
---|
82 | %define %proxy(TYPE) |
---|
83 | %extend TYPE { |
---|
84 | %proxy_pythoncode(TYPE); |
---|
85 | } |
---|
86 | %enddef |
---|
87 | |
---|
88 | /* Define a proxy class for wrapping an opaque struct */ |
---|
89 | %define %opaque_proxy(TYPE) |
---|
90 | struct TYPE { |
---|
91 | %extend { |
---|
92 | %proxy_pythoncode(TYPE); |
---|
93 | } |
---|
94 | } |
---|
95 | %enddef |
---|
96 | |
---|
97 | /* Treat typemapped function pointers as objects, which have a bound |
---|
98 | * __call__ method. This mapping depends on the function pointer being |
---|
99 | * typemapped as a CALLABLE_CALLBACK. */ |
---|
100 | %define %funcptr_proxy(TYPE, INVOKE) |
---|
101 | %nodefault TYPE; |
---|
102 | struct TYPE { |
---|
103 | %extend { |
---|
104 | %proxy_pythoncode(TYPE); |
---|
105 | %pythoncode %{ |
---|
106 | def __call__(self, *args): |
---|
107 | return INVOKE(self, *args) |
---|
108 | %} |
---|
109 | } |
---|
110 | }; |
---|
111 | |
---|
112 | %enddef |
---|
113 | |
---|
114 | /* Add member functions to objects so that their function pointers can |
---|
115 | * be invoked. |
---|
116 | * |
---|
117 | * Unlike the CALLABLE_CALLBACKS, these member functions don't have or |
---|
118 | * need typemaps, because the underlying C/SWIG object for the callback |
---|
119 | * is hidden. |
---|
120 | */ |
---|
121 | %define %funcptr_member_proxy(TYPE, MEMBER, INVOKE) |
---|
122 | %extend TYPE { |
---|
123 | %pythoncode %{ |
---|
124 | def MEMBER(self, *args): |
---|
125 | return INVOKE(self, *args) |
---|
126 | %} |
---|
127 | } |
---|
128 | %enddef |
---|
129 | |
---|
130 | |
---|
131 | #endif |
---|