Mercurial > cpython-lru_cache-weakref
comparison Python/pythonrun.c @ 72926:db4aa878cea2
Port SetAttrString/HasAttrString to SetAttrId/GetAttrId.
| author | Martin v. Löwis <martin@v.loewis.de> |
|---|---|
| date | Fri, 14 Oct 2011 15:16:45 +0200 |
| parents | 7109f31300fb |
| children | af0800b986b7 |
comparison
equal
deleted
inserted
replaced
| 72925:7109f31300fb | 72926:db4aa878cea2 |
|---|---|
| 808 PyObject *line_buffering; | 808 PyObject *line_buffering; |
| 809 int buffering, isatty; | 809 int buffering, isatty; |
| 810 _Py_IDENTIFIER(open); | 810 _Py_IDENTIFIER(open); |
| 811 _Py_IDENTIFIER(isatty); | 811 _Py_IDENTIFIER(isatty); |
| 812 _Py_IDENTIFIER(TextIOWrapper); | 812 _Py_IDENTIFIER(TextIOWrapper); |
| 813 _Py_IDENTIFIER(name); | |
| 814 _Py_IDENTIFIER(mode); | |
| 813 | 815 |
| 814 /* stdin is always opened in buffered mode, first because it shouldn't | 816 /* stdin is always opened in buffered mode, first because it shouldn't |
| 815 make a difference in common use cases, second because TextIOWrapper | 817 make a difference in common use cases, second because TextIOWrapper |
| 816 depends on the presence of a read1() method which only exists on | 818 depends on the presence of a read1() method which only exists on |
| 817 buffered streams. | 819 buffered streams. |
| 840 raw = buf; | 842 raw = buf; |
| 841 Py_INCREF(raw); | 843 Py_INCREF(raw); |
| 842 } | 844 } |
| 843 | 845 |
| 844 text = PyUnicode_FromString(name); | 846 text = PyUnicode_FromString(name); |
| 845 if (text == NULL || PyObject_SetAttrString(raw, "name", text) < 0) | 847 if (text == NULL || _PyObject_SetAttrId(raw, &PyId_name, text) < 0) |
| 846 goto error; | 848 goto error; |
| 847 res = _PyObject_CallMethodId(raw, &PyId_isatty, ""); | 849 res = _PyObject_CallMethodId(raw, &PyId_isatty, ""); |
| 848 if (res == NULL) | 850 if (res == NULL) |
| 849 goto error; | 851 goto error; |
| 850 isatty = PyObject_IsTrue(res); | 852 isatty = PyObject_IsTrue(res); |
| 877 if (write_mode) | 879 if (write_mode) |
| 878 mode = "w"; | 880 mode = "w"; |
| 879 else | 881 else |
| 880 mode = "r"; | 882 mode = "r"; |
| 881 text = PyUnicode_FromString(mode); | 883 text = PyUnicode_FromString(mode); |
| 882 if (!text || PyObject_SetAttrString(stream, "mode", text) < 0) | 884 if (!text || _PyObject_SetAttrId(stream, &PyId_mode, text) < 0) |
| 883 goto error; | 885 goto error; |
| 884 Py_CLEAR(text); | 886 Py_CLEAR(text); |
| 885 return stream; | 887 return stream; |
| 886 | 888 |
| 887 error: | 889 error: |
| 1545 static void | 1547 static void |
| 1546 print_exception(PyObject *f, PyObject *value) | 1548 print_exception(PyObject *f, PyObject *value) |
| 1547 { | 1549 { |
| 1548 int err = 0; | 1550 int err = 0; |
| 1549 PyObject *type, *tb; | 1551 PyObject *type, *tb; |
| 1552 _Py_IDENTIFIER(print_file_and_line); | |
| 1550 | 1553 |
| 1551 if (!PyExceptionInstance_Check(value)) { | 1554 if (!PyExceptionInstance_Check(value)) { |
| 1552 PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f); | 1555 PyFile_WriteString("TypeError: print_exception(): Exception expected for value, ", f); |
| 1553 PyFile_WriteString(Py_TYPE(value)->tp_name, f); | 1556 PyFile_WriteString(Py_TYPE(value)->tp_name, f); |
| 1554 PyFile_WriteString(" found\n", f); | 1557 PyFile_WriteString(" found\n", f); |
| 1560 type = (PyObject *) Py_TYPE(value); | 1563 type = (PyObject *) Py_TYPE(value); |
| 1561 tb = PyException_GetTraceback(value); | 1564 tb = PyException_GetTraceback(value); |
| 1562 if (tb && tb != Py_None) | 1565 if (tb && tb != Py_None) |
| 1563 err = PyTraceBack_Print(tb, f); | 1566 err = PyTraceBack_Print(tb, f); |
| 1564 if (err == 0 && | 1567 if (err == 0 && |
| 1565 PyObject_HasAttrString(value, "print_file_and_line")) | 1568 _PyObject_HasAttrId(value, &PyId_print_file_and_line)) |
| 1566 { | 1569 { |
| 1567 PyObject *message; | 1570 PyObject *message; |
| 1568 const char *filename, *text; | 1571 const char *filename, *text; |
| 1569 int lineno, offset; | 1572 int lineno, offset; |
| 1570 if (!parse_syntax_error(value, &message, &filename, | 1573 if (!parse_syntax_error(value, &message, &filename, |
