[issue46375] io.BytesIO does not have peek()

2022-01-22 Thread Marcel Martin
Marcel Martin added the comment: I opened a PR, but I now wonder whether the missing peek() is by design. First, I noticed that instead of using BytesIO directly, I can wrap the instance in an io.BufferedReader, which does have peek(). (It’s just a bit inconvenient.) The second thing is

[issue46375] io.BytesIO does not have peek()

2022-01-22 Thread Marcel Martin
Change by Marcel Martin : -- keywords: +patch pull_requests: +28996 stage: -> patch review pull_request: https://github.com/python/cpython/pull/30808 ___ Python tracker ___

[issue46375] io.BytesIO does not have peek()

2022-01-14 Thread Kumar Aditya
Change by Kumar Aditya : -- nosy: +benjamin.peterson, kumaraditya303, stutzbach ___ Python tracker ___ ___ Python-bugs-list mailing

[issue46375] io.BytesIO does not have peek()

2022-01-14 Thread Marcel Martin
testing), for which I need to add a small workaround using tell() and seek(). -- components: Library (Lib) messages: 410552 nosy: marcelm priority: normal severity: normal status: open title: io.BytesIO does not have peek() type: enhancement versions: Python 3.11

[issue26817] Docs for StringIO should link to io.BytesIO

2020-05-09 Thread Zachary Ware
Change by Zachary Ware : -- resolution: -> out of date stage: -> resolved status: open -> closed ___ Python tracker ___ ___

[issue26817] Docs for StringIO should link to io.BytesIO

2020-05-09 Thread Zackery Spytz
Zackery Spytz added the comment: Python 2 is EOL. -- nosy: +ZackerySpytz ___ Python tracker ___ ___ Python-bugs-list mailing list

[issue31025] io.BytesIO: no way to get the length of the underlying buffer without copying data

2017-07-26 Thread R. David Murray
R. David Murray added the comment: So you are saying that BytesIO has code that checks that its argument only has a single reference and modifies the string in place when it can if so? You can't depend on that in any other implementation of Python, and shouldn't depend on it in CPython

[issue31025] io.BytesIO: no way to get the length of the underlying buffer without copying data

2017-07-26 Thread Arthur Darcet
, then you need to copy it first, otherwise the original bytes object would get modified Case (1): % python -m timeit -s "import io; b = io.BytesIO(b'0' * 2 ** 30)" "b.getbuffer()" 100 loops, best of 3: 0.201 usec per loop Case (2): python -m timeit -s "import

[issue31025] io.BytesIO: no way to get the length of the underlying buffer without copying data

2017-07-25 Thread R. David Murray
R. David Murray added the comment: I'm confused, I don't see how there can be any difference between (1) and (2). -- nosy: +r.david.murray ___ Python tracker

[issue31025] io.BytesIO: no way to get the length of the underlying buffer without copying data

2017-07-25 Thread Arthur Darcet
Arthur Darcet added the comment: it's a tiny bit slow, but that works, thank you. I guess we can close this % python -m timeit -s "import io; b = io.BytesIO(b'0' * 2 ** 30)" "p = b.tell(); b.seek(0, 2); b.tell(); b.seek(p)" 100 loops, best of 3: 0.615 usec per loop %

[issue31025] io.BytesIO: no way to get the length of the underlying buffer without copying data

2017-07-25 Thread Martin Panter
Martin Panter added the comment: Can’t you use b.seek(0, SEEK_END)? -- nosy: +martin.panter versions: -Python 2.7, Python 3.3, Python 3.4, Python 3.5, Python 3.6 ___ Python tracker

[issue31025] io.BytesIO: no way to get the length of the underlying buffer without copying data

2017-07-25 Thread Arthur Darcet
n Python that would reliably not copy any data Should I open a PR to add a `size()` method on the BytesIO class? (simply returning `PyLong_FromSsize_t(self->string_size)` -- components: IO messages: 299054 nosy: rthr priority: normal severity: normal status: open title: io.B

[issue26817] Docs for StringIO should link to io.BytesIO

2016-04-21 Thread Thomas Guettler
New submission from Thomas Guettler: I think a warning at the top of StringIO docs is needed. And it should link to io.BytesIO. Maybe even deprecate StringIO and cStringIO in Python2? StringIO docs: https://docs.python.org/2/library/stringio.html io.BytesIO docs: https://docs.python.org/2

Re: io.BytesIO

2013-03-25 Thread Steven D'Aprano
obj = io.BytesIO(bx*12468) py obj.getbuffer().nbytes 12468 py len(obj.getvalue()) 12468 py len(obj.getbuffer()) 12468 py obj.seek(0, 2) 12468 As far as I can tell, BytesIO objects do not have a fixed size buffer. They will increase in size as needed, just like real file objects on a disk

Re: io.BytesIO

2013-03-25 Thread Fabian von Romberg
memory has been allocated for buffering. getsizeof gets the size of the object structure. I can see at least four ways to get the current size of the BytesIO buffer: py obj = io.BytesIO(bx*12468) py obj.getbuffer().nbytes 12468 py len(obj.getvalue()) 12468 py len(obj.getbuffer

io.BytesIO

2013-03-24 Thread Fabian von Romberg
Hi, is there any way to get the allocated memory size from a io.BytesIO object? Thanks and regards, Fabian -- http://mail.python.org/mailman/listinfo/python-list

Re: io.BytesIO

2013-03-24 Thread Steven D'Aprano
On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote: Hi, is there any way to get the allocated memory size from a io.BytesIO object? The same as for any object: py import io, sys py obj = io.BytesIO() py sys.getsizeof(obj) 48 Is this what you are after, the size of the object

Re: io.BytesIO

2013-03-24 Thread Fabian von Romberg
an attribute or method? Regards, Fabian On 03/24/2013 11:47 PM, Steven D'Aprano wrote: On Sun, 24 Mar 2013 22:56:12 -0500, Fabian von Romberg wrote: Hi, is there any way to get the allocated memory size from a io.BytesIO object? The same as for any object: py import io, sys py obj

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2012-02-24 Thread Ezio Melotti
Changes by Ezio Melotti ezio.melo...@gmail.com: -- versions: -Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12817 ___ ___

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2012-02-24 Thread Stefan Krah
Stefan Krah stefan-use...@bytereef.org added the comment: The current interpretation in the PEP-3118 repo is that a request without PyBUF_FORMAT means implicit cast to unsigned bytes. This makes the behavior of PyObject_AsWriteBuffer() correct, so I'm closing this. -- resolution: -

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2011-08-23 Thread Stefan Krah
Stefan Krah stefan-use...@bytereef.org added the comment: I've come to think that PyBUF_SIMPLE requests were really intended as a way of casting contiguous buffers with arbitrary formats to one-dimensional buffers of unsigned bytes. At least that is what Numpy does. Then test_multiprocessing

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2011-08-23 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Please also see issue5231. -- ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue12817 ___ ___

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2011-08-22 Thread Stefan Krah
', [1,2,3,4,5]) m = memoryview(a) m.format 'i' buf = io.BytesIO(bytearray(5)) buf.readinto(m) Traceback (most recent call last): File stdin, line 1, in module TypeError: expected an object with a writable buffer interface The error occurs in Objects/abstract.c:315: ((*pb-bf_getbuffer)(obj

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2011-08-22 Thread Stefan Krah
Stefan Krah stefan-use...@bytereef.org added the comment: Of course, there is another interpretation: [PyBUF_FORMAT] The returned buffer must have true format information if this flag is provided. This would be used when the consumer is going to be checking for what 'kind' of data is

[issue12817] test_multiprocessing: io.BytesIO() requires bytearray buffers

2011-08-22 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Antoine, is it correct that io.BytesIO should only be used with bytearray buffers? BytesIO does a copy of the original object, it does not touch the original buffer. -- ___ Python tracker rep

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-09-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: This was committed in r84562. -- resolution: - fixed stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5506

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-09-03 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Here is a patch implementing getbuffer(), together with tests. -- keywords: +patch stage: needs patch - patch review Added file: http://bugs.python.org/file18731/bytesiobuf2.patch ___ Python tracker

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-09-03 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: There was an unused weakreflist member. -- Added file: http://bugs.python.org/file18732/bytesiobuf2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5506

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-09-03 Thread Antoine Pitrou
Changes by Antoine Pitrou pit...@free.fr: Removed file: http://bugs.python.org/file18731/bytesiobuf2.patch ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5506 ___

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-09-03 Thread Antoine Pitrou
Changes by Antoine Pitrou pit...@free.fr: -- components: +IO nosy: +amaury.forgeotdarc, benjamin.peterson ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5506 ___

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-09-01 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Thinking about it, I'm not sure this would be a good idea to do this by default. There is an ambiguity where it's not obvious if the buffer would contain the whole data or only the bytes after the current position. I think perhaps an explicit

[issue5506] io.BytesIO doesn't support the buffer protocol

2010-08-08 Thread Terry J. Reedy
Changes by Terry J. Reedy tjre...@udel.edu: -- versions: +Python 3.2 -Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5506 ___ ___

[issue7349] StringIO.StringIO, io.BytesIO, and io.StringIO accept None in places where other file-like objects don't

2009-12-13 Thread Benjamin Peterson
Benjamin Peterson benja...@python.org added the comment: Fixed in r76805. I think I got all the cases... -- nosy: +benjamin.peterson resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7349

[issue7349] StringIO.StringIO, io.BytesIO, and io.StringIO accept None in places where other file-like objects don't

2009-11-18 Thread Jean-Paul Calderone
New submission from Jean-Paul Calderone exar...@divmod.com: The actual file type rejects None in places like as the argument to read or readlines. StringIO.StringIO, io.BytesIO, and io.StringIO all accept None to mean the same as passing no argument at all. This makes it tricky to write code

[issue7349] StringIO.StringIO, io.BytesIO, and io.StringIO accept None in places where other file-like objects don't

2009-11-18 Thread Philip Jenvey
Philip Jenvey pjen...@underboss.org added the comment: The original pure-python impl. of io accepted None, and still does. This is a regression in C impl. -- nosy: +pjenvey ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7349

[issue7349] StringIO.StringIO, io.BytesIO, and io.StringIO accept None in places where other file-like objects don't

2009-11-18 Thread R. David Murray
Changes by R. David Murray rdmur...@bitdance.com: -- nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7349 ___ ___ Python-bugs-list

[issue7249] Consider allowing io.BytesIO sizes to be passed as 'long' in 2.6

2009-11-02 Thread Georg Brandl
Changes by Georg Brandl ge...@python.org: -- assignee: - pitrou nosy: +pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7249 ___ ___

[issue7249] Consider allowing io.BytesIO sizes to be passed as 'long' in 2.6

2009-11-02 Thread Antoine Pitrou
Changes by Antoine Pitrou pit...@free.fr: -- components: +IO priority: - normal stage: - needs patch versions: +Python 2.7 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue7249 ___

[issue7249] Consider allowing io.BytesIO sizes to be passed as 'long' in 2.6

2009-11-02 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I've committed to the 2.6 branch in r76073. 2.7 is actually ok. Thanks for the report! -- resolution: - fixed status: open - closed ___ Python tracker rep...@bugs.python.org

[issue7249] Consider allowing io.BytesIO sizes to be passed as 'long' in 2.6

2009-11-01 Thread Ryan Leslie
New submission from Ryan Leslie ryle...@gmail.com: py StringIO.StringIO(foo).read(long(1)) 'f' py io.BytesIO(foo).read(long(1)) Traceback (most recent call last): File stdin, line 1, in module TypeError: integer argument expected, got 'long' This is known to cause problems when reading zip

[issue5449] bug fix to prevent io.BytesIO from accepting arbitrary keyword arguments

2009-08-04 Thread Alexandre Vassalotti
Alexandre Vassalotti alexan...@peadrop.com added the comment: Committed in r74316. Thanks! -- nosy: +alexandre.vassalotti resolution: - accepted stage: - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org

[issue6218] Make io.BytesIO and io.StringIO picklable.

2009-07-21 Thread Alexandre Vassalotti
Alexandre Vassalotti alexan...@peadrop.com added the comment: Committed in r74158 (branches/py3k). -- resolution: - accepted stage: patch review - committed/rejected status: open - closed ___ Python tracker rep...@bugs.python.org

[issue6218] Make io.BytesIO and io.StringIO picklable.

2009-06-08 Thread Alexandre Vassalotti
Alexandre Vassalotti alexan...@peadrop.com added the comment: I split the bug fixes in the patch into two separate issues. It looks like pickling support for io.StringIO and io.BytesIO will have to wait for 3.2. -- dependencies: +Better type checking for the arguments of io.StringIO

[issue6218] Make io.BytesIO and io.StringIO picklable.

2009-06-06 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: I think it's too late for 3.1, since it's a new feature. -- nosy: +benjamin.peterson, pitrou versions: -Python 3.1 ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue6218

[issue6218] Make io.BytesIO and io.StringIO picklable.

2009-06-05 Thread Alexandre Vassalotti
New submission from Alexandre Vassalotti alexan...@peadrop.com: Here is a patch to add pickling support to io.BytesIO and io.StringIO. Although they are non-trivial, the additions were made with a fair amount of care (and love!) and thus I believe they could be included in 3.1. Furthermore

[issue5506] io.BytesIO doesn't support the buffer protocol

2009-04-05 Thread Georg Brandl
Georg Brandl ge...@python.org added the comment: Is this still unimplemented? -- nosy: +georg.brandl ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5506 ___

[issue5506] io.BytesIO doesn't support the buffer protocol

2009-04-05 Thread Antoine Pitrou
Antoine Pitrou pit...@free.fr added the comment: Yes. I don't remember which use case I was thinking about when I suggested this, but it may be useful to e.g. write() all the data to a file object without actually making a copy (getvalue() does). --

[issue5506] io.BytesIO doesn't support the buffer protocol

2009-03-18 Thread Antoine Pitrou
New submission from Antoine Pitrou pit...@free.fr: It may be logical for BytesIO to support the buffer protocol (readable /and/ writable). -- components: Library (Lib) messages: 83740 nosy: pitrou priority: normal severity: normal stage: test needed status: open title: io.BytesIO

[issue5449] bug fix to prevent io.BytesIO from accepting arbitrary keyword arguments

2009-03-13 Thread Antoine Pitrou
Changes by Antoine Pitrou pit...@free.fr: -- nosy: +benjamin.peterson, pitrou ___ Python tracker rep...@bugs.python.org http://bugs.python.org/issue5449 ___ ___