-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an optional newline parameter to binascii.b2a_base64() to not add a newline #69544
Comments
The base64.b64encode() function calls binascii.b2a_base64() and then strips the newline. It would be more efficient to directly not add a newline. Attached patch adds an optional newline parameter to binascii.b2a_base64(). It also modifies base64.b64encode() to call binascii.b2a_base64() with newline=False. |
+1. Not sure about the parameter name, but if no one suggests better, it LGTM. Added comments on Rietveld. What about adding the same parameter to binascii.b2a_uu()? |
Oh, I forgot to add an unit test.
This function is used in Lib/encodings/uu_codec.py and Lib/uu.py, but the newline is not stripped. So I don't think that it's worth to add an optional parameter. |
Updated patch to take Serhiy's comments in account and now with an unit test! |
Oh by the way, the new parameter is a keyword only parameter. It's not possible to write b2a_base64(data, False). Maybe I should also add an unit test for this. |
The “newline” name seems as good as any. The patch looks good in general. I left a few comments. I agree with not bothering for the UU encoder. That encoding has an embedded line length byte at the start of each line, so it makes less sense to omit newlines. Base-64 is used in places such as URLs where multiline output is not relevant, but I don’t know of a similar case for the UU encoding. If I was doing it, I wouldn’t bother with a test case for keyword-only-ness, but suit yourself. |
With Martin's comments the patch LGTM. |
New changeset 463a09a3bfff by Victor Stinner in branch 'default': |
Thanks for reviews Serhiy & Martin. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: