Issue23093
Created on 2014-12-20 14:19 by martin.panter, last changed 2014-12-22 03:01 by python-dev. This issue is now closed.
| Files | ||||
|---|---|---|---|---|
| File name | Uploaded | Description | Edit | |
| detach-indep.patch | martin.panter, 2014-12-20 14:19 | review | ||
| detach-indep.v2.patch | martin.panter, 2014-12-21 11:17 | review | ||
| Messages (6) | |||
|---|---|---|---|
| msg232971 - (view) | Author: Martin Panter (martin.panter) * | Date: 2014-12-20 14:19 | |
Patch to fix the underlying issue I mentioned in msg230955. After calling detach() on one of the BufferedIOBase wrappers or a TextIOWrapper, most operations will raise an exception. My patch ensures the following operations are still usable, because they are documented and it doesn’t make sense to disable them: repr(stream) stream.encoding stream.errors stream.line_buffering |
|||
| msg232973 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2014-12-20 16:42 | |
The issue is still here.
>>> f = open('/dev/null')
>>> f
<_io.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
>>> f.buffer.detach()
<_io.FileIO name='/dev/null' mode='rb' closefd=True>
>>> f
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: raw stream has been detached
Python implementation works.
>>> import _pyio
>>> f = _pyio.open('/dev/null')
>>> f
<_pyio.TextIOWrapper name='/dev/null' mode='r' encoding='UTF-8'>
>>> f.buffer.detach()
<_io.FileIO name='/dev/null' mode='rb' closefd=True>
>>> f
<_pyio.TextIOWrapper mode='r' encoding='UTF-8'>
>>> f = _pyio.open('/dev/null')
>>> f.detach()
<_pyio.BufferedReader name='/dev/null'>
>>> f
<_pyio.TextIOWrapper mode='r' encoding='UTF-8'>
>>> f = _pyio.open('/dev/null', 'rb')
>>> f
<_pyio.BufferedReader name='/dev/null'>
>>> f.detach()
<_io.FileIO name='/dev/null' mode='rb' closefd=True>
>>> f
<_pyio.BufferedReader>
I would be good to make Python and C implementation match.
|
|||
| msg232983 - (view) | Author: Martin Panter (martin.panter) * | Date: 2014-12-20 22:01 | |
Damn, detaching the intermediate buffered stream is a bit more awkward. The difference between the “io” and “_pyio” implementations boils down to: * io.BufferedReader/Writer/RWPair.name properties raise a ValueError if the stream is detached * _pyio._BufferedIOMixin.name property returns “self.raw.name”. When detached, “self.raw” is None, so this causes an AttributeError. This is significant because io.TextIOWrapper.__repr__() only handles AttributeError when accessing “self.buffer.name”. The best option that I can think of to fix this is to make all the repr() implementations handle this ValueError exception. |
|||
| msg232997 - (view) | Author: Martin Panter (martin.panter) * | Date: 2014-12-21 11:17 | |
Here is patch v2, which ignores any exception derived from the Exception base class when reading the self.name etc properties. I’m interested what people think of this approach. |
|||
| msg232998 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * | Date: 2014-12-21 14:17 | |
It looks reasonable to me. |
|||
| msg233006 - (view) | Author: Roundup Robot (python-dev) | Date: 2014-12-22 03:01 | |
New changeset f3ff3e424b6f by Benjamin Peterson in branch '3.4': allow more operations to work on detached streams (closes #23093) https://hg.python.org/cpython/rev/f3ff3e424b6f New changeset afa8d8ab0937 by Benjamin Peterson in branch '2.7': allow more operations to work on detached streams (closes #23093) https://hg.python.org/cpython/rev/afa8d8ab0937 New changeset f2cfa8a348dd by Benjamin Peterson in branch 'default': merge 3.4 (#23093) https://hg.python.org/cpython/rev/f2cfa8a348dd |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2014-12-22 03:01:25 | python-dev | set | status: open -> closed nosy:
+ python-dev resolution: fixed |
| 2014-12-21 14:17:16 | serhiy.storchaka | set | messages: + msg232998 |
| 2014-12-21 11:17:11 | martin.panter | set | files:
+ detach-indep.v2.patch messages: + msg232997 |
| 2014-12-20 22:01:00 | martin.panter | set | messages: + msg232983 |
| 2014-12-20 16:42:27 | serhiy.storchaka | set | versions:
+ Python 2.7, Python 3.5 nosy: + hynek, stutzbach, pitrou, serhiy.storchaka, benjamin.peterson messages: + msg232973 stage: patch review |
| 2014-12-20 14:19:49 | martin.panter | create | |