Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 1 | |
| 2 | #include "Python.h" |
| 3 | |
| 4 | PyDoc_STRVAR(operator_doc, |
| 5 | "Operator interface.\n\ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 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\ |
Martin v. Löwis | 14f8b4c | 2002-06-13 20:33:02 +0000 | [diff] [blame] | 11 | '__' are also provided for convenience."); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 12 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 13 | #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 14 | PyObject *a1; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 15 | if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 16 | return AOP(a1); } |
| 17 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 18 | #define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 19 | PyObject *a1, *a2; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 20 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 21 | return AOP(a1,a2); } |
| 22 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 23 | #define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 24 | PyObject *a1; int a2; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 25 | if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 26 | return AOP(a1,a2); } |
| 27 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 28 | #define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 29 | PyObject *a1, *a2; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 30 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 31 | if(-1 == AOP(a1,a2)) return NULL; \ |
| 32 | Py_INCREF(Py_None); \ |
| 33 | return Py_None; } |
| 34 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 35 | #define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 36 | PyObject *a1, *a2, *a3; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 37 | if(! PyArg_ParseTuple(a,"OOO:" #OP,&a1,&a2,&a3)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 38 | if(-1 == AOP(a1,a2,a3)) return NULL; \ |
| 39 | Py_INCREF(Py_None); \ |
| 40 | return Py_None; } |
| 41 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 42 | #define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 43 | PyObject *a1; long r; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 44 | if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 45 | if(-1 == (r=AOP(a1))) return NULL; \ |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 46 | return PyBool_FromLong(r); } |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 47 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 48 | #define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 49 | PyObject *a1, *a2; long r; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 50 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 51 | if(-1 == (r=AOP(a1,a2))) return NULL; \ |
| 52 | return PyInt_FromLong(r); } |
| 53 | |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 54 | #define spami2b(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 55 | PyObject *a1, *a2; long r; \ |
| 56 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
| 57 | if(-1 == (r=AOP(a1,a2))) return NULL; \ |
| 58 | return PyBool_FromLong(r); } |
| 59 | |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 60 | #define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 61 | PyObject *a1, *a2; \ |
| 62 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
| 63 | return PyObject_RichCompare(a1,a2,A); } |
| 64 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 65 | spami(isCallable , PyCallable_Check) |
| 66 | spami(isNumberType , PyNumber_Check) |
| 67 | spami(truth , PyObject_IsTrue) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 68 | spam2(op_add , PyNumber_Add) |
| 69 | spam2(op_sub , PyNumber_Subtract) |
| 70 | spam2(op_mul , PyNumber_Multiply) |
| 71 | spam2(op_div , PyNumber_Divide) |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 72 | spam2(op_floordiv , PyNumber_FloorDivide) |
| 73 | spam2(op_truediv , PyNumber_TrueDivide) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 74 | spam2(op_mod , PyNumber_Remainder) |
| 75 | spam1(op_neg , PyNumber_Negative) |
| 76 | spam1(op_pos , PyNumber_Positive) |
| 77 | spam1(op_abs , PyNumber_Absolute) |
| 78 | spam1(op_inv , PyNumber_Invert) |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 79 | spam1(op_invert , PyNumber_Invert) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 80 | spam2(op_lshift , PyNumber_Lshift) |
| 81 | spam2(op_rshift , PyNumber_Rshift) |
Guido van Rossum | 99c185e | 1998-04-09 17:54:26 +0000 | [diff] [blame] | 82 | spami(op_not_ , PyObject_Not) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 83 | spam2(op_and_ , PyNumber_And) |
| 84 | spam2(op_xor , PyNumber_Xor) |
| 85 | spam2(op_or_ , PyNumber_Or) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 86 | spami(isSequenceType , PySequence_Check) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 87 | spam2(op_concat , PySequence_Concat) |
| 88 | spamoi(op_repeat , PySequence_Repeat) |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 89 | spami2b(op_contains , PySequence_Contains) |
| 90 | spami2b(sequenceIncludes, PySequence_Contains) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 91 | spami2(indexOf , PySequence_Index) |
| 92 | spami2(countOf , PySequence_Count) |
| 93 | spami(isMappingType , PyMapping_Check) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 94 | spam2(op_getitem , PyObject_GetItem) |
| 95 | spam2n(op_delitem , PyObject_DelItem) |
| 96 | spam3n(op_setitem , PyObject_SetItem) |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 97 | spamrc(op_lt , Py_LT) |
| 98 | spamrc(op_le , Py_LE) |
| 99 | spamrc(op_eq , Py_EQ) |
| 100 | spamrc(op_ne , Py_NE) |
| 101 | spamrc(op_gt , Py_GT) |
| 102 | spamrc(op_ge , Py_GE) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 103 | |
| 104 | static PyObject* |
Raymond Hettinger | 5959c55 | 2002-08-19 03:19:09 +0000 | [diff] [blame] | 105 | op_pow(PyObject *s, PyObject *a) |
| 106 | { |
| 107 | PyObject *a1, *a2; |
| 108 | if (PyArg_ParseTuple(a,"OO:pow",&a1,&a2)) |
| 109 | return PyNumber_Power(a1, a2, Py_None); |
| 110 | return NULL; |
| 111 | } |
| 112 | |
| 113 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 114 | op_getslice(PyObject *s, PyObject *a) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 115 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 116 | PyObject *a1; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 117 | int a2,a3; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 118 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 119 | if (!PyArg_ParseTuple(a,"Oii:getslice",&a1,&a2,&a3)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 120 | return NULL; |
| 121 | return PySequence_GetSlice(a1,a2,a3); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 122 | } |
| 123 | |
| 124 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 125 | op_setslice(PyObject *s, PyObject *a) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 126 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 127 | PyObject *a1, *a4; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 128 | int a2,a3; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 129 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 130 | if (!PyArg_ParseTuple(a,"OiiO:setslice",&a1,&a2,&a3,&a4)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 131 | return NULL; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 132 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 133 | if (-1 == PySequence_SetSlice(a1,a2,a3,a4)) |
| 134 | return NULL; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 135 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 136 | Py_INCREF(Py_None); |
| 137 | return Py_None; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 138 | } |
| 139 | |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 140 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 141 | op_delslice(PyObject *s, PyObject *a) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 142 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 143 | PyObject *a1; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 144 | int a2,a3; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 145 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 146 | if(! PyArg_ParseTuple(a,"Oii:delslice",&a1,&a2,&a3)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 147 | return NULL; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 148 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 149 | if (-1 == PySequence_DelSlice(a1,a2,a3)) |
| 150 | return NULL; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 151 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 152 | Py_INCREF(Py_None); |
| 153 | return Py_None; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 154 | } |
| 155 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 156 | #undef spam1 |
| 157 | #undef spam2 |
Neal Norwitz | 200788c | 2002-08-13 22:20:41 +0000 | [diff] [blame] | 158 | #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, PyDoc_STR(DOC)}, |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 159 | #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, DOC}, \ |
Neal Norwitz | 200788c | 2002-08-13 22:20:41 +0000 | [diff] [blame] | 160 | {#ALTOP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)}, |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 161 | |
| 162 | static struct PyMethodDef operator_methods[] = { |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 163 | |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 164 | spam1(isCallable, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 165 | "isCallable(a) -- Same as callable(a).") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 166 | spam1(isNumberType, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 167 | "isNumberType(a) -- Return True if a has a numeric type, False otherwise.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 168 | spam1(isSequenceType, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 169 | "isSequenceType(a) -- Return True if a has a sequence type, False otherwise.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 170 | spam1(truth, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 171 | "truth(a) -- Return True if a is true, False otherwise.") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 172 | spam2(contains,__contains__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 173 | "contains(a, b) -- Same as b in a (note reversed operands).") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 174 | spam1(sequenceIncludes, |
| 175 | "sequenceIncludes(a, b) -- Same as b in a (note reversed operands; deprecated).") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 176 | spam1(indexOf, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 177 | "indexOf(a, b) -- Return the first index of b in a.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 178 | spam1(countOf, |
| 179 | "countOf(a, b) -- Return the number of times b occurs in a.") |
| 180 | spam1(isMappingType, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 181 | "isMappingType(a) -- Return True if a has a mapping type, False otherwise.") |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 182 | |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 183 | spam2(add,__add__, "add(a, b) -- Same as a + b.") |
| 184 | spam2(sub,__sub__, "sub(a, b) -- Same as a - b.") |
| 185 | spam2(mul,__mul__, "mul(a, b) -- Same as a * b.") |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 186 | spam2(div,__div__, "div(a, b) -- Same as a / b when __future__.division is not in effect.") |
| 187 | spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.") |
| 188 | spam2(truediv,__truediv__, "truediv(a, b) -- Same as a / b when __future__.division is in effect.") |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 189 | spam2(mod,__mod__, "mod(a, b) -- Same as a % b.") |
| 190 | spam2(neg,__neg__, "neg(a) -- Same as -a.") |
| 191 | spam2(pos,__pos__, "pos(a) -- Same as +a.") |
| 192 | spam2(abs,__abs__, "abs(a) -- Same as abs(a).") |
| 193 | spam2(inv,__inv__, "inv(a) -- Same as ~a.") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 194 | spam2(invert,__invert__, "invert(a) -- Same as ~a.") |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 195 | spam2(lshift,__lshift__, "lshift(a, b) -- Same as a << b.") |
| 196 | spam2(rshift,__rshift__, "rshift(a, b) -- Same as a >> b.") |
| 197 | spam2(not_,__not__, "not_(a) -- Same as not a.") |
| 198 | spam2(and_,__and__, "and_(a, b) -- Same as a & b.") |
| 199 | spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") |
| 200 | spam2(or_,__or__, "or_(a, b) -- Same as a | b.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 201 | spam2(concat,__concat__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 202 | "concat(a, b) -- Same as a + b, for a and b sequences.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 203 | spam2(repeat,__repeat__, |
Guido van Rossum | 36a484f | 1996-12-05 19:01:16 +0000 | [diff] [blame] | 204 | "repeat(a, b) -- Return a * b, where a is a sequence, and b is an integer.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 205 | spam2(getitem,__getitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 206 | "getitem(a, b) -- Same as a[b].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 207 | spam2(setitem,__setitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 208 | "setitem(a, b, c) -- Same as a[b] = c.") |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 209 | spam2(delitem,__delitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 210 | "delitem(a, b) -- Same as del a[b].") |
Raymond Hettinger | 5959c55 | 2002-08-19 03:19:09 +0000 | [diff] [blame] | 211 | spam2(pow,__pow__, "pow(a, b) -- Same as a**b.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 212 | spam2(getslice,__getslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 213 | "getslice(a, b, c) -- Same as a[b:c].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 214 | spam2(setslice,__setslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 215 | "setslice(a, b, c, d) -- Same as a[b:c] = d.") |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 216 | spam2(delslice,__delslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 217 | "delslice(a, b, c) -- Same as del a[b:c].") |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 218 | spam2(lt,__lt__, "lt(a, b) -- Same as a<b.") |
| 219 | spam2(le,__le__, "le(a, b) -- Same as a<=b.") |
| 220 | spam2(eq,__eq__, "eq(a, b) -- Same as a==b.") |
| 221 | spam2(ne,__ne__, "ne(a, b) -- Same as a!=b.") |
| 222 | spam2(gt,__gt__, "gt(a, b) -- Same as a>b.") |
| 223 | spam2(ge,__ge__, "ge(a, b) -- Same as a>=b.") |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 224 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 225 | {NULL, NULL} /* sentinel */ |
| 226 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 227 | }; |
| 228 | |
| 229 | |
| 230 | /* Initialization function for the module (*must* be called initoperator) */ |
| 231 | |
Mark Hammond | fe51c6d | 2002-08-02 02:27:13 +0000 | [diff] [blame] | 232 | PyMODINIT_FUNC |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 233 | initoperator(void) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 234 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 235 | /* Create the module and add the functions */ |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 236 | Py_InitModule4("operator", operator_methods, operator_doc, |
| 237 | (PyObject*)NULL, PYTHON_API_VERSION); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 238 | } |