Mercurial > cpython-lru_cache-weakref
annotate Modules/operator.c @ 32975:9b188158181f legacy-trunk
Typo fix; use 'in-place' instead of 'inplace'
| author | Andrew M. Kuchling <amk@amk.ca> |
|---|---|
| date | Fri, 06 Aug 2004 18:55:09 +0000 |
| parents | d7630ce7aa9f |
| children | 97c97194e64b ddc2276c247e |
| rev | line source |
|---|---|
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22805
diff
changeset
|
1 |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22805
diff
changeset
|
2 #include "Python.h" |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22805
diff
changeset
|
3 |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22805
diff
changeset
|
4 PyDoc_STRVAR(operator_doc, |
|
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22805
diff
changeset
|
5 "Operator interface.\n\ |
| 3844 | 6 \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 class methods; variants without leading and trailing\n\ | |
|
23832
ed1ba37a46b7
Patch #568124: Add doc string macros.
Martin v. Löwis <martin@v.loewis.de>
parents:
22805
diff
changeset
|
11 '__' are also provided for convenience."); |
| 3844 | 12 |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
13 #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ |
| 3844 | 14 return AOP(a1); } |
| 15 | |
| 13422 | 16 #define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 3844 | 17 PyObject *a1, *a2; \ |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
18 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ |
| 3844 | 19 return AOP(a1,a2); } |
| 20 | |
| 13422 | 21 #define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 3844 | 22 PyObject *a1; int a2; \ |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
23 if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \ |
| 3844 | 24 return AOP(a1,a2); } |
| 25 | |
| 13422 | 26 #define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 3844 | 27 PyObject *a1, *a2; \ |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
28 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ |
| 3844 | 29 if(-1 == AOP(a1,a2)) return NULL; \ |
| 30 Py_INCREF(Py_None); \ | |
| 31 return Py_None; } | |
| 32 | |
| 13422 | 33 #define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 3844 | 34 PyObject *a1, *a2, *a3; \ |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
35 if(! PyArg_UnpackTuple(a,#OP,3,3,&a1,&a2,&a3)) return NULL; \ |
| 3844 | 36 if(-1 == AOP(a1,a2,a3)) return NULL; \ |
| 37 Py_INCREF(Py_None); \ | |
| 38 return Py_None; } | |
| 39 | |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
40 #define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a1) { \ |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
41 long r; \ |
| 3844 | 42 if(-1 == (r=AOP(a1))) return NULL; \ |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
43 return PyBool_FromLong(r); } |
| 3844 | 44 |
| 13422 | 45 #define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 3844 | 46 PyObject *a1, *a2; long r; \ |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
47 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ |
| 3844 | 48 if(-1 == (r=AOP(a1,a2))) return NULL; \ |
| 49 return PyInt_FromLong(r); } | |
| 50 | |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
51 #define spami2b(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
52 PyObject *a1, *a2; long r; \ |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
53 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
54 if(-1 == (r=AOP(a1,a2))) return NULL; \ |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
55 return PyBool_FromLong(r); } |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
56 |
|
19111
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
57 #define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \ |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
58 PyObject *a1, *a2; \ |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
59 if(! PyArg_UnpackTuple(a,#OP,2,2,&a1,&a2)) return NULL; \ |
|
19111
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
60 return PyObject_RichCompare(a1,a2,A); } |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
61 |
| 3844 | 62 spami(isCallable , PyCallable_Check) |
| 63 spami(isNumberType , PyNumber_Check) | |
| 64 spami(truth , PyObject_IsTrue) | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
65 spam2(op_add , PyNumber_Add) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
66 spam2(op_sub , PyNumber_Subtract) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
67 spam2(op_mul , PyNumber_Multiply) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
68 spam2(op_div , PyNumber_Divide) |
|
19111
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
69 spam2(op_floordiv , PyNumber_FloorDivide) |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
70 spam2(op_truediv , PyNumber_TrueDivide) |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
71 spam2(op_mod , PyNumber_Remainder) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
72 spam1(op_neg , PyNumber_Negative) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
73 spam1(op_pos , PyNumber_Positive) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
74 spam1(op_abs , PyNumber_Absolute) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
75 spam1(op_inv , PyNumber_Invert) |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
76 spam1(op_invert , PyNumber_Invert) |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
77 spam2(op_lshift , PyNumber_Lshift) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
78 spam2(op_rshift , PyNumber_Rshift) |
| 7936 | 79 spami(op_not_ , PyObject_Not) |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
80 spam2(op_and_ , PyNumber_And) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
81 spam2(op_xor , PyNumber_Xor) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
82 spam2(op_or_ , PyNumber_Or) |
| 3844 | 83 spami(isSequenceType , PySequence_Check) |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
84 spam2(op_concat , PySequence_Concat) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
85 spamoi(op_repeat , PySequence_Repeat) |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
86 spami2b(op_contains , PySequence_Contains) |
|
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
87 spami2b(sequenceIncludes, PySequence_Contains) |
| 3844 | 88 spami2(indexOf , PySequence_Index) |
| 89 spami2(countOf , PySequence_Count) | |
| 90 spami(isMappingType , PyMapping_Check) | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
91 spam2(op_getitem , PyObject_GetItem) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
92 spam2n(op_delitem , PyObject_DelItem) |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
93 spam3n(op_setitem , PyObject_SetItem) |
|
19111
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
94 spamrc(op_lt , Py_LT) |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
95 spamrc(op_le , Py_LE) |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
96 spamrc(op_eq , Py_EQ) |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
97 spamrc(op_ne , Py_NE) |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
98 spamrc(op_gt , Py_GT) |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
99 spamrc(op_ge , Py_GE) |
| 3844 | 100 |
| 101 static PyObject* | |
|
24887
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
102 op_pow(PyObject *s, PyObject *a) |
|
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
103 { |
|
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
104 PyObject *a1, *a2; |
|
26818
e094a03a80ff
SF patch #659536: Use PyArg_UnpackTuple where possible.
Raymond Hettinger <python@rcn.com>
parents:
24887
diff
changeset
|
105 if (PyArg_UnpackTuple(a,"pow", 2, 2, &a1, &a2)) |
|
24887
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
106 return PyNumber_Power(a1, a2, Py_None); |
|
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
107 return NULL; |
|
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
108 } |
|
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
109 |
|
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
110 static PyObject* |
|
27290
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
111 is_(PyObject *s, PyObject *a) |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
112 { |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
113 PyObject *a1, *a2, *result = NULL; |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
114 if (PyArg_UnpackTuple(a,"is_", 2, 2, &a1, &a2)) { |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
115 result = (a1 == a2) ? Py_True : Py_False; |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
116 Py_INCREF(result); |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
117 } |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
118 return result; |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
119 } |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
120 |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
121 static PyObject* |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
122 is_not(PyObject *s, PyObject *a) |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
123 { |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
124 PyObject *a1, *a2, *result = NULL; |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
125 if (PyArg_UnpackTuple(a,"is_not", 2, 2, &a1, &a2)) { |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
126 result = (a1 != a2) ? Py_True : Py_False; |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
127 Py_INCREF(result); |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
128 } |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
129 return result; |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
130 } |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
131 |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
132 static PyObject* |
| 13422 | 133 op_getslice(PyObject *s, PyObject *a) |
| 3844 | 134 { |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
135 PyObject *a1; |
|
6183
64e194c5f854
Some long variables should have been int to match the 'i' format specifier.
Guido van Rossum <guido@python.org>
parents:
4775
diff
changeset
|
136 int a2,a3; |
| 3844 | 137 |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
138 if (!PyArg_ParseTuple(a,"Oii:getslice",&a1,&a2,&a3)) |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
139 return NULL; |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
140 return PySequence_GetSlice(a1,a2,a3); |
| 3844 | 141 } |
| 142 | |
| 143 static PyObject* | |
| 13422 | 144 op_setslice(PyObject *s, PyObject *a) |
| 3844 | 145 { |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
146 PyObject *a1, *a4; |
|
6183
64e194c5f854
Some long variables should have been int to match the 'i' format specifier.
Guido van Rossum <guido@python.org>
parents:
4775
diff
changeset
|
147 int a2,a3; |
| 3844 | 148 |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
149 if (!PyArg_ParseTuple(a,"OiiO:setslice",&a1,&a2,&a3,&a4)) |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
150 return NULL; |
| 3844 | 151 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
152 if (-1 == PySequence_SetSlice(a1,a2,a3,a4)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
153 return NULL; |
| 3844 | 154 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
155 Py_INCREF(Py_None); |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
156 return Py_None; |
| 3844 | 157 } |
| 158 | |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
159 static PyObject* |
| 13422 | 160 op_delslice(PyObject *s, PyObject *a) |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
161 { |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
162 PyObject *a1; |
|
6183
64e194c5f854
Some long variables should have been int to match the 'i' format specifier.
Guido van Rossum <guido@python.org>
parents:
4775
diff
changeset
|
163 int a2,a3; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
164 |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
165 if(! PyArg_ParseTuple(a,"Oii:delslice",&a1,&a2,&a3)) |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
166 return NULL; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
167 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
168 if (-1 == PySequence_DelSlice(a1,a2,a3)) |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
169 return NULL; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
170 |
|
4775
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
171 Py_INCREF(Py_None); |
|
0d0c413b6f25
Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents:
4580
diff
changeset
|
172 return Py_None; |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
173 } |
|
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
174 |
| 3844 | 175 #undef spam1 |
| 176 #undef spam2 | |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
177 #undef spam1o |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
178 #undef spam1o |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
179 #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, PyDoc_STR(DOC)}, |
| 13422 | 180 #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, DOC}, \ |
|
24796
de71e6fe64b0
Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents:
24471
diff
changeset
|
181 {#ALTOP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)}, |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
182 #define spam1o(OP,DOC) {#OP, OP, METH_O, PyDoc_STR(DOC)}, |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
183 #define spam2o(OP,ALTOP,DOC) {#OP, op_##OP, METH_O, DOC}, \ |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
184 {#ALTOP, op_##OP, METH_O, PyDoc_STR(DOC)}, |
| 3844 | 185 |
| 186 static struct PyMethodDef operator_methods[] = { | |
| 187 | |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
188 spam1o(isCallable, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
189 "isCallable(a) -- Same as callable(a).") |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
190 spam1o(isNumberType, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
191 "isNumberType(a) -- Return True if a has a numeric type, False otherwise.") |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
192 spam1o(isSequenceType, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
193 "isSequenceType(a) -- Return True if a has a sequence type, False otherwise.") |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
194 spam1o(truth, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
195 "truth(a) -- Return True if a is true, False otherwise.") |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
196 spam2(contains,__contains__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
197 "contains(a, b) -- Same as b in a (note reversed operands).") |
|
14654
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
198 spam1(sequenceIncludes, |
|
0bd746bc7627
Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents:
13651
diff
changeset
|
199 "sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
200 spam1(indexOf, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
201 "indexOf(a, b) -- Return the first index of b in a.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
202 spam1(countOf, |
|
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
203 "countOf(a, b) -- Return the number of times b occurs in a.") |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
204 spam1o(isMappingType, |
|
22785
aa8d59823add
Add the 'bool' type and its values 'False' and 'True', as described in
Guido van Rossum <guido@python.org>
parents:
19111
diff
changeset
|
205 "isMappingType(a) -- Return True if a has a mapping type, False otherwise.") |
| 3844 | 206 |
|
27290
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
207 spam1(is_, "is_(a, b) -- Same as a is b.") |
|
e83a42a90df1
SF patch #670423: Add missing identity tests to operator.c
Raymond Hettinger <python@rcn.com>
parents:
27044
diff
changeset
|
208 spam1(is_not, "is_not(a, b) -- Same as a is not b.") |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
209 spam2(add,__add__, "add(a, b) -- Same as a + b.") |
|
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
210 spam2(sub,__sub__, "sub(a, b) -- Same as a - b.") |
|
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
211 spam2(mul,__mul__, "mul(a, b) -- Same as a * b.") |
|
19111
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
212 spam2(div,__div__, "div(a, b) -- Same as a / b when __future__.division is not in effect.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
213 spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
214 spam2(truediv,__truediv__, "truediv(a, b) -- Same as a / b when __future__.division is in effect.") |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
215 spam2(mod,__mod__, "mod(a, b) -- Same as a % b.") |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
216 spam2o(neg,__neg__, "neg(a) -- Same as -a.") |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
217 spam2o(pos,__pos__, "pos(a) -- Same as +a.") |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
218 spam2o(abs,__abs__, "abs(a) -- Same as abs(a).") |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
219 spam2o(inv,__inv__, "inv(a) -- Same as ~a.") |
|
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
220 spam2o(invert,__invert__, "invert(a) -- Same as ~a.") |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
221 spam2(lshift,__lshift__, "lshift(a, b) -- Same as a << b.") |
|
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
222 spam2(rshift,__rshift__, "rshift(a, b) -- Same as a >> b.") |
|
27044
23280a64288e
SF patch 660559: Use METH_O and METH_NOARGS where possible
Raymond Hettinger <python@rcn.com>
parents:
26818
diff
changeset
|
223 spam2o(not_,__not__, "not_(a) -- Same as not a.") |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
224 spam2(and_,__and__, "and_(a, b) -- Same as a & b.") |
|
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
225 spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") |
|
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
226 spam2(or_,__or__, "or_(a, b) -- Same as a | b.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
227 spam2(concat,__concat__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
228 "concat(a, b) -- Same as a + b, for a and b sequences.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
229 spam2(repeat,__repeat__, |
|
4580
11bd4f497742
Correct typo -- repeat implements *, not +.
Guido van Rossum <guido@python.org>
parents:
4104
diff
changeset
|
230 "repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
231 spam2(getitem,__getitem__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
232 "getitem(a, b) -- Same as a[b].") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
233 spam2(setitem,__setitem__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
234 "setitem(a, b, c) -- Same as a[b] = c.") |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
235 spam2(delitem,__delitem__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
236 "delitem(a, b) -- Same as del a[b].") |
|
24887
d797cfa8ca0d
Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents:
24796
diff
changeset
|
237 spam2(pow,__pow__, "pow(a, b) -- Same as a**b.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
238 spam2(getslice,__getslice__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
239 "getslice(a, b, c) -- Same as a[b:c].") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
240 spam2(setslice,__setslice__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
241 "setslice(a, b, c, d) -- Same as a[b:c] = d.") |
|
4089
9f70d995d027
Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents:
4033
diff
changeset
|
242 spam2(delslice,__delslice__, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
243 "delslice(a, b, c) -- Same as del a[b:c].") |
|
19111
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
244 spam2(lt,__lt__, "lt(a, b) -- Same as a<b.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
245 spam2(le,__le__, "le(a, b) -- Same as a<=b.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
246 spam2(eq,__eq__, "eq(a, b) -- Same as a==b.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
247 spam2(ne,__ne__, "ne(a, b) -- Same as a!=b.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
248 spam2(gt,__gt__, "gt(a, b) -- Same as a>b.") |
|
6ba441507220
Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents:
14654
diff
changeset
|
249 spam2(ge,__ge__, "ge(a, b) -- Same as a>=b.") |
|
4033
5592de9656de
Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents:
3976
diff
changeset
|
250 |
| 3844 | 251 {NULL, NULL} /* sentinel */ |
| 252 | |
| 253 }; | |
| 254 | |
|
31052
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
255 /* itemgetter object **********************************************************/ |
| 3844 | 256 |
|
31052
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
257 typedef struct { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
258 PyObject_HEAD |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
259 PyObject *item; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
260 } itemgetterobject; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
261 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
262 static PyTypeObject itemgetter_type; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
263 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
264 static PyObject * |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
265 itemgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
266 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
267 itemgetterobject *ig; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
268 PyObject *item; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
269 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
270 if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &item)) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
271 return NULL; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
272 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
273 /* create itemgetterobject structure */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
274 ig = PyObject_GC_New(itemgetterobject, &itemgetter_type); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
275 if (ig == NULL) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
276 return NULL; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
277 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
278 Py_INCREF(item); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
279 ig->item = item; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
280 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
281 PyObject_GC_Track(ig); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
282 return (PyObject *)ig; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
283 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
284 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
285 static void |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
286 itemgetter_dealloc(itemgetterobject *ig) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
287 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
288 PyObject_GC_UnTrack(ig); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
289 Py_XDECREF(ig->item); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
290 PyObject_GC_Del(ig); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
291 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
292 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
293 static int |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
294 itemgetter_traverse(itemgetterobject *ig, visitproc visit, void *arg) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
295 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
296 if (ig->item) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
297 return visit(ig->item, arg); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
298 return 0; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
299 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
300 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
301 static PyObject * |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
302 itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
303 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
304 PyObject * obj; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
305 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
306 if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
307 return NULL; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
308 return PyObject_GetItem(obj, ig->item); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
309 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
310 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
311 PyDoc_STRVAR(itemgetter_doc, |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
312 "itemgetter(item) --> itemgetter object\n\ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
313 \n\ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
314 Return a callable object that fetches the given item from its operand.\n\ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
315 After, f=itemgetter(2), the call f(b) returns b[2]."); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
316 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
317 static PyTypeObject itemgetter_type = { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
318 PyObject_HEAD_INIT(NULL) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
319 0, /* ob_size */ |
| 31110 | 320 "operator.itemgetter", /* tp_name */ |
|
31052
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
321 sizeof(itemgetterobject), /* tp_basicsize */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
322 0, /* tp_itemsize */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
323 /* methods */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
324 (destructor)itemgetter_dealloc, /* tp_dealloc */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
325 0, /* tp_print */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
326 0, /* tp_getattr */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
327 0, /* tp_setattr */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
328 0, /* tp_compare */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
329 0, /* tp_repr */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
330 0, /* tp_as_number */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
331 0, /* tp_as_sequence */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
332 0, /* tp_as_mapping */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
333 0, /* tp_hash */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
334 (ternaryfunc)itemgetter_call, /* tp_call */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
335 0, /* tp_str */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
336 PyObject_GenericGetAttr, /* tp_getattro */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
337 0, /* tp_setattro */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
338 0, /* tp_as_buffer */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
339 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
340 itemgetter_doc, /* tp_doc */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
341 (traverseproc)itemgetter_traverse, /* tp_traverse */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
342 0, /* tp_clear */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
343 0, /* tp_richcompare */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
344 0, /* tp_weaklistoffset */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
345 0, /* tp_iter */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
346 0, /* tp_iternext */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
347 0, /* tp_methods */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
348 0, /* tp_members */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
349 0, /* tp_getset */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
350 0, /* tp_base */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
351 0, /* tp_dict */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
352 0, /* tp_descr_get */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
353 0, /* tp_descr_set */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
354 0, /* tp_dictoffset */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
355 0, /* tp_init */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
356 0, /* tp_alloc */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
357 itemgetter_new, /* tp_new */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
358 0, /* tp_free */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
359 }; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
360 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
361 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
362 /* attrgetter object **********************************************************/ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
363 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
364 typedef struct { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
365 PyObject_HEAD |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
366 PyObject *attr; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
367 } attrgetterobject; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
368 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
369 static PyTypeObject attrgetter_type; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
370 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
371 static PyObject * |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
372 attrgetter_new(PyTypeObject *type, PyObject *args, PyObject *kwds) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
373 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
374 attrgetterobject *ag; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
375 PyObject *attr; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
376 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
377 if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &attr)) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
378 return NULL; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
379 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
380 /* create attrgetterobject structure */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
381 ag = PyObject_GC_New(attrgetterobject, &attrgetter_type); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
382 if (ag == NULL) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
383 return NULL; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
384 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
385 Py_INCREF(attr); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
386 ag->attr = attr; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
387 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
388 PyObject_GC_Track(ag); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
389 return (PyObject *)ag; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
390 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
391 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
392 static void |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
393 attrgetter_dealloc(attrgetterobject *ag) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
394 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
395 PyObject_GC_UnTrack(ag); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
396 Py_XDECREF(ag->attr); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
397 PyObject_GC_Del(ag); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
398 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
399 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
400 static int |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
401 attrgetter_traverse(attrgetterobject *ag, visitproc visit, void *arg) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
402 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
403 if (ag->attr) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
404 return visit(ag->attr, arg); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
405 return 0; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
406 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
407 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
408 static PyObject * |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
409 attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
410 { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
411 PyObject * obj; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
412 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
413 if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
414 return NULL; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
415 return PyObject_GetAttr(obj, ag->attr); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
416 } |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
417 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
418 PyDoc_STRVAR(attrgetter_doc, |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
419 "attrgetter(attr) --> attrgetter object\n\ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
420 \n\ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
421 Return a callable object that fetches the given attribute from its operand.\n\ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
422 After, f=attrgetter('name'), the call f(b) returns b.name."); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
423 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
424 static PyTypeObject attrgetter_type = { |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
425 PyObject_HEAD_INIT(NULL) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
426 0, /* ob_size */ |
| 31110 | 427 "operator.attrgetter", /* tp_name */ |
|
31052
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
428 sizeof(attrgetterobject), /* tp_basicsize */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
429 0, /* tp_itemsize */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
430 /* methods */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
431 (destructor)attrgetter_dealloc, /* tp_dealloc */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
432 0, /* tp_print */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
433 0, /* tp_getattr */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
434 0, /* tp_setattr */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
435 0, /* tp_compare */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
436 0, /* tp_repr */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
437 0, /* tp_as_number */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
438 0, /* tp_as_sequence */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
439 0, /* tp_as_mapping */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
440 0, /* tp_hash */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
441 (ternaryfunc)attrgetter_call, /* tp_call */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
442 0, /* tp_str */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
443 PyObject_GenericGetAttr, /* tp_getattro */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
444 0, /* tp_setattro */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
445 0, /* tp_as_buffer */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
446 Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC, /* tp_flags */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
447 attrgetter_doc, /* tp_doc */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
448 (traverseproc)attrgetter_traverse, /* tp_traverse */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
449 0, /* tp_clear */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
450 0, /* tp_richcompare */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
451 0, /* tp_weaklistoffset */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
452 0, /* tp_iter */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
453 0, /* tp_iternext */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
454 0, /* tp_methods */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
455 0, /* tp_members */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
456 0, /* tp_getset */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
457 0, /* tp_base */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
458 0, /* tp_dict */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
459 0, /* tp_descr_get */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
460 0, /* tp_descr_set */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
461 0, /* tp_dictoffset */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
462 0, /* tp_init */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
463 0, /* tp_alloc */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
464 attrgetter_new, /* tp_new */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
465 0, /* tp_free */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
466 }; |
| 3844 | 467 /* Initialization function for the module (*must* be called initoperator) */ |
| 468 | |
|
24471
f66b3a3509c7
Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents:
23832
diff
changeset
|
469 PyMODINIT_FUNC |
|
13651
8a063423e0b7
Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents:
13424
diff
changeset
|
470 initoperator(void) |
| 3844 | 471 { |
|
31052
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
472 PyObject *m; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
473 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
474 /* Create the module and add the functions */ |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
475 m = Py_InitModule4("operator", operator_methods, operator_doc, |
|
8414
4064b6729537
Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents:
8406
diff
changeset
|
476 (PyObject*)NULL, PYTHON_API_VERSION); |
|
31052
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
477 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
478 if (PyType_Ready(&itemgetter_type) < 0) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
479 return; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
480 Py_INCREF(&itemgetter_type); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
481 PyModule_AddObject(m, "itemgetter", (PyObject *)&itemgetter_type); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
482 |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
483 if (PyType_Ready(&attrgetter_type) < 0) |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
484 return; |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
485 Py_INCREF(&attrgetter_type); |
|
456e274f8602
As discussed on python-dev, added two extractor functions to the
Raymond Hettinger <python@rcn.com>
parents:
27290
diff
changeset
|
486 PyModule_AddObject(m, "attrgetter", (PyObject *)&attrgetter_type); |
| 3844 | 487 } |
