Mercurial > cpython-lru_cache-weakref
comparison Python/errors.c @ 16850:2d4da6cfee61 legacy-trunk
Add PyErr_WarnExplicit(), which calls warnings.warn_explicit(), with
explicit filename, lineno etc. arguments.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Wed, 28 Feb 2001 21:46:24 +0000 |
| parents | 09f6c1372056 |
| children | 86fd723f2928 |
comparison
equal
deleted
inserted
replaced
| 16849:a8771a52abb3 | 16850:2d4da6cfee61 |
|---|---|
| 621 Py_DECREF(res); | 621 Py_DECREF(res); |
| 622 return 0; | 622 return 0; |
| 623 } | 623 } |
| 624 } | 624 } |
| 625 | 625 |
| 626 | |
| 627 /* Warning with explicit origin */ | |
| 628 int | |
| 629 PyErr_WarnExplicit(PyObject *category, char *message, | |
| 630 char *filename, int lineno, | |
| 631 char *module, PyObject *registry) | |
| 632 { | |
| 633 PyObject *mod, *dict, *func = NULL; | |
| 634 | |
| 635 mod = PyImport_ImportModule("warnings"); | |
| 636 if (mod != NULL) { | |
| 637 dict = PyModule_GetDict(mod); | |
| 638 func = PyDict_GetItemString(dict, "warn_explicit"); | |
| 639 Py_DECREF(mod); | |
| 640 } | |
| 641 if (func == NULL) { | |
| 642 PySys_WriteStderr("warning: %s\n", message); | |
| 643 return 0; | |
| 644 } | |
| 645 else { | |
| 646 PyObject *args, *res; | |
| 647 | |
| 648 if (category == NULL) | |
| 649 category = PyExc_RuntimeWarning; | |
| 650 if (registry == NULL) | |
| 651 registry = Py_None; | |
| 652 args = Py_BuildValue("(sOsizO)", message, category, | |
| 653 filename, lineno, module, registry); | |
| 654 if (args == NULL) | |
| 655 return -1; | |
| 656 res = PyEval_CallObject(func, args); | |
| 657 Py_DECREF(args); | |
| 658 if (res == NULL) | |
| 659 return -1; | |
| 660 Py_DECREF(res); | |
| 661 return 0; | |
| 662 } | |
| 663 } | |
| 664 | |
| 665 | |
| 666 /* XXX There's a comment missing here */ | |
| 667 | |
| 626 void | 668 void |
| 627 PyErr_SyntaxLocation(char *filename, int lineno) | 669 PyErr_SyntaxLocation(char *filename, int lineno) |
| 628 { | 670 { |
| 629 PyObject *exc, *v, *tb, *tmp; | 671 PyObject *exc, *v, *tb, *tmp; |
| 630 | 672 |
