4 PyDoc_STRVAR(operator_doc
,
5 "Operator interface.\n\
7 This module exports a set of functions implemented in C corresponding\n\
8 to the intrinsic operators of Python. For example, operator.add(x, y)\n\
9 is equivalent to the expression x+y. The function names are those\n\
10 used for special methods; variants without leading and trailing\n\
11 '__' are also provided for convenience.");
13 #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \
16 #define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
18 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
21 #define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
22 PyObject *a1; int a2; \
23 if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \
26 #define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
28 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
29 if(-1 == AOP(a1,a2)) return NULL; \
33 #define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
34 PyObject *a1, *a2, *a3; \
35 if(! PyArg_UnpackTuple(a,#OP,3,3,&a1,&a2,&a3)) return NULL; \
36 if(-1 == AOP(a1,a2,a3)) return NULL; \
40 #define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \
42 if(-1 == (r=AOP(a1))) return NULL; \
43 return PyBool_FromLong(r); }
45 #define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
46 PyObject *a1, *a2; long r; \
47 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
48 if(-1 == (r=AOP(a1,a2))) return NULL; \
49 return PyInt_FromLong(r); }
51 #define spamn2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
52 PyObject *a1, *a2; Py_ssize_t r; \
53 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
54 if(-1 == (r=AOP(a1,a2))) return NULL; \
55 return PyInt_FromSsize_t(r); }
57 #define spami2b(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
58 PyObject *a1, *a2; long r; \
59 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
60 if(-1 == (r=AOP(a1,a2))) return NULL; \
61 return PyBool_FromLong(r); }
63 #define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \
65 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \
66 return PyObject_RichCompare(a1,a2,A); }
68 /* Deprecated operators that need warnings. */
70 op_isCallable(PyObject
*x
)
72 if (PyErr_WarnPy3k("operator.isCallable() is not supported in 3.x. "
73 "Use hasattr(obj, '__call__').", 1) < 0)
75 return PyCallable_Check(x
);
79 op_sequenceIncludes(PyObject
*seq
, PyObject
* ob
)
81 if (PyErr_WarnPy3k("operator.sequenceIncludes() is not supported "
82 "in 3.x. Use operator.contains().", 1) < 0)
84 return PySequence_Contains(seq
, ob
);
87 spami(isCallable
, op_isCallable
)
88 spami(isNumberType
, PyNumber_Check
)
89 spami(truth
, PyObject_IsTrue
)
90 spam2(op_add
, PyNumber_Add
)
91 spam2(op_sub
, PyNumber_Subtract
)
92 spam2(op_mul
, PyNumber_Multiply
)
93 spam2(op_div
, PyNumber_Divide
)
94 spam2(op_floordiv
, PyNumber_FloorDivide
)
95 spam2(op_truediv
, PyNumber_TrueDivide
)
96 spam2(op_mod
, PyNumber_Remainder
)
97 spam1(op_neg
, PyNumber_Negative
)
98 spam1(op_pos
, PyNumber_Positive
)
99 spam1(op_abs
, PyNumber_Absolute
)
100 spam1(op_inv
, PyNumber_Invert
)
101 spam1(op_invert
, PyNumber_Invert
)
102 spam2(op_lshift
, PyNumber_Lshift
)
103 spam2(op_rshift
, PyNumber_Rshift
)
104 spami(op_not_
, PyObject_Not
)
105 spam2(op_and_
, PyNumber_And
)
106 spam2(op_xor
, PyNumber_Xor
)
107 spam2(op_or_
, PyNumber_Or
)
108 spam2(op_iadd
, PyNumber_InPlaceAdd
)
109 spam2(op_isub
, PyNumber_InPlaceSubtract
)
110 spam2(op_imul
, PyNumber_InPlaceMultiply
)
111 spam2(op_idiv
, PyNumber_InPlaceDivide
)
112 spam2(op_ifloordiv
, PyNumber_InPlaceFloorDivide
)
113 spam2(op_itruediv
, PyNumber_InPlaceTrueDivide
)
114 spam2(op_imod
, PyNumber_InPlaceRemainder
)
115 spam2(op_ilshift
, PyNumber_InPlaceLshift
)
116 spam2(op_irshift
, PyNumber_InPlaceRshift
)
117 spam2(op_iand
, PyNumber_InPlaceAnd
)
118 spam2(op_ixor
, PyNumber_InPlaceXor
)
119 spam2(op_ior
, PyNumber_InPlaceOr
)
120 spami(isSequenceType
, PySequence_Check
)
121 spam2(op_concat
, PySequence_Concat
)
122 spamoi(op_repeat
, PySequence_Repeat
)
123 spam2(op_iconcat
, PySequence_InPlaceConcat
)
124 spamoi(op_irepeat
, PySequence_InPlaceRepeat
)
125 spami2b(op_contains
, PySequence_Contains
)
126 spami2b(sequenceIncludes
, op_sequenceIncludes
)
127 spamn2(indexOf
, PySequence_Index
)
128 spamn2(countOf
, PySequence_Count
)
129 spami(isMappingType
, PyMapping_Check
)
130 spam2(op_getitem
, PyObject_GetItem
)
131 spam2n(op_delitem
, PyObject_DelItem
)
132 spam3n(op_setitem
, PyObject_SetItem
)
133 spamrc(op_lt
, Py_LT
)
134 spamrc(op_le
, Py_LE
)
135 spamrc(op_eq
, Py_EQ
)
136 spamrc(op_ne
, Py_NE
)
137 spamrc(op_gt
, Py_GT
)
138 spamrc(op_ge
, Py_GE
)
141 op_pow(PyObject
*s
, PyObject
*a
)
144 if (PyArg_UnpackTuple(a
,"pow", 2, 2, &a1
, &a2
))
145 return PyNumber_Power(a1
, a2
, Py_None
);
150 op_ipow(PyObject
*s
, PyObject
*a
)
153 if (PyArg_UnpackTuple(a
,"ipow", 2, 2, &a1
, &a2
))
154 return PyNumber_InPlacePower(a1
, a2
, Py_None
);
159 op_index(PyObject
*s
, PyObject
*a
)
161 return PyNumber_Index(a
);
165 is_(PyObject
*s
, PyObject
*a
)
167 PyObject
*a1
, *a2
, *result
= NULL
;
168 if (PyArg_UnpackTuple(a
,"is_", 2, 2, &a1
, &a2
)) {
169 result
= (a1
== a2
) ? Py_True
: Py_False
;
176 is_not(PyObject
*s
, PyObject
*a
)
178 PyObject
*a1
, *a2
, *result
= NULL
;
179 if (PyArg_UnpackTuple(a
,"is_not", 2, 2, &a1
, &a2
)) {
180 result
= (a1
!= a2
) ? Py_True
: Py_False
;
187 op_getslice(PyObject
*s
, PyObject
*a
)
192 if (!PyArg_ParseTuple(a
, "Onn:getslice", &a1
, &a2
, &a3
))
194 return PySequence_GetSlice(a1
, a2
, a3
);
198 op_setslice(PyObject
*s
, PyObject
*a
)
203 if (!PyArg_ParseTuple(a
, "OnnO:setslice", &a1
, &a2
, &a3
, &a4
))
206 if (-1 == PySequence_SetSlice(a1
, a2
, a3
, a4
))
213 op_delslice(PyObject
*s
, PyObject
*a
)
218 if (!PyArg_ParseTuple(a
, "Onn:delslice", &a1
, &a2
, &a3
))
221 if (-1 == PySequence_DelSlice(a1
, a2
, a3
))
231 #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, PyDoc_STR(DOC)},
232 #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)}, \
233 {#ALTOP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)},
234 #define spam1o(OP,DOC) {#OP, OP, METH_O, PyDoc_STR(DOC)},
235 #define spam2o(OP,ALTOP,DOC) {#OP, op_##OP, METH_O, PyDoc_STR(DOC)}, \
236 {#ALTOP, op_##OP, METH_O, PyDoc_STR(DOC)},
238 static struct PyMethodDef operator_methods
[] = {
241 "isCallable(a) -- Same as callable(a).")
243 "isNumberType(a) -- Return True if a has a numeric type, False otherwise.")
244 spam1o(isSequenceType
,
245 "isSequenceType(a) -- Return True if a has a sequence type, False otherwise.")
247 "truth(a) -- Return True if a is true, False otherwise.")
248 spam2(contains
,__contains__
,
249 "contains(a, b) -- Same as b in a (note reversed operands).")
250 spam1(sequenceIncludes
,
251 "sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).")
253 "indexOf(a, b) -- Return the first index of b in a.")
255 "countOf(a, b) -- Return the number of times b occurs in a.")
256 spam1o(isMappingType
,
257 "isMappingType(a) -- Return True if a has a mapping type, False otherwise.")
259 spam1(is_
, "is_(a, b) -- Same as a is b.")
260 spam1(is_not
, "is_not(a, b) -- Same as a is not b.")
261 spam2o(index
, __index__
, "index(a) -- Same as a.__index__()")
262 spam2(add
,__add__
, "add(a, b) -- Same as a + b.")
263 spam2(sub
,__sub__
, "sub(a, b) -- Same as a - b.")
264 spam2(mul
,__mul__
, "mul(a, b) -- Same as a * b.")
265 spam2(div
,__div__
, "div(a, b) -- Same as a / b when __future__.division is not in effect.")
266 spam2(floordiv
,__floordiv__
, "floordiv(a, b) -- Same as a // b.")
267 spam2(truediv
,__truediv__
, "truediv(a, b) -- Same as a / b when __future__.division is in effect.")
268 spam2(mod
,__mod__
, "mod(a, b) -- Same as a % b.")
269 spam2o(neg
,__neg__
, "neg(a) -- Same as -a.")
270 spam2o(pos
,__pos__
, "pos(a) -- Same as +a.")
271 spam2o(abs
,__abs__
, "abs(a) -- Same as abs(a).")
272 spam2o(inv
,__inv__
, "inv(a) -- Same as ~a.")
273 spam2o(invert
,__invert__
, "invert(a) -- Same as ~a.")
274 spam2(lshift
,__lshift__
, "lshift(a, b) -- Same as a << b.")
275 spam2(rshift
,__rshift__
, "rshift(a, b) -- Same as a >> b.")
276 spam2o(not_
,__not__
, "not_(a) -- Same as not a.")
277 spam2(and_
,__and__
, "and_(a, b) -- Same as a & b.")
278 spam2(xor,__xor__
, "xor(a, b) -- Same as a ^ b.")
279 spam2(or_
,__or__
, "or_(a, b) -- Same as a | b.")
280 spam2(iadd
,__iadd__
, "a = iadd(a, b) -- Same as a += b.")
281 spam2(isub
,__isub__
, "a = isub(a, b) -- Same as a -= b.")
282 spam2(imul
,__imul__
, "a = imul(a, b) -- Same as a *= b.")
283 spam2(idiv
,__idiv__
, "a = idiv(a, b) -- Same as a /= b when __future__.division is not in effect.")
284 spam2(ifloordiv
,__ifloordiv__
, "a = ifloordiv(a, b) -- Same as a //= b.")
285 spam2(itruediv
,__itruediv__
, "a = itruediv(a, b) -- Same as a /= b when __future__.division is in effect.")
286 spam2(imod
,__imod__
, "a = imod(a, b) -- Same as a %= b.")
287 spam2(ilshift
,__ilshift__
, "a = ilshift(a, b) -- Same as a <<= b.")
288 spam2(irshift
,__irshift__
, "a = irshift(a, b) -- Same as a >>= b.")
289 spam2(iand
,__iand__
, "a = iand(a, b) -- Same as a &= b.")
290 spam2(ixor
,__ixor__
, "a = ixor(a, b) -- Same as a ^= b.")
291 spam2(ior
,__ior__
, "a = ior(a, b) -- Same as a |= b.")
292 spam2(concat
,__concat__
,
293 "concat(a, b) -- Same as a + b, for a and b sequences.")
294 spam2(repeat
,__repeat__
,
295 "repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.")
296 spam2(iconcat
,__iconcat__
,
297 "a = iconcat(a, b) -- Same as a += b, for a and b sequences.")
298 spam2(irepeat
,__irepeat__
,
299 "a = irepeat(a, b) -- Same as a *= b, where a is a sequence, and b is an integer.")
300 spam2(getitem
,__getitem__
,
301 "getitem(a, b) -- Same as a[b].")
302 spam2(setitem
,__setitem__
,
303 "setitem(a, b, c) -- Same as a[b] = c.")
304 spam2(delitem
,__delitem__
,
305 "delitem(a, b) -- Same as del a[b].")
306 spam2(pow
,__pow__
, "pow(a, b) -- Same as a ** b.")
307 spam2(ipow
,__ipow__
, "a = ipow(a, b) -- Same as a **= b.")
308 spam2(getslice
,__getslice__
,
309 "getslice(a, b, c) -- Same as a[b:c].")
310 spam2(setslice
,__setslice__
,
311 "setslice(a, b, c, d) -- Same as a[b:c] = d.")
312 spam2(delslice
,__delslice__
,
313 "delslice(a, b, c) -- Same as del a[b:c].")
314 spam2(lt
,__lt__
, "lt(a, b) -- Same as a<b.")
315 spam2(le
,__le__
, "le(a, b) -- Same as a<=b.")
316 spam2(eq
,__eq__
, "eq(a, b) -- Same as a==b.")
317 spam2(ne
,__ne__
, "ne(a, b) -- Same as a!=b.")
318 spam2(gt
,__gt__
, "gt(a, b) -- Same as a>b.")
319 spam2(ge
,__ge__
, "ge(a, b) -- Same as a>=b.")
321 {NULL
, NULL
} /* sentinel */
325 /* itemgetter object **********************************************************/
333 static PyTypeObject itemgetter_type
;
336 itemgetter_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
338 itemgetterobject
*ig
;
342 if (!_PyArg_NoKeywords("itemgetter()", kwds
))
345 nitems
= PyTuple_GET_SIZE(args
);
347 if (!PyArg_UnpackTuple(args
, "itemgetter", 1, 1, &item
))
352 /* create itemgetterobject structure */
353 ig
= PyObject_GC_New(itemgetterobject
, &itemgetter_type
);
361 PyObject_GC_Track(ig
);
362 return (PyObject
*)ig
;
366 itemgetter_dealloc(itemgetterobject
*ig
)
368 PyObject_GC_UnTrack(ig
);
369 Py_XDECREF(ig
->item
);
374 itemgetter_traverse(itemgetterobject
*ig
, visitproc visit
, void *arg
)
381 itemgetter_call(itemgetterobject
*ig
, PyObject
*args
, PyObject
*kw
)
383 PyObject
*obj
, *result
;
384 Py_ssize_t i
, nitems
=ig
->nitems
;
386 if (!PyArg_UnpackTuple(args
, "itemgetter", 1, 1, &obj
))
389 return PyObject_GetItem(obj
, ig
->item
);
391 assert(PyTuple_Check(ig
->item
));
392 assert(PyTuple_GET_SIZE(ig
->item
) == nitems
);
394 result
= PyTuple_New(nitems
);
398 for (i
=0 ; i
< nitems
; i
++) {
399 PyObject
*item
, *val
;
400 item
= PyTuple_GET_ITEM(ig
->item
, i
);
401 val
= PyObject_GetItem(obj
, item
);
406 PyTuple_SET_ITEM(result
, i
, val
);
411 PyDoc_STRVAR(itemgetter_doc
,
412 "itemgetter(item, ...) --> itemgetter object\n\
414 Return a callable object that fetches the given item(s) from its operand.\n\
415 After, f=itemgetter(2), the call f(r) returns r[2].\n\
416 After, g=itemgetter(2,5,3), the call g(r) returns (r[2], r[5], r[3])");
418 static PyTypeObject itemgetter_type
= {
419 PyVarObject_HEAD_INIT(NULL
, 0)
420 "operator.itemgetter", /* tp_name */
421 sizeof(itemgetterobject
), /* tp_basicsize */
424 (destructor
)itemgetter_dealloc
, /* tp_dealloc */
430 0, /* tp_as_number */
431 0, /* tp_as_sequence */
432 0, /* tp_as_mapping */
434 (ternaryfunc
)itemgetter_call
, /* tp_call */
436 PyObject_GenericGetAttr
, /* tp_getattro */
438 0, /* tp_as_buffer */
439 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
, /* tp_flags */
440 itemgetter_doc
, /* tp_doc */
441 (traverseproc
)itemgetter_traverse
, /* tp_traverse */
443 0, /* tp_richcompare */
444 0, /* tp_weaklistoffset */
452 0, /* tp_descr_get */
453 0, /* tp_descr_set */
454 0, /* tp_dictoffset */
457 itemgetter_new
, /* tp_new */
462 /* attrgetter object **********************************************************/
470 static PyTypeObject attrgetter_type
;
473 attrgetter_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
475 attrgetterobject
*ag
;
479 if (!_PyArg_NoKeywords("attrgetter()", kwds
))
482 nattrs
= PyTuple_GET_SIZE(args
);
484 if (!PyArg_UnpackTuple(args
, "attrgetter", 1, 1, &attr
))
489 /* create attrgetterobject structure */
490 ag
= PyObject_GC_New(attrgetterobject
, &attrgetter_type
);
498 PyObject_GC_Track(ag
);
499 return (PyObject
*)ag
;
503 attrgetter_dealloc(attrgetterobject
*ag
)
505 PyObject_GC_UnTrack(ag
);
506 Py_XDECREF(ag
->attr
);
511 attrgetter_traverse(attrgetterobject
*ag
, visitproc visit
, void *arg
)
518 dotted_getattr(PyObject
*obj
, PyObject
*attr
)
522 #ifdef Py_USING_UNICODE
523 if (PyUnicode_Check(attr
)) {
524 attr
= _PyUnicode_AsDefaultEncodedString(attr
, NULL
);
530 if (!PyString_Check(attr
)) {
531 PyErr_SetString(PyExc_TypeError
,
532 "attribute name must be a string");
536 s
= PyString_AS_STRING(attr
);
539 PyObject
*newobj
, *str
;
541 str
= p
? PyString_FromStringAndSize(s
, (p
-s
)) :
542 PyString_FromString(s
);
547 newobj
= PyObject_GetAttr(obj
, str
);
553 if (p
== NULL
) break;
561 attrgetter_call(attrgetterobject
*ag
, PyObject
*args
, PyObject
*kw
)
563 PyObject
*obj
, *result
;
564 Py_ssize_t i
, nattrs
=ag
->nattrs
;
566 if (!PyArg_UnpackTuple(args
, "attrgetter", 1, 1, &obj
))
569 return dotted_getattr(obj
, ag
->attr
);
571 assert(PyTuple_Check(ag
->attr
));
572 assert(PyTuple_GET_SIZE(ag
->attr
) == nattrs
);
574 result
= PyTuple_New(nattrs
);
578 for (i
=0 ; i
< nattrs
; i
++) {
579 PyObject
*attr
, *val
;
580 attr
= PyTuple_GET_ITEM(ag
->attr
, i
);
581 val
= dotted_getattr(obj
, attr
);
586 PyTuple_SET_ITEM(result
, i
, val
);
591 PyDoc_STRVAR(attrgetter_doc
,
592 "attrgetter(attr, ...) --> attrgetter object\n\
594 Return a callable object that fetches the given attribute(s) from its operand.\n\
595 After, f=attrgetter('name'), the call f(r) returns r.name.\n\
596 After, g=attrgetter('name', 'date'), the call g(r) returns (r.name, r.date).\n\
597 After, h=attrgetter('name.first', 'name.last'), the call h(r) returns\n\
598 (r.name.first, r.name.last).");
600 static PyTypeObject attrgetter_type
= {
601 PyVarObject_HEAD_INIT(NULL
, 0)
602 "operator.attrgetter", /* tp_name */
603 sizeof(attrgetterobject
), /* tp_basicsize */
606 (destructor
)attrgetter_dealloc
, /* tp_dealloc */
612 0, /* tp_as_number */
613 0, /* tp_as_sequence */
614 0, /* tp_as_mapping */
616 (ternaryfunc
)attrgetter_call
, /* tp_call */
618 PyObject_GenericGetAttr
, /* tp_getattro */
620 0, /* tp_as_buffer */
621 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
, /* tp_flags */
622 attrgetter_doc
, /* tp_doc */
623 (traverseproc
)attrgetter_traverse
, /* tp_traverse */
625 0, /* tp_richcompare */
626 0, /* tp_weaklistoffset */
634 0, /* tp_descr_get */
635 0, /* tp_descr_set */
636 0, /* tp_dictoffset */
639 attrgetter_new
, /* tp_new */
644 /* methodcaller object **********************************************************/
651 } methodcallerobject
;
653 static PyTypeObject methodcaller_type
;
656 methodcaller_new(PyTypeObject
*type
, PyObject
*args
, PyObject
*kwds
)
658 methodcallerobject
*mc
;
659 PyObject
*name
, *newargs
;
661 if (PyTuple_GET_SIZE(args
) < 1) {
662 PyErr_SetString(PyExc_TypeError
, "methodcaller needs at least "
663 "one argument, the method name");
667 /* create methodcallerobject structure */
668 mc
= PyObject_GC_New(methodcallerobject
, &methodcaller_type
);
672 newargs
= PyTuple_GetSlice(args
, 1, PyTuple_GET_SIZE(args
));
673 if (newargs
== NULL
) {
679 name
= PyTuple_GET_ITEM(args
, 0);
686 PyObject_GC_Track(mc
);
687 return (PyObject
*)mc
;
691 methodcaller_dealloc(methodcallerobject
*mc
)
693 PyObject_GC_UnTrack(mc
);
694 Py_XDECREF(mc
->name
);
695 Py_XDECREF(mc
->args
);
696 Py_XDECREF(mc
->kwds
);
701 methodcaller_traverse(methodcallerobject
*mc
, visitproc visit
, void *arg
)
709 methodcaller_call(methodcallerobject
*mc
, PyObject
*args
, PyObject
*kw
)
711 PyObject
*method
, *obj
, *result
;
713 if (!PyArg_UnpackTuple(args
, "methodcaller", 1, 1, &obj
))
715 method
= PyObject_GetAttr(obj
, mc
->name
);
718 result
= PyObject_Call(method
, mc
->args
, mc
->kwds
);
723 PyDoc_STRVAR(methodcaller_doc
,
724 "methodcaller(name, ...) --> methodcaller object\n\
726 Return a callable object that calls the given method on its operand.\n\
727 After, f = methodcaller('name'), the call f(r) returns r.name().\n\
728 After, g = methodcaller('name', 'date', foo=1), the call g(r) returns\n\
729 r.name('date', foo=1).");
731 static PyTypeObject methodcaller_type
= {
732 PyVarObject_HEAD_INIT(NULL
, 0)
733 "operator.methodcaller", /* tp_name */
734 sizeof(methodcallerobject
), /* tp_basicsize */
737 (destructor
)methodcaller_dealloc
, /* tp_dealloc */
743 0, /* tp_as_number */
744 0, /* tp_as_sequence */
745 0, /* tp_as_mapping */
747 (ternaryfunc
)methodcaller_call
, /* tp_call */
749 PyObject_GenericGetAttr
, /* tp_getattro */
751 0, /* tp_as_buffer */
752 Py_TPFLAGS_DEFAULT
| Py_TPFLAGS_HAVE_GC
,/* tp_flags */
753 methodcaller_doc
, /* tp_doc */
754 (traverseproc
)methodcaller_traverse
, /* tp_traverse */
756 0, /* tp_richcompare */
757 0, /* tp_weaklistoffset */
765 0, /* tp_descr_get */
766 0, /* tp_descr_set */
767 0, /* tp_dictoffset */
770 methodcaller_new
, /* tp_new */
775 /* Initialization function for the module (*must* be called initoperator) */
782 /* Create the module and add the functions */
783 m
= Py_InitModule4("operator", operator_methods
, operator_doc
,
784 (PyObject
*)NULL
, PYTHON_API_VERSION
);
788 if (PyType_Ready(&itemgetter_type
) < 0)
790 Py_INCREF(&itemgetter_type
);
791 PyModule_AddObject(m
, "itemgetter", (PyObject
*)&itemgetter_type
);
793 if (PyType_Ready(&attrgetter_type
) < 0)
795 Py_INCREF(&attrgetter_type
);
796 PyModule_AddObject(m
, "attrgetter", (PyObject
*)&attrgetter_type
);
798 if (PyType_Ready(&methodcaller_type
) < 0)
800 Py_INCREF(&methodcaller_type
);
801 PyModule_AddObject(m
, "methodcaller", (PyObject
*)&methodcaller_type
);