Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(4)

Side by Side Diff: Python/_warnings.c

Issue 10639: reindent.py converts newlines to platform default
Patch Set: Created 8 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Python/thread_wince.h ('k') | Tools/gdb/libpython.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #include "Python.h" 1 #include "Python.h"
2 #include "frameobject.h" 2 #include "frameobject.h"
3 3
4 #define MODULE_NAME "_warnings" 4 #define MODULE_NAME "_warnings"
5 5
6 PyDoc_STRVAR(warnings__doc__, 6 PyDoc_STRVAR(warnings__doc__,
7 MODULE_NAME " provides basic warning filtering support.\n" 7 MODULE_NAME " provides basic warning filtering support.\n"
8 "It is a helper module to speed up interpreter start-up."); 8 "It is a helper module to speed up interpreter start-up.");
9 9
10 /* Both 'filters' and 'onceregistry' can be set in warnings.py; 10 /* Both 'filters' and 'onceregistry' can be set in warnings.py;
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
402 if (rc == 0) { 402 if (rc == 0) {
403 PyObject *show_fxn = get_warnings_attr("showwarning"); 403 PyObject *show_fxn = get_warnings_attr("showwarning");
404 if (show_fxn == NULL) { 404 if (show_fxn == NULL) {
405 if (PyErr_Occurred()) 405 if (PyErr_Occurred())
406 goto cleanup; 406 goto cleanup;
407 show_warning(filename, lineno, text, category, sourceline); 407 show_warning(filename, lineno, text, category, sourceline);
408 } 408 }
409 else { 409 else {
410 PyObject *res; 410 PyObject *res;
411 411
412 if (!PyCallable_Check(show_fxn)) { 412 if (!PyMethod_Check(show_fxn) && !PyFunction_Check(show_fxn)) {
413 PyErr_SetString(PyExc_TypeError, 413 PyErr_SetString(PyExc_TypeError,
414 "warnings.showwarning() must be set to a " 414 "warnings.showwarning() must be set to a "
415 "callable"); 415 "function or method");
416 Py_DECREF(show_fxn); 416 Py_DECREF(show_fxn);
417 goto cleanup; 417 goto cleanup;
418 } 418 }
419 419
420 res = PyObject_CallFunctionObjArgs(show_fxn, message, category, 420 res = PyObject_CallFunctionObjArgs(show_fxn, message, category,
421 filename, lineno_obj, 421 filename, lineno_obj,
422 NULL); 422 NULL);
423 Py_DECREF(show_fxn); 423 Py_DECREF(show_fxn);
424 Py_XDECREF(res); 424 Py_XDECREF(res);
425 if (res == NULL) 425 if (res == NULL)
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
489 if (*module == NULL) { 489 if (*module == NULL) {
490 *module = PyUnicode_FromString("<string>"); 490 *module = PyUnicode_FromString("<string>");
491 if (*module == NULL) 491 if (*module == NULL)
492 goto handle_error; 492 goto handle_error;
493 } 493 }
494 else 494 else
495 Py_INCREF(*module); 495 Py_INCREF(*module);
496 496
497 /* Setup filename. */ 497 /* Setup filename. */
498 *filename = PyDict_GetItemString(globals, "__file__"); 498 *filename = PyDict_GetItemString(globals, "__file__");
499 if (*filename != NULL && PyUnicode_Check(*filename)) { 499 if (*filename != NULL) {
500 Py_ssize_t len = PyUnicode_GetSize(*filename); 500 Py_ssize_t len = PyUnicode_GetSize(*filename);
501 Py_UNICODE *unicode = PyUnicode_AS_UNICODE(*filename); 501 Py_UNICODE *unicode = PyUnicode_AS_UNICODE(*filename);
502 502
503 /* if filename.lower().endswith((".pyc", ".pyo")): */ 503 /* if filename.lower().endswith((".pyc", ".pyo")): */
504 if (len >= 4 && 504 if (len >= 4 &&
505 unicode[len-4] == '.' && 505 unicode[len-4] == '.' &&
506 Py_UNICODE_TOLOWER(unicode[len-3]) == 'p' && 506 Py_UNICODE_TOLOWER(unicode[len-3]) == 'p' &&
507 Py_UNICODE_TOLOWER(unicode[len-2]) == 'y' && 507 Py_UNICODE_TOLOWER(unicode[len-2]) == 'y' &&
508 (Py_UNICODE_TOLOWER(unicode[len-1]) == 'c' || 508 (Py_UNICODE_TOLOWER(unicode[len-1]) == 'c' ||
509 Py_UNICODE_TOLOWER(unicode[len-1]) == 'o')) 509 Py_UNICODE_TOLOWER(unicode[len-1]) == 'o'))
510 { 510 {
511 *filename = PyUnicode_FromUnicode(unicode, len-1); 511 *filename = PyUnicode_FromUnicode(unicode, len-1);
512 if (*filename == NULL) 512 if (*filename == NULL)
513 goto handle_error; 513 goto handle_error;
514 } 514 }
515 else 515 else
516 Py_INCREF(*filename); 516 Py_INCREF(*filename);
517 } 517 }
518 else { 518 else {
519 const char *module_str = _PyUnicode_AsString(*module); 519 const char *module_str = _PyUnicode_AsString(*module);
520 *filename = NULL;
521 if (module_str == NULL) 520 if (module_str == NULL)
522 goto handle_error; 521 goto handle_error;
523 if (strcmp(module_str, "__main__") == 0) { 522 if (strcmp(module_str, "__main__") == 0) {
524 PyObject *argv = PySys_GetObject("argv"); 523 PyObject *argv = PySys_GetObject("argv");
525 if (argv != NULL && PyList_Size(argv) > 0) { 524 if (argv != NULL && PyList_Size(argv) > 0) {
526 int is_true; 525 int is_true;
527 *filename = PyList_GetItem(argv, 0); 526 *filename = PyList_GetItem(argv, 0);
528 Py_INCREF(*filename); 527 Py_INCREF(*filename);
529 /* If sys.argv[0] is false, then use '__main__'. */ 528 /* If sys.argv[0] is false, then use '__main__'. */
530 is_true = PyObject_IsTrue(*filename); 529 is_true = PyObject_IsTrue(*filename);
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 if (PyModule_AddObject(m, "_onceregistry", _once_registry) < 0) 964 if (PyModule_AddObject(m, "_onceregistry", _once_registry) < 0)
966 return NULL; 965 return NULL;
967 966
968 _default_action = PyUnicode_FromString("default"); 967 _default_action = PyUnicode_FromString("default");
969 if (_default_action == NULL) 968 if (_default_action == NULL)
970 return NULL; 969 return NULL;
971 if (PyModule_AddObject(m, "_defaultaction", _default_action) < 0) 970 if (PyModule_AddObject(m, "_defaultaction", _default_action) < 0)
972 return NULL; 971 return NULL;
973 return m; 972 return m;
974 } 973 }
OLDNEW
« no previous file with comments | « Python/thread_wince.h ('k') | Tools/gdb/libpython.py » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+