LEFT | RIGHT |
1 | 1 |
2 #include "Python.h" | 2 #include "Python.h" |
3 #include "structmember.h" | 3 #include "structmember.h" |
4 | 4 |
5 /* _functools module written and maintained | 5 /* _functools module written and maintained |
6 by Hye-Shik Chang <perky@FreeBSD.org> | 6 by Hye-Shik Chang <perky@FreeBSD.org> |
7 with adaptations by Raymond Hettinger <python@rcn.com> | 7 with adaptations by Raymond Hettinger <python@rcn.com> |
8 Copyright (c) 2004, 2005, 2006 Python Software Foundation. | 8 Copyright (c) 2004, 2005, 2006 Python Software Foundation. |
9 All rights reserved. | 9 All rights reserved. |
10 */ | 10 */ |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
183 Py_VISIT(pto->dict); | 183 Py_VISIT(pto->dict); |
184 return 0; | 184 return 0; |
185 } | 185 } |
186 | 186 |
187 static PyObject * | 187 static PyObject * |
188 partial_richcompare(PyObject *left, PyObject *right, int op) | 188 partial_richcompare(PyObject *left, PyObject *right, int op) |
189 { | 189 { |
190 int result; | 190 int result; |
191 partialobject *l_pto; | 191 partialobject *l_pto; |
192 partialobject *r_pto; | 192 partialobject *r_pto; |
| 193 PyObject *l_dict; |
| 194 PyObject *r_dict; |
193 | 195 |
194 if (PyType_IsSubtype(Py_TYPE(right), &partial_type) && (op == Py_EQ || op ==
Py_NE)) { | 196 if (PyType_IsSubtype(Py_TYPE(right), &partial_type) && (op == Py_EQ || op ==
Py_NE)) { |
195 l_pto = (partialobject *)left; | 197 l_pto = (partialobject *)left; |
196 r_pto = (partialobject *)right; | 198 r_pto = (partialobject *)right; |
197 if (l_pto->fn == r_pto->fn) { | 199 if (l_pto->fn == r_pto->fn) { |
| 200 /* Compare args: */ |
198 result = PyObject_RichCompareBool(l_pto->args, r_pto->args, Py_EQ); | 201 result = PyObject_RichCompareBool(l_pto->args, r_pto->args, Py_EQ); |
199 if (result == -1) | 202 if (result == -1) |
200 return NULL; | 203 return NULL; |
| 204 /* Compare keywords: */ |
201 if (result == 1) | 205 if (result == 1) |
202 result = PyObject_RichCompareBool(l_pto->kw, r_pto->kw, Py_EQ); | 206 result = PyObject_RichCompareBool(l_pto->kw, r_pto->kw, Py_EQ); |
203 if (result == -1) | 207 if (result == -1) |
204 return NULL; | 208 return NULL; |
| 209 /* Compare __dict__: */ |
| 210 if (result == 1 && (l_pto->dict != r_pto->dict)) { |
| 211 l_dict = PyObject_GetAttrString(left, "__dict__"); |
| 212 if (l_dict == NULL) |
| 213 return NULL; |
| 214 r_dict = PyObject_GetAttrString(right, "__dict__"); |
| 215 if (r_dict == NULL) { |
| 216 Py_DECREF(l_dict); |
| 217 return NULL; |
| 218 } |
| 219 result = PyObject_RichCompareBool(l_dict, r_dict, Py_EQ); |
| 220 Py_DECREF(l_dict); |
| 221 Py_DECREF(r_dict); |
| 222 } |
205 } | 223 } |
206 else | 224 else |
207 result = 0; | 225 result = 0; |
208 | 226 |
209 if (op == Py_NE) | 227 if (op == Py_NE) |
210 result = (result == 0); | 228 result = (result == 0); |
211 | 229 |
212 if(result) { | 230 if(result) { |
213 Py_INCREF(Py_True); | 231 Py_INCREF(Py_True); |
214 return Py_True; | 232 return Py_True; |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 } | 299 } |
282 else { | 300 else { |
283 keywords = Py_None; | 301 keywords = Py_None; |
284 Py_INCREF(Py_None); | 302 Py_INCREF(Py_None); |
285 } | 303 } |
286 return keywords; | 304 return keywords; |
287 } | 305 } |
288 | 306 |
289 static PyGetSetDef partial_getsetlist[] = { | 307 static PyGetSetDef partial_getsetlist[] = { |
290 {"__dict__", (getter)partial_get_dict, (setter)partial_set_dict}, | 308 {"__dict__", (getter)partial_get_dict, (setter)partial_set_dict}, |
291 {"keywords", (getter)partial_get_keywords, NULL, | 309 {"keywords", (getter)partial_get_keywords, NULL, |
292 "dictionary of keyword arguments to future partial calls"}, | 310 "dictionary of keyword arguments to future partial calls"}, |
293 {NULL} /* Sentinel */ | 311 {NULL} /* Sentinel */ |
294 }; | 312 }; |
295 | 313 |
296 /* Pickle strategy: | 314 /* Pickle strategy: |
297 __reduce__ by itself doesn't support getting kwargs in the unpickle | 315 __reduce__ by itself doesn't support getting kwargs in the unpickle |
298 operation so we define a __setstate__ that replaces all the information | 316 operation so we define a __setstate__ that replaces all the information |
299 about the partial. If we only replaced part of it someone would use | 317 about the partial. If we only replaced part of it someone would use |
300 it as a hook to do stange things. | 318 it as a hook to do stange things. |
301 */ | 319 */ |
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
503 Py_DECREF(m); | 521 Py_DECREF(m); |
504 return NULL; | 522 return NULL; |
505 } | 523 } |
506 name = strchr(typelist[i]->tp_name, '.'); | 524 name = strchr(typelist[i]->tp_name, '.'); |
507 assert (name != NULL); | 525 assert (name != NULL); |
508 Py_INCREF(typelist[i]); | 526 Py_INCREF(typelist[i]); |
509 PyModule_AddObject(m, name+1, (PyObject *)typelist[i]); | 527 PyModule_AddObject(m, name+1, (PyObject *)typelist[i]); |
510 } | 528 } |
511 return m; | 529 return m; |
512 } | 530 } |
LEFT | RIGHT |