[issue29328] struct module should support variable-length strings

Raymond Hettinger report at bugs.python.org
Mon Jan 23 03:33:53 EST 2017


Raymond Hettinger added the comment:

FWIW, the existence of netstruct https://github.com/stendec/netstruct does at least show that a coherent proposal is possible (the docs provide an API, motivation and examples).

One question is whether this could be implemented in the stdlib struct module without major brain surgery to the existing code which is organized around an initial prepare_s() step whose output is a PyStructObject which includes a fixed s_size field.  The various parsing routines all depend on the s_size field.  Where this proposal would require too much of a total rewrite is likely only answerable by someone building a patch with tests and real-world examples.

Another question is whether supporting variable length input would be better served by providing an alternative API that is better designed for it.  For example, unpack(fmt, input_stream or iterator, limit=None) which would consume as many bytes as needed from the input stream with an optional limit.  This would be nicer than having to figure-out in advance how to extract an input string of the appropriate size.

A last question is whether this should remain outside the standard library.  With PyPI becoming so rich and easy to access, we're often deciding that code is better-off outside the standard library where it can flourish in a more fluid environment.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29328>
_______________________________________


More information about the Python-bugs-list mailing list