File tree Expand file tree Collapse file tree 1 file changed +8
-12
lines changed
Expand file tree Collapse file tree 1 file changed +8
-12
lines changed Original file line number Diff line number Diff line change @@ -1944,25 +1944,21 @@ _bufferedwriter_reset_buf(buffered *self)
19441944static void
19451945_bufferedwriter_set_append (buffered * self )
19461946{
1947- PyObject * mode = _PyObject_GetAttrId (self -> raw , & PyId_mode );
1948- if (mode != NULL && PyUnicode_Check (mode )) {
1947+ PyObject * mode = NULL ;
1948+ if (PyObject_GetOptionalAttr (self -> raw , & _Py_ID (mode ), & mode ) < 0 ) {
1949+ /* Raw fileobj has no mode string so as far as we can know it has
1950+ normal write behavior */
1951+ self -> appending = 0 ;
1952+ } else if (mode != NULL && PyUnicode_Check (mode )) {
19491953 if (PyUnicode_FindChar (mode , 'a' , 0 ,
1950- PyUnicode_GET_LENGTH (mode ), 1 ) != -1 ) {
1954+ PyUnicode_GET_LENGTH (mode ), 1 ) >= 0 ) {
19511955 self -> appending = 1 ;
19521956 }
19531957 else {
19541958 self -> appending = 0 ;
19551959 }
19561960 Py_DECREF (mode );
19571961 }
1958- else {
1959- if (PyErr_ExceptionMatches (PyExc_AttributeError )) {
1960- PyErr_Clear ();
1961- }
1962- /* Raw fileobj has no mode string so as far as we can know it has
1963- normal write behavior */
1964- self -> appending = 0 ;
1965- }
19661962}
19671963
19681964/*[clinic input]
@@ -2063,7 +2059,7 @@ static PyObject *
20632059_bufferedwriter_flush_unlocked (buffered * self )
20642060{
20652061 Py_ssize_t written = 0 ;
2066- Py_off_t n , rewind ;
2062+ Py_off_t n ;
20672063
20682064 if (!VALID_WRITE_BUFFER (self ) || self -> write_pos == self -> write_end )
20692065 goto end ;
You can’t perform that action at this time.
0 commit comments