|
37 | 37 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
38 | 38 | # SOFTWARE.
|
39 | 39 |
|
40 |
| -from _descriptor import descriptor |
41 |
| - |
42 | 40 | class CallableProxyType(object):
|
43 | 41 | pass
|
44 | 42 |
|
| 43 | + |
45 | 44 | # weak refs are used to allow circular data structures to be collected.
|
46 | 45 | # Java's GC has no problem with these, so we can make this a simple proxy.
|
47 | 46 | class ProxyType(object):
|
48 | 47 | def __init__(self, other):
|
49 | 48 | object.__setattr__(self, "value", other)
|
50 | 49 |
|
51 |
| - def __getattribute__(self, key): |
52 |
| - return object.__getattribute__(self, "value").__getattribute__(key) |
| 50 | + def __getattr__(self, key): |
| 51 | + return getattr(object.__getattribute__(self, "value"), key) |
53 | 52 |
|
54 | 53 | def __setattr__(self, key, value):
|
55 |
| - return object.__getattribute__(self, "value").__setattr__(key, value) |
| 54 | + setattr(object.__getattribute__(self, "value"), key, value) |
56 | 55 |
|
57 | 56 | def __delattr__(self, key):
|
58 |
| - return object.__getattribute__(self, "value").__delattr__(key) |
| 57 | + return delattr(object.__getattribute__(self, "value"), key) |
59 | 58 |
|
60 | 59 | def __getitem__(self, key):
|
61 |
| - return object.__getattribute__(self, "value").__getitem__(key) |
| 60 | + return object.__getattribute__(self, "value")[key] |
62 | 61 |
|
63 | 62 | def __setitem__(self, key, value):
|
64 |
| - return object.__getattribute__(self, "value").__setitem__(key, value) |
65 |
| - |
66 |
| - def __delitem__(self, other): |
67 |
| - return object.__getattribute__(self, "value").__delitem__(other) |
| 63 | + object.__getattribute__(self, "value")[key] = value |
68 | 64 |
|
69 |
| - def __ceil__(self): |
70 |
| - return object.__getattribute__(self, "value").__ceil__() |
71 |
| - |
72 |
| - def __floor__(self): |
73 |
| - return object.__getattribute__(self, "value").__floor__() |
| 65 | + def __delitem__(self, key): |
| 66 | + del object.__getattribute__(self, "value")[key] |
74 | 67 |
|
75 | 68 | def __repr__(self):
|
76 | 69 | return f"<weakproxy at {id(self)} to {type(self).__name__} at {id(object.__getattribute__(self, 'value'))}>"
|
77 | 70 |
|
78 | 71 | def __str__(self):
|
79 |
| - return object.__getattribute__(self, "value").__str__() |
| 72 | + return str(object.__getattribute__(self, "value")) |
80 | 73 |
|
81 | 74 | def __bytes__(self):
|
82 | 75 | return object.__getattribute__(self, "value").__bytes__()
|
83 | 76 |
|
84 |
| - def __format__(self, format_spec): |
85 |
| - return object.__getattribute__(self, "value").__format__(self, format_spec) |
86 |
| - |
87 | 77 | def __lt__(self, other):
|
88 |
| - return object.__getattribute__(self, "value").__lt__(other) |
| 78 | + return object.__getattribute__(self, "value") < other |
89 | 79 |
|
90 | 80 | def __le__(self, other):
|
91 |
| - return object.__getattribute__(self, "value").__le__(other) |
| 81 | + return object.__getattribute__(self, "value") <= other |
92 | 82 |
|
93 | 83 | def __eq__(self, other):
|
94 |
| - return object.__getattribute__(self, "value").__eq__(other) |
| 84 | + return object.__getattribute__(self, "value") == other |
95 | 85 |
|
96 | 86 | def __ne__(self, other):
|
97 |
| - return object.__getattribute__(self, "value").__ne__(other) |
| 87 | + return object.__getattribute__(self, "value") != other |
98 | 88 |
|
99 | 89 | def __gt__(self, other):
|
100 |
| - return object.__getattribute__(self, "value").__gt__(other) |
| 90 | + return object.__getattribute__(self, "value") > other |
101 | 91 |
|
102 | 92 | def __ge__(self, other):
|
103 |
| - return object.__getattribute__(self, "value").__ge__(other) |
| 93 | + return object.__getattribute__(self, "value") >= other |
104 | 94 |
|
105 | 95 | def __hash__(self):
|
106 |
| - return object.__getattribute__(self, "value").__hash__() |
| 96 | + return hash(object.__getattribute__(self, "value")) |
107 | 97 |
|
108 | 98 | def __bool__(self):
|
109 |
| - return object.__getattribute__(self, "value").__bool__() |
| 99 | + return bool(object.__getattribute__(self, "value")) |
110 | 100 |
|
111 | 101 | def __call__(self, *args):
|
112 |
| - return object.__getattribute__(self, "value").__call__(*args) |
| 102 | + return object.__getattribute__(self, "value")(*args) |
113 | 103 |
|
114 | 104 | def __len__(self):
|
115 |
| - return object.__getattribute__(self, "value").__len__() |
| 105 | + return len(object.__getattribute__(self, "value")) |
116 | 106 |
|
117 | 107 | def __iter__(self):
|
118 |
| - return object.__getattribute__(self, "value").__iter__() |
| 108 | + return iter(object.__getattribute__(self, "value")) |
119 | 109 |
|
120 | 110 | def __next__(self):
|
121 |
| - return object.__getattribute__(self, "value").__next__() |
| 111 | + return next(object.__getattribute__(self, "value")) |
122 | 112 |
|
123 | 113 | def __reversed__(self):
|
124 | 114 | return object.__getattribute__(self, "value").__reversed__()
|
125 | 115 |
|
126 | 116 | def __contains__(self, obj):
|
127 |
| - return object.__getattribute__(self, "value").__contains__(obj) |
| 117 | + return obj in object.__getattribute__(self, "value") |
128 | 118 |
|
129 | 119 | def __add__(self, other):
|
130 |
| - return object.__getattribute__(self, "value").__add__(other) |
| 120 | + return object.__getattribute__(self, "value") + other |
131 | 121 |
|
132 | 122 | def __sub__(self, other):
|
133 |
| - return object.__getattribute__(self, "value").__sub__(other) |
| 123 | + return object.__getattribute__(self, "value") - other |
134 | 124 |
|
135 | 125 | def __mul__(self, other):
|
136 |
| - return object.__getattribute__(self, "value").__mul__(other) |
| 126 | + return object.__getattribute__(self, "value") * other |
137 | 127 |
|
138 | 128 | def __matmul__(self, other):
|
139 |
| - return object.__getattribute__(self, "value").__matmul__(other) |
| 129 | + return object.__getattribute__(self, "value") @ other |
140 | 130 |
|
141 | 131 | def __truediv__(self, other):
|
142 |
| - return object.__getattribute__(self, "value").__truediv__(other) |
143 |
| - |
144 |
| - def __trunc__(self): |
145 |
| - return object.__getattribute__(self, "value").__trunc__() |
| 132 | + return object.__getattribute__(self, "value") / other |
146 | 133 |
|
147 | 134 | def __floordiv__(self, other):
|
148 |
| - return object.__getattribute__(self, "value").__floordiv__(other) |
| 135 | + return object.__getattribute__(self, "value") // other |
149 | 136 |
|
150 | 137 | def __mod__(self, other):
|
151 |
| - return object.__getattribute__(self, "value").__mod__(other) |
| 138 | + return object.__getattribute__(self, "value") % other |
152 | 139 |
|
153 | 140 | def __divmod__(self, other):
|
154 |
| - return object.__getattribute__(self, "value").__divmod__(other) |
| 141 | + return divmod(object.__getattribute__(self, "value"), other) |
155 | 142 |
|
156 | 143 | def __pow__(self, exp, mod=None):
|
157 |
| - if mod is None: |
158 |
| - return object.__getattribute__(self, "value").__pow__(exp) |
159 |
| - return object.__getattribute__(self, "value").__pow__(exp, mod) |
| 144 | + return pow(object.__getattribute__(self, "value"), exp, mod) |
160 | 145 |
|
161 | 146 | def __lshift__(self, other):
|
162 |
| - return object.__getattribute__(self, "value").__lshift__(other) |
| 147 | + return object.__getattribute__(self, "value") << other |
163 | 148 |
|
164 | 149 | def __rshift__(self, other):
|
165 |
| - return object.__getattribute__(self, "value").__rshift__(other) |
| 150 | + return object.__getattribute__(self, "value") >> other |
166 | 151 |
|
167 | 152 | def __and__(self, other):
|
168 |
| - return object.__getattribute__(self, "value").__and__(other) |
| 153 | + return object.__getattribute__(self, "value") & other |
169 | 154 |
|
170 | 155 | def __xor__(self, other):
|
171 |
| - return object.__getattribute__(self, "value").__xor__(other) |
| 156 | + return object.__getattribute__(self, "value") ^ other |
172 | 157 |
|
173 | 158 | def __or__(self, other):
|
174 |
| - return object.__getattribute__(self, "value").__or__(other) |
175 |
| - |
176 |
| - def __radd__(self, other): |
177 |
| - return object.__getattribute__(self, "value").__radd__(other) |
178 |
| - |
179 |
| - def __rsub__(self, other): |
180 |
| - return object.__getattribute__(self, "value").__rsub__(other) |
181 |
| - |
182 |
| - def __rmul__(self, other): |
183 |
| - return object.__getattribute__(self, "value").__rmul__(other) |
184 |
| - |
185 |
| - def __rmatmul__(self, other): |
186 |
| - return object.__getattribute__(self, "value").__rmatmul__(other) |
187 |
| - |
188 |
| - def __rtruediv__(self, other): |
189 |
| - return object.__getattribute__(self, "value").__rtruediv__(other) |
190 |
| - |
191 |
| - def __rfloordiv__(self, other): |
192 |
| - return object.__getattribute__(self, "value").__rfloordiv__(other) |
193 |
| - |
194 |
| - def __rmod__(self, other): |
195 |
| - return object.__getattribute__(self, "value").__rmod__(other) |
196 |
| - |
197 |
| - def __rdivmod__(self, other): |
198 |
| - return object.__getattribute__(self, "value").__rdivmod__(other) |
199 |
| - |
200 |
| - def __rpow__(self, exp, mod=None): |
201 |
| - if mod is None: |
202 |
| - return object.__getattribute__(self, "value").__rpow__(exp) |
203 |
| - return object.__getattribute__(self, "value").__rpow__(exp, mod) |
204 |
| - |
205 |
| - def __rlshift__(self, other): |
206 |
| - return object.__getattribute__(self, "value").__rlshift__(other) |
207 |
| - |
208 |
| - def __rand__(self, other): |
209 |
| - return object.__getattribute__(self, "value").__rand__(other) |
210 |
| - |
211 |
| - def __rxor__(self, other): |
212 |
| - return object.__getattribute__(self, "value").__rxor__(other) |
213 |
| - |
214 |
| - def __ror__(self, other): |
215 |
| - return object.__getattribute__(self, "value").__ror__(other) |
| 159 | + return object.__getattribute__(self, "value") | other |
216 | 160 |
|
217 | 161 | def __iadd__(self, other):
|
218 |
| - return object.__getattribute__(self, "value").__iadd__(other) |
| 162 | + value = object.__getattribute__(self, "value") |
| 163 | + value += other |
| 164 | + return value |
219 | 165 |
|
220 | 166 | def __isub__(self, other):
|
221 |
| - return object.__getattribute__(self, "value").__isub__(other) |
| 167 | + value = object.__getattribute__(self, "value") |
| 168 | + value -= other |
| 169 | + return value |
222 | 170 |
|
223 | 171 | def __imul__(self, other):
|
224 |
| - return object.__getattribute__(self, "value").__imul__(other) |
| 172 | + value = object.__getattribute__(self, "value") |
| 173 | + value *= other |
| 174 | + return value |
225 | 175 |
|
226 | 176 | def __imatmul__(self, other):
|
227 |
| - return object.__getattribute__(self, "value").__imatmul__(other) |
| 177 | + value = object.__getattribute__(self, "value") |
| 178 | + value @= other |
| 179 | + return value |
228 | 180 |
|
229 | 181 | def __itruediv__(self, other):
|
230 |
| - return object.__getattribute__(self, "value").__itruediv__(other) |
| 182 | + value = object.__getattribute__(self, "value") |
| 183 | + value /= other |
| 184 | + return value |
231 | 185 |
|
232 | 186 | def __ifloordiv__(self, other):
|
233 |
| - return object.__getattribute__(self, "value").__ifloordiv__(other) |
| 187 | + value = object.__getattribute__(self, "value") |
| 188 | + value //= other |
| 189 | + return value |
234 | 190 |
|
235 | 191 | def __imod__(self, other):
|
236 |
| - return object.__getattribute__(self, "value").__imod__(other) |
| 192 | + value = object.__getattribute__(self, "value") |
| 193 | + value %= other |
| 194 | + return value |
237 | 195 |
|
238 |
| - def __ipow__(self, exp, mod=None): |
239 |
| - if mod is None: |
240 |
| - return object.__getattribute__(self, "value").__ipow__(exp) |
241 |
| - return object.__getattribute__(self, "value").__ipow__(exp, mod) |
| 196 | + def __ipow__(self, exp): |
| 197 | + value = object.__getattribute__(self, "value") |
| 198 | + value **= exp |
| 199 | + return value |
242 | 200 |
|
243 | 201 | def __ilshift__(self, other):
|
244 |
| - return object.__getattribute__(self, "value").__ilshift__(other) |
| 202 | + value = object.__getattribute__(self, "value") |
| 203 | + value <<= other |
| 204 | + return value |
245 | 205 |
|
246 | 206 | def __irshift__(self, other):
|
247 |
| - return object.__getattribute__(self, "value").__irshift__(other) |
| 207 | + value = object.__getattribute__(self, "value") |
| 208 | + value >>= other |
| 209 | + return value |
248 | 210 |
|
249 | 211 | def __iand__(self, other):
|
250 |
| - return object.__getattribute__(self, "value").__iand__(other) |
| 212 | + value = object.__getattribute__(self, "value") |
| 213 | + value &= other |
| 214 | + return value |
251 | 215 |
|
252 | 216 | def __ixor__(self, other):
|
253 |
| - return object.__getattribute__(self, "value").__ixor__(other) |
| 217 | + value = object.__getattribute__(self, "value") |
| 218 | + value ^= other |
| 219 | + return value |
254 | 220 |
|
255 | 221 | def __ior__(self, other):
|
256 |
| - return object.__getattribute__(self, "value").__ior__(other) |
| 222 | + value = object.__getattribute__(self, "value") |
| 223 | + value |= other |
| 224 | + return value |
257 | 225 |
|
258 | 226 | def __neg__(self):
|
259 |
| - return object.__getattribute__(self, "value").__neg__() |
| 227 | + return -object.__getattribute__(self, "value") |
260 | 228 |
|
261 | 229 | def __pos__(self):
|
262 |
| - return object.__getattribute__(self, "value").__pos__() |
| 230 | + return +object.__getattribute__(self, "value") |
263 | 231 |
|
264 | 232 | def __abs__(self):
|
265 |
| - return object.__getattribute__(self, "value").__abs__() |
| 233 | + return abs(object.__getattribute__(self, "value")) |
266 | 234 |
|
267 | 235 | def __invert__(self):
|
268 |
| - return object.__getattribute__(self, "value").__invert__() |
269 |
| - |
270 |
| - def __complex__(self): |
271 |
| - return object.__getattribute__(self, "value").__complex__() |
| 236 | + return ~object.__getattribute__(self, "value") |
272 | 237 |
|
273 | 238 | def __int__(self):
|
274 |
| - return object.__getattribute__(self, "value").__int__() |
| 239 | + return int(object.__getattribute__(self, "value")) |
275 | 240 |
|
276 | 241 | def __float__(self):
|
277 |
| - return object.__getattribute__(self, "value").__float__() |
| 242 | + return float(object.__getattribute__(self, "value")) |
278 | 243 |
|
279 | 244 | def __round__(self):
|
280 |
| - return object.__getattribute__(self, "value").__round__() |
| 245 | + return round(object.__getattribute__(self, "value")) |
281 | 246 |
|
282 | 247 | def __index__(self):
|
283 |
| - return object.__getattribute__(self, "value").__index__() |
| 248 | + v = object.__getattribute__(self, "value") |
| 249 | + if not hasattr(v, "__index__"): |
| 250 | + raise TypeError("'%s' object cannot be interpreted as an integer" % type(v)) |
| 251 | + result = v.__index__() |
| 252 | + result_type = type(result) |
| 253 | + if not isinstance(result, int): |
| 254 | + raise TypeError("__index__ returned non-int (type %s)" % result_type) |
| 255 | + return result |
284 | 256 |
|
285 | 257 |
|
286 | 258 | ref = ReferenceType
|
|
0 commit comments