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 | |
| 11 | /* |
| 12 | |
| 13 | Copyright |
| 14 | |
| 15 | Copyright 1996 Digital Creations, L.C., 910 Princess Anne |
| 16 | Street, Suite 300, Fredericksburg, Virginia 22401 U.S.A. All |
| 17 | rights reserved. Copyright in this software is owned by DCLC, |
| 18 | unless otherwise indicated. Permission to use, copy and |
| 19 | distribute this software is hereby granted, provided that the |
| 20 | above copyright notice appear in all copies and that both that |
| 21 | copyright notice and this permission notice appear. Note that |
| 22 | any product, process or technology described in this software |
| 23 | may be the subject of other Intellectual Property rights |
| 24 | reserved by Digital Creations, L.C. and are not licensed |
| 25 | hereunder. |
| 26 | |
| 27 | Trademarks |
| 28 | |
| 29 | Digital Creations & DCLC, are trademarks of Digital Creations, L.C.. |
| 30 | All other trademarks are owned by their respective companies. |
| 31 | |
| 32 | No Warranty |
| 33 | |
| 34 | The software is provided "as is" without warranty of any kind, |
| 35 | either express or implied, including, but not limited to, the |
| 36 | implied warranties of merchantability, fitness for a particular |
| 37 | purpose, or non-infringement. This software could include |
| 38 | technical inaccuracies or typographical errors. Changes are |
| 39 | periodically made to the software; these changes will be |
| 40 | incorporated in new editions of the software. DCLC may make |
| 41 | improvements and/or changes in this software at any time |
| 42 | without notice. |
| 43 | |
| 44 | Limitation Of Liability |
| 45 | |
| 46 | In no event will DCLC be liable for direct, indirect, special, |
| 47 | incidental, economic, cover, or consequential damages arising |
| 48 | out of the use of or inability to use this software even if |
| 49 | advised of the possibility of such damages. Some states do not |
| 50 | allow the exclusion or limitation of implied warranties or |
| 51 | limitation of liability for incidental or consequential |
| 52 | damages, so the above limitation or exclusion may not apply to |
| 53 | you. |
| 54 | |
| 55 | |
| 56 | If you have questions regarding this software, |
| 57 | contact: |
| 58 | |
| 59 | Jim Fulton, jim@digicool.com |
| 60 | Digital Creations L.C. |
| 61 | |
| 62 | (540) 371-6909 |
| 63 | |
| 64 | Modifications |
| 65 | |
| 66 | Renamed and slightly rearranged by Guido van Rossum |
| 67 | |
| 68 | */ |
| 69 | |
| 70 | #include "Python.h" |
| 71 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 72 | #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 73 | PyObject *a1; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 74 | if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 75 | return AOP(a1); } |
| 76 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 77 | #define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 78 | PyObject *a1, *a2; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 79 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 80 | return AOP(a1,a2); } |
| 81 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 82 | #define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 83 | PyObject *a1; int a2; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 84 | if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 85 | return AOP(a1,a2); } |
| 86 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 87 | #define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 88 | PyObject *a1, *a2; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 89 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 90 | if(-1 == AOP(a1,a2)) return NULL; \ |
| 91 | Py_INCREF(Py_None); \ |
| 92 | return Py_None; } |
| 93 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 94 | #define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 95 | PyObject *a1, *a2, *a3; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 96 | if(! PyArg_ParseTuple(a,"OOO:" #OP,&a1,&a2,&a3)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 97 | if(-1 == AOP(a1,a2,a3)) return NULL; \ |
| 98 | Py_INCREF(Py_None); \ |
| 99 | return Py_None; } |
| 100 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 101 | #define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 102 | PyObject *a1; long r; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 103 | if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 104 | if(-1 == (r=AOP(a1))) return NULL; \ |
| 105 | return PyInt_FromLong(r); } |
| 106 | |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 107 | #define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 108 | PyObject *a1, *a2; long r; \ |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 109 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 110 | if(-1 == (r=AOP(a1,a2))) return NULL; \ |
| 111 | return PyInt_FromLong(r); } |
| 112 | |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 113 | #define spamrc(OP,A) static PyObject *OP(PyObject *s, PyObject *a) { \ |
| 114 | PyObject *a1, *a2; \ |
| 115 | if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \ |
| 116 | return PyObject_RichCompare(a1,a2,A); } |
| 117 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 118 | spami(isCallable , PyCallable_Check) |
| 119 | spami(isNumberType , PyNumber_Check) |
| 120 | spami(truth , PyObject_IsTrue) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 121 | spam2(op_add , PyNumber_Add) |
| 122 | spam2(op_sub , PyNumber_Subtract) |
| 123 | spam2(op_mul , PyNumber_Multiply) |
| 124 | spam2(op_div , PyNumber_Divide) |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 125 | spam2(op_floordiv , PyNumber_FloorDivide) |
| 126 | spam2(op_truediv , PyNumber_TrueDivide) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 127 | spam2(op_mod , PyNumber_Remainder) |
| 128 | spam1(op_neg , PyNumber_Negative) |
| 129 | spam1(op_pos , PyNumber_Positive) |
| 130 | spam1(op_abs , PyNumber_Absolute) |
| 131 | spam1(op_inv , PyNumber_Invert) |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 132 | spam1(op_invert , PyNumber_Invert) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 133 | spam2(op_lshift , PyNumber_Lshift) |
| 134 | spam2(op_rshift , PyNumber_Rshift) |
Guido van Rossum | 99c185e | 1998-04-09 17:54:26 +0000 | [diff] [blame] | 135 | spami(op_not_ , PyObject_Not) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 136 | spam2(op_and_ , PyNumber_And) |
| 137 | spam2(op_xor , PyNumber_Xor) |
| 138 | spam2(op_or_ , PyNumber_Or) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 139 | spami(isSequenceType , PySequence_Check) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 140 | spam2(op_concat , PySequence_Concat) |
| 141 | spamoi(op_repeat , PySequence_Repeat) |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 142 | spami2(op_contains , PySequence_Contains) |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 143 | spami2(sequenceIncludes, PySequence_Contains) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 144 | spami2(indexOf , PySequence_Index) |
| 145 | spami2(countOf , PySequence_Count) |
| 146 | spami(isMappingType , PyMapping_Check) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 147 | spam2(op_getitem , PyObject_GetItem) |
| 148 | spam2n(op_delitem , PyObject_DelItem) |
| 149 | spam3n(op_setitem , PyObject_SetItem) |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 150 | spamrc(op_lt , Py_LT) |
| 151 | spamrc(op_le , Py_LE) |
| 152 | spamrc(op_eq , Py_EQ) |
| 153 | spamrc(op_ne , Py_NE) |
| 154 | spamrc(op_gt , Py_GT) |
| 155 | spamrc(op_ge , Py_GE) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 156 | |
| 157 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 158 | op_getslice(PyObject *s, PyObject *a) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 159 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 160 | PyObject *a1; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 161 | int a2,a3; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 162 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 163 | if (!PyArg_ParseTuple(a,"Oii:getslice",&a1,&a2,&a3)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 164 | return NULL; |
| 165 | return PySequence_GetSlice(a1,a2,a3); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 169 | op_setslice(PyObject *s, PyObject *a) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 170 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 171 | PyObject *a1, *a4; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 172 | int a2,a3; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 173 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 174 | if (!PyArg_ParseTuple(a,"OiiO:setslice",&a1,&a2,&a3,&a4)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 175 | return NULL; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 176 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 177 | if (-1 == PySequence_SetSlice(a1,a2,a3,a4)) |
| 178 | return NULL; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 179 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 180 | Py_INCREF(Py_None); |
| 181 | return Py_None; |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 184 | static PyObject* |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 185 | op_delslice(PyObject *s, PyObject *a) |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 186 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 187 | PyObject *a1; |
Guido van Rossum | 24a4994 | 1997-08-28 18:11:05 +0000 | [diff] [blame] | 188 | int a2,a3; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 189 | |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 190 | if(! PyArg_ParseTuple(a,"Oii:delslice",&a1,&a2,&a3)) |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 191 | return NULL; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 192 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 193 | if (-1 == PySequence_DelSlice(a1,a2,a3)) |
| 194 | return NULL; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 195 | |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 196 | Py_INCREF(Py_None); |
| 197 | return Py_None; |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 198 | } |
| 199 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 200 | #undef spam1 |
| 201 | #undef spam2 |
Fred Drake | 5639ba4 | 2000-07-08 04:12:08 +0000 | [diff] [blame] | 202 | #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, DOC}, |
| 203 | #define spam2(OP,ALTOP,DOC) {#OP, op_##OP, METH_VARARGS, DOC}, \ |
| 204 | {#ALTOP, op_##OP, METH_VARARGS, DOC}, |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 205 | |
| 206 | static struct PyMethodDef operator_methods[] = { |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 207 | |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 208 | spam1(isCallable, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 209 | "isCallable(a) -- Same as callable(a).") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 210 | spam1(isNumberType, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 211 | "isNumberType(a) -- Return 1 if a has a numeric type, and zero otherwise.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 212 | spam1(isSequenceType, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 213 | "isSequenceType(a) -- Return 1 if a has a sequence type, and zero otherwise.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 214 | spam1(truth, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 215 | "truth(a) -- Return 1 if a is true, and 0 otherwise.") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 216 | spam2(contains,__contains__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 217 | "contains(a, b) -- Same as b in a (note reversed operands).") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 218 | spam1(sequenceIncludes, |
| 219 | "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] | 220 | spam1(indexOf, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 221 | "indexOf(a, b) -- Return the first index of b in a.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 222 | spam1(countOf, |
| 223 | "countOf(a, b) -- Return the number of times b occurs in a.") |
| 224 | spam1(isMappingType, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 225 | "isMappingType(a) -- Return 1 if a has a mapping type, and zero otherwise.") |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 226 | |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 227 | spam2(add,__add__, "add(a, b) -- Same as a + b.") |
| 228 | spam2(sub,__sub__, "sub(a, b) -- Same as a - b.") |
| 229 | spam2(mul,__mul__, "mul(a, b) -- Same as a * b.") |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 230 | spam2(div,__div__, "div(a, b) -- Same as a / b when __future__.division is not in effect.") |
| 231 | spam2(floordiv,__floordiv__, "floordiv(a, b) -- Same as a // b.") |
| 232 | 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] | 233 | spam2(mod,__mod__, "mod(a, b) -- Same as a % b.") |
| 234 | spam2(neg,__neg__, "neg(a) -- Same as -a.") |
| 235 | spam2(pos,__pos__, "pos(a) -- Same as +a.") |
| 236 | spam2(abs,__abs__, "abs(a) -- Same as abs(a).") |
| 237 | spam2(inv,__inv__, "inv(a) -- Same as ~a.") |
Fred Drake | ea4d3f0 | 2000-09-17 16:09:27 +0000 | [diff] [blame] | 238 | spam2(invert,__invert__, "invert(a) -- Same as ~a.") |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 239 | spam2(lshift,__lshift__, "lshift(a, b) -- Same as a << b.") |
| 240 | spam2(rshift,__rshift__, "rshift(a, b) -- Same as a >> b.") |
| 241 | spam2(not_,__not__, "not_(a) -- Same as not a.") |
| 242 | spam2(and_,__and__, "and_(a, b) -- Same as a & b.") |
| 243 | spam2(xor,__xor__, "xor(a, b) -- Same as a ^ b.") |
| 244 | spam2(or_,__or__, "or_(a, b) -- Same as a | b.") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 245 | spam2(concat,__concat__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 246 | "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] | 247 | spam2(repeat,__repeat__, |
Guido van Rossum | 36a484f | 1996-12-05 19:01:16 +0000 | [diff] [blame] | 248 | "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] | 249 | spam2(getitem,__getitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 250 | "getitem(a, b) -- Same as a[b].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 251 | spam2(setitem,__setitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 252 | "setitem(a, b, c) -- Same as a[b] = c.") |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 253 | spam2(delitem,__delitem__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 254 | "delitem(a, b) -- Same as del a[b].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 255 | spam2(getslice,__getslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 256 | "getslice(a, b, c) -- Same as a[b:c].") |
Guido van Rossum | 1720230 | 1996-08-19 22:01:39 +0000 | [diff] [blame] | 257 | spam2(setslice,__setslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 258 | "setslice(a, b, c, d) -- Same as a[b:c] = d.") |
Guido van Rossum | c9fb47e | 1996-08-21 17:40:51 +0000 | [diff] [blame] | 259 | spam2(delslice,__delslice__, |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 260 | "delslice(a, b, c) -- Same as del a[b:c].") |
Fred Drake | 428e75f | 2001-08-09 20:14:34 +0000 | [diff] [blame] | 261 | spam2(lt,__lt__, "lt(a, b) -- Same as a<b.") |
| 262 | spam2(le,__le__, "le(a, b) -- Same as a<=b.") |
| 263 | spam2(eq,__eq__, "eq(a, b) -- Same as a==b.") |
| 264 | spam2(ne,__ne__, "ne(a, b) -- Same as a!=b.") |
| 265 | spam2(gt,__gt__, "gt(a, b) -- Same as a>b.") |
| 266 | spam2(ge,__ge__, "ge(a, b) -- Same as a>=b.") |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 267 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 268 | {NULL, NULL} /* sentinel */ |
| 269 | |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 270 | }; |
| 271 | |
| 272 | |
| 273 | /* Initialization function for the module (*must* be called initoperator) */ |
| 274 | |
Guido van Rossum | 3886bb6 | 1998-12-04 18:50:17 +0000 | [diff] [blame] | 275 | DL_EXPORT(void) |
Thomas Wouters | f3f33dc | 2000-07-21 06:00:07 +0000 | [diff] [blame] | 276 | initoperator(void) |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 277 | { |
Barry Warsaw | 19f61ae | 1996-12-18 19:50:00 +0000 | [diff] [blame] | 278 | /* Create the module and add the functions */ |
Guido van Rossum | 832f6d2 | 1998-05-22 18:12:59 +0000 | [diff] [blame] | 279 | Py_InitModule4("operator", operator_methods, operator_doc, |
| 280 | (PyObject*)NULL, PYTHON_API_VERSION); |
Guido van Rossum | 037b940 | 1996-07-30 16:55:54 +0000 | [diff] [blame] | 281 | } |