wrapt 2.1.0.dev2__cp314-cp314t-musllinux_1_2_x86_64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of wrapt might be problematic. Click here for more details.

wrapt/_wrappers.c ADDED
@@ -0,0 +1,4097 @@
1
+ /* ------------------------------------------------------------------------- */
2
+
3
+ #include "Python.h"
4
+
5
+ #include "structmember.h"
6
+
7
+ #ifndef PyVarObject_HEAD_INIT
8
+ #define PyVarObject_HEAD_INIT(type, size) PyObject_HEAD_INIT(type) size,
9
+ #endif
10
+
11
+ /* ------------------------------------------------------------------------- */
12
+
13
+ typedef struct
14
+ {
15
+ PyObject_HEAD
16
+
17
+ PyObject *dict;
18
+ PyObject *wrapped;
19
+ PyObject *weakreflist;
20
+ } WraptObjectProxyObject;
21
+
22
+ PyTypeObject WraptObjectProxy_Type;
23
+ PyTypeObject WraptCallableObjectProxy_Type;
24
+
25
+ typedef struct
26
+ {
27
+ WraptObjectProxyObject object_proxy;
28
+
29
+ PyObject *args;
30
+ PyObject *kwargs;
31
+ } WraptPartialCallableObjectProxyObject;
32
+
33
+ PyTypeObject WraptPartialCallableObjectProxy_Type;
34
+
35
+ typedef struct
36
+ {
37
+ WraptObjectProxyObject object_proxy;
38
+
39
+ PyObject *instance;
40
+ PyObject *wrapper;
41
+ PyObject *enabled;
42
+ PyObject *binding;
43
+ PyObject *parent;
44
+ PyObject *owner;
45
+ } WraptFunctionWrapperObject;
46
+
47
+ PyTypeObject WraptFunctionWrapperBase_Type;
48
+ PyTypeObject WraptBoundFunctionWrapper_Type;
49
+ PyTypeObject WraptFunctionWrapper_Type;
50
+
51
+ /* ------------------------------------------------------------------------- */
52
+
53
+ static int raise_uninitialized_wrapper_error(WraptObjectProxyObject *object)
54
+ {
55
+ // Before raising an exception we need to first check whether this is a lazy
56
+ // proxy object and attempt to intialize the wrapped object using the supplied
57
+ // callback if so. If the callback is not present then we can proceed to raise
58
+ // the exception, but if the callback is present and returns a value, we set
59
+ // that as the wrapped object and continue and return without raising an error.
60
+
61
+ static PyObject *wrapped_str = NULL;
62
+ static PyObject *wrapped_factory_str = NULL;
63
+ static PyObject *wrapped_get_str = NULL;
64
+
65
+ PyObject *callback = NULL;
66
+ PyObject *value = NULL;
67
+
68
+ if (!wrapped_str)
69
+ {
70
+ wrapped_str = PyUnicode_InternFromString("__wrapped__");
71
+ wrapped_factory_str = PyUnicode_InternFromString("__wrapped_factory__");
72
+ wrapped_get_str = PyUnicode_InternFromString("__wrapped_get__");
73
+ }
74
+
75
+ // Note that we use existance of __wrapped_factory__ to gate whether we can
76
+ // attempt to initialize the wrapped object lazily, but it is __wrapped_get__
77
+ // that we actually call to do the initialization. This is so that we can
78
+ // handle multithreading correctly by having __wrapped_get__ use a lock to
79
+ // protect against multiple threads trying to initialize the wrapped object
80
+ // at the same time.
81
+
82
+ callback = PyObject_GenericGetAttr((PyObject *)object, wrapped_factory_str);
83
+
84
+ if (callback)
85
+ {
86
+ if (callback != Py_None)
87
+ {
88
+ Py_DECREF(callback);
89
+
90
+ callback = PyObject_GenericGetAttr((PyObject *)object, wrapped_get_str);
91
+
92
+ if (!callback)
93
+ return -1;
94
+
95
+ value = PyObject_CallObject(callback, NULL);
96
+
97
+ Py_DECREF(callback);
98
+
99
+ if (value)
100
+ {
101
+ // We use setattr so that special dunder methods will be properly set.
102
+
103
+ if (PyObject_SetAttr((PyObject *)object, wrapped_str, value) == -1)
104
+ {
105
+ Py_DECREF(value);
106
+ return -1;
107
+ }
108
+
109
+ Py_DECREF(value);
110
+
111
+ return 0;
112
+ }
113
+ else
114
+ {
115
+ return -1;
116
+ }
117
+ }
118
+ else
119
+ {
120
+ Py_DECREF(callback);
121
+ }
122
+ }
123
+ else
124
+ PyErr_Clear();
125
+
126
+ // We need to reach into the wrapt.wrappers module to get the exception
127
+ // class because the exception we need to raise needs to inherit from both
128
+ // ValueError and AttributeError and we can't do that in C code using the
129
+ // built in exception classes, or at least not easily or safely.
130
+
131
+ PyObject *wrapt_wrappers_module = NULL;
132
+ PyObject *wrapper_not_initialized_error = NULL;
133
+
134
+ // Import the wrapt.wrappers module and get the exception class.
135
+ // We do this fresh each time to be safe with multiple sub-interpreters.
136
+
137
+ wrapt_wrappers_module = PyImport_ImportModule("wrapt.wrappers");
138
+
139
+ if (!wrapt_wrappers_module)
140
+ {
141
+ // Fallback to ValueError if import fails.
142
+
143
+ PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized");
144
+
145
+ return -1;
146
+ }
147
+
148
+ wrapper_not_initialized_error = PyObject_GetAttrString(
149
+ wrapt_wrappers_module, "WrapperNotInitializedError");
150
+
151
+ if (!wrapper_not_initialized_error)
152
+ {
153
+ // Fallback to ValueError if attribute lookup fails.
154
+
155
+ Py_DECREF(wrapt_wrappers_module);
156
+
157
+ PyErr_SetString(PyExc_ValueError, "wrapper has not been initialized");
158
+
159
+ return -1;
160
+ }
161
+
162
+ // Raise the custom exception.
163
+
164
+ PyErr_SetString(wrapper_not_initialized_error,
165
+ "wrapper has not been initialized");
166
+
167
+ // Clean up references.
168
+
169
+ Py_DECREF(wrapper_not_initialized_error);
170
+ Py_DECREF(wrapt_wrappers_module);
171
+
172
+ return -1;
173
+ }
174
+
175
+ /* ------------------------------------------------------------------------- */
176
+
177
+ static PyObject *WraptObjectProxy_new(PyTypeObject *type, PyObject *args,
178
+ PyObject *kwds)
179
+ {
180
+ WraptObjectProxyObject *self;
181
+
182
+ self = (WraptObjectProxyObject *)type->tp_alloc(type, 0);
183
+
184
+ if (!self)
185
+ return NULL;
186
+
187
+ self->dict = PyDict_New();
188
+ self->wrapped = NULL;
189
+ self->weakreflist = NULL;
190
+
191
+ return (PyObject *)self;
192
+ }
193
+
194
+ /* ------------------------------------------------------------------------- */
195
+
196
+ static int WraptObjectProxy_raw_init(WraptObjectProxyObject *self,
197
+ PyObject *wrapped)
198
+ {
199
+ static PyObject *module_str = NULL;
200
+ static PyObject *doc_str = NULL;
201
+ static PyObject *wrapped_factory_str = NULL;
202
+
203
+ PyObject *object = NULL;
204
+
205
+ // If wrapped is Py_None and we have a __wrapped_factory__ attribute
206
+ // then we defer initialization of the wrapped object until it is first needed.
207
+
208
+ if (!wrapped_factory_str)
209
+ {
210
+ wrapped_factory_str = PyUnicode_InternFromString("__wrapped_factory__");
211
+ }
212
+
213
+ if (wrapped == Py_None)
214
+ {
215
+ PyObject *callback = NULL;
216
+
217
+ callback = PyObject_GenericGetAttr((PyObject *)self, wrapped_factory_str);
218
+
219
+ if (callback)
220
+ {
221
+ if (callback != Py_None)
222
+ {
223
+ Py_DECREF(callback);
224
+ return 0;
225
+ }
226
+ else
227
+ {
228
+ Py_DECREF(callback);
229
+ }
230
+ }
231
+ else
232
+ PyErr_Clear();
233
+ }
234
+
235
+ Py_INCREF(wrapped);
236
+ Py_XDECREF(self->wrapped);
237
+ self->wrapped = wrapped;
238
+
239
+ if (!module_str)
240
+ {
241
+ module_str = PyUnicode_InternFromString("__module__");
242
+ }
243
+
244
+ if (!doc_str)
245
+ {
246
+ doc_str = PyUnicode_InternFromString("__doc__");
247
+ }
248
+
249
+ object = PyObject_GetAttr(wrapped, module_str);
250
+
251
+ if (object)
252
+ {
253
+ if (PyDict_SetItem(self->dict, module_str, object) == -1)
254
+ {
255
+ Py_DECREF(object);
256
+ return -1;
257
+ }
258
+ Py_DECREF(object);
259
+ }
260
+ else
261
+ PyErr_Clear();
262
+
263
+ object = PyObject_GetAttr(wrapped, doc_str);
264
+
265
+ if (object)
266
+ {
267
+ if (PyDict_SetItem(self->dict, doc_str, object) == -1)
268
+ {
269
+ Py_DECREF(object);
270
+ return -1;
271
+ }
272
+ Py_DECREF(object);
273
+ }
274
+ else
275
+ PyErr_Clear();
276
+
277
+ return 0;
278
+ }
279
+
280
+ /* ------------------------------------------------------------------------- */
281
+
282
+ static int WraptObjectProxy_init(WraptObjectProxyObject *self, PyObject *args,
283
+ PyObject *kwds)
284
+ {
285
+ PyObject *wrapped = NULL;
286
+
287
+ char *const kwlist[] = {"wrapped", NULL};
288
+
289
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:ObjectProxy", kwlist,
290
+ &wrapped))
291
+ {
292
+ return -1;
293
+ }
294
+
295
+ return WraptObjectProxy_raw_init(self, wrapped);
296
+ }
297
+
298
+ /* ------------------------------------------------------------------------- */
299
+
300
+ static int WraptObjectProxy_traverse(WraptObjectProxyObject *self,
301
+ visitproc visit, void *arg)
302
+ {
303
+ Py_VISIT(self->dict);
304
+ Py_VISIT(self->wrapped);
305
+
306
+ return 0;
307
+ }
308
+
309
+ /* ------------------------------------------------------------------------- */
310
+
311
+ static int WraptObjectProxy_clear(WraptObjectProxyObject *self)
312
+ {
313
+ Py_CLEAR(self->dict);
314
+ Py_CLEAR(self->wrapped);
315
+
316
+ return 0;
317
+ }
318
+
319
+ /* ------------------------------------------------------------------------- */
320
+
321
+ static void WraptObjectProxy_dealloc(WraptObjectProxyObject *self)
322
+ {
323
+ PyObject_GC_UnTrack(self);
324
+
325
+ if (self->weakreflist != NULL)
326
+ PyObject_ClearWeakRefs((PyObject *)self);
327
+
328
+ WraptObjectProxy_clear(self);
329
+
330
+ Py_TYPE(self)->tp_free(self);
331
+ }
332
+
333
+ /* ------------------------------------------------------------------------- */
334
+
335
+ static PyObject *WraptObjectProxy_repr(WraptObjectProxyObject *self)
336
+ {
337
+ if (!self->wrapped)
338
+ {
339
+ if (raise_uninitialized_wrapper_error(self) == -1)
340
+ return NULL;
341
+ }
342
+
343
+ return PyUnicode_FromFormat("<%s at %p for %s at %p>", Py_TYPE(self)->tp_name,
344
+ self, Py_TYPE(self->wrapped)->tp_name,
345
+ self->wrapped);
346
+ }
347
+
348
+ /* ------------------------------------------------------------------------- */
349
+
350
+ static Py_hash_t WraptObjectProxy_hash(WraptObjectProxyObject *self)
351
+ {
352
+ if (!self->wrapped)
353
+ {
354
+ if (raise_uninitialized_wrapper_error(self) == -1)
355
+ return -1;
356
+ }
357
+
358
+ return PyObject_Hash(self->wrapped);
359
+ }
360
+
361
+ /* ------------------------------------------------------------------------- */
362
+
363
+ static PyObject *WraptObjectProxy_str(WraptObjectProxyObject *self)
364
+ {
365
+ if (!self->wrapped)
366
+ {
367
+ if (raise_uninitialized_wrapper_error(self) == -1)
368
+ return NULL;
369
+ }
370
+
371
+ return PyObject_Str(self->wrapped);
372
+ }
373
+
374
+ /* ------------------------------------------------------------------------- */
375
+
376
+ static PyObject *WraptObjectProxy_add(PyObject *o1, PyObject *o2)
377
+ {
378
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
379
+ {
380
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
381
+ {
382
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
383
+ return NULL;
384
+ }
385
+
386
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
387
+ }
388
+
389
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
390
+ {
391
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
392
+ {
393
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
394
+ return NULL;
395
+ }
396
+
397
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
398
+ }
399
+
400
+ return PyNumber_Add(o1, o2);
401
+ }
402
+
403
+ /* ------------------------------------------------------------------------- */
404
+
405
+ static PyObject *WraptObjectProxy_subtract(PyObject *o1, PyObject *o2)
406
+ {
407
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
408
+ {
409
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
410
+ {
411
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
412
+ return NULL;
413
+ }
414
+
415
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
416
+ }
417
+
418
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
419
+ {
420
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
421
+ {
422
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
423
+ return NULL;
424
+ }
425
+
426
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
427
+ }
428
+
429
+ return PyNumber_Subtract(o1, o2);
430
+ }
431
+
432
+ /* ------------------------------------------------------------------------- */
433
+
434
+ static PyObject *WraptObjectProxy_multiply(PyObject *o1, PyObject *o2)
435
+ {
436
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
437
+ {
438
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
439
+ {
440
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
441
+ return NULL;
442
+ }
443
+
444
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
445
+ }
446
+
447
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
448
+ {
449
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
450
+ {
451
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
452
+ return NULL;
453
+ }
454
+
455
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
456
+ }
457
+
458
+ return PyNumber_Multiply(o1, o2);
459
+ }
460
+
461
+ /* ------------------------------------------------------------------------- */
462
+
463
+ static PyObject *WraptObjectProxy_remainder(PyObject *o1, PyObject *o2)
464
+ {
465
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
466
+ {
467
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
468
+ {
469
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
470
+ return NULL;
471
+ }
472
+
473
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
474
+ }
475
+
476
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
477
+ {
478
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
479
+ {
480
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
481
+ return NULL;
482
+ }
483
+
484
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
485
+ }
486
+
487
+ return PyNumber_Remainder(o1, o2);
488
+ }
489
+
490
+ /* ------------------------------------------------------------------------- */
491
+
492
+ static PyObject *WraptObjectProxy_divmod(PyObject *o1, PyObject *o2)
493
+ {
494
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
495
+ {
496
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
497
+ {
498
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
499
+ return NULL;
500
+ }
501
+
502
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
503
+ }
504
+
505
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
506
+ {
507
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
508
+ {
509
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
510
+ return NULL;
511
+ }
512
+
513
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
514
+ }
515
+
516
+ return PyNumber_Divmod(o1, o2);
517
+ }
518
+
519
+ /* ------------------------------------------------------------------------- */
520
+
521
+ static PyObject *WraptObjectProxy_power(PyObject *o1, PyObject *o2,
522
+ PyObject *modulo)
523
+ {
524
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
525
+ {
526
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
527
+ {
528
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
529
+ return NULL;
530
+ }
531
+
532
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
533
+ }
534
+
535
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
536
+ {
537
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
538
+ {
539
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
540
+ return NULL;
541
+ }
542
+
543
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
544
+ }
545
+
546
+ return PyNumber_Power(o1, o2, modulo);
547
+ }
548
+
549
+ /* ------------------------------------------------------------------------- */
550
+
551
+ static PyObject *WraptObjectProxy_negative(WraptObjectProxyObject *self)
552
+ {
553
+ if (!self->wrapped)
554
+ {
555
+ if (raise_uninitialized_wrapper_error(self) == -1)
556
+ return NULL;
557
+ }
558
+
559
+ return PyNumber_Negative(self->wrapped);
560
+ }
561
+
562
+ /* ------------------------------------------------------------------------- */
563
+
564
+ static PyObject *WraptObjectProxy_positive(WraptObjectProxyObject *self)
565
+ {
566
+ if (!self->wrapped)
567
+ {
568
+ if (raise_uninitialized_wrapper_error(self) == -1)
569
+ return NULL;
570
+ }
571
+
572
+ return PyNumber_Positive(self->wrapped);
573
+ }
574
+
575
+ /* ------------------------------------------------------------------------- */
576
+
577
+ static PyObject *WraptObjectProxy_absolute(WraptObjectProxyObject *self)
578
+ {
579
+ if (!self->wrapped)
580
+ {
581
+ if (raise_uninitialized_wrapper_error(self) == -1)
582
+ return NULL;
583
+ }
584
+
585
+ return PyNumber_Absolute(self->wrapped);
586
+ }
587
+
588
+ /* ------------------------------------------------------------------------- */
589
+
590
+ static int WraptObjectProxy_bool(WraptObjectProxyObject *self)
591
+ {
592
+ if (!self->wrapped)
593
+ {
594
+ if (raise_uninitialized_wrapper_error(self) == -1)
595
+ return -1;
596
+ }
597
+
598
+ return PyObject_IsTrue(self->wrapped);
599
+ }
600
+
601
+ /* ------------------------------------------------------------------------- */
602
+
603
+ static PyObject *WraptObjectProxy_invert(WraptObjectProxyObject *self)
604
+ {
605
+ if (!self->wrapped)
606
+ {
607
+ if (raise_uninitialized_wrapper_error(self) == -1)
608
+ return NULL;
609
+ }
610
+
611
+ return PyNumber_Invert(self->wrapped);
612
+ }
613
+
614
+ /* ------------------------------------------------------------------------- */
615
+
616
+ static PyObject *WraptObjectProxy_lshift(PyObject *o1, PyObject *o2)
617
+ {
618
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
619
+ {
620
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
621
+ {
622
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
623
+ return NULL;
624
+ }
625
+
626
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
627
+ }
628
+
629
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
630
+ {
631
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
632
+ {
633
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
634
+ return NULL;
635
+ }
636
+
637
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
638
+ }
639
+
640
+ return PyNumber_Lshift(o1, o2);
641
+ }
642
+
643
+ /* ------------------------------------------------------------------------- */
644
+
645
+ static PyObject *WraptObjectProxy_rshift(PyObject *o1, PyObject *o2)
646
+ {
647
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
648
+ {
649
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
650
+ {
651
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
652
+ return NULL;
653
+ }
654
+
655
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
656
+ }
657
+
658
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
659
+ {
660
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
661
+ {
662
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
663
+ return NULL;
664
+ }
665
+
666
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
667
+ }
668
+
669
+ return PyNumber_Rshift(o1, o2);
670
+ }
671
+
672
+ /* ------------------------------------------------------------------------- */
673
+
674
+ static PyObject *WraptObjectProxy_and(PyObject *o1, PyObject *o2)
675
+ {
676
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
677
+ {
678
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
679
+ {
680
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
681
+ return NULL;
682
+ }
683
+
684
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
685
+ }
686
+
687
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
688
+ {
689
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
690
+ {
691
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
692
+ return NULL;
693
+ }
694
+
695
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
696
+ }
697
+
698
+ return PyNumber_And(o1, o2);
699
+ }
700
+
701
+ /* ------------------------------------------------------------------------- */
702
+
703
+ static PyObject *WraptObjectProxy_xor(PyObject *o1, PyObject *o2)
704
+ {
705
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
706
+ {
707
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
708
+ {
709
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
710
+ return NULL;
711
+ }
712
+
713
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
714
+ }
715
+
716
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
717
+ {
718
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
719
+ {
720
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
721
+ return NULL;
722
+ }
723
+
724
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
725
+ }
726
+
727
+ return PyNumber_Xor(o1, o2);
728
+ }
729
+
730
+ /* ------------------------------------------------------------------------- */
731
+
732
+ static PyObject *WraptObjectProxy_or(PyObject *o1, PyObject *o2)
733
+ {
734
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
735
+ {
736
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
737
+ {
738
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
739
+ return NULL;
740
+ }
741
+
742
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
743
+ }
744
+
745
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
746
+ {
747
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
748
+ {
749
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
750
+ return NULL;
751
+ }
752
+
753
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
754
+ }
755
+
756
+ return PyNumber_Or(o1, o2);
757
+ }
758
+
759
+ /* ------------------------------------------------------------------------- */
760
+
761
+ static PyObject *WraptObjectProxy_long(WraptObjectProxyObject *self)
762
+ {
763
+ if (!self->wrapped)
764
+ {
765
+ if (raise_uninitialized_wrapper_error(self) == -1)
766
+ return NULL;
767
+ }
768
+
769
+ return PyNumber_Long(self->wrapped);
770
+ }
771
+
772
+ /* ------------------------------------------------------------------------- */
773
+
774
+ static PyObject *WraptObjectProxy_float(WraptObjectProxyObject *self)
775
+ {
776
+ if (!self->wrapped)
777
+ {
778
+ if (raise_uninitialized_wrapper_error(self) == -1)
779
+ return NULL;
780
+ }
781
+
782
+ return PyNumber_Float(self->wrapped);
783
+ }
784
+
785
+ /* ------------------------------------------------------------------------- */
786
+
787
+ static PyObject *WraptObjectProxy_inplace_add(WraptObjectProxyObject *self,
788
+ PyObject *other)
789
+ {
790
+ PyObject *object = NULL;
791
+
792
+ if (!self->wrapped)
793
+ {
794
+ if (raise_uninitialized_wrapper_error(self) == -1)
795
+ return NULL;
796
+ }
797
+
798
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
799
+ other = ((WraptObjectProxyObject *)other)->wrapped;
800
+
801
+ if (PyObject_HasAttrString(self->wrapped, "__iadd__"))
802
+ {
803
+ object = PyNumber_InPlaceAdd(self->wrapped, other);
804
+
805
+ if (!object)
806
+ return NULL;
807
+
808
+ Py_DECREF(self->wrapped);
809
+ self->wrapped = object;
810
+
811
+ Py_INCREF(self);
812
+ return (PyObject *)self;
813
+ }
814
+ else
815
+ {
816
+ PyObject *result = PyNumber_Add(self->wrapped, other);
817
+
818
+ if (!result)
819
+ return NULL;
820
+
821
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
822
+
823
+ if (!proxy_type)
824
+ {
825
+ Py_DECREF(proxy_type);
826
+ return NULL;
827
+ }
828
+
829
+ PyObject *proxy_args = PyTuple_Pack(1, result);
830
+
831
+ Py_DECREF(result);
832
+
833
+ if (!proxy_args)
834
+ {
835
+ Py_DECREF(proxy_type);
836
+ return NULL;
837
+ }
838
+
839
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
840
+
841
+ Py_DECREF(proxy_type);
842
+ Py_DECREF(proxy_args);
843
+
844
+ return proxy_instance;
845
+ }
846
+ }
847
+
848
+ /* ------------------------------------------------------------------------- */
849
+
850
+ static PyObject *WraptObjectProxy_inplace_subtract(WraptObjectProxyObject *self,
851
+ PyObject *other)
852
+ {
853
+ PyObject *object = NULL;
854
+
855
+ if (!self->wrapped)
856
+ {
857
+ if (raise_uninitialized_wrapper_error(self) == -1)
858
+ return NULL;
859
+ }
860
+
861
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
862
+ other = ((WraptObjectProxyObject *)other)->wrapped;
863
+
864
+ if (PyObject_HasAttrString(self->wrapped, "__isub__"))
865
+ {
866
+ object = PyNumber_InPlaceSubtract(self->wrapped, other);
867
+
868
+ if (!object)
869
+ return NULL;
870
+
871
+ Py_DECREF(self->wrapped);
872
+ self->wrapped = object;
873
+
874
+ Py_INCREF(self);
875
+ return (PyObject *)self;
876
+ }
877
+ else
878
+ {
879
+ PyObject *result = PyNumber_Subtract(self->wrapped, other);
880
+
881
+ if (!result)
882
+ return NULL;
883
+
884
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
885
+
886
+ if (!proxy_type)
887
+ {
888
+ Py_DECREF(proxy_type);
889
+ return NULL;
890
+ }
891
+
892
+ PyObject *proxy_args = PyTuple_Pack(1, result);
893
+
894
+ Py_DECREF(result);
895
+
896
+ if (!proxy_args)
897
+ {
898
+ Py_DECREF(proxy_type);
899
+ return NULL;
900
+ }
901
+
902
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
903
+
904
+ Py_DECREF(proxy_type);
905
+ Py_DECREF(proxy_args);
906
+
907
+ return proxy_instance;
908
+ }
909
+ }
910
+
911
+ /* ------------------------------------------------------------------------- */
912
+
913
+ static PyObject *WraptObjectProxy_inplace_multiply(WraptObjectProxyObject *self,
914
+ PyObject *other)
915
+ {
916
+ PyObject *object = NULL;
917
+
918
+ if (!self->wrapped)
919
+ {
920
+ if (raise_uninitialized_wrapper_error(self) == -1)
921
+ return NULL;
922
+ }
923
+
924
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
925
+ other = ((WraptObjectProxyObject *)other)->wrapped;
926
+
927
+ if (PyObject_HasAttrString(self->wrapped, "__imul__"))
928
+ {
929
+ object = PyNumber_InPlaceMultiply(self->wrapped, other);
930
+
931
+ if (!object)
932
+ return NULL;
933
+
934
+ Py_DECREF(self->wrapped);
935
+ self->wrapped = object;
936
+
937
+ Py_INCREF(self);
938
+ return (PyObject *)self;
939
+ }
940
+ else
941
+ {
942
+ PyObject *result = PyNumber_Multiply(self->wrapped, other);
943
+
944
+ if (!result)
945
+ return NULL;
946
+
947
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
948
+
949
+ if (!proxy_type)
950
+ {
951
+ Py_DECREF(proxy_type);
952
+ return NULL;
953
+ }
954
+
955
+ PyObject *proxy_args = PyTuple_Pack(1, result);
956
+
957
+ Py_DECREF(result);
958
+
959
+ if (!proxy_args)
960
+ {
961
+ Py_DECREF(proxy_type);
962
+ return NULL;
963
+ }
964
+
965
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
966
+
967
+ Py_DECREF(proxy_type);
968
+ Py_DECREF(proxy_args);
969
+
970
+ return proxy_instance;
971
+ }
972
+ }
973
+
974
+ /* ------------------------------------------------------------------------- */
975
+
976
+ static PyObject *
977
+ WraptObjectProxy_inplace_remainder(WraptObjectProxyObject *self,
978
+ PyObject *other)
979
+ {
980
+ PyObject *object = NULL;
981
+
982
+ if (!self->wrapped)
983
+ {
984
+ if (raise_uninitialized_wrapper_error(self) == -1)
985
+ return NULL;
986
+ }
987
+
988
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
989
+ other = ((WraptObjectProxyObject *)other)->wrapped;
990
+
991
+ if (PyObject_HasAttrString(self->wrapped, "__imod__"))
992
+ {
993
+ object = PyNumber_InPlaceRemainder(self->wrapped, other);
994
+
995
+ if (!object)
996
+ return NULL;
997
+
998
+ Py_DECREF(self->wrapped);
999
+ self->wrapped = object;
1000
+
1001
+ Py_INCREF(self);
1002
+ return (PyObject *)self;
1003
+ }
1004
+ else
1005
+ {
1006
+ PyObject *result = PyNumber_Remainder(self->wrapped, other);
1007
+
1008
+ if (!result)
1009
+ return NULL;
1010
+
1011
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1012
+
1013
+ if (!proxy_type)
1014
+ {
1015
+ Py_DECREF(proxy_type);
1016
+ return NULL;
1017
+ }
1018
+
1019
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1020
+
1021
+ Py_DECREF(result);
1022
+
1023
+ if (!proxy_args)
1024
+ {
1025
+ Py_DECREF(proxy_type);
1026
+ return NULL;
1027
+ }
1028
+
1029
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1030
+
1031
+ Py_DECREF(proxy_type);
1032
+ Py_DECREF(proxy_args);
1033
+
1034
+ return proxy_instance;
1035
+ }
1036
+ }
1037
+
1038
+ /* ------------------------------------------------------------------------- */
1039
+
1040
+ static PyObject *WraptObjectProxy_inplace_power(WraptObjectProxyObject *self,
1041
+ PyObject *other,
1042
+ PyObject *modulo)
1043
+ {
1044
+ PyObject *object = NULL;
1045
+
1046
+ if (!self->wrapped)
1047
+ {
1048
+ if (raise_uninitialized_wrapper_error(self) == -1)
1049
+ return NULL;
1050
+ }
1051
+
1052
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1053
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1054
+
1055
+ if (PyObject_HasAttrString(self->wrapped, "__ipow__"))
1056
+ {
1057
+ object = PyNumber_InPlacePower(self->wrapped, other, modulo);
1058
+
1059
+ if (!object)
1060
+ return NULL;
1061
+
1062
+ Py_DECREF(self->wrapped);
1063
+ self->wrapped = object;
1064
+
1065
+ Py_INCREF(self);
1066
+ return (PyObject *)self;
1067
+ }
1068
+ else
1069
+ {
1070
+ PyObject *result = PyNumber_Power(self->wrapped, other, modulo);
1071
+
1072
+ if (!result)
1073
+ return NULL;
1074
+
1075
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1076
+
1077
+ if (!proxy_type)
1078
+ {
1079
+ Py_DECREF(proxy_type);
1080
+ return NULL;
1081
+ }
1082
+
1083
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1084
+
1085
+ Py_DECREF(result);
1086
+
1087
+ if (!proxy_args)
1088
+ {
1089
+ Py_DECREF(proxy_type);
1090
+ return NULL;
1091
+ }
1092
+
1093
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1094
+
1095
+ Py_DECREF(proxy_type);
1096
+ Py_DECREF(proxy_args);
1097
+
1098
+ return proxy_instance;
1099
+ }
1100
+ }
1101
+
1102
+ /* ------------------------------------------------------------------------- */
1103
+
1104
+ static PyObject *WraptObjectProxy_inplace_lshift(WraptObjectProxyObject *self,
1105
+ PyObject *other)
1106
+ {
1107
+ PyObject *object = NULL;
1108
+
1109
+ if (!self->wrapped)
1110
+ {
1111
+ if (raise_uninitialized_wrapper_error(self) == -1)
1112
+ return NULL;
1113
+ }
1114
+
1115
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1116
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1117
+
1118
+ if (PyObject_HasAttrString(self->wrapped, "__ilshift__"))
1119
+ {
1120
+ object = PyNumber_InPlaceLshift(self->wrapped, other);
1121
+
1122
+ if (!object)
1123
+ return NULL;
1124
+
1125
+ Py_DECREF(self->wrapped);
1126
+ self->wrapped = object;
1127
+
1128
+ Py_INCREF(self);
1129
+ return (PyObject *)self;
1130
+ }
1131
+ else
1132
+ {
1133
+ PyObject *result = PyNumber_Lshift(self->wrapped, other);
1134
+
1135
+ if (!result)
1136
+ return NULL;
1137
+
1138
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1139
+
1140
+ if (!proxy_type)
1141
+ {
1142
+ Py_DECREF(proxy_type);
1143
+ return NULL;
1144
+ }
1145
+
1146
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1147
+
1148
+ Py_DECREF(result);
1149
+
1150
+ if (!proxy_args)
1151
+ {
1152
+ Py_DECREF(proxy_type);
1153
+ return NULL;
1154
+ }
1155
+
1156
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1157
+
1158
+ Py_DECREF(proxy_type);
1159
+ Py_DECREF(proxy_args);
1160
+
1161
+ return proxy_instance;
1162
+ }
1163
+ }
1164
+
1165
+ /* ------------------------------------------------------------------------- */
1166
+
1167
+ static PyObject *WraptObjectProxy_inplace_rshift(WraptObjectProxyObject *self,
1168
+ PyObject *other)
1169
+ {
1170
+ PyObject *object = NULL;
1171
+
1172
+ if (!self->wrapped)
1173
+ {
1174
+ if (raise_uninitialized_wrapper_error(self) == -1)
1175
+ return NULL;
1176
+ }
1177
+
1178
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1179
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1180
+
1181
+ if (PyObject_HasAttrString(self->wrapped, "__irshift__"))
1182
+ {
1183
+ object = PyNumber_InPlaceRshift(self->wrapped, other);
1184
+
1185
+ if (!object)
1186
+ return NULL;
1187
+
1188
+ Py_DECREF(self->wrapped);
1189
+ self->wrapped = object;
1190
+
1191
+ Py_INCREF(self);
1192
+ return (PyObject *)self;
1193
+ }
1194
+ else
1195
+ {
1196
+ PyObject *result = PyNumber_Rshift(self->wrapped, other);
1197
+
1198
+ if (!result)
1199
+ return NULL;
1200
+
1201
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1202
+
1203
+ if (!proxy_type)
1204
+ {
1205
+ Py_DECREF(proxy_type);
1206
+ return NULL;
1207
+ }
1208
+
1209
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1210
+
1211
+ Py_DECREF(result);
1212
+
1213
+ if (!proxy_args)
1214
+ {
1215
+ Py_DECREF(proxy_type);
1216
+ return NULL;
1217
+ }
1218
+
1219
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1220
+
1221
+ Py_DECREF(proxy_type);
1222
+ Py_DECREF(proxy_args);
1223
+
1224
+ return proxy_instance;
1225
+ }
1226
+ }
1227
+
1228
+ /* ------------------------------------------------------------------------- */
1229
+
1230
+ static PyObject *WraptObjectProxy_inplace_and(WraptObjectProxyObject *self,
1231
+ PyObject *other)
1232
+ {
1233
+ PyObject *object = NULL;
1234
+
1235
+ if (!self->wrapped)
1236
+ {
1237
+ if (raise_uninitialized_wrapper_error(self) == -1)
1238
+ return NULL;
1239
+ }
1240
+
1241
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1242
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1243
+
1244
+ if (PyObject_HasAttrString(self->wrapped, "__iand__"))
1245
+ {
1246
+ object = PyNumber_InPlaceAnd(self->wrapped, other);
1247
+
1248
+ if (!object)
1249
+ return NULL;
1250
+
1251
+ Py_DECREF(self->wrapped);
1252
+ self->wrapped = object;
1253
+
1254
+ Py_INCREF(self);
1255
+ return (PyObject *)self;
1256
+ }
1257
+ else
1258
+ {
1259
+ PyObject *result = PyNumber_And(self->wrapped, other);
1260
+
1261
+ if (!result)
1262
+ return NULL;
1263
+
1264
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1265
+
1266
+ if (!proxy_type)
1267
+ {
1268
+ Py_DECREF(proxy_type);
1269
+ return NULL;
1270
+ }
1271
+
1272
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1273
+
1274
+ Py_DECREF(result);
1275
+
1276
+ if (!proxy_args)
1277
+ {
1278
+ Py_DECREF(proxy_type);
1279
+ return NULL;
1280
+ }
1281
+
1282
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1283
+
1284
+ Py_DECREF(proxy_type);
1285
+ Py_DECREF(proxy_args);
1286
+
1287
+ return proxy_instance;
1288
+ }
1289
+ }
1290
+
1291
+ /* ------------------------------------------------------------------------- */
1292
+
1293
+ static PyObject *WraptObjectProxy_inplace_xor(WraptObjectProxyObject *self,
1294
+ PyObject *other)
1295
+ {
1296
+ PyObject *object = NULL;
1297
+
1298
+ if (!self->wrapped)
1299
+ {
1300
+ if (raise_uninitialized_wrapper_error(self) == -1)
1301
+ return NULL;
1302
+ }
1303
+
1304
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1305
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1306
+
1307
+ if (PyObject_HasAttrString(self->wrapped, "__ixor__"))
1308
+ {
1309
+ object = PyNumber_InPlaceXor(self->wrapped, other);
1310
+
1311
+ if (!object)
1312
+ return NULL;
1313
+
1314
+ Py_DECREF(self->wrapped);
1315
+ self->wrapped = object;
1316
+
1317
+ Py_INCREF(self);
1318
+ return (PyObject *)self;
1319
+ }
1320
+ else
1321
+ {
1322
+ PyObject *result = PyNumber_Xor(self->wrapped, other);
1323
+
1324
+ if (!result)
1325
+ return NULL;
1326
+
1327
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1328
+
1329
+ if (!proxy_type)
1330
+ {
1331
+ Py_DECREF(proxy_type);
1332
+ return NULL;
1333
+ }
1334
+
1335
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1336
+
1337
+ Py_DECREF(result);
1338
+
1339
+ if (!proxy_args)
1340
+ {
1341
+ Py_DECREF(proxy_type);
1342
+ return NULL;
1343
+ }
1344
+
1345
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1346
+
1347
+ Py_DECREF(proxy_type);
1348
+ Py_DECREF(proxy_args);
1349
+
1350
+ return proxy_instance;
1351
+ }
1352
+ }
1353
+
1354
+ /* ------------------------------------------------------------------------- */
1355
+
1356
+ static PyObject *WraptObjectProxy_inplace_or(WraptObjectProxyObject *self,
1357
+ PyObject *other)
1358
+ {
1359
+ PyObject *object = NULL;
1360
+
1361
+ if (!self->wrapped)
1362
+ {
1363
+ if (raise_uninitialized_wrapper_error(self) == -1)
1364
+ return NULL;
1365
+ }
1366
+
1367
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1368
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1369
+
1370
+ if (PyObject_HasAttrString(self->wrapped, "__ior__"))
1371
+ {
1372
+ object = PyNumber_InPlaceOr(self->wrapped, other);
1373
+
1374
+ if (!object)
1375
+ return NULL;
1376
+
1377
+ Py_DECREF(self->wrapped);
1378
+ self->wrapped = object;
1379
+
1380
+ Py_INCREF(self);
1381
+ return (PyObject *)self;
1382
+ }
1383
+ else
1384
+ {
1385
+ PyObject *result = PyNumber_Or(self->wrapped, other);
1386
+
1387
+ if (!result)
1388
+ return NULL;
1389
+
1390
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1391
+
1392
+ if (!proxy_type)
1393
+ {
1394
+ Py_DECREF(proxy_type);
1395
+ return NULL;
1396
+ }
1397
+
1398
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1399
+
1400
+ Py_DECREF(result);
1401
+
1402
+ if (!proxy_args)
1403
+ {
1404
+ Py_DECREF(proxy_type);
1405
+ return NULL;
1406
+ }
1407
+
1408
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1409
+
1410
+ Py_DECREF(proxy_type);
1411
+ Py_DECREF(proxy_args);
1412
+
1413
+ return proxy_instance;
1414
+ }
1415
+ }
1416
+
1417
+ /* ------------------------------------------------------------------------- */
1418
+
1419
+ static PyObject *WraptObjectProxy_floor_divide(PyObject *o1, PyObject *o2)
1420
+ {
1421
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
1422
+ {
1423
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
1424
+ {
1425
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
1426
+ return NULL;
1427
+ }
1428
+
1429
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
1430
+ }
1431
+
1432
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
1433
+ {
1434
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
1435
+ {
1436
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
1437
+ return NULL;
1438
+ }
1439
+
1440
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
1441
+ }
1442
+
1443
+ return PyNumber_FloorDivide(o1, o2);
1444
+ }
1445
+
1446
+ /* ------------------------------------------------------------------------- */
1447
+
1448
+ static PyObject *WraptObjectProxy_true_divide(PyObject *o1, PyObject *o2)
1449
+ {
1450
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
1451
+ {
1452
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
1453
+ {
1454
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
1455
+ return NULL;
1456
+ }
1457
+
1458
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
1459
+ }
1460
+
1461
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
1462
+ {
1463
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
1464
+ {
1465
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
1466
+ return NULL;
1467
+ }
1468
+
1469
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
1470
+ }
1471
+
1472
+ return PyNumber_TrueDivide(o1, o2);
1473
+ }
1474
+
1475
+ /* ------------------------------------------------------------------------- */
1476
+
1477
+ static PyObject *
1478
+ WraptObjectProxy_inplace_floor_divide(WraptObjectProxyObject *self,
1479
+ PyObject *other)
1480
+ {
1481
+ PyObject *object = NULL;
1482
+
1483
+ if (!self->wrapped)
1484
+ {
1485
+ if (raise_uninitialized_wrapper_error(self) == -1)
1486
+ return NULL;
1487
+ }
1488
+
1489
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1490
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1491
+
1492
+ if (PyObject_HasAttrString(self->wrapped, "__ifloordiv__"))
1493
+ {
1494
+ object = PyNumber_InPlaceFloorDivide(self->wrapped, other);
1495
+
1496
+ if (!object)
1497
+ return NULL;
1498
+
1499
+ Py_DECREF(self->wrapped);
1500
+ self->wrapped = object;
1501
+
1502
+ Py_INCREF(self);
1503
+ return (PyObject *)self;
1504
+ }
1505
+ else
1506
+ {
1507
+ PyObject *result = PyNumber_FloorDivide(self->wrapped, other);
1508
+
1509
+ if (!result)
1510
+ return NULL;
1511
+
1512
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1513
+
1514
+ if (!proxy_type)
1515
+ {
1516
+ Py_DECREF(proxy_type);
1517
+ return NULL;
1518
+ }
1519
+
1520
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1521
+
1522
+ Py_DECREF(result);
1523
+
1524
+ if (!proxy_args)
1525
+ {
1526
+ Py_DECREF(proxy_type);
1527
+ return NULL;
1528
+ }
1529
+
1530
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1531
+
1532
+ Py_DECREF(proxy_type);
1533
+ Py_DECREF(proxy_args);
1534
+
1535
+ return proxy_instance;
1536
+ }
1537
+ }
1538
+
1539
+ /* ------------------------------------------------------------------------- */
1540
+
1541
+ static PyObject *
1542
+ WraptObjectProxy_inplace_true_divide(WraptObjectProxyObject *self,
1543
+ PyObject *other)
1544
+ {
1545
+ PyObject *object = NULL;
1546
+
1547
+ if (!self->wrapped)
1548
+ {
1549
+ if (raise_uninitialized_wrapper_error(self) == -1)
1550
+ return NULL;
1551
+ }
1552
+
1553
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1554
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1555
+
1556
+ if (PyObject_HasAttrString(self->wrapped, "__itruediv__"))
1557
+ {
1558
+ object = PyNumber_InPlaceTrueDivide(self->wrapped, other);
1559
+
1560
+ if (!object)
1561
+ return NULL;
1562
+
1563
+ Py_DECREF(self->wrapped);
1564
+ self->wrapped = object;
1565
+
1566
+ Py_INCREF(self);
1567
+ return (PyObject *)self;
1568
+ }
1569
+ else
1570
+ {
1571
+ PyObject *result = PyNumber_TrueDivide(self->wrapped, other);
1572
+
1573
+ if (!result)
1574
+ return NULL;
1575
+
1576
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1577
+
1578
+ if (!proxy_type)
1579
+ {
1580
+ Py_DECREF(proxy_type);
1581
+ return NULL;
1582
+ }
1583
+
1584
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1585
+
1586
+ Py_DECREF(result);
1587
+
1588
+ if (!proxy_args)
1589
+ {
1590
+ Py_DECREF(proxy_type);
1591
+ return NULL;
1592
+ }
1593
+
1594
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1595
+
1596
+ Py_DECREF(proxy_type);
1597
+ Py_DECREF(proxy_args);
1598
+
1599
+ return proxy_instance;
1600
+ }
1601
+ }
1602
+
1603
+ /* ------------------------------------------------------------------------- */
1604
+
1605
+ static PyObject *WraptObjectProxy_index(WraptObjectProxyObject *self)
1606
+ {
1607
+ if (!self->wrapped)
1608
+ {
1609
+ if (raise_uninitialized_wrapper_error(self) == -1)
1610
+ return NULL;
1611
+ }
1612
+
1613
+ return PyNumber_Index(self->wrapped);
1614
+ }
1615
+
1616
+ /* ------------------------------------------------------------------------- */
1617
+
1618
+ static PyObject *WraptObjectProxy_matrix_multiply(PyObject *o1, PyObject *o2)
1619
+ {
1620
+ if (PyObject_IsInstance(o1, (PyObject *)&WraptObjectProxy_Type))
1621
+ {
1622
+ if (!((WraptObjectProxyObject *)o1)->wrapped)
1623
+ {
1624
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o1) == -1)
1625
+ return NULL;
1626
+ }
1627
+
1628
+ o1 = ((WraptObjectProxyObject *)o1)->wrapped;
1629
+ }
1630
+
1631
+ if (PyObject_IsInstance(o2, (PyObject *)&WraptObjectProxy_Type))
1632
+ {
1633
+ if (!((WraptObjectProxyObject *)o2)->wrapped)
1634
+ {
1635
+ if (raise_uninitialized_wrapper_error((WraptObjectProxyObject *)o2) == -1)
1636
+ return NULL;
1637
+ }
1638
+
1639
+ o2 = ((WraptObjectProxyObject *)o2)->wrapped;
1640
+ }
1641
+
1642
+ return PyNumber_MatrixMultiply(o1, o2);
1643
+ }
1644
+
1645
+ /* ------------------------------------------------------------------------- */
1646
+
1647
+ static PyObject *WraptObjectProxy_inplace_matrix_multiply(
1648
+ WraptObjectProxyObject *self, PyObject *other)
1649
+ {
1650
+ PyObject *object = NULL;
1651
+
1652
+ if (!self->wrapped)
1653
+ {
1654
+ if (raise_uninitialized_wrapper_error(self) == -1)
1655
+ return NULL;
1656
+ }
1657
+
1658
+ if (PyObject_IsInstance(other, (PyObject *)&WraptObjectProxy_Type))
1659
+ other = ((WraptObjectProxyObject *)other)->wrapped;
1660
+
1661
+ if (PyObject_HasAttrString(self->wrapped, "__imatmul__"))
1662
+ {
1663
+ object = PyNumber_InPlaceMatrixMultiply(self->wrapped, other);
1664
+
1665
+ if (!object)
1666
+ return NULL;
1667
+
1668
+ Py_DECREF(self->wrapped);
1669
+ self->wrapped = object;
1670
+
1671
+ Py_INCREF(self);
1672
+ return (PyObject *)self;
1673
+ }
1674
+ else
1675
+ {
1676
+ PyObject *result = PyNumber_MatrixMultiply(self->wrapped, other);
1677
+
1678
+ if (!result)
1679
+ return NULL;
1680
+
1681
+ PyObject *proxy_type = PyObject_GetAttrString((PyObject *)self, "__object_proxy__");
1682
+
1683
+ if (!proxy_type)
1684
+ {
1685
+ Py_DECREF(proxy_type);
1686
+ return NULL;
1687
+ }
1688
+
1689
+ PyObject *proxy_args = PyTuple_Pack(1, result);
1690
+
1691
+ Py_DECREF(result);
1692
+
1693
+ if (!proxy_args)
1694
+ {
1695
+ Py_DECREF(proxy_type);
1696
+ return NULL;
1697
+ }
1698
+
1699
+ PyObject *proxy_instance = PyObject_Call(proxy_type, proxy_args, NULL);
1700
+
1701
+ Py_DECREF(proxy_type);
1702
+ Py_DECREF(proxy_args);
1703
+
1704
+ return proxy_instance;
1705
+ }
1706
+ }
1707
+
1708
+ /* ------------------------------------------------------------------------- */
1709
+
1710
+ static Py_ssize_t WraptObjectProxy_length(WraptObjectProxyObject *self)
1711
+ {
1712
+ if (!self->wrapped)
1713
+ {
1714
+ if (raise_uninitialized_wrapper_error(self) == -1)
1715
+ return -1;
1716
+ }
1717
+
1718
+ return PyObject_Length(self->wrapped);
1719
+ }
1720
+
1721
+ /* ------------------------------------------------------------------------- */
1722
+
1723
+ static int WraptObjectProxy_contains(WraptObjectProxyObject *self,
1724
+ PyObject *value)
1725
+ {
1726
+ if (!self->wrapped)
1727
+ {
1728
+ if (raise_uninitialized_wrapper_error(self) == -1)
1729
+ return -1;
1730
+ }
1731
+
1732
+ return PySequence_Contains(self->wrapped, value);
1733
+ }
1734
+
1735
+ /* ------------------------------------------------------------------------- */
1736
+
1737
+ static PyObject *WraptObjectProxy_getitem(WraptObjectProxyObject *self,
1738
+ PyObject *key)
1739
+ {
1740
+ if (!self->wrapped)
1741
+ {
1742
+ if (raise_uninitialized_wrapper_error(self) == -1)
1743
+ return NULL;
1744
+ }
1745
+
1746
+ return PyObject_GetItem(self->wrapped, key);
1747
+ }
1748
+
1749
+ /* ------------------------------------------------------------------------- */
1750
+
1751
+ static int WraptObjectProxy_setitem(WraptObjectProxyObject *self, PyObject *key,
1752
+ PyObject *value)
1753
+ {
1754
+ if (!self->wrapped)
1755
+ {
1756
+ if (raise_uninitialized_wrapper_error(self) == -1)
1757
+ return -1;
1758
+ }
1759
+
1760
+ if (value == NULL)
1761
+ return PyObject_DelItem(self->wrapped, key);
1762
+ else
1763
+ return PyObject_SetItem(self->wrapped, key, value);
1764
+ }
1765
+
1766
+ /* ------------------------------------------------------------------------- */
1767
+
1768
+ static PyObject *WraptObjectProxy_self_setattr(WraptObjectProxyObject *self,
1769
+ PyObject *args)
1770
+ {
1771
+ PyObject *name = NULL;
1772
+ PyObject *value = NULL;
1773
+
1774
+ if (!PyArg_ParseTuple(args, "UO:__self_setattr__", &name, &value))
1775
+ return NULL;
1776
+
1777
+ if (PyObject_GenericSetAttr((PyObject *)self, name, value) != 0)
1778
+ {
1779
+ return NULL;
1780
+ }
1781
+
1782
+ Py_INCREF(Py_None);
1783
+ return Py_None;
1784
+ }
1785
+
1786
+ /* ------------------------------------------------------------------------- */
1787
+
1788
+ static PyObject *WraptObjectProxy_dir(WraptObjectProxyObject *self,
1789
+ PyObject *args)
1790
+ {
1791
+ if (!self->wrapped)
1792
+ {
1793
+ if (raise_uninitialized_wrapper_error(self) == -1)
1794
+ return NULL;
1795
+ }
1796
+
1797
+ return PyObject_Dir(self->wrapped);
1798
+ }
1799
+
1800
+ /* ------------------------------------------------------------------------- */
1801
+
1802
+ static PyObject *WraptObjectProxy_enter(WraptObjectProxyObject *self,
1803
+ PyObject *args, PyObject *kwds)
1804
+ {
1805
+ PyObject *method = NULL;
1806
+ PyObject *result = NULL;
1807
+
1808
+ if (!self->wrapped)
1809
+ {
1810
+ if (raise_uninitialized_wrapper_error(self) == -1)
1811
+ return NULL;
1812
+ }
1813
+
1814
+ method = PyObject_GetAttrString(self->wrapped, "__enter__");
1815
+
1816
+ if (!method)
1817
+ return NULL;
1818
+
1819
+ result = PyObject_Call(method, args, kwds);
1820
+
1821
+ Py_DECREF(method);
1822
+
1823
+ return result;
1824
+ }
1825
+
1826
+ /* ------------------------------------------------------------------------- */
1827
+
1828
+ static PyObject *WraptObjectProxy_exit(WraptObjectProxyObject *self,
1829
+ PyObject *args, PyObject *kwds)
1830
+ {
1831
+ PyObject *method = NULL;
1832
+ PyObject *result = NULL;
1833
+
1834
+ if (!self->wrapped)
1835
+ {
1836
+ if (raise_uninitialized_wrapper_error(self) == -1)
1837
+ return NULL;
1838
+ }
1839
+
1840
+ method = PyObject_GetAttrString(self->wrapped, "__exit__");
1841
+
1842
+ if (!method)
1843
+ return NULL;
1844
+
1845
+ result = PyObject_Call(method, args, kwds);
1846
+
1847
+ Py_DECREF(method);
1848
+
1849
+ return result;
1850
+ }
1851
+
1852
+ /* ------------------------------------------------------------------------- */
1853
+
1854
+ static PyObject *WraptObjectProxy_aenter(WraptObjectProxyObject *self,
1855
+ PyObject *args, PyObject *kwds)
1856
+ {
1857
+ PyObject *method = NULL;
1858
+ PyObject *result = NULL;
1859
+
1860
+ if (!self->wrapped)
1861
+ {
1862
+ if (raise_uninitialized_wrapper_error(self) == -1)
1863
+ return NULL;
1864
+ }
1865
+
1866
+ method = PyObject_GetAttrString(self->wrapped, "__aenter__");
1867
+
1868
+ if (!method)
1869
+ return NULL;
1870
+
1871
+ result = PyObject_Call(method, args, kwds);
1872
+
1873
+ Py_DECREF(method);
1874
+
1875
+ return result;
1876
+ }
1877
+
1878
+ /* ------------------------------------------------------------------------- */
1879
+
1880
+ static PyObject *WraptObjectProxy_aexit(WraptObjectProxyObject *self,
1881
+ PyObject *args, PyObject *kwds)
1882
+ {
1883
+ PyObject *method = NULL;
1884
+ PyObject *result = NULL;
1885
+
1886
+ if (!self->wrapped)
1887
+ {
1888
+ if (raise_uninitialized_wrapper_error(self) == -1)
1889
+ return NULL;
1890
+ }
1891
+
1892
+ method = PyObject_GetAttrString(self->wrapped, "__aexit__");
1893
+
1894
+ if (!method)
1895
+ return NULL;
1896
+
1897
+ result = PyObject_Call(method, args, kwds);
1898
+
1899
+ Py_DECREF(method);
1900
+
1901
+ return result;
1902
+ }
1903
+
1904
+ /* ------------------------------------------------------------------------- */
1905
+
1906
+ static PyObject *WraptObjectProxy_copy(WraptObjectProxyObject *self,
1907
+ PyObject *args, PyObject *kwds)
1908
+ {
1909
+ PyErr_SetString(PyExc_NotImplementedError,
1910
+ "object proxy must define __copy__()");
1911
+
1912
+ return NULL;
1913
+ }
1914
+
1915
+ /* ------------------------------------------------------------------------- */
1916
+
1917
+ static PyObject *WraptObjectProxy_deepcopy(WraptObjectProxyObject *self,
1918
+ PyObject *args, PyObject *kwds)
1919
+ {
1920
+ PyErr_SetString(PyExc_NotImplementedError,
1921
+ "object proxy must define __deepcopy__()");
1922
+
1923
+ return NULL;
1924
+ }
1925
+
1926
+ /* ------------------------------------------------------------------------- */
1927
+
1928
+ static PyObject *WraptObjectProxy_reduce(WraptObjectProxyObject *self,
1929
+ PyObject *args, PyObject *kwds)
1930
+ {
1931
+ PyErr_SetString(PyExc_NotImplementedError,
1932
+ "object proxy must define __reduce__()");
1933
+
1934
+ return NULL;
1935
+ }
1936
+
1937
+ /* ------------------------------------------------------------------------- */
1938
+
1939
+ static PyObject *WraptObjectProxy_reduce_ex(WraptObjectProxyObject *self,
1940
+ PyObject *args, PyObject *kwds)
1941
+ {
1942
+ PyErr_SetString(PyExc_NotImplementedError,
1943
+ "object proxy must define __reduce_ex__()");
1944
+
1945
+ return NULL;
1946
+ }
1947
+
1948
+ /* ------------------------------------------------------------------------- */
1949
+
1950
+ static PyObject *WraptObjectProxy_bytes(WraptObjectProxyObject *self,
1951
+ PyObject *args)
1952
+ {
1953
+ if (!self->wrapped)
1954
+ {
1955
+ if (raise_uninitialized_wrapper_error(self) == -1)
1956
+ return NULL;
1957
+ }
1958
+
1959
+ return PyObject_Bytes(self->wrapped);
1960
+ }
1961
+
1962
+ /* ------------------------------------------------------------------------- */
1963
+
1964
+ static PyObject *WraptObjectProxy_format(WraptObjectProxyObject *self,
1965
+ PyObject *args)
1966
+ {
1967
+ PyObject *format_spec = NULL;
1968
+
1969
+ if (!self->wrapped)
1970
+ {
1971
+ if (raise_uninitialized_wrapper_error(self) == -1)
1972
+ return NULL;
1973
+ }
1974
+
1975
+ if (!PyArg_ParseTuple(args, "|O:format", &format_spec))
1976
+ return NULL;
1977
+
1978
+ return PyObject_Format(self->wrapped, format_spec);
1979
+ }
1980
+
1981
+ /* ------------------------------------------------------------------------- */
1982
+
1983
+ static PyObject *WraptObjectProxy_reversed(WraptObjectProxyObject *self,
1984
+ PyObject *args)
1985
+ {
1986
+ if (!self->wrapped)
1987
+ {
1988
+ if (raise_uninitialized_wrapper_error(self) == -1)
1989
+ return NULL;
1990
+ }
1991
+
1992
+ return PyObject_CallFunctionObjArgs((PyObject *)&PyReversed_Type,
1993
+ self->wrapped, NULL);
1994
+ }
1995
+
1996
+ /* ------------------------------------------------------------------------- */
1997
+
1998
+ static PyObject *WraptObjectProxy_round(WraptObjectProxyObject *self,
1999
+ PyObject *args, PyObject *kwds)
2000
+ {
2001
+ PyObject *ndigits = NULL;
2002
+
2003
+ PyObject *module = NULL;
2004
+ PyObject *round = NULL;
2005
+
2006
+ PyObject *result = NULL;
2007
+
2008
+ char *const kwlist[] = {"ndigits", NULL};
2009
+
2010
+ if (!self->wrapped)
2011
+ {
2012
+ if (raise_uninitialized_wrapper_error(self) == -1)
2013
+ return NULL;
2014
+ }
2015
+
2016
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:ObjectProxy", kwlist,
2017
+ &ndigits))
2018
+ {
2019
+ return NULL;
2020
+ }
2021
+
2022
+ module = PyImport_ImportModule("builtins");
2023
+
2024
+ if (!module)
2025
+ return NULL;
2026
+
2027
+ round = PyObject_GetAttrString(module, "round");
2028
+
2029
+ if (!round)
2030
+ {
2031
+ Py_DECREF(module);
2032
+ return NULL;
2033
+ }
2034
+
2035
+ Py_INCREF(round);
2036
+ Py_DECREF(module);
2037
+
2038
+ result = PyObject_CallFunctionObjArgs(round, self->wrapped, ndigits, NULL);
2039
+
2040
+ Py_DECREF(round);
2041
+
2042
+ return result;
2043
+ }
2044
+
2045
+ /* ------------------------------------------------------------------------- */
2046
+
2047
+ static PyObject *WraptObjectProxy_complex(WraptObjectProxyObject *self,
2048
+ PyObject *args)
2049
+ {
2050
+ if (!self->wrapped)
2051
+ {
2052
+ if (raise_uninitialized_wrapper_error(self) == -1)
2053
+ return NULL;
2054
+ }
2055
+
2056
+ return PyObject_CallFunctionObjArgs((PyObject *)&PyComplex_Type,
2057
+ self->wrapped, NULL);
2058
+ }
2059
+
2060
+ /* ------------------------------------------------------------------------- */
2061
+
2062
+ static PyObject *WraptObjectProxy_mro_entries(WraptObjectProxyObject *self,
2063
+ PyObject *args, PyObject *kwds)
2064
+ {
2065
+ PyObject *wrapped = NULL;
2066
+ PyObject *mro_entries_method = NULL;
2067
+ PyObject *result = NULL;
2068
+ int is_type = 0;
2069
+
2070
+ if (!self->wrapped)
2071
+ {
2072
+ if (raise_uninitialized_wrapper_error(self) == -1)
2073
+ return NULL;
2074
+ }
2075
+
2076
+ wrapped = self->wrapped;
2077
+
2078
+ // Check if wrapped is a type (class).
2079
+
2080
+ is_type = PyType_Check(wrapped);
2081
+
2082
+ // If wrapped is not a type and has __mro_entries__, forward to it.
2083
+
2084
+ if (!is_type)
2085
+ {
2086
+ mro_entries_method = PyObject_GetAttrString(wrapped, "__mro_entries__");
2087
+
2088
+ if (mro_entries_method)
2089
+ {
2090
+ // Call wrapped.__mro_entries__(bases).
2091
+
2092
+ result = PyObject_Call(mro_entries_method, args, kwds);
2093
+
2094
+ Py_DECREF(mro_entries_method);
2095
+
2096
+ return result;
2097
+ }
2098
+ else
2099
+ {
2100
+ PyErr_Clear();
2101
+ }
2102
+ }
2103
+
2104
+ return Py_BuildValue("(O)", wrapped);
2105
+ }
2106
+
2107
+ /* ------------------------------------------------------------------------- */
2108
+
2109
+ static PyObject *WraptObjectProxy_get_name(WraptObjectProxyObject *self)
2110
+ {
2111
+ if (!self->wrapped)
2112
+ {
2113
+ if (raise_uninitialized_wrapper_error(self) == -1)
2114
+ return NULL;
2115
+ }
2116
+
2117
+ return PyObject_GetAttrString(self->wrapped, "__name__");
2118
+ }
2119
+
2120
+ /* ------------------------------------------------------------------------- */
2121
+
2122
+ static int WraptObjectProxy_set_name(WraptObjectProxyObject *self,
2123
+ PyObject *value)
2124
+ {
2125
+ if (!self->wrapped)
2126
+ {
2127
+ if (raise_uninitialized_wrapper_error(self) == -1)
2128
+ return -1;
2129
+ }
2130
+
2131
+ return PyObject_SetAttrString(self->wrapped, "__name__", value);
2132
+ }
2133
+
2134
+ /* ------------------------------------------------------------------------- */
2135
+
2136
+ static PyObject *WraptObjectProxy_get_qualname(WraptObjectProxyObject *self)
2137
+ {
2138
+ if (!self->wrapped)
2139
+ {
2140
+ if (raise_uninitialized_wrapper_error(self) == -1)
2141
+ return NULL;
2142
+ }
2143
+
2144
+ return PyObject_GetAttrString(self->wrapped, "__qualname__");
2145
+ }
2146
+
2147
+ /* ------------------------------------------------------------------------- */
2148
+
2149
+ static int WraptObjectProxy_set_qualname(WraptObjectProxyObject *self,
2150
+ PyObject *value)
2151
+ {
2152
+ if (!self->wrapped)
2153
+ {
2154
+ if (raise_uninitialized_wrapper_error(self) == -1)
2155
+ return -1;
2156
+ }
2157
+
2158
+ return PyObject_SetAttrString(self->wrapped, "__qualname__", value);
2159
+ }
2160
+
2161
+ /* ------------------------------------------------------------------------- */
2162
+
2163
+ static PyObject *WraptObjectProxy_get_module(WraptObjectProxyObject *self)
2164
+ {
2165
+ if (!self->wrapped)
2166
+ {
2167
+ if (raise_uninitialized_wrapper_error(self) == -1)
2168
+ return NULL;
2169
+ }
2170
+
2171
+ return PyObject_GetAttrString(self->wrapped, "__module__");
2172
+ }
2173
+
2174
+ /* ------------------------------------------------------------------------- */
2175
+
2176
+ static int WraptObjectProxy_set_module(WraptObjectProxyObject *self,
2177
+ PyObject *value)
2178
+ {
2179
+ if (!self->wrapped)
2180
+ {
2181
+ if (raise_uninitialized_wrapper_error(self) == -1)
2182
+ return -1;
2183
+ }
2184
+
2185
+ if (PyObject_SetAttrString(self->wrapped, "__module__", value) == -1)
2186
+ return -1;
2187
+
2188
+ return PyDict_SetItemString(self->dict, "__module__", value);
2189
+ }
2190
+
2191
+ /* ------------------------------------------------------------------------- */
2192
+
2193
+ static PyObject *WraptObjectProxy_get_doc(WraptObjectProxyObject *self)
2194
+ {
2195
+ if (!self->wrapped)
2196
+ {
2197
+ if (raise_uninitialized_wrapper_error(self) == -1)
2198
+ return NULL;
2199
+ }
2200
+
2201
+ return PyObject_GetAttrString(self->wrapped, "__doc__");
2202
+ }
2203
+
2204
+ /* ------------------------------------------------------------------------- */
2205
+
2206
+ static int WraptObjectProxy_set_doc(WraptObjectProxyObject *self,
2207
+ PyObject *value)
2208
+ {
2209
+ if (!self->wrapped)
2210
+ {
2211
+ if (raise_uninitialized_wrapper_error(self) == -1)
2212
+ return -1;
2213
+ }
2214
+
2215
+ if (PyObject_SetAttrString(self->wrapped, "__doc__", value) == -1)
2216
+ return -1;
2217
+
2218
+ return PyDict_SetItemString(self->dict, "__doc__", value);
2219
+ }
2220
+
2221
+ /* ------------------------------------------------------------------------- */
2222
+
2223
+ static PyObject *WraptObjectProxy_get_class(WraptObjectProxyObject *self)
2224
+ {
2225
+ if (!self->wrapped)
2226
+ {
2227
+ if (raise_uninitialized_wrapper_error(self) == -1)
2228
+ return NULL;
2229
+ }
2230
+
2231
+ return PyObject_GetAttrString(self->wrapped, "__class__");
2232
+ }
2233
+
2234
+ /* ------------------------------------------------------------------------- */
2235
+
2236
+ static int WraptObjectProxy_set_class(WraptObjectProxyObject *self,
2237
+ PyObject *value)
2238
+ {
2239
+ if (!self->wrapped)
2240
+ {
2241
+ if (raise_uninitialized_wrapper_error(self) == -1)
2242
+ return -1;
2243
+ }
2244
+
2245
+ return PyObject_SetAttrString(self->wrapped, "__class__", value);
2246
+ }
2247
+
2248
+ /* ------------------------------------------------------------------------- */
2249
+
2250
+ static PyObject *
2251
+ WraptObjectProxy_get_annotations(WraptObjectProxyObject *self)
2252
+ {
2253
+ if (!self->wrapped)
2254
+ {
2255
+ if (raise_uninitialized_wrapper_error(self) == -1)
2256
+ return NULL;
2257
+ }
2258
+
2259
+ return PyObject_GetAttrString(self->wrapped, "__annotations__");
2260
+ }
2261
+
2262
+ /* ------------------------------------------------------------------------- */
2263
+
2264
+ static int WraptObjectProxy_set_annotations(WraptObjectProxyObject *self,
2265
+ PyObject *value)
2266
+ {
2267
+ if (!self->wrapped)
2268
+ {
2269
+ if (raise_uninitialized_wrapper_error(self) == -1)
2270
+ return -1;
2271
+ }
2272
+
2273
+ return PyObject_SetAttrString(self->wrapped, "__annotations__", value);
2274
+ }
2275
+
2276
+ /* ------------------------------------------------------------------------- */
2277
+
2278
+ static PyObject *WraptObjectProxy_get_wrapped(WraptObjectProxyObject *self)
2279
+ {
2280
+ if (!self->wrapped)
2281
+ {
2282
+ if (raise_uninitialized_wrapper_error(self) == -1)
2283
+ return NULL;
2284
+ }
2285
+
2286
+ Py_INCREF(self->wrapped);
2287
+ return self->wrapped;
2288
+ }
2289
+
2290
+ /* ------------------------------------------------------------------------- */
2291
+
2292
+ static PyObject *WraptObjectProxy_get_object_proxy(WraptObjectProxyObject *self)
2293
+ {
2294
+ Py_INCREF(&WraptObjectProxy_Type);
2295
+ return (PyObject *)&WraptObjectProxy_Type;
2296
+ }
2297
+
2298
+ /* ------------------------------------------------------------------------- */
2299
+
2300
+ static int WraptObjectProxy_set_wrapped(WraptObjectProxyObject *self,
2301
+ PyObject *value)
2302
+ {
2303
+ static PyObject *fixups_str = NULL;
2304
+
2305
+ PyObject *fixups = NULL;
2306
+
2307
+ if (!value)
2308
+ {
2309
+ PyErr_SetString(PyExc_TypeError, "__wrapped__ must be an object");
2310
+ return -1;
2311
+ }
2312
+
2313
+ Py_INCREF(value);
2314
+ Py_XDECREF(self->wrapped);
2315
+
2316
+ self->wrapped = value;
2317
+
2318
+ if (!fixups_str)
2319
+ {
2320
+ fixups_str = PyUnicode_InternFromString("__wrapped_setattr_fixups__");
2321
+ }
2322
+
2323
+ fixups = PyObject_GetAttr((PyObject *)self, fixups_str);
2324
+
2325
+ if (fixups)
2326
+ {
2327
+ PyObject *result = NULL;
2328
+
2329
+ result = PyObject_CallObject(fixups, NULL);
2330
+ Py_DECREF(fixups);
2331
+
2332
+ if (!result)
2333
+ return -1;
2334
+
2335
+ Py_DECREF(result);
2336
+ }
2337
+ else
2338
+ PyErr_Clear();
2339
+
2340
+ return 0;
2341
+ }
2342
+
2343
+ /* ------------------------------------------------------------------------- */
2344
+
2345
+ static PyObject *WraptObjectProxy_getattro(WraptObjectProxyObject *self,
2346
+ PyObject *name)
2347
+ {
2348
+ PyObject *object = NULL;
2349
+ PyObject *result = NULL;
2350
+
2351
+ static PyObject *getattr_str = NULL;
2352
+
2353
+ object = PyObject_GenericGetAttr((PyObject *)self, name);
2354
+
2355
+ if (object)
2356
+ return object;
2357
+
2358
+ if (!PyErr_ExceptionMatches(PyExc_AttributeError))
2359
+ return NULL;
2360
+
2361
+ PyErr_Clear();
2362
+
2363
+ if (!getattr_str)
2364
+ {
2365
+ getattr_str = PyUnicode_InternFromString("__getattr__");
2366
+ }
2367
+
2368
+ object = PyObject_GenericGetAttr((PyObject *)self, getattr_str);
2369
+
2370
+ if (!object)
2371
+ return NULL;
2372
+
2373
+ result = PyObject_CallFunctionObjArgs(object, name, NULL);
2374
+
2375
+ Py_DECREF(object);
2376
+
2377
+ return result;
2378
+ }
2379
+
2380
+ /* ------------------------------------------------------------------------- */
2381
+
2382
+ static PyObject *WraptObjectProxy_getattr(WraptObjectProxyObject *self,
2383
+ PyObject *args)
2384
+ {
2385
+ PyObject *name = NULL;
2386
+
2387
+ if (!PyArg_ParseTuple(args, "U:__getattr__", &name))
2388
+ return NULL;
2389
+
2390
+ if (!self->wrapped)
2391
+ {
2392
+ if (raise_uninitialized_wrapper_error(self) == -1)
2393
+ return NULL;
2394
+ }
2395
+
2396
+ return PyObject_GetAttr(self->wrapped, name);
2397
+ }
2398
+
2399
+ /* ------------------------------------------------------------------------- */
2400
+
2401
+ static int WraptObjectProxy_setattro(WraptObjectProxyObject *self,
2402
+ PyObject *name, PyObject *value)
2403
+ {
2404
+ static PyObject *self_str = NULL;
2405
+ static PyObject *startswith_str = NULL;
2406
+
2407
+ PyObject *match = NULL;
2408
+
2409
+ if (!startswith_str)
2410
+ {
2411
+ startswith_str = PyUnicode_InternFromString("startswith");
2412
+ }
2413
+
2414
+ if (!self_str)
2415
+ {
2416
+ self_str = PyUnicode_InternFromString("_self_");
2417
+ }
2418
+
2419
+ match = PyObject_CallMethodObjArgs(name, startswith_str, self_str, NULL);
2420
+
2421
+ if (match == Py_True)
2422
+ {
2423
+ Py_DECREF(match);
2424
+
2425
+ return PyObject_GenericSetAttr((PyObject *)self, name, value);
2426
+ }
2427
+ else if (!match)
2428
+ PyErr_Clear();
2429
+
2430
+ Py_XDECREF(match);
2431
+
2432
+ if (PyObject_HasAttr((PyObject *)Py_TYPE(self), name))
2433
+ return PyObject_GenericSetAttr((PyObject *)self, name, value);
2434
+
2435
+ if (!self->wrapped)
2436
+ {
2437
+ if (raise_uninitialized_wrapper_error(self) == -1)
2438
+ return -1;
2439
+ }
2440
+
2441
+ return PyObject_SetAttr(self->wrapped, name, value);
2442
+ }
2443
+
2444
+ /* ------------------------------------------------------------------------- */
2445
+
2446
+ static PyObject *WraptObjectProxy_richcompare(WraptObjectProxyObject *self,
2447
+ PyObject *other, int opcode)
2448
+ {
2449
+ if (!self->wrapped)
2450
+ {
2451
+ if (raise_uninitialized_wrapper_error(self) == -1)
2452
+ return NULL;
2453
+ }
2454
+
2455
+ return PyObject_RichCompare(self->wrapped, other, opcode);
2456
+ }
2457
+
2458
+ /* ------------------------------------------------------------------------- */
2459
+
2460
+ static PyObject *WraptObjectProxy_iter(WraptObjectProxyObject *self)
2461
+ {
2462
+ if (!self->wrapped)
2463
+ {
2464
+ if (raise_uninitialized_wrapper_error(self) == -1)
2465
+ return NULL;
2466
+ }
2467
+
2468
+ return PyObject_GetIter(self->wrapped);
2469
+ }
2470
+
2471
+ /* ------------------------------------------------------------------------- */
2472
+
2473
+ static PyNumberMethods WraptObjectProxy_as_number = {
2474
+ (binaryfunc)WraptObjectProxy_add, /*nb_add*/
2475
+ (binaryfunc)WraptObjectProxy_subtract, /*nb_subtract*/
2476
+ (binaryfunc)WraptObjectProxy_multiply, /*nb_multiply*/
2477
+ (binaryfunc)WraptObjectProxy_remainder, /*nb_remainder*/
2478
+ (binaryfunc)WraptObjectProxy_divmod, /*nb_divmod*/
2479
+ (ternaryfunc)WraptObjectProxy_power, /*nb_power*/
2480
+ (unaryfunc)WraptObjectProxy_negative, /*nb_negative*/
2481
+ (unaryfunc)WraptObjectProxy_positive, /*nb_positive*/
2482
+ (unaryfunc)WraptObjectProxy_absolute, /*nb_absolute*/
2483
+ (inquiry)WraptObjectProxy_bool, /*nb_nonzero/nb_bool*/
2484
+ (unaryfunc)WraptObjectProxy_invert, /*nb_invert*/
2485
+ (binaryfunc)WraptObjectProxy_lshift, /*nb_lshift*/
2486
+ (binaryfunc)WraptObjectProxy_rshift, /*nb_rshift*/
2487
+ (binaryfunc)WraptObjectProxy_and, /*nb_and*/
2488
+ (binaryfunc)WraptObjectProxy_xor, /*nb_xor*/
2489
+ (binaryfunc)WraptObjectProxy_or, /*nb_or*/
2490
+ (unaryfunc)WraptObjectProxy_long, /*nb_int*/
2491
+ 0, /*nb_long/nb_reserved*/
2492
+ (unaryfunc)WraptObjectProxy_float, /*nb_float*/
2493
+ (binaryfunc)WraptObjectProxy_inplace_add, /*nb_inplace_add*/
2494
+ (binaryfunc)WraptObjectProxy_inplace_subtract, /*nb_inplace_subtract*/
2495
+ (binaryfunc)WraptObjectProxy_inplace_multiply, /*nb_inplace_multiply*/
2496
+ (binaryfunc)WraptObjectProxy_inplace_remainder, /*nb_inplace_remainder*/
2497
+ (ternaryfunc)WraptObjectProxy_inplace_power, /*nb_inplace_power*/
2498
+ (binaryfunc)WraptObjectProxy_inplace_lshift, /*nb_inplace_lshift*/
2499
+ (binaryfunc)WraptObjectProxy_inplace_rshift, /*nb_inplace_rshift*/
2500
+ (binaryfunc)WraptObjectProxy_inplace_and, /*nb_inplace_and*/
2501
+ (binaryfunc)WraptObjectProxy_inplace_xor, /*nb_inplace_xor*/
2502
+ (binaryfunc)WraptObjectProxy_inplace_or, /*nb_inplace_or*/
2503
+ (binaryfunc)WraptObjectProxy_floor_divide, /*nb_floor_divide*/
2504
+ (binaryfunc)WraptObjectProxy_true_divide, /*nb_true_divide*/
2505
+ (binaryfunc)
2506
+ WraptObjectProxy_inplace_floor_divide, /*nb_inplace_floor_divide*/
2507
+ (binaryfunc)WraptObjectProxy_inplace_true_divide, /*nb_inplace_true_divide*/
2508
+ (unaryfunc)WraptObjectProxy_index, /*nb_index*/
2509
+ (binaryfunc)WraptObjectProxy_matrix_multiply, /*nb_matrix_multiply*/
2510
+ (binaryfunc)WraptObjectProxy_inplace_matrix_multiply, /*nb_inplace_matrix_multiply*/
2511
+ };
2512
+
2513
+ static PySequenceMethods WraptObjectProxy_as_sequence = {
2514
+ (lenfunc)WraptObjectProxy_length, /*sq_length*/
2515
+ 0, /*sq_concat*/
2516
+ 0, /*sq_repeat*/
2517
+ 0, /*sq_item*/
2518
+ 0, /*sq_slice*/
2519
+ 0, /*sq_ass_item*/
2520
+ 0, /*sq_ass_slice*/
2521
+ (objobjproc)WraptObjectProxy_contains, /* sq_contains */
2522
+ };
2523
+
2524
+ static PyMappingMethods WraptObjectProxy_as_mapping = {
2525
+ (lenfunc)WraptObjectProxy_length, /*mp_length*/
2526
+ (binaryfunc)WraptObjectProxy_getitem, /*mp_subscript*/
2527
+ (objobjargproc)WraptObjectProxy_setitem, /*mp_ass_subscript*/
2528
+ };
2529
+
2530
+ static PyMethodDef WraptObjectProxy_methods[] = {
2531
+ {"__self_setattr__", (PyCFunction)WraptObjectProxy_self_setattr,
2532
+ METH_VARARGS, 0},
2533
+ {"__dir__", (PyCFunction)WraptObjectProxy_dir, METH_NOARGS, 0},
2534
+ {"__enter__", (PyCFunction)WraptObjectProxy_enter,
2535
+ METH_VARARGS | METH_KEYWORDS, 0},
2536
+ {"__exit__", (PyCFunction)WraptObjectProxy_exit,
2537
+ METH_VARARGS | METH_KEYWORDS, 0},
2538
+ {"__aenter__", (PyCFunction)WraptObjectProxy_aenter,
2539
+ METH_VARARGS | METH_KEYWORDS, 0},
2540
+ {"__aexit__", (PyCFunction)WraptObjectProxy_aexit,
2541
+ METH_VARARGS | METH_KEYWORDS, 0},
2542
+ {"__copy__", (PyCFunction)WraptObjectProxy_copy, METH_NOARGS, 0},
2543
+ {"__deepcopy__", (PyCFunction)WraptObjectProxy_deepcopy,
2544
+ METH_VARARGS | METH_KEYWORDS, 0},
2545
+ {"__reduce__", (PyCFunction)WraptObjectProxy_reduce, METH_NOARGS, 0},
2546
+ {"__reduce_ex__", (PyCFunction)WraptObjectProxy_reduce_ex,
2547
+ METH_VARARGS | METH_KEYWORDS, 0},
2548
+ {"__getattr__", (PyCFunction)WraptObjectProxy_getattr, METH_VARARGS, 0},
2549
+ {"__bytes__", (PyCFunction)WraptObjectProxy_bytes, METH_NOARGS, 0},
2550
+ {"__format__", (PyCFunction)WraptObjectProxy_format, METH_VARARGS, 0},
2551
+ {"__reversed__", (PyCFunction)WraptObjectProxy_reversed, METH_NOARGS, 0},
2552
+ {"__round__", (PyCFunction)WraptObjectProxy_round,
2553
+ METH_VARARGS | METH_KEYWORDS, 0},
2554
+ {"__complex__", (PyCFunction)WraptObjectProxy_complex, METH_NOARGS, 0},
2555
+ {"__mro_entries__", (PyCFunction)WraptObjectProxy_mro_entries,
2556
+ METH_VARARGS | METH_KEYWORDS, 0},
2557
+ {NULL, NULL},
2558
+ };
2559
+
2560
+ static PyGetSetDef WraptObjectProxy_getset[] = {
2561
+ {"__name__", (getter)WraptObjectProxy_get_name,
2562
+ (setter)WraptObjectProxy_set_name, 0},
2563
+ {"__qualname__", (getter)WraptObjectProxy_get_qualname,
2564
+ (setter)WraptObjectProxy_set_qualname, 0},
2565
+ {"__module__", (getter)WraptObjectProxy_get_module,
2566
+ (setter)WraptObjectProxy_set_module, 0},
2567
+ {"__doc__", (getter)WraptObjectProxy_get_doc,
2568
+ (setter)WraptObjectProxy_set_doc, 0},
2569
+ {"__class__", (getter)WraptObjectProxy_get_class,
2570
+ (setter)WraptObjectProxy_set_class, 0},
2571
+ {"__annotations__", (getter)WraptObjectProxy_get_annotations,
2572
+ (setter)WraptObjectProxy_set_annotations, 0},
2573
+ {"__wrapped__", (getter)WraptObjectProxy_get_wrapped,
2574
+ (setter)WraptObjectProxy_set_wrapped, 0},
2575
+ {"__object_proxy__", (getter)WraptObjectProxy_get_object_proxy, 0, 0},
2576
+ {NULL},
2577
+ };
2578
+
2579
+ PyTypeObject WraptObjectProxy_Type = {
2580
+ PyVarObject_HEAD_INIT(NULL, 0) "ObjectProxy", /*tp_name*/
2581
+ sizeof(WraptObjectProxyObject), /*tp_basicsize*/
2582
+ 0, /*tp_itemsize*/
2583
+ /* methods */
2584
+ (destructor)WraptObjectProxy_dealloc, /*tp_dealloc*/
2585
+ 0, /*tp_print*/
2586
+ 0, /*tp_getattr*/
2587
+ 0, /*tp_setattr*/
2588
+ 0, /*tp_as_async*/
2589
+ (unaryfunc)WraptObjectProxy_repr, /*tp_repr*/
2590
+ &WraptObjectProxy_as_number, /*tp_as_number*/
2591
+ &WraptObjectProxy_as_sequence, /*tp_as_sequence*/
2592
+ &WraptObjectProxy_as_mapping, /*tp_as_mapping*/
2593
+ (hashfunc)WraptObjectProxy_hash, /*tp_hash*/
2594
+ 0, /*tp_call*/
2595
+ (unaryfunc)WraptObjectProxy_str, /*tp_str*/
2596
+ (getattrofunc)WraptObjectProxy_getattro, /*tp_getattro*/
2597
+ (setattrofunc)WraptObjectProxy_setattro, /*tp_setattro*/
2598
+ 0, /*tp_as_buffer*/
2599
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2600
+ 0, /*tp_doc*/
2601
+ (traverseproc)WraptObjectProxy_traverse, /*tp_traverse*/
2602
+ (inquiry)WraptObjectProxy_clear, /*tp_clear*/
2603
+ (richcmpfunc)WraptObjectProxy_richcompare, /*tp_richcompare*/
2604
+ offsetof(WraptObjectProxyObject, weakreflist), /*tp_weaklistoffset*/
2605
+ 0, /* (getiterfunc)WraptObjectProxy_iter, */ /*tp_iter*/
2606
+ 0, /*tp_iternext*/
2607
+ WraptObjectProxy_methods, /*tp_methods*/
2608
+ 0, /*tp_members*/
2609
+ WraptObjectProxy_getset, /*tp_getset*/
2610
+ 0, /*tp_base*/
2611
+ 0, /*tp_dict*/
2612
+ 0, /*tp_descr_get*/
2613
+ 0, /*tp_descr_set*/
2614
+ offsetof(WraptObjectProxyObject, dict), /*tp_dictoffset*/
2615
+ (initproc)WraptObjectProxy_init, /*tp_init*/
2616
+ PyType_GenericAlloc, /*tp_alloc*/
2617
+ WraptObjectProxy_new, /*tp_new*/
2618
+ PyObject_GC_Del, /*tp_free*/
2619
+ 0, /*tp_is_gc*/
2620
+ };
2621
+
2622
+ /* ------------------------------------------------------------------------- */
2623
+
2624
+ static PyObject *WraptCallableObjectProxy_call(WraptObjectProxyObject *self,
2625
+ PyObject *args, PyObject *kwds)
2626
+ {
2627
+ if (!self->wrapped)
2628
+ {
2629
+ if (raise_uninitialized_wrapper_error(self) == -1)
2630
+ return NULL;
2631
+ }
2632
+
2633
+ return PyObject_Call(self->wrapped, args, kwds);
2634
+ }
2635
+
2636
+ /* ------------------------------------------------------------------------- */;
2637
+
2638
+ static PyGetSetDef WraptCallableObjectProxy_getset[] = {
2639
+ {"__module__", (getter)WraptObjectProxy_get_module,
2640
+ (setter)WraptObjectProxy_set_module, 0},
2641
+ {"__doc__", (getter)WraptObjectProxy_get_doc,
2642
+ (setter)WraptObjectProxy_set_doc, 0},
2643
+ {NULL},
2644
+ };
2645
+
2646
+ PyTypeObject WraptCallableObjectProxy_Type = {
2647
+ PyVarObject_HEAD_INIT(NULL, 0) "CallableObjectProxy", /*tp_name*/
2648
+ sizeof(WraptObjectProxyObject), /*tp_basicsize*/
2649
+ 0, /*tp_itemsize*/
2650
+ /* methods */
2651
+ 0, /*tp_dealloc*/
2652
+ 0, /*tp_print*/
2653
+ 0, /*tp_getattr*/
2654
+ 0, /*tp_setattr*/
2655
+ 0, /*tp_compare*/
2656
+ 0, /*tp_repr*/
2657
+ 0, /*tp_as_number*/
2658
+ 0, /*tp_as_sequence*/
2659
+ 0, /*tp_as_mapping*/
2660
+ 0, /*tp_hash*/
2661
+ (ternaryfunc)WraptCallableObjectProxy_call, /*tp_call*/
2662
+ 0, /*tp_str*/
2663
+ 0, /*tp_getattro*/
2664
+ 0, /*tp_setattro*/
2665
+ 0, /*tp_as_buffer*/
2666
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
2667
+ 0, /*tp_doc*/
2668
+ 0, /*tp_traverse*/
2669
+ 0, /*tp_clear*/
2670
+ 0, /*tp_richcompare*/
2671
+ offsetof(WraptObjectProxyObject, weakreflist), /*tp_weaklistoffset*/
2672
+ 0, /*tp_iter*/
2673
+ 0, /*tp_iternext*/
2674
+ 0, /*tp_methods*/
2675
+ 0, /*tp_members*/
2676
+ WraptCallableObjectProxy_getset, /*tp_getset*/
2677
+ 0, /*tp_base*/
2678
+ 0, /*tp_dict*/
2679
+ 0, /*tp_descr_get*/
2680
+ 0, /*tp_descr_set*/
2681
+ 0, /*tp_dictoffset*/
2682
+ (initproc)WraptObjectProxy_init, /*tp_init*/
2683
+ 0, /*tp_alloc*/
2684
+ 0, /*tp_new*/
2685
+ 0, /*tp_free*/
2686
+ 0, /*tp_is_gc*/
2687
+ };
2688
+
2689
+ /* ------------------------------------------------------------------------- */
2690
+
2691
+ static PyObject *WraptPartialCallableObjectProxy_new(PyTypeObject *type,
2692
+ PyObject *args,
2693
+ PyObject *kwds)
2694
+ {
2695
+ WraptPartialCallableObjectProxyObject *self;
2696
+
2697
+ self = (WraptPartialCallableObjectProxyObject *)WraptObjectProxy_new(
2698
+ type, args, kwds);
2699
+
2700
+ if (!self)
2701
+ return NULL;
2702
+
2703
+ self->args = NULL;
2704
+ self->kwargs = NULL;
2705
+
2706
+ return (PyObject *)self;
2707
+ }
2708
+
2709
+ /* ------------------------------------------------------------------------- */
2710
+
2711
+ static int WraptPartialCallableObjectProxy_raw_init(
2712
+ WraptPartialCallableObjectProxyObject *self, PyObject *wrapped,
2713
+ PyObject *args, PyObject *kwargs)
2714
+ {
2715
+ int result = 0;
2716
+
2717
+ result = WraptObjectProxy_raw_init((WraptObjectProxyObject *)self, wrapped);
2718
+
2719
+ if (result == 0)
2720
+ {
2721
+ Py_INCREF(args);
2722
+ Py_XDECREF(self->args);
2723
+ self->args = args;
2724
+
2725
+ Py_XINCREF(kwargs);
2726
+ Py_XDECREF(self->kwargs);
2727
+ self->kwargs = kwargs;
2728
+ }
2729
+
2730
+ return result;
2731
+ }
2732
+
2733
+ /* ------------------------------------------------------------------------- */
2734
+
2735
+ static int WraptPartialCallableObjectProxy_init(
2736
+ WraptPartialCallableObjectProxyObject *self, PyObject *args,
2737
+ PyObject *kwds)
2738
+ {
2739
+ PyObject *wrapped = NULL;
2740
+ PyObject *fnargs = NULL;
2741
+
2742
+ int result = 0;
2743
+
2744
+ if (!PyObject_Length(args))
2745
+ {
2746
+ PyErr_SetString(PyExc_TypeError, "__init__ of partial needs an argument");
2747
+ return -1;
2748
+ }
2749
+
2750
+ if (PyObject_Length(args) < 1)
2751
+ {
2752
+ PyErr_SetString(PyExc_TypeError,
2753
+ "partial type takes at least one argument");
2754
+ return -1;
2755
+ }
2756
+
2757
+ wrapped = PyTuple_GetItem(args, 0);
2758
+
2759
+ if (!PyCallable_Check(wrapped))
2760
+ {
2761
+ PyErr_SetString(PyExc_TypeError, "the first argument must be callable");
2762
+ return -1;
2763
+ }
2764
+
2765
+ fnargs = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
2766
+
2767
+ if (!fnargs)
2768
+ return -1;
2769
+
2770
+ result =
2771
+ WraptPartialCallableObjectProxy_raw_init(self, wrapped, fnargs, kwds);
2772
+
2773
+ Py_DECREF(fnargs);
2774
+
2775
+ return result;
2776
+ }
2777
+
2778
+ /* ------------------------------------------------------------------------- */
2779
+
2780
+ static int WraptPartialCallableObjectProxy_traverse(
2781
+ WraptPartialCallableObjectProxyObject *self, visitproc visit, void *arg)
2782
+ {
2783
+ WraptObjectProxy_traverse((WraptObjectProxyObject *)self, visit, arg);
2784
+
2785
+ Py_VISIT(self->args);
2786
+ Py_VISIT(self->kwargs);
2787
+
2788
+ return 0;
2789
+ }
2790
+
2791
+ /* ------------------------------------------------------------------------- */
2792
+
2793
+ static int WraptPartialCallableObjectProxy_clear(
2794
+ WraptPartialCallableObjectProxyObject *self)
2795
+ {
2796
+ WraptObjectProxy_clear((WraptObjectProxyObject *)self);
2797
+
2798
+ Py_CLEAR(self->args);
2799
+ Py_CLEAR(self->kwargs);
2800
+
2801
+ return 0;
2802
+ }
2803
+
2804
+ /* ------------------------------------------------------------------------- */
2805
+
2806
+ static void WraptPartialCallableObjectProxy_dealloc(
2807
+ WraptPartialCallableObjectProxyObject *self)
2808
+ {
2809
+ PyObject_GC_UnTrack(self);
2810
+
2811
+ WraptPartialCallableObjectProxy_clear(self);
2812
+
2813
+ WraptObjectProxy_dealloc((WraptObjectProxyObject *)self);
2814
+ }
2815
+
2816
+ /* ------------------------------------------------------------------------- */
2817
+
2818
+ static PyObject *WraptPartialCallableObjectProxy_call(
2819
+ WraptPartialCallableObjectProxyObject *self, PyObject *args,
2820
+ PyObject *kwds)
2821
+ {
2822
+ PyObject *fnargs = NULL;
2823
+ PyObject *fnkwargs = NULL;
2824
+
2825
+ PyObject *result = NULL;
2826
+
2827
+ long i;
2828
+ long offset;
2829
+
2830
+ if (!self->object_proxy.wrapped)
2831
+ {
2832
+ if (raise_uninitialized_wrapper_error(&self->object_proxy) == -1)
2833
+ return NULL;
2834
+ }
2835
+
2836
+ fnargs = PyTuple_New(PyTuple_Size(self->args) + PyTuple_Size(args));
2837
+
2838
+ for (i = 0; i < PyTuple_Size(self->args); i++)
2839
+ {
2840
+ PyObject *item;
2841
+ item = PyTuple_GetItem(self->args, i);
2842
+ Py_INCREF(item);
2843
+ PyTuple_SetItem(fnargs, i, item);
2844
+ }
2845
+
2846
+ offset = PyTuple_Size(self->args);
2847
+
2848
+ for (i = 0; i < PyTuple_Size(args); i++)
2849
+ {
2850
+ PyObject *item;
2851
+ item = PyTuple_GetItem(args, i);
2852
+ Py_INCREF(item);
2853
+ PyTuple_SetItem(fnargs, offset + i, item);
2854
+ }
2855
+
2856
+ fnkwargs = PyDict_New();
2857
+
2858
+ if (self->kwargs && PyDict_Update(fnkwargs, self->kwargs) == -1)
2859
+ {
2860
+ Py_DECREF(fnargs);
2861
+ Py_DECREF(fnkwargs);
2862
+ return NULL;
2863
+ }
2864
+
2865
+ if (kwds && PyDict_Update(fnkwargs, kwds) == -1)
2866
+ {
2867
+ Py_DECREF(fnargs);
2868
+ Py_DECREF(fnkwargs);
2869
+ return NULL;
2870
+ }
2871
+
2872
+ result = PyObject_Call(self->object_proxy.wrapped, fnargs, fnkwargs);
2873
+
2874
+ Py_DECREF(fnargs);
2875
+ Py_DECREF(fnkwargs);
2876
+
2877
+ return result;
2878
+ }
2879
+
2880
+ /* ------------------------------------------------------------------------- */;
2881
+
2882
+ static PyGetSetDef WraptPartialCallableObjectProxy_getset[] = {
2883
+ {"__module__", (getter)WraptObjectProxy_get_module,
2884
+ (setter)WraptObjectProxy_set_module, 0},
2885
+ {"__doc__", (getter)WraptObjectProxy_get_doc,
2886
+ (setter)WraptObjectProxy_set_doc, 0},
2887
+ {NULL},
2888
+ };
2889
+
2890
+ PyTypeObject WraptPartialCallableObjectProxy_Type = {
2891
+ PyVarObject_HEAD_INIT(NULL, 0) "PartialCallableObjectProxy", /*tp_name*/
2892
+ sizeof(WraptPartialCallableObjectProxyObject), /*tp_basicsize*/
2893
+ 0, /*tp_itemsize*/
2894
+ /* methods */
2895
+ (destructor)WraptPartialCallableObjectProxy_dealloc, /*tp_dealloc*/
2896
+ 0, /*tp_print*/
2897
+ 0, /*tp_getattr*/
2898
+ 0, /*tp_setattr*/
2899
+ 0, /*tp_compare*/
2900
+ 0, /*tp_repr*/
2901
+ 0, /*tp_as_number*/
2902
+ 0, /*tp_as_sequence*/
2903
+ 0, /*tp_as_mapping*/
2904
+ 0, /*tp_hash*/
2905
+ (ternaryfunc)WraptPartialCallableObjectProxy_call, /*tp_call*/
2906
+ 0, /*tp_str*/
2907
+ 0, /*tp_getattro*/
2908
+ 0, /*tp_setattro*/
2909
+ 0, /*tp_as_buffer*/
2910
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
2911
+ 0, /*tp_doc*/
2912
+ (traverseproc)WraptPartialCallableObjectProxy_traverse, /*tp_traverse*/
2913
+ (inquiry)WraptPartialCallableObjectProxy_clear, /*tp_clear*/
2914
+ 0, /*tp_richcompare*/
2915
+ offsetof(WraptObjectProxyObject, weakreflist), /*tp_weaklistoffset*/
2916
+ 0, /*tp_iter*/
2917
+ 0, /*tp_iternext*/
2918
+ 0, /*tp_methods*/
2919
+ 0, /*tp_members*/
2920
+ WraptPartialCallableObjectProxy_getset, /*tp_getset*/
2921
+ 0, /*tp_base*/
2922
+ 0, /*tp_dict*/
2923
+ 0, /*tp_descr_get*/
2924
+ 0, /*tp_descr_set*/
2925
+ 0, /*tp_dictoffset*/
2926
+ (initproc)WraptPartialCallableObjectProxy_init, /*tp_init*/
2927
+ 0, /*tp_alloc*/
2928
+ WraptPartialCallableObjectProxy_new, /*tp_new*/
2929
+ 0, /*tp_free*/
2930
+ 0, /*tp_is_gc*/
2931
+ };
2932
+
2933
+ /* ------------------------------------------------------------------------- */
2934
+
2935
+ static PyObject *WraptFunctionWrapperBase_new(PyTypeObject *type,
2936
+ PyObject *args, PyObject *kwds)
2937
+ {
2938
+ WraptFunctionWrapperObject *self;
2939
+
2940
+ self = (WraptFunctionWrapperObject *)WraptObjectProxy_new(type, args, kwds);
2941
+
2942
+ if (!self)
2943
+ return NULL;
2944
+
2945
+ self->instance = NULL;
2946
+ self->wrapper = NULL;
2947
+ self->enabled = NULL;
2948
+ self->binding = NULL;
2949
+ self->parent = NULL;
2950
+ self->owner = NULL;
2951
+
2952
+ return (PyObject *)self;
2953
+ }
2954
+
2955
+ /* ------------------------------------------------------------------------- */
2956
+
2957
+ static int WraptFunctionWrapperBase_raw_init(
2958
+ WraptFunctionWrapperObject *self, PyObject *wrapped, PyObject *instance,
2959
+ PyObject *wrapper, PyObject *enabled, PyObject *binding, PyObject *parent,
2960
+ PyObject *owner)
2961
+ {
2962
+ int result = 0;
2963
+
2964
+ result = WraptObjectProxy_raw_init((WraptObjectProxyObject *)self, wrapped);
2965
+
2966
+ if (result == 0)
2967
+ {
2968
+ Py_INCREF(instance);
2969
+ Py_XDECREF(self->instance);
2970
+ self->instance = instance;
2971
+
2972
+ Py_INCREF(wrapper);
2973
+ Py_XDECREF(self->wrapper);
2974
+ self->wrapper = wrapper;
2975
+
2976
+ Py_INCREF(enabled);
2977
+ Py_XDECREF(self->enabled);
2978
+ self->enabled = enabled;
2979
+
2980
+ Py_INCREF(binding);
2981
+ Py_XDECREF(self->binding);
2982
+ self->binding = binding;
2983
+
2984
+ Py_INCREF(parent);
2985
+ Py_XDECREF(self->parent);
2986
+ self->parent = parent;
2987
+
2988
+ Py_INCREF(owner);
2989
+ Py_XDECREF(self->owner);
2990
+ self->owner = owner;
2991
+ }
2992
+
2993
+ return result;
2994
+ }
2995
+
2996
+ /* ------------------------------------------------------------------------- */
2997
+
2998
+ static int WraptFunctionWrapperBase_init(WraptFunctionWrapperObject *self,
2999
+ PyObject *args, PyObject *kwds)
3000
+ {
3001
+ PyObject *wrapped = NULL;
3002
+ PyObject *instance = NULL;
3003
+ PyObject *wrapper = NULL;
3004
+ PyObject *enabled = Py_None;
3005
+ PyObject *binding = NULL;
3006
+ PyObject *parent = Py_None;
3007
+ PyObject *owner = Py_None;
3008
+
3009
+ static PyObject *callable_str = NULL;
3010
+
3011
+ char *const kwlist[] = {"wrapped", "instance", "wrapper", "enabled",
3012
+ "binding", "parent", "owner", NULL};
3013
+
3014
+ if (!callable_str)
3015
+ {
3016
+ callable_str = PyUnicode_InternFromString("callable");
3017
+ }
3018
+
3019
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO|OOOO:FunctionWrapperBase",
3020
+ kwlist, &wrapped, &instance, &wrapper,
3021
+ &enabled, &binding, &parent, &owner))
3022
+ {
3023
+ return -1;
3024
+ }
3025
+
3026
+ if (!binding)
3027
+ binding = callable_str;
3028
+
3029
+ return WraptFunctionWrapperBase_raw_init(self, wrapped, instance, wrapper,
3030
+ enabled, binding, parent, owner);
3031
+ }
3032
+
3033
+ /* ------------------------------------------------------------------------- */
3034
+
3035
+ static int WraptFunctionWrapperBase_traverse(WraptFunctionWrapperObject *self,
3036
+ visitproc visit, void *arg)
3037
+ {
3038
+ WraptObjectProxy_traverse((WraptObjectProxyObject *)self, visit, arg);
3039
+
3040
+ Py_VISIT(self->instance);
3041
+ Py_VISIT(self->wrapper);
3042
+ Py_VISIT(self->enabled);
3043
+ Py_VISIT(self->binding);
3044
+ Py_VISIT(self->parent);
3045
+ Py_VISIT(self->owner);
3046
+
3047
+ return 0;
3048
+ }
3049
+
3050
+ /* ------------------------------------------------------------------------- */
3051
+
3052
+ static int WraptFunctionWrapperBase_clear(WraptFunctionWrapperObject *self)
3053
+ {
3054
+ WraptObjectProxy_clear((WraptObjectProxyObject *)self);
3055
+
3056
+ Py_CLEAR(self->instance);
3057
+ Py_CLEAR(self->wrapper);
3058
+ Py_CLEAR(self->enabled);
3059
+ Py_CLEAR(self->binding);
3060
+ Py_CLEAR(self->parent);
3061
+ Py_CLEAR(self->owner);
3062
+
3063
+ return 0;
3064
+ }
3065
+
3066
+ /* ------------------------------------------------------------------------- */
3067
+
3068
+ static void WraptFunctionWrapperBase_dealloc(WraptFunctionWrapperObject *self)
3069
+ {
3070
+ PyObject_GC_UnTrack(self);
3071
+
3072
+ WraptFunctionWrapperBase_clear(self);
3073
+
3074
+ WraptObjectProxy_dealloc((WraptObjectProxyObject *)self);
3075
+ }
3076
+
3077
+ /* ------------------------------------------------------------------------- */
3078
+
3079
+ static PyObject *WraptFunctionWrapperBase_call(WraptFunctionWrapperObject *self,
3080
+ PyObject *args, PyObject *kwds)
3081
+ {
3082
+ PyObject *param_kwds = NULL;
3083
+
3084
+ PyObject *result = NULL;
3085
+
3086
+ static PyObject *function_str = NULL;
3087
+ static PyObject *callable_str = NULL;
3088
+ static PyObject *classmethod_str = NULL;
3089
+ static PyObject *instancemethod_str = NULL;
3090
+
3091
+ if (!function_str)
3092
+ {
3093
+ function_str = PyUnicode_InternFromString("function");
3094
+ callable_str = PyUnicode_InternFromString("callable");
3095
+ classmethod_str = PyUnicode_InternFromString("classmethod");
3096
+ instancemethod_str = PyUnicode_InternFromString("instancemethod");
3097
+ }
3098
+
3099
+ if (self->enabled != Py_None)
3100
+ {
3101
+ if (PyCallable_Check(self->enabled))
3102
+ {
3103
+ PyObject *object = NULL;
3104
+
3105
+ object = PyObject_CallFunctionObjArgs(self->enabled, NULL);
3106
+
3107
+ if (!object)
3108
+ return NULL;
3109
+
3110
+ if (PyObject_Not(object))
3111
+ {
3112
+ Py_DECREF(object);
3113
+ return PyObject_Call(self->object_proxy.wrapped, args, kwds);
3114
+ }
3115
+
3116
+ Py_DECREF(object);
3117
+ }
3118
+ else if (PyObject_Not(self->enabled))
3119
+ {
3120
+ return PyObject_Call(self->object_proxy.wrapped, args, kwds);
3121
+ }
3122
+ }
3123
+
3124
+ if (!kwds)
3125
+ {
3126
+ param_kwds = PyDict_New();
3127
+ kwds = param_kwds;
3128
+ }
3129
+
3130
+ if ((self->instance == Py_None) &&
3131
+ (self->binding == function_str ||
3132
+ PyObject_RichCompareBool(self->binding, function_str, Py_EQ) == 1 ||
3133
+ self->binding == instancemethod_str ||
3134
+ PyObject_RichCompareBool(self->binding, instancemethod_str, Py_EQ) ==
3135
+ 1 ||
3136
+ self->binding == callable_str ||
3137
+ PyObject_RichCompareBool(self->binding, callable_str, Py_EQ) == 1 ||
3138
+ self->binding == classmethod_str ||
3139
+ PyObject_RichCompareBool(self->binding, classmethod_str, Py_EQ) == 1))
3140
+ {
3141
+
3142
+ PyObject *instance = NULL;
3143
+
3144
+ instance = PyObject_GetAttrString(self->object_proxy.wrapped, "__self__");
3145
+
3146
+ if (instance)
3147
+ {
3148
+ result = PyObject_CallFunctionObjArgs(self->wrapper,
3149
+ self->object_proxy.wrapped,
3150
+ instance, args, kwds, NULL);
3151
+
3152
+ Py_XDECREF(param_kwds);
3153
+
3154
+ Py_DECREF(instance);
3155
+
3156
+ return result;
3157
+ }
3158
+ else
3159
+ PyErr_Clear();
3160
+ }
3161
+
3162
+ result =
3163
+ PyObject_CallFunctionObjArgs(self->wrapper, self->object_proxy.wrapped,
3164
+ self->instance, args, kwds, NULL);
3165
+
3166
+ Py_XDECREF(param_kwds);
3167
+
3168
+ return result;
3169
+ }
3170
+
3171
+ /* ------------------------------------------------------------------------- */
3172
+
3173
+ static PyObject *
3174
+ WraptFunctionWrapperBase_descr_get(WraptFunctionWrapperObject *self,
3175
+ PyObject *obj, PyObject *type)
3176
+ {
3177
+ PyObject *bound_type = NULL;
3178
+ PyObject *descriptor = NULL;
3179
+ PyObject *result = NULL;
3180
+
3181
+ static PyObject *bound_type_str = NULL;
3182
+ static PyObject *function_str = NULL;
3183
+ static PyObject *callable_str = NULL;
3184
+ static PyObject *builtin_str = NULL;
3185
+ static PyObject *class_str = NULL;
3186
+ static PyObject *instancemethod_str = NULL;
3187
+
3188
+ if (!bound_type_str)
3189
+ {
3190
+ bound_type_str = PyUnicode_InternFromString("__bound_function_wrapper__");
3191
+ }
3192
+
3193
+ if (!function_str)
3194
+ {
3195
+ function_str = PyUnicode_InternFromString("function");
3196
+ callable_str = PyUnicode_InternFromString("callable");
3197
+ builtin_str = PyUnicode_InternFromString("builtin");
3198
+ class_str = PyUnicode_InternFromString("class");
3199
+ instancemethod_str = PyUnicode_InternFromString("instancemethod");
3200
+ }
3201
+
3202
+ if (self->parent == Py_None)
3203
+ {
3204
+ if (self->binding == builtin_str ||
3205
+ PyObject_RichCompareBool(self->binding, builtin_str, Py_EQ) == 1)
3206
+ {
3207
+ Py_INCREF(self);
3208
+ return (PyObject *)self;
3209
+ }
3210
+
3211
+ if (self->binding == class_str ||
3212
+ PyObject_RichCompareBool(self->binding, class_str, Py_EQ) == 1)
3213
+ {
3214
+ Py_INCREF(self);
3215
+ return (PyObject *)self;
3216
+ }
3217
+
3218
+ if (Py_TYPE(self->object_proxy.wrapped)->tp_descr_get == NULL)
3219
+ {
3220
+ Py_INCREF(self);
3221
+ return (PyObject *)self;
3222
+ }
3223
+
3224
+ descriptor = (Py_TYPE(self->object_proxy.wrapped)->tp_descr_get)(
3225
+ self->object_proxy.wrapped, obj, type);
3226
+
3227
+ if (!descriptor)
3228
+ return NULL;
3229
+
3230
+ if (Py_TYPE(self) != &WraptFunctionWrapper_Type)
3231
+ {
3232
+ bound_type = PyObject_GenericGetAttr((PyObject *)self, bound_type_str);
3233
+
3234
+ if (!bound_type)
3235
+ PyErr_Clear();
3236
+ }
3237
+
3238
+ if (obj == NULL)
3239
+ obj = Py_None;
3240
+
3241
+ result = PyObject_CallFunctionObjArgs(
3242
+ bound_type ? bound_type : (PyObject *)&WraptBoundFunctionWrapper_Type,
3243
+ descriptor, obj, self->wrapper, self->enabled, self->binding, self,
3244
+ type, NULL);
3245
+
3246
+ Py_XDECREF(bound_type);
3247
+ Py_DECREF(descriptor);
3248
+
3249
+ return result;
3250
+ }
3251
+
3252
+ if (self->instance == Py_None &&
3253
+ (self->binding == function_str ||
3254
+ PyObject_RichCompareBool(self->binding, function_str, Py_EQ) == 1 ||
3255
+ self->binding == instancemethod_str ||
3256
+ PyObject_RichCompareBool(self->binding, instancemethod_str, Py_EQ) ==
3257
+ 1 ||
3258
+ self->binding == callable_str ||
3259
+ PyObject_RichCompareBool(self->binding, callable_str, Py_EQ) == 1))
3260
+ {
3261
+
3262
+ PyObject *wrapped = NULL;
3263
+
3264
+ static PyObject *wrapped_str = NULL;
3265
+
3266
+ if (!wrapped_str)
3267
+ {
3268
+ wrapped_str = PyUnicode_InternFromString("__wrapped__");
3269
+ }
3270
+
3271
+ wrapped = PyObject_GetAttr(self->parent, wrapped_str);
3272
+
3273
+ if (!wrapped)
3274
+ return NULL;
3275
+
3276
+ if (Py_TYPE(wrapped)->tp_descr_get == NULL)
3277
+ {
3278
+ PyErr_Format(PyExc_AttributeError,
3279
+ "'%s' object has no attribute '__get__'",
3280
+ Py_TYPE(wrapped)->tp_name);
3281
+ Py_DECREF(wrapped);
3282
+ return NULL;
3283
+ }
3284
+
3285
+ descriptor = (Py_TYPE(wrapped)->tp_descr_get)(wrapped, obj, type);
3286
+
3287
+ Py_DECREF(wrapped);
3288
+
3289
+ if (!descriptor)
3290
+ return NULL;
3291
+
3292
+ if (Py_TYPE(self->parent) != &WraptFunctionWrapper_Type)
3293
+ {
3294
+ bound_type =
3295
+ PyObject_GenericGetAttr((PyObject *)self->parent, bound_type_str);
3296
+
3297
+ if (!bound_type)
3298
+ PyErr_Clear();
3299
+ }
3300
+
3301
+ if (obj == NULL)
3302
+ obj = Py_None;
3303
+
3304
+ result = PyObject_CallFunctionObjArgs(
3305
+ bound_type ? bound_type : (PyObject *)&WraptBoundFunctionWrapper_Type,
3306
+ descriptor, obj, self->wrapper, self->enabled, self->binding,
3307
+ self->parent, type, NULL);
3308
+
3309
+ Py_XDECREF(bound_type);
3310
+ Py_DECREF(descriptor);
3311
+
3312
+ return result;
3313
+ }
3314
+
3315
+ Py_INCREF(self);
3316
+ return (PyObject *)self;
3317
+ }
3318
+
3319
+ /* ------------------------------------------------------------------------- */
3320
+
3321
+ static PyObject *
3322
+ WraptFunctionWrapperBase_set_name(WraptFunctionWrapperObject *self,
3323
+ PyObject *args, PyObject *kwds)
3324
+ {
3325
+ PyObject *method = NULL;
3326
+ PyObject *result = NULL;
3327
+
3328
+ if (!self->object_proxy.wrapped)
3329
+ {
3330
+ if (raise_uninitialized_wrapper_error(&self->object_proxy) == -1)
3331
+ return NULL;
3332
+ }
3333
+
3334
+ method = PyObject_GetAttrString(self->object_proxy.wrapped, "__set_name__");
3335
+
3336
+ if (!method)
3337
+ {
3338
+ PyErr_Clear();
3339
+ Py_INCREF(Py_None);
3340
+ return Py_None;
3341
+ }
3342
+
3343
+ result = PyObject_Call(method, args, kwds);
3344
+
3345
+ Py_DECREF(method);
3346
+
3347
+ return result;
3348
+ }
3349
+
3350
+ /* ------------------------------------------------------------------------- */
3351
+
3352
+ static PyObject *
3353
+ WraptFunctionWrapperBase_instancecheck(WraptFunctionWrapperObject *self,
3354
+ PyObject *instance)
3355
+ {
3356
+ PyObject *result = NULL;
3357
+
3358
+ int check = 0;
3359
+
3360
+ if (!self->object_proxy.wrapped)
3361
+ {
3362
+ if (raise_uninitialized_wrapper_error(&self->object_proxy) == -1)
3363
+ return NULL;
3364
+ }
3365
+
3366
+ check = PyObject_IsInstance(instance, self->object_proxy.wrapped);
3367
+
3368
+ if (check < 0)
3369
+ {
3370
+ return NULL;
3371
+ }
3372
+
3373
+ result = check ? Py_True : Py_False;
3374
+
3375
+ Py_INCREF(result);
3376
+ return result;
3377
+ }
3378
+
3379
+ /* ------------------------------------------------------------------------- */
3380
+
3381
+ static PyObject *
3382
+ WraptFunctionWrapperBase_subclasscheck(WraptFunctionWrapperObject *self,
3383
+ PyObject *args)
3384
+ {
3385
+ PyObject *subclass = NULL;
3386
+ PyObject *object = NULL;
3387
+ PyObject *result = NULL;
3388
+
3389
+ int check = 0;
3390
+
3391
+ if (!self->object_proxy.wrapped)
3392
+ {
3393
+ if (raise_uninitialized_wrapper_error(&self->object_proxy) == -1)
3394
+ return NULL;
3395
+ }
3396
+
3397
+ if (!PyArg_ParseTuple(args, "O", &subclass))
3398
+ return NULL;
3399
+
3400
+ object = PyObject_GetAttrString(subclass, "__wrapped__");
3401
+
3402
+ if (!object)
3403
+ PyErr_Clear();
3404
+
3405
+ check = PyObject_IsSubclass(object ? object : subclass,
3406
+ self->object_proxy.wrapped);
3407
+
3408
+ Py_XDECREF(object);
3409
+
3410
+ if (check == -1)
3411
+ return NULL;
3412
+
3413
+ result = check ? Py_True : Py_False;
3414
+
3415
+ Py_INCREF(result);
3416
+
3417
+ return result;
3418
+ }
3419
+
3420
+ /* ------------------------------------------------------------------------- */
3421
+
3422
+ static PyObject *
3423
+ WraptFunctionWrapperBase_get_self_instance(WraptFunctionWrapperObject *self,
3424
+ void *closure)
3425
+ {
3426
+ if (!self->instance)
3427
+ {
3428
+ Py_INCREF(Py_None);
3429
+ return Py_None;
3430
+ }
3431
+
3432
+ Py_INCREF(self->instance);
3433
+ return self->instance;
3434
+ }
3435
+
3436
+ /* ------------------------------------------------------------------------- */
3437
+
3438
+ static PyObject *
3439
+ WraptFunctionWrapperBase_get_self_wrapper(WraptFunctionWrapperObject *self,
3440
+ void *closure)
3441
+ {
3442
+ if (!self->wrapper)
3443
+ {
3444
+ Py_INCREF(Py_None);
3445
+ return Py_None;
3446
+ }
3447
+
3448
+ Py_INCREF(self->wrapper);
3449
+ return self->wrapper;
3450
+ }
3451
+
3452
+ /* ------------------------------------------------------------------------- */
3453
+
3454
+ static PyObject *
3455
+ WraptFunctionWrapperBase_get_self_enabled(WraptFunctionWrapperObject *self,
3456
+ void *closure)
3457
+ {
3458
+ if (!self->enabled)
3459
+ {
3460
+ Py_INCREF(Py_None);
3461
+ return Py_None;
3462
+ }
3463
+
3464
+ Py_INCREF(self->enabled);
3465
+ return self->enabled;
3466
+ }
3467
+
3468
+ /* ------------------------------------------------------------------------- */
3469
+
3470
+ static PyObject *
3471
+ WraptFunctionWrapperBase_get_self_binding(WraptFunctionWrapperObject *self,
3472
+ void *closure)
3473
+ {
3474
+ if (!self->binding)
3475
+ {
3476
+ Py_INCREF(Py_None);
3477
+ return Py_None;
3478
+ }
3479
+
3480
+ Py_INCREF(self->binding);
3481
+ return self->binding;
3482
+ }
3483
+
3484
+ /* ------------------------------------------------------------------------- */
3485
+
3486
+ static PyObject *
3487
+ WraptFunctionWrapperBase_get_self_parent(WraptFunctionWrapperObject *self,
3488
+ void *closure)
3489
+ {
3490
+ if (!self->parent)
3491
+ {
3492
+ Py_INCREF(Py_None);
3493
+ return Py_None;
3494
+ }
3495
+
3496
+ Py_INCREF(self->parent);
3497
+ return self->parent;
3498
+ }
3499
+
3500
+ /* ------------------------------------------------------------------------- */
3501
+
3502
+ static PyObject *
3503
+ WraptFunctionWrapperBase_get_self_owner(WraptFunctionWrapperObject *self,
3504
+ void *closure)
3505
+ {
3506
+ if (!self->owner)
3507
+ {
3508
+ Py_INCREF(Py_None);
3509
+ return Py_None;
3510
+ }
3511
+
3512
+ Py_INCREF(self->owner);
3513
+ return self->owner;
3514
+ }
3515
+
3516
+ /* ------------------------------------------------------------------------- */;
3517
+
3518
+ static PyMethodDef WraptFunctionWrapperBase_methods[] = {
3519
+ {"__set_name__", (PyCFunction)WraptFunctionWrapperBase_set_name,
3520
+ METH_VARARGS | METH_KEYWORDS, 0},
3521
+ {"__instancecheck__", (PyCFunction)WraptFunctionWrapperBase_instancecheck,
3522
+ METH_O, 0},
3523
+ {"__subclasscheck__", (PyCFunction)WraptFunctionWrapperBase_subclasscheck,
3524
+ METH_VARARGS, 0},
3525
+ {NULL, NULL},
3526
+ };
3527
+
3528
+ /* ------------------------------------------------------------------------- */;
3529
+
3530
+ static PyGetSetDef WraptFunctionWrapperBase_getset[] = {
3531
+ {"__module__", (getter)WraptObjectProxy_get_module,
3532
+ (setter)WraptObjectProxy_set_module, 0},
3533
+ {"__doc__", (getter)WraptObjectProxy_get_doc,
3534
+ (setter)WraptObjectProxy_set_doc, 0},
3535
+ {"_self_instance", (getter)WraptFunctionWrapperBase_get_self_instance, NULL,
3536
+ 0},
3537
+ {"_self_wrapper", (getter)WraptFunctionWrapperBase_get_self_wrapper, NULL,
3538
+ 0},
3539
+ {"_self_enabled", (getter)WraptFunctionWrapperBase_get_self_enabled, NULL,
3540
+ 0},
3541
+ {"_self_binding", (getter)WraptFunctionWrapperBase_get_self_binding, NULL,
3542
+ 0},
3543
+ {"_self_parent", (getter)WraptFunctionWrapperBase_get_self_parent, NULL, 0},
3544
+ {"_self_owner", (getter)WraptFunctionWrapperBase_get_self_owner, NULL, 0},
3545
+ {NULL},
3546
+ };
3547
+
3548
+ PyTypeObject WraptFunctionWrapperBase_Type = {
3549
+ PyVarObject_HEAD_INIT(NULL, 0) "_FunctionWrapperBase", /*tp_name*/
3550
+ sizeof(WraptFunctionWrapperObject), /*tp_basicsize*/
3551
+ 0, /*tp_itemsize*/
3552
+ /* methods */
3553
+ (destructor)WraptFunctionWrapperBase_dealloc, /*tp_dealloc*/
3554
+ 0, /*tp_print*/
3555
+ 0, /*tp_getattr*/
3556
+ 0, /*tp_setattr*/
3557
+ 0, /*tp_compare*/
3558
+ 0, /*tp_repr*/
3559
+ 0, /*tp_as_number*/
3560
+ 0, /*tp_as_sequence*/
3561
+ 0, /*tp_as_mapping*/
3562
+ 0, /*tp_hash*/
3563
+ (ternaryfunc)WraptFunctionWrapperBase_call, /*tp_call*/
3564
+ 0, /*tp_str*/
3565
+ 0, /*tp_getattro*/
3566
+ 0, /*tp_setattro*/
3567
+ 0, /*tp_as_buffer*/
3568
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE | Py_TPFLAGS_HAVE_GC, /*tp_flags*/
3569
+ 0, /*tp_doc*/
3570
+ (traverseproc)WraptFunctionWrapperBase_traverse, /*tp_traverse*/
3571
+ (inquiry)WraptFunctionWrapperBase_clear, /*tp_clear*/
3572
+ 0, /*tp_richcompare*/
3573
+ offsetof(WraptObjectProxyObject, weakreflist), /*tp_weaklistoffset*/
3574
+ 0, /*tp_iter*/
3575
+ 0, /*tp_iternext*/
3576
+ WraptFunctionWrapperBase_methods, /*tp_methods*/
3577
+ 0, /*tp_members*/
3578
+ WraptFunctionWrapperBase_getset, /*tp_getset*/
3579
+ 0, /*tp_base*/
3580
+ 0, /*tp_dict*/
3581
+ (descrgetfunc)WraptFunctionWrapperBase_descr_get, /*tp_descr_get*/
3582
+ 0, /*tp_descr_set*/
3583
+ 0, /*tp_dictoffset*/
3584
+ (initproc)WraptFunctionWrapperBase_init, /*tp_init*/
3585
+ 0, /*tp_alloc*/
3586
+ WraptFunctionWrapperBase_new, /*tp_new*/
3587
+ 0, /*tp_free*/
3588
+ 0, /*tp_is_gc*/
3589
+ };
3590
+
3591
+ /* ------------------------------------------------------------------------- */
3592
+
3593
+ static PyObject *
3594
+ WraptBoundFunctionWrapper_call(WraptFunctionWrapperObject *self, PyObject *args,
3595
+ PyObject *kwds)
3596
+ {
3597
+ PyObject *param_args = NULL;
3598
+ PyObject *param_kwds = NULL;
3599
+
3600
+ PyObject *wrapped = NULL;
3601
+ PyObject *instance = NULL;
3602
+
3603
+ PyObject *result = NULL;
3604
+
3605
+ static PyObject *function_str = NULL;
3606
+ static PyObject *callable_str = NULL;
3607
+
3608
+ if (self->enabled != Py_None)
3609
+ {
3610
+ if (PyCallable_Check(self->enabled))
3611
+ {
3612
+ PyObject *object = NULL;
3613
+
3614
+ object = PyObject_CallFunctionObjArgs(self->enabled, NULL);
3615
+
3616
+ if (!object)
3617
+ return NULL;
3618
+
3619
+ if (PyObject_Not(object))
3620
+ {
3621
+ Py_DECREF(object);
3622
+ return PyObject_Call(self->object_proxy.wrapped, args, kwds);
3623
+ }
3624
+
3625
+ Py_DECREF(object);
3626
+ }
3627
+ else if (PyObject_Not(self->enabled))
3628
+ {
3629
+ return PyObject_Call(self->object_proxy.wrapped, args, kwds);
3630
+ }
3631
+ }
3632
+
3633
+ if (!function_str)
3634
+ {
3635
+ function_str = PyUnicode_InternFromString("function");
3636
+ callable_str = PyUnicode_InternFromString("callable");
3637
+ }
3638
+
3639
+ /*
3640
+ * We need to do things different depending on whether we are likely
3641
+ * wrapping an instance method vs a static method or class method.
3642
+ */
3643
+
3644
+ if (self->binding == function_str ||
3645
+ PyObject_RichCompareBool(self->binding, function_str, Py_EQ) == 1 ||
3646
+ self->binding == callable_str ||
3647
+ PyObject_RichCompareBool(self->binding, callable_str, Py_EQ) == 1)
3648
+ {
3649
+
3650
+ // if (self->instance == Py_None) {
3651
+ // /*
3652
+ // * This situation can occur where someone is calling the
3653
+ // * instancemethod via the class type and passing the
3654
+ // * instance as the first argument. We need to shift the args
3655
+ // * before making the call to the wrapper and effectively
3656
+ // * bind the instance to the wrapped function using a partial
3657
+ // * so the wrapper doesn't see anything as being different.
3658
+ // */
3659
+
3660
+ // if (PyTuple_Size(args) == 0) {
3661
+ // PyErr_SetString(PyExc_TypeError,
3662
+ // "missing 1 required positional argument");
3663
+ // return NULL;
3664
+ // }
3665
+
3666
+ // instance = PyTuple_GetItem(args, 0);
3667
+
3668
+ // if (!instance)
3669
+ // return NULL;
3670
+
3671
+ // wrapped = PyObject_CallFunctionObjArgs(
3672
+ // (PyObject *)&WraptPartialCallableObjectProxy_Type,
3673
+ // self->object_proxy.wrapped, instance, NULL);
3674
+
3675
+ // if (!wrapped)
3676
+ // return NULL;
3677
+
3678
+ // param_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
3679
+
3680
+ // if (!param_args) {
3681
+ // Py_DECREF(wrapped);
3682
+ // return NULL;
3683
+ // }
3684
+
3685
+ // args = param_args;
3686
+ // }
3687
+
3688
+ if (self->instance == Py_None && PyTuple_Size(args) != 0)
3689
+ {
3690
+ /*
3691
+ * This situation can occur where someone is calling the
3692
+ * instancemethod via the class type and passing the
3693
+ * instance as the first argument. We need to shift the args
3694
+ * before making the call to the wrapper and effectively
3695
+ * bind the instance to the wrapped function using a partial
3696
+ * so the wrapper doesn't see anything as being different.
3697
+ */
3698
+
3699
+ instance = PyTuple_GetItem(args, 0);
3700
+
3701
+ if (!instance)
3702
+ return NULL;
3703
+
3704
+ if (PyObject_IsInstance(instance, self->owner) == 1)
3705
+ {
3706
+ wrapped = PyObject_CallFunctionObjArgs(
3707
+ (PyObject *)&WraptPartialCallableObjectProxy_Type,
3708
+ self->object_proxy.wrapped, instance, NULL);
3709
+
3710
+ if (!wrapped)
3711
+ return NULL;
3712
+
3713
+ param_args = PyTuple_GetSlice(args, 1, PyTuple_Size(args));
3714
+
3715
+ if (!param_args)
3716
+ {
3717
+ Py_DECREF(wrapped);
3718
+ return NULL;
3719
+ }
3720
+
3721
+ args = param_args;
3722
+ }
3723
+ else
3724
+ {
3725
+ instance = self->instance;
3726
+ }
3727
+ }
3728
+ else
3729
+ {
3730
+ instance = self->instance;
3731
+ }
3732
+
3733
+ if (!wrapped)
3734
+ {
3735
+ Py_INCREF(self->object_proxy.wrapped);
3736
+ wrapped = self->object_proxy.wrapped;
3737
+ }
3738
+
3739
+ if (!kwds)
3740
+ {
3741
+ param_kwds = PyDict_New();
3742
+ kwds = param_kwds;
3743
+ }
3744
+
3745
+ result = PyObject_CallFunctionObjArgs(self->wrapper, wrapped, instance,
3746
+ args, kwds, NULL);
3747
+
3748
+ Py_XDECREF(param_args);
3749
+ Py_XDECREF(param_kwds);
3750
+ Py_DECREF(wrapped);
3751
+
3752
+ return result;
3753
+ }
3754
+ else
3755
+ {
3756
+ /*
3757
+ * As in this case we would be dealing with a classmethod or
3758
+ * staticmethod, then _self_instance will only tell us whether
3759
+ * when calling the classmethod or staticmethod they did it via
3760
+ * an instance of the class it is bound to and not the case
3761
+ * where done by the class type itself. We thus ignore
3762
+ * _self_instance and use the __self__ attribute of the bound
3763
+ * function instead. For a classmethod, this means instance will
3764
+ * be the class type and for a staticmethod it will be None.
3765
+ * This is probably the more useful thing we can pass through
3766
+ * even though we loose knowledge of whether they were called on
3767
+ * the instance vs the class type, as it reflects what they have
3768
+ * available in the decoratored function.
3769
+ */
3770
+
3771
+ instance = PyObject_GetAttrString(self->object_proxy.wrapped, "__self__");
3772
+
3773
+ if (!instance)
3774
+ {
3775
+ PyErr_Clear();
3776
+ Py_INCREF(Py_None);
3777
+ instance = Py_None;
3778
+ }
3779
+
3780
+ if (!kwds)
3781
+ {
3782
+ param_kwds = PyDict_New();
3783
+ kwds = param_kwds;
3784
+ }
3785
+
3786
+ result = PyObject_CallFunctionObjArgs(
3787
+ self->wrapper, self->object_proxy.wrapped, instance, args, kwds, NULL);
3788
+
3789
+ Py_XDECREF(param_kwds);
3790
+
3791
+ Py_DECREF(instance);
3792
+
3793
+ return result;
3794
+ }
3795
+ }
3796
+
3797
+ /* ------------------------------------------------------------------------- */
3798
+
3799
+ static PyGetSetDef WraptBoundFunctionWrapper_getset[] = {
3800
+ {"__module__", (getter)WraptObjectProxy_get_module,
3801
+ (setter)WraptObjectProxy_set_module, 0},
3802
+ {"__doc__", (getter)WraptObjectProxy_get_doc,
3803
+ (setter)WraptObjectProxy_set_doc, 0},
3804
+ {NULL},
3805
+ };
3806
+
3807
+ PyTypeObject WraptBoundFunctionWrapper_Type = {
3808
+ PyVarObject_HEAD_INIT(NULL, 0) "BoundFunctionWrapper", /*tp_name*/
3809
+ sizeof(WraptFunctionWrapperObject), /*tp_basicsize*/
3810
+ 0, /*tp_itemsize*/
3811
+ /* methods */
3812
+ 0, /*tp_dealloc*/
3813
+ 0, /*tp_print*/
3814
+ 0, /*tp_getattr*/
3815
+ 0, /*tp_setattr*/
3816
+ 0, /*tp_compare*/
3817
+ 0, /*tp_repr*/
3818
+ 0, /*tp_as_number*/
3819
+ 0, /*tp_as_sequence*/
3820
+ 0, /*tp_as_mapping*/
3821
+ 0, /*tp_hash*/
3822
+ (ternaryfunc)WraptBoundFunctionWrapper_call, /*tp_call*/
3823
+ 0, /*tp_str*/
3824
+ 0, /*tp_getattro*/
3825
+ 0, /*tp_setattro*/
3826
+ 0, /*tp_as_buffer*/
3827
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
3828
+ 0, /*tp_doc*/
3829
+ 0, /*tp_traverse*/
3830
+ 0, /*tp_clear*/
3831
+ 0, /*tp_richcompare*/
3832
+ offsetof(WraptObjectProxyObject, weakreflist), /*tp_weaklistoffset*/
3833
+ 0, /*tp_iter*/
3834
+ 0, /*tp_iternext*/
3835
+ 0, /*tp_methods*/
3836
+ 0, /*tp_members*/
3837
+ WraptBoundFunctionWrapper_getset, /*tp_getset*/
3838
+ 0, /*tp_base*/
3839
+ 0, /*tp_dict*/
3840
+ 0, /*tp_descr_get*/
3841
+ 0, /*tp_descr_set*/
3842
+ 0, /*tp_dictoffset*/
3843
+ 0, /*tp_init*/
3844
+ 0, /*tp_alloc*/
3845
+ 0, /*tp_new*/
3846
+ 0, /*tp_free*/
3847
+ 0, /*tp_is_gc*/
3848
+ };
3849
+
3850
+ /* ------------------------------------------------------------------------- */
3851
+
3852
+ static int WraptFunctionWrapper_init(WraptFunctionWrapperObject *self,
3853
+ PyObject *args, PyObject *kwds)
3854
+ {
3855
+ PyObject *wrapped = NULL;
3856
+ PyObject *wrapper = NULL;
3857
+ PyObject *enabled = Py_None;
3858
+ PyObject *binding = NULL;
3859
+ PyObject *instance = NULL;
3860
+
3861
+ static PyObject *function_str = NULL;
3862
+ static PyObject *classmethod_str = NULL;
3863
+ static PyObject *staticmethod_str = NULL;
3864
+ static PyObject *callable_str = NULL;
3865
+ static PyObject *builtin_str = NULL;
3866
+ static PyObject *class_str = NULL;
3867
+ static PyObject *instancemethod_str = NULL;
3868
+
3869
+ int result = 0;
3870
+
3871
+ char *const kwlist[] = {"wrapped", "wrapper", "enabled", NULL};
3872
+
3873
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O:FunctionWrapper", kwlist,
3874
+ &wrapped, &wrapper, &enabled))
3875
+ {
3876
+ return -1;
3877
+ }
3878
+
3879
+ if (!function_str)
3880
+ {
3881
+ function_str = PyUnicode_InternFromString("function");
3882
+ }
3883
+
3884
+ if (!classmethod_str)
3885
+ {
3886
+ classmethod_str = PyUnicode_InternFromString("classmethod");
3887
+ }
3888
+
3889
+ if (!staticmethod_str)
3890
+ {
3891
+ staticmethod_str = PyUnicode_InternFromString("staticmethod");
3892
+ }
3893
+
3894
+ if (!callable_str)
3895
+ {
3896
+ callable_str = PyUnicode_InternFromString("callable");
3897
+ }
3898
+
3899
+ if (!builtin_str)
3900
+ {
3901
+ builtin_str = PyUnicode_InternFromString("builtin");
3902
+ }
3903
+
3904
+ if (!class_str)
3905
+ {
3906
+ class_str = PyUnicode_InternFromString("class");
3907
+ }
3908
+
3909
+ if (!instancemethod_str)
3910
+ {
3911
+ instancemethod_str = PyUnicode_InternFromString("instancemethod");
3912
+ }
3913
+
3914
+ if (PyObject_IsInstance(wrapped,
3915
+ (PyObject *)&WraptFunctionWrapperBase_Type))
3916
+ {
3917
+ binding = PyObject_GetAttrString(wrapped, "_self_binding");
3918
+ }
3919
+
3920
+ if (!binding)
3921
+ {
3922
+ if (PyCFunction_Check(wrapped))
3923
+ {
3924
+ binding = builtin_str;
3925
+ }
3926
+ else if (PyObject_IsInstance(wrapped, (PyObject *)&PyFunction_Type))
3927
+ {
3928
+ binding = function_str;
3929
+ }
3930
+ else if (PyObject_IsInstance(wrapped, (PyObject *)&PyClassMethod_Type))
3931
+ {
3932
+ binding = classmethod_str;
3933
+ }
3934
+ else if (PyObject_IsInstance(wrapped, (PyObject *)&PyType_Type))
3935
+ {
3936
+ binding = class_str;
3937
+ }
3938
+ else if (PyObject_IsInstance(wrapped, (PyObject *)&PyStaticMethod_Type))
3939
+ {
3940
+ binding = staticmethod_str;
3941
+ }
3942
+ else if ((instance = PyObject_GetAttrString(wrapped, "__self__")) != 0)
3943
+ {
3944
+ if (PyObject_IsInstance(instance, (PyObject *)&PyType_Type))
3945
+ {
3946
+ binding = classmethod_str;
3947
+ }
3948
+ else if (PyObject_IsInstance(wrapped, (PyObject *)&PyMethod_Type))
3949
+ {
3950
+ binding = instancemethod_str;
3951
+ }
3952
+ else
3953
+ binding = callable_str;
3954
+
3955
+ Py_DECREF(instance);
3956
+ }
3957
+ else
3958
+ {
3959
+ PyErr_Clear();
3960
+
3961
+ binding = callable_str;
3962
+ }
3963
+ }
3964
+
3965
+ result = WraptFunctionWrapperBase_raw_init(
3966
+ self, wrapped, Py_None, wrapper, enabled, binding, Py_None, Py_None);
3967
+
3968
+ return result;
3969
+ }
3970
+
3971
+ /* ------------------------------------------------------------------------- */
3972
+
3973
+ static PyGetSetDef WraptFunctionWrapper_getset[] = {
3974
+ {"__module__", (getter)WraptObjectProxy_get_module,
3975
+ (setter)WraptObjectProxy_set_module, 0},
3976
+ {"__doc__", (getter)WraptObjectProxy_get_doc,
3977
+ (setter)WraptObjectProxy_set_doc, 0},
3978
+ {NULL},
3979
+ };
3980
+
3981
+ PyTypeObject WraptFunctionWrapper_Type = {
3982
+ PyVarObject_HEAD_INIT(NULL, 0) "FunctionWrapper", /*tp_name*/
3983
+ sizeof(WraptFunctionWrapperObject), /*tp_basicsize*/
3984
+ 0, /*tp_itemsize*/
3985
+ /* methods */
3986
+ 0, /*tp_dealloc*/
3987
+ 0, /*tp_print*/
3988
+ 0, /*tp_getattr*/
3989
+ 0, /*tp_setattr*/
3990
+ 0, /*tp_compare*/
3991
+ 0, /*tp_repr*/
3992
+ 0, /*tp_as_number*/
3993
+ 0, /*tp_as_sequence*/
3994
+ 0, /*tp_as_mapping*/
3995
+ 0, /*tp_hash*/
3996
+ 0, /*tp_call*/
3997
+ 0, /*tp_str*/
3998
+ 0, /*tp_getattro*/
3999
+ 0, /*tp_setattro*/
4000
+ 0, /*tp_as_buffer*/
4001
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
4002
+ 0, /*tp_doc*/
4003
+ 0, /*tp_traverse*/
4004
+ 0, /*tp_clear*/
4005
+ 0, /*tp_richcompare*/
4006
+ offsetof(WraptObjectProxyObject, weakreflist), /*tp_weaklistoffset*/
4007
+ 0, /*tp_iter*/
4008
+ 0, /*tp_iternext*/
4009
+ 0, /*tp_methods*/
4010
+ 0, /*tp_members*/
4011
+ WraptFunctionWrapper_getset, /*tp_getset*/
4012
+ 0, /*tp_base*/
4013
+ 0, /*tp_dict*/
4014
+ 0, /*tp_descr_get*/
4015
+ 0, /*tp_descr_set*/
4016
+ 0, /*tp_dictoffset*/
4017
+ (initproc)WraptFunctionWrapper_init, /*tp_init*/
4018
+ 0, /*tp_alloc*/
4019
+ 0, /*tp_new*/
4020
+ 0, /*tp_free*/
4021
+ 0, /*tp_is_gc*/
4022
+ };
4023
+
4024
+ /* ------------------------------------------------------------------------- */
4025
+
4026
+ static struct PyModuleDef moduledef = {
4027
+ PyModuleDef_HEAD_INIT,
4028
+ "_wrappers", /* m_name */
4029
+ NULL, /* m_doc */
4030
+ -1, /* m_size */
4031
+ NULL, /* m_methods */
4032
+ NULL, /* m_reload */
4033
+ NULL, /* m_traverse */
4034
+ NULL, /* m_clear */
4035
+ NULL, /* m_free */
4036
+ };
4037
+
4038
+ static PyObject *moduleinit(void)
4039
+ {
4040
+ PyObject *module;
4041
+
4042
+ module = PyModule_Create(&moduledef);
4043
+
4044
+ if (module == NULL)
4045
+ return NULL;
4046
+
4047
+ if (PyType_Ready(&WraptObjectProxy_Type) < 0)
4048
+ return NULL;
4049
+
4050
+ /* Ensure that inheritance relationships specified. */
4051
+
4052
+ WraptCallableObjectProxy_Type.tp_base = &WraptObjectProxy_Type;
4053
+ WraptPartialCallableObjectProxy_Type.tp_base = &WraptObjectProxy_Type;
4054
+ WraptFunctionWrapperBase_Type.tp_base = &WraptObjectProxy_Type;
4055
+ WraptBoundFunctionWrapper_Type.tp_base = &WraptFunctionWrapperBase_Type;
4056
+ WraptFunctionWrapper_Type.tp_base = &WraptFunctionWrapperBase_Type;
4057
+
4058
+ if (PyType_Ready(&WraptCallableObjectProxy_Type) < 0)
4059
+ return NULL;
4060
+ if (PyType_Ready(&WraptPartialCallableObjectProxy_Type) < 0)
4061
+ return NULL;
4062
+ if (PyType_Ready(&WraptFunctionWrapperBase_Type) < 0)
4063
+ return NULL;
4064
+ if (PyType_Ready(&WraptBoundFunctionWrapper_Type) < 0)
4065
+ return NULL;
4066
+ if (PyType_Ready(&WraptFunctionWrapper_Type) < 0)
4067
+ return NULL;
4068
+
4069
+ Py_INCREF(&WraptObjectProxy_Type);
4070
+ PyModule_AddObject(module, "ObjectProxy", (PyObject *)&WraptObjectProxy_Type);
4071
+ Py_INCREF(&WraptCallableObjectProxy_Type);
4072
+ PyModule_AddObject(module, "CallableObjectProxy",
4073
+ (PyObject *)&WraptCallableObjectProxy_Type);
4074
+ Py_INCREF(&WraptPartialCallableObjectProxy_Type);
4075
+ PyModule_AddObject(module, "PartialCallableObjectProxy",
4076
+ (PyObject *)&WraptPartialCallableObjectProxy_Type);
4077
+ Py_INCREF(&WraptFunctionWrapper_Type);
4078
+ PyModule_AddObject(module, "FunctionWrapper",
4079
+ (PyObject *)&WraptFunctionWrapper_Type);
4080
+
4081
+ Py_INCREF(&WraptFunctionWrapperBase_Type);
4082
+ PyModule_AddObject(module, "_FunctionWrapperBase",
4083
+ (PyObject *)&WraptFunctionWrapperBase_Type);
4084
+ Py_INCREF(&WraptBoundFunctionWrapper_Type);
4085
+ PyModule_AddObject(module, "BoundFunctionWrapper",
4086
+ (PyObject *)&WraptBoundFunctionWrapper_Type);
4087
+
4088
+ #ifdef Py_GIL_DISABLED
4089
+ PyUnstable_Module_SetGIL(module, Py_MOD_GIL_NOT_USED);
4090
+ #endif
4091
+
4092
+ return module;
4093
+ }
4094
+
4095
+ PyMODINIT_FUNC PyInit__wrappers(void) { return moduleinit(); }
4096
+
4097
+ /* ------------------------------------------------------------------------- */