This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author jmb236
Recipients SilentGhost, jmb236, serhiy.storchaka
Date 2016-04-14.17:46:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1460656004.78.0.852919938376.issue26756@psf.upfronthosting.co.za>
In-reply-to
Content
I was suggesting that the openhook could somehow be applied to a
*reopening* of sys.stdin.  Something like this:

326c326,329
<                     self._file = sys.stdin
---
>                     if self._openhook:
>                         self._file = self._openhook(self._filename, self._mode)
>                     else:
>                         self._file = sys.stdin

But this won't work because self._filename here is '<stdin>' which
isn't a real filename.  In conjunction with a change to my hook:

   def hook(filename, mode):
       if filename == '<stdin>':
           return io.TextIOWrapper(sys.stdin.buffer, errors='replace')
       return open(filename, mode, errors='replace')

things would work, but this is a bit awkward.

This works for me without changing my hook:

326c326,329
<                     self._file = sys.stdin
---
>                     if self._openhook:
>                         self._file = self._openhook('/dev/stdin', self._mode)
>                     else:
>                         self._file = sys.stdin

but I realize that using /dev/stdin is not portable.

The desired outcome is really just to control Unicode behavior from
stdin, not necessary the ability to provide a generic hook.  Adding an
'errors' keyword to apply to stdin would solve my case, but if you
open up 'errors', someone may also want 'encoding', and the others,
which is why it would be nicer if this could somehow be solved with
the existing openhook interface.
History
Date User Action Args
2016-04-14 17:46:44jmb236setrecipients: + jmb236, SilentGhost, serhiy.storchaka
2016-04-14 17:46:44jmb236setmessageid: <1460656004.78.0.852919938376.issue26756@psf.upfronthosting.co.za>
2016-04-14 17:46:44jmb236linkissue26756 messages
2016-04-14 17:46:44jmb236create