[Python-3000] Proposed new language for newline parameter to TextIOBase

Adam Olsen rhamph at gmail.com
Wed Aug 15 22:36:58 CEST 2007


On 8/15/07, Guido van Rossum <guido at python.org> wrote:
> On 8/15/07, Adam Olsen <rhamph at gmail.com> wrote:
> > On 8/14/07, Guido van Rossum <guido at python.org> wrote:
> > > (2) newline='': input with untranslated universal newlines mode; lines
> > > may end in \r, \n, or \r\n, and these are returned untranslated.
> >
> > Caveat: this mode cannot be supported by sockets.  When reading a lone
> > \r you need to peek ahead to ensure the next character is not a \n,
> > but for sockets that may block indefinitely.
>
> It depends on what you want. In general *any* read from a socket may
> block indefinitely. If the protocol requires turning around at \r *or*
> \r\n I'd say the protocol is insane.
>
> > I don't expect sockets to use the file API by default, but there's
> > enough overlap (named pipes?) that limitations like this should be
> > well documented (and if possible, produce an explicit error!)
>
> Why do you want it to produce an error? Who says I don't know what I'm
> doing when I request that mode?

As you just said, you'd be insane to require it.

But on second thought I don't think we can reliably say it's wrong.  A
named pipe may just have a file cat'd through it, which would handle
this mode just fine.

It should be documented that interactive streams cannot safely use this mode.

-- 
Adam Olsen, aka Rhamphoryncus


More information about the Python-3000 mailing list