Drop usage of cStringIO in _c_urlarg.c
|Reported by:||loewis||Owned by:|
(diff, github, buildbot, log)
This patch drops usage of cStringIO from _c_urlarg.c, and replaces it with a regular string object. This is necessary to port the module to Python 3, as there won't be a cStringIO module anymore.
In addition, I also think this is a structural improvement, as using cStringIO is really overkill here. Please correct me if I'm wrong: unquote can only ever shrink the string. Therefore, it is possible to start with a buffer with a size equal to the input string, and can be guaranteed that the output will fit.
The patch uses _PyString_Resize. If that is no acceptable, I can rewrite it to use a separate buffer. Using _PyString_Resize has the advantage that it may avoid an extra copy at the end, namely if only few escaped characters had been in the URL (so that resizing the string doesn't need to reallocate the string object).