Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
a4815caa
Kaydet (Commit)
a4815caa
authored
Ock 09, 2011
tarafından
Antoine Pitrou
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Issue #10872: The repr() of TextIOWrapper objects now includes the mode
if available. (at Georg's request)
üst
a6c91f5e
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
51 additions
and
11 deletions
+51
-11
_pyio.py
Lib/_pyio.py
+10
-3
test_io.py
Lib/test/test_io.py
+4
-1
NEWS
Misc/NEWS
+3
-0
textio.c
Modules/_io/textio.c
+34
-7
No files found.
Lib/_pyio.py
Dosyayı görüntüle @
a4815caa
...
@@ -1504,13 +1504,20 @@ class TextIOWrapper(TextIOBase):
...
@@ -1504,13 +1504,20 @@ class TextIOWrapper(TextIOBase):
# - "chars_..." for integer variables that count decoded characters
# - "chars_..." for integer variables that count decoded characters
def
__repr__
(
self
):
def
__repr__
(
self
):
result
=
"<_pyio.TextIOWrapper"
try
:
try
:
name
=
self
.
name
name
=
self
.
name
except
AttributeError
:
except
AttributeError
:
return
"<_pyio.TextIOWrapper encoding={0!r}>"
.
format
(
self
.
encoding
)
pass
else
:
result
+=
" name={0!r}"
.
format
(
name
)
try
:
mode
=
self
.
mode
except
AttributeError
:
pass
else
:
else
:
re
turn
"<_pyio.TextIOWrapper name={0!r} encoding={1!r}>"
.
format
(
re
sult
+=
" mode={0!r}"
.
format
(
mode
)
name
,
self
.
encoding
)
return
result
+
" encoding={0!r}>"
.
format
(
self
.
encoding
)
@property
@property
def
encoding
(
self
):
def
encoding
(
self
):
...
...
Lib/test/test_io.py
Dosyayı görüntüle @
a4815caa
...
@@ -1717,9 +1717,12 @@ class TextIOWrapperTest(unittest.TestCase):
...
@@ -1717,9 +1717,12 @@ class TextIOWrapperTest(unittest.TestCase):
raw
.
name
=
"dummy"
raw
.
name
=
"dummy"
self
.
assertEqual
(
repr
(
t
),
self
.
assertEqual
(
repr
(
t
),
"<
%
s.TextIOWrapper name='dummy' encoding='utf-8'>"
%
modname
)
"<
%
s.TextIOWrapper name='dummy' encoding='utf-8'>"
%
modname
)
t
.
mode
=
"r"
self
.
assertEqual
(
repr
(
t
),
"<
%
s.TextIOWrapper name='dummy' mode='r' encoding='utf-8'>"
%
modname
)
raw
.
name
=
b
"dummy"
raw
.
name
=
b
"dummy"
self
.
assertEqual
(
repr
(
t
),
self
.
assertEqual
(
repr
(
t
),
"<
%
s.TextIOWrapper name=b'dummy' encoding='utf-8'>"
%
modname
)
"<
%
s.TextIOWrapper name=b'dummy'
mode='r'
encoding='utf-8'>"
%
modname
)
def
test_line_buffering
(
self
):
def
test_line_buffering
(
self
):
r
=
self
.
BytesIO
()
r
=
self
.
BytesIO
()
...
...
Misc/NEWS
Dosyayı görüntüle @
a4815caa
...
@@ -40,6 +40,9 @@ Core and Builtins
...
@@ -40,6 +40,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #10872: The repr() of TextIOWrapper objects now includes the mode
if available.
- Issue #10869: Fixed bug where ast.increment_lineno modified the root
- Issue #10869: Fixed bug where ast.increment_lineno modified the root
node twice.
node twice.
...
...
Modules/_io/textio.c
Dosyayı görüntüle @
a4815caa
...
@@ -2323,25 +2323,52 @@ textiowrapper_truncate(textio *self, PyObject *args)
...
@@ -2323,25 +2323,52 @@ textiowrapper_truncate(textio *self, PyObject *args)
static
PyObject
*
static
PyObject
*
textiowrapper_repr
(
textio
*
self
)
textiowrapper_repr
(
textio
*
self
)
{
{
PyObject
*
nameobj
,
*
re
s
;
PyObject
*
nameobj
,
*
modeobj
,
*
res
,
*
s
;
CHECK_INITIALIZED
(
self
);
CHECK_INITIALIZED
(
self
);
res
=
PyUnicode_FromString
(
"<_io.TextIOWrapper"
);
if
(
res
==
NULL
)
return
NULL
;
nameobj
=
PyObject_GetAttrString
((
PyObject
*
)
self
,
"name"
);
nameobj
=
PyObject_GetAttrString
((
PyObject
*
)
self
,
"name"
);
if
(
nameobj
==
NULL
)
{
if
(
nameobj
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
PyErr_Clear
();
PyErr_Clear
();
else
else
return
NULL
;
goto
error
;
res
=
PyUnicode_FromFormat
(
"<_io.TextIOWrapper encoding=%R>"
,
self
->
encoding
);
}
}
else
{
else
{
res
=
PyUnicode_FromFormat
(
"<_io.TextIOWrapper name=%R encoding=%R>"
,
s
=
PyUnicode_FromFormat
(
" name=%R"
,
nameobj
);
nameobj
,
self
->
encoding
);
Py_DECREF
(
nameobj
);
Py_DECREF
(
nameobj
);
if
(
s
==
NULL
)
goto
error
;
PyUnicode_AppendAndDel
(
&
res
,
s
);
if
(
res
==
NULL
)
return
NULL
;
}
}
return
res
;
modeobj
=
PyObject_GetAttrString
((
PyObject
*
)
self
,
"mode"
);
if
(
modeobj
==
NULL
)
{
if
(
PyErr_ExceptionMatches
(
PyExc_AttributeError
))
PyErr_Clear
();
else
goto
error
;
}
else
{
s
=
PyUnicode_FromFormat
(
" mode=%R"
,
modeobj
);
Py_DECREF
(
modeobj
);
if
(
s
==
NULL
)
goto
error
;
PyUnicode_AppendAndDel
(
&
res
,
s
);
if
(
res
==
NULL
)
return
NULL
;
}
s
=
PyUnicode_FromFormat
(
"%U encoding=%R>"
,
res
,
self
->
encoding
);
Py_DECREF
(
res
);
return
s
;
error:
Py_XDECREF
(
res
);
return
NULL
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment