Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 1 | static char operator_doc[] = "\ |
| 2 | Operator interface.\n\ |
| 3 | \n\ |
| 4 | This module exports a set of functions implemented in C corresponding\n\ |
| 5 | to the intrinsic operators of Python. For example, operator.add(x, y)\n\ |
| 6 | is equivalent to the expression x+y. The function names are those\n\ |
| 7 | used for special class methods; variants without leading and trailing\n\ |
| 8 | '__' are also provided for convenience.\n\ |
| 9 | "; |
| 10 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 11 | #include "Python.h" |
| 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* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 105 | op_getslice(PyObject *s, PyObject *a) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 106 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 107 | PyObject *a1; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 108 | int a2,a3; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 109 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 110 | if (!PyArg_ParseTuple(a,"Oii:getslice",&a1,&a2,&a3)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 111 | return NULL; |
| 112 | return PySequence_GetSlice(a1,a2,a3); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 116 | op_setslice(PyObject *s, PyObject *a) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 117 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 118 | PyObject *a1, *a4; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 119 | int a2,a3; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 120 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 121 | if (!PyArg_ParseTuple(a,"OiiO:setslice",&a1,&a2,&a3,&a4)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 122 | return NULL; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 123 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 124 | if (-1 == PySequence_SetSlice(a1,a2,a3,a4)) |
| 125 | return NULL; |
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 | Py_INCREF(Py_None); |
| 128 | return Py_None; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 129 | } |
| 130 | |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 131 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 132 | op_delslice(PyObject *s, PyObject *a) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 133 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 134 | PyObject *a1; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 135 | int a2,a3; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 136 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 137 | if(! PyArg_ParseTuple(a,"Oii:delslice",&a1,&a2,&a3)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 138 | return NULL; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 139 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 140 | if (-1 == PySequence_DelSlice(a1,a2,a3)) |
| 141 | return NULL; |
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 | Py_INCREF(Py_None); |
| 144 | return Py_None; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 147 | #undef spam1 |
| 148 | #undef spam2 |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 149 | #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, DOC}, |
| 150 | #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, DOC}, \ |
| 151 | {#ALTOP, op_##OP, METH_VARARGS, DOC}, |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 152 | |
| 153 | static struct PyMethodDef operator_methods[] = { |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 154 | |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 155 | spam1(isCallable, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 156 | "isCallable(a) -- Same as callable(a).") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 157 | spam1(isNumberType, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 158 | "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] | 159 | spam1(isSequenceType, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 160 | "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] | 161 | spam1(truth, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 162 | "truth(a) -- Return True if a is true, False otherwise.") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 163 | spam2(contains,__contains__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 164 | "contains(a, b) -- Same as b in a (note reversed operands).") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 165 | spam1(sequenceIncludes, |
| 166 | "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] | 167 | spam1(indexOf, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 168 | "indexOf(a, b) -- Return the first index of b in a.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 169 | spam1(countOf, |
| 170 | "countOf(a, b) -- Return the number of times b occurs in a.") |
| 171 | spam1(isMappingType, |
Guido van Rossum | 77f6a65 | 2002-04-03 22:41:51 +0000 | [diff] [blame] | 172 | "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] | 173 | |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 174 | spam2(add,__add__, "add(a, b) -- Same as a + b.") |
| 175 | spam2(sub,__sub__, "sub(a, b) -- Same as a - b.") |
| 176 | spam2(mul,__mul__, "mul(a, b) -- Same as a * b.") |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 177 | spam2(div,__div__, "div(a, b) -- Same as a / b when __future__.division is not in effect.") |
| 178 | spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.") |
| 179 | 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] | 180 | spam2(mod,__mod__, "mod(a, b) -- Same as a % b.") |
| 181 | spam2(neg,__neg__, "neg(a) -- Same as -a.") |
| 182 | spam2(pos,__pos__, "pos(a) -- Same as +a.") |
| 183 | spam2(abs,__abs__, "abs(a) -- Same as abs(a).") |
| 184 | spam2(inv,__inv__, "inv(a) -- Same as ~a.") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 185 | spam2(invert,__invert__, "invert(a) -- Same as ~a.") |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 186 | spam2(lshift,__lshift__, "lshift(a, b) -- Same as a << b.") |
| 187 | spam2(rshift,__rshift__, "rshift(a, b) -- Same as a >> b.") |
| 188 | spam2(not_,__not__, "not_(a) -- Same as not a.") |
| 189 | spam2(and_,__and__, "and_(a, b) -- Same as a & b.") |
| 190 | spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") |
| 191 | spam2(or_,__or__, "or_(a, b) -- Same as a | b.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 192 | spam2(concat,__concat__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 193 | "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] | 194 | spam2(repeat,__repeat__, |
Guido van Rossum | 36a484f | 1996-12-05 19:01:16 +0000 | [diff] [blame] | 195 | "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] | 196 | spam2(getitem,__getitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 197 | "getitem(a, b) -- Same as a[b].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 198 | spam2(setitem,__setitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 199 | "setitem(a, b, c) -- Same as a[b] = c.") |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 200 | spam2(delitem,__delitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 201 | "delitem(a, b) -- Same as del a[b].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 202 | spam2(getslice,__getslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 203 | "getslice(a, b, c) -- Same as a[b:c].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 204 | spam2(setslice,__setslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 205 | "setslice(a, b, c, d) -- Same as a[b:c] = d.") |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 206 | spam2(delslice,__delslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 207 | "delslice(a, b, c) -- Same as del a[b:c].") |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 208 | spam2(lt,__lt__, "lt(a, b) -- Same as a<b.") |
| 209 | spam2(le,__le__, "le(a, b) -- Same as a<=b.") |
| 210 | spam2(eq,__eq__, "eq(a, b) -- Same as a==b.") |
| 211 | spam2(ne,__ne__, "ne(a, b) -- Same as a!=b.") |
| 212 | spam2(gt,__gt__, "gt(a, b) -- Same as a>b.") |
| 213 | spam2(ge,__ge__, "ge(a, b) -- Same as a>=b.") |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 214 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 215 | {NULL, NULL} /* sentinel */ |
| 216 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | |
| 220 | /* Initialization function for the module (*must* be called initoperator) */ |
| 221 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 222 | DL_EXPORT(void) |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 223 | initoperator(void) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 224 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 225 | /* Create the module and add the functions */ |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 226 | Py_InitModule4("operator", operator_methods, operator_doc, |
| 227 | (PyObject*)NULL, PYTHON_API_VERSION); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 228 | } |