Re: [Python-Dev] BufferedReader.peek() ignores its argument
On Sat, Apr 4, 2009 at 9:03 PM, Antoine Pitrou solip...@pitrou.net wrote: Hello, Currently, BufferedReader.peek() ignores its argument and can return more or less than the number of bytes requested by the user. This is how it was implemented in the Python version, and we've reflected this in the C version. It seems a bit strange and unhelpful though. Should we change the implementation so that the argument to peek() becomes the upper bound to the number of bytes returned? I am not sure if this is a good idea. Currently, the argument of peek() is documented as a lower bound that cannot exceed the size of the buffer: Returns buffered bytes without advancing the position. The argument indicates a desired minimal number of bytes; we do at most one raw read to satisfy it. We never return more than self.buffer_size. Changing the meaning of peek() now could introduce at least some confusion and maybe also bugs. And personally, I like the current behavior, since it guarantees that peek() won't return an empty string unless you reached the end-of-file. Plus, it is fairly easy to cap the number of bytes returned by doing f.peek()[:upper_bound]. -- Alexandre ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] BufferedReader.peek() ignores its argument
Alexandre Vassalotti alexandre at peadrop.com writes: I am not sure if this is a good idea. Currently, the argument of peek() is documented as a lower bound that cannot exceed the size of the buffer: Unfortunately, in practice, the argument is neither a lower bound nor an upper bound. It's just used as some kind of internal heuristic (in the Python version) or not used at all (in the C version). Regards Antoine. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
[Python-Dev] BufferedReader.peek() ignores its argument
Hello, Currently, BufferedReader.peek() ignores its argument and can return more or less than the number of bytes requested by the user. This is how it was implemented in the Python version, and we've reflected this in the C version. It seems a bit strange and unhelpful though. Should we change the implementation so that the argument to peek() becomes the upper bound to the number of bytes returned? Thanks for your advice, Antoine. ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] BufferedReader.peek() ignores its argument
2009/4/4 Antoine Pitrou solip...@pitrou.net: Hello, Currently, BufferedReader.peek() ignores its argument and can return more or less than the number of bytes requested by the user. This is how it was implemented in the Python version, and we've reflected this in the C version. It seems a bit strange and unhelpful though. Should we change the implementation so that the argument to peek() becomes the upper bound to the number of bytes returned? +1 That sounds more useful. Thanks for your advice, -- Regards, Benjamin ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com
Re: [Python-Dev] BufferedReader.peek() ignores its argument
On Sun, Apr 05, 2009, Antoine Pitrou wrote: Currently, BufferedReader.peek() ignores its argument and can return more or less than the number of bytes requested by the user. This is how it was implemented in the Python version, and we've reflected this in the C version. It seems a bit strange and unhelpful though. Should we change the implementation so that the argument to peek() becomes the upper bound to the number of bytes returned? IIRC, this was made to handle SSL where the number of bytes returned may need to be larger than the size. If that's the case, there should be a record somewhere in the list archives... (Or possibly the svn logs.) -- Aahz (a...@pythoncraft.com) * http://www.pythoncraft.com/ Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it. --Brian W. Kernighan ___ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com