annotate Modules/operator.c @ 25135:0f0016632be4 legacy-trunk

_formatparam(), set_param(): RFC 2231 encoding support by Oleg Broytmann in SF patch #600096. Specifically, the former function now encodes the triplets, while the latter adds optional charset and language arguments.
author Barry Warsaw <barry@python.org>
date Fri, 06 Sep 2002 03:55:04 +0000
parents d797cfa8ca0d
children e094a03a80ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 \n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 This module exports a set of functions implemented in C corresponding\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 to the intrinsic operators of Python. For example, operator.add(x, y)\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 is equivalent to the expression x+y. The function names are those\n\
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
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
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
13 #define spam1(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 PyObject *a1; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
15 if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 return AOP(a1); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
18 #define spam2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 PyObject *a1, *a2; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
20 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 return AOP(a1,a2); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
23 #define spamoi(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
24 PyObject *a1; int a2; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
25 if(! PyArg_ParseTuple(a,"Oi:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
26 return AOP(a1,a2); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
27
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
28 #define spam2n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
29 PyObject *a1, *a2; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
30 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
31 if(-1 == AOP(a1,a2)) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
32 Py_INCREF(Py_None); \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
33 return Py_None; }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
34
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
35 #define spam3n(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
36 PyObject *a1, *a2, *a3; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
37 if(! PyArg_ParseTuple(a,"OOO:" #OP,&a1,&a2,&a3)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 if(-1 == AOP(a1,a2,a3)) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
39 Py_INCREF(Py_None); \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 return Py_None; }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
41
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
42 #define spami(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
43 PyObject *a1; long r; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
44 if(! PyArg_ParseTuple(a,"O:" #OP,&a1)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
45 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
46 return PyBool_FromLong(r); }
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
47
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
48 #define spami2(OP,AOP) static PyObject *OP(PyObject *s, PyObject *a) { \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
49 PyObject *a1, *a2; long r; \
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
50 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
51 if(-1 == (r=AOP(a1,a2))) return NULL; \
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
52 return PyInt_FromLong(r); }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
53
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 #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
55 PyObject *a1, *a2; long 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 if(! PyArg_ParseTuple(a,"OO:" #OP,&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
57 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
58 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
59
19111
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
60 #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
61 PyObject *a1, *a2; \
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
62 if(! PyArg_ParseTuple(a,"OO:" #OP,&a1,&a2)) return NULL; \
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
63 return PyObject_RichCompare(a1,a2,A); }
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
64
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
65 spami(isCallable , PyCallable_Check)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
66 spami(isNumberType , PyNumber_Check)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
67 spami(truth , PyObject_IsTrue)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
68 spam2(op_add , PyNumber_Add)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
69 spam2(op_sub , PyNumber_Subtract)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
70 spam2(op_mul , PyNumber_Multiply)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
71 spam2(op_div , PyNumber_Divide)
19111
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
72 spam2(op_floordiv , PyNumber_FloorDivide)
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
73 spam2(op_truediv , PyNumber_TrueDivide)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
74 spam2(op_mod , PyNumber_Remainder)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
75 spam1(op_neg , PyNumber_Negative)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
76 spam1(op_pos , PyNumber_Positive)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
77 spam1(op_abs , PyNumber_Absolute)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
78 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
79 spam1(op_invert , PyNumber_Invert)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
80 spam2(op_lshift , PyNumber_Lshift)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
81 spam2(op_rshift , PyNumber_Rshift)
7936
1f38a2b548bf Add not_ and __not__.
Guido van Rossum <guido@python.org>
parents: 6227
diff changeset
82 spami(op_not_ , PyObject_Not)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
83 spam2(op_and_ , PyNumber_And)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
84 spam2(op_xor , PyNumber_Xor)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
85 spam2(op_or_ , PyNumber_Or)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
86 spami(isSequenceType , PySequence_Check)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
87 spam2(op_concat , PySequence_Concat)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
88 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
89 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
90 spami2b(sequenceIncludes, PySequence_Contains)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
91 spami2(indexOf , PySequence_Index)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
92 spami2(countOf , PySequence_Count)
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
93 spami(isMappingType , PyMapping_Check)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
94 spam2(op_getitem , PyObject_GetItem)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
95 spam2n(op_delitem , PyObject_DelItem)
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
96 spam3n(op_setitem , PyObject_SetItem)
19111
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
97 spamrc(op_lt , Py_LT)
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
98 spamrc(op_le , Py_LE)
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
99 spamrc(op_eq , Py_EQ)
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
100 spamrc(op_ne , Py_NE)
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
101 spamrc(op_gt , Py_GT)
6ba441507220 Add wrappers around the rich-comparison operations.
Fred Drake <fdrake@acm.org>
parents: 14654
diff changeset
102 spamrc(op_ge , Py_GE)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
103
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
104 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
105 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
106 {
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 24796
diff changeset
107 PyObject *a1, *a2;
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 24796
diff changeset
108 if (PyArg_ParseTuple(a,"OO:pow",&a1,&a2))
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 24796
diff changeset
109 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
110 return NULL;
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 24796
diff changeset
111 }
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 24796
diff changeset
112
d797cfa8ca0d Added __pow__(a,b) to the operator module. Completes the pattern of
Raymond Hettinger <python@rcn.com>
parents: 24796
diff changeset
113 static PyObject*
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
114 op_getslice(PyObject *s, PyObject *a)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
115 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
116 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
117 int a2,a3;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
118
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
119 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
120 return NULL;
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
121 return PySequence_GetSlice(a1,a2,a3);
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
122 }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
123
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
124 static PyObject*
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
125 op_setslice(PyObject *s, PyObject *a)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
126 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
127 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
128 int a2,a3;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
129
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
130 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
131 return NULL;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
132
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
133 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
134 return NULL;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
135
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
136 Py_INCREF(Py_None);
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
137 return Py_None;
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
138 }
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
139
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
140 static PyObject*
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
141 op_delslice(PyObject *s, PyObject *a)
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
142 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
143 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
144 int a2,a3;
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
145
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
146 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
147 return NULL;
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
148
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
149 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
150 return NULL;
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
151
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
152 Py_INCREF(Py_None);
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
153 return Py_None;
4089
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
154 }
9f70d995d027 Added delslice and delitem.
Guido van Rossum <guido@python.org>
parents: 4033
diff changeset
155
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
156 #undef spam1
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
157 #undef spam2
24796
de71e6fe64b0 Allow more docstrings to be removed during compilation in some modules
Neal Norwitz <nnorwitz@gmail.com>
parents: 24471
diff changeset
158 #define spam1(OP,DOC) {#OP, OP, METH_VARARGS, PyDoc_STR(DOC)},
13422
aa3d3bece774 ANSI-fy the sources.
Fred Drake <fdrake@acm.org>
parents: 9588
diff changeset
159 #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
160 {#ALTOP, op_##OP, METH_VARARGS, PyDoc_STR(DOC)},
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
161
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
162 static struct PyMethodDef operator_methods[] = {
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
163
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
164 spam1(isCallable,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
165 "isCallable(a) -- Same as callable(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
166 spam1(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
167 "isNumberType(a) -- Return True if a has a numeric type, False otherwise.")
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
168 spam1(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
169 "isSequenceType(a) -- Return True if a has a sequence type, False otherwise.")
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
170 spam1(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
171 "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
172 spam2(contains,__contains__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
173 "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
174 spam1(sequenceIncludes,
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
175 "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
176 spam1(indexOf,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
177 "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
178 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
179 "countOf(a, b) -- Return the number of times b occurs in a.")
5592de9656de Made it palatable for K&R preprocessors. The spam macros don't have
Guido van Rossum <guido@python.org>
parents: 3976
diff changeset
180 spam1(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
181 "isMappingType(a) -- Return True if a has a mapping type, False otherwise.")
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
182
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
183 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
184 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
185 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
186 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
187 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
188 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
189 spam2(mod,__mod__, "mod(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
190 spam2(neg,__neg__, "neg(a) -- Same as -a.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
191 spam2(pos,__pos__, "pos(a) -- Same as +a.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
192 spam2(abs,__abs__, "abs(a) -- Same as abs(a).")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
193 spam2(inv,__inv__, "inv(a) -- Same as ~a.")
14654
0bd746bc7627 Add invert() and __invert__() as aliases for inv()/__inv__().
Fred Drake <fdrake@acm.org>
parents: 13651
diff changeset
194 spam2(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
195 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
196 spam2(rshift,__rshift__, "rshift(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
197 spam2(not_,__not__, "not_(a) -- Same as not a.")
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
198 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
199 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
200 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
201 spam2(concat,__concat__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
202 "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
203 spam2(repeat,__repeat__,
4580
11bd4f497742 Correct typo -- repeat implements *, not +.
Guido van Rossum <guido@python.org>
parents: 4104
diff changeset
204 "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
205 spam2(getitem,__getitem__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
206 "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
207 spam2(setitem,__setitem__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
208 "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
209 spam2(delitem,__delitem__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
210 "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
211 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
212 spam2(getslice,__getslice__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
213 "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
214 spam2(setslice,__setslice__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
215 "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
216 spam2(delslice,__delslice__,
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
217 "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
218 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
219 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
220 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
221 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
222 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
223 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
224
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
225 {NULL, NULL} /* sentinel */
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
226
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
227 };
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
228
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
229
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
230 /* Initialization function for the module (*must* be called initoperator) */
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
231
24471
f66b3a3509c7 Excise DL_EXPORT/DL_IMPORT from Modules/*. Required adding a prototype
Mark Hammond <mhammond@skippinet.com.au>
parents: 23832
diff changeset
232 PyMODINIT_FUNC
13651
8a063423e0b7 Bunch of minor ANSIfications: 'void initfunc()' -> 'void initfunc(void)',
Thomas Wouters <thomas@python.org>
parents: 13424
diff changeset
233 initoperator(void)
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
234 {
4775
0d0c413b6f25 Tabification changes only; the module was already newly named.
Barry Warsaw <barry@python.org>
parents: 4580
diff changeset
235 /* Create the module and add the functions */
8414
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
236 Py_InitModule4("operator", operator_methods, operator_doc,
4064b6729537 Add an alias (and preferred name) "contains" for "sequenceIncludes".
Guido van Rossum <guido@python.org>
parents: 8406
diff changeset
237 (PyObject*)NULL, PYTHON_API_VERSION);
3844
0d54a14ef0b8 Operators like __add__
Guido van Rossum <guido@python.org>
parents:
diff changeset
238 }