-
-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
base64_codec uses assert for runtime validity checks #62040
Comments
encodings.base64_codec currently uses "assert errors=='strict'" in a few places, since it doesn't actually support any of the Unicode specific error handling modes. This should either be discarded entirely (and document that the error handling mode is irrelevant for this codec), or else turned into a real check that raises ValueError if an unsupported error mode is passed in. I have a slight preference for just ignoring the error mode as irrelevant (since this isn't a text encoding in the normal Unicode serialisation-as-bytes sense). |
I see that there is identical usage of "assert errors=='strict'" in a number of similar encodings modules: base64_codec.py The error handling mode is irrelevant for all these codecs, so the attached patch addresses them all (choosing to ignore the error mode and documenting this). |
Having discussed this with Ezio, I think the better option might be to raise ValueError instead - if someone is expecting to be able to silently recover from errors they won't be able to, and should find out about this sooner rather than later. |
On 07.07.2013 16:31, Alex Henderson wrote:
+1 |
ValueError works for me. |
OK, now raises ValueError on passing anything other than 'strict'. Note that for the incremental classes I've put checking in __init__ so that ValueError is raised when non-'strict' values are passed to the constructor, not when the incremental encode/decode methods are subsequently called. |
Is this patch likely to go ahead? It has been sitting around a while and would conflict with patches I am working on. If so, I reckon it would be good to factor out some of the new bits of code (_check_strict, _StrictErrors) into a common place, like the “codecs” module. |
Thanks for the patch. I left a couple of comments on Rietveld. |
Would also be good to document that errors='ignored' is not allowed. Currently the documentation says The following string values are defined and implemented by all standard Python codecs:
|
I'd be slightly more inclined to file the fact that "ignore" isn't supported by the base64 codec as a potential bug, with changing the docs as one possible resolution. It shouldn't hold up switching from the assertions to proper runtime checks. |
This issue is 6 years old and has patches: it is no newcomer friendly, I remove the "easy" keyword. |
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: