Revision 745

View differences:

org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/lazy_object_proxy/simple.py
1
import operator
2

  
3
from .compat import PY2
4
from .compat import PY3
5
from .compat import with_metaclass
6
from .utils import cached_property
7
from .utils import identity
8

  
9

  
10
def make_proxy_method(code):
11
    def proxy_wrapper(self, *args):
12
        return code(self.__wrapped__, *args)
13

  
14
    return proxy_wrapper
15

  
16

  
17
class _ProxyMethods(object):
18
    # We use properties to override the values of __module__ and
19
    # __doc__. If we add these in ObjectProxy, the derived class
20
    # __dict__ will still be setup to have string variants of these
21
    # attributes and the rules of descriptors means that they appear to
22
    # take precedence over the properties in the base class. To avoid
23
    # that, we copy the properties into the derived class type itself
24
    # via a meta class. In that way the properties will always take
25
    # precedence.
26

  
27
    @property
28
    def __module__(self):
29
        return self.__wrapped__.__module__
30

  
31
    @__module__.setter
32
    def __module__(self, value):
33
        self.__wrapped__.__module__ = value
34

  
35
    @property
36
    def __doc__(self):
37
        return self.__wrapped__.__doc__
38

  
39
    @__doc__.setter
40
    def __doc__(self, value):
41
        self.__wrapped__.__doc__ = value
42

  
43
    # Need to also propagate the special __weakref__ attribute for case
44
    # where decorating classes which will define this. If do not define
45
    # it and use a function like inspect.getmembers() on a decorator
46
    # class it will fail. This can't be in the derived classes.
47

  
48
    @property
49
    def __weakref__(self):
50
        return self.__wrapped__.__weakref__
51

  
52

  
53
class _ProxyMetaType(type):
54
    def __new__(cls, name, bases, dictionary):
55
        # Copy our special properties into the class so that they
56
        # always take precedence over attributes of the same name added
57
        # during construction of a derived class. This is to save
58
        # duplicating the implementation for them in all derived classes.
59

  
60
        dictionary.update(vars(_ProxyMethods))
61
        dictionary.pop('__dict__')
62

  
63
        return type.__new__(cls, name, bases, dictionary)
64

  
65

  
66
class Proxy(with_metaclass(_ProxyMetaType)):
67
    __factory__ = None
68

  
69
    def __init__(self, factory):
70
        self.__dict__['__factory__'] = factory
71

  
72
    @cached_property
73
    def __wrapped__(self):
74
        self = self.__dict__
75
        if '__factory__' in self:
76
            factory = self['__factory__']
77
            return factory()
78
        else:
79
            raise ValueError("Proxy hasn't been initiated: __factory__ is missing.")
80

  
81
    __name__ = property(make_proxy_method(operator.attrgetter('__name__')))
82
    __class__ = property(make_proxy_method(operator.attrgetter('__class__')))
83
    __annotations__ = property(make_proxy_method(operator.attrgetter('__anotations__')))
84
    __dir__ = make_proxy_method(dir)
85
    __str__ = make_proxy_method(str)
86

  
87
    if PY3:
88
        __bytes__ = make_proxy_method(bytes)
89

  
90
    def __repr__(self, __getattr__=object.__getattribute__):
91
        if '__wrapped__' in self.__dict__:
92
            return '<%s at 0x%x wrapping %r at 0x%x with factory %r>' % (
93
                type(self).__name__, id(self),
94
                self.__wrapped__, id(self.__wrapped__),
95
                self.__factory__
96
            )
97
        else:
98
            return '<%s at 0x%x with factory %r>' % (
99
                type(self).__name__, id(self),
100
                self.__factory__
101
            )
102

  
103
    __reversed__ = make_proxy_method(reversed)
104

  
105
    if PY3:
106
        __round__ = make_proxy_method(round)
107

  
108
    __lt__ = make_proxy_method(operator.lt)
109
    __le__ = make_proxy_method(operator.le)
110
    __eq__ = make_proxy_method(operator.eq)
111
    __ne__ = make_proxy_method(operator.ne)
112
    __gt__ = make_proxy_method(operator.gt)
113
    __ge__ = make_proxy_method(operator.ge)
114
    __hash__ = make_proxy_method(hash)
115
    __nonzero__ = make_proxy_method(bool)
116
    __bool__ = make_proxy_method(bool)
117

  
118
    def __setattr__(self, name, value):
119
        if hasattr(type(self), name):
120
            self.__dict__[name] = value
121
        else:
122
            setattr(self.__wrapped__, name, value)
123

  
124
    def __getattr__(self, name):
125
        if name in ('__wrapped__', '__factory__'):
126
            raise AttributeError(name)
127
        else:
128
            return getattr(self.__wrapped__, name)
129

  
130
    def __delattr__(self, name):
131
        if hasattr(type(self), name):
132
            del self.__dict__[name]
133
        else:
134
            delattr(self.__wrapped__, name)
135

  
136
    __add__ = make_proxy_method(operator.add)
137
    __sub__ = make_proxy_method(operator.sub)
138
    __mul__ = make_proxy_method(operator.mul)
139
    __div__ = make_proxy_method(operator.div if PY2 else operator.truediv)
140
    __truediv__ = make_proxy_method(operator.truediv)
141
    __floordiv__ = make_proxy_method(operator.floordiv)
142
    __mod__ = make_proxy_method(operator.mod)
143
    __divmod__ = make_proxy_method(divmod)
144
    __pow__ = make_proxy_method(pow)
145
    __lshift__ = make_proxy_method(operator.lshift)
146
    __rshift__ = make_proxy_method(operator.rshift)
147
    __and__ = make_proxy_method(operator.and_)
148
    __xor__ = make_proxy_method(operator.xor)
149
    __or__ = make_proxy_method(operator.or_)
150

  
151
    def __radd__(self, other):
152
        return other + self.__wrapped__
153

  
154
    def __rsub__(self, other):
155
        return other - self.__wrapped__
156

  
157
    def __rmul__(self, other):
158
        return other * self.__wrapped__
159

  
160
    def __rdiv__(self, other):
161
        return operator.div(other, self.__wrapped__)
162

  
163
    def __rtruediv__(self, other):
164
        return operator.truediv(other, self.__wrapped__)
165

  
166
    def __rfloordiv__(self, other):
167
        return other // self.__wrapped__
168

  
169
    def __rmod__(self, other):
170
        return other % self.__wrapped__
171

  
172
    def __rdivmod__(self, other):
173
        return divmod(other, self.__wrapped__)
174

  
175
    def __rpow__(self, other, *args):
176
        return pow(other, self.__wrapped__, *args)
177

  
178
    def __rlshift__(self, other):
179
        return other << self.__wrapped__
180

  
181
    def __rrshift__(self, other):
182
        return other >> self.__wrapped__
183

  
184
    def __rand__(self, other):
185
        return other & self.__wrapped__
186

  
187
    def __rxor__(self, other):
188
        return other ^ self.__wrapped__
189

  
190
    def __ror__(self, other):
191
        return other | self.__wrapped__
192

  
193
    __iadd__ = make_proxy_method(operator.iadd)
194
    __isub__ = make_proxy_method(operator.isub)
195
    __imul__ = make_proxy_method(operator.imul)
196
    __idiv__ = make_proxy_method(operator.idiv if PY2 else operator.itruediv)
197
    __itruediv__ = make_proxy_method(operator.itruediv)
198
    __ifloordiv__ = make_proxy_method(operator.ifloordiv)
199
    __imod__ = make_proxy_method(operator.imod)
200
    __ipow__ = make_proxy_method(operator.ipow)
201
    __ilshift__ = make_proxy_method(operator.ilshift)
202
    __irshift__ = make_proxy_method(operator.irshift)
203
    __iand__ = make_proxy_method(operator.iand)
204
    __ixor__ = make_proxy_method(operator.ixor)
205
    __ior__ = make_proxy_method(operator.ior)
206
    __neg__ = make_proxy_method(operator.neg)
207
    __pos__ = make_proxy_method(operator.pos)
208
    __abs__ = make_proxy_method(operator.abs)
209
    __invert__ = make_proxy_method(operator.invert)
210

  
211
    __int__ = make_proxy_method(int)
212

  
213
    if PY2:
214
        __long__ = make_proxy_method(long)  # flake8: noqa
215

  
216
    __float__ = make_proxy_method(float)
217
    __oct__ = make_proxy_method(oct)
218
    __hex__ = make_proxy_method(hex)
219
    __index__ = make_proxy_method(operator.index)
220
    __len__ = make_proxy_method(len)
221
    __contains__ = make_proxy_method(operator.contains)
222
    __getitem__ = make_proxy_method(operator.getitem)
223
    __setitem__ = make_proxy_method(operator.setitem)
224
    __delitem__ = make_proxy_method(operator.delitem)
225

  
226
    if PY2:
227
        __getslice__ = make_proxy_method(operator.getslice)
228
        __setslice__ = make_proxy_method(operator.setslice)
229
        __delslice__ = make_proxy_method(operator.delslice)
230

  
231
    def __enter__(self):
232
        return self.__wrapped__.__enter__()
233

  
234
    def __exit__(self, *args, **kwargs):
235
        return self.__wrapped__.__exit__(*args, **kwargs)
236

  
237
    __iter__ = make_proxy_method(iter)
238

  
239
    def __call__(self, *args, **kwargs):
240
        return self.__wrapped__(*args, **kwargs)
241

  
242
    def __reduce__(self):
243
        return identity, (self.__wrapped__,)
244

  
245
    def __reduce_ex__(self, protocol):
246
        return identity, (self.__wrapped__,)
org.gvsig.scripting/trunk/org.gvsig.scripting/org.gvsig.scripting.app/org.gvsig.scripting.app.mainplugin/src/main/resources-plugin/scripting/lib/lazy_object_proxy/cext.c
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
#define Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(object) \
12
    if (PyObject_IsInstance(object, (PyObject *)&Proxy_Type)) { \
13
        object = Proxy__ensure_wrapped((ProxyObject *)object); \
14
        if (!object) return NULL; \
15
    }
16

  
17
#define Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self) if (!Proxy__ensure_wrapped(self)) return NULL;
18
#define Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self) if (!Proxy__ensure_wrapped(self)) return -1;
19

  
20
#if PY_MAJOR_VERSION < 3
21
#define Py_hash_t long
22
#endif
23

  
24
/* ------------------------------------------------------------------------- */
25

  
26
typedef struct {
27
    PyObject_HEAD
28

  
29
    PyObject *dict;
30
    PyObject *wrapped;
31
    PyObject *factory;
32
} ProxyObject;
33

  
34
PyTypeObject Proxy_Type;
35

  
36

  
37
/* ------------------------------------------------------------------------- */
38

  
39
static PyObject *identity_ref = NULL;
40
static PyObject *
41
identity(PyObject *self, PyObject *value)
42
{
43
    Py_INCREF(value);
44
    return value;
45
}
46

  
47
/* ------------------------------------------------------------------------- */
48

  
49
PyDoc_STRVAR(identity_doc, "Indentity function: returns the single argument.");
50

  
51
static struct PyMethodDef module_functions[] = {
52
    {"identity", identity, METH_O, identity_doc},
53
    {NULL,       NULL}
54
};
55

  
56
/* ------------------------------------------------------------------------- */
57

  
58
static PyObject *Proxy__ensure_wrapped(ProxyObject *self)
59
{
60
    PyObject *wrapped;
61

  
62
    if (self->wrapped) {
63
        return self->wrapped;
64
    } else {
65
        if (self->factory) {
66
            wrapped = PyObject_CallFunctionObjArgs(self->factory, NULL);
67
            if (wrapped) {
68
                self->wrapped = wrapped;
69
                return wrapped;
70
            } else {
71
                return NULL;
72
            }
73
        } else {
74
            PyErr_SetString(PyExc_ValueError, "Proxy hasn't been initiated: __factory__ is missing.");
75
            return NULL;
76
        }
77
    }
78
}
79

  
80
/* ------------------------------------------------------------------------- */
81

  
82
static PyObject *Proxy_new(PyTypeObject *type,
83
        PyObject *args, PyObject *kwds)
84
{
85
    ProxyObject *self;
86

  
87
    self = (ProxyObject *)type->tp_alloc(type, 0);
88

  
89
    if (!self)
90
        return NULL;
91

  
92
    self->dict = PyDict_New();
93
    self->wrapped = NULL;
94
    self->factory = NULL;
95

  
96
    return (PyObject *)self;
97
}
98

  
99
/* ------------------------------------------------------------------------- */
100

  
101
static int Proxy_raw_init(ProxyObject *self,
102
        PyObject *factory)
103
{
104
    Py_INCREF(factory);
105
    Py_XDECREF(self->wrapped);
106
    Py_XDECREF(self->factory);
107
    self->factory = factory;
108

  
109
    return 0;
110
}
111

  
112
/* ------------------------------------------------------------------------- */
113

  
114
static int Proxy_init(ProxyObject *self,
115
        PyObject *args, PyObject *kwds)
116
{
117
    PyObject *wrapped = NULL;
118

  
119
    static char *kwlist[] = { "wrapped", NULL };
120

  
121
    if (!PyArg_ParseTupleAndKeywords(args, kwds, "O:ObjectProxy",
122
            kwlist, &wrapped)) {
123
        return -1;
124
    }
125

  
126
    return Proxy_raw_init(self, wrapped);
127
}
128

  
129
/* ------------------------------------------------------------------------- */
130

  
131
static int Proxy_traverse(ProxyObject *self,
132
        visitproc visit, void *arg)
133
{
134
    Py_VISIT(self->dict);
135
    Py_VISIT(self->wrapped);
136
    Py_VISIT(self->factory);
137
    return 0;
138
}
139

  
140
/* ------------------------------------------------------------------------- */
141

  
142
static int Proxy_clear(ProxyObject *self)
143
{
144
    Py_CLEAR(self->dict);
145
    Py_CLEAR(self->wrapped);
146
    Py_CLEAR(self->factory);
147
    return 0;
148
}
149

  
150
/* ------------------------------------------------------------------------- */
151

  
152
static void Proxy_dealloc(ProxyObject *self)
153
{
154
    PyObject_GC_UnTrack(self);
155

  
156
    Proxy_clear(self);
157

  
158
    Py_TYPE(self)->tp_free(self);
159
}
160

  
161
/* ------------------------------------------------------------------------- */
162

  
163
static PyObject *Proxy_repr(ProxyObject *self)
164
{
165

  
166
#if PY_MAJOR_VERSION < 3
167
    PyObject *factory_repr;
168

  
169
    factory_repr = PyObject_Repr(self->factory);
170
    if (factory_repr == NULL)
171
        return NULL;
172
#endif
173

  
174
    if (self->wrapped) {
175
#if PY_MAJOR_VERSION >= 3
176
        return PyUnicode_FromFormat("<%s at %p wrapping %R at %p with factory %R>",
177
                Py_TYPE(self)->tp_name, self,
178
                self->wrapped, self->wrapped,
179
                self->factory);
180
#else
181
        PyObject *wrapped_repr;
182

  
183
        wrapped_repr = PyObject_Repr(self->wrapped);
184
        if (wrapped_repr == NULL)
185
            return NULL;
186

  
187
        return PyString_FromFormat("<%s at %p wrapping %s at %p with factory %s>",
188
                Py_TYPE(self)->tp_name, self,
189
                PyString_AS_STRING(wrapped_repr), self->wrapped,
190
                PyString_AS_STRING(factory_repr));
191
#endif
192
    } else {
193
#if PY_MAJOR_VERSION >= 3
194
        return PyUnicode_FromFormat("<%s at %p with factory %R>",
195
                Py_TYPE(self)->tp_name, self,
196
                self->factory);
197
#else
198
        return PyString_FromFormat("<%s at %p with factory %s>",
199
                Py_TYPE(self)->tp_name, self,
200
                PyString_AS_STRING(factory_repr));
201
#endif
202
    }
203
}
204

  
205
/* ------------------------------------------------------------------------- */
206

  
207
static Py_hash_t Proxy_hash(ProxyObject *self)
208
{
209
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
210

  
211
    return PyObject_Hash(self->wrapped);
212
}
213

  
214
/* ------------------------------------------------------------------------- */
215

  
216
static PyObject *Proxy_str(ProxyObject *self)
217
{
218
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
219

  
220
    return PyObject_Str(self->wrapped);
221
}
222

  
223
/* ------------------------------------------------------------------------- */
224

  
225
static PyObject *Proxy_add(PyObject *o1, PyObject *o2)
226
{
227
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
228
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
229

  
230
    return PyNumber_Add(o1, o2);
231
}
232

  
233
/* ------------------------------------------------------------------------- */
234

  
235
static PyObject *Proxy_subtract(PyObject *o1, PyObject *o2)
236
{
237
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
238
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
239

  
240
    return PyNumber_Subtract(o1, o2);
241
}
242

  
243
/* ------------------------------------------------------------------------- */
244

  
245
static PyObject *Proxy_multiply(PyObject *o1, PyObject *o2)
246
{
247
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
248
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
249

  
250
    return PyNumber_Multiply(o1, o2);
251
}
252

  
253
/* ------------------------------------------------------------------------- */
254

  
255
#if PY_MAJOR_VERSION < 3
256
static PyObject *Proxy_divide(PyObject *o1, PyObject *o2)
257
{
258
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
259
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
260

  
261
    return PyNumber_Divide(o1, o2);
262
}
263
#endif
264

  
265
/* ------------------------------------------------------------------------- */
266

  
267
static PyObject *Proxy_remainder(PyObject *o1, PyObject *o2)
268
{
269
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
270
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
271

  
272
    return PyNumber_Remainder(o1, o2);
273
}
274

  
275
/* ------------------------------------------------------------------------- */
276

  
277
static PyObject *Proxy_divmod(PyObject *o1, PyObject *o2)
278
{
279
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
280
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
281

  
282
    return PyNumber_Divmod(o1, o2);
283
}
284

  
285
/* ------------------------------------------------------------------------- */
286

  
287
static PyObject *Proxy_power(PyObject *o1, PyObject *o2,
288
        PyObject *modulo)
289
{
290
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
291
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
292

  
293
    return PyNumber_Power(o1, o2, modulo);
294
}
295

  
296
/* ------------------------------------------------------------------------- */
297

  
298
static PyObject *Proxy_negative(ProxyObject *self)
299
{
300
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
301

  
302
    return PyNumber_Negative(self->wrapped);
303
}
304

  
305
/* ------------------------------------------------------------------------- */
306

  
307
static PyObject *Proxy_positive(ProxyObject *self)
308
{
309
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
310

  
311
    return PyNumber_Positive(self->wrapped);
312
}
313

  
314
/* ------------------------------------------------------------------------- */
315

  
316
static PyObject *Proxy_absolute(ProxyObject *self)
317
{
318
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
319

  
320
    return PyNumber_Absolute(self->wrapped);
321
}
322

  
323
/* ------------------------------------------------------------------------- */
324

  
325
static int Proxy_bool(ProxyObject *self)
326
{
327
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
328

  
329
    return PyObject_IsTrue(self->wrapped);
330
}
331

  
332
/* ------------------------------------------------------------------------- */
333

  
334
static PyObject *Proxy_invert(ProxyObject *self)
335
{
336
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
337

  
338
    return PyNumber_Invert(self->wrapped);
339
}
340

  
341
/* ------------------------------------------------------------------------- */
342

  
343
static PyObject *Proxy_lshift(PyObject *o1, PyObject *o2)
344
{
345
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
346
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
347

  
348
    return PyNumber_Lshift(o1, o2);
349
}
350

  
351
/* ------------------------------------------------------------------------- */
352

  
353
static PyObject *Proxy_rshift(PyObject *o1, PyObject *o2)
354
{
355
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
356
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
357

  
358
    return PyNumber_Rshift(o1, o2);
359
}
360

  
361
/* ------------------------------------------------------------------------- */
362

  
363
static PyObject *Proxy_and(PyObject *o1, PyObject *o2)
364
{
365
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
366
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
367

  
368
    return PyNumber_And(o1, o2);
369
}
370

  
371
/* ------------------------------------------------------------------------- */
372

  
373
static PyObject *Proxy_xor(PyObject *o1, PyObject *o2)
374
{
375
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
376
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
377

  
378
    return PyNumber_Xor(o1, o2);
379
}
380

  
381
/* ------------------------------------------------------------------------- */
382

  
383
static PyObject *Proxy_or(PyObject *o1, PyObject *o2)
384
{
385
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
386
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
387

  
388
    return PyNumber_Or(o1, o2);
389
}
390

  
391
/* ------------------------------------------------------------------------- */
392

  
393
#if PY_MAJOR_VERSION < 3
394
static PyObject *Proxy_int(ProxyObject *self)
395
{
396
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
397

  
398
    return PyNumber_Int(self->wrapped);
399
}
400
#endif
401

  
402
/* ------------------------------------------------------------------------- */
403

  
404
static PyObject *Proxy_long(ProxyObject *self)
405
{
406
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
407

  
408
    return PyNumber_Long(self->wrapped);
409
}
410

  
411
/* ------------------------------------------------------------------------- */
412

  
413
static PyObject *Proxy_float(ProxyObject *self)
414
{
415
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
416

  
417
    return PyNumber_Float(self->wrapped);
418
}
419

  
420
/* ------------------------------------------------------------------------- */
421

  
422
#if PY_MAJOR_VERSION < 3
423
static PyObject *Proxy_oct(ProxyObject *self)
424
{
425
    PyNumberMethods *nb;
426

  
427
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
428

  
429
    if ((nb = self->wrapped->ob_type->tp_as_number) == NULL ||
430
        nb->nb_oct == NULL) {
431
        PyErr_SetString(PyExc_TypeError,
432
                   "oct() argument can't be converted to oct");
433
        return NULL;
434
    }
435

  
436
    return (*nb->nb_oct)(self->wrapped);
437
}
438
#endif
439

  
440
/* ------------------------------------------------------------------------- */
441

  
442
#if PY_MAJOR_VERSION < 3
443
static PyObject *Proxy_hex(ProxyObject *self)
444
{
445
    PyNumberMethods *nb;
446

  
447
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
448

  
449
    if ((nb = self->wrapped->ob_type->tp_as_number) == NULL ||
450
        nb->nb_hex == NULL) {
451
        PyErr_SetString(PyExc_TypeError,
452
                   "hex() argument can't be converted to hex");
453
        return NULL;
454
    }
455

  
456
    return (*nb->nb_hex)(self->wrapped);
457
}
458
#endif
459

  
460
/* ------------------------------------------------------------------------- */
461

  
462
static PyObject *Proxy_inplace_add(ProxyObject *self,
463
        PyObject *other)
464
{
465
    PyObject *object = NULL;
466

  
467
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
468
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
469

  
470
    object = PyNumber_InPlaceAdd(self->wrapped, other);
471

  
472
    if (!object)
473
        return NULL;
474

  
475
    Py_DECREF(self->wrapped);
476
    self->wrapped = object;
477

  
478
    Py_INCREF(self);
479
    return (PyObject *)self;
480
}
481

  
482
/* ------------------------------------------------------------------------- */
483

  
484
static PyObject *Proxy_inplace_subtract(
485
        ProxyObject *self, PyObject *other)
486
{
487
    PyObject *object = NULL;
488

  
489
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
490
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
491

  
492
    object = PyNumber_InPlaceSubtract(self->wrapped, other);
493

  
494
    if (!object)
495
        return NULL;
496

  
497
    Py_DECREF(self->wrapped);
498
    self->wrapped = object;
499

  
500
    Py_INCREF(self);
501
    return (PyObject *)self;
502
}
503

  
504
/* ------------------------------------------------------------------------- */
505

  
506
static PyObject *Proxy_inplace_multiply(
507
        ProxyObject *self, PyObject *other)
508
{
509
    PyObject *object = NULL;
510

  
511
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
512
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
513

  
514
    object = PyNumber_InPlaceMultiply(self->wrapped, other);
515

  
516
    if (!object)
517
        return NULL;
518

  
519
    Py_DECREF(self->wrapped);
520
    self->wrapped = object;
521

  
522
    Py_INCREF(self);
523
    return (PyObject *)self;
524
}
525

  
526
/* ------------------------------------------------------------------------- */
527

  
528
#if PY_MAJOR_VERSION < 3
529
static PyObject *Proxy_inplace_divide(
530
        ProxyObject *self, PyObject *other)
531
{
532
    PyObject *object = NULL;
533

  
534
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
535
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
536

  
537
    object = PyNumber_InPlaceDivide(self->wrapped, other);
538

  
539
    if (!object)
540
        return NULL;
541

  
542
    Py_DECREF(self->wrapped);
543
    self->wrapped = object;
544

  
545
    Py_INCREF(self);
546
    return (PyObject *)self;
547
}
548
#endif
549

  
550
/* ------------------------------------------------------------------------- */
551

  
552
static PyObject *Proxy_inplace_remainder(
553
        ProxyObject *self, PyObject *other)
554
{
555
    PyObject *object = NULL;
556

  
557
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
558
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
559

  
560
    object = PyNumber_InPlaceRemainder(self->wrapped, other);
561

  
562
    if (!object)
563
        return NULL;
564

  
565
    Py_DECREF(self->wrapped);
566
    self->wrapped = object;
567

  
568
    Py_INCREF(self);
569
    return (PyObject *)self;
570
}
571

  
572
/* ------------------------------------------------------------------------- */
573

  
574
static PyObject *Proxy_inplace_power(ProxyObject *self,
575
        PyObject *other, PyObject *modulo)
576
{
577
    PyObject *object = NULL;
578

  
579
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
580
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
581

  
582
    object = PyNumber_InPlacePower(self->wrapped, other, modulo);
583

  
584
    if (!object)
585
        return NULL;
586

  
587
    Py_DECREF(self->wrapped);
588
    self->wrapped = object;
589

  
590
    Py_INCREF(self);
591
    return (PyObject *)self;
592
}
593

  
594
/* ------------------------------------------------------------------------- */
595

  
596
static PyObject *Proxy_inplace_lshift(ProxyObject *self,
597
        PyObject *other)
598
{
599
    PyObject *object = NULL;
600

  
601
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
602
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
603

  
604
    object = PyNumber_InPlaceLshift(self->wrapped, other);
605

  
606
    if (!object)
607
        return NULL;
608

  
609
    Py_DECREF(self->wrapped);
610
    self->wrapped = object;
611

  
612
    Py_INCREF(self);
613
    return (PyObject *)self;
614
}
615

  
616
/* ------------------------------------------------------------------------- */
617

  
618
static PyObject *Proxy_inplace_rshift(ProxyObject *self,
619
        PyObject *other)
620
{
621
    PyObject *object = NULL;
622

  
623
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
624
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
625

  
626
    object = PyNumber_InPlaceRshift(self->wrapped, other);
627

  
628
    if (!object)
629
        return NULL;
630

  
631
    Py_DECREF(self->wrapped);
632
    self->wrapped = object;
633

  
634
    Py_INCREF(self);
635
    return (PyObject *)self;
636
}
637

  
638
/* ------------------------------------------------------------------------- */
639

  
640
static PyObject *Proxy_inplace_and(ProxyObject *self,
641
        PyObject *other)
642
{
643
    PyObject *object = NULL;
644

  
645
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
646
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
647

  
648
    object = PyNumber_InPlaceAnd(self->wrapped, other);
649

  
650
    if (!object)
651
        return NULL;
652

  
653
    Py_DECREF(self->wrapped);
654
    self->wrapped = object;
655

  
656
    Py_INCREF(self);
657
    return (PyObject *)self;
658
}
659

  
660
/* ------------------------------------------------------------------------- */
661

  
662
static PyObject *Proxy_inplace_xor(ProxyObject *self,
663
        PyObject *other)
664
{
665
    PyObject *object = NULL;
666

  
667
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
668
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
669

  
670
    object = PyNumber_InPlaceXor(self->wrapped, other);
671

  
672
    if (!object)
673
        return NULL;
674

  
675
    Py_DECREF(self->wrapped);
676
    self->wrapped = object;
677

  
678
    Py_INCREF(self);
679
    return (PyObject *)self;
680
}
681

  
682
/* ------------------------------------------------------------------------- */
683

  
684
static PyObject *Proxy_inplace_or(ProxyObject *self,
685
        PyObject *other)
686
{
687
    PyObject *object = NULL;
688

  
689
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
690
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
691

  
692
    object = PyNumber_InPlaceOr(self->wrapped, other);
693

  
694
    Py_DECREF(self->wrapped);
695
    self->wrapped = object;
696

  
697
    Py_INCREF(self);
698
    return (PyObject *)self;
699
}
700

  
701
/* ------------------------------------------------------------------------- */
702

  
703
static PyObject *Proxy_floor_divide(PyObject *o1, PyObject *o2)
704
{
705
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
706
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
707

  
708
    return PyNumber_FloorDivide(o1, o2);
709
}
710

  
711
/* ------------------------------------------------------------------------- */
712

  
713
static PyObject *Proxy_true_divide(PyObject *o1, PyObject *o2)
714
{
715
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o1);
716
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(o2);
717

  
718
    return PyNumber_TrueDivide(o1, o2);
719
}
720

  
721
/* ------------------------------------------------------------------------- */
722

  
723
static PyObject *Proxy_inplace_floor_divide(
724
        ProxyObject *self, PyObject *other)
725
{
726
    PyObject *object = NULL;
727

  
728
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
729
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
730

  
731
    object = PyNumber_InPlaceFloorDivide(self->wrapped, other);
732

  
733
    if (!object)
734
        return NULL;
735

  
736
    Py_DECREF(self->wrapped);
737
    self->wrapped = object;
738

  
739
    Py_INCREF(self);
740
    return (PyObject *)self;
741
}
742

  
743
/* ------------------------------------------------------------------------- */
744

  
745
static PyObject *Proxy_inplace_true_divide(
746
        ProxyObject *self, PyObject *other)
747
{
748
    PyObject *object = NULL;
749

  
750
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
751
    Proxy__WRAPPED_REPLACE_OR_RETURN_NULL(other);
752

  
753
    object = PyNumber_InPlaceTrueDivide(self->wrapped, other);
754

  
755
    if (!object)
756
        return NULL;
757

  
758
    Py_DECREF(self->wrapped);
759
    self->wrapped = object;
760

  
761
    Py_INCREF(self);
762
    return (PyObject *)self;
763
}
764

  
765
/* ------------------------------------------------------------------------- */
766

  
767
static PyObject *Proxy_index(ProxyObject *self)
768
{
769
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
770

  
771
    return PyNumber_Index(self->wrapped);
772
}
773

  
774
/* ------------------------------------------------------------------------- */
775

  
776
static Py_ssize_t Proxy_length(ProxyObject *self)
777
{
778
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
779

  
780
    return PyObject_Length(self->wrapped);
781
}
782

  
783
/* ------------------------------------------------------------------------- */
784

  
785
static int Proxy_contains(ProxyObject *self,
786
        PyObject *value)
787
{
788
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
789

  
790
    return PySequence_Contains(self->wrapped, value);
791
}
792

  
793
/* ------------------------------------------------------------------------- */
794

  
795
static PyObject *Proxy_getitem(ProxyObject *self,
796
        PyObject *key)
797
{
798
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
799

  
800
    return PyObject_GetItem(self->wrapped, key);
801
}
802

  
803
/* ------------------------------------------------------------------------- */
804

  
805
static int Proxy_setitem(ProxyObject *self,
806
        PyObject *key, PyObject* value)
807
{
808
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
809

  
810
    if (value == NULL)
811
        return PyObject_DelItem(self->wrapped, key);
812
    else
813
        return PyObject_SetItem(self->wrapped, key, value);
814
}
815

  
816
/* ------------------------------------------------------------------------- */
817

  
818
static PyObject *Proxy_dir(
819
        ProxyObject *self, PyObject *args)
820
{
821
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
822

  
823
    return PyObject_Dir(self->wrapped);
824
}
825

  
826
/* ------------------------------------------------------------------------- */
827

  
828
static PyObject *Proxy_enter(
829
        ProxyObject *self, PyObject *args, PyObject *kwds)
830
{
831
    PyObject *method = NULL;
832
    PyObject *result = NULL;
833

  
834
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
835

  
836
    method = PyObject_GetAttrString(self->wrapped, "__enter__");
837

  
838
    if (!method)
839
        return NULL;
840

  
841
    result = PyObject_Call(method, args, kwds);
842

  
843
    Py_DECREF(method);
844

  
845
    return result;
846
}
847

  
848
/* ------------------------------------------------------------------------- */
849

  
850
static PyObject *Proxy_exit(
851
        ProxyObject *self, PyObject *args, PyObject *kwds)
852
{
853
    PyObject *method = NULL;
854
    PyObject *result = NULL;
855

  
856
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
857

  
858
    method = PyObject_GetAttrString(self->wrapped, "__exit__");
859

  
860
    if (!method)
861
        return NULL;
862

  
863
    result = PyObject_Call(method, args, kwds);
864

  
865
    Py_DECREF(method);
866

  
867
    return result;
868
}
869

  
870
/* ------------------------------------------------------------------------- */
871

  
872
static PyObject *Proxy_bytes(
873
        ProxyObject *self, PyObject *args)
874
{
875
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
876

  
877
    return PyObject_Bytes(self->wrapped);
878
}
879

  
880
/* ------------------------------------------------------------------------- */
881

  
882
static PyObject *Proxy_reversed(
883
        ProxyObject *self, PyObject *args)
884
{
885
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
886

  
887
    return PyObject_CallFunctionObjArgs((PyObject *)&PyReversed_Type,
888
            self->wrapped, NULL);
889
}
890

  
891
/* ------------------------------------------------------------------------- */
892
static PyObject *Proxy_reduce(
893
        ProxyObject *self, PyObject *args)
894
{
895
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
896

  
897
    return Py_BuildValue("(O(O))", identity_ref, self->wrapped);
898
}
899

  
900
/* ------------------------------------------------------------------------- */
901

  
902
#if PY_MAJOR_VERSION >= 3
903
static PyObject *Proxy_round(
904
        ProxyObject *self, PyObject *args)
905
{
906
    PyObject *module = NULL;
907
    PyObject *dict = NULL;
908
    PyObject *round = NULL;
909

  
910
    PyObject *result = NULL;
911

  
912
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
913

  
914
    module = PyImport_ImportModule("builtins");
915

  
916
    if (!module)
917
        return NULL;
918

  
919
    dict = PyModule_GetDict(module);
920
    round = PyDict_GetItemString(dict, "round");
921

  
922
    if (!round) {
923
        Py_DECREF(module);
924
        return NULL;
925
    }
926

  
927
    Py_INCREF(round);
928
    Py_DECREF(module);
929

  
930
    result = PyObject_CallFunctionObjArgs(round, self->wrapped, NULL);
931

  
932
    Py_DECREF(round);
933

  
934
    return result;
935
}
936
#endif
937

  
938
/* ------------------------------------------------------------------------- */
939

  
940
static PyObject *Proxy_get_name(
941
        ProxyObject *self)
942
{
943
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
944

  
945
    return PyObject_GetAttrString(self->wrapped, "__name__");
946
}
947

  
948
/* ------------------------------------------------------------------------- */
949

  
950
static int Proxy_set_name(ProxyObject *self,
951
        PyObject *value)
952
{
953
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
954

  
955
    return PyObject_SetAttrString(self->wrapped, "__name__", value);
956
}
957

  
958
/* ------------------------------------------------------------------------- */
959

  
960
static PyObject *Proxy_get_qualname(
961
        ProxyObject *self)
962
{
963
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
964

  
965
    return PyObject_GetAttrString(self->wrapped, "__qualname__");
966
}
967

  
968
/* ------------------------------------------------------------------------- */
969

  
970
static int Proxy_set_qualname(ProxyObject *self,
971
        PyObject *value)
972
{
973
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
974

  
975
    return PyObject_SetAttrString(self->wrapped, "__qualname__", value);
976
}
977

  
978
/* ------------------------------------------------------------------------- */
979

  
980
static PyObject *Proxy_get_module(
981
        ProxyObject *self)
982
{
983
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
984

  
985
    return PyObject_GetAttrString(self->wrapped, "__module__");
986
}
987

  
988
/* ------------------------------------------------------------------------- */
989

  
990
static int Proxy_set_module(ProxyObject *self,
991
        PyObject *value)
992
{
993
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
994

  
995
    if (PyObject_SetAttrString(self->wrapped, "__module__", value) == -1)
996
        return -1;
997

  
998
    return PyDict_SetItemString(self->dict, "__module__", value);
999
}
1000

  
1001
/* ------------------------------------------------------------------------- */
1002

  
1003
static PyObject *Proxy_get_doc(
1004
        ProxyObject *self)
1005
{
1006
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1007

  
1008
    return PyObject_GetAttrString(self->wrapped, "__doc__");
1009
}
1010

  
1011
/* ------------------------------------------------------------------------- */
1012

  
1013
static int Proxy_set_doc(ProxyObject *self,
1014
        PyObject *value)
1015
{
1016
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
1017

  
1018
    if (PyObject_SetAttrString(self->wrapped, "__doc__", value) == -1)
1019
        return -1;
1020

  
1021
    return PyDict_SetItemString(self->dict, "__doc__", value);
1022
}
1023

  
1024
/* ------------------------------------------------------------------------- */
1025

  
1026
static PyObject *Proxy_get_class(
1027
        ProxyObject *self)
1028
{
1029
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1030

  
1031
    return PyObject_GetAttrString(self->wrapped, "__class__");
1032
}
1033

  
1034
/* ------------------------------------------------------------------------- */
1035

  
1036
static PyObject *Proxy_get_annotations(
1037
        ProxyObject *self)
1038
{
1039
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1040

  
1041
    return PyObject_GetAttrString(self->wrapped, "__annotations__");
1042
}
1043

  
1044
/* ------------------------------------------------------------------------- */
1045

  
1046
static int Proxy_set_annotations(ProxyObject *self,
1047
        PyObject *value)
1048
{
1049
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
1050

  
1051
    return PyObject_SetAttrString(self->wrapped, "__annotations__", value);
1052
}
1053

  
1054
/* ------------------------------------------------------------------------- */
1055

  
1056
static PyObject *Proxy_get_wrapped(
1057
        ProxyObject *self)
1058
{
1059
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1060

  
1061
    Py_INCREF(self->wrapped);
1062
    return self->wrapped;
1063
}
1064

  
1065
/* ------------------------------------------------------------------------- */
1066

  
1067
static int Proxy_set_wrapped(ProxyObject *self,
1068
        PyObject *value)
1069
{
1070
    if (value) Py_INCREF(value);
1071
    Py_XDECREF(self->wrapped);
1072

  
1073
    self->wrapped = value;
1074

  
1075
    return 0;
1076
}
1077

  
1078
/* ------------------------------------------------------------------------- */
1079

  
1080
static PyObject *Proxy_get_factory(
1081
        ProxyObject *self)
1082
{
1083
    Py_INCREF(self->factory);
1084
    return self->factory;
1085
}
1086

  
1087
/* ------------------------------------------------------------------------- */
1088

  
1089
static int Proxy_set_factory(ProxyObject *self,
1090
        PyObject *value)
1091
{
1092
    if (value) Py_INCREF(value);
1093
    Py_XDECREF(self->factory);
1094

  
1095
    self->factory = value;
1096

  
1097
    return 0;
1098
}
1099

  
1100
/* ------------------------------------------------------------------------- */
1101

  
1102
static PyObject *Proxy_getattro(
1103
        ProxyObject *self, PyObject *name)
1104
{
1105
    PyObject *object = NULL;
1106
    PyObject *result = NULL;
1107

  
1108
    static PyObject *getattr_str = NULL;
1109

  
1110
    object = PyObject_GenericGetAttr((PyObject *)self, name);
1111

  
1112
    if (object)
1113
        return object;
1114

  
1115
    PyErr_Clear();
1116

  
1117
    if (!getattr_str) {
1118
#if PY_MAJOR_VERSION >= 3
1119
        getattr_str = PyUnicode_InternFromString("__getattr__");
1120
#else
1121
        getattr_str = PyString_InternFromString("__getattr__");
1122
#endif
1123
    }
1124

  
1125
    object = PyObject_GenericGetAttr((PyObject *)self, getattr_str);
1126

  
1127
    if (!object)
1128
        return NULL;
1129

  
1130
    result = PyObject_CallFunctionObjArgs(object, name, NULL);
1131

  
1132
    Py_DECREF(object);
1133

  
1134
    return result;
1135
}
1136

  
1137
/* ------------------------------------------------------------------------- */
1138

  
1139
static PyObject *Proxy_getattr(
1140
        ProxyObject *self, PyObject *args)
1141
{
1142
    PyObject *name = NULL;
1143

  
1144
#if PY_MAJOR_VERSION >= 3
1145
    if (!PyArg_ParseTuple(args, "U:__getattr__", &name))
1146
        return NULL;
1147
#else
1148
    if (!PyArg_ParseTuple(args, "S:__getattr__", &name))
1149
        return NULL;
1150
#endif
1151

  
1152
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1153

  
1154
    return PyObject_GetAttr(self->wrapped, name);
1155
}
1156

  
1157
/* ------------------------------------------------------------------------- */
1158

  
1159
static int Proxy_setattro(
1160
        ProxyObject *self, PyObject *name, PyObject *value)
1161
{
1162
    if (PyObject_HasAttr((PyObject *)Py_TYPE(self), name))
1163
        return PyObject_GenericSetAttr((PyObject *)self, name, value);
1164

  
1165
    Proxy__ENSURE_WRAPPED_OR_RETURN_MINUS1(self);
1166

  
1167
    return PyObject_SetAttr(self->wrapped, name, value);
1168
}
1169

  
1170
/* ------------------------------------------------------------------------- */
1171

  
1172
static PyObject *Proxy_richcompare(ProxyObject *self,
1173
        PyObject *other, int opcode)
1174
{
1175
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1176

  
1177
    return PyObject_RichCompare(self->wrapped, other, opcode);
1178
}
1179

  
1180
/* ------------------------------------------------------------------------- */
1181

  
1182
static PyObject *Proxy_iter(ProxyObject *self)
1183
{
1184
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1185

  
1186
    return PyObject_GetIter(self->wrapped);
1187
}
1188

  
1189
/* ------------------------------------------------------------------------- */
1190

  
1191
static PyObject *Proxy_call(
1192
        ProxyObject *self, PyObject *args, PyObject *kwds)
1193
{
1194
    Proxy__ENSURE_WRAPPED_OR_RETURN_NULL(self);
1195

  
1196
    return PyObject_Call(self->wrapped, args, kwds);
1197
}
1198

  
1199
/* ------------------------------------------------------------------------- */;
1200

  
1201
static PyNumberMethods Proxy_as_number = {
1202
    (binaryfunc)Proxy_add,                  /*nb_add*/
1203
    (binaryfunc)Proxy_subtract,             /*nb_subtract*/
1204
    (binaryfunc)Proxy_multiply,             /*nb_multiply*/
1205
#if PY_MAJOR_VERSION < 3
1206
    (binaryfunc)Proxy_divide,               /*nb_divide*/
1207
#endif
1208
    (binaryfunc)Proxy_remainder,            /*nb_remainder*/
1209
    (binaryfunc)Proxy_divmod,               /*nb_divmod*/
1210
    (ternaryfunc)Proxy_power,               /*nb_power*/
1211
    (unaryfunc)Proxy_negative,              /*nb_negative*/
1212
    (unaryfunc)Proxy_positive,              /*nb_positive*/
1213
    (unaryfunc)Proxy_absolute,              /*nb_absolute*/
1214
    (inquiry)Proxy_bool,                    /*nb_nonzero/nb_bool*/
1215
    (unaryfunc)Proxy_invert,                /*nb_invert*/
1216
    (binaryfunc)Proxy_lshift,               /*nb_lshift*/
1217
    (binaryfunc)Proxy_rshift,               /*nb_rshift*/
1218
    (binaryfunc)Proxy_and,                  /*nb_and*/
1219
    (binaryfunc)Proxy_xor,                  /*nb_xor*/
1220
    (binaryfunc)Proxy_or,                   /*nb_or*/
1221
#if PY_MAJOR_VERSION < 3
1222
    0,                                      /*nb_coerce*/
1223
#endif
1224
#if PY_MAJOR_VERSION < 3
1225
    (unaryfunc)Proxy_int,                   /*nb_int*/
1226
    (unaryfunc)Proxy_long,                  /*nb_long*/
1227
#else
1228
    (unaryfunc)Proxy_long,                  /*nb_int*/
1229
    0,                                      /*nb_long/nb_reserved*/
1230
#endif
1231
    (unaryfunc)Proxy_float,                 /*nb_float*/
1232
#if PY_MAJOR_VERSION < 3
1233
    (unaryfunc)Proxy_oct,                   /*nb_oct*/
1234
    (unaryfunc)Proxy_hex,                   /*nb_hex*/
1235
#endif
1236
    (binaryfunc)Proxy_inplace_add,          /*nb_inplace_add*/
1237
    (binaryfunc)Proxy_inplace_subtract,     /*nb_inplace_subtract*/
1238
    (binaryfunc)Proxy_inplace_multiply,     /*nb_inplace_multiply*/
1239
#if PY_MAJOR_VERSION < 3
1240
    (binaryfunc)Proxy_inplace_divide,       /*nb_inplace_divide*/
1241
#endif
1242
    (binaryfunc)Proxy_inplace_remainder,    /*nb_inplace_remainder*/
1243
    (ternaryfunc)Proxy_inplace_power,       /*nb_inplace_power*/
1244
    (binaryfunc)Proxy_inplace_lshift,       /*nb_inplace_lshift*/
1245
    (binaryfunc)Proxy_inplace_rshift,       /*nb_inplace_rshift*/
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff